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]

test_traceparent_not_added_by_default

Ishaan Jaffd12578e4eacf
diff --git a/litellm/tests/test_proxy_utils.py b/litellm/tests/test_proxy_utils.py
index aea81b0173b..30a1aac5cec 100644
--- a/litellm/tests/test_proxy_utils.py
+++ b/litellm/tests/test_proxy_utils.py
@@ -1,9 +1,16 @@
import asyncio
+import os
+import sys
from unittest.mock import Mock
import pytest
from fastapi import Request
+import litellm
+
+sys.path.insert(
+ 0, os.path.abspath("../..")
+) # Adds the parent directory to the system path
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request
from litellm.types.utils import SupportedCacheControls
@@ -13,7 +20,7 @@ from litellm.types.utils import SupportedCacheControls
def mock_request(monkeypatch):
mock_request = Mock(spec=Request)
mock_request.query_params = {} # Set mock query_params to an empty dictionary
- mock_request.headers = {}
+ mock_request.headers = {"traceparent": "test_traceparent"}
monkeypatch.setattr(
"litellm.proxy.litellm_pre_call_utils.add_litellm_data_to_request", mock_request
)
@@ -60,3 +67,38 @@ async def test_add_litellm_data_to_request_non_thread_endpoint(endpoint, mock_re
assert "metadata" in data
assert "litellm_metadata" not in data
+
+
+# test adding traceparent
+
+
+ "endpoint", ["/chat/completions", "/v1/completions", "/completions"]
+)
+async def test_traceparent_not_added_by_default(endpoint, mock_request):
+ """
+ This tests that traceparent is not forwarded in the extra_headers
+
+ We had an incident where bedrock calls were failing because traceparent was forwarded
+ """
+ from litellm.integrations.opentelemetry import OpenTelemetry
+
+ otel_logger = OpenTelemetry()
+ setattr(litellm.proxy.proxy_server, "open_telemetry_logger", otel_logger)
+
+ mock_request.url.path = endpoint
+ user_api_key_dict = UserAPIKeyAuth(
+ api_key="test_api_key", user_id="test_user_id", org_id="test_org_id"
+ )
+ proxy_config = Mock()
+
+ data = {}
+ await add_litellm_data_to_request(
+ data, mock_request, user_api_key_dict, proxy_config
+ )
+
+ print("DATA: ", data)
+
+ _extra_headers = data.get("extra_headers") or {}
+ assert "traceparent" not in _extra_headers