fix(otel): preserve valid exporter beside gated preset

This commit is contained in:
Yucheng He 2026-09-05 07:40:38 -07:00
parent e5a9850409
commit 9e3d9dc466
2 changed files with 21 additions and 1 deletions

View file

@ -4835,7 +4835,10 @@ def _maybe_construct_otel_v2(callback_name: str, _in_memory_loggers: list[Custom
# If env vars are missing or the preset raises, defer to the legacy path
# so customers get the same error story they had before V2 landed.
return None
config: Final = _only_the_gated_exporter(built) if _is_credential_gated(built) else built
gated: Final = _is_credential_gated(built)
if _exports_nowhere(built) and not (serves_a_destination and has_v2_logger):
return None
config: Final = _only_the_gated_exporter(built) if gated and serves_a_destination and has_v2_logger else built
if _exports_nowhere(config):
verbose_logger.warning(
"OTel V2: no operator credentials for '%s'; only key/team destinations will receive its traces",

View file

@ -1157,6 +1157,23 @@ class TestPresetDegradation:
assert logger is None
def test_a_valid_newrelic_base_exporter_survives_without_a_license_key(self, monkeypatch):
from litellm.litellm_core_utils.litellm_logging import _maybe_construct_otel_v2
monkeypatch.delenv("NEW_RELIC_LICENSE_KEY", raising=False)
monkeypatch.setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector.local:4318")
monkeypatch.setenv("LITELLM_OTEL_V2", "true")
is_otel_v2_enabled.cache_clear()
logger = in_fresh_context(_maybe_construct_otel_v2, "newrelic", [])
is_otel_v2_enabled.cache_clear()
assert logger is not None
assert [spec.endpoint for spec in logger.config.exporters] == [
"http://collector.local:4318",
"https://otlp.nr-data.net",
]
def test_a_destination_for_one_backend_does_not_degrade_another(self, monkeypatch):
from litellm.litellm_core_utils.litellm_logging import _maybe_construct_otel_v2