@@ -390,6 +390,44 @@ describe('trace', () => {
390390 } ) ;
391391 } ) ;
392392
393+ it ( 'allows to pass span links in span options' , ( ) => {
394+ const rawSpan1 = startInactiveSpan ( { name : 'pageload_span' } ) ;
395+
396+ // @ts -expect-error links exists on span
397+ expect ( rawSpan1 ?. links ) . toEqual ( [ ] ) ;
398+
399+ const span1JSON = spanToJSON ( rawSpan1 ) ;
400+
401+ startSpan (
402+ {
403+ name : '/users/:id' ,
404+ links : [
405+ {
406+ context : rawSpan1 . spanContext ( ) ,
407+ attributes : { 'sentry.link.type' : 'previous_trace' } ,
408+ } ,
409+ ] ,
410+ } ,
411+ rawSpan2 => {
412+ const span2LinkJSON = spanToJSON ( rawSpan2 ) . links ?. [ 0 ] ;
413+
414+ expect ( span2LinkJSON ?. attributes ?. [ 'sentry.link.type' ] ) . toBe ( 'previous_trace' ) ;
415+
416+ // @ts -expect-error links and _spanContext exist on span
417+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( rawSpan1 . _spanContext . traceId ) ;
418+ // @ts -expect-error links and _spanContext exist on span
419+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( span1JSON . trace_id ) ;
420+ expect ( span2LinkJSON ?. trace_id ) . toBe ( span1JSON . trace_id ) ;
421+
422+ // @ts -expect-error links and _spanContext exist on span
423+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( rawSpan1 ?. _spanContext . spanId ) ;
424+ // @ts -expect-error links and _spanContext exist on span
425+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( span1JSON . span_id ) ;
426+ expect ( span2LinkJSON ?. span_id ) . toBe ( span1JSON . span_id ) ;
427+ } ,
428+ ) ;
429+ } ) ;
430+
393431 it ( 'allows to force a transaction with forceTransaction=true' , async ( ) => {
394432 const client = getClient ( ) ! ;
395433 const transactionEvents : Event [ ] = [ ] ;
@@ -651,6 +689,44 @@ describe('trace', () => {
651689 } ) ;
652690 } ) ;
653691
692+ it ( 'allows to pass span links in span options' , ( ) => {
693+ const rawSpan1 = startInactiveSpan ( { name : 'pageload_span' } ) ;
694+
695+ // @ts -expect-error links exists on span
696+ expect ( rawSpan1 ?. links ) . toEqual ( [ ] ) ;
697+
698+ const rawSpan2 = startInactiveSpan ( {
699+ name : 'GET users/[id]' ,
700+ links : [
701+ {
702+ context : rawSpan1 . spanContext ( ) ,
703+ attributes : { 'sentry.link.type' : 'previous_trace' } ,
704+ } ,
705+ ] ,
706+ } ) ;
707+
708+ const span1JSON = spanToJSON ( rawSpan1 ) ;
709+ const span2JSON = spanToJSON ( rawSpan2 ) ;
710+ const span2LinkJSON = span2JSON . links ?. [ 0 ] ;
711+
712+ expect ( span2LinkJSON ?. attributes ?. [ 'sentry.link.type' ] ) . toBe ( 'previous_trace' ) ;
713+
714+ // @ts -expect-error links and _spanContext exist on span
715+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( rawSpan1 . _spanContext . traceId ) ;
716+ // @ts -expect-error links and _spanContext exist on span
717+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( span1JSON . trace_id ) ;
718+ expect ( span2LinkJSON ?. trace_id ) . toBe ( span1JSON . trace_id ) ;
719+
720+ // @ts -expect-error links and _spanContext exist on span
721+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( rawSpan1 ?. _spanContext . spanId ) ;
722+ // @ts -expect-error links and _spanContext exist on span
723+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( span1JSON . span_id ) ;
724+ expect ( span2LinkJSON ?. span_id ) . toBe ( span1JSON . span_id ) ;
725+
726+ // sampling decision is inherited
727+ expect ( span2LinkJSON ?. sampled ) . toBe ( Boolean ( spanToJSON ( rawSpan1 ) . data [ 'sentry.sample_rate' ] ) ) ;
728+ } ) ;
729+
654730 it ( 'allows to force a transaction with forceTransaction=true' , async ( ) => {
655731 const client = getClient ( ) ! ;
656732 const transactionEvents : Event [ ] = [ ] ;
@@ -974,6 +1050,44 @@ describe('trace', () => {
9741050 } ) ;
9751051 } ) ;
9761052
1053+ it ( 'allows to pass span links in span options' , ( ) => {
1054+ const rawSpan1 = startInactiveSpan ( { name : 'pageload_span' } ) ;
1055+
1056+ // @ts -expect-error links exists on span
1057+ expect ( rawSpan1 ?. links ) . toEqual ( [ ] ) ;
1058+
1059+ const span1JSON = spanToJSON ( rawSpan1 ) ;
1060+
1061+ startSpanManual (
1062+ {
1063+ name : '/users/:id' ,
1064+ links : [
1065+ {
1066+ context : rawSpan1 . spanContext ( ) ,
1067+ attributes : { 'sentry.link.type' : 'previous_trace' } ,
1068+ } ,
1069+ ] ,
1070+ } ,
1071+ rawSpan2 => {
1072+ const span2LinkJSON = spanToJSON ( rawSpan2 ) . links ?. [ 0 ] ;
1073+
1074+ expect ( span2LinkJSON ?. attributes ?. [ 'sentry.link.type' ] ) . toBe ( 'previous_trace' ) ;
1075+
1076+ // @ts -expect-error links and _spanContext exist on span
1077+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( rawSpan1 . _spanContext . traceId ) ;
1078+ // @ts -expect-error links and _spanContext exist on span
1079+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . traceId ) . toEqual ( span1JSON . trace_id ) ;
1080+ expect ( span2LinkJSON ?. trace_id ) . toBe ( span1JSON . trace_id ) ;
1081+
1082+ // @ts -expect-error links and _spanContext exist on span
1083+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( rawSpan1 ?. _spanContext . spanId ) ;
1084+ // @ts -expect-error links and _spanContext exist on span
1085+ expect ( rawSpan2 ?. links ?. [ 0 ] . context . spanId ) . toEqual ( span1JSON . span_id ) ;
1086+ expect ( span2LinkJSON ?. span_id ) . toBe ( span1JSON . span_id ) ;
1087+ } ,
1088+ ) ;
1089+ } ) ;
1090+
9771091 it ( 'allows to force a transaction with forceTransaction=true' , async ( ) => {
9781092 const client = getClient ( ) ! ;
9791093 const transactionEvents : Event [ ] = [ ] ;
0 commit comments