Skip to content

Commit

Permalink
Do not mark 404 responses as errors (#568)
Browse files Browse the repository at this point in the history
* Reproduce error spans for 404 response

Co-authored-by: Mateusz Łach <[email protected]>

* document existing behaviour

* fix part 1

* fix part 2

* cleanup test

* OWIN tests case fix

* add missing // Modified by Splunk Inc.

* typo fix

* update changelog

Co-authored-by: Mateusz Łach <[email protected]>
  • Loading branch information
Kielek and lachmatt authored Aug 11, 2022
1 parent 34dc24f commit bd166e5
Show file tree
Hide file tree
Showing 36 changed files with 1,192 additions and 62 deletions.
96 changes: 50 additions & 46 deletions Datadog.Trace.sln
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Telemetry", "tracer
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox.AutomaticInstrumentation", "tracer\test\test-applications\regression\Sandbox.AutomaticInstrumentation\Sandbox.AutomaticInstrumentation.csproj", "{10619BA2-AED1-482A-8570-BB7C7B83DDDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Datadog.Trace.Coverage.collector", "tracer\src\Datadog.Trace.Coverage.collector\Datadog.Trace.Coverage.collector.csproj", "{7A0D8A39-C60D-4BA1-93AB-D429080BBFA5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Trace.Coverage.collector", "tracer\src\Datadog.Trace.Coverage.collector\Datadog.Trace.Coverage.collector.csproj", "{7A0D8A39-C60D-4BA1-93AB-D429080BBFA5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.TraceAnnotations", "tracer\test\test-applications\integrations\Samples.TraceAnnotations\Samples.TraceAnnotations.csproj", "{230A9B80-E1AA-469F-86F2-B7E257F14E66}"
EndProject
Expand Down Expand Up @@ -468,16 +468,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.InstrumentedAssembl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.InstrumentedAssemblyVerification.Standalone", "tracer\src\Datadog.InstrumentedAssemblyVerification.Standalone\Datadog.InstrumentedAssemblyVerification.Standalone.csproj", "{61FD6A7E-38EB-4B90-A890-DE3205C041B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.AspNetMvc5CustomException", "tracer\test\test-applications\aspnet\Samples.AspNetMvc5CustomException\Samples.AspNetMvc5CustomException.csproj", "{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{3c6dd42e-9214-4747-92ba-78de29aace59}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{6d86109f-b7c9-477d-86d7-45735a3a0818}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{7b0822f6-80de-4b49-8125-93975678d0d5}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{99a62ccf-8e7f-4d57-8383-d38c371c8087}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{b6a98887-4a47-4c19-9c6f-d833e24f4b1c}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{bbb60b0f-bf01-4499-936a-4a299a9acfd4}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{fab2b108-e5be-4647-869b-1dc5d362252e}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -2251,6 +2244,30 @@ Global
{47DA933E-8DBC-4B03-A1D1-2BBE5F4D0D70}.Release|x64.Build.0 = Release|x64
{47DA933E-8DBC-4B03-A1D1-2BBE5F4D0D70}.Release|x86.ActiveCfg = Release|Win32
{47DA933E-8DBC-4B03-A1D1-2BBE5F4D0D70}.Release|x86.Build.0 = Release|Win32
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x64.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x64.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x86.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x86.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|Any CPU.Build.0 = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x64.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x64.Build.0 = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x86.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x86.Build.0 = Release|Any CPU
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|Any CPU.ActiveCfg = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|Any CPU.Build.0 = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x64.ActiveCfg = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x64.Build.0 = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x86.ActiveCfg = Debug|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x86.Build.0 = Debug|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|Any CPU.ActiveCfg = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|Any CPU.Build.0 = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x64.ActiveCfg = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x64.Build.0 = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x86.ActiveCfg = Release|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x86.Build.0 = Release|x86
{CD816C0C-D116-49A1-93A7-8095594224EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD816C0C-D116-49A1-93A7-8095594224EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD816C0C-D116-49A1-93A7-8095594224EB}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -2287,42 +2304,18 @@ Global
{61FD6A7E-38EB-4B90-A890-DE3205C041B1}.Release|x64.Build.0 = Release|Any CPU
{61FD6A7E-38EB-4B90-A890-DE3205C041B1}.Release|x86.ActiveCfg = Release|Any CPU
{61FD6A7E-38EB-4B90-A890-DE3205C041B1}.Release|x86.Build.0 = Release|Any CPU
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|Any CPU.ActiveCfg = Debug|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|Any CPU.Build.0 = Debug|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|x64.ActiveCfg = Debug|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|x64.Build.0 = Debug|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|x86.ActiveCfg = Debug|x86
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Debug|x86.Build.0 = Debug|x86
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|Any CPU.ActiveCfg = Release|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|Any CPU.Build.0 = Release|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|x64.ActiveCfg = Release|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|x64.Build.0 = Release|x64
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|x86.ActiveCfg = Release|x86
{F6A03B6C-EBF9-4581-9904-EDC7270CF3BD}.Release|x86.Build.0 = Release|x86
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x64.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x64.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x86.ActiveCfg = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Debug|x86.Build.0 = Debug|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|Any CPU.Build.0 = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x64.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x64.Build.0 = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x86.ActiveCfg = Release|Any CPU
{4067EAF6-28C5-4B04-9C8A-80720C0541E6}.Release|x86.Build.0 = Release|Any CPU
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|Any CPU.ActiveCfg = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|Any CPU.Build.0 = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x64.ActiveCfg = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x64.Build.0 = Debug|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x86.ActiveCfg = Debug|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Debug|x86.Build.0 = Debug|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|Any CPU.ActiveCfg = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|Any CPU.Build.0 = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x64.ActiveCfg = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x64.Build.0 = Release|x64
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x86.ActiveCfg = Release|x86
{C4CDF6A6-40E5-4CCD-AC4C-143F9F4398CA}.Release|x86.Build.0 = Release|x86
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|x64.ActiveCfg = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|x64.Build.0 = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|x86.ActiveCfg = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Debug|x86.Build.0 = Debug|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|Any CPU.Build.0 = Release|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|x64.ActiveCfg = Release|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|x64.Build.0 = Release|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|x86.ActiveCfg = Release|Any CPU
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2495,8 +2488,19 @@ Global
{CD816C0C-D116-49A1-93A7-8095594224EB} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{FCE813DE-7BF2-4F63-8303-E92F90780C81} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{61FD6A7E-38EB-4B90-A890-DE3205C041B1} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB}
{F71B1B2D-C3E0-49B6-AC29-B96F45E12D5E} = {AFA0AB23-64F0-4AC1-9050-6CE8FE06F580}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{3c6dd42e-9214-4747-92ba-78de29aace59}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{6d86109f-b7c9-477d-86d7-45735a3a0818}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{7b0822f6-80de-4b49-8125-93975678d0d5}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{99a62ccf-8e7f-4d57-8383-d38c371c8087}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{b6a98887-4a47-4c19-9c6f-d833e24f4b1c}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{bbb60b0f-bf01-4499-936a-4a299a9acfd4}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{f71b1b2d-c3e0-49b6-ac29-b96f45e12d5e}*SharedItemsImports = 4
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{fab2b108-e5be-4647-869b-1dc5d362252e}*SharedItemsImports = 4
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this repository adheres to [Semantic Versioning](https://semver.org/spec/v2.

### Bugfixes

- [ASP.NET Web API 2 Instrumentation] Fix the case when the spans was
incorrectly marked as errors when servers return 404 status code.

### Enhancements

## [Release 0.2.7](https://github.com/signalfx/signalfx-dotnet-tracing/releases/tag/v0.2.7)
Expand Down
1 change: 1 addition & 0 deletions tracer/src/Datadog.Trace/AspNet/SharedItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Datadog.Trace.AspNet
internal static class SharedItems
{
public const string HttpContextPropagatedResourceNameKey = "__SignalFx.Tracing.ClrProfiler.Managed.AspNetMvcIntegration-aspnet.resourcename";
public const string HttpContextPropagatedExceptionKey = "__SignalFx.Tracing.ClrProfiler.Managed.AspNetMvcIntegration-aspnet.exception";
private static readonly Func<Stack<Scope>, Scope> Pop = stack => stack.Pop();
private static readonly Func<Stack<Scope>, Scope> Peek = stack => stack.Peek();

Expand Down
10 changes: 7 additions & 3 deletions tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ private void OnEndRequest(object sender, EventArgs eventArgs)
scope.Span.ResourceName = $"{app.Request.HttpMethod.ToUpperInvariant()} {path.ToLowerInvariant()}";
}

if (app.Context.Items[SharedItems.HttpContextPropagatedExceptionKey] is Exception exception && app.Context.Response.StatusCode != 404)
{
scope.Span.SetException(exception);
}

scope.Dispose();
}
finally
Expand Down Expand Up @@ -240,9 +245,8 @@ private void OnError(object sender, EventArgs eventArgs)
var httpContext = (sender as HttpApplication)?.Context;
var exception = httpContext?.Error;

// We want to ignore 404 exceptions here, as they are not errors
var httpException = exception as HttpException;
var is404 = httpException?.GetHttpCode() == 404;
// We want to ignore 404 code as it is not an error
var is404 = httpContext?.Response.StatusCode == 404;

if (httpContext?.Items[_httpContextScopeKey] is Scope scope)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

// Modified by Splunk Inc.

#if NETFRAMEWORK
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -99,8 +101,6 @@ internal static TResponse OnAsyncMethodEnd<TTarget, TResponse>(TTarget instance,

if (exception != null)
{
scope.Span.SetException(exception);

// We don't have access to the final status code at this point
// Ask the HttpContext to call us back to that we can get it
if (httpContext != null)
Expand All @@ -111,14 +111,15 @@ internal static TResponse OnAsyncMethodEnd<TTarget, TResponse>(TTarget instance,
// us to defer finishing the span later while making sure callers of this method do not
// get this scope when calling Tracer.ActiveScope
var now = scope.Span.Context.TraceContext.UtcNow;
httpContext.AddOnRequestCompleted(h => OnRequestCompletedAfterException(h, scope, now));
httpContext.AddOnRequestCompleted(h => OnRequestCompletedAfterException(h, scope, now, exception));

scope.SetFinishOnClose(false);
scope.Dispose();
}
else
{
// Looks like we won't be able to get the final status code
scope.Span.SetException(exception);
scope.Dispose();
}
}
Expand All @@ -132,8 +133,13 @@ internal static TResponse OnAsyncMethodEnd<TTarget, TResponse>(TTarget instance,
return responseMessage;
}

private static void OnRequestCompletedAfterException(HttpContext httpContext, Scope scope, DateTimeOffset finishTime)
private static void OnRequestCompletedAfterException(HttpContext httpContext, Scope scope, DateTimeOffset finishTime, Exception exception)
{
if (httpContext.Response.StatusCode != 404)
{
scope.Span.SetException(exception);
}

HttpContextHelper.AddHeaderTagsFromHttpResponse(httpContext, scope);
scope.Span.SetHttpStatusCode(httpContext.Response.StatusCode, isServer: true, Tracer.Instance.Settings);
scope.Span.Finish(finishTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ internal static CallTargetReturn<TResult> OnMethodEnd<TTarget, TResult>(TTarget
{
if (exception != null)
{
scope.Span.SetException(exception);

// In case of exception, the status code is set further down the ASP.NET pipeline
// We use the OnRequestCompleted callback to be notified when that happens.
// We don't know how long it'll take for ASP.NET to invoke the callback,
Expand All @@ -78,7 +76,7 @@ internal static CallTargetReturn<TResult> OnMethodEnd<TTarget, TResult>(TTarget
// us to defer finishing the span later while making sure callers of this method do not
// get this scope when calling Tracer.ActiveScope
var now = scope.Span.Context.TraceContext.UtcNow;
httpContext.AddOnRequestCompleted(h => OnRequestCompletedAfterException(h, scope, now));
httpContext.AddOnRequestCompleted(h => OnRequestCompletedAfterException(h, scope, now, exception));

scope.SetFinishOnClose(false);
scope.Dispose();
Expand All @@ -94,8 +92,13 @@ internal static CallTargetReturn<TResult> OnMethodEnd<TTarget, TResult>(TTarget
return new CallTargetReturn<TResult>(returnValue);
}

private static void OnRequestCompletedAfterException(HttpContext httpContext, Scope scope, DateTimeOffset finishTime)
private static void OnRequestCompletedAfterException(HttpContext httpContext, Scope scope, DateTimeOffset finishTime, Exception exception)
{
if (httpContext.Response.StatusCode != 404)
{
scope.Span.SetException(exception);
}

HttpContextHelper.AddHeaderTagsFromHttpResponse(httpContext, scope);

if (!HttpRuntime.UsingIntegratedPipeline && httpContext.Response.StatusCode == 200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

// Modified by Splunk Inc.

#if NETFRAMEWORK

using System.ComponentModel;
using System.Threading;
using Datadog.Trace.AspNet;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;

Expand Down Expand Up @@ -51,11 +54,12 @@ internal static CallTargetState OnMethodBegin<TTarget, TExceptionHandler, TExcep
var scope = Tracer.Instance.ActiveScope;
var exception = context.Exception;

if (scope is not null && exception is not null)
var httpContext = System.Web.HttpContext.Current;
if (scope is not null && httpContext is not null && exception is not null)
{
// Only try setting an exception if there's an active span
// The rest of the instrumentation will handle disposing the scope
scope.Span.SetException(exception);
// The exception should be set only when it is available and the response status code is not equal to 404
// as the final status code is not available here (nor when the method finished) the exception has to be registered for further usage.
httpContext.Items[SharedItems.HttpContextPropagatedExceptionKey] = exception;
}

return CallTargetState.GetDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

// Modified by Splunk Inc.

#if NET461
#pragma warning disable SA1402 // File may only contain a single class
#pragma warning disable SA1649 // File name must match first type name
Expand Down
Loading

0 comments on commit bd166e5

Please sign in to comment.