Skip to content

Commit bc14e1f

Browse files
committed
Inline checks for AddHeaderTagsToSpan
1 parent 3c77dd7 commit bc14e1f

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#if !NETFRAMEWORK
77
using System;
88
using System.Collections.Generic;
9+
using System.Collections.ObjectModel;
910
using System.Linq;
1011
using Datadog.Trace.AppSec;
1112
using Datadog.Trace.AppSec.Coordinator;
@@ -74,29 +75,24 @@ private PropagationContext ExtractPropagatedContext(Tracer tracer, HttpRequest r
7475
return default;
7576
}
7677

77-
private void AddHeaderTagsToSpan(ISpan span, HttpRequest request, Tracer tracer)
78+
private void AddHeaderTagsToSpan(ISpan span, HttpRequest request, Tracer tracer, ReadOnlyDictionary<string, string> headerTagsInternal)
7879
{
79-
var headerTagsInternal = tracer.CurrentTraceSettings.Settings.HeaderTags;
80-
81-
if (!headerTagsInternal.IsNullOrEmpty())
80+
try
8281
{
83-
try
84-
{
85-
// extract propagation details from http headers
86-
if (request.Headers is { } requestHeaders)
87-
{
88-
tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(
89-
span,
90-
new HeadersCollectionAdapter(requestHeaders),
91-
headerTagsInternal,
92-
defaultTagPrefix: SpanContextPropagator.HttpRequestHeadersTagPrefix);
93-
}
94-
}
95-
catch (Exception ex)
82+
// extract propagation details from http headers
83+
if (request.Headers is { } requestHeaders)
9684
{
97-
_log.Error(ex, "Error extracting propagated HTTP headers.");
85+
tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(
86+
span,
87+
new HeadersCollectionAdapter(requestHeaders),
88+
headerTagsInternal,
89+
defaultTagPrefix: SpanContextPropagator.HttpRequestHeadersTagPrefix);
9890
}
9991
}
92+
catch (Exception ex)
93+
{
94+
_log.Error(ex, "Error extracting propagated HTTP headers.");
95+
}
10096
}
10197

10298
public Scope StartAspNetCorePipelineScope(Tracer tracer, Security security, Iast.Iast iast, HttpContext httpContext, string resourceName)
@@ -125,7 +121,13 @@ public Scope StartAspNetCorePipelineScope(Tracer tracer, Security security, Iast
125121

126122
var scope = tracer.StartActiveInternal(_requestInOperationName, extractedContext.SpanContext, tags: tags, links: extractedContext.Links);
127123
scope.Span.DecorateWebServerSpan(resourceName, httpMethod, host, url, userAgent, tags);
128-
AddHeaderTagsToSpan(scope.Span, request, tracer);
124+
125+
var headerTagsInternal = tracer.CurrentTraceSettings.Settings.HeaderTags;
126+
if (!headerTagsInternal.IsNullOrEmpty())
127+
{
128+
AddHeaderTagsToSpan(scope.Span, request, tracer, headerTagsInternal);
129+
}
130+
129131
tracer.TracerManager.SpanContextPropagator.AddBaggageToSpanAsTags(scope.Span, extractedContext.Baggage, tracer.Settings.BaggageTagKeys);
130132

131133
var originalPath = request.PathBase.HasValue ? request.PathBase.Add(request.Path) : request.Path;

0 commit comments

Comments
 (0)