Skip to content

fix(asyncio): Add task_isolation setting for AsyncioIntegration (#5371)#5734

Open
harryautomazione wants to merge 1 commit intogetsentry:masterfrom
harryautomazione:fix/issue-5371
Open

fix(asyncio): Add task_isolation setting for AsyncioIntegration (#5371)#5734
harryautomazione wants to merge 1 commit intogetsentry:masterfrom
harryautomazione:fix/issue-5371

Conversation

@harryautomazione
Copy link

Problem

Currently, AsyncioIntegration wraps every asyncio task in a new isolation_scope(). While this is great for isolating background tasks, it prevents scope data (like tags set via sentry_sdk.set_tag()) inside async endpoints from propagating back to the parent middleware transaction (e.g. in FastAPI/Starlette).

Solution

This PR adds a task_isolation: bool parameter (default True) to AsyncioIntegration.
Setting task_isolation=False disables the automatic isolation_scope() for tasks, allowing tags written inside endpoints to correctly attach to the outer HTTP transaction trace.

Fixes #5371

Verification

Verified with a reproduction script that with task_isolation=False, tags set inside local endpoint asyncio tasks correctly surface on the captured HTTP response transaction.

@harryautomazione harryautomazione requested a review from a team as a code owner March 22, 2026 17:42
@github-actions
Copy link
Contributor

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).


New Features ✨

  • (asgi) Add option to disable suppressing chained exceptions by alexander-alderman-webb in #5714
  • (logging) Separate ignore lists for events/breadcrumbs and sentry logs by sl0thentr0py in #5698

Bug Fixes 🐛

Anthropic

  • Set exception info on streaming span when applicable by alexander-alderman-webb in #5683
  • 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

Other

Documentation 📚

  • Add note on AI PRs to CONTRIBUTING.md by sentrivana in #5696

Internal Changes 🔧

  • Add -latest alias for each integration test suite by sentrivana in #5706
  • Use date-based branch names for toxgen PRs by sentrivana in #5704
  • 🤖 Update test matrix with new releases (03/19) by github-actions in #5703
  • 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.

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.

AsyncIOIntegration cause misbehavior in transactions created from auto-integrations

1 participant