Skip to content

Commit ed9596e

Browse files
Merge branch 'webb/openai/streaming-response' into webb/openai/add-response-model
2 parents 4dade58 + 82843e2 commit ed9596e

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
@@ -640,6 +640,13 @@ def new_iterator() -> "Iterator[ChatCompletionChunk]":
640640
set_data_normalized(
641641
span, SPANDATA.GEN_AI_RESPONSE_TEXT, all_responses
642642
)
643+
_calculate_token_usage(
644+
messages,
645+
response,
646+
span,
647+
all_responses,
648+
integration.count_tokens,
649+
)
643650

644651
if finish_span:
645652
span.__exit__(None, None, None)
@@ -675,6 +682,13 @@ async def new_iterator_async() -> "AsyncIterator[ChatCompletionChunk]":
675682
set_data_normalized(
676683
span, SPANDATA.GEN_AI_RESPONSE_TEXT, all_responses
677684
)
685+
_calculate_token_usage(
686+
messages,
687+
response,
688+
span,
689+
all_responses,
690+
integration.count_tokens,
691+
)
678692

679693
if finish_span:
680694
span.__exit__(None, None, None)

0 commit comments

Comments
 (0)