Addressing feedback for potential better practice.

This commit is contained in:
Josh Bonczkowski 2026-03-13 14:58:43 -04:00
parent 807b8ed72d
commit 37d8be3779

View file

@ -243,9 +243,9 @@ class NewRelicLogger(CustomLogger):
- span_id: str or None (only present if found in headers) - span_id: str or None (only present if found in headers)
""" """
try: try:
litellm_params = kwargs.get("litellm_params", {}) litellm_params = kwargs.get("litellm_params") or {}
metadata = litellm_params.get("metadata", {}) metadata = litellm_params.get("metadata") or {}
headers = metadata.get("headers", {}) headers = metadata.get("headers") or {}
traceparent = headers.get("traceparent", None) traceparent = headers.get("traceparent", None)
trace_id = None trace_id = None
@ -326,7 +326,7 @@ class NewRelicLogger(CustomLogger):
Returns "unknown" if choices are not present or finish_reason is not found. Returns "unknown" if choices are not present or finish_reason is not found.
""" """
choices = response_obj.get("choices", []) choices = response_obj.get("choices") or []
if choices and len(choices) > 0: if choices and len(choices) > 0:
return choices[0].get("finish_reason", "unknown") return choices[0].get("finish_reason", "unknown")
return "unknown" return "unknown"
@ -363,7 +363,7 @@ class NewRelicLogger(CustomLogger):
Returns dict with available parameters, omitting those not present. Returns dict with available parameters, omitting those not present.
""" """
optional_params = kwargs.get("optional_params", {}) optional_params = kwargs.get("optional_params") or {}
params = {} params = {}
temperature = optional_params.get("temperature") temperature = optional_params.get("temperature")
@ -431,7 +431,7 @@ class NewRelicLogger(CustomLogger):
end_time = kwargs.get("end_time") end_time = kwargs.get("end_time")
# Extract request messages # Extract request messages
request_messages = kwargs.get("messages", []) request_messages = kwargs.get("messages") or []
for msg in request_messages: for msg in request_messages:
message_data = { message_data = {
"role": msg.get("role", "user"), "role": msg.get("role", "user"),
@ -452,7 +452,7 @@ class NewRelicLogger(CustomLogger):
sequence += 1 sequence += 1
# Extract response messages from choices # Extract response messages from choices
choices = response_obj.get("choices", []) choices = response_obj.get("choices") or []
if choices and len(choices) > 0: if choices and len(choices) > 0:
for choice in choices: for choice in choices:
message = choice.get("message", None) message = choice.get("message", None)