Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(profiling): Enable profiling for ASGI frameworks #1824

Merged
merged 10 commits into from
Jan 17, 2023

Conversation

Zylphrex
Copy link
Member

@Zylphrex Zylphrex commented Jan 5, 2023

This enables profiling for ASGI frameworks. When running in ASGI sync views, the
transaction gets started in the main thread then the request is dispatched to a
handler thread. We want to set the handler thread as the active thread id to
ensure that profiles will show it on first render.

This enables profiling for ASGI frameworks. When running in ASGI sync views, the
transaction gets started in the main thread then the request is dispatched to a
handler thread. We want to set the handler thread as the active thread id to
ensure that profiles will show it on first render.
@Zylphrex Zylphrex force-pushed the txiao/feat/enable-profiling-for-asgi-frameworks branch from 4411f92 to 2c9d119 Compare January 5, 2023 21:51
@Zylphrex Zylphrex changed the title feat(profiling): Set active thread id for ASGI frameworks feat(profiling): Enable profiling for ASGI frameworks Jan 5, 2023
@Zylphrex Zylphrex marked this pull request as ready for review January 9, 2023 17:16
@Zylphrex Zylphrex requested review from sl0thentr0py and a team January 9, 2023 17:16
sentry_sdk/profiler.py Show resolved Hide resolved
sentry_sdk/integrations/fastapi.py Show resolved Hide resolved
sentry_sdk/integrations/quart.py Outdated Show resolved Hide resolved
Zylphrex added a commit that referenced this pull request Jan 10, 2023
Following up to #1824 to set the active thread id for quart.
with hub.configure_scope() as sentry_scope:
if sentry_scope.profile is not None:
sentry_scope.profile.active_thread_id = (
threading.current_thread().ident
Copy link
Member

Choose a reason for hiding this comment

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

Because current_thread() can be a dummy object (see https://docs.python.org/3/library/threading.html#threading.current_thread) maybe it is saver to use threading.get_ident()?
(But if the dummy object also has a .ident my comment can be ignored)

Copy link
Member Author

Choose a reason for hiding this comment

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

_DummyThread inherits from Thread (source) and so both should have the ident property.

@Zylphrex Zylphrex merged commit 43ca991 into master Jan 17, 2023
@Zylphrex Zylphrex deleted the txiao/feat/enable-profiling-for-asgi-frameworks branch January 17, 2023 20:49
Zylphrex added a commit that referenced this pull request Jan 19, 2023
Following up to #1824 to set the active thread id for quart.
sl0thentr0py pushed a commit that referenced this pull request Mar 6, 2023
Following up to #1824 to set the active thread id for quart.
sl0thentr0py pushed a commit that referenced this pull request Mar 6, 2023
Following up to #1824 to set the active thread id for quart.
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.

3 participants