Skip to content

Commit 977290e

Browse files
author
Liudmila Molkova
committed
review comments
1 parent 67fb151 commit 977290e

File tree

2 files changed

+6
-16
lines changed
  • instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2

2 files changed

+6
-16
lines changed

instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def traced_method(wrapped, instance, args, kwargs):
5454
if span.is_recording():
5555
for message in kwargs.get("messages", []):
5656
event_logger.emit(
57-
message_to_event(
58-
message, span.get_span_context(), capture_content
59-
)
57+
message_to_event(message, capture_content)
6058
)
6159

6260
try:
@@ -95,11 +93,7 @@ def _set_response_attributes(
9593
if getattr(result, "choices", None):
9694
choices = result.choices
9795
for choice in choices:
98-
event_logger.emit(
99-
choice_to_event(
100-
choice, span.get_span_context(), capture_content
101-
)
102-
)
96+
event_logger.emit(choice_to_event(choice, capture_content))
10397

10498
finish_reasons = []
10599
for choice in choices:
@@ -268,6 +262,8 @@ def cleanup(self):
268262
event_attributes = {
269263
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value
270264
}
265+
266+
# this span is not current, so we need to manually set the context on event
271267
span_ctx = self.span.get_span_context()
272268
self.event_logger.emit(
273269
Event(

instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def get_property_value(obj, property_name):
100100
return getattr(obj, property_name, None)
101101

102102

103-
def message_to_event(message, span_ctx, capture_content):
103+
def message_to_event(message, capture_content):
104104
attributes = {
105105
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value
106106
}
@@ -123,13 +123,10 @@ def message_to_event(message, span_ctx, capture_content):
123123
name=f"gen_ai.{role}.message",
124124
attributes=attributes,
125125
body=body if body else None,
126-
trace_id=span_ctx.trace_id,
127-
span_id=span_ctx.span_id,
128-
trace_flags=span_ctx.trace_flags,
129126
)
130127

131128

132-
def choice_to_event(choice, span_ctx, capture_content):
129+
def choice_to_event(choice, capture_content):
133130
attributes = {
134131
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value
135132
}
@@ -157,9 +154,6 @@ def choice_to_event(choice, span_ctx, capture_content):
157154
name="gen_ai.choice",
158155
attributes=attributes,
159156
body=body,
160-
trace_id=span_ctx.trace_id,
161-
span_id=span_ctx.span_id,
162-
trace_flags=span_ctx.trace_flags,
163157
)
164158

165159

0 commit comments

Comments
 (0)