From 35937f57e7ae4141916c9450c1b62e35305829ad Mon Sep 17 00:00:00 2001 From: mrinal Date: Tue, 22 Sep 2026 23:19:25 +0000 Subject: [PATCH] refactor(otel v2): move the internal-spans sentinel and env var name to constants.py Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/constants.py | 5 +++++ litellm/integrations/otel/plumbing/context.py | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index e5b662bd515..7b18adc0688 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1677,6 +1677,11 @@ LITELLM_LOGGING_NO_UPSTREAM_LLM_CALL: Final = "litellm_no_upstream_llm_call" # the key's values after the team metadata merge so a key outranks its team). OTEL_SERVICE_NAME_METADATA_KEYS: Final = ("otel_service_name_override", "otel_service_name") +# ``litellm_settings: otel_tenant_internal_spans`` value (and its env equivalent) that +# keeps the proxy's own SERVICE and DB_CALL spans out of tenant OTel destinations. +OTEL_EXCLUDE_INTERNAL_SPANS: Final = "exclude" +OTEL_TENANT_INTERNAL_SPANS_ENV: Final = "LITELLM_OTEL_TENANT_INTERNAL_SPANS" + # Key Rotation Constants LITELLM_KEY_ROTATION_ENABLED: Final = os.getenv("LITELLM_KEY_ROTATION_ENABLED", "false") LITELLM_KEY_ROTATION_CHECK_INTERVAL_SECONDS: Final = int( diff --git a/litellm/integrations/otel/plumbing/context.py b/litellm/integrations/otel/plumbing/context.py index 506d79598eb..e6d94747f7d 100644 --- a/litellm/integrations/otel/plumbing/context.py +++ b/litellm/integrations/otel/plumbing/context.py @@ -20,6 +20,7 @@ from opentelemetry.trace.propagation.tracecontext import ( TraceContextTextMapPropagator, ) +from litellm.constants import OTEL_EXCLUDE_INTERNAL_SPANS, OTEL_TENANT_INTERNAL_SPANS_ENV from litellm.integrations.otel.model.semconv import HTTP from litellm.types.utils import OtelInternalSpans @@ -401,10 +402,6 @@ def tenant_destinations_are_additive() -> bool: return isinstance(configured, str) and configured.strip().lower() == ADDITIVE_DESTINATION_MODE -EXCLUDE_INTERNAL_SPANS: Final = "exclude" -OTEL_TENANT_INTERNAL_SPANS_ENV: Final = "LITELLM_OTEL_TENANT_INTERNAL_SPANS" - - def tenant_internal_spans_default() -> OtelInternalSpans: """The ``internal_spans`` a tenant destination gets when its own callback vars name none. @@ -414,7 +411,7 @@ def tenant_internal_spans_default() -> OtelInternalSpans: import litellm configured: Final = litellm.otel_tenant_internal_spans or os.environ.get(OTEL_TENANT_INTERNAL_SPANS_ENV) - if isinstance(configured, str) and configured.strip().lower() == EXCLUDE_INTERNAL_SPANS: + if isinstance(configured, str) and configured.strip().lower() == OTEL_EXCLUDE_INTERNAL_SPANS: return "exclude" return "include"