Skip to content

Commit e7c5c5a

Browse files
Merge branch 'webb/openai/add-response-model' into webb/openai/add-response-model-completions
2 parents b07d1df + ed9596e commit e7c5c5a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ def new_iterator() -> "Iterator[ChatCompletionChunk]":
642642
set_data_normalized(
643643
span, SPANDATA.GEN_AI_RESPONSE_TEXT, all_responses
644644
)
645+
_calculate_token_usage(
646+
messages,
647+
response,
648+
span,
649+
all_responses,
650+
integration.count_tokens,
651+
)
645652

646653
if finish_span:
647654
span.__exit__(None, None, None)
@@ -679,6 +686,13 @@ async def new_iterator_async() -> "AsyncIterator[ChatCompletionChunk]":
679686
set_data_normalized(
680687
span, SPANDATA.GEN_AI_RESPONSE_TEXT, all_responses
681688
)
689+
_calculate_token_usage(
690+
messages,
691+
response,
692+
span,
693+
all_responses,
694+
integration.count_tokens,
695+
)
682696

683697
if finish_span:
684698
span.__exit__(None, None, None)

0 commit comments

Comments
 (0)