fix(otel): avoid console export without operator destination

This commit is contained in:
Yucheng He 2026-09-05 08:01:09 -07:00
parent 9e3d9dc466
commit 88526c39c6
2 changed files with 20 additions and 0 deletions

View file

@ -4836,8 +4836,13 @@ def _maybe_construct_otel_v2(callback_name: str, _in_memory_loggers: list[Custom
# so customers get the same error story they had before V2 landed.
return None
gated: Final = _is_credential_gated(built)
has_operator_exporter: Final = any(
not _is_gated(spec) and bool(spec.model_dump(exclude_defaults=True)) for spec in built.exporters
)
if _exports_nowhere(built) and not (serves_a_destination and has_v2_logger):
return None
if gated and not has_operator_exporter 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(

View file

@ -1174,6 +1174,21 @@ class TestPresetDegradation:
"https://otlp.nr-data.net",
]
def test_a_credentialless_newrelic_without_a_base_exporter_falls_back(self, monkeypatch, capsys):
from litellm.litellm_core_utils.litellm_logging import _maybe_construct_otel_v2
monkeypatch.delenv("NEW_RELIC_LICENSE_KEY", raising=False)
for name in _OTEL_SHORTHAND_ENV:
monkeypatch.delenv(name, raising=False)
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 None
assert capsys.readouterr().out == ""
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