@@ -296,3 +296,123 @@ sentryTest(
296
296
) ;
297
297
} ,
298
298
) ;
299
+
300
+ // Doing this in buffer mode to test changing error sample rate after first
301
+ // error happens.
302
+ sentryTest ( '[buffer-mode] can sample on each error event' , async ( { getLocalTestPath, page, browserName } ) => {
303
+ // This was sometimes flaky on firefox/webkit, so skipping for now
304
+ if ( shouldSkipReplayTest ( ) || [ 'firefox' , 'webkit' ] . includes ( browserName ) ) {
305
+ sentryTest . skip ( ) ;
306
+ }
307
+
308
+ let callsToSentry = 0 ;
309
+ const errorEventIds : string [ ] = [ ] ;
310
+ const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
311
+ const reqErrorPromise = waitForErrorRequest ( page ) ;
312
+
313
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
314
+ const event = envelopeRequestParser ( route . request ( ) ) ;
315
+ // error events have no type field
316
+ if ( event && ! event . type && event . event_id ) {
317
+ errorEventIds . push ( event . event_id ) ;
318
+ }
319
+ // We only want to count errors & replays here
320
+ if ( event && ( ! event . type || isReplayEvent ( event ) ) ) {
321
+ callsToSentry ++ ;
322
+ }
323
+
324
+ return route . fulfill ( {
325
+ status : 200 ,
326
+ contentType : 'application/json' ,
327
+ body : JSON . stringify ( { id : 'test-id' } ) ,
328
+ } ) ;
329
+ } ) ;
330
+
331
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
332
+
333
+ await page . goto ( url ) ;
334
+ // Start buffering and assert that it is enabled
335
+ expect (
336
+ await page . evaluate ( ( ) => {
337
+ const replayIntegration = ( window as unknown as Window & { Replay : InstanceType < typeof Replay > } ) . Replay ;
338
+ // @ts -ignore private
339
+ const replay = replayIntegration . _replay ;
340
+ replayIntegration . startBuffering ( ) ;
341
+ return replay . isEnabled ( ) ;
342
+ } ) ,
343
+ ) . toBe ( true ) ;
344
+
345
+ await page . click ( '#go-background' ) ;
346
+ await page . click ( '#error' ) ;
347
+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
348
+
349
+ // 1 error, no replay
350
+ expect ( callsToSentry ) . toEqual ( 1 ) ;
351
+ await reqErrorPromise ;
352
+
353
+ await page . evaluate ( async ( ) => {
354
+ const replayIntegration = ( window as unknown as Window & { Replay : Replay } ) . Replay ;
355
+ // @ts -ignore private member, change errorSampleRate
356
+ replayIntegration . _replay . _options . errorSampleRate = 1.0 ;
357
+ } ) ;
358
+
359
+ // Error sample rate is now at 1.0, this error should create a replay
360
+ await page . click ( '#error2' ) ;
361
+ await reqErrorPromise ;
362
+
363
+ const req0 = await reqPromise0 ;
364
+
365
+ // 2 errors, 1 flush
366
+ expect ( callsToSentry ) . toEqual ( 3 ) ;
367
+
368
+ const event0 = getReplayEvent ( req0 ) ;
369
+ const content0 = getReplayRecordingContent ( req0 ) ;
370
+
371
+ expect ( event0 ) . toEqual (
372
+ getExpectedReplayEvent ( {
373
+ contexts : { replay : { error_sample_rate : 1 , session_sample_rate : 0 } } ,
374
+ error_ids : errorEventIds ,
375
+ replay_type : 'buffer' ,
376
+ } ) ,
377
+ ) ;
378
+
379
+ // The first event should have both, full and incremental snapshots,
380
+ // as we recorded and kept all events in the buffer
381
+ expect ( content0 . fullSnapshots ) . toHaveLength ( 1 ) ;
382
+ // We want to make sure that the event that triggered the error was
383
+ // recorded, as well as the first error that did not get sampled.
384
+ expect ( content0 . breadcrumbs ) . toEqual (
385
+ expect . arrayContaining ( [
386
+ {
387
+ ...expectedClickBreadcrumb ,
388
+ message : 'body > button#error' ,
389
+ data : {
390
+ nodeId : expect . any ( Number ) ,
391
+ node : {
392
+ attributes : {
393
+ id : 'error' ,
394
+ } ,
395
+ id : expect . any ( Number ) ,
396
+ tagName : 'button' ,
397
+ textContent : '***** *****' ,
398
+ } ,
399
+ } ,
400
+ } ,
401
+ {
402
+ ...expectedClickBreadcrumb ,
403
+ message : 'body > button#error2' ,
404
+ data : {
405
+ nodeId : expect . any ( Number ) ,
406
+ node : {
407
+ attributes : {
408
+ id : 'error2' ,
409
+ } ,
410
+ id : expect . any ( Number ) ,
411
+ tagName : 'button' ,
412
+ textContent : '******* *****' ,
413
+ } ,
414
+ } ,
415
+ } ,
416
+ ] ) ,
417
+ ) ;
418
+ } ) ;
0 commit comments