1- import { getCurrentHub , setCurrentClient , spanToJSON } from '@sentry/core' ;
2- import { OpenTelemetryScope } from '../../src/custom/scope' ;
3- import { OpenTelemetryTransaction , startTransaction } from '../../src/custom/transaction' ;
1+ import { Transaction , getCurrentHub , setCurrentClient , spanToJSON } from '@sentry/core' ;
2+ import { startTransaction } from '../../src/custom/transaction' ;
43import { TestClient , getDefaultTestClientOptions } from '../helpers/TestClient' ;
54
6- describe ( 'NodeExperimentalTransaction' , ( ) => {
7- afterEach ( ( ) => {
8- jest . resetAllMocks ( ) ;
9- } ) ;
10-
11- it ( 'works with finishWithScope without arguments' , ( ) => {
12- const client = new TestClient ( getDefaultTestClientOptions ( ) ) ;
13-
14- const mockSend = jest . spyOn ( client , 'captureEvent' ) . mockImplementation ( ( ) => 'mocked' ) ;
15-
16- // eslint-disable-next-line deprecation/deprecation
17- const hub = getCurrentHub ( ) ;
18- setCurrentClient ( client ) ;
19- client . init ( ) ;
20-
21- // eslint-disable-next-line deprecation/deprecation
22- const transaction = new OpenTelemetryTransaction ( { name : 'test' , sampled : true } , hub ) ;
23-
24- const res = transaction . finishWithScope ( ) ;
25-
26- expect ( mockSend ) . toBeCalledTimes ( 1 ) ;
27- expect ( mockSend ) . toBeCalledWith (
28- expect . objectContaining ( {
29- contexts : {
30- trace : {
31- data : {
32- 'sentry.origin' : 'manual' ,
33- } ,
34- span_id : expect . any ( String ) ,
35- trace_id : expect . any ( String ) ,
36- origin : 'manual' ,
37- } ,
38- } ,
39- spans : [ ] ,
40- start_timestamp : expect . any ( Number ) ,
41- tags : { } ,
42- timestamp : expect . any ( Number ) ,
43- transaction : 'test' ,
44- type : 'transaction' ,
45- sdkProcessingMetadata : {
46- source : 'custom' ,
47- spanMetadata : { } ,
48- dynamicSamplingContext : {
49- environment : 'production' ,
50- trace_id : expect . any ( String ) ,
51- transaction : 'test' ,
52- sampled : 'true' ,
53- } ,
54- } ,
55- transaction_info : { source : 'custom' } ,
56- } ) ,
57- { event_id : expect . any ( String ) } ,
58- undefined ,
59- ) ;
60- expect ( res ) . toBe ( 'mocked' ) ;
61- } ) ;
62-
63- it ( 'works with finishWithScope with endTime' , ( ) => {
64- const client = new TestClient ( getDefaultTestClientOptions ( ) ) ;
65-
66- const mockSend = jest . spyOn ( client , 'captureEvent' ) . mockImplementation ( ( ) => 'mocked' ) ;
67-
68- // eslint-disable-next-line deprecation/deprecation
69- const hub = getCurrentHub ( ) ;
70- setCurrentClient ( client ) ;
71- client . init ( ) ;
72-
73- // eslint-disable-next-line deprecation/deprecation
74- const transaction = new OpenTelemetryTransaction ( { name : 'test' , startTimestamp : 123456 , sampled : true } , hub ) ;
75-
76- const res = transaction . finishWithScope ( 1234567 ) ;
77-
78- expect ( mockSend ) . toBeCalledTimes ( 1 ) ;
79- expect ( mockSend ) . toBeCalledWith (
80- expect . objectContaining ( {
81- start_timestamp : 123456 ,
82- timestamp : 1234567 ,
83- } ) ,
84- { event_id : expect . any ( String ) } ,
85- undefined ,
86- ) ;
87- expect ( res ) . toBe ( 'mocked' ) ;
88- } ) ;
89-
90- it ( 'works with finishWithScope with endTime & scope' , ( ) => {
91- const client = new TestClient ( getDefaultTestClientOptions ( ) ) ;
92-
93- const mockSend = jest . spyOn ( client , 'captureEvent' ) . mockImplementation ( ( ) => 'mocked' ) ;
94-
95- // eslint-disable-next-line deprecation/deprecation
96- const hub = getCurrentHub ( ) ;
97- setCurrentClient ( client ) ;
98- client . init ( ) ;
99-
100- // eslint-disable-next-line deprecation/deprecation
101- const transaction = new OpenTelemetryTransaction ( { name : 'test' , startTimestamp : 123456 , sampled : true } , hub ) ;
102-
103- const scope = new OpenTelemetryScope ( ) ;
104- scope . setTags ( {
105- tag1 : 'yes' ,
106- tag2 : 'no' ,
107- } ) ;
108- scope . setContext ( 'os' , { name : 'Custom OS' } ) ;
109-
110- const res = transaction . finishWithScope ( 1234567 , scope ) ;
111-
112- expect ( mockSend ) . toBeCalledTimes ( 1 ) ;
113- expect ( mockSend ) . toBeCalledWith (
114- expect . objectContaining ( {
115- contexts : {
116- trace : {
117- data : {
118- 'sentry.origin' : 'manual' ,
119- } ,
120- span_id : expect . any ( String ) ,
121- trace_id : expect . any ( String ) ,
122- origin : 'manual' ,
123- } ,
124- } ,
125- spans : [ ] ,
126- start_timestamp : 123456 ,
127- tags : { } ,
128- timestamp : 1234567 ,
129- transaction : 'test' ,
130- type : 'transaction' ,
131- sdkProcessingMetadata : {
132- source : 'custom' ,
133- spanMetadata : { } ,
134- dynamicSamplingContext : {
135- environment : 'production' ,
136- trace_id : expect . any ( String ) ,
137- transaction : 'test' ,
138- sampled : 'true' ,
139- } ,
140- } ,
141- transaction_info : { source : 'custom' } ,
142- } ) ,
143- { event_id : expect . any ( String ) } ,
144- scope ,
145- ) ;
146- expect ( res ) . toBe ( 'mocked' ) ;
147- } ) ;
148- } ) ;
149-
1505describe ( 'startTranscation' , ( ) => {
1516 afterEach ( ( ) => {
1527 jest . resetAllMocks ( ) ;
1538 } ) ;
1549
155- it ( 'creates a NodeExperimentalTransaction ' , ( ) => {
10+ it ( 'creates a Transaction ' , ( ) => {
15611 const client = new TestClient ( getDefaultTestClientOptions ( ) ) ;
15712 // eslint-disable-next-line deprecation/deprecation
15813 const hub = getCurrentHub ( ) ;
@@ -161,7 +16,7 @@ describe('startTranscation', () => {
16116
16217 const transaction = startTransaction ( hub , { name : 'test' } ) ;
16318
164- expect ( transaction ) . toBeInstanceOf ( OpenTelemetryTransaction ) ;
19+ expect ( transaction ) . toBeInstanceOf ( Transaction ) ;
16520 expect ( transaction [ '_sampled' ] ) . toBe ( undefined ) ;
16621 // eslint-disable-next-line deprecation/deprecation
16722 expect ( transaction . spanRecorder ) . toBeDefined ( ) ;
@@ -197,7 +52,7 @@ describe('startTranscation', () => {
19752 traceId : 'trace1' ,
19853 } ) ;
19954
200- expect ( transaction ) . toBeInstanceOf ( OpenTelemetryTransaction ) ;
55+ expect ( transaction ) . toBeInstanceOf ( Transaction ) ;
20156 // eslint-disable-next-line deprecation/deprecation
20257 expect ( transaction . metadata ) . toEqual ( {
20358 source : 'custom' ,
0 commit comments