Skip to content

Tracing

Updated 3 min read

The Envoy AI Gateway can export a trace span for every model call and a set of GenAI metrics, using the OpenTelemetry GenAI conventions. The AI Gateway example in this repo turns that on and points it at the collector that Nebari Infrastructure Core (NIC) runs in the cluster. This page covers the gateway. Request content is never captured unless you opt in.


  • Spans. The AI Gateway’s external processor (ai-gateway-extproc) writes one span per model call. It runs as a native sidecar (init) container in the Envoy pods, and its spans and metrics carry service.name ai-gateway.
  • GenAI attributes. With AI_GATEWAY_TRACING_SEMCONV set to gen_ai, spans use the GenAI attribute names. Both streamed and non-streamed calls carry gen_ai.usage.input_tokens and gen_ai.usage.output_tokens. With AI Gateway v1.1.0, a streamed request that the client cancels before the answer ends may leave no gateway span (theagentrouter/agent-router#2753).
  • GenAI metrics. The same process exports GenAI metrics, including token usage. Metrics are exported every 60 seconds unless you set OTEL_METRIC_EXPORT_INTERVAL.

The tracing settings are two environment variables on the extproc, set through the chart’s extProc.extraEnvVars in the Helm values of the envoy-ai-gateway Application:

examples/envoy-ai-gateway.yaml
# Generated from operator/cmd/render-pins/templates/envoy-ai-gateway.yaml.tmpl, do not edit.
# Envoy AI Gateway ArgoCD Applications.
#
# The AI Gateway is shipped as TWO separate Helm charts:
#   1. ai-gateway-crds-helm  - CRDs (AIGatewayRoute, AIServiceBackend,
#                              BackendSecurityPolicy, GatewayConfig, MCPRoute)
#   2. ai-gateway-helm       - Controller + webhooks
#
# Prerequisites:
#   - Kubernetes 1.32+
#   - Envoy Gateway v1.8.1+ installed WITH the AI-Gateway-compatible
#     values (extensionApis.enableBackend, extensionManager pointing at
#     this controller, backendResources allowing InferencePool). See
#     ./envoy-gateway.yaml for the complete configuration. Nebari
#     Infrastructure Core ships a bare Envoy Gateway install by
#     default - you MUST replace or supplement those values with the
#     ones in envoy-gateway.yaml or the pack's routing will 404 at
#     runtime.
#
# This manual installation is a workaround until the chart's
# envoyAIGateway.install flag is implemented:
#   https://github.com/nebari-dev/nebari-llm-serving-pack/issues/44
#
# References:
#   - https://aigateway.envoyproxy.io/docs/getting-started/installation/
#   - https://github.com/envoyproxy/ai-gateway
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: envoy-ai-gateway-crds
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "3"
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: nebari-apps

  source:
    chart: ai-gateway-crds-helm
    repoURL: docker.io/envoyproxy
    targetRevision: v1.1.0

  destination:
    server: https://kubernetes.default.svc
    namespace: envoy-ai-gateway-system

  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
      - ServerSideApply=true
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: envoy-ai-gateway
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "4"
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: nebari-apps

  source:
    chart: ai-gateway-helm
    repoURL: docker.io/envoyproxy
    targetRevision: v1.1.0
    helm:
      releaseName: envoy-ai-gateway
      # Webhook TLS via cert-manager, NOT the chart's default self-signed mode.
      #
      # The default mode generates a CA at Helm *render* time, guarded by a
      # `lookup` that is always empty under ArgoCD, so every render mints a new
      # CA while the controller writes `caBundle` only once at startup. The two
      # drift apart and the API server rejects every Envoy proxy pod CREATE.
      # See https://github.com/nebari-dev/llm-serving-pack/issues/84
      #
      # Requires cert-manager and cainjector, which Nebari Infrastructure Core
      # installs by default.
      values: |
        controller:
          mutatingWebhook:
            certManager:
              enable: true

        # Exports gateway traces and GenAI metrics to NIC's in-cluster
        # collector over OTLP/HTTP, under the OpenTelemetry GenAI conventions.
        # Message content stays out. The spans need a trace backend behind the
        # collector (the lgtm pack) or they land in the collector's own log.
        extProc:
          extraEnvVars:
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: http://opentelemetry-collector.monitoring.svc.cluster.local:4318
            - name: AI_GATEWAY_TRACING_SEMCONV
              value: gen_ai

  destination:
    server: https://kubernetes.default.svc
    namespace: envoy-ai-gateway-system

  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
      - ServerSideApply=true
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m

OTEL_EXPORTER_OTLP_ENDPOINT points at NIC’s collector (Service opentelemetry-collector in the monitoring namespace, OTLP/HTTP on port 4318). AI_GATEWAY_TRACING_SEMCONV selects the GenAI conventions. The example sets no protocol or metrics exporter variables.

An existing install re-applies the updated envoy-ai-gateway Application, or merges the extProc.extraEnvVars block into the values of its own copy (see Installation). After the sync, the AI Gateway controller rolls the Envoy pods on its own, because the extproc configuration hash changes. There is no manual restart step.

To check it, send a request through a model endpoint, then look at your trace backend, or at the collector’s log if you have none (next section).


The collector only forwards what it receives. To see and search traces you need a trace backend pack deployed behind it, such as the lgtm pack.

Without one, NIC’s base collector writes every span to its own log at verbosity: detailed, which is very noisy. NIC has an open request to lower it to basic: nebari-infrastructure-core#810. Until a backend is in place, the spans show up in the collector’s log. NIC runs the collector as a DaemonSet, and its Service only sends traffic to the collector pod on the same node (internalTrafficPolicy: Local), so read the log of the collector pod on the node that runs the Envoy pod. Select the pods with the Service’s own selector:

Terminal window
kubectl -n monitoring get svc opentelemetry-collector -o jsonpath='{.spec.selector}'
kubectl -n monitoring get pods -l <key>=<value> -o wide # pick the pod on the Envoy pod's node
kubectl -n monitoring logs <collector-pod>

By default the spans and metrics hold no prompts or completions: only the model, token counts, timing and status. Capturing message content is an opt-in through the extproc environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. The example does not set it. Turning it on puts user prompts and model output into your trace storage and the collector log, makes spans much larger, and sends that data to everyone who can read traces. Enable it only if you accept that.


If a caller sends a W3C traceparent header, the gateway span continues that trace. Requests without one start a new trace.

The AI Gateway maps the request header agent-session-id to the span attribute session.id by default (the chart’s controller.spanRequestHeaderAttributes). The example leaves that setting at the chart default, so an agent that sends agent-session-id gets all of its calls grouped under one session.id.


Sampling is parent-based. A caller’s traceparent with the sampled flag unset means the gateway records no span for that call, and a sampled one means it does. For requests with no parent the default sampler applies. To change this, set OTEL_TRACES_SAMPLER (and OTEL_TRACES_SAMPLER_ARG where the sampler needs one) in the same extraEnvVars list.


Tracing is never a hard dependency. If the collector is missing or unreachable, requests are unaffected. The extproc logs export failures every few seconds for traces and once per metric export interval for metrics, not once per request. On a cluster without NIC’s collector, install it or point OTEL_EXPORTER_OTLP_ENDPOINT elsewhere.