@@ -2,6 +2,8 @@ import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
2
2
3
3
import type { Event , Span } from '@sentry/types' ;
4
4
import {
5
+ SentryNonRecordingSpan ,
6
+ SentrySpan ,
5
7
addTracingExtensions ,
6
8
getActiveSpan ,
7
9
getClient ,
@@ -40,6 +42,7 @@ describe('startIdleSpan', () => {
40
42
it ( 'sets & unsets the idle span on the scope' , ( ) => {
41
43
const idleSpan = startIdleSpan ( { name : 'foo' } ) ;
42
44
expect ( idleSpan ) . toBeDefined ( ) ;
45
+ expect ( idleSpan ) . toBeInstanceOf ( SentrySpan ) ;
43
46
44
47
expect ( getActiveSpan ( ) ) . toBe ( idleSpan ) ;
45
48
@@ -49,12 +52,26 @@ describe('startIdleSpan', () => {
49
52
expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
50
53
} ) ;
51
54
55
+ it ( 'returns non recording span if tracing is disabled' , ( ) => {
56
+ const options = getDefaultTestClientOptions ( { dsn } ) ;
57
+ const client = new TestClient ( options ) ;
58
+ setCurrentClient ( client ) ;
59
+ client . init ( ) ;
60
+
61
+ const idleSpan = startIdleSpan ( { name : 'foo' } ) ;
62
+ expect ( idleSpan ) . toBeDefined ( ) ;
63
+ expect ( idleSpan ) . toBeInstanceOf ( SentryNonRecordingSpan ) ;
64
+
65
+ // not set as active span, though
66
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
67
+ } ) ;
68
+
52
69
it ( 'does not finish idle span if there are still active activities' , ( ) => {
53
- const idleSpan = startIdleSpan ( { name : 'foo' } ) ! ;
70
+ const idleSpan = startIdleSpan ( { name : 'foo' } ) ;
54
71
expect ( idleSpan ) . toBeDefined ( ) ;
55
72
56
73
startSpanManual ( { name : 'inner1' } , span => {
57
- const childSpan = startInactiveSpan ( { name : 'inner2' } ) ! ;
74
+ const childSpan = startInactiveSpan ( { name : 'inner2' } ) ;
58
75
59
76
span ?. end ( ) ;
60
77
jest . advanceTimersByTime ( TRACING_DEFAULTS . idleTimeout + 1 ) ;
@@ -72,7 +89,7 @@ describe('startIdleSpan', () => {
72
89
73
90
it ( 'calls beforeSpanEnd callback before finishing' , ( ) => {
74
91
const beforeSpanEnd = jest . fn ( ) ;
75
- const idleSpan = startIdleSpan ( { name : 'foo' } , { beforeSpanEnd } ) ! ;
92
+ const idleSpan = startIdleSpan ( { name : 'foo' } , { beforeSpanEnd } ) ;
76
93
expect ( idleSpan ) . toBeDefined ( ) ;
77
94
78
95
expect ( beforeSpanEnd ) . not . toHaveBeenCalled ( ) ;
@@ -108,7 +125,7 @@ describe('startIdleSpan', () => {
108
125
const inner = startInactiveSpan ( { name : 'from beforeSpanEnd' , startTime : baseTimeInSeconds } ) ;
109
126
inner ?. end ( baseTimeInSeconds ) ;
110
127
} ) ;
111
- const idleSpan = startIdleSpan ( { name : 'idle span 2' , startTime : baseTimeInSeconds } , { beforeSpanEnd } ) ! ;
128
+ const idleSpan = startIdleSpan ( { name : 'idle span 2' , startTime : baseTimeInSeconds } , { beforeSpanEnd } ) ;
112
129
expect ( idleSpan ) . toBeDefined ( ) ;
113
130
114
131
expect ( beforeSpanEnd ) . not . toHaveBeenCalled ( ) ;
@@ -152,26 +169,26 @@ describe('startIdleSpan', () => {
152
169
// We want to accomodate a bit of drift there, so we ensure this starts earlier...
153
170
const baseTimeInSeconds = Math . floor ( Date . now ( ) / 1000 ) - 9999 ;
154
171
155
- const idleSpan = startIdleSpan ( { name : 'idle span' , startTime : baseTimeInSeconds } ) ! ;
172
+ const idleSpan = startIdleSpan ( { name : 'idle span' , startTime : baseTimeInSeconds } ) ;
156
173
expect ( idleSpan ) . toBeDefined ( ) ;
157
174
158
175
// regular child - should be kept
159
176
const regularSpan = startInactiveSpan ( {
160
177
name : 'regular span' ,
161
178
startTime : baseTimeInSeconds + 2 ,
162
- } ) ! ;
179
+ } ) ;
163
180
164
181
// discardedSpan - startTimestamp is too large
165
- const discardedSpan = startInactiveSpan ( { name : 'discarded span' , startTime : baseTimeInSeconds + 99 } ) ! ;
182
+ const discardedSpan = startInactiveSpan ( { name : 'discarded span' , startTime : baseTimeInSeconds + 99 } ) ;
166
183
// discardedSpan2 - endTime is too large
167
- const discardedSpan2 = startInactiveSpan ( { name : 'discarded span' , startTime : baseTimeInSeconds + 3 } ) ! ;
184
+ const discardedSpan2 = startInactiveSpan ( { name : 'discarded span' , startTime : baseTimeInSeconds + 3 } ) ;
168
185
discardedSpan2 . end ( baseTimeInSeconds + 99 ) ! ;
169
186
170
187
// Should be cancelled - will not finish
171
188
const cancelledSpan = startInactiveSpan ( {
172
189
name : 'cancelled span' ,
173
190
startTime : baseTimeInSeconds + 4 ,
174
- } ) ! ;
191
+ } ) ;
175
192
176
193
regularSpan . end ( baseTimeInSeconds + 4 ) ;
177
194
idleSpan . end ( baseTimeInSeconds + 10 ) ;
@@ -225,7 +242,7 @@ describe('startIdleSpan', () => {
225
242
hookSpans . push ( { span, hook : 'spanEnd' } ) ;
226
243
} ) ;
227
244
228
- const idleSpan = startIdleSpan ( { name : 'idle span' } ) ! ;
245
+ const idleSpan = startIdleSpan ( { name : 'idle span' } ) ;
229
246
expect ( idleSpan ) . toBeDefined ( ) ;
230
247
231
248
expect ( hookSpans ) . toEqual ( [ { span : idleSpan , hook : 'spanStart' } ] ) ;
@@ -250,7 +267,7 @@ describe('startIdleSpan', () => {
250
267
251
268
const recordDroppedEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
252
269
253
- const idleSpan = startIdleSpan ( { name : 'idle span' } ) ! ;
270
+ const idleSpan = startIdleSpan ( { name : 'idle span' } ) ;
254
271
expect ( idleSpan ) . toBeDefined ( ) ;
255
272
256
273
idleSpan ?. end ( ) ;
@@ -260,15 +277,15 @@ describe('startIdleSpan', () => {
260
277
261
278
describe ( 'idleTimeout' , ( ) => {
262
279
it ( 'finishes if no activities are added to the idle span' , ( ) => {
263
- const idleSpan = startIdleSpan ( { name : 'idle span' } ) ! ;
280
+ const idleSpan = startIdleSpan ( { name : 'idle span' } ) ;
264
281
expect ( idleSpan ) . toBeDefined ( ) ;
265
282
266
283
jest . advanceTimersByTime ( TRACING_DEFAULTS . idleTimeout ) ;
267
284
expect ( spanToJSON ( idleSpan ) . timestamp ) . toBeDefined ( ) ;
268
285
} ) ;
269
286
270
287
it ( 'does not finish if a activity is started' , ( ) => {
271
- const idleSpan = startIdleSpan ( { name : 'idle span' } ) ! ;
288
+ const idleSpan = startIdleSpan ( { name : 'idle span' } ) ;
272
289
expect ( idleSpan ) . toBeDefined ( ) ;
273
290
274
291
startInactiveSpan ( { name : 'span' } ) ;
@@ -279,7 +296,7 @@ describe('startIdleSpan', () => {
279
296
280
297
it ( 'does not finish when idleTimeout is not exceed after last activity finished' , ( ) => {
281
298
const idleTimeout = 10 ;
282
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { idleTimeout } ) ! ;
299
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { idleTimeout } ) ;
283
300
expect ( idleSpan ) . toBeDefined ( ) ;
284
301
285
302
startSpan ( { name : 'span1' } , ( ) => { } ) ;
@@ -295,7 +312,7 @@ describe('startIdleSpan', () => {
295
312
296
313
it ( 'finish when idleTimeout is exceeded after last activity finished' , ( ) => {
297
314
const idleTimeout = 10 ;
298
- const idleSpan = startIdleSpan ( { name : 'idle span' , startTime : 1234 } , { idleTimeout } ) ! ;
315
+ const idleSpan = startIdleSpan ( { name : 'idle span' , startTime : 1234 } , { idleTimeout } ) ;
299
316
expect ( idleSpan ) . toBeDefined ( ) ;
300
317
301
318
startSpan ( { name : 'span1' } , ( ) => { } ) ;
@@ -312,7 +329,7 @@ describe('startIdleSpan', () => {
312
329
313
330
describe ( 'child span timeout' , ( ) => {
314
331
it ( 'finishes when a child span exceed timeout' , ( ) => {
315
- const idleSpan = startIdleSpan ( { name : 'idle span' } ) ! ;
332
+ const idleSpan = startIdleSpan ( { name : 'idle span' } ) ;
316
333
expect ( idleSpan ) . toBeDefined ( ) ;
317
334
318
335
// Start any span to cancel idle timeout
@@ -333,7 +350,7 @@ describe('startIdleSpan', () => {
333
350
} ) ;
334
351
335
352
it ( 'resets after new activities are added' , ( ) => {
336
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { finalTimeout : 99_999 } ) ! ;
353
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { finalTimeout : 99_999 } ) ;
337
354
expect ( idleSpan ) . toBeDefined ( ) ;
338
355
339
356
// Start any span to cancel idle timeout
@@ -370,7 +387,7 @@ describe('startIdleSpan', () => {
370
387
371
388
describe ( 'disableAutoFinish' , ( ) => {
372
389
it ( 'skips idle timeout if disableAutoFinish=true' , ( ) => {
373
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ! ;
390
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ;
374
391
expect ( idleSpan ) . toBeDefined ( ) ;
375
392
376
393
jest . advanceTimersByTime ( TRACING_DEFAULTS . idleTimeout ) ;
@@ -387,7 +404,7 @@ describe('startIdleSpan', () => {
387
404
} ) ;
388
405
389
406
it ( 'skips span timeout if disableAutoFinish=true' , ( ) => {
390
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true , finalTimeout : 99_999 } ) ! ;
407
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true , finalTimeout : 99_999 } ) ;
391
408
expect ( idleSpan ) . toBeDefined ( ) ;
392
409
393
410
startInactiveSpan ( { name : 'inner' } ) ;
@@ -406,16 +423,16 @@ describe('startIdleSpan', () => {
406
423
} ) ;
407
424
408
425
it ( 'times out at final timeout if disableAutoFinish=true' , ( ) => {
409
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ! ;
426
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ;
410
427
expect ( idleSpan ) . toBeDefined ( ) ;
411
428
412
429
jest . advanceTimersByTime ( TRACING_DEFAULTS . finalTimeout ) ;
413
430
expect ( spanToJSON ( idleSpan ) . timestamp ) . toBeDefined ( ) ;
414
431
} ) ;
415
432
416
433
it ( 'ignores it if hook is emitted with other span' , ( ) => {
417
- const span = startInactiveSpan ( { name : 'other span' } ) ! ;
418
- const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ! ;
434
+ const span = startInactiveSpan ( { name : 'other span' } ) ;
435
+ const idleSpan = startIdleSpan ( { name : 'idle span' } , { disableAutoFinish : true } ) ;
419
436
expect ( idleSpan ) . toBeDefined ( ) ;
420
437
421
438
jest . advanceTimersByTime ( TRACING_DEFAULTS . idleTimeout ) ;
0 commit comments