Skip to content

Commit 0b1d9b9

Browse files
committed
Add comments to changes in instrumentation.
1 parent c9d0fe8 commit 0b1d9b9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

newrelic/hooks/mlmodel_openai.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ def _record_completion_success(transaction, linking_metadata, completion_id, kwa
496496
finish_reason = kwargs.get("finish_reason")
497497
if "content" in kwargs:
498498
output_message_list = [{"content": kwargs.get("content"), "role": kwargs.get("role")}]
499+
# When tools are involved, the content key may hold an empty string which we do not want to report
500+
# In this case, the content we are interested in capturing will already be covered in the input_message_list
501+
# We empty out the output_message_list so that we do not report an empty message
499502
if "tool_call" in finish_reason and not kwargs.get("content"):
500503
output_message_list = []
501504
request_model = kwargs.get("model") or kwargs.get("engine")
@@ -767,6 +770,9 @@ def _record_stream_chunk(self, return_val):
767770

768771
def _record_events_on_stop_iteration(self, transaction):
769772
if hasattr(self, "_nr_ft"):
773+
# We first check for our saved linking metadata before making a new call to get_trace_linking_metadata
774+
# Directly calling get_trace_linking_metadata() causes the incorrect span ID to be captured and associated with the LLM call
775+
# This leads to incorrect linking of the LLM call in the UI
770776
linking_metadata = self._nr_metadata or get_trace_linking_metadata()
771777
self._nr_ft.__exit__(None, None, None)
772778
try:

0 commit comments

Comments
 (0)