1
- import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , addTracingExtensions , spanToJSON } from '@sentry/core' ;
1
+ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , addTracingExtensions , spanIsSampled , spanToJSON } from '@sentry/core' ;
2
+ import type { Transaction as TransactionClass } from '@sentry/core' ;
2
3
import { NodeClient , setCurrentClient } from '@sentry/node-experimental' ;
3
4
import * as SentryNode from '@sentry/node-experimental' ;
4
- import type { Transaction } from '@sentry/types' ;
5
+ import type { Span , Transaction } from '@sentry/types' ;
5
6
import type { Handle } from '@sveltejs/kit' ;
6
7
import { redirect } from '@sveltejs/kit' ;
7
8
import { vi } from 'vitest' ;
@@ -117,9 +118,9 @@ describe('handleSentry', () => {
117
118
} ) ;
118
119
119
120
it ( "creates a transaction if there's no active span" , async ( ) => {
120
- let ref : any = undefined ;
121
+ let _span : Span | undefined = undefined ;
121
122
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
122
- ref = transaction ;
123
+ _span = transaction ;
123
124
} ) ;
124
125
125
126
try {
@@ -128,22 +129,25 @@ describe('handleSentry', () => {
128
129
//
129
130
}
130
131
131
- expect ( ref ) . toBeDefined ( ) ;
132
+ expect ( _span ! ) . toBeDefined ( ) ;
132
133
133
- expect ( spanToJSON ( ref ) . description ) . toEqual ( 'GET /users/[id]' ) ;
134
- expect ( spanToJSON ( ref ) . op ) . toEqual ( 'http.server' ) ;
135
- expect ( ref . status ) . toEqual ( isError ? 'internal_error' : 'ok' ) ;
136
- expect ( ref . attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toEqual ( 'route' ) ;
134
+ expect ( spanToJSON ( _span ! ) . description ) . toEqual ( 'GET /users/[id]' ) ;
135
+ expect ( spanToJSON ( _span ! ) . op ) . toEqual ( 'http.server' ) ;
136
+ expect ( spanToJSON ( _span ! ) . status ) . toEqual ( isError ? 'internal_error' : 'ok' ) ;
137
+ expect ( spanToJSON ( _span ! ) . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toEqual ( 'route' ) ;
137
138
138
- expect ( ref . endTimestamp ) . toBeDefined ( ) ;
139
- expect ( ref . spanRecorder . spans ) . toHaveLength ( 1 ) ;
139
+ expect ( spanToJSON ( _span ! ) . timestamp ) . toBeDefined ( ) ;
140
+
141
+ // eslint-disable-next-line deprecation/deprecation
142
+ const spans = ( _span ! as TransactionClass ) . spanRecorder ?. spans ;
143
+ expect ( spans ) . toHaveLength ( 1 ) ;
140
144
} ) ;
141
145
142
146
it ( 'creates a child span for nested server calls (i.e. if there is an active span)' , async ( ) => {
143
- let ref : any = undefined ;
147
+ let _span : Span | undefined = undefined ;
144
148
let txnCount = 0 ;
145
149
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
146
- ref = transaction ;
150
+ _span = transaction ;
147
151
++ txnCount ;
148
152
} ) ;
149
153
@@ -164,17 +168,19 @@ describe('handleSentry', () => {
164
168
}
165
169
166
170
expect ( txnCount ) . toEqual ( 1 ) ;
167
- expect ( ref ) . toBeDefined ( ) ;
171
+ expect ( _span ! ) . toBeDefined ( ) ;
172
+
173
+ expect ( spanToJSON ( _span ! ) . description ) . toEqual ( 'GET /users/[id]' ) ;
174
+ expect ( spanToJSON ( _span ! ) . op ) . toEqual ( 'http.server' ) ;
175
+ expect ( spanToJSON ( _span ! ) . status ) . toEqual ( isError ? 'internal_error' : 'ok' ) ;
176
+ expect ( spanToJSON ( _span ! ) . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toEqual ( 'route' ) ;
168
177
169
- expect ( spanToJSON ( ref ) . description ) . toEqual ( 'GET /users/[id]' ) ;
170
- expect ( spanToJSON ( ref ) . op ) . toEqual ( 'http.server' ) ;
171
- expect ( ref . status ) . toEqual ( isError ? 'internal_error' : 'ok' ) ;
172
- expect ( ref . attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toEqual ( 'route' ) ;
178
+ expect ( spanToJSON ( _span ! ) . timestamp ) . toBeDefined ( ) ;
173
179
174
- expect ( ref . endTimestamp ) . toBeDefined ( ) ;
180
+ // eslint-disable-next-line deprecation/deprecation
181
+ const spans = ( _span ! as TransactionClass ) . spanRecorder ?. spans ?. map ( spanToJSON ) ;
175
182
176
- expect ( ref . spanRecorder . spans ) . toHaveLength ( 2 ) ;
177
- const spans = ref . spanRecorder . spans . map ( spanToJSON ) ;
183
+ expect ( spans ) . toHaveLength ( 2 ) ;
178
184
expect ( spans ) . toEqual (
179
185
expect . arrayContaining ( [
180
186
expect . objectContaining ( { op : 'http.server' , description : 'GET /users/[id]' } ) ,
@@ -198,9 +204,9 @@ describe('handleSentry', () => {
198
204
} ,
199
205
} ) ;
200
206
201
- let ref : any = undefined ;
207
+ let _span : Span | undefined = undefined ;
202
208
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
203
- ref = transaction ;
209
+ _span = transaction ;
204
210
} ) ;
205
211
206
212
try {
@@ -209,10 +215,10 @@ describe('handleSentry', () => {
209
215
//
210
216
}
211
217
212
- expect ( ref ) . toBeDefined ( ) ;
213
- expect ( ref . traceId ) . toEqual ( '1234567890abcdef1234567890abcdef' ) ;
214
- expect ( ref . parentSpanId ) . toEqual ( '1234567890abcdef' ) ;
215
- expect ( ref . sampled ) . toEqual ( true ) ;
218
+ expect ( _span ! ) . toBeDefined ( ) ;
219
+ expect ( _span ! . spanContext ( ) . traceId ) . toEqual ( '1234567890abcdef1234567890abcdef' ) ;
220
+ expect ( spanToJSON ( _span ! ) . parent_span_id ) . toEqual ( '1234567890abcdef' ) ;
221
+ expect ( spanIsSampled ( _span ! ) ) . toEqual ( true ) ;
216
222
} ) ;
217
223
218
224
it ( 'creates a transaction with dynamic sampling context from baggage header' , async ( ) => {
@@ -238,9 +244,9 @@ describe('handleSentry', () => {
238
244
} ,
239
245
} ) ;
240
246
241
- let ref : any = undefined ;
247
+ let _span : Span | undefined = undefined ;
242
248
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
243
- ref = transaction ;
249
+ _span = transaction ;
244
250
} ) ;
245
251
246
252
try {
@@ -249,8 +255,8 @@ describe('handleSentry', () => {
249
255
//
250
256
}
251
257
252
- expect ( ref ) . toBeDefined ( ) ;
253
- expect ( ref . metadata . dynamicSamplingContext ) . toEqual ( {
258
+ expect ( _span ! ) . toBeDefined ( ) ;
259
+ expect ( _span . metadata . dynamicSamplingContext ) . toEqual ( {
254
260
environment : 'production' ,
255
261
release : '1.0.0' ,
256
262
public_key : 'dogsarebadatkeepingsecrets' ,
@@ -302,9 +308,9 @@ describe('handleSentry', () => {
302
308
} ) ;
303
309
304
310
it ( "doesn't create a transaction if there's no route" , async ( ) => {
305
- let ref : any = undefined ;
311
+ let _span : Span | undefined = undefined ;
306
312
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
307
- ref = transaction ;
313
+ _span = transaction ;
308
314
} ) ;
309
315
310
316
try {
@@ -313,13 +319,13 @@ describe('handleSentry', () => {
313
319
//
314
320
}
315
321
316
- expect ( ref ) . toBeUndefined ( ) ;
322
+ expect ( _span ! ) . toBeUndefined ( ) ;
317
323
} ) ;
318
324
319
325
it ( "Creates a transaction if there's no route but `handleUnknownRequests` is true" , async ( ) => {
320
- let ref : any = undefined ;
326
+ let _span : Span | undefined = undefined ;
321
327
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
322
- ref = transaction ;
328
+ _span = transaction ;
323
329
} ) ;
324
330
325
331
try {
@@ -331,7 +337,7 @@ describe('handleSentry', () => {
331
337
//
332
338
}
333
339
334
- expect ( ref ) . toBeDefined ( ) ;
340
+ expect ( _span ! ) . toBeDefined ( ) ;
335
341
} ) ;
336
342
} ) ;
337
343
} ) ;
0 commit comments