@@ -2,23 +2,20 @@ import { SentrySpan, getTraceData } from '../../../src/';
2
2
import * as SentryCoreCurrentScopes from '../../../src/currentScopes' ;
3
3
import * as SentryCoreExports from '../../../src/exports' ;
4
4
import * as SentryCoreTracing from '../../../src/tracing' ;
5
+ import * as SentryCoreTracingDsc from '../../../src/tracing/dynamicSamplingContext' ;
6
+ import { freezeDscOnSpan } from '../../../src/tracing/dynamicSamplingContext' ;
5
7
import * as SentryCoreSpanUtils from '../../../src/utils/spanUtils' ;
6
8
7
9
import { isValidBaggageString } from '../../../src/utils/traceData' ;
8
10
9
11
const TRACE_FLAG_SAMPLED = 1 ;
10
12
11
- const mockedSpan = new SentrySpan ( {
12
- traceId : '12345678901234567890123456789012' ,
13
- spanId : '1234567890123456' ,
14
- sampled : true ,
15
- } ) ;
16
-
17
13
const mockedClient = { } as any ;
18
14
19
15
const mockedScope = {
20
16
getPropagationContext : ( ) => ( {
21
17
traceId : '123' ,
18
+ spanId : '456' ,
22
19
} ) ,
23
20
} as any ;
24
21
@@ -33,11 +30,16 @@ describe('getTraceData', () => {
33
30
34
31
it ( 'returns the tracing data from the span, if a span is available' , ( ) => {
35
32
{
36
- jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromSpan' ) . mockReturnValueOnce ( {
37
- environment : 'production' ,
33
+ const mockedSpan = new SentrySpan ( {
34
+ traceId : '12345678901234567890123456789012' ,
35
+ spanId : '1234567890123456' ,
36
+ sampled : true ,
38
37
} ) ;
39
- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => mockedSpan ) ;
40
- jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementationOnce ( ( ) => mockedScope ) ;
38
+ freezeDscOnSpan ( mockedSpan , { environment : 'production' } ) ;
39
+
40
+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => mockedSpan ) ;
41
+ jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementation ( ( ) => mockedScope ) ;
42
+ jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementation ( ( ) => mockedClient ) ;
41
43
42
44
const data = getTraceData ( ) ;
43
45
@@ -49,8 +51,8 @@ describe('getTraceData', () => {
49
51
} ) ;
50
52
51
53
it ( 'returns propagationContext DSC data if no span is available' , ( ) => {
52
- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => undefined ) ;
53
- jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementationOnce (
54
+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => undefined ) ;
55
+ jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementation (
54
56
( ) =>
55
57
( {
56
58
getPropagationContext : ( ) => ( {
@@ -65,7 +67,7 @@ describe('getTraceData', () => {
65
67
} ) ,
66
68
} ) as any ,
67
69
) ;
68
- jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementationOnce ( ( ) => mockedClient ) ;
70
+ jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementation ( ( ) => mockedClient ) ;
69
71
70
72
const traceData = getTraceData ( ) ;
71
73
@@ -76,13 +78,13 @@ describe('getTraceData', () => {
76
78
} ) ;
77
79
78
80
it ( 'returns only the `sentry-trace` value if no DSC is available' , ( ) => {
79
- jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromClient ' ) . mockReturnValueOnce ( {
81
+ jest . spyOn ( SentryCoreTracingDsc , 'getDynamicSamplingContextFromSpan ' ) . mockReturnValue ( {
80
82
trace_id : '' ,
81
83
public_key : undefined ,
82
84
} ) ;
83
85
84
86
// @ts -expect-error - we don't need to provide all the properties
85
- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
87
+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
86
88
isRecording : ( ) => true ,
87
89
spanContext : ( ) => {
88
90
return {
@@ -93,8 +95,13 @@ describe('getTraceData', () => {
93
95
} ,
94
96
} ) ) ;
95
97
96
- jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementationOnce ( ( ) => mockedScope ) ;
97
- jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementationOnce ( ( ) => mockedClient ) ;
98
+ jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementation ( ( ) => mockedScope ) ;
99
+ jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementation ( ( ) => {
100
+ return {
101
+ getOptions : ( ) => ( { } ) ,
102
+ getDsn : ( ) => ( { } ) ,
103
+ } as any ;
104
+ } ) ;
98
105
99
106
const traceData = getTraceData ( ) ;
100
107
@@ -103,14 +110,14 @@ describe('getTraceData', () => {
103
110
} ) ;
104
111
} ) ;
105
112
106
- it ( 'returns only the `sentry-trace` tag if no DSC is available without a client' , ( ) => {
113
+ it ( 'returns empty object without a client' , ( ) => {
107
114
jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromClient' ) . mockReturnValueOnce ( {
108
115
trace_id : '' ,
109
116
public_key : undefined ,
110
117
} ) ;
111
118
112
119
// @ts -expect-error - we don't need to provide all the properties
113
- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
120
+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
114
121
isRecording : ( ) => true ,
115
122
spanContext : ( ) => {
116
123
return {
@@ -120,20 +127,17 @@ describe('getTraceData', () => {
120
127
} ;
121
128
} ,
122
129
} ) ) ;
123
- jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementationOnce ( ( ) => mockedScope ) ;
124
- jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementationOnce ( ( ) => undefined ) ;
130
+ jest . spyOn ( SentryCoreCurrentScopes , 'getCurrentScope' ) . mockImplementation ( ( ) => mockedScope ) ;
131
+ jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementation ( ( ) => undefined ) ;
125
132
126
133
const traceData = getTraceData ( ) ;
127
134
128
- expect ( traceData ) . toEqual ( {
129
- 'sentry-trace' : '12345678901234567890123456789012-1234567890123456-1' ,
130
- } ) ;
131
- expect ( 'baggage' in traceData ) . toBe ( false ) ;
135
+ expect ( traceData ) . toEqual ( { } ) ;
132
136
} ) ;
133
137
134
138
it ( 'returns an empty object if the `sentry-trace` value is invalid' , ( ) => {
135
139
// @ts -expect-error - we don't need to provide all the properties
136
- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
140
+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
137
141
isRecording : ( ) => true ,
138
142
spanContext : ( ) => {
139
143
return {
0 commit comments