Skip to content

feat(k8s): export gateway spans without key metadata - #4520

Merged
dan-petty merged 2 commits into
mainfrom
feat/4518-export-gateway-spans-without-key-metadata
Nov 11, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/4518-export-gateway-spans-without-key-metadata

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The LiteLLM gateway sends a span for each request to the in-cluster OpenTelemetry Collector over OTLP/HTTP, so a trace shows its queue, retry and fallback time. turn_off_message_logging keeps the prompt and the reply off the spans. LiteLLM still writes key data on each span (the key hash, alias and user, and the x- request headers), and a refused key puts its hash in the error text. A transform processor of the Collector traces pipeline deletes these attributes and each attribute that names authorization or an API key, and masks each 64-digit hex value of gateway spans, before Tempo. The gateway egress admits only the Collector pods on TCP 4318. Checks of the k8s row of devops ci read the callback, the endpoint, the egress rule and the effect of the processor.

Closes #4518

Change: openspec/changes/archive/2026-11-11-4518-export-gateway-spans-without-key-metadata/

The LiteLLM gateway sends its spans to the in-cluster OpenTelemetry
Collector over OTLP/HTTP, with message logging off. The Collector
traces pipeline deletes the key data that LiteLLM writes on each span
(metadata.user_api_key_*, metadata.requester_custom_headers, header
attributes that name authorization or an API key) and the SHA-256 key
hash in gateway error text, before Tempo stores the span. The gateway
egress admits only the Collector pods on TCP 4318.

Checks of the k8s row of devops ci read the callback, the endpoint,
the egress rule and the effect of the processor statements.
@dan-petty dan-petty added type/feature Type feature: a new function scope/k8s Kubernetes commands, Helm charts, pods, services, and policies labels Nov 11, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Evidence

  • uv run devops ci --only k8s: 106 cases, 0 failed. The three new checks fail on origin/main and pass on this branch.
  • uv run devops ci test tests/ai/benchmark/test_k8s_llm_gateway.py: the egress test admits the Collector peer on TCP 4318 only.
  • kubectl kustomize k8s/llm, k8s/llm/gateway and k8s/otel: all render.
  • otelcol-contrib validate (image otel/opentelemetry-collector-contrib:0.161.0, the live version) accepts the config of k8s/otel/values.yaml. A copy with an unknown OTTL function fails, so validate parses the statements.
  • A throwaway Collector of the same image, with transform/key_data and a debug exporter, got one gateway span and one devops-cli span over OTLP/JSON. The gateway span lost metadata.user_api_key_hash, metadata.user_api_key_alias, metadata.requester_custom_headers and http.request.header.authorization; the hash in exception and in the event exception.message became <redacted>; the event lost x-api-key. The devops-cli span kept its 64-digit digest.

This pull request ships alone. Gateway spans become children of devops-cli spans only for requests that carry traceparent. The UnifiedClient path sends it now. The pydantic-ai agent path sends it after the agent spans change of #2536. A request without traceparent gets its own gateway trace.

Rollout (a person, after the merge)

Argo CD syncs from main. Do not apply by hand.

  1. The otel-collector Application syncs first (sync wave 1). The Collector pod restarts with transform/key_data. Check: kubectl -n otel rollout status deploy/otel-collector-opentelemetry-collector and kubectl -n otel logs deploy/otel-collector-opentelemetry-collector --since=5m | grep -i -E "error|ottl" (expect no line).
  2. The llm Application syncs. The gateway ConfigMap gets a new hash, so the gateway pod rolls. Check: kubectl -n llm rollout status deploy/llm-gateway and kubectl -n llm logs deploy/llm-gateway --since=5m | grep -i opentelemetry (expect no ImportError and no export error).

If the llm Application syncs before the Collector has the rule, gateway spans can reach Tempo without the rule for that time. To prevent this, sync otel-collector first and wait for step 1: argocd app sync otel-collector, then argocd app sync llm.

Live check (a person)

Make one call through the gateway, for example devops ai gateway status, or a chat call. Then in Grafana Explore, data source Tempo, for the last 15 minutes:

  1. A gateway span exists: { resource.service.name = "llm-gateway" }. Expect Received Proxy Server Request and litellm_request spans.
  2. No span holds key data: { resource.service.name = "llm-gateway" && span.metadata.user_api_key_hash != nil } and { span.metadata.user_api_key_alias != nil || span.metadata.requester_custom_headers != nil }. Expect no trace. Also check the attribute list: list_tempo_attribute_names with scope span must hold no name that starts with metadata.user_api_key_.
  3. No content: { resource.service.name = "llm-gateway" && span.gen_ai.input.messages != nil }. Expect no trace.
  4. Nesting: { resource.service.name = "llm-gateway" } && { resource.service.name = "devops-cli" } for a UnifiedClient call shows the gateway span under the devops-cli span.

Rollback

