Skip to content

Always sample checkin regardless of sample_rate #2279

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

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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