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