@@ -271,7 +271,7 @@ public void ActivityIsAvailibleDuringRequest()
271
271
}
272
272
273
273
[ Fact ]
274
- public void ActivityParentIdAndBaggeReadFromHeaders ( )
274
+ public void ActivityParentIdAndBaggageReadFromHeaders ( )
275
275
{
276
276
var diagnosticListener = new DiagnosticListener ( "DummySource" ) ;
277
277
var hostingApplication = CreateApplication ( out var features , diagnosticListener : diagnosticListener ) ;
@@ -291,7 +291,7 @@ public void ActivityParentIdAndBaggeReadFromHeaders()
291
291
Headers = new HeaderDictionary ( )
292
292
{
293
293
{ "Request-Id" , "ParentId1" } ,
294
- { "Correlation-Context " , "Key1=value1, Key2=value2" }
294
+ { "baggage " , "Key1=value1, Key2=value2" }
295
295
}
296
296
} ) ;
297
297
hostingApplication . CreateContext ( features ) ;
@@ -301,6 +301,67 @@ public void ActivityParentIdAndBaggeReadFromHeaders()
301
301
Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key2" && pair . Value == "value2" ) ;
302
302
}
303
303
304
+ [ Fact ]
305
+ public void ActivityBaggageReadFromLegacyHeaders ( )
306
+ {
307
+ var diagnosticListener = new DiagnosticListener ( "DummySource" ) ;
308
+ var hostingApplication = CreateApplication ( out var features , diagnosticListener : diagnosticListener ) ;
309
+
310
+ diagnosticListener . Subscribe ( new CallbackDiagnosticListener ( pair => { } ) ,
311
+ s =>
312
+ {
313
+ if ( s . StartsWith ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , StringComparison . Ordinal ) )
314
+ {
315
+ return true ;
316
+ }
317
+ return false ;
318
+ } ) ;
319
+
320
+ features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
321
+ {
322
+ Headers = new HeaderDictionary ( )
323
+ {
324
+ { "Request-Id" , "ParentId1" } ,
325
+ { "Correlation-Context" , "Key1=value1, Key2=value2" }
326
+ }
327
+ } ) ;
328
+ hostingApplication . CreateContext ( features ) ;
329
+ Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
330
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key1" && pair . Value == "value1" ) ;
331
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key2" && pair . Value == "value2" ) ;
332
+ }
333
+
334
+ [ Fact ]
335
+ public void ActivityBaggagePrefersW3CBaggageHeaderName ( )
336
+ {
337
+ var diagnosticListener = new DiagnosticListener ( "DummySource" ) ;
338
+ var hostingApplication = CreateApplication ( out var features , diagnosticListener : diagnosticListener ) ;
339
+
340
+ diagnosticListener . Subscribe ( new CallbackDiagnosticListener ( pair => { } ) ,
341
+ s =>
342
+ {
343
+ if ( s . StartsWith ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , StringComparison . Ordinal ) )
344
+ {
345
+ return true ;
346
+ }
347
+ return false ;
348
+ } ) ;
349
+
350
+ features . Set < IHttpRequestFeature > ( new HttpRequestFeature ( )
351
+ {
352
+ Headers = new HeaderDictionary ( )
353
+ {
354
+ { "Request-Id" , "ParentId1" } ,
355
+ { "Correlation-Context" , "Key1=value1, Key2=value2" } ,
356
+ { "baggage" , "Key1=value3, Key2=value4" }
357
+ }
358
+ } ) ;
359
+ hostingApplication . CreateContext ( features ) ;
360
+ Assert . Equal ( "Microsoft.AspNetCore.Hosting.HttpRequestIn" , Activity . Current . OperationName ) ;
361
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key1" && pair . Value == "value3" ) ;
362
+ Assert . Contains ( Activity . Current . Baggage , pair => pair . Key == "Key2" && pair . Value == "value4" ) ;
363
+ }
364
+
304
365
[ Fact ]
305
366
public void ActivityBaggagePreservesItemsOrder ( )
306
367
{
@@ -322,7 +383,7 @@ public void ActivityBaggagePreservesItemsOrder()
322
383
Headers = new HeaderDictionary ( )
323
384
{
324
385
{ "Request-Id" , "ParentId1" } ,
325
- { "Correlation-Context " , "Key1=value1, Key2=value2, Key1=value3" } // duplicated keys allowed by the contract
386
+ { "baggage " , "Key1=value1, Key2=value2, Key1=value3" } // duplicated keys allowed by the contract
326
387
}
327
388
} ) ;
328
389
hostingApplication . CreateContext ( features ) ;
@@ -359,7 +420,7 @@ public void ActivityBaggageValuesAreUrlDecodedFromHeaders()
359
420
Headers = new HeaderDictionary ( )
360
421
{
361
422
{ "Request-Id" , "ParentId1" } ,
362
- { "Correlation-Context " , "Key1=value1%2F1" }
423
+ { "baggage " , "Key1=value1%2F1" }
363
424
}
364
425
} ) ;
365
426
hostingApplication . CreateContext ( features ) ;
@@ -389,7 +450,7 @@ public void ActivityTraceParentAndTraceStateFromHeaders()
389
450
{
390
451
{ "traceparent" , "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" } ,
391
452
{ "tracestate" , "TraceState1" } ,
392
- { "Correlation-Context " , "Key1=value1, Key2=value2" }
453
+ { "baggage " , "Key1=value1, Key2=value2" }
393
454
}
394
455
} ) ;
395
456
hostingApplication . CreateContext ( features ) ;
0 commit comments