Skip to content

feat(cohere): Add span streaming support

1f3d056
Select commit
Loading
Failed to load commit list.
Merged

feat(cohere): Add span streaming support #6479

feat(cohere): Add span streaming support
1f3d056
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed Jun 1, 2026 in 25m 54s

3 issues

Low

No test coverage for embed error handling in span streaming mode - `sentry_sdk/integrations/cohere.py:245`

There is no test_bad_embed test for either traditional or span-streaming mode, so the new with span_ctx as span: error path in new_embed (where a raised exception triggers StreamedSpan.__exit__ to set error status) is untested. Consider adding a test similar to test_span_status_error_streaming for the embed path.

StreamedSpan may leak on scope if `_capture_exception` raises before `span.__exit__` in shared internal-exceptions block - `sentry_sdk/integrations/cohere.py:171-174`

In the streaming branch of _wrap_chat.new_chat, when is_span_streaming_enabled=True, a StreamedSpan immediately registers itself as _scope.streamed_span during __init__ (via _start()). On the error path, _capture_exception(e) and span.__exit__(*exc_info) share a single with capture_internal_exceptions(): block. If _capture_exception raises (e.g. failure inside event_from_exception or capture_event), the exception is swallowed by capture_internal_exceptions and span.__exit__ is skipped. The span is never ended and _scope.streamed_span is not restored to its previous value, so any subsequent streamed span started on the same scope is incorrectly parented under the leaked chat span until the scope is torn down. Splitting the two calls into independent with capture_internal_exceptions(): blocks ensures cleanup always runs.

StreamedSpan leaks if streaming generator is never fully consumed

When is_span_streaming_enabled=True and chat_stream is used, _end_span(span) is only reachable at the end of the new_iterator() generator; if the caller breaks out of iteration early, the StreamedSpan is never ended and remains the active span on the scope indefinitely, causing all subsequent child spans in that scope to be incorrectly parented.

4 skills analyzed
Skill Findings Duration Cost
security-review 0 3.9s $0.08
code-review 1 13m 46s $2.63
find-bugs 2 24m 22s $4.67
skill-scanner 0 3.9s $0.06

⏱ 38m 16s · 5.6M in / 244.5k out · $7.45