Skip to content

Commit 29692eb

Browse files
authored
Update session also for non sampled events and change filter order
We have already merged #1390 where we moved `ignore_errors` before sampling. Background for the order change: We want to update the session for dropped events in case the event is dropped by sampling. Events dropped by other mechanisms should not update the session. See getsentry/develop#551 Now we would like to discuss if we can simply move sampling after `before_send` and `event_processor` and update the session right before sampling. What are implications of changing this? * How does this affect session count and session crash rate? * Will this have a negative effect on performance as `before_send` and `event_processor` will now be executed for every event instead of only being executed for sampled events? Developers may have fine tuned their sample rate for a good performance tradeoff and now we change. Also developers can supply their own implementations for both `before_send` and `event_processor` on some SDKs so we have no way of predicting performance I'm afraid. * We are uncertain why a developer chose to drop an event in `before_send` and `event_processor`: ** Was it because they want to ignore the event - then it shouldn't update the session ** Or was it to save quota - then it should update the session Please feel free to optimize the code this is just to start the discussion.
1 parent 91436cd commit 29692eb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sentry_sdk/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ def _should_capture(
260260
if ignored_by_config_option:
261261
return False
262262

263+
return True
264+
265+
def _should_sample(
266+
self,
267+
event, # type: Event
268+
):
263269
not_in_sample_rate = (
264270
self.options["sample_rate"] < 1.0
265271
and random.random() >= self.options["sample_rate"]
@@ -270,7 +276,7 @@ def _should_capture(
270276
self.transport.record_lost_event("sample_rate", data_category="error")
271277

272278
return False
273-
279+
274280
return True
275281

276282
def _update_session_from_event(
@@ -348,6 +354,9 @@ def capture_event(
348354
session = scope._session if scope else None
349355
if session:
350356
self._update_session_from_event(session, event)
357+
358+
if not self._should_sample(event):
359+
return None
351360

352361
attachments = hint.get("attachments")
353362
is_transaction = event_opt.get("type") == "transaction"

0 commit comments

Comments
 (0)