@@ -3,54 +3,102 @@ import type * as Sentry from '@sentry/browser';
3
3
import type { EventEnvelopeHeaders } from '@sentry/types' ;
4
4
5
5
import { sentryTest } from '../../../utils/fixtures' ;
6
- import {
7
- envelopeHeaderRequestParser ,
8
- envelopeRequestParser ,
9
- getFirstSentryEnvelopeRequest ,
10
- shouldSkipTracingTest ,
11
- waitForTransactionRequest ,
12
- } from '../../../utils/helpers' ;
6
+ import { envelopeRequestParser , shouldSkipTracingTest , waitForTransactionRequest } from '../../../utils/helpers' ;
13
7
import { getReplaySnapshot , shouldSkipReplayTest , waitForReplayRunning } from '../../../utils/replayHelpers' ;
14
8
15
9
type TestWindow = Window & { Sentry : typeof Sentry ; Replay : Sentry . Replay } ;
16
10
17
- sentryTest ( 'should add replay_id to dsc of transactions' , async ( { getLocalTestPath, page, browserName } ) => {
18
- // This is flaky on webkit, so skipping there...
19
- if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
20
- sentryTest . skip ( ) ;
21
- }
11
+ sentryTest (
12
+ 'should add replay_id to dsc of transactions when in session mode' ,
13
+ async ( { getLocalTestPath, page, browserName } ) => {
14
+ // This is flaky on webkit, so skipping there...
15
+ if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
16
+ sentryTest . skip ( ) ;
17
+ }
22
18
23
- const url = await getLocalTestPath ( { testDir : __dirname } ) ;
24
- await page . goto ( url ) ;
19
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
20
+ await page . goto ( url ) ;
25
21
26
- await waitForReplayRunning ( page ) ;
22
+ const transactionReq = waitForTransactionRequest ( page ) ;
23
+
24
+ await page . evaluate ( ( ) => {
25
+ ( window as unknown as TestWindow ) . Replay . start ( ) ;
26
+ } ) ;
27
27
28
- await page . evaluate ( ( ) => {
29
- ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
30
- scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
31
- scope . setTransactionName ( 'testTransactionDSC' ) ;
28
+ await waitForReplayRunning ( page ) ;
29
+
30
+ await page . evaluate ( ( ) => {
31
+ ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
32
+ scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
33
+ scope . setTransactionName ( 'testTransactionDSC' ) ;
34
+ } ) ;
32
35
} ) ;
33
- } ) ;
34
36
35
- const envHeader = await getFirstSentryEnvelopeRequest < EventEnvelopeHeaders > ( page , url , envelopeHeaderRequestParser ) ;
37
+ const req0 = await transactionReq ;
36
38
37
- const replay = await getReplaySnapshot ( page ) ;
39
+ const envHeader = envelopeRequestParser ( req0 , 0 ) as EventEnvelopeHeaders ;
40
+ const replay = await getReplaySnapshot ( page ) ;
38
41
39
- expect ( replay . session ?. id ) . toBeDefined ( ) ;
42
+ expect ( replay . session ?. id ) . toBeDefined ( ) ;
40
43
41
- expect ( envHeader . trace ) . toBeDefined ( ) ;
42
- expect ( envHeader . trace ) . toEqual ( {
43
- environment : 'production' ,
44
- user_segment : 'segmentB' ,
45
- sample_rate : '1' ,
46
- trace_id : expect . any ( String ) ,
47
- public_key : 'public' ,
48
- replay_id : replay . session ?. id ,
49
- } ) ;
50
- } ) ;
44
+ expect ( envHeader . trace ) . toBeDefined ( ) ;
45
+ expect ( envHeader . trace ) . toEqual ( {
46
+ environment : 'production' ,
47
+ user_segment : 'segmentB' ,
48
+ sample_rate : '1' ,
49
+ trace_id : expect . any ( String ) ,
50
+ public_key : 'public' ,
51
+ replay_id : replay . session ?. id ,
52
+ } ) ;
53
+ } ,
54
+ ) ;
51
55
52
56
sentryTest (
53
- 'should not add replay_id to dsc of transactions if replay is not enabled' ,
57
+ 'should not add replay_id to dsc of transactions when in buffer mode' ,
58
+ async ( { getLocalTestPath, page, browserName } ) => {
59
+ // This is flaky on webkit, so skipping there...
60
+ if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
61
+ sentryTest . skip ( ) ;
62
+ }
63
+
64
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
65
+ await page . goto ( url ) ;
66
+
67
+ const transactionReq = waitForTransactionRequest ( page ) ;
68
+
69
+ await page . evaluate ( ( ) => {
70
+ ( window as unknown as TestWindow ) . Replay . startBuffering ( ) ;
71
+ } ) ;
72
+
73
+ await waitForReplayRunning ( page ) ;
74
+
75
+ await page . evaluate ( ( ) => {
76
+ ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
77
+ scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
78
+ scope . setTransactionName ( 'testTransactionDSC' ) ;
79
+ } ) ;
80
+ } ) ;
81
+
82
+ const req0 = await transactionReq ;
83
+
84
+ const envHeader = envelopeRequestParser ( req0 , 0 ) as EventEnvelopeHeaders ;
85
+ const replay = await getReplaySnapshot ( page ) ;
86
+
87
+ expect ( replay . session ?. id ) . toBeDefined ( ) ;
88
+
89
+ expect ( envHeader . trace ) . toBeDefined ( ) ;
90
+ expect ( envHeader . trace ) . toEqual ( {
91
+ environment : 'production' ,
92
+ user_segment : 'segmentB' ,
93
+ sample_rate : '1' ,
94
+ trace_id : expect . any ( String ) ,
95
+ public_key : 'public' ,
96
+ } ) ;
97
+ } ,
98
+ ) ;
99
+
100
+ sentryTest (
101
+ 'should add replay_id to dsc of transactions when switching from buffer to session mode' ,
54
102
async ( { getLocalTestPath, page, browserName } ) => {
55
103
// This is flaky on webkit, so skipping there...
56
104
if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
@@ -68,13 +116,68 @@ sentryTest(
68
116
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
69
117
await page . goto ( url ) ;
70
118
119
+ const transactionReq = waitForTransactionRequest ( page ) ;
120
+
121
+ await page . evaluate ( ( ) => {
122
+ ( window as unknown as TestWindow ) . Replay . startBuffering ( ) ;
123
+ } ) ;
124
+
71
125
await waitForReplayRunning ( page ) ;
72
126
127
+ await page . evaluate ( async ( ) => {
128
+ // Manually trigger error handling
129
+ await ( window as unknown as TestWindow ) . Replay . flush ( ) ;
130
+ } ) ;
131
+
132
+ await page . evaluate ( ( ) => {
133
+ ( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
134
+ scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
135
+ scope . setTransactionName ( 'testTransactionDSC' ) ;
136
+ } ) ;
137
+ } ) ;
138
+
139
+ const req0 = await transactionReq ;
140
+
141
+ const envHeader = envelopeRequestParser ( req0 , 0 ) as EventEnvelopeHeaders ;
142
+ const replay = await getReplaySnapshot ( page ) ;
143
+
144
+ expect ( replay . session ?. id ) . toBeDefined ( ) ;
145
+ expect ( replay . recordingMode ) . toBe ( 'session' ) ;
146
+
147
+ expect ( envHeader . trace ) . toBeDefined ( ) ;
148
+ expect ( envHeader . trace ) . toEqual ( {
149
+ environment : 'production' ,
150
+ user_segment : 'segmentB' ,
151
+ sample_rate : '1' ,
152
+ trace_id : expect . any ( String ) ,
153
+ public_key : 'public' ,
154
+ replay_id : replay . session ?. id ,
155
+ } ) ;
156
+ } ,
157
+ ) ;
158
+
159
+ sentryTest (
160
+ 'should not add replay_id to dsc of transactions if replay is not enabled' ,
161
+ async ( { getLocalTestPath, page, browserName } ) => {
162
+ // This is flaky on webkit, so skipping there...
163
+ if ( shouldSkipReplayTest ( ) || shouldSkipTracingTest ( ) || browserName === 'webkit' ) {
164
+ sentryTest . skip ( ) ;
165
+ }
166
+
167
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
168
+ return route . fulfill ( {
169
+ status : 200 ,
170
+ contentType : 'application/json' ,
171
+ body : JSON . stringify ( { id : 'test-id' } ) ,
172
+ } ) ;
173
+ } ) ;
174
+
175
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
176
+ await page . goto ( url ) ;
177
+
73
178
const transactionReq = waitForTransactionRequest ( page ) ;
74
179
75
180
await page . evaluate ( async ( ) => {
76
- await ( window as unknown as TestWindow ) . Replay . stop ( ) ;
77
-
78
181
( window as unknown as TestWindow ) . Sentry . configureScope ( scope => {
79
182
scope . setUser ( { id : 'user123' , segment : 'segmentB' } ) ;
80
183
scope . setTransactionName ( 'testTransactionDSC' ) ;
0 commit comments