Skip to content

Commit 5bf108e

Browse files
authored
Do not record gen_ai.request.stream on fetch_response spans (#709)
1 parent 838493d commit 5bf108e

5 files changed

Lines changed: 4 additions & 14 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not record `gen_ai.request.stream` on `fetch_response` spans.

‎instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/patch_responses.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
get_fetch_response_creation_kwargs,
2020
get_inference_creation_kwargs,
2121
get_response_error,
22-
is_streamed_raw_response,
2322
set_fetch_response_attributes,
2423
set_invocation_response_attributes,
2524
)
@@ -215,11 +214,6 @@ def _start_fetch_response_invocation(
215214
) -> FetchResponseInvocation:
216215
invocation = handler.fetch_response(
217216
**get_fetch_response_creation_kwargs(response_id, instance),
218-
request_stream=(
219-
True
220-
if is_streaming(kwargs) or is_streamed_raw_response(kwargs)
221-
else None
222-
),
223217
)
224218
invocation.stream_cursor = _get_stream_cursor(kwargs)
225219
invocation.attributes[OpenAIAttributes.OPENAI_API_TYPE] = (

‎instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ async def test_async_responses_retrieve_streaming(
380380
response_model=response.model,
381381
response_status="completed",
382382
finish_reasons=("stop",),
383-
request_stream=True,
384383
stream_cursor=str(RETRIEVE_STREAM_CURSOR),
385384
response_service_tier=response.service_tier,
386385
)
@@ -455,7 +454,7 @@ async def test_async_responses_retrieve_with_streaming_response_stays_lazy(
455454
span.attributes[GenAIAttributes.GEN_AI_RESPONSE_ID]
456455
== RETRIEVE_RESPONSE_ID
457456
)
458-
assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_STREAM] is True
457+
assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes
459458
assert response.id == RETRIEVE_RESPONSE_ID
460459

461460

‎instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ def test_responses_retrieve_streaming(
417417
response_model=response.model,
418418
response_status="completed",
419419
finish_reasons=("stop",),
420-
request_stream=True,
421420
stream_cursor=str(RETRIEVE_STREAM_CURSOR),
422421
response_service_tier=response.service_tier,
423422
)
@@ -476,7 +475,7 @@ def test_responses_retrieve_with_streaming_response_stays_lazy(
476475
span.attributes[GenAIAttributes.GEN_AI_RESPONSE_ID]
477476
== RETRIEVE_RESPONSE_ID
478477
)
479-
assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_STREAM] is True
478+
assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes
480479
assert response.id == RETRIEVE_RESPONSE_ID
481480

482481

‎instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_utils.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ def assert_fetch_response_attributes(
386386
response_model: str | None = None,
387387
response_status: str | None = None,
388388
finish_reasons: tuple | None = None,
389-
request_stream: bool | None = None,
390389
stream_cursor: str | None = None,
391390
response_service_tier: str | None = None,
392391
server_address: str = "api.openai.com",
@@ -419,6 +418,7 @@ def assert_fetch_response_attributes(
419418
assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS not in span.attributes
420419
assert GenAIAttributes.GEN_AI_REQUEST_MODEL not in span.attributes
421420
assert GenAIAttributes.GEN_AI_INPUT_MESSAGES not in span.attributes
421+
assert GenAIAttributes.GEN_AI_REQUEST_STREAM not in span.attributes
422422

423423
_assert_optional_attribute(
424424
span, GenAIAttributes.GEN_AI_RESPONSE_MODEL, response_model
@@ -427,9 +427,6 @@ def assert_fetch_response_attributes(
427427
_assert_optional_attribute(
428428
span, GenAIAttributes.GEN_AI_RESPONSE_FINISH_REASONS, finish_reasons
429429
)
430-
_assert_optional_attribute(
431-
span, GenAIAttributes.GEN_AI_REQUEST_STREAM, request_stream
432-
)
433430
_assert_optional_attribute(
434431
span, GEN_AI_REQUEST_STREAM_CURSOR, stream_cursor
435432
)

0 commit comments

Comments
 (0)