@@ -1054,6 +1054,48 @@ public void ActivityListenersAreCalled()
10541054 hostingApplication . CreateContext ( features ) ;
10551055 Assert . Equal ( "0123456789abcdef" , parentSpanId ) ;
10561056
1057+ Assert . Empty ( tags ) ;
1058+ }
1059+
1060+ [ Fact ]
1061+ public void ActivityListeners_DontSuppressActivityTags_TagsAdded ( )
1062+ {
1063+ var testSource = new ActivitySource ( Path . GetRandomFileName ( ) ) ;
1064+ var hostingApplication = CreateApplication ( out var features , activitySource : testSource , suppressActivityOpenTelemetryData : false ) ;
1065+ var parentSpanId = "" ;
1066+ var tags = new List < KeyValuePair < string , object > > ( ) ;
1067+ using var listener = new ActivityListener
1068+ {
1069+ ShouldListenTo = activitySource => ReferenceEquals ( activitySource , testSource ) ,
1070+ Sample = ( ref ActivityCreationOptions < ActivityContext > _ ) => ActivitySamplingResult . AllData ,
1071+ ActivityStarted = activity =>
1072+ {
1073+ parentSpanId = Activity . Current . ParentSpanId . ToHexString ( ) ;
1074+ tags = Activity . Current . TagObjects . OrderBy ( t => t . Key ) . ToList ( ) ;
1075+ }
1076+ } ;
1077+
1078+ ActivitySource . AddActivityListener ( listener ) ;
1079+
1080+ features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
1081+ {
1082+ Headers = new HeaderDictionary ( )
1083+ {
1084+ { "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
1085+ { "tracestate" , "TraceState1" } ,
1086+ { "baggage" , "Key1=value1, Key2=value2" } ,
1087+ { "host" , "localhost:8080" }
1088+ } ,
1089+ PathBase = "/path_base" ,
1090+ Path = "/path" ,
1091+ Scheme = "http" ,
1092+ Method = "CUSTOM_METHOD" ,
1093+ Protocol = "HTTP/1.1"
1094+ } ) ;
1095+
1096+ hostingApplication . CreateContext ( features ) ;
1097+ Assert . Equal ( "0123456789abcdef" , parentSpanId ) ;
1098+
10571099 Assert . Collection ( tags ,
10581100 kvp => AssertKeyValuePair ( kvp , "http.request.method" , "_OTHER" ) ,
10591101 kvp => AssertKeyValuePair ( kvp , "http.request.method_original" , "CUSTOM_METHOD" ) ,
@@ -1078,7 +1120,7 @@ static void AssertKeyValuePair<T>(KeyValuePair<string, T> pair, string key, T va
10781120 public void ActivityListeners_DefaultPorts ( string scheme , int ? expectedPort )
10791121 {
10801122 var testSource = new ActivitySource ( Path . GetRandomFileName ( ) ) ;
1081- var hostingApplication = CreateApplication ( out var features , activitySource : testSource ) ;
1123+ var hostingApplication = CreateApplication ( out var features , activitySource : testSource , suppressActivityOpenTelemetryData : false ) ;
10821124 var tags = new Dictionary < string , object > ( ) ;
10831125 using var listener = new ActivityListener
10841126 {
@@ -1152,7 +1194,8 @@ private static void AssertProperty<T>(object o, string name)
11521194
11531195 private static HostingApplication CreateApplication ( out FeatureCollection features ,
11541196 DiagnosticListener diagnosticListener = null , ActivitySource activitySource = null , ILogger logger = null ,
1155- Action < DefaultHttpContext > configure = null , HostingEventSource eventSource = null , IMeterFactory meterFactory = null )
1197+ Action < DefaultHttpContext > configure = null , HostingEventSource eventSource = null , IMeterFactory meterFactory = null ,
1198+ bool ? suppressActivityOpenTelemetryData = null )
11561199 {
11571200 var httpContextFactory = new Mock < IHttpContextFactory > ( ) ;
11581201
@@ -1174,6 +1217,11 @@ private static HostingApplication CreateApplication(out FeatureCollection featur
11741217 eventSource ?? HostingEventSource . Log ,
11751218 new HostingMetrics ( meterFactory ?? new TestMeterFactory ( ) ) ) ;
11761219
1220+ if ( suppressActivityOpenTelemetryData is { } suppress )
1221+ {
1222+ hostingApplication . SuppressActivityOpenTelemetryData = suppress ;
1223+ }
1224+
11771225 return hostingApplication ;
11781226 }
11791227
0 commit comments