@@ -279,9 +279,9 @@ def _set_output_data(span, response, kwargs, integration, finish_span=True):
279
279
280
280
def new_iterator ():
281
281
# type: () -> Iterator[ChatCompletionChunk]
282
- with capture_internal_exceptions ():
283
- count_tokens_manually = True
284
- for x in old_iterator :
282
+ count_tokens_manually = True
283
+ for x in old_iterator :
284
+ with capture_internal_exceptions () :
285
285
# OpenAI chat completion API
286
286
if hasattr (x , "choices" ):
287
287
choice_index = 0
@@ -312,8 +312,9 @@ def new_iterator():
312
312
)
313
313
count_tokens_manually = False
314
314
315
- yield x
315
+ yield x
316
316
317
+ with capture_internal_exceptions ():
317
318
if len (data_buf ) > 0 :
318
319
all_responses = ["" .join (chunk ) for chunk in data_buf ]
319
320
if should_send_default_pii () and integration .include_prompts :
@@ -334,9 +335,9 @@ def new_iterator():
334
335
335
336
async def new_iterator_async ():
336
337
# type: () -> AsyncIterator[ChatCompletionChunk]
337
- with capture_internal_exceptions ():
338
- count_tokens_manually = True
339
- async for x in old_iterator :
338
+ count_tokens_manually = True
339
+ async for x in old_iterator :
340
+ with capture_internal_exceptions () :
340
341
# OpenAI chat completion API
341
342
if hasattr (x , "choices" ):
342
343
choice_index = 0
@@ -367,8 +368,9 @@ async def new_iterator_async():
367
368
)
368
369
count_tokens_manually = False
369
370
370
- yield x
371
+ yield x
371
372
373
+ with capture_internal_exceptions ():
372
374
if len (data_buf ) > 0 :
373
375
all_responses = ["" .join (chunk ) for chunk in data_buf ]
374
376
if should_send_default_pii () and integration .include_prompts :
0 commit comments