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(logging): add litellm_call_id to StandardLoggingPayload and OTel span (#26133)

ishaan-berri8a4a775b1ba9
diff --git a/litellm/integrations/opentelemetry.py b/litellm/integrations/opentelemetry.py
index ecfb42cea7b..7ff360758e8 100644
--- a/litellm/integrations/opentelemetry.py
+++ b/litellm/integrations/opentelemetry.py
@@ -1615,6 +1615,14 @@ class OpenTelemetry(CustomLogger):
value=response_id,
)
+ litellm_call_id = standard_logging_payload.get("litellm_call_id")
+ if litellm_call_id:
+ self.safe_set_attribute(
+ span=span,
+ key="litellm.call_id",
+ value=litellm_call_id,
+ )
+
# The model used to generate the response.
if response_obj and response_obj.get("model"):
self.safe_set_attribute(
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py
index fd14f55add3..625cb83724b 100644
--- a/litellm/litellm_core_utils/litellm_logging.py
+++ b/litellm/litellm_core_utils/litellm_logging.py
@@ -5512,6 +5512,8 @@ def get_standard_logging_object_payload(
payload: StandardLoggingPayload = StandardLoggingPayload(
id=str(id),
+ litellm_call_id=kwargs.get("litellm_call_id")
+ or litellm_params.get("litellm_call_id"),
trace_id=StandardLoggingPayloadSetup._get_standard_logging_payload_trace_id(
logging_obj=logging_obj,
litellm_params=litellm_params,
diff --git a/litellm/types/utils.py b/litellm/types/utils.py
index 4fe4b124da9..e3058d106a6 100644
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@ -2851,6 +2851,7 @@ class StandardAuditLogPayload(TypedDict):
class StandardLoggingPayload(TypedDict):
id: str
trace_id: str # Trace multiple LLM calls belonging to same overall request (e.g. fallbacks/retries)
+ litellm_call_id: Optional[str] # UUID returned in x-litellm-call-id response header
call_type: str
stream: Optional[bool]
response_cost: float
diff --git a/tests/logging_callback_tests/test_otel_logging.py b/tests/logging_callback_tests/test_otel_logging.py
index fdb333899cc..ea1c884c324 100644
--- a/tests/logging_callback_tests/test_otel_logging.py
+++ b/tests/logging_callback_tests/test_otel_logging.py
@@ -253,6 +253,7 @@ def validate_redacted_message_span_attributes(span):
or attr.startswith("gen_ai.cost.")
or attr.startswith("gen_ai.operation.")
or attr.startswith("gen_ai.request.")
+ or attr.startswith("litellm.")
), f"Non-metadata attribute found: {attr}"
pass
diff --git a/tests/test_litellm/integrations/test_opentelemetry.py b/tests/test_litellm/integrations/test_opentelemetry.py
index 725836e1340..e723298b1c9 100644
--- a/tests/test_litellm/integrations/test_opentelemetry.py
+++ b/tests/test_litellm/integrations/test_opentelemetry.py
@@ -2752,3 +2752,26 @@ class TestResponseIdFallback(unittest.TestCase):
mock_span.set_attribute.assert_any_call(
"gen_ai.response.id", "litellm-img-call-101"
)
+
+ def test_litellm_call_id_emitted_as_span_attribute(self):
+ """litellm.call_id must be set on the span from standard_logging_payload."""
+ otel = OpenTelemetry()
+ mock_span = MagicMock()
+
+ call_id = "my-litellm-call-uuid-456"
+ kwargs = {
+ "model": "gpt-4o",
+ "optional_params": {},
+ "litellm_params": {"custom_llm_provider": "openai"},
+ "standard_logging_object": {
+ "id": "chatcmpl-provider-id",
+ "litellm_call_id": call_id,
+ "call_type": "completion",
+ "metadata": {},
+ },
+ }
+ response_obj = {"id": "chatcmpl-provider-id", "model": "gpt-4o"}
+
+ otel.set_attributes(mock_span, kwargs, response_obj)
+
+ mock_span.set_attribute.assert_any_call("litellm.call_id", call_id)
diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py
index c3849e5869a..cf7be6bf1c7 100644
--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py
+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py
@@ -2410,3 +2410,29 @@ def test_get_additional_headers_reset_fields_preserved():
assert result is not None
assert result["x_ratelimit_reset_requests"] == "1s" # type: ignore
assert result["x_ratelimit_reset_tokens"] == "100ms" # type: ignore
+
+
+# ── litellm_call_id propagation ───────────────────────────────────────────────
+
+
+def test_get_standard_logging_object_payload_includes_litellm_call_id(logging_obj):
+ """litellm_call_id from kwargs must appear in the returned StandardLoggingPayload."""
+ import datetime
+
+ from litellm.litellm_core_utils.litellm_logging import (
+ get_standard_logging_object_payload,
+ )
+
+ call_id = "test-call-id-abc-123"
+ now = datetime.datetime.now()
+ payload = get_standard_logging_object_payload(
+ kwargs={"litellm_call_id": call_id, "model": "gpt-4o", "messages": []},
+ init_response_obj={},
+ start_time=now,
+ end_time=now,
+ logging_obj=logging_obj,
+ status="success",
+ )
+
+ assert payload is not None
+ assert payload["litellm_call_id"] == call_id