Minor perf improvement for AspNetCore instrumentation (#5157)

This commit is contained in:
Utkarsh Umesan Pillai 2023-12-11 20:56:26 -08:00 committed by GitHub
parent ffc17408fd
commit 0278deb7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -39,7 +39,17 @@ internal class HttpInListener : ListenerHandler
private const string DiagnosticSourceName = "Microsoft.AspNetCore";
private const string UnknownHostName = "UNKNOWN-HOST";
private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) => request.Headers[name];
private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) =>
{
if (request.Headers.TryGetValue(name, out var value))
{
// This causes allocation as the `StringValues` struct has to be casted to an `IEnumerable<string>` object.
return value;
}
return Enumerable.Empty<string>();
};
private static readonly PropertyFetcher<Exception> ExceptionPropertyFetcher = new("Exception");
#if !NET6_0_OR_GREATER