File tree 2 files changed +18
-16
lines changed
2 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -158,14 +158,6 @@ impl Client {
158
158
mut event : Event < ' static > ,
159
159
scope : Option < & Scope > ,
160
160
) -> Option < Event < ' static > > {
161
- if let Some ( scope) = scope {
162
- scope. update_session_from_event ( & event) ;
163
- }
164
-
165
- if !self . sample_should_send ( ) {
166
- return None ;
167
- }
168
-
169
161
// event_id and sdk_info are set before the processors run so that the
170
162
// processors can poke around in that data.
171
163
if event. event_id . is_nil ( ) {
@@ -211,10 +203,20 @@ impl Client {
211
203
if let Some ( ref func) = self . options . before_send {
212
204
sentry_debug ! ( "invoking before_send callback" ) ;
213
205
let id = event. event_id ;
214
- func ( event) . or_else ( move || {
206
+ if let Some ( processed_event) = func ( event) {
207
+ event = processed_event;
208
+ } else {
215
209
sentry_debug ! ( "before_send dropped event {:?}" , id) ;
216
- None
217
- } )
210
+ return None ;
211
+ }
212
+ }
213
+
214
+ if let Some ( scope) = scope {
215
+ scope. update_session_from_event ( & event) ;
216
+ }
217
+
218
+ if !self . sample_should_send ( ) {
219
+ None
218
220
} else {
219
221
Some ( event)
220
222
}
Original file line number Diff line number Diff line change @@ -439,8 +439,9 @@ mod tests {
439
439
sentry:: start_session ( ) ;
440
440
}
441
441
442
- // this error will be discarded because of the event processor,
443
- // but the session will still be updated accordingly.
442
+ // This error will be discarded because of the event processor,
443
+ // and session will not be updated.
444
+ // Only events dropped due to sampling should update the session.
444
445
let err = "NaN" . parse :: < usize > ( ) . unwrap_err ( ) ;
445
446
sentry:: capture_error ( & err) ;
446
447
} ,
@@ -469,11 +470,10 @@ mod tests {
469
470
470
471
assert_eq ! ( aggregates[ 0 ] . distinct_id, None ) ;
471
472
assert_eq ! ( aggregates[ 0 ] . exited, 50 ) ;
472
- assert_eq ! ( aggregates[ 1 ] . errored, 1 ) ;
473
473
474
+ assert_eq ! ( aggregates[ 1 ] . errored, 0 ) ;
474
475
assert_eq ! ( aggregates[ 1 ] . distinct_id, Some ( "foo-bar" . into( ) ) ) ;
475
- assert_eq ! ( aggregates[ 1 ] . exited, 49 ) ;
476
- assert_eq ! ( aggregates[ 1 ] . errored, 1 ) ;
476
+ assert_eq ! ( aggregates[ 1 ] . exited, 50 ) ;
477
477
} else {
478
478
panic ! ( "expected session" ) ;
479
479
}
You can’t perform that action at this time.
0 commit comments