設定 OpenTelemetry POC

原始碼 examples/online_serving/opentelemetry

設定 OpenTelemetry POC#

  1. 安裝 OpenTelemetry 包

    pip install \
      'opentelemetry-sdk>=1.26.0,<1.27.0' \
      'opentelemetry-api>=1.26.0,<1.27.0' \
      'opentelemetry-exporter-otlp>=1.26.0,<1.27.0' \
      'opentelemetry-semantic-conventions-ai>=0.4.1,<0.5.0'
    
  2. 在 Docker 容器中啟動 Jaeger

    # From: https://www.jaegertracing.io/docs/1.57/getting-started/
    docker run --rm --name jaeger \
        -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
        -p 6831:6831/udp \
        -p 6832:6832/udp \
        -p 5778:5778 \
        -p 16686:16686 \
        -p 4317:4317 \
        -p 4318:4318 \
        -p 14250:14250 \
        -p 14268:14268 \
        -p 14269:14269 \
        -p 9411:9411 \
        jaegertracing/all-in-one:1.57
    
  3. 在新 Shell 中,匯出 Jaeger IP

    export JAEGER_IP=$(docker inspect   --format '{{ .NetworkSettings.IPAddress }}' jaeger)
    export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=grpc://$JAEGER_IP:4317
    

    然後為 OpenTelemetry 設定 vLLM 的服務名稱,啟用與 Jaeger 的不安全連線並執行 vLLM

    export OTEL_SERVICE_NAME="vllm-server"
    export OTEL_EXPORTER_OTLP_TRACES_INSECURE=true
    vllm serve facebook/opt-125m --otlp-traces-endpoint="$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"
    
  4. 在新 Shell 中,使用來自虛擬客戶端的跟蹤上下文傳送請求

    export JAEGER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' jaeger)
    export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=grpc://$JAEGER_IP:4317
    export OTEL_EXPORTER_OTLP_TRACES_INSECURE=true
    export OTEL_SERVICE_NAME="client-service"
    python dummy_client.py
    
  5. 開啟 Jaeger WebUI: https://:16686/

    在搜尋窗格中,選擇 vllm-server 服務並點選 Find Traces。您應該獲得一個跟蹤列表,每個請求對應一個跟蹤。 Traces

  6. 點選跟蹤將顯示其 Span 及其標籤。在此演示中,每個跟蹤有 2 個 Span。一個來自包含提示文字的虛擬客戶端,另一個來自包含有關請求元資料的 vLLM。 Spans details

匯出器協議#

OpenTelemetry 支援 grpchttp/protobuf 作為匯出器中跟蹤資料的傳輸協議。預設情況下,使用 grpc。要將 http/protobuf 設定為協議,請按如下方式配置 OTEL_EXPORTER_OTLP_TRACES_PROTOCOL 環境變數

export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://$JAEGER_IP:4318/v1/traces
vllm serve facebook/opt-125m --otlp-traces-endpoint="$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"

FastAPI 的 Instrumentation#

OpenTelemetry 允許 FastAPI 的自動 Instrumentation。

  1. 安裝 Instrumentation 庫

    pip install opentelemetry-instrumentation-fastapi
    
  2. 使用 opentelemetry-instrument 執行 vLLM

    opentelemetry-instrument vllm serve facebook/opt-125m
    
  3. 向 vLLM 傳送請求並在 Jaeger 中找到其跟蹤。它應該包含來自 FastAPI 的 Span。

FastAPI Spans

示例材料#