Skip to content

feat(asyncpg): Add span streaming support#6215

Merged
ericapisani merged 5 commits intomasterfrom
py-2305-migrate-asyncpg
May 11, 2026
Merged

feat(asyncpg): Add span streaming support#6215
ericapisani merged 5 commits intomasterfrom
py-2305-migrate-asyncpg

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented May 6, 2026

Migrates the asyncpg integration to support the stream trace lifecycle.

The integration now uses record_sql_queries_supporting_streaming and StreamedSpan so that DB spans are emitted as soon as they complete rather than being buffered until transaction end.

Tests are parameterized over both span_streaming=True and span_streaming=False to verify both paths.

Fixes PY-2305, fixes #6003

Migrates the asyncpg integration to use `record_sql_queries_supporting_streaming` and `StreamedSpan`, adding support for the `stream` trace lifecycle. Tests are parameterized to cover both static and streaming modes.

Fixes PY-2305
Fixes #6003
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 6, 2026

@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run

@ericapisani
Copy link
Copy Markdown
Member Author

@sentry review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.06s

All tests are passing successfully.

❌ Patch coverage is 8.16%. Project has 15155 uncovered lines.

Files with missing lines (1)
File Patch % Lines
asyncpg.py 10.87% ⚠️ 123 Missing

Generated by Codecov Action

Comment thread sentry_sdk/integrations/asyncpg.py
Comment thread sentry_sdk/integrations/asyncpg.py
Copy link
Copy Markdown

@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 2 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit fd3ee4e. Configure here.

Comment thread sentry_sdk/integrations/asyncpg.py Outdated
Comment thread sentry_sdk/integrations/asyncpg.py
…an has been created. This allows the traces_sampler to see the attributes and make decisions based on them
Comment thread sentry_sdk/integrations/asyncpg.py
@ericapisani ericapisani marked this pull request as ready for review May 8, 2026 18:10
@ericapisani ericapisani requested a review from a team as a code owner May 8, 2026 18:10
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To keep the amount of changes within this pull request under control, I've separated out a number of clean up changes related to the tests in the other pull request.

Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Looking great! See one comment.

) as span:
_set_db_data(span, args[0])
res = f(*args, **kwargs)
span.set_data("db.cursor", res)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know we're not porting this to streamed spans, which is 💯 the right call, but are we removing it for legacy spans, too? I'd keep it in the old path, to reduce the odds of breaking a user. We'll anyway get rid of this in the next major when span streaming is the default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

are we removing it for legacy spans, too?

We aren't 👍🏻

It's non-obvious from this diff, but because we're calling _record on line 147, and it calls record_sql_queries_supporting_streaming, this is still getting set for legacy spans

@ericapisani ericapisani merged commit b3c6226 into master May 11, 2026
150 checks passed
@ericapisani ericapisani deleted the py-2305-migrate-asyncpg branch May 11, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate asyncpg to span first

2 participants