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' ;
23import { NodeClient , setCurrentClient } from '@sentry/node-experimental' ;
34import * as SentryNode from '@sentry/node-experimental' ;
4- import type { Transaction } from '@sentry/types' ;
5+ import type { Span , Transaction } from '@sentry/types' ;
56import type { Handle } from '@sveltejs/kit' ;
67import { redirect } from '@sveltejs/kit' ;
78import { vi } from 'vitest' ;
@@ -117,9 +118,9 @@ describe('handleSentry', () => {
117118 } ) ;
118119
119120 it ( "creates a transaction if there's no active span" , async ( ) => {
120- let ref : any = undefined ;
121+ let _span : Span | undefined = undefined ;
121122 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
122- ref = transaction ;
123+ _span = transaction ;
123124 } ) ;
124125
125126 try {
@@ -128,22 +129,25 @@ describe('handleSentry', () => {
128129 //
129130 }
130131
131- expect ( ref ) . toBeDefined ( ) ;
132+ expect ( _span ! ) . toBeDefined ( ) ;
132133
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' ) ;
137138
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 ) ;
140144 } ) ;
141145
142146 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 ;
144148 let txnCount = 0 ;
145149 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
146- ref = transaction ;
150+ _span = transaction ;
147151 ++ txnCount ;
148152 } ) ;
149153
@@ -164,17 +168,19 @@ describe('handleSentry', () => {
164168 }
165169
166170 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' ) ;
168177
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 ( ) ;
173179
174- expect ( ref . endTimestamp ) . toBeDefined ( ) ;
180+ // eslint-disable-next-line deprecation/deprecation
181+ const spans = ( _span ! as TransactionClass ) . spanRecorder ?. spans ?. map ( spanToJSON ) ;
175182
176- expect ( ref . spanRecorder . spans ) . toHaveLength ( 2 ) ;
177- const spans = ref . spanRecorder . spans . map ( spanToJSON ) ;
183+ expect ( spans ) . toHaveLength ( 2 ) ;
178184 expect ( spans ) . toEqual (
179185 expect . arrayContaining ( [
180186 expect . objectContaining ( { op : 'http.server' , description : 'GET /users/[id]' } ) ,
@@ -198,9 +204,9 @@ describe('handleSentry', () => {
198204 } ,
199205 } ) ;
200206
201- let ref : any = undefined ;
207+ let _span : Span | undefined = undefined ;
202208 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
203- ref = transaction ;
209+ _span = transaction ;
204210 } ) ;
205211
206212 try {
@@ -209,10 +215,10 @@ describe('handleSentry', () => {
209215 //
210216 }
211217
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 ) ;
216222 } ) ;
217223
218224 it ( 'creates a transaction with dynamic sampling context from baggage header' , async ( ) => {
@@ -238,9 +244,9 @@ describe('handleSentry', () => {
238244 } ,
239245 } ) ;
240246
241- let ref : any = undefined ;
247+ let _span : Span | undefined = undefined ;
242248 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
243- ref = transaction ;
249+ _span = transaction ;
244250 } ) ;
245251
246252 try {
@@ -249,8 +255,8 @@ describe('handleSentry', () => {
249255 //
250256 }
251257
252- expect ( ref ) . toBeDefined ( ) ;
253- expect ( ref . metadata . dynamicSamplingContext ) . toEqual ( {
258+ expect ( _span ! ) . toBeDefined ( ) ;
259+ expect ( _span . metadata . dynamicSamplingContext ) . toEqual ( {
254260 environment : 'production' ,
255261 release : '1.0.0' ,
256262 public_key : 'dogsarebadatkeepingsecrets' ,
@@ -302,9 +308,9 @@ describe('handleSentry', () => {
302308 } ) ;
303309
304310 it ( "doesn't create a transaction if there's no route" , async ( ) => {
305- let ref : any = undefined ;
311+ let _span : Span | undefined = undefined ;
306312 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
307- ref = transaction ;
313+ _span = transaction ;
308314 } ) ;
309315
310316 try {
@@ -313,13 +319,13 @@ describe('handleSentry', () => {
313319 //
314320 }
315321
316- expect ( ref ) . toBeUndefined ( ) ;
322+ expect ( _span ! ) . toBeUndefined ( ) ;
317323 } ) ;
318324
319325 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 ;
321327 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
322- ref = transaction ;
328+ _span = transaction ;
323329 } ) ;
324330
325331 try {
@@ -331,7 +337,7 @@ describe('handleSentry', () => {
331337 //
332338 }
333339
334- expect ( ref ) . toBeDefined ( ) ;
340+ expect ( _span ! ) . toBeDefined ( ) ;
335341 } ) ;
336342 } ) ;
337343} ) ;
0 commit comments