1
1
import { TraceFlags , context , trace } from '@opentelemetry/api' ;
2
2
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base' ;
3
- import { spanToJSON } from '@sentry/core' ;
4
- import { SentrySpanProcessor , getClient , setPropagationContextOnContext } from '@sentry/opentelemetry' ;
3
+ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , spanToJSON } from '@sentry/core' ;
4
+ import { SentrySpanProcessor , setPropagationContextOnContext } from '@sentry/opentelemetry' ;
5
5
import type { PropagationContext , TransactionEvent } from '@sentry/types' ;
6
6
import { logger } from '@sentry/utils' ;
7
7
8
8
import * as Sentry from '../../src' ;
9
- import type { NodeClient } from '../../src/sdk/client' ;
10
9
import { cleanupOtel , getProvider , mockSdkInit } from '../helpers/mockSdkInit' ;
11
10
12
11
describe ( 'Integration | Transactions' , ( ) => {
@@ -20,7 +19,7 @@ describe('Integration | Transactions', () => {
20
19
21
20
mockSdkInit ( { enableTracing : true , beforeSendTransaction } ) ;
22
21
23
- const client = Sentry . getClient < NodeClient > ( ) ;
22
+ const client = Sentry . getClient ( ) ! ;
24
23
25
24
Sentry . addBreadcrumb ( { message : 'test breadcrumb 1' , timestamp : 123456 } ) ;
26
25
Sentry . setTag ( 'outer.tag' , 'test value' ) ;
@@ -29,11 +28,11 @@ describe('Integration | Transactions', () => {
29
28
{
30
29
op : 'test op' ,
31
30
name : 'test name' ,
32
- attributes : {
33
- [ Sentry . SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'task' ,
34
- } ,
35
31
origin : 'auto.test' ,
36
32
metadata : { requestPath : 'test-path' } ,
33
+ attributes : {
34
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'task' ,
35
+ } ,
37
36
} ,
38
37
span => {
39
38
Sentry . addBreadcrumb ( { message : 'test breadcrumb 2' , timestamp : 123456 } ) ;
@@ -88,6 +87,8 @@ describe('Integration | Transactions', () => {
88
87
'sentry.op' : 'test op' ,
89
88
'sentry.origin' : 'auto.test' ,
90
89
'sentry.source' : 'task' ,
90
+ 'sentry.sample_rate' : 1 ,
91
+ 'test.outer' : 'test value' ,
91
92
} ,
92
93
op : 'test op' ,
93
94
span_id : expect . any ( String ) ,
@@ -120,6 +121,7 @@ describe('Integration | Transactions', () => {
120
121
tags : {
121
122
'outer.tag' : 'test value' ,
122
123
'test.tag' : 'test value' ,
124
+ transaction : 'test name' ,
123
125
} ,
124
126
timestamp : expect . any ( Number ) ,
125
127
transaction : 'test name' ,
@@ -175,39 +177,31 @@ describe('Integration | Transactions', () => {
175
177
176
178
mockSdkInit ( { enableTracing : true , beforeSendTransaction } ) ;
177
179
178
- const client = Sentry . getClient ( ) ;
180
+ const client = Sentry . getClient ( ) ! ;
179
181
180
182
Sentry . addBreadcrumb ( { message : 'test breadcrumb 1' , timestamp : 123456 } ) ;
181
183
182
184
Sentry . withIsolationScope ( ( ) => {
183
- Sentry . startSpan (
184
- {
185
- op : 'test op' ,
186
- name : 'test name' ,
187
- origin : 'auto.test' ,
188
- attributes : { [ Sentry . SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'task' } ,
189
- } ,
190
- span => {
191
- Sentry . addBreadcrumb ( { message : 'test breadcrumb 2' , timestamp : 123456 } ) ;
185
+ Sentry . startSpan ( { op : 'test op' , name : 'test name' , source : 'task' , origin : 'auto.test' } , span => {
186
+ Sentry . addBreadcrumb ( { message : 'test breadcrumb 2' , timestamp : 123456 } ) ;
192
187
193
- span . setAttributes ( {
194
- 'test.outer' : 'test value' ,
195
- } ) ;
188
+ span . setAttributes ( {
189
+ 'test.outer' : 'test value' ,
190
+ } ) ;
196
191
197
- const subSpan = Sentry . startInactiveSpan ( { name : 'inner span 1' } ) ;
198
- subSpan . end ( ) ;
192
+ const subSpan = Sentry . startInactiveSpan ( { name : 'inner span 1' } ) ;
193
+ subSpan . end ( ) ;
199
194
200
- Sentry . setTag ( 'test.tag' , 'test value' ) ;
195
+ Sentry . setTag ( 'test.tag' , 'test value' ) ;
201
196
202
- Sentry . startSpan ( { name : 'inner span 2' } , innerSpan => {
203
- Sentry . addBreadcrumb ( { message : 'test breadcrumb 3' , timestamp : 123456 } ) ;
197
+ Sentry . startSpan ( { name : 'inner span 2' } , innerSpan => {
198
+ Sentry . addBreadcrumb ( { message : 'test breadcrumb 3' , timestamp : 123456 } ) ;
204
199
205
- innerSpan . setAttributes ( {
206
- 'test.inner' : 'test value' ,
207
- } ) ;
200
+ innerSpan . setAttributes ( {
201
+ 'test.inner' : 'test value' ,
208
202
} ) ;
209
- } ,
210
- ) ;
203
+ } ) ;
204
+ } ) ;
211
205
} ) ;
212
206
213
207
Sentry . withIsolationScope ( ( ) => {
@@ -255,6 +249,8 @@ describe('Integration | Transactions', () => {
255
249
'sentry.op' : 'test op' ,
256
250
'sentry.origin' : 'auto.test' ,
257
251
'sentry.source' : 'task' ,
252
+ 'test.outer' : 'test value' ,
253
+ 'sentry.sample_rate' : 1 ,
258
254
} ,
259
255
op : 'test op' ,
260
256
span_id : expect . any ( String ) ,
@@ -265,7 +261,7 @@ describe('Integration | Transactions', () => {
265
261
} ) ,
266
262
spans : [ expect . any ( Object ) , expect . any ( Object ) ] ,
267
263
start_timestamp : expect . any ( Number ) ,
268
- tags : { 'test.tag' : 'test value' } ,
264
+ tags : { 'test.tag' : 'test value' , transaction : 'test name' } ,
269
265
timestamp : expect . any ( Number ) ,
270
266
transaction : 'test name' ,
271
267
transaction_info : { source : 'task' } ,
@@ -295,6 +291,8 @@ describe('Integration | Transactions', () => {
295
291
'sentry.op' : 'test op b' ,
296
292
'sentry.origin' : 'manual' ,
297
293
'sentry.source' : 'custom' ,
294
+ 'test.outer' : 'test value b' ,
295
+ 'sentry.sample_rate' : 1 ,
298
296
} ,
299
297
op : 'test op b' ,
300
298
span_id : expect . any ( String ) ,
@@ -305,7 +303,7 @@ describe('Integration | Transactions', () => {
305
303
} ) ,
306
304
spans : [ expect . any ( Object ) , expect . any ( Object ) ] ,
307
305
start_timestamp : expect . any ( Number ) ,
308
- tags : { 'test.tag' : 'test value b' } ,
306
+ tags : { 'test.tag' : 'test value b' , transaction : 'test name b' } ,
309
307
timestamp : expect . any ( Number ) ,
310
308
transaction : 'test name b' ,
311
309
transaction_info : { source : 'custom' } ,
@@ -322,7 +320,7 @@ describe('Integration | Transactions', () => {
322
320
323
321
mockSdkInit ( { enableTracing : true , beforeSendTransaction } ) ;
324
322
325
- const client = Sentry . getClient < NodeClient > ( ) ;
323
+ const client = Sentry . getClient < Sentry . NodeClient > ( ) ;
326
324
327
325
Sentry . addBreadcrumb ( { message : 'test breadcrumb 1' , timestamp : 123456 } ) ;
328
326
@@ -401,6 +399,8 @@ describe('Integration | Transactions', () => {
401
399
'otel.kind' : 'INTERNAL' ,
402
400
'sentry.origin' : 'manual' ,
403
401
'sentry.source' : 'custom' ,
402
+ 'test.outer' : 'test value' ,
403
+ 'sentry.sample_rate' : 1 ,
404
404
} ,
405
405
span_id : expect . any ( String ) ,
406
406
status : 'ok' ,
@@ -410,7 +410,7 @@ describe('Integration | Transactions', () => {
410
410
} ) ,
411
411
spans : [ expect . any ( Object ) , expect . any ( Object ) ] ,
412
412
start_timestamp : expect . any ( Number ) ,
413
- tags : { 'test.tag' : 'test value' } ,
413
+ tags : { 'test.tag' : 'test value' , transaction : 'test name' } ,
414
414
timestamp : expect . any ( Number ) ,
415
415
transaction : 'test name' ,
416
416
type : 'transaction' ,
@@ -438,6 +438,8 @@ describe('Integration | Transactions', () => {
438
438
'otel.kind' : 'INTERNAL' ,
439
439
'sentry.origin' : 'manual' ,
440
440
'sentry.source' : 'custom' ,
441
+ 'test.outer' : 'test value b' ,
442
+ 'sentry.sample_rate' : 1 ,
441
443
} ,
442
444
span_id : expect . any ( String ) ,
443
445
status : 'ok' ,
@@ -447,7 +449,7 @@ describe('Integration | Transactions', () => {
447
449
} ) ,
448
450
spans : [ expect . any ( Object ) , expect . any ( Object ) ] ,
449
451
start_timestamp : expect . any ( Number ) ,
450
- tags : { 'test.tag' : 'test value b' } ,
452
+ tags : { 'test.tag' : 'test value b' , transaction : 'test name b' } ,
451
453
timestamp : expect . any ( Number ) ,
452
454
transaction : 'test name b' ,
453
455
type : 'transaction' ,
@@ -481,7 +483,7 @@ describe('Integration | Transactions', () => {
481
483
482
484
mockSdkInit ( { enableTracing : true , beforeSendTransaction } ) ;
483
485
484
- const client = getClient ( ) as NodeClient ;
486
+ const client = Sentry . getClient ( ) ! ;
485
487
486
488
// We simulate the correct context we'd normally get from the SentryPropagator
487
489
context . with (
@@ -519,6 +521,7 @@ describe('Integration | Transactions', () => {
519
521
'sentry.op' : 'test op' ,
520
522
'sentry.origin' : 'auto.test' ,
521
523
'sentry.source' : 'task' ,
524
+ 'sentry.sample_rate' : 1 ,
522
525
} ,
523
526
op : 'test op' ,
524
527
span_id : expect . any ( String ) ,
@@ -592,7 +595,7 @@ describe('Integration | Transactions', () => {
592
595
593
596
mockSdkInit ( { enableTracing : true , beforeSendTransaction } ) ;
594
597
595
- const client = getClient ( ) as NodeClient ;
598
+ const client = Sentry . getClient ( ) ! ;
596
599
const provider = getProvider ( ) ;
597
600
const multiSpanProcessor = provider ?. activeSpanProcessor as
598
601
| ( SpanProcessor & { _spanProcessors ?: SpanProcessor [ ] } )
0 commit comments