Addressed feedback where the newrelic options might not apply correctly.

This commit is contained in:
Josh Bonczkowski 2026-03-13 16:34:49 -04:00
parent 1688fd496a
commit 24c20be337
2 changed files with 20 additions and 2 deletions

View file

@ -51,7 +51,6 @@ from litellm.integrations.custom_logger import CustomLogger
from litellm.types.integrations.newrelic import NewRelicInitParams
from litellm.types.utils import ModelResponse, Message
# Global state for supportability metric emission
# Protected by _metric_lock to ensure thread-safe access
_last_metric_emission_time: float = 0.0
@ -72,7 +71,12 @@ class NewRelicLogger(CustomLogger):
# Handle newrelic_params set as litellm.newrelic_params
#########################################################
dict_newrelic_params = self._get_newrelic_params()
kwargs.update(dict_newrelic_params)
# Use setdefault so constructor kwargs take priority over global params.
# model_dump() always returns all fields (including defaults), so update()
# would silently overwrite explicit constructor args like turn_off_message_logging=True.
for k, v in dict_newrelic_params.items():
kwargs.setdefault(k, v)
# CustomLogger.__init__ will set self.turn_off_message_logging from kwargs
super().__init__(**kwargs)

View file

@ -163,6 +163,20 @@ class TestNewRelicLoggerInit:
logger = NewRelicLogger(turn_off_message_logging=False)
assert logger.record_content is False
def test_constructor_kwargs_take_priority_over_global_params(self):
"""Constructor turn_off_message_logging=True must not be overwritten by
litellm.newrelic_params which defaults turn_off_message_logging to False."""
from litellm.types.integrations.newrelic import NewRelicInitParams
with patch("newrelic.agent.register_application"):
with patch.dict(os.environ, NR_ENV):
with patch(
"litellm.newrelic_params",
NewRelicInitParams(turn_off_message_logging=False),
):
logger = NewRelicLogger(turn_off_message_logging=True)
assert logger.record_content is False
# ---------------------------------------------------------------------------
# 2. _parse_bool_env