diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 15cd94c3a1..628cb00ee3 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -260,6 +260,13 @@ def _should_capture( if ignored_by_config_option: return False + return True + + def _should_sample_error( + self, + event, # type: Event + ): + # type: (...) -> bool not_in_sample_rate = ( self.options["sample_rate"] < 1.0 and random.random() >= self.options["sample_rate"] @@ -349,9 +356,13 @@ def capture_event( if session: self._update_session_from_event(session, event) - attachments = hint.get("attachments") is_transaction = event_opt.get("type") == "transaction" + if not is_transaction and not self._should_sample_error(event): + return None + + attachments = hint.get("attachments") + # this is outside of the `if` immediately below because even if we don't # use the value, we want to make sure we remove it before the event is # sent