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' ;
4
3
import { TestClient , getDefaultTestClientOptions } from '../helpers/TestClient' ;
5
4
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
-
150
5
describe ( 'startTranscation' , ( ) => {
151
6
afterEach ( ( ) => {
152
7
jest . resetAllMocks ( ) ;
153
8
} ) ;
154
9
155
- it ( 'creates a NodeExperimentalTransaction ' , ( ) => {
10
+ it ( 'creates a Transaction ' , ( ) => {
156
11
const client = new TestClient ( getDefaultTestClientOptions ( ) ) ;
157
12
// eslint-disable-next-line deprecation/deprecation
158
13
const hub = getCurrentHub ( ) ;
@@ -161,7 +16,7 @@ describe('startTranscation', () => {
161
16
162
17
const transaction = startTransaction ( hub , { name : 'test' } ) ;
163
18
164
- expect ( transaction ) . toBeInstanceOf ( OpenTelemetryTransaction ) ;
19
+ expect ( transaction ) . toBeInstanceOf ( Transaction ) ;
165
20
expect ( transaction [ '_sampled' ] ) . toBe ( undefined ) ;
166
21
// eslint-disable-next-line deprecation/deprecation
167
22
expect ( transaction . spanRecorder ) . toBeDefined ( ) ;
@@ -197,7 +52,7 @@ describe('startTranscation', () => {
197
52
traceId : 'trace1' ,
198
53
} ) ;
199
54
200
- expect ( transaction ) . toBeInstanceOf ( OpenTelemetryTransaction ) ;
55
+ expect ( transaction ) . toBeInstanceOf ( Transaction ) ;
201
56
// eslint-disable-next-line deprecation/deprecation
202
57
expect ( transaction . metadata ) . toEqual ( {
203
58
source : 'custom' ,
0 commit comments