From 3466138cf52a5c7731f7fed56dd8919c4b890d17 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 18 Oct 2023 17:00:18 +0200 Subject: [PATCH 1/9] Created issues_sampler --- sentry_sdk/client.py | 9 +++++---- sentry_sdk/consts.py | 1 + tests/test_client.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index b65c3f0c76..cdffad5f5e 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -456,10 +456,11 @@ def _should_sample_error( event, # type: Event ): # type: (...) -> bool - not_in_sample_rate = ( - self.options["sample_rate"] < 1.0 - and random.random() >= self.options["sample_rate"] - ) + try: + sample_rate = self.options["issues_sampler"](event) + except (KeyError, TypeError): + sample_rate = self.options["sample_rate"] + not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate if not_in_sample_rate: # because we will not sample this event, record a "lost event". if self.transport: diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 5bc3e2aa85..c6fc370950 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -261,6 +261,7 @@ def __init__( event_scrubber=None, # type: Optional[sentry_sdk.scrubber.EventScrubber] max_value_length=DEFAULT_MAX_VALUE_LENGTH, # type: int enable_backpressure_handling=True, # type: bool + issues_sampler=None, # type: Optional[Callable[[Event], Union[float, bool]]] ): # type: (...) -> None pass diff --git a/tests/test_client.py b/tests/test_client.py index bf3e4e79be..72f6704845 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1196,3 +1196,39 @@ def test_debug_option( assert "something is wrong" in caplog.text else: assert "something is wrong" not in caplog.text + + +@pytest.mark.parametrize( + ("sampler_function_mock", "sample_rate", "expected_events"), + ( + # Baseline test with issues_sampler only, both floats and bools + (mock.MagicMock(return_value=1.0), None, 1), + (mock.MagicMock(return_value=0.0), None, 0), + (mock.MagicMock(return_value=True), None, 1), + (mock.MagicMock(return_value=False), None, 0), + # Baseline test with sample_rate only + (None, 0.0, 0), + (None, 1.0, 1), + # issues_sampler takes precedence over sample_rate + (mock.MagicMock(return_value=1.0), 0.0, 1), + (mock.MagicMock(return_value=0.0), 1.0, 0), + ), +) +def test_issues_sampler( + sentry_init, capture_events, sampler_function_mock, sample_rate, expected_events +): + sentry_init(issues_sampler=sampler_function_mock, sample_rate=sample_rate) + + events = capture_events() + + try: + 1 / 0 + except ZeroDivisionError: + capture_exception() + + assert len(events) == expected_events + + try: + sampler_function_mock.assert_called_once() + except AttributeError: + ... # sampler_function_mock is None From bc0926c1ece387c49046c755acff4fe0c4e96141 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 18 Oct 2023 17:10:09 +0200 Subject: [PATCH 2/9] Verify the event gets passed --- tests/test_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 72f6704845..d9f657ec51 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1230,5 +1230,10 @@ def test_issues_sampler( try: sampler_function_mock.assert_called_once() + + # Ensure one argument (the event) was passed to the sampler function + assert len(sampler_function_mock.call_args[0]) == 1 except AttributeError: - ... # sampler_function_mock is None + # sampler_function_mock should be None in this case, + # but let's double-check to ensure the test is working correctly + assert sampler_function_mock is None From bfedd03ba0b2b1674fa3d777b2f2207e367259eb Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 19 Oct 2023 11:51:41 +0200 Subject: [PATCH 3/9] Restructured tests, adding different sample rates based on exception --- tests/test_client.py | 97 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index d9f657ec51..a198615f98 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -25,6 +25,12 @@ from sentry_sdk.utils import logger from sentry_sdk.serializer import MAX_DATABAG_BREADTH from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, DEFAULT_MAX_VALUE_LENGTH +from sentry_sdk._types import TYPE_CHECKING + +if TYPE_CHECKING: + from collections.abc import Callable + from typing import Any, Optional, Union + from sentry_sdk._types import Event try: from unittest import mock # python 3.3 and above @@ -1198,42 +1204,95 @@ def test_debug_option( assert "something is wrong" not in caplog.text +class IssuesSamplerTestConfig: + def __init__( + self, + expected_events, + sampler_function=None, + sample_rate=None, + exception_to_raise=Exception, + ): + # type: (int, Optional[Callable[[Event], Union[float, bool]]], Optional[float], type[Exception]) -> None + self.sampler_function_mock = ( + None + if sampler_function is None + else mock.MagicMock(side_effect=sampler_function) + ) + self.expected_events = expected_events + self.sample_rate = sample_rate + self.exception_to_raise = exception_to_raise + + def init_sdk(self, sentry_init): + # type: (Callable[[*Any], None]) -> None + sentry_init( + issues_sampler=self.sampler_function_mock, sample_rate=self.sample_rate + ) + + def raise_exception(self): + # type: () -> None + raise self.exception_to_raise() + + +@mock.patch("sentry_sdk.client.random.random", return_value=0.618) @pytest.mark.parametrize( - ("sampler_function_mock", "sample_rate", "expected_events"), + "test_config", ( # Baseline test with issues_sampler only, both floats and bools - (mock.MagicMock(return_value=1.0), None, 1), - (mock.MagicMock(return_value=0.0), None, 0), - (mock.MagicMock(return_value=True), None, 1), - (mock.MagicMock(return_value=False), None, 0), + IssuesSamplerTestConfig(sampler_function=lambda _: 1.0, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda _: 0.7, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda _: 0.6, expected_events=0), + IssuesSamplerTestConfig(sampler_function=lambda _: 0.0, expected_events=0), + IssuesSamplerTestConfig(sampler_function=lambda _: True, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda _: False, expected_events=0), # Baseline test with sample_rate only - (None, 0.0, 0), - (None, 1.0, 1), + IssuesSamplerTestConfig(sample_rate=1.0, expected_events=1), + IssuesSamplerTestConfig(sample_rate=0.7, expected_events=1), + IssuesSamplerTestConfig(sample_rate=0.6, expected_events=0), + IssuesSamplerTestConfig(sample_rate=0.0, expected_events=0), # issues_sampler takes precedence over sample_rate - (mock.MagicMock(return_value=1.0), 0.0, 1), - (mock.MagicMock(return_value=0.0), 1.0, 0), + IssuesSamplerTestConfig( + sampler_function=lambda _: 1.0, sample_rate=0.0, expected_events=1 + ), + IssuesSamplerTestConfig( + sampler_function=lambda _: 0.0, sample_rate=1.0, expected_events=0 + ), + # Different sample rates based on exception + IssuesSamplerTestConfig( + sampler_function=lambda event: { + "ZeroDivisionError": 1.0, + "AttributeError": 0.0, + }[event["exception"]["values"][0]["type"]], + exception_to_raise=ZeroDivisionError, + expected_events=1, + ), + IssuesSamplerTestConfig( + sampler_function=lambda event: { + "ZeroDivisionError": 1.0, + "AttributeError": 0.0, + }[event["exception"]["values"][0]["type"]], + exception_to_raise=AttributeError, + expected_events=0, + ), ), ) -def test_issues_sampler( - sentry_init, capture_events, sampler_function_mock, sample_rate, expected_events -): - sentry_init(issues_sampler=sampler_function_mock, sample_rate=sample_rate) +def test_issues_sampler(_, sentry_init, capture_events, test_config): + test_config.init_sdk(sentry_init) events = capture_events() try: - 1 / 0 - except ZeroDivisionError: + test_config.raise_exception() + except Exception: capture_exception() - assert len(events) == expected_events + assert len(events) == test_config.expected_events try: - sampler_function_mock.assert_called_once() + assert test_config.sampler_function_mock.call_count == 1 # Ensure one argument (the event) was passed to the sampler function - assert len(sampler_function_mock.call_args[0]) == 1 + assert len(test_config.sampler_function_mock.call_args[0]) == 1 except AttributeError: # sampler_function_mock should be None in this case, # but let's double-check to ensure the test is working correctly - assert sampler_function_mock is None + assert test_config.sampler_function_mock is None From 90f0c2bf57aa79efd56ed0e7468b541e75aae4b6 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 19 Oct 2023 15:31:58 +0200 Subject: [PATCH 4/9] Update tests/test_client.py Co-authored-by: Ivana Kellyerova --- tests/test_client.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index a198615f98..fea191978e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1287,12 +1287,8 @@ def test_issues_sampler(_, sentry_init, capture_events, test_config): assert len(events) == test_config.expected_events - try: + if test_config.sampler_function_mock is not None: assert test_config.sampler_function_mock.call_count == 1 # Ensure one argument (the event) was passed to the sampler function assert len(test_config.sampler_function_mock.call_args[0]) == 1 - except AttributeError: - # sampler_function_mock should be None in this case, - # but let's double-check to ensure the test is working correctly - assert test_config.sampler_function_mock is None From 7535624f65e3415e9f0c0b57217cf510acd8fc69 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 19 Oct 2023 16:23:36 +0200 Subject: [PATCH 5/9] Pass hint also to the sampler --- sentry_sdk/client.py | 13 +++++++++---- sentry_sdk/consts.py | 3 ++- tests/test_client.py | 42 +++++++++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index cdffad5f5e..a2ab9e57f2 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -454,12 +454,17 @@ def _should_capture( def _should_sample_error( self, event, # type: Event + hint, # type: Hint ): # type: (...) -> bool - try: - sample_rate = self.options["issues_sampler"](event) - except (KeyError, TypeError): + sampler = self.options.get("issues_sampler", None) + + if callable(sampler): + with capture_internal_exceptions(): + sample_rate = sampler(event, hint) + else: sample_rate = self.options["sample_rate"] + not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate if not_in_sample_rate: # because we will not sample this event, record a "lost event". @@ -557,7 +562,7 @@ def capture_event( if ( not is_transaction and not is_checkin - and not self._should_sample_error(event) + and not self._should_sample_error(event, hint) ): return None diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index c6fc370950..6cbc646c97 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -22,6 +22,7 @@ BreadcrumbProcessor, Event, EventProcessor, + Hint, ProfilerMode, TracesSampler, TransactionProcessor, @@ -261,7 +262,7 @@ def __init__( event_scrubber=None, # type: Optional[sentry_sdk.scrubber.EventScrubber] max_value_length=DEFAULT_MAX_VALUE_LENGTH, # type: int enable_backpressure_handling=True, # type: bool - issues_sampler=None, # type: Optional[Callable[[Event], Union[float, bool]]] + issues_sampler=None, # type: Optional[Callable[[Event, Hint], Union[float, bool]]] ): # type: (...) -> None pass diff --git a/tests/test_client.py b/tests/test_client.py index fea191978e..06b187eeb6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1238,12 +1238,12 @@ def raise_exception(self): "test_config", ( # Baseline test with issues_sampler only, both floats and bools - IssuesSamplerTestConfig(sampler_function=lambda _: 1.0, expected_events=1), - IssuesSamplerTestConfig(sampler_function=lambda _: 0.7, expected_events=1), - IssuesSamplerTestConfig(sampler_function=lambda _: 0.6, expected_events=0), - IssuesSamplerTestConfig(sampler_function=lambda _: 0.0, expected_events=0), - IssuesSamplerTestConfig(sampler_function=lambda _: True, expected_events=1), - IssuesSamplerTestConfig(sampler_function=lambda _: False, expected_events=0), + IssuesSamplerTestConfig(sampler_function=lambda *_: 1.0, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda *_: 0.7, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda *_: 0.6, expected_events=0), + IssuesSamplerTestConfig(sampler_function=lambda *_: 0.0, expected_events=0), + IssuesSamplerTestConfig(sampler_function=lambda *_: True, expected_events=1), + IssuesSamplerTestConfig(sampler_function=lambda *_: False, expected_events=0), # Baseline test with sample_rate only IssuesSamplerTestConfig(sample_rate=1.0, expected_events=1), IssuesSamplerTestConfig(sample_rate=0.7, expected_events=1), @@ -1251,14 +1251,14 @@ def raise_exception(self): IssuesSamplerTestConfig(sample_rate=0.0, expected_events=0), # issues_sampler takes precedence over sample_rate IssuesSamplerTestConfig( - sampler_function=lambda _: 1.0, sample_rate=0.0, expected_events=1 + sampler_function=lambda *_: 1.0, sample_rate=0.0, expected_events=1 ), IssuesSamplerTestConfig( - sampler_function=lambda _: 0.0, sample_rate=1.0, expected_events=0 + sampler_function=lambda *_: 0.0, sample_rate=1.0, expected_events=0 ), - # Different sample rates based on exception + # Different sample rates based on exception, retrieved both from event and hint IssuesSamplerTestConfig( - sampler_function=lambda event: { + sampler_function=lambda event, _: { "ZeroDivisionError": 1.0, "AttributeError": 0.0, }[event["exception"]["values"][0]["type"]], @@ -1266,13 +1266,29 @@ def raise_exception(self): expected_events=1, ), IssuesSamplerTestConfig( - sampler_function=lambda event: { + sampler_function=lambda event, _: { "ZeroDivisionError": 1.0, "AttributeError": 0.0, }[event["exception"]["values"][0]["type"]], exception_to_raise=AttributeError, expected_events=0, ), + IssuesSamplerTestConfig( + sampler_function=lambda _, hint: { + ZeroDivisionError: 1.0, + AttributeError: 0.0, + }[hint["exc_info"][0]], + exception_to_raise=ZeroDivisionError, + expected_events=1, + ), + IssuesSamplerTestConfig( + sampler_function=lambda _, hint: { + ZeroDivisionError: 1.0, + AttributeError: 0.0, + }[hint["exc_info"][0]], + exception_to_raise=AttributeError, + expected_events=0, + ), ), ) def test_issues_sampler(_, sentry_init, capture_events, test_config): @@ -1290,5 +1306,5 @@ def test_issues_sampler(_, sentry_init, capture_events, test_config): if test_config.sampler_function_mock is not None: assert test_config.sampler_function_mock.call_count == 1 - # Ensure one argument (the event) was passed to the sampler function - assert len(test_config.sampler_function_mock.call_args[0]) == 1 + # Ensure two arguments (the event and hint) were passed to the sampler function + assert len(test_config.sampler_function_mock.call_args[0]) == 2 From 2379acc9168c7a59781f8d08144f1e91fda348e0 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 20 Oct 2023 11:51:24 +0200 Subject: [PATCH 6/9] Renamed issues_sampler to events_sampler --- sentry_sdk/client.py | 2 +- sentry_sdk/consts.py | 2 +- tests/test_client.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index a2ab9e57f2..d70ed23609 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -457,7 +457,7 @@ def _should_sample_error( hint, # type: Hint ): # type: (...) -> bool - sampler = self.options.get("issues_sampler", None) + sampler = self.options.get("events_sampler", None) if callable(sampler): with capture_internal_exceptions(): diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 6cbc646c97..80c5c4bfd4 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -262,7 +262,7 @@ def __init__( event_scrubber=None, # type: Optional[sentry_sdk.scrubber.EventScrubber] max_value_length=DEFAULT_MAX_VALUE_LENGTH, # type: int enable_backpressure_handling=True, # type: bool - issues_sampler=None, # type: Optional[Callable[[Event, Hint], Union[float, bool]]] + events_sampler=None, # type: Optional[Callable[[Event, Hint], Union[float, bool]]] ): # type: (...) -> None pass diff --git a/tests/test_client.py b/tests/test_client.py index 06b187eeb6..e82e18dac5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1225,7 +1225,7 @@ def __init__( def init_sdk(self, sentry_init): # type: (Callable[[*Any], None]) -> None sentry_init( - issues_sampler=self.sampler_function_mock, sample_rate=self.sample_rate + events_sampler=self.sampler_function_mock, sample_rate=self.sample_rate ) def raise_exception(self): @@ -1237,7 +1237,7 @@ def raise_exception(self): @pytest.mark.parametrize( "test_config", ( - # Baseline test with issues_sampler only, both floats and bools + # Baseline test with events_sampler only, both floats and bools IssuesSamplerTestConfig(sampler_function=lambda *_: 1.0, expected_events=1), IssuesSamplerTestConfig(sampler_function=lambda *_: 0.7, expected_events=1), IssuesSamplerTestConfig(sampler_function=lambda *_: 0.6, expected_events=0), @@ -1249,7 +1249,7 @@ def raise_exception(self): IssuesSamplerTestConfig(sample_rate=0.7, expected_events=1), IssuesSamplerTestConfig(sample_rate=0.6, expected_events=0), IssuesSamplerTestConfig(sample_rate=0.0, expected_events=0), - # issues_sampler takes precedence over sample_rate + # events_sampler takes precedence over sample_rate IssuesSamplerTestConfig( sampler_function=lambda *_: 1.0, sample_rate=0.0, expected_events=1 ), @@ -1291,7 +1291,7 @@ def raise_exception(self): ), ), ) -def test_issues_sampler(_, sentry_init, capture_events, test_config): +def test_events_sampler(_, sentry_init, capture_events, test_config): test_config.init_sdk(sentry_init) events = capture_events() From 4a10d4d0cc3765146a663c68886712bfbd55830a Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 20 Oct 2023 14:56:05 +0200 Subject: [PATCH 7/9] Handle invalid events_sampler return value --- sentry_sdk/client.py | 18 +++++++++++++++++- tests/test_client.py | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index d70ed23609..fe461d2425 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -465,7 +465,23 @@ def _should_sample_error( else: sample_rate = self.options["sample_rate"] - not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate + try: + not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate + except TypeError: + parameter, verb = ( + ("events_sampler", "returned") + if callable(sampler) + else ("sample_rate", "contains") + ) + logger.warning( + "The provided %s %s an invalid value. The value should be a float or a bool. Defaulting to sampling the event." + % (parameter, verb) + ) + + # If the sample_rate has an invalid value, we should sample the event, since the default behavior + # (when no sample_rate or events_sampler is provided) is to sample all events. + not_in_sample_rate = False + if not_in_sample_rate: # because we will not sample this event, record a "lost event". if self.transport: diff --git a/tests/test_client.py b/tests/test_client.py index e82e18dac5..879a0217ce 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1289,6 +1289,11 @@ def raise_exception(self): exception_to_raise=AttributeError, expected_events=0, ), + # If sampler returns invalid value, we should still send the event + IssuesSamplerTestConfig( + sampler_function=lambda *_: "This is an invalid return value for the sampler", + expected_events=1, + ), ), ) def test_events_sampler(_, sentry_init, capture_events, test_config): From 6622efcd8cb1331c5546b76a6cedc0074822e4ee Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 20 Oct 2023 15:07:31 +0200 Subject: [PATCH 8/9] Added value to warning --- sentry_sdk/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index fe461d2425..ef29fae7f1 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -474,8 +474,8 @@ def _should_sample_error( else ("sample_rate", "contains") ) logger.warning( - "The provided %s %s an invalid value. The value should be a float or a bool. Defaulting to sampling the event." - % (parameter, verb) + "The provided %s %s an invalid value of %s. The value should be a float or a bool. Defaulting to sampling the event." + % (parameter, verb, repr(sample_rate)) ) # If the sample_rate has an invalid value, we should sample the event, since the default behavior From e678ea095a5540f4e068c04897b14566fcfef6cf Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 20 Oct 2023 15:26:03 +0200 Subject: [PATCH 9/9] Rename to `error_sampler` --- sentry_sdk/client.py | 6 +++--- sentry_sdk/consts.py | 2 +- tests/test_client.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index ef29fae7f1..749ab23cfe 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -457,7 +457,7 @@ def _should_sample_error( hint, # type: Hint ): # type: (...) -> bool - sampler = self.options.get("events_sampler", None) + sampler = self.options.get("error_sampler", None) if callable(sampler): with capture_internal_exceptions(): @@ -469,7 +469,7 @@ def _should_sample_error( not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate except TypeError: parameter, verb = ( - ("events_sampler", "returned") + ("error_sampler", "returned") if callable(sampler) else ("sample_rate", "contains") ) @@ -479,7 +479,7 @@ def _should_sample_error( ) # If the sample_rate has an invalid value, we should sample the event, since the default behavior - # (when no sample_rate or events_sampler is provided) is to sample all events. + # (when no sample_rate or error_sampler is provided) is to sample all events. not_in_sample_rate = False if not_in_sample_rate: diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 80c5c4bfd4..60cb65bc15 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -262,7 +262,7 @@ def __init__( event_scrubber=None, # type: Optional[sentry_sdk.scrubber.EventScrubber] max_value_length=DEFAULT_MAX_VALUE_LENGTH, # type: int enable_backpressure_handling=True, # type: bool - events_sampler=None, # type: Optional[Callable[[Event, Hint], Union[float, bool]]] + error_sampler=None, # type: Optional[Callable[[Event, Hint], Union[float, bool]]] ): # type: (...) -> None pass diff --git a/tests/test_client.py b/tests/test_client.py index 879a0217ce..5a7a5cff16 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1225,7 +1225,7 @@ def __init__( def init_sdk(self, sentry_init): # type: (Callable[[*Any], None]) -> None sentry_init( - events_sampler=self.sampler_function_mock, sample_rate=self.sample_rate + error_sampler=self.sampler_function_mock, sample_rate=self.sample_rate ) def raise_exception(self): @@ -1237,7 +1237,7 @@ def raise_exception(self): @pytest.mark.parametrize( "test_config", ( - # Baseline test with events_sampler only, both floats and bools + # Baseline test with error_sampler only, both floats and bools IssuesSamplerTestConfig(sampler_function=lambda *_: 1.0, expected_events=1), IssuesSamplerTestConfig(sampler_function=lambda *_: 0.7, expected_events=1), IssuesSamplerTestConfig(sampler_function=lambda *_: 0.6, expected_events=0), @@ -1249,7 +1249,7 @@ def raise_exception(self): IssuesSamplerTestConfig(sample_rate=0.7, expected_events=1), IssuesSamplerTestConfig(sample_rate=0.6, expected_events=0), IssuesSamplerTestConfig(sample_rate=0.0, expected_events=0), - # events_sampler takes precedence over sample_rate + # error_sampler takes precedence over sample_rate IssuesSamplerTestConfig( sampler_function=lambda *_: 1.0, sample_rate=0.0, expected_events=1 ), @@ -1296,7 +1296,7 @@ def raise_exception(self): ), ), ) -def test_events_sampler(_, sentry_init, capture_events, test_config): +def test_error_sampler(_, sentry_init, capture_events, test_config): test_config.init_sdk(sentry_init) events = capture_events()