From d2bae3313bba16c60abc8cbe75fbe7a640f47534 Mon Sep 17 00:00:00 2001 From: Ali Waleed Date: Mon, 2 Dec 2024 12:48:53 +0200 Subject: [PATCH] fix missing request attributes --- .../src/opentelemetry/instrumentation/openai_v2/patch.py | 4 +++- .../src/opentelemetry/instrumentation/openai_v2/utils.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py index cd284473ce..bbe9c4f01c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py @@ -30,6 +30,7 @@ is_streaming, message_to_event, set_span_attribute, + set_span_attributes, ) @@ -40,7 +41,6 @@ def chat_completions_create( def traced_method(wrapped, instance, args, kwargs): span_attributes = {**get_llm_request_attributes(kwargs, instance)} - span_name = f"{span_attributes[GenAIAttributes.GEN_AI_OPERATION_NAME]} {span_attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL]}" with tracer.start_as_current_span( name=span_name, @@ -48,6 +48,7 @@ def traced_method(wrapped, instance, args, kwargs): attributes=span_attributes, end_on_exit=False, ) as span: + set_span_attributes(span, span_attributes) if span.is_recording(): for message in kwargs.get("messages", []): event_logger.emit( @@ -90,6 +91,7 @@ async def traced_method(wrapped, instance, args, kwargs): attributes=span_attributes, end_on_exit=False, ) as span: + set_span_attributes(span, span_attributes) if span.is_recording(): for message in kwargs.get("messages", []): event_logger.emit( diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py index cf920c17ee..c513bfd24a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py @@ -164,7 +164,7 @@ def choice_to_event(choice, capture_content): def set_span_attributes(span, attributes: dict): - for field, value in attributes.model_dump(by_alias=True).items(): + for field, value in attributes.items(): set_span_attribute(span, field, value)