@@ -11,6 +11,7 @@ import {
11
11
import type { ReplayContainer } from '../../src/replay' ;
12
12
import { clearSession } from '../../src/session/clearSession' ;
13
13
import { addEvent } from '../../src/util/addEvent' ;
14
+ import { createOptionsEvent } from '../../src/util/handleRecordingEmit' ;
14
15
import { PerformanceEntryResource } from '../fixtures/performanceEntry/resource' ;
15
16
import type { RecordMock } from '../index' ;
16
17
import { BASE_TIMESTAMP } from '../index' ;
@@ -50,6 +51,7 @@ describe('Integration | errorSampleRate', () => {
50
51
it ( 'uploads a replay when `Sentry.captureException` is called and continues recording' , async ( ) => {
51
52
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 3 } ;
52
53
mockRecord . _emitter ( TEST_EVENT ) ;
54
+ const optionsEvent = createOptionsEvent ( replay )
53
55
54
56
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
55
57
expect ( replay ) . not . toHaveLastSentReplay ( ) ;
@@ -72,15 +74,10 @@ describe('Integration | errorSampleRate', () => {
72
74
recordingPayloadHeader : { segment_id : 0 } ,
73
75
replayEventPayload : expect . objectContaining ( {
74
76
replay_type : 'buffer' ,
75
- contexts : {
76
- replay : {
77
- error_sample_rate : 1 ,
78
- session_sample_rate : 0 ,
79
- } ,
80
- } ,
81
77
} ) ,
82
78
recordingData : JSON . stringify ( [
83
79
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
80
+ optionsEvent ,
84
81
TEST_EVENT ,
85
82
{
86
83
type : 5 ,
@@ -104,12 +101,6 @@ describe('Integration | errorSampleRate', () => {
104
101
recordingPayloadHeader : { segment_id : 1 } ,
105
102
replayEventPayload : expect . objectContaining ( {
106
103
replay_type : 'buffer' ,
107
- contexts : {
108
- replay : {
109
- error_sample_rate : 1 ,
110
- session_sample_rate : 0 ,
111
- } ,
112
- } ,
113
104
} ) ,
114
105
recordingData : JSON . stringify ( [
115
106
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + DEFAULT_FLUSH_MIN_DELAY + 40 , type : 2 } ,
@@ -161,6 +152,7 @@ describe('Integration | errorSampleRate', () => {
161
152
it ( 'manually flushes replay and does not continue to record' , async ( ) => {
162
153
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 3 } ;
163
154
mockRecord . _emitter ( TEST_EVENT ) ;
155
+ const optionsEvent = createOptionsEvent ( replay ) ;
164
156
165
157
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
166
158
expect ( replay ) . not . toHaveLastSentReplay ( ) ;
@@ -186,6 +178,7 @@ describe('Integration | errorSampleRate', () => {
186
178
} ) ,
187
179
recordingData : JSON . stringify ( [
188
180
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
181
+ optionsEvent ,
189
182
TEST_EVENT ,
190
183
{
191
184
type : 5 ,
@@ -218,15 +211,10 @@ describe('Integration | errorSampleRate', () => {
218
211
recordingPayloadHeader : { segment_id : 0 } ,
219
212
replayEventPayload : expect . objectContaining ( {
220
213
replay_type : 'buffer' ,
221
- contexts : {
222
- replay : {
223
- error_sample_rate : 1 ,
224
- session_sample_rate : 0 ,
225
- } ,
226
- } ,
227
214
} ) ,
228
215
recordingData : JSON . stringify ( [
229
216
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
217
+ optionsEvent ,
230
218
TEST_EVENT ,
231
219
{
232
220
type : 5 ,
@@ -532,6 +520,7 @@ describe('Integration | errorSampleRate', () => {
532
520
it ( 'has the correct timestamps with deferred root event and last replay update' , async ( ) => {
533
521
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 3 } ;
534
522
mockRecord . _emitter ( TEST_EVENT ) ;
523
+ const optionsEvent = createOptionsEvent ( replay ) ;
535
524
536
525
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
537
526
expect ( replay ) . not . toHaveLastSentReplay ( ) ;
@@ -548,7 +537,7 @@ describe('Integration | errorSampleRate', () => {
548
537
await new Promise ( process . nextTick ) ;
549
538
550
539
expect ( replay ) . toHaveSentReplay ( {
551
- recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
540
+ recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , optionsEvent , TEST_EVENT ] ) ,
552
541
replayEventPayload : expect . objectContaining ( {
553
542
replay_start_timestamp : BASE_TIMESTAMP / 1000 ,
554
543
// the exception happens roughly 10 seconds after BASE_TIMESTAMP
@@ -584,6 +573,7 @@ describe('Integration | errorSampleRate', () => {
584
573
// in production, this happens at a time interval
585
574
// session started time should be updated to this current timestamp
586
575
mockRecord . takeFullSnapshot ( true ) ;
576
+ const optionsEvent = createOptionsEvent ( replay ) ;
587
577
588
578
jest . runAllTimers ( ) ;
589
579
jest . advanceTimersByTime ( 20 ) ;
@@ -611,6 +601,7 @@ describe('Integration | errorSampleRate', () => {
611
601
timestamp : BASE_TIMESTAMP + ELAPSED + 20 ,
612
602
type : 2 ,
613
603
} ,
604
+ optionsEvent ,
614
605
] ) ,
615
606
} ) ;
616
607
} ) ;
@@ -726,8 +717,9 @@ it('sends a replay after loading the session multiple times', async () => {
726
717
} ,
727
718
autoStart : false ,
728
719
} ) ;
729
- // @ts -ignore this is protected, but we want to call it for this test
730
- integration . _initialize ( ) ;
720
+ integration [ '_initialize' ] ( ) ;
721
+
722
+ const optionsEvent = createOptionsEvent ( replay )
731
723
732
724
jest . runAllTimers ( ) ;
733
725
@@ -744,12 +736,14 @@ it('sends a replay after loading the session multiple times', async () => {
744
736
await new Promise ( process . nextTick ) ;
745
737
746
738
expect ( replay ) . toHaveSentReplay ( {
747
- recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
739
+ recordingPayloadHeader : { segment_id : 0 } ,
740
+ recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , optionsEvent , TEST_EVENT ] ) ,
748
741
} ) ;
749
742
750
743
// Latest checkout when we call `startRecording` again after uploading segment
751
744
// after an error occurs (e.g. when we switch to session replay recording)
752
745
expect ( replay ) . toHaveLastSentReplay ( {
746
+ recordingPayloadHeader : { segment_id : 1 } ,
753
747
recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + 5040 , type : 2 } ] ) ,
754
748
} ) ;
755
749
} ) ;
0 commit comments