Skip to content

Commit

Permalink
Always sample checkin regardless of sample_rate (#2279)
Browse files Browse the repository at this point in the history
* Always sample checkin regardless of sample_rate

* Added test case for cron check-in

* Test for sample rate affecting errors
  • Loading branch information
szokeasaurusrex committed Jul 31, 2023
1 parent d48d3eb commit 69866be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 6 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,16 @@ def capture_event(
self._update_session_from_event(session, event)

is_transaction = event_opt.get("type") == "transaction"
is_checkin = event_opt.get("type") == "check_in"

if not is_transaction and not self._should_sample_error(event):
if (
not is_transaction
and not is_checkin
and not self._should_sample_error(event)
):
return None

tracing_enabled = has_tracing_enabled(self.options)
is_checkin = event_opt.get("type") == "check_in"
attachments = hint.get("attachments")

trace_context = event_opt.get("contexts", {}).get("trace") or {}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ def test_capture_checkin_simple(sentry_init):
assert check_in_id == "112233"


def test_sample_rate_doesnt_affect_crons(sentry_init, capture_envelopes):
sentry_init(sample_rate=0)
envelopes = capture_envelopes()

capture_checkin(check_in_id="112233")

assert len(envelopes) == 1

check_in = envelopes[0].items[0].payload.json
assert check_in["check_in_id"] == "112233"


def test_capture_checkin_new_id(sentry_init):
sentry_init()

Expand Down
14 changes: 13 additions & 1 deletion tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from sentry_sdk import Hub, start_span, start_transaction
from sentry_sdk import Hub, start_span, start_transaction, capture_exception
from sentry_sdk.tracing import Transaction
from sentry_sdk.utils import logger

Expand Down Expand Up @@ -226,6 +226,18 @@ def test_passes_custom_samling_context_from_start_transaction_to_traces_sampler(
)


def test_sample_rate_affects_errors(sentry_init, capture_events):
sentry_init(sample_rate=0)
events = capture_events()

try:
1 / 0
except Exception:
capture_exception()

assert len(events) == 0


@pytest.mark.parametrize(
"traces_sampler_return_value",
[
Expand Down

0 comments on commit 69866be

Please sign in to comment.