Skip to content

Commit 9863b8b

Browse files
anna-gitNachoEchevarriaandrewlock
authored
Set resource name after exception in OnEndRequest method (#8439)
When no resource-based sampling rules are configured, the resource name was only set in OnEndRequest. If OnEndRequest doesn't complete (e.g., client disconnect), the resource name remained null and defaulted to the operation name aspnet.request in Span.Finish(). This fix ensures the resource name is always set early in OnBeginRequest. Fixes APMS-19184 Made-with: Cursor ## Summary of changes ## Reason for change https://datadoghq.atlassian.net/browse/APMS-19184 ## Implementation details ## Test coverage ## Other details <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: NachoEchevarria <ignacio.echevarria@datadoghq.com> Co-authored-by: NachoEchevarria <53266532+NachoEchevarria@users.noreply.github.com> Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com>
1 parent b176976 commit 9863b8b

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="TracingHttpModule.cs" company="Datadog">
1+
// <copyright file="TracingHttpModule.cs" company="Datadog">
22
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
33
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
44
// </copyright>
@@ -130,10 +130,10 @@ private void OnBeginRequest(object sender, EventArgs eventArgs)
130130
Scope scope = null;
131131
Scope inferredProxyScope = null;
132132
bool shouldDisposeScope = true;
133+
var tracer = Tracer.Instance;
134+
133135
try
134136
{
135-
var tracer = Tracer.Instance;
136-
137137
if (!tracer.CurrentTraceSettings.Settings.IsIntegrationEnabled(IntegrationId))
138138
{
139139
// integration disabled
@@ -263,6 +263,18 @@ private void OnBeginRequest(object sender, EventArgs eventArgs)
263263
if (shouldDisposeScope)
264264
{
265265
// Dispose here, as the scope won't be in context items and won't get disposed on request end in that case...
266+
try
267+
{
268+
if (scope?.Span is { ResourceName: null } span)
269+
{
270+
span.ResourceName = BuildResourceName(tracer, (sender as HttpApplication)?.Context?.Request);
271+
}
272+
}
273+
catch (Exception ex2)
274+
{
275+
Log.Debug(ex2, "Unable to set fallback resource name.");
276+
}
277+
266278
scope?.Dispose();
267279
inferredProxyScope?.Dispose();
268280
}
@@ -417,6 +429,18 @@ private void OnEndRequest(object sender, EventArgs eventArgs)
417429
}
418430
finally
419431
{
432+
try
433+
{
434+
if (scope.Span.ResourceName is null)
435+
{
436+
scope.Span.ResourceName = BuildResourceName(tracer, app.Request);
437+
}
438+
}
439+
catch (Exception ex)
440+
{
441+
Log.Debug(ex, "Unable to set fallback resource name.");
442+
}
443+
420444
scope.Dispose();
421445
proxyScope?.Dispose();
422446
// Clear the context to make sure another TracingHttpModule doesn't try to close the same scope

0 commit comments

Comments
 (0)