Skip to content

refactor(fastapi): use a global dependency for active thread tracking - #7826

Open
faizansaiyed123 wants to merge 31 commits into
getsentry:masterfrom
faizansaiyed123:fix/7753-fastapi-global-dependency
Open

faizansaiyed123 wants to merge 31 commits into
getsentry:masterfrom
faizansaiyed123:fix/7753-fastapi-global-dependency

Conversation

@faizansaiyed123

@faizansaiyed123 faizansaiyed123 commented Oct 2, 2026 •

Copy link
Copy Markdown

Ref #7753

Follow-up to #7825.

This PR replaces FastAPI's private routing.get_request_handler monkey patch with an application-level global dependency.

Changes:

  • Patch FastAPI.__init__ to register a Sentry global dependency before user-supplied global dependencies.
  • Use Starlette's HTTPConnection injection so the dependency is safe for FastAPI versions where global dependencies also apply to WebSockets.
  • Move FastAPI-specific transaction naming and http.route setup into the dependency, using FastAPI's effective route context when available.
  • Install the Starlette sync-handler wrapper on the request's Dependant so synchronous endpoints update thread metadata in their actual worker thread.
  • Preserve FastAPI request event processing and streamed request-body handling inside the global dependency.
  • Preserve user-supplied global dependencies.
  • Remove the private get_request_handler patch.

This branch includes #7825 so it can be reviewed end-to-end. Once #7825 is merged, this PR can be rebased/simplified to the dependency-only diff.

@faizansaiyed123
faizansaiyed123 requested a review from a team as a code owner October 2, 2026 03:19

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread sentry_sdk/integrations/fastapi.py Outdated
Comment thread sentry_sdk/integrations/fastapi.py
Comment thread sentry_sdk/integrations/fastapi.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread sentry_sdk/integrations/fastapi.py
Comment thread sentry_sdk/integrations/fastapi.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread sentry_sdk/integrations/fastapi.py
@faizansaiyed123
faizansaiyed123 force-pushed the fix/7753-fastapi-global-dependency branch from ffa6378 to c428c6e Compare October 2, 2026 05:45

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread tests/integrations/fastapi/test_fastapi.py Outdated

Copy link
Copy Markdown
Author

cursor review

Copy link
Copy Markdown
Author

bugbot run verbose=true

@cursor

cursor Bot commented Oct 2, 2026

Copy link
Copy Markdown

Bugbot request id: 8939ba6b-1511-41cb-8bd6-5514646cb90c

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor

cursor Bot commented Oct 2, 2026

Copy link
Copy Markdown

Bugbot rules debug

No rules were used for this review.

https://cursor.com/docs/bugbot#team-rules

Bugbot request id: 8939ba6b-1511-41cb-8bd6-5514646cb90c

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1e3d9c2. Configure here.

This branch has not been deployed

No deployments
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.

1 participant