Skip to content

fix(anthropic): Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans#5675

Merged
alexander-alderman-webb merged 33 commits intomasterfrom
webb/anthropic/async-iterators
Mar 18, 2026
Merged

fix(anthropic): Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans#5675
alexander-alderman-webb merged 33 commits intomasterfrom
webb/anthropic/async-iterators

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Mar 16, 2026

Description

Close AI Client Spans when the Anthropic SDK's HTTP connection is closed and not merely when the streamed response iterator is consumed or the GC collects the private _iterator instance variable. Patch the close() method that also closes the connection.

Issues

Reminders

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Anthropic

  • Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans by alexander-alderman-webb in #5675
  • Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Internal Changes 🔧

  • Add client report tests for span streaming by sentrivana in #5677

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Codecov Results 📊

1784 passed | ⏭️ 187 skipped | Total: 1971 | Pass Rate: 90.51% | Execution Time: 2m 16s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 12071 uncovered lines.

Files with missing lines (1)
File Patch % Lines
anthropic.py 5.79% ⚠️ 407 Missing

Generated by Codecov Action

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review March 17, 2026 12:38
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner March 17, 2026 12:38
@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft March 17, 2026 13:06
@alexander-alderman-webb alexander-alderman-webb changed the title fix(anthropic): Respect iterator protocol in asynchronous streamed responses fix(anthropic): Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans Mar 17, 2026
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review March 17, 2026 15:15
Base automatically changed from webb/anthropic/sync-iterators to master March 18, 2026 13:20
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@alexander-alderman-webb alexander-alderman-webb merged commit 6d33d36 into master Mar 18, 2026
185 of 191 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/anthropic/async-iterators branch March 18, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants