Skip to content

Commit

Permalink
fix(profiling): Check transaction sampled status before profiling (#1624
Browse files Browse the repository at this point in the history
)

Should always check if the transaction is sampled before deciding to profile to
avoid profiling when it's not necessary.
  • Loading branch information
Zylphrex authored Sep 19, 2022
1 parent 7dc58d2 commit e32f224
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,13 @@ def stop_profiling(self):
return should_stop_timer


def _should_profile(hub):
# type: (Optional[sentry_sdk.Hub]) -> bool
def _should_profile(transaction, hub):
# type: (sentry_sdk.tracing.Transaction, Optional[sentry_sdk.Hub]) -> bool

# The corresponding transaction was not sampled,
# so don't generate a profile for it.
if not transaction.sampled:
return False

# The profiler hasn't been properly initialized.
if _sample_buffer is None or _scheduler is None:
Expand Down Expand Up @@ -357,7 +362,7 @@ def start_profiling(transaction, hub=None):
# type: (sentry_sdk.tracing.Transaction, Optional[sentry_sdk.Hub]) -> Generator[None, None, None]

# if profiling was not enabled, this should be a noop
if _should_profile(hub):
if _should_profile(transaction, hub):
with Profile(transaction, hub=hub):
yield
else:
Expand Down

0 comments on commit e32f224

Please sign in to comment.