fix(otel): configurable baggage, pass-through + service spans, typed guardrails - #29263
Merged
yassin-berriai merged 1 commit intoMay 29, 2026
Conversation
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
yassin-berriai
changed the base branch from
litellm_internal_staging
to
litellm_fix/kind-ptolemy-CNozr
May 29, 2026 06:03
yassin-berriai
changed the base branch from
litellm_fix/kind-ptolemy-CNozr
to
litellm_fix/export_server_otel_span
May 29, 2026 06:03
yassin-berriai
changed the base branch from
litellm_fix/export_server_otel_span
to
litellm_fix/kind-ptolemy-CNozr
May 29, 2026 06:04
…guardrails - Baggage allowlists are configurable via LITELLM_OTEL_BAGGAGE_PROMOTED_KEYS / LITELLM_OTEL_BAGGAGE_METADATA_KEYS env vars (comma-separated) and via callback_settings.otel.* in config.yaml, instead of being hard-coded. - Pass-through LLM-call spans now nest under the proxy server span: the proxy threads the server span as litellm_parent_otel_span and the adapter falls back to it when the ambient context (a detached logging task) has lost it. - Service spans (Redis/Postgres) now emit under LITELLM_OTEL_V2: the service logger dispatch recognizes the V2 OpenTelemetryV2 logger, which is a plain CustomLogger and not a subclass of the legacy OpenTelemetry. - Guardrail span data is built from the typed, provider-agnostic StandardLoggingGuardrailInformation (normalizing enum/list guardrail_mode and adding guardrail_id / policy_template / detection_method) instead of assuming one provider's field shape.
yassin-berriai
force-pushed
the
claude/litellm-tracing-config-Sh4Lz
branch
from
May 29, 2026 15:35
d2986fd to
f7bcd08
Compare
yassin-berriai
merged commit May 29, 2026
f7bcd08
into
litellm_fix/kind-ptolemy-CNozr
43 of 45 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #28909 (typed semconv-aligned OpenTelemetry V2 instrumentation). This branch carries that work plus fixes for four problems found in it. All changes stay gated behind
LITELLM_OTEL_V2.1. Baggage allowlists are configurable (not hard-coded)
baggage_promoted_keys/baggage_metadata_keyspreviously had no env or config wiring. They are now configurable two ways:LITELLM_OTEL_BAGGAGE_PROMOTED_KEYS,LITELLM_OTEL_BAGGAGE_METADATA_KEYS. ANoDecode+field_validator(mode="before")lets a plaina,b,cstring parse into a list (pydantic-settings would otherwise demand JSON).callback_settings.otel.baggage_promoted_keys(a YAML list). These reach the config because theOpenTelemetryV2constructor now buildsOpenTelemetryV2Config(**kwargs)from the settings passed through.2. Pass-through LLM-call span no longer missing
Pass-through endpoints dispatch their logging from a detached
asyncio.create_taskwhose copied OTel context may no longer carry the server span, so the LLM-call span was dropped / orphaned. Fix:litellm_parent_otel_spanin request metadata (matching what normal proxy routes already do)._emit_llm_callfalls back to that explicitly-threaded parent span when the ambient context has no recordable span. The normal path (ambient server span present) is unchanged.3. Service spans no longer always missing
litellm/_service_logger.pyonly dispatched to loggers that were instances of the legacyOpenTelemetry. The V2OpenTelemetryV2is a plainCustomLogger, so it never matched and Redis/Postgres service spans were always dropped. The dispatch now resolves both the legacy and V2 OTel loggers (via a lazily-imported, SDK-optional helper), whether registered as an instance or as the"otel"string.4. Guardrail span data is typed and provider-agnostic
GuardrailSpanData.from_logging_entrywas untyped (Mapping[str, object]) and read ad-hoc bare keys (name/status/mode) that match no single schema. It now:StandardLoggingGuardrailInformationand reads only its canonical, provider-agnostic keys.guardrail_mode(aGuardrailEventHooksenum, a list of them, or aGuardrailMode) to a stable string — e.g."pre_call", not"GuardrailEventHooks.pre_call", and joins multiple modes.guardrail_id,policy_template,detection_methodas span attributes.Tests
tests/test_litellm/integrations/otel/test_otel_v2_config_fixes.py— baggage env/config wiring, pass-through threaded-parent fallback (and ambient-wins precedence), guardrail mode normalization + typed metadata mapping.tests/test_litellm/test_service_logger.py— V2 logger is recognized by the service-span dispatch (instance,"otel"string, unrelated-callback no-op) and an end-to-end service span is emitted.tests/test_litellm/integrations/otel/suite passes;ruff/mypy/blackclean on the changed files.Generated by Claude Code