Activity.Baggage values are now be Url decoded in HostingApplicationDiagnostics. (#18948)

This commit is contained in:
Vaughan Reid 2020-02-20 00:03:36 +02:00 committed by GitHub
parent 76d197f0dd
commit b6698757a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
@ -272,7 +273,7 @@ namespace Microsoft.AspNetCore.Hosting
{
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()));
}
}
}

View File

@ -345,6 +345,35 @@ namespace Microsoft.AspNetCore.Hosting.Tests
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]
public void ActivityTraceParentAndTraceStateFromHeaders()