Revert the squash commit with a pull request into main. Argo CD then removes the otel callback, the OTEL_* variables and the egress rule, and the gateway pod rolls. The revert also removes transform/key_data; keep it with a partial revert if only the gateway part fails, because it deletes nothing that another service needs.

@dan-petty
dan-petty marked this pull request as ready for review November 11, 2026 06:15
@dan-petty
dan-petty enabled auto-merge (squash) November 11, 2026 06:15
@dan-petty
dan-petty merged commit 7234d71 into main Nov 11, 2026
31 checks passed
@dan-petty
dan-petty deleted the feat/4518-export-gateway-spans-without-key-metadata branch November 11, 2026 06:17
@dan-petty

Copy link
Copy Markdown
Owner Author

Review findings after the merge, and what I did:

# Severity Finding Verdict Action
1 major transform/key_data (k8s/otel/values.yaml) does not delete the request bodies of LiteLLM management-endpoint spans. request.key on /key/block and /key/unblock can hold a raw sk- key. request.callback_vars on /team/{team_id}/callback holds callback secrets. GATEWAY_KEY_ATTRIBUTES in tests/gate/k8s_checks/otel_collector.py does not list them. Confirmed This PR is merged, so I filed #4539.

How I verified the finding (LiteLLM v1.103.10 source, the image tag in k8s/llm/gateway/deployment.yaml):

  • _emit_management_endpoint_otel_span (litellm/proxy/management_helpers/utils.py) reads the parsed request body when the endpoint has an http_request argument. _CREDENTIAL_FIELDS filters only the response.
  • The success hook and the failure hook (litellm/integrations/opentelemetry.py, lines 3390 and 3448) write request.<field> for each body field.
  • block_key and unblock_key take http_request, and their body is BlockKeyRequest.key: str. add_team_callbacks takes http_request, and its body has callback_vars: dict[str, str].
  • The gateway sets callbacks: ["otel"] and does not set LITELLM_OTEL_V2, so it uses this legacy path.
  • No present rule matches request.key or request.callback_vars, and a raw sk- key is not 64-digit hex.

The fix in #4539 deletes by prefix, not field by field: ^(request|response)[.] on llm-gateway spans. In v1.103.10 only the management hooks write these prefixes, so the rule removes no model, route, token or error attribute. The issue also adds the attributes to the gate check, so the k8s row fails if the path comes back. The path is latent: the review found no request.* span attribute in Tempo since 2026-11-11T00:00Z.

dan-petty pushed a commit that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.112.0](v0.111.0...v0.112.0)
(2026-11-11)


### Features

* **k8s:** export gateway spans without key metadata
([#4520](#4520))
([7234d71](7234d71))
* **k8s:** set the homelab domain in container env values
([#4608](#4608))
([a3bcf7c](a3bcf7c))
* **telemetry:** send pydantic-ai spans through the exporter seam
([#4538](#4538))
([fcf2a7a](fcf2a7a))


### Bug Fixes

* **ai:** price cached prompt tokens of chat calls
([#4584](#4584))
([f84bbe6](f84bbe6))
* **devcontainer:** stop uv noise lines in agent shells
([#4592](#4592))
([9ba375c](9ba375c))
* **k8s:** delete gateway management bodies from spans
([#4551](#4551))
([b835d3c](b835d3c))
* **k8s:** set the kube context and namespace on devops pods
([#4514](#4514))
([9087b39](9087b39))
* **roadmap:** a refused spec after the archive is a plan defect
([#4549](#4549))
([1db29f7](1db29f7))
* **roadmap:** count and log the reason of a left-out stage item
([#4541](#4541))
([5600179](5600179))
* **roadmap:** default the step ceiling to twice the budget
([#4556](#4556))
([1dfb6c8](1dfb6c8))
* **roadmap:** explain --trace shows the argument digest
([#4526](#4526))
([c92195f](c92195f))
* **roadmap:** explain totals count dropped model events
([#4543](#4543))
([fe0e979](fe0e979))
* **roadmap:** give each eval verify run its own report file
([#4534](#4534))
([ad27f2d](ad27f2d))
* **roadmap:** one event loop and a time limit for decide_all
([#4585](#4585))
([ec51e01](ec51e01))
* **roadmap:** scoped updates send requests with no row scope
([#4531](#4531))
([5f75d25](5f75d25))
* **roadmap:** the caller gate reads an added parameter span
([#4548](#4548))
([1ba07c1](1ba07c1))
* **roadmap:** the implement shell waits for its command
([#4536](#4536))
([571e044](571e044))
* **roadmap:** the module-test and caller gates read imports and calls
([#4490](#4490))
([8a22e82](8a22e82))
* **service:** put trace ids on Service JSON log lines
([#4511](#4511))
([0d7a0d2](0d7a0d2))


### Performance Improvements

* **ai:** keep intake embeddings between CLI runs
([#4546](#4546))
([812871e](812871e))
* **roadmap:** intake reads only the issues that changed
([#4552](#4552))
([7dfd155](7dfd155))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(k8s): export gateway spans without key metadata

1 participant