11import { createRunner } from '../../../utils/runner' ;
22
33describe ( 'span links' , ( ) => {
4+ test ( 'should link spans by adding "links" to span options' , done => {
5+ let span1_traceId : string , span1_spanId : string ;
6+
7+ createRunner ( __dirname , 'scenario-span-options.ts' )
8+ . expect ( {
9+ transaction : event => {
10+ expect ( event . transaction ) . toBe ( 'parent1' ) ;
11+
12+ const traceContext = event . contexts ?. trace ;
13+ span1_traceId = traceContext ?. trace_id as string ;
14+ span1_spanId = traceContext ?. span_id as string ;
15+ } ,
16+ } )
17+ . expect ( {
18+ transaction : event => {
19+ expect ( event . transaction ) . toBe ( 'parent2' ) ;
20+
21+ const traceContext = event . contexts ?. trace ;
22+ expect ( traceContext ) . toBeDefined ( ) ;
23+ expect ( traceContext ?. links ) . toEqual ( [
24+ expect . objectContaining ( {
25+ trace_id : expect . stringMatching ( span1_traceId ) ,
26+ span_id : expect . stringMatching ( span1_spanId ) ,
27+ } ) ,
28+ ] ) ;
29+ } ,
30+ } )
31+ . start ( done ) ;
32+ } ) ;
33+
434 test ( 'should link spans with addLink() in trace context' , done => {
535 let span1_traceId : string , span1_spanId : string ;
636
@@ -9,9 +39,8 @@ describe('span links', () => {
939 transaction : event => {
1040 expect ( event . transaction ) . toBe ( 'span1' ) ;
1141
12- // assigning a string to prevent "might be undefined"
13- span1_traceId = event . contexts ?. trace ?. trace_id || 'non-existent-trace-id' ;
14- span1_spanId = event . contexts ?. trace ?. span_id || 'non-existent-span-id' ;
42+ span1_traceId = event . contexts ?. trace ?. trace_id as string ;
43+ span1_spanId = event . contexts ?. trace ?. span_id as string ;
1544
1645 expect ( event . spans ) . toEqual ( [ ] ) ;
1746 } ,
@@ -42,9 +71,8 @@ describe('span links', () => {
4271 transaction : event => {
4372 expect ( event . transaction ) . toBe ( 'span1' ) ;
4473
45- // assigning a string to prevent "might be undefined"
46- span1_traceId = event . contexts ?. trace ?. trace_id || 'non-existent-trace-id' ;
47- span1_spanId = event . contexts ?. trace ?. span_id || 'non-existent-span-id' ;
74+ span1_traceId = event . contexts ?. trace ?. trace_id as string ;
75+ span1_spanId = event . contexts ?. trace ?. span_id as string ;
4876
4977 expect ( event . spans ) . toEqual ( [ ] ) ;
5078 } ,
@@ -53,9 +81,8 @@ describe('span links', () => {
5381 transaction : event => {
5482 expect ( event . transaction ) . toBe ( 'span2' ) ;
5583
56- // assigning a string to prevent "might be undefined"
57- span2_traceId = event . contexts ?. trace ?. trace_id || 'non-existent-trace-id' ;
58- span2_spanId = event . contexts ?. trace ?. span_id || 'non-existent-span-id' ;
84+ span2_traceId = event . contexts ?. trace ?. trace_id as string ;
85+ span2_spanId = event . contexts ?. trace ?. span_id as string ;
5986
6087 expect ( event . spans ) . toEqual ( [ ] ) ;
6188 } ,
@@ -89,9 +116,8 @@ describe('span links', () => {
89116 transaction : event => {
90117 expect ( event . transaction ) . toBe ( 'parent1' ) ;
91118
92- // assigning a string to prevent "might be undefined"
93- const parent1_traceId = event . contexts ?. trace ?. trace_id || 'non-existent-span-id' ;
94- const parent1_spanId = event . contexts ?. trace ?. span_id || 'non-existent-span-id' ;
119+ const parent1_traceId = event . contexts ?. trace ?. trace_id as string ;
120+ const parent1_spanId = event . contexts ?. trace ?. span_id as string ;
95121
96122 const spans = event . spans || [ ] ;
97123 const child1_1 = spans . find ( span => span . description === 'child1.1' ) ;
@@ -129,9 +155,8 @@ describe('span links', () => {
129155 transaction : event => {
130156 expect ( event . transaction ) . toBe ( 'parent1' ) ;
131157
132- // assigning a string to prevent "might be undefined"
133- const parent1_traceId = event . contexts ?. trace ?. trace_id || 'non-existent-span-id' ;
134- const parent1_spanId = event . contexts ?. trace ?. span_id || 'non-existent-span-id' ;
158+ const parent1_traceId = event . contexts ?. trace ?. trace_id as string ;
159+ const parent1_spanId = event . contexts ?. trace ?. span_id as string ;
135160
136161 const spans = event . spans || [ ] ;
137162 const child1_1 = spans . find ( span => span . description === 'child1.1' ) ;
@@ -148,12 +173,8 @@ describe('span links', () => {
148173 span_id : expect . stringMatching ( parent1_spanId ) ,
149174 } ) ,
150175 expect . objectContaining ( {
151- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
152- // @ts -expect-error traceID is defined
153- trace_id : expect . stringMatching ( child1_1 ?. trace_id ) ,
154- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
155- // @ts -expect-error spanID is defined
156- span_id : expect . stringMatching ( child1_1 ?. span_id ) ,
176+ trace_id : expect . stringMatching ( child1_1 ?. trace_id as string ) ,
177+ span_id : expect . stringMatching ( child1_1 ?. span_id as string ) ,
157178 attributes : expect . objectContaining ( {
158179 'sentry.link.type' : 'previous_trace' ,
159180 } ) ,
0 commit comments