@@ -504,10 +504,10 @@ public void ActivityParentIdAndBaggageReadFromHeaders()
504
504
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
505
505
{
506
506
Headers = new HeaderDictionary ( )
507
- {
508
- { "Request-Id" , "ParentId1" } ,
509
- { "baggage" , "Key1=value1, Key2=value2" }
510
- }
507
+ {
508
+ { "Request-Id" , "ParentId1" } ,
509
+ { "baggage" , "Key1=value1, Key2=value2" }
510
+ }
511
511
} ) ;
512
512
hostingApplication . CreateContext ( features ) ;
513
513
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
@@ -517,7 +517,7 @@ public void ActivityParentIdAndBaggageReadFromHeaders()
517
517
}
518
518
519
519
[ Fact ]
520
- public void ActivityBaggageReadFromLegacyHeaders ( )
520
+ public void BaggageReadFromHeadersWithoutRequestId ( )
521
521
{
522
522
var diagnosticListener = new DiagnosticListener ( "DummySource" ) ;
523
523
var hostingApplication = CreateApplication ( out var features , diagnosticListener : diagnosticListener ) ;
@@ -535,10 +535,39 @@ public void ActivityBaggageReadFromLegacyHeaders()
535
535
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
536
536
{
537
537
Headers = new HeaderDictionary ( )
538
+ {
539
+ { "baggage" , "Key1=value1, Key2=value2" }
540
+ }
541
+ } ) ;
542
+ hostingApplication . CreateContext ( features ) ;
543
+ Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
544
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key1" && pair . Value == "value1" ) ;
545
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key2" && pair . Value == "value2" ) ;
546
+ }
547
+
548
+ [ Fact ]
549
+ public void ActivityBaggageReadFromLegacyHeaders ( )
550
+ {
551
+ var diagnosticListener = new DiagnosticListener ( "DummySource" ) ;
552
+ var hostingApplication = CreateApplication ( out var features , diagnosticListener : diagnosticListener ) ;
553
+
554
+ diagnosticListener . Subscribe ( new CallbackDiagnosticListener ( pair => { } ) ,
555
+ s =>
556
+ {
557
+ if ( s . StartsWith ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , StringComparison . Ordinal ) )
538
558
{
539
- { "Request-Id" , "ParentId1" } ,
540
- { "Correlation-Context" , "Key1=value1, Key2=value2" }
559
+ return true ;
541
560
}
561
+ return false ;
562
+ } ) ;
563
+
564
+ features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
565
+ {
566
+ Headers = new HeaderDictionary ( )
567
+ {
568
+ { "Request-Id" , "ParentId1" } ,
569
+ { "Correlation-Context" , "Key1=value1, Key2=value2" }
570
+ }
542
571
} ) ;
543
572
hostingApplication . CreateContext ( features ) ;
544
573
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
@@ -565,11 +594,11 @@ public void ActivityBaggagePrefersW3CBaggageHeaderName()
565
594
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
566
595
{
567
596
Headers = new HeaderDictionary ( )
568
- {
569
- { "Request-Id" , "ParentId1" } ,
570
- { "Correlation-Context" , "Key1=value1, Key2=value2" } ,
571
- { "baggage" , "Key1=value3, Key2=value4" }
572
- }
597
+ {
598
+ { "Request-Id" , "ParentId1" } ,
599
+ { "Correlation-Context" , "Key1=value1, Key2=value2" } ,
600
+ { "baggage" , "Key1=value3, Key2=value4" }
601
+ }
573
602
} ) ;
574
603
hostingApplication . CreateContext ( features ) ;
575
604
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
@@ -596,20 +625,20 @@ public void ActivityBaggagePreservesItemsOrder()
596
625
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
597
626
{
598
627
Headers = new HeaderDictionary ( )
599
- {
600
- { "Request-Id" , "ParentId1" } ,
601
- { "baggage" , "Key1=value1, Key2=value2, Key1=value3" } // duplicated keys allowed by the contract
602
- }
628
+ {
629
+ { "Request-Id" , "ParentId1" } ,
630
+ { "baggage" , "Key1=value1, Key2=value2, Key1=value3" } // duplicated keys allowed by the contract
631
+ }
603
632
} ) ;
604
633
hostingApplication . CreateContext ( features ) ;
605
634
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
606
635
607
636
var expectedBaggage = new [ ]
608
637
{
609
- KeyValuePair . Create ( "Key1" , "value1" ) ,
610
- KeyValuePair . Create ( "Key2" , "value2" ) ,
611
- KeyValuePair . Create ( "Key1" , "value3" )
612
- } ;
638
+ KeyValuePair . Create ( "Key1" , "value1" ) ,
639
+ KeyValuePair . Create ( "Key2" , "value2" ) ,
640
+ KeyValuePair . Create ( "Key1" , "value3" )
641
+ } ;
613
642
614
643
Assert . Equal ( expectedBaggage , Activity . Current . Baggage . ToArray ( ) ) ;
615
644
}
@@ -633,10 +662,10 @@ public void ActivityBaggageValuesAreUrlDecodedFromHeaders()
633
662
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
634
663
{
635
664
Headers = new HeaderDictionary ( )
636
- {
637
- { "Request-Id" , "ParentId1" } ,
638
- { "baggage" , "Key1=value1%2F1" }
639
- }
665
+ {
666
+ { "Request-Id" , "ParentId1" } ,
667
+ { "baggage" , "Key1=value1%2F1" }
668
+ }
640
669
} ) ;
641
670
hostingApplication . CreateContext ( features ) ;
642
671
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
@@ -662,11 +691,11 @@ public void ActivityTraceParentAndTraceStateFromHeaders()
662
691
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
663
692
{
664
693
Headers = new HeaderDictionary ( )
665
- {
666
- { "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
667
- { "tracestate" , "TraceState1" } ,
668
- { "baggage" , "Key1=value1, Key2=value2" }
669
- }
694
+ {
695
+ { "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
696
+ { "tracestate" , "TraceState1" } ,
697
+ { "baggage" , "Key1=value1, Key2=value2" }
698
+ }
670
699
} ) ;
671
700
hostingApplication . CreateContext ( features ) ;
672
701
Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
@@ -704,9 +733,9 @@ public void SamplersReceiveCorrectParentAndTraceIds()
704
733
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
705
734
{
706
735
Headers = new HeaderDictionary ( )
707
- {
708
- { "traceparent" , "00-35aae61e3e99044eb5ea5007f2cd159b-40a8bd87c078cb4c-00" } ,
709
- }
736
+ {
737
+ { "traceparent" , "00-35aae61e3e99044eb5ea5007f2cd159b-40a8bd87c078cb4c-00" } ,
738
+ }
710
739
} ) ;
711
740
712
741
hostingApplication . CreateContext ( features ) ;
@@ -772,11 +801,11 @@ public void ActivityListenersAreCalled()
772
801
features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
773
802
{
774
803
Headers = new HeaderDictionary ( )
775
- {
776
- { "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
777
- { "tracestate" , "TraceState1" } ,
778
- { "baggage" , "Key1=value1, Key2=value2" }
779
- }
804
+ {
805
+ { "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
806
+ { "tracestate" , "TraceState1" } ,
807
+ { "baggage" , "Key1=value1, Key2=value2" }
808
+ }
780
809
} ) ;
781
810
782
811
hostingApplication . CreateContext ( features ) ;
0 commit comments