Skip to content

Commit 91436cd

Browse files
Change ordering of event drop mechanisms (getsentry#1390)
* Change ordering of event drop mechanisms As requested by @mitsuhiko this PR shall serve as basis for discussing the ordering of event drop mechanisms and its implications. We are planning for `sample_rate` to update the session counts despite dropping an event (see getsentry/develop#551 and getsentry/develop#537). Without changing the order of filtering mechanisms this would mean any event dropped by `sample_rate` would update the session even if it would be dropped by `ignore_errors` which should not update the session counts when dropping an event. By changing the order we would first drop `ignored_errors` and only then check `sample_rate`, so session counts would not be affected in the case mentioned before. The same reasoning could probably be applied to `event_processor` and `before_send` but we don't know why a developer decided to drop an event there. Was it because they don't care about the event (then session should not be updated) or to save quota (session should be updated)? Also these may be more expensive in terms of performance (developers can provide their own implementations for both of those on some SDKs). So moving them before `sample_rate` would execute `before_send` and `event_processor` for every event instead of only doing it for the sampled events. Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
1 parent 7d84f41 commit 91436cd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

sentry_sdk/client.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,18 @@ def _is_ignored_error(self, event, hint):
224224
if exc_info is None:
225225
return False
226226

227-
type_name = get_type_name(exc_info[0])
228-
full_name = "%s.%s" % (exc_info[0].__module__, type_name)
227+
error = exc_info[0]
228+
error_type_name = get_type_name(exc_info[0])
229+
error_full_name = "%s.%s" % (exc_info[0].__module__, error_type_name)
229230

230-
for errcls in self.options["ignore_errors"]:
231+
for ignored_error in self.options["ignore_errors"]:
231232
# String types are matched against the type name in the
232233
# exception only
233-
if isinstance(errcls, string_types):
234-
if errcls == full_name or errcls == type_name:
234+
if isinstance(ignored_error, string_types):
235+
if ignored_error == error_full_name or ignored_error == error_type_name:
235236
return True
236237
else:
237-
if issubclass(exc_info[0], errcls):
238+
if issubclass(error, ignored_error):
238239
return True
239240

240241
return False
@@ -246,23 +247,28 @@ def _should_capture(
246247
scope=None, # type: Optional[Scope]
247248
):
248249
# type: (...) -> bool
249-
if event.get("type") == "transaction":
250-
# Transactions are sampled independent of error events.
250+
# Transactions are sampled independent of error events.
251+
is_transaction = event.get("type") == "transaction"
252+
if is_transaction:
251253
return True
252254

253-
if scope is not None and not scope._should_capture:
255+
ignoring_prevents_recursion = scope is not None and not scope._should_capture
256+
if ignoring_prevents_recursion:
254257
return False
255258

256-
if (
259+
ignored_by_config_option = self._is_ignored_error(event, hint)
260+
if ignored_by_config_option:
261+
return False
262+
263+
not_in_sample_rate = (
257264
self.options["sample_rate"] < 1.0
258265
and random.random() >= self.options["sample_rate"]
259-
):
260-
# record a lost event if we did not sample this.
266+
)
267+
if not_in_sample_rate:
268+
# because we will not sample this event, record a "lost event".
261269
if self.transport:
262270
self.transport.record_lost_event("sample_rate", data_category="error")
263-
return False
264271

265-
if self._is_ignored_error(event, hint):
266272
return False
267273

268274
return True

0 commit comments

Comments
 (0)