Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(otel): accept UPPER_SNAKE_CASE OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT in v2 (#30562)

Yassin Kortam27c1dfbdc757
diff --git a/litellm/integrations/otel/model/config.py b/litellm/integrations/otel/model/config.py
index ca46182bc66..4f7c3277ebb 100644
--- a/litellm/integrations/otel/model/config.py
+++ b/litellm/integrations/otel/model/config.py
@@ -184,6 +184,20 @@ class OpenTelemetryV2Config(BaseSettings):
),
)
+ @field_validator("capture_message_content", mode="before")
+ @classmethod
+ def _normalize_capture_message_content(cls, value: object) -> object:
+ """Fold the capture mode to its canonical lower_snake_case form.
+
+ V1 read this env var case-insensitively, so operators set the
+ UPPER_SNAKE_CASE form (e.g. ``SPAN_AND_EVENT``). The canonical values
+ here are lower_snake_case; normalizing at the boundary keeps both
+ spellings working and lets every downstream comparison stay exact.
+ """
+ if isinstance(value, str):
+ return value.lower()
+ return value
+
@field_validator(
"baggage_promoted_keys",
"baggage_metadata_keys",
diff --git a/tests/test_litellm/integrations/otel/test_otel_v2_sources_of_truth.py b/tests/test_litellm/integrations/otel/test_otel_v2_sources_of_truth.py
index 20824ca09e6..3447f5bdb7e 100644
--- a/tests/test_litellm/integrations/otel/test_otel_v2_sources_of_truth.py
+++ b/tests/test_litellm/integrations/otel/test_otel_v2_sources_of_truth.py
@@ -528,6 +528,35 @@ def test_capture_span_content_resolves_modes():
).capture_span_content
is False
)
+ # V1 accepted UPPER_SNAKE_CASE; the env value is case-insensitive so an
+ # operator carrying ``SPAN_AND_EVENT`` forward still enables capture.
+ assert (
+ OpenTelemetryV2Config(
+ capture_message_content="SPAN_AND_EVENT"
+ ).capture_span_content
+ is True
+ )
+ assert (
+ OpenTelemetryV2Config(capture_message_content="SPAN_ONLY").capture_span_content
+ is True
+ )
+ assert (
+ OpenTelemetryV2Config(capture_message_content="NO_CONTENT").capture_span_content
+ is False
+ )
+
+
+def test_capture_message_content_normalizer_only_touches_strings():
+ """The casing normalizer lower-cases strings and leaves anything else
+ untouched, so a non-string value still fails the field's ``str`` validation
+ instead of being silently coerced into a bogus capture mode."""
+ import pytest
+ from pydantic import ValidationError
+
+ from litellm.integrations.otel.model.config import OpenTelemetryV2Config
+
+ with pytest.raises(ValidationError):
+ OpenTelemetryV2Config(capture_message_content=123)
def test_v2_flag_is_off_by_default(monkeypatch):