GeezerVison is showing github.com — refactor: move FastAPI active thread tracking into Starlette by faizansaiyed123 · Pull Request #7825 · getsentry/sentry-python
Conversation
Ref #7753
This separates the active-thread/profiler bookkeeping from the FastAPI-specific request handling.
Changes:
- Centralize active-thread updates in the Starlette integration.
- Provide a Starlette sync-handler wrapper so active-thread metadata is updated in the thread that actually executes a synchronous handler.
- Reuse that wrapper from the FastAPI integration.
- Preserve both static transaction and span-streaming behavior.
The follow-up FastAPI PR uses this Starlette helper while replacing the private FastAPI request-handler patch with a global dependency.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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.

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 87d3a13. Configure here.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, except for one attribute name, left a suggestion there.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+652
to
+660
|
|
if getattr(handler, "_sentry_active_thread_is_patched", False):
|
|
|
return handler
|
|
|
|
|
|
@functools.wraps(handler)
|
|
|
def _sentry_sync_handler(*args: "Any", **kwargs: "Any") -> "Any":
|
|
|
_update_active_thread()
|
|
|
return handler(*args, **kwargs)
|
|
|
|
|
|
_sentry_sync_handler._sentry_active_thread_is_patched = True # type: ignore[attr-defined]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
if getattr(handler, "_sentry_active_thread_is_patched", False): |
|
return handler |
|
|
|
@functools.wraps(handler) |
|
def _sentry_sync_handler(*args: "Any", **kwargs: "Any") -> "Any": |
|
_update_active_thread() |
|
return handler(*args, **kwargs) |
|
|
|
_sentry_sync_handler._sentry_active_thread_is_patched = True # type: ignore[attr-defined] |
|
if getattr(handler, "_sentry_patched", False): |
|
return handler |
|
|
|
@functools.wraps(handler) |
|
def _sentry_sync_handler(*args: "Any", **kwargs: "Any") -> "Any": |
|
_update_active_thread() |
|
return handler(*args, **kwargs) |
|
|
|
_sentry_sync_handler._sentry_patched = True # type: ignore[attr-defined] |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|