Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sentry_sdk/integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ def new_iterator() -> "Iterator[ChatCompletionChunk]":
data_buf[0].append(x.delta or "")

if isinstance(x, ResponseCompletedEvent):
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.response.model)

_calculate_token_usage(
input,
x.response,
Expand Down Expand Up @@ -801,6 +803,8 @@ async def new_iterator_async() -> "AsyncIterator[ChatCompletionChunk]":
data_buf[0].append(x.delta or "")

if isinstance(x, ResponseCompletedEvent):
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.response.model)

_calculate_token_usage(
input,
x.response,
Expand Down
5 changes: 5 additions & 0 deletions tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,7 @@ async def test_ai_client_span_streaming_responses_async_api(

expected_data = {
"gen_ai.operation.name": "responses",
"gen_ai.response.model": "response-model-id",
"gen_ai.response.streaming": True,
"gen_ai.system": "openai",
"gen_ai.response.time_to_first_token": mock.ANY,
Expand Down Expand Up @@ -2769,6 +2770,8 @@ def test_streaming_responses_api(
(span,) = transaction["spans"]
assert span["op"] == "gen_ai.responses"

assert span["data"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "response-model-id"

if send_default_pii and include_prompts:
assert span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES] == '["hello"]'
assert span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT] == "hello world"
Expand Down Expand Up @@ -2824,6 +2827,8 @@ async def test_streaming_responses_api_async(
(span,) = transaction["spans"]
assert span["op"] == "gen_ai.responses"

assert span["data"][SPANDATA.GEN_AI_RESPONSE_MODEL] == "response-model-id"

if send_default_pii and include_prompts:
assert span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES] == '["hello"]'
assert span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT] == "hello world"
Expand Down
Loading