Skip to content

fix(k8s): delete gateway management bodies from spans #4539

Closed

Description

@dan-petty

Problem Description

The transform/key_data processor in k8s/otel/values.yaml (#4518, PR #4520) does not delete the request bodies of LiteLLM management-endpoint spans. Some of these bodies can hold a raw virtual key or a callback secret. Tempo can thus store key data from the gateway.

The gateway (ghcr.io/berriai/litellm:v1.103.10, callbacks: ["otel"], no LITELLM_OTEL_V2) uses the legacy OpenTelemetry logger. For each management endpoint that has an http_request argument, _emit_management_endpoint_otel_span (litellm/proxy/management_helpers/utils.py) reads the parsed request body. The success hook and the failure hook (litellm/integrations/opentelemetry.py, lines 3390 and 3448) write one span attribute request.<field> for each body field. _CREDENTIAL_FIELDS filters only the response, not the request body.

Affected attributes:

  • request.key on /key/block and /key/unblock (BlockKeyRequest.key). The docstring says that this value can be the unhashed key (sk-...).
  • request.callback_vars on /team/{team_id}/callback (dict[str, str] of callback secrets).

The present rules do not match these names: ^metadata[.](user_api_key_|requester_custom_headers) and (?i)(authorization|api[-_]?key) do not match request.key or request.callback_vars. A raw sk- key is not 64-digit hex, so replace_all_patterns does not mask it. The gate check GATEWAY_KEY_ATTRIBUTES (tests/gate/k8s_checks/otel_collector.py) does not list these attributes, so the k8s row does not find the gap.

The path is latent: the review found no request.* span attribute in Tempo since 2026-11-11T00:00Z. The gateway keeps virtual keys in its database (k8s/README.md), so an operator call to /key/block or a team callback set-up writes the data.

Reproduction Steps

  1. Read litellm/proxy/management_helpers/utils.py (_emit_management_endpoint_otel_span) and litellm/integrations/opentelemetry.py (async_management_endpoint_success_hook) of LiteLLM v1.103.10.
  2. Send a /key/block request with body {"key": "sk-example"} to the gateway.
  3. Find the /key/block span in Tempo. It has the attribute request.key with the value sk-example.

Without the cluster: add "request.key": "sk-example" and "request.callback_vars": '{"langfuse_secret_key": "example"}' to GATEWAY_KEY_ATTRIBUTES and run the k8s row of devops ci. The check fails.

Expected vs Actual Behavior

Expected: the Collector deletes every gateway span attribute that can hold key data before the Tempo exporter.

Actual: request.key and request.callback_vars of management spans go to Tempo unchanged.

Proposed Fix

Use one deny rule by prefix, not one rule for each field. Traces do not need management request or response bodies. Only the management hooks write request.* and response.* attributes in LiteLLM v1.103.10, so the rule removes no model, route, token or error attribute.

  1. In transform/key_data, add one span statement: delete_matching_keys(span.attributes, "^(request|response)[.]") where resource.attributes["service.name"] == "llm-gateway".
  2. Add request.key (raw sk- value), request.callback_vars and one response.* field to GATEWAY_KEY_ATTRIBUTES, so that the k8s row fails if this path comes back.
  3. Extend the requirement "The Collector deletes gateway key data before Tempo" in openspec/specs/llm-telemetry-content/spec.md to cover management request and response bodies.

Environment Diagnostics

  • Gateway: LiteLLM v1.103.10, legacy OTel logger.
  • Collector: OpenTelemetry Collector contrib v0.161.0, transform/key_data with error_mode: propagate.

Logs, Traces, or Terminal Output

Source review of LiteLLM v1.103.10 (litellm/proxy/management_endpoints/key_management_endpoints.py: block_key and unblock_key take http_request; team_callback_endpoints.py: add_team_callbacks takes http_request).

Source: #4520

Proposed design

Problem statement

The transform/key_data processor leaves the request and response bodies of LiteLLM management endpoints on gateway spans: a /key/block call can write a raw sk- key to Tempo as request.key, and a team callback can write callback secrets as request.callback_vars. The k8s gate lists neither attribute, and its statement reader cannot read a pattern that holds a group together with a where clause, so it would reject the prefix rule that fixes the leak. Add one gateway-scoped prefix deny rule, guard it in the gate fixtures and the reader, and record it in the spec, the processor comment and the gateway telemetry docs.

Acceptance criteria

Requirement: Gateway management bodies deleted

The traces pipeline of the Collector SHALL delete every span attribute whose name starts with request. or response. on a span whose service.name is llm-gateway.

Scenario: Gateway management span loses its bodies

  • WHEN The k8s row applies the statements of transform/key_data to a llm-gateway span with request.key sk-example, request.callback_vars, response.callback_vars and the kept model attributes.
  • THEN The span keeps no attribute whose name starts with request. or response., and it keeps gen_ai.request.model, http.route, gen_ai.usage.input_tokens and error.type.

Requirement: Other services keep request attributes

The prefix deny rule SHALL apply only to a span whose service.name is llm-gateway.

Scenario: devops-cli span keeps a request attribute

  • WHEN The k8s row applies the statements to a devops-cli span with request.key sk-example and review.digest.
  • THEN The span keeps request.key sk-example and review.digest.

Requirement: Gate check reads a grouped pattern

The statement reader of the k8s gate check SHALL read a delete_matching_keys statement whose quoted pattern holds a group and whose where clause names the gateway.

Scenario: Grouped pattern with a where clause

  • WHEN The k8s row reads delete_matching_keys(span.attributes, "^(request|response)[.]") where resource.attributes["service.name"] == "llm-gateway" from k8s/otel/values.yaml.
  • THEN The check applies the pattern ^(request|response)[.] to the gateway span and raises no the check does not read assertion.

Requirement: Gate fixture covers management bodies

GATEWAY_KEY_ATTRIBUTES in the k8s gate check SHALL include request.key with a raw sk- value, request.callback_vars with a callback secret, and response.callback_vars.

Scenario: Gate fixture holds the management attributes

  • WHEN The k8s row reads GATEWAY_KEY_ATTRIBUTES.
  • THEN The mapping holds request.key sk-example, request.callback_vars with langfuse_secret_key, and response.callback_vars.

Requirement: Spec covers management bodies

The llm-telemetry-content spec SHALL state that the Collector deletes the gateway management request.* and response.* span attributes before Tempo.

Scenario: Spec names the management bodies

  • WHEN A reader opens the requirement The Collector deletes gateway key data before Tempo.
  • THEN The requirement names the request.* and response.* management body attributes, and a scenario checks that a gateway span loses them while a devops-cli span keeps request.key.

Requirement: Processor comment names management bodies

The comment of transform/key_data in k8s/otel/values.yaml SHALL name the management request.* and response.* body attributes beside the other key rules.

Scenario: Processor comment names the bodies

  • WHEN A reader opens k8s/otel/values.yaml at transform/key_data.
  • THEN The comment names the management request and response bodies, the raw key of /key/block and the gateway condition.

Requirement: Gateway docs name management bodies

The Gateway spans paragraph of k8s/README.md SHALL state that the Collector deletes the management request.* and response.* span attributes of the gateway.

Scenario: README names the management bodies

  • WHEN A reader opens the Gateway spans paragraph of k8s/README.md.
  • THEN The paragraph names the management request and response body attributes beside the existing key attributes and the 64-digit hash rule.

Existing Tool Considered

No alternatives check has run. The OpenTelemetry Collector Contrib transform processor with the OTTL delete_matching_keys function (contrib v0.161.0, k8s/otel/values.yaml:83-94) is open, maintained and already in the traces pipeline. It covers the need and lacks only the ^(request|response)[.] pattern, which this change adds. No new runtime code is built; the project's own gate check only needs its statement reader to read quoted arguments so that it can read the new pattern.

Key questions

  • Which OTTL statement removes the management request and response bodies from gateway spans?: Add one span statement to transform/key_data: delete_matching_keys(span.attributes, "^(request|response)[.]") where resource.attributes["service.name"] == "llm-gateway". The service condition keeps the rule off every other service. (best practice) [sources: k8s/otel/values.yaml:88, k8s/otel/values.yaml:90, tests/gate/k8s_checks/otel_collector.py:31]
    • Chosen: One prefix deny rule on gateway spans. It removes every current and future request.* and response.* field, and the service condition keeps other spans.
    • Rejected: One rule for each known field. It misses a new management field and needs an edit for each endpoint.
    • Rejected: One prefix deny rule for all services. request.* and response.* are generic HTTP names that another service's instrumentation can write, while only the LiteLLM management hooks write them here.
    • Rejected: A regex on values. replace_all_patterns rewrites a value but cannot delete an attribute, and a raw sk- key is not a 64-digit hex value.
  • Does the prefix deny rule need a statement for span events?: No. Add a span statement only. The management hooks write the request body as span attributes, and an event-context statement cannot remove a span attribute; the spanevent group keeps its refused-key hash rule. (best practice) [sources: k8s/otel/values.yaml:79, k8s/otel/values.yaml:91, openspec/changes/archive/2026-11-11-4518-export-gateway-spans-without-key-metadata/design.md:7]
    • Chosen: Span statement only. The affected attributes are span attributes, and the processor comment and the archived design record why the two contexts are separate groups.
    • Rejected: Span and span event statements. An event statement runs on the exception event, not on the span, so it removes none of the management body attributes and adds a statement with no effect.
  • Can the k8s gate check read the new statement as written?: No. _STATEMENT reads the arguments with a greedy .* and backtracks only to the last ) before a where clause, so the ) of (request|response) makes the fullmatch fail and the check raises the check does not read. Read the arguments as a comma-separated list of double-quoted strings in tests/gate/k8s_checks/otel_collector.py. (best practice) [sources: tests/gate/k8s_checks/otel_collector.py:73, tests/gate/k8s_checks/otel_collector.py:105, k8s/otel/values.yaml:90]
    • Chosen: Read the quoted arguments. It accepts any pattern the rule needs, including a group, and still fails on a function, a context or an argument form the check does not know.
    • Rejected: Make the .* non-greedy. It stops at the first ) and only succeeds because the where group forces a longer match; it still reads arbitrary text as an argument.
    • Rejected: Drop the group from the OTTL pattern. ^request[.]|^response[.] fits the rule to a reader limitation and breaks again on the next grouped pattern.
    • Rejected: Leave the reader unchanged. The k8s row raises the check does not read on the new statement, so the change cannot pass CI.
  • Which gate attributes prove the management body path?: Add request.key sk-example, request.callback_vars {"langfuse_secret_key": "example"} and response.callback_vars to GATEWAY_KEY_ATTRIBUTES. (best practice) [sources: tests/gate/k8s_checks/otel_collector.py:31, tests/gate/k8s_checks/otel_collector.py:173]
    • Chosen: request.key, request.callback_vars and response.callback_vars. It covers the raw key, the callback secret, and both branches of the prefix rule with one field name on each side.
    • Rejected: Only request.key and request.callback_vars. No fixture exercises response.*, so a rule that misses the second branch still passes.
    • Rejected: A synthetic response.example. It names a field that a management response does not hold, while the same field on both prefixes proves the alternation covers each side.
  • Should the gate test prove that a non-gateway span keeps a request.* attribute?: Yes. Add request.key sk-example to OTHER_SERVICE_ATTRIBUTES and keep it in the expected devops-cli span. (best practice) [sources: tests/gate/k8s_checks/otel_collector.py:64, tests/gate/k8s_checks/otel_collector.py:180]
    • Chosen: Add request.key to the devops-cli span. It tests the service condition, not only the deletion; a missing condition would delete the attribute and fail the check.
    • Rejected: Test only gateway spans. A rule without the service condition would pass, and every service would lose its request.* attributes.
  • How do the spec and the docs record the management body rule?: Extend the requirement The Collector deletes gateway key data before Tempo in openspec/specs/llm-telemetry-content/spec.md to name the gateway management request.* and response.* span attributes and add a scenario for them, and name the rule in the Gateway spans paragraph of k8s/README.md and in the comment of transform/key_data. (best practice) [sources: openspec/specs/llm-telemetry-content/spec.md:55, k8s/README.md:176, k8s/otel/values.yaml:73]
    • Chosen: Extend the existing requirement, README paragraph and processor comment. One requirement keeps the Collector key rule in one place, and both prose passages describe the same processor, so they must name the new rule.
    • Rejected: Add a separate requirement. It splits one processor rule across two requirements.
    • Rejected: Change only the code and the gate. The spec, the README and the processor comment would describe a rule that no longer matches the processor.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/k8s
    status/new
    value/high
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/k8s. The (k8s) scope of the title gives the scope.
    • Priority: P1-High. Raw API keys and callback secrets can be stored in Tempo, which is a security gap even though the path is currently latent.
    • Value: High. It prevents raw virtual keys and callback secrets from reaching Tempo, protecting operator credentials.
    • Effort: Low. The fix adds one span delete rule, three gate-check entries, and one spec sentence.
    • Related: feat(k8s): export gateway spans without key metadata #4518, which asks for a different change. Both items deal with gateway span key-data filtering in the transform/key_data processor, but #4518 covers model and route attributes while the candidate adds management-endpoint request and response body deletion.
  3. added
    priority/p1-high
    owner/agent
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

  6. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 11, 2026
  7. added a commit that references this issue on Nov 11, 2026
    c6c1646
  8. removed
    status/in-review
    owner/agent
    on Nov 11, 2026
  9. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 14:13 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p1-highscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions