Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sentry_sdk/profiler/continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setup_continuous_profiler(options, sdk_info, capture_func):

if _scheduler is not None:
logger.debug("[Profiling] Continuous Profiler is already setup")
return False
teardown_continuous_profiler()

if is_gevent():
# If gevent has patched the threading modules then we cannot rely on
Expand Down Expand Up @@ -122,6 +122,13 @@ def setup_continuous_profiler(options, sdk_info, capture_func):
return True


def is_profile_session_sampled():
# type: () -> bool
if _scheduler is None:
return False
return _scheduler.sampled


def try_autostart_continuous_profiler():
# type: () -> None

Expand Down
11 changes: 8 additions & 3 deletions tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sentry_sdk
from sentry_sdk.consts import VERSION
from sentry_sdk.profiler.continuous_profiler import (
is_profile_session_sampled,
get_profiler_id,
setup_continuous_profiler,
start_profiler,
Expand Down Expand Up @@ -113,19 +114,23 @@ def test_continuous_profiler_valid_mode(mode, make_options, teardown_profiling):
],
)
def test_continuous_profiler_setup_twice(mode, make_options, teardown_profiling):
options = make_options(mode=mode)
# setting up the first time should return True to indicate success
options = make_options(mode=mode, profile_session_sample_rate=0.0)
assert setup_continuous_profiler(
options,
mock_sdk_info,
lambda envelope: None,
)
# setting up the second time should return False to indicate no-op
assert not setup_continuous_profiler(
assert not is_profile_session_sampled()

# setting up the second time should return True to indicate re-init
options = make_options(mode=mode, profile_session_sample_rate=1.0)
assert setup_continuous_profiler(
options,
mock_sdk_info,
lambda envelope: None,
)
assert is_profile_session_sampled()


def assert_single_transaction_with_profile_chunks(
Expand Down