1
1
import {
2
2
ROOT_CONTEXT ,
3
+ SpanKind ,
3
4
TraceFlags ,
4
5
context ,
5
6
defaultTextMapGetter ,
8
9
trace ,
9
10
} from '@opentelemetry/api' ;
10
11
import { suppressTracing } from '@opentelemetry/core' ;
11
- import { getCurrentScope , withScope } from '@sentry/core' ;
12
+ import { ATTR_URL_FULL , SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions' ;
13
+ import { SEMANTIC_ATTRIBUTE_SENTRY_OP , getCurrentScope , withScope } from '@sentry/core' ;
12
14
13
15
import { SENTRY_BAGGAGE_HEADER , SENTRY_SCOPES_CONTEXT_KEY , SENTRY_TRACE_HEADER } from '../src/constants' ;
14
16
import { SentryPropagator } from '../src/propagator' ;
@@ -28,6 +30,7 @@ describe('SentryPropagator', () => {
28
30
release : '1.0.0' ,
29
31
enableTracing : true ,
30
32
dsn : 'https://abc@domain/123' ,
33
+ tracePropagationTargets : [ '/path2' ] ,
31
34
} ) ;
32
35
} ) ;
33
36
@@ -545,6 +548,111 @@ describe('SentryPropagator', () => {
545
548
expect ( carrier [ SENTRY_TRACE_HEADER ] ) . toBe ( undefined ) ;
546
549
expect ( carrier [ SENTRY_BAGGAGE_HEADER ] ) . toBe ( undefined ) ;
547
550
} ) ;
551
+
552
+ it . each ( [
553
+ [
554
+ {
555
+ attributes : { [ ATTR_URL_FULL ] : 'https://domain.com/path2' } ,
556
+ kind : SpanKind . CLIENT ,
557
+ } ,
558
+ true ,
559
+ ] ,
560
+ [
561
+ {
562
+ // eslint-disable-next-line deprecation/deprecation
563
+ attributes : { [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path2' } ,
564
+ kind : SpanKind . CLIENT ,
565
+ } ,
566
+ true ,
567
+ ] ,
568
+ [
569
+ {
570
+ attributes : { [ ATTR_URL_FULL ] : 'https://domain.com/path3' } ,
571
+ kind : SpanKind . CLIENT ,
572
+ } ,
573
+ false ,
574
+ ] ,
575
+ [
576
+ {
577
+ // eslint-disable-next-line deprecation/deprecation
578
+ attributes : { [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path3' } ,
579
+ kind : SpanKind . CLIENT ,
580
+ } ,
581
+ false ,
582
+ ] ,
583
+ [
584
+ {
585
+ attributes : { [ ATTR_URL_FULL ] : 'https://domain.com/path2' } ,
586
+ } ,
587
+ true ,
588
+ ] ,
589
+ [
590
+ {
591
+ // eslint-disable-next-line deprecation/deprecation
592
+ attributes : { [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path2' } ,
593
+ } ,
594
+ true ,
595
+ ] ,
596
+ [
597
+ {
598
+ attributes : { [ ATTR_URL_FULL ] : 'https://domain.com/path3' } ,
599
+ } ,
600
+ true ,
601
+ ] ,
602
+ [
603
+ {
604
+ // eslint-disable-next-line deprecation/deprecation
605
+ attributes : { [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path3' } ,
606
+ } ,
607
+ true ,
608
+ ] ,
609
+ [
610
+ {
611
+ attributes : { [ ATTR_URL_FULL ] : 'https://domain.com/path3' } ,
612
+ kind : SpanKind . SERVER ,
613
+ } ,
614
+ true ,
615
+ ] ,
616
+ [
617
+ {
618
+ // eslint-disable-next-line deprecation/deprecation
619
+ attributes : { [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path3' } ,
620
+ kind : SpanKind . SERVER ,
621
+ } ,
622
+ true ,
623
+ ] ,
624
+ [
625
+ {
626
+ attributes : {
627
+ [ ATTR_URL_FULL ] : 'https://domain.com/path3' ,
628
+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'http.client' ,
629
+ } ,
630
+ } ,
631
+ false ,
632
+ ] ,
633
+ [
634
+ {
635
+ attributes : {
636
+ // eslint-disable-next-line deprecation/deprecation
637
+ [ SEMATTRS_HTTP_URL ] : 'https://domain.com/path3' ,
638
+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'http.client' ,
639
+ } ,
640
+ } ,
641
+ false ,
642
+ ] ,
643
+ ] ) ( 'for %p injection is %p' , ( spanContext , shouldInject ) => {
644
+ trace . getTracer ( 'test' ) . startActiveSpan ( 'test' , spanContext , span => {
645
+ propagator . inject ( context . active ( ) , carrier , defaultTextMapSetter ) ;
646
+
647
+ if ( shouldInject ) {
648
+ expect ( carrier [ SENTRY_TRACE_HEADER ] ) . toBe ( `${ span . spanContext ( ) . traceId } -${ span . spanContext ( ) . spanId } -1` ) ;
649
+ expect ( carrier [ SENTRY_BAGGAGE_HEADER ] ) . toMatch ( / .+ / ) ;
650
+ } else {
651
+ expect ( carrier [ SENTRY_TRACE_HEADER ] ) . toBe ( undefined ) ;
652
+ expect ( carrier [ SENTRY_BAGGAGE_HEADER ] ) . toBe ( undefined ) ;
653
+ }
654
+ } ) ;
655
+ } ) ;
548
656
} ) ;
549
657
550
658
describe ( 'extract' , ( ) => {
0 commit comments