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