From 083e78bb5ab0fc61fc8bcae7e46d6effc6d9c786 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Tue, 21 Jan 2025 16:48:04 -0500 Subject: [PATCH 1/4] chore(profiling): Change continuous profile sampling frequency and buffer size This lowers the sampling frequency of continous profiles to 21Hz and increases the buffer size to 1 minute. --- sentry_sdk/profiler/continuous_profiler.py | 12 +++++++----- tests/profiler/test_continuous_profiler.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sentry_sdk/profiler/continuous_profiler.py b/sentry_sdk/profiler/continuous_profiler.py index 5d64896b93..68f5c5790a 100644 --- a/sentry_sdk/profiler/continuous_profiler.py +++ b/sentry_sdk/profiler/continuous_profiler.py @@ -9,10 +9,7 @@ from sentry_sdk.consts import VERSION from sentry_sdk.envelope import Envelope from sentry_sdk._lru_cache import LRUCache -from sentry_sdk.profiler.utils import ( - DEFAULT_SAMPLING_FREQUENCY, - extract_stack, -) +from sentry_sdk.profiler.utils import extract_stack from sentry_sdk.utils import ( capture_internal_exception, is_gevent, @@ -52,6 +49,11 @@ ) +# The default sampling frequency to use. This is set at 21 in order to +# mitigate the effects of lockstep sampling. +DEFAULT_SAMPLING_FREQUENCY = 21 + + try: from gevent.monkey import get_original from gevent.threadpool import ThreadPool as _ThreadPool @@ -407,7 +409,7 @@ def teardown(self): self.buffer = None -PROFILE_BUFFER_SECONDS = 10 +PROFILE_BUFFER_SECONDS = 60 class ProfileBuffer: diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 1b96f27036..32d0e8d0b0 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -200,7 +200,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.05) + time.sleep(0.1) assert_single_transaction_with_profile_chunks(envelopes, thread) @@ -211,7 +211,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.05) + time.sleep(0.1) assert_single_transaction_without_profile_chunks(envelopes) @@ -221,7 +221,7 @@ def test_continuous_profiler_auto_start_and_manual_stop( with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.05) + time.sleep(0.1) assert_single_transaction_with_profile_chunks(envelopes, thread) From 98aec9b4fecb159840fe09bd0902d0d288931a48 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 16:55:16 -0800 Subject: [PATCH 2/4] revert sampling frequency --- sentry_sdk/profiler/continuous_profiler.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/profiler/continuous_profiler.py b/sentry_sdk/profiler/continuous_profiler.py index 68f5c5790a..5a76a0696c 100644 --- a/sentry_sdk/profiler/continuous_profiler.py +++ b/sentry_sdk/profiler/continuous_profiler.py @@ -9,7 +9,10 @@ from sentry_sdk.consts import VERSION from sentry_sdk.envelope import Envelope from sentry_sdk._lru_cache import LRUCache -from sentry_sdk.profiler.utils import extract_stack +from sentry_sdk.profiler.utils import ( + DEFAULT_SAMPLING_FREQUENCY, + extract_stack, +) from sentry_sdk.utils import ( capture_internal_exception, is_gevent, @@ -49,11 +52,6 @@ ) -# The default sampling frequency to use. This is set at 21 in order to -# mitigate the effects of lockstep sampling. -DEFAULT_SAMPLING_FREQUENCY = 21 - - try: from gevent.monkey import get_original from gevent.threadpool import ThreadPool as _ThreadPool From 89016af30f3712a34c8cbab7fdc8062863d14964 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Mon, 3 Feb 2025 12:57:40 -0500 Subject: [PATCH 3/4] bump From 2f497c33a3b8aad305f614dd943b5439963fb4b7 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Mon, 3 Feb 2025 13:05:05 -0500 Subject: [PATCH 4/4] fix mypy comment --- sentry_sdk/transport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index 8798115898..3329b201b1 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -720,7 +720,7 @@ def _request( try: import httpcore - import h2 # type: ignore # noqa: F401 + import h2 # noqa: F401 except ImportError: # Sorry, no Http2Transport for you class Http2Transport(HttpTransport):