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]

(Bug fix) dd-trace used by default on litellm proxy (#8817)

Ishaan Jaff7021f2f24490
diff --git a/litellm/litellm_core_utils/dd_tracing.py b/litellm/litellm_core_utils/dd_tracing.py
index 4df3026144a..4b33b2c4239 100644
--- a/litellm/litellm_core_utils/dd_tracing.py
+++ b/litellm/litellm_core_utils/dd_tracing.py
@@ -6,10 +6,22 @@ If the ddtrace package is not installed, the tracer will be a no-op.
from contextlib import contextmanager
+from litellm.secret_managers.main import get_secret_bool
+
+
+def _should_use_dd_tracer():
+ """
+ Returns True if `USE_DDTRACE` is set to True in .env
+ """
+ return get_secret_bool("USE_DDTRACE", False) is True
+
+
+has_ddtrace = False
try:
from ddtrace import tracer as dd_tracer
- has_ddtrace = True
+ if _should_use_dd_tracer():
+ has_ddtrace = True
except ImportError:
has_ddtrace = False
diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml
index a8479264e9d..f603d5946fa 100644
--- a/litellm/proxy/proxy_config.yaml
+++ b/litellm/proxy/proxy_config.yaml
@@ -9,10 +9,3 @@ model_list:
general_settings:
store_model_in_db: true
-
-litellm_settings:
- cache: true
- cache_params:
- type: redis
- ttl: 600
- redis_startup_nodes: [{"host": "127.0.0.1", "port": "7100"}]
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index b5db78ef880..7f2d7d4f11f 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -3388,7 +3388,9 @@ class ProxyStartupEvent:
DD tracer is used to trace Python applications.
Doc: https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/python/
"""
- if get_secret_bool("USE_DDTRACE", False) is True:
+ from litellm.litellm_core_utils.dd_tracing import _should_use_dd_tracer
+
+ if _should_use_dd_tracer():
import ddtrace
ddtrace.patch_all(logging=True, openai=False)
diff --git a/tests/litellm/litellm_core_utils/test_dd_tracing.py b/tests/litellm/litellm_core_utils/test_dd_tracing.py
index 0492295071d..75318c83ab7 100644
--- a/tests/litellm/litellm_core_utils/test_dd_tracing.py
+++ b/tests/litellm/litellm_core_utils/test_dd_tracing.py
@@ -9,7 +9,7 @@ sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
-from litellm.litellm_core_utils.dd_tracing import dd_tracer
+from litellm.litellm_core_utils.dd_tracing import _should_use_dd_tracer, dd_tracer
def test_dd_tracer_when_package_exists():
@@ -51,3 +51,22 @@ def test_null_tracer_context_manager():
# Test that we can call methods on the null span
span.finish()
assert True # If we get here without exceptions, the test passes
+
+
+def test_should_use_dd_tracer():
+ with patch(
+ "litellm.litellm_core_utils.dd_tracing.get_secret_bool"
+ ) as mock_get_secret:
+ # Test when USE_DDTRACE is True
+
+ mock_get_secret.return_value = True
+ assert _should_use_dd_tracer() is True
+ mock_get_secret.assert_called_once_with("USE_DDTRACE", False)
+
+ # Reset the mock for the next test
+ mock_get_secret.reset_mock()
+
+ # Test when USE_DDTRACE is False
+ mock_get_secret.return_value = False
+ assert _should_use_dd_tracer() is False
+ mock_get_secret.assert_called_once_with("USE_DDTRACE", False)