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

Fixed local var not present when error in users error_sampler function #2511

Merged
merged 8 commits into from
Dec 13, 2023
16 changes: 12 additions & 4 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,28 @@
hint, # type: Hint
):
# type: (...) -> bool
sampler = self.options.get("error_sampler", None)
error_sampler = self.options.get("error_sampler", None)

if callable(sampler):
if callable(error_sampler):
antonpirker marked this conversation as resolved.
Show resolved Hide resolved
with capture_internal_exceptions():
sample_rate = sampler(event, hint)
sample_rate = error_sampler(event, hint)
else:
sample_rate = self.options["sample_rate"]

try:
not_in_sample_rate = sample_rate < 1.0 and random.random() >= sample_rate
except NameError:
logger.warning(

Check warning on line 480 in sentry_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/client.py#L480

Added line #L480 was not covered by tests
"The provided error_sampler raised an error. Defaulting to sampling the event."
)

# If the error_sampler raised an error, we should sample the event, since the default behavior
# (when no sample_rate or error_sampler is provided) is to sample all events.
not_in_sample_rate = False

Check warning on line 486 in sentry_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/client.py#L486

Added line #L486 was not covered by tests
except TypeError:
parameter, verb = (
("error_sampler", "returned")
if callable(sampler)
if callable(error_sampler)
else ("sample_rate", "contains")
)
logger.warning(
Expand Down