Activity.Baggage values are now be Url decoded in HostingApplicationDiagnostics. (#18948)
This commit is contained in:
parent
76d197f0dd
commit
b6698757a8
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Web;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
@ -272,7 +273,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
if (NameValueHeaderValue.TryParse(item, out var baggageItem))
|
if (NameValueHeaderValue.TryParse(item, out var baggageItem))
|
||||||
{
|
{
|
||||||
activity.AddBaggage(baggageItem.Name.ToString(), baggageItem.Value.ToString());
|
activity.AddBaggage(baggageItem.Name.ToString(), HttpUtility.UrlDecode(baggageItem.Value.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,35 @@ namespace Microsoft.AspNetCore.Hosting.Tests
|
||||||
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
|
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ActivityBaggageValuesAreUrlDecodedFromHeaders()
|
||||||
|
{
|
||||||
|
var diagnosticListener = new DiagnosticListener("DummySource");
|
||||||
|
var hostingApplication = CreateApplication(out var features, diagnosticListener: diagnosticListener);
|
||||||
|
|
||||||
|
diagnosticListener.Subscribe(new CallbackDiagnosticListener(pair => { }),
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (s.StartsWith("Microsoft.AspNetCore.Hosting.HttpRequestIn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
features.Set<IHttpRequestFeature>(new HttpRequestFeature()
|
||||||
|
{
|
||||||
|
Headers = new HeaderDictionary()
|
||||||
|
{
|
||||||
|
{"Request-Id", "ParentId1"},
|
||||||
|
{"Correlation-Context", "Key1=value1%2F1"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
hostingApplication.CreateContext(features);
|
||||||
|
Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", Activity.Current.OperationName);
|
||||||
|
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key1" && pair.Value == "value1/1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ActivityTraceParentAndTraceStateFromHeaders()
|
public void ActivityTraceParentAndTraceStateFromHeaders()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue