Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASM] Remove httpcontext from context store at the end of the request #6151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tracer/src/Datadog.Trace/AppSec/CoreHttpContextStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class CoreHttpContextStore

public static readonly CoreHttpContextStore Instance = new();

private readonly AsyncLocal<HttpContext> _localStore = new();
private readonly AsyncLocal<HttpContext?> _localStore = new();

public HttpContext? Get()
{
Expand All @@ -36,6 +36,8 @@ internal class CoreHttpContextStore
}

public void Set(HttpContext context) => _localStore.Value = context;

public void Remove() => _localStore.Value = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ private void OnHostingHttpRequestInStop(object arg)
AspNetCoreRequestHandler.StopAspNetCorePipelineScope(tracer, CurrentSecurity, rootScope, httpContext);
}

CoreHttpContextStore.Instance.Remove();

// If we don't have a scope, no need to call Stop pipeline
}

Expand All @@ -689,6 +691,8 @@ private void OnHostingUnhandledException(object arg)
AspNetCoreRequestHandler.HandleAspNetCoreException(tracer, CurrentSecurity, rootSpan, httpContext, unhandledStruct.Exception);
}

CoreHttpContextStore.Instance.Remove();

// If we don't have a span, no need to call Handle exception
}

Expand Down
Loading