@@ -2,23 +2,20 @@ import { SentrySpan, getTraceData } from '../../../src/';
22import * as SentryCoreCurrentScopes from '../../../src/currentScopes' ;
33import * as SentryCoreExports from '../../../src/exports' ;
44import * as SentryCoreTracing from '../../../src/tracing' ;
5+ import * as SentryCoreTracingDsc from '../../../src/tracing/dynamicSamplingContext' ;
6+ import { freezeDscOnSpan } from '../../../src/tracing/dynamicSamplingContext' ;
57import * as SentryCoreSpanUtils from '../../../src/utils/spanUtils' ;
68
79import { isValidBaggageString } from '../../../src/utils/traceData' ;
810
911const TRACE_FLAG_SAMPLED = 1 ;
1012
11- const mockedSpan = new SentrySpan ( {
12- traceId : '12345678901234567890123456789012' ,
13- spanId : '1234567890123456' ,
14- sampled : true ,
15- } ) ;
16-
1713const mockedClient = { } as any ;
1814
1915const mockedScope = {
2016 getPropagationContext : ( ) => ( {
2117 traceId : '123' ,
18+ spanId : '456' ,
2219 } ) ,
2320} as any ;
2421
@@ -33,11 +30,16 @@ describe('getTraceData', () => {
3330
3431 it ( 'returns the tracing data from the span, if a span is available' , ( ) => {
3532 {
36- jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromSpan' ) . mockReturnValueOnce ( {
37- environment : 'production' ,
33+ const mockedSpan = new SentrySpan ( {
34+ traceId : '12345678901234567890123456789012' ,
35+ spanId : '1234567890123456' ,
36+ sampled : true ,
3837 } ) ;
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 ) ;
4143
4244 const data = getTraceData ( ) ;
4345
@@ -49,8 +51,8 @@ describe('getTraceData', () => {
4951 } ) ;
5052
5153 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 (
5456 ( ) =>
5557 ( {
5658 getPropagationContext : ( ) => ( {
@@ -65,7 +67,7 @@ describe('getTraceData', () => {
6567 } ) ,
6668 } ) as any ,
6769 ) ;
68- jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementationOnce ( ( ) => mockedClient ) ;
70+ jest . spyOn ( SentryCoreCurrentScopes , 'getClient' ) . mockImplementation ( ( ) => mockedClient ) ;
6971
7072 const traceData = getTraceData ( ) ;
7173
@@ -76,13 +78,13 @@ describe('getTraceData', () => {
7678 } ) ;
7779
7880 it ( 'returns only the `sentry-trace` value if no DSC is available' , ( ) => {
79- jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromClient ' ) . mockReturnValueOnce ( {
81+ jest . spyOn ( SentryCoreTracingDsc , 'getDynamicSamplingContextFromSpan ' ) . mockReturnValue ( {
8082 trace_id : '' ,
8183 public_key : undefined ,
8284 } ) ;
8385
8486 // @ts -expect-error - we don't need to provide all the properties
85- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
87+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
8688 isRecording : ( ) => true ,
8789 spanContext : ( ) => {
8890 return {
@@ -93,8 +95,13 @@ describe('getTraceData', () => {
9395 } ,
9496 } ) ) ;
9597
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+ } ) ;
98105
99106 const traceData = getTraceData ( ) ;
100107
@@ -103,14 +110,14 @@ describe('getTraceData', () => {
103110 } ) ;
104111 } ) ;
105112
106- it ( 'returns only the `sentry-trace` tag if no DSC is available without a client' , ( ) => {
113+ it ( 'returns empty object without a client' , ( ) => {
107114 jest . spyOn ( SentryCoreTracing , 'getDynamicSamplingContextFromClient' ) . mockReturnValueOnce ( {
108115 trace_id : '' ,
109116 public_key : undefined ,
110117 } ) ;
111118
112119 // @ts -expect-error - we don't need to provide all the properties
113- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
120+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
114121 isRecording : ( ) => true ,
115122 spanContext : ( ) => {
116123 return {
@@ -120,20 +127,17 @@ describe('getTraceData', () => {
120127 } ;
121128 } ,
122129 } ) ) ;
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 ) ;
125132
126133 const traceData = getTraceData ( ) ;
127134
128- expect ( traceData ) . toEqual ( {
129- 'sentry-trace' : '12345678901234567890123456789012-1234567890123456-1' ,
130- } ) ;
131- expect ( 'baggage' in traceData ) . toBe ( false ) ;
135+ expect ( traceData ) . toEqual ( { } ) ;
132136 } ) ;
133137
134138 it ( 'returns an empty object if the `sentry-trace` value is invalid' , ( ) => {
135139 // @ts -expect-error - we don't need to provide all the properties
136- jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementationOnce ( ( ) => ( {
140+ jest . spyOn ( SentryCoreSpanUtils , 'getActiveSpan' ) . mockImplementation ( ( ) => ( {
137141 isRecording : ( ) => true ,
138142 spanContext : ( ) => {
139143 return {
0 commit comments