diff --git a/instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/709.fixed b/instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/709.fixed new file mode 100644 index 000000000..12b04168a --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/709.fixed @@ -0,0 +1 @@ +Do not record `gen_ai.request.stream` on `fetch_response` spans. diff --git a/instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py b/instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py index 01ff3b0f1..18c185b1f 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py +++ b/instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py @@ -19,7 +19,6 @@ get_fetch_response_creation_kwargs, get_inference_creation_kwargs, get_response_error, - is_streamed_raw_response, set_fetch_response_attributes, set_invocation_response_attributes, ) @@ -215,11 +214,6 @@ def _start_fetch_response_invocation( ) -> FetchResponseInvocation: invocation = handler.fetch_response( **get_fetch_response_creation_kwargs(response_id, instance), - request_stream=( - True - if is_streaming(kwargs) or is_streamed_raw_response(kwargs) - else None - ), ) invocation.stream_cursor = _get_stream_cursor(kwargs) invocation.attributes[OpenAIAttributes.OPENAI_API_TYPE] = ( diff --git a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py index 30a86368c..bc7deac90 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py +++ b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py @@ -380,7 +380,6 @@ async def test_async_responses_retrieve_streaming( response_model=response.model, response_status="completed", finish_reasons=("stop",), - request_stream=True, stream_cursor=str(RETRIEVE_STREAM_CURSOR), response_service_tier=response.service_tier, ) @@ -455,7 +454,7 @@ async def test_async_responses_retrieve_with_streaming_response_stays_lazy( span.attributes[GenAIAttributes.GEN_AI_RESPONSE_ID] == RETRIEVE_RESPONSE_ID ) - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_STREAM] is True + assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes assert response.id == RETRIEVE_RESPONSE_ID diff --git a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py index 4099894e2..fddda91f1 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py +++ b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py @@ -417,7 +417,6 @@ def test_responses_retrieve_streaming( response_model=response.model, response_status="completed", finish_reasons=("stop",), - request_stream=True, stream_cursor=str(RETRIEVE_STREAM_CURSOR), response_service_tier=response.service_tier, ) @@ -476,7 +475,7 @@ def test_responses_retrieve_with_streaming_response_stays_lazy( span.attributes[GenAIAttributes.GEN_AI_RESPONSE_ID] == RETRIEVE_RESPONSE_ID ) - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_STREAM] is True + assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes assert response.id == RETRIEVE_RESPONSE_ID diff --git a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py index c876f931a..b9c9894b6 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py +++ b/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py @@ -386,7 +386,6 @@ def assert_fetch_response_attributes( response_model: str | None = None, response_status: str | None = None, finish_reasons: tuple | None = None, - request_stream: bool | None = None, stream_cursor: str | None = None, response_service_tier: str | None = None, server_address: str = "api.openai.com", @@ -419,6 +418,7 @@ def assert_fetch_response_attributes( assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS not in span.attributes assert GenAIAttributes.GEN_AI_REQUEST_MODEL not in span.attributes assert GenAIAttributes.GEN_AI_INPUT_MESSAGES not in span.attributes + assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes _assert_optional_attribute( span, GenAIAttributes.GEN_AI_RESPONSE_MODEL, response_model @@ -427,9 +427,6 @@ def assert_fetch_response_attributes( _assert_optional_attribute( span, GenAIAttributes.GEN_AI_RESPONSE_FINISH_REASONS, finish_reasons ) - _assert_optional_attribute( - span, GenAIAttributes.GEN_AI_REQUEST_STREAM, request_stream - ) _assert_optional_attribute( span, GEN_AI_REQUEST_STREAM_CURSOR, stream_cursor )