diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index d9a78156f4b..c155092fdbd 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -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( diff --git a/tests/test_litellm/integrations/otel/test_otel_v2_destinations.py b/tests/test_litellm/integrations/otel/test_otel_v2_destinations.py index 30e067df9f9..d52183638b8 100644 --- a/tests/test_litellm/integrations/otel/test_otel_v2_destinations.py +++ b/tests/test_litellm/integrations/otel/test_otel_v2_destinations.py @@ -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