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

HTTP info not applies to local scope #2337

Closed
JLuse opened this issue Apr 27, 2023 · 3 comments · Fixed by #2339
Closed

HTTP info not applies to local scope #2337

JLuse opened this issue Apr 27, 2023 · 3 comments · Fixed by #2339
Assignees
Labels
ASP.NET Core Bug Something isn't working

Comments

@JLuse
Copy link

JLuse commented Apr 27, 2023

Package

Sentry.AspNetCore

SDK Version

3.30.0

Steps to Reproduce

Description:
When trying to addBreadcrumbs to local scope, HTTP info/context is not applied to events unless you capture an event to the global scope prior to applying breadcrumbs to local scope. Test utilizing UseSentry() and attached repro app - MyWebApp.zip

Steps to repro:

  1. Add DSN
  2. Navigate to Index.cshtml.cs -> Run with local scope -> event has breadcrumbs with missing HTTP context
  3. Uncomment first try/catch -> run -> find event with breadcrumbs now has HTTP context
  4. Comment first try/catch -> Uncomment last try/catch -> run -> now eventa with local scope has breadcrumbs with missing HTTP context

Expected Result

Issues to have HTTP context when addingBreadcrumbs to the local scope when initializing with UseSentry()

Actual Result

Only when adding the global scope first, is the HTTP context applied for local scope

@mattjohnsonpint
Copy link
Contributor

Thanks for reporting. I'll take a look soon.

@mattjohnsonpint
Copy link
Contributor

Thanks for the app sample. On further investigation, a smaller reproduction of the same bug is:

using Sentry;

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseSentry(dsn);

var app = builder.Build();
app.MapGet("/", () =>
{
    SentrySdk.CaptureMessage("test", scope => { });
    return "ok";
});

app.Run();

That will capture a message, but the HTTP request context is absent from the event. Remove the scope argument from the capture call, and it works fine.

I believe I know what's causing this, and I should have a fix ready shortly. Thanks.

@mattjohnsonpint
Copy link
Contributor

FYI - It's not just the HTTP Request context, but rather anything that is added to the scope by the ASP.NET Core Middleware at this point:

scope.OnEvaluating += (_, _) =>
{
SyncOptionsScope(hub);
PopulateScope(context, scope);
};

That could be many things, depending on how the app is configured.

There are two issues here:

  1. When a scope is cloned, the OnEvaluating handler is not copied over to the new scope. So the event doesn't fire on the scope that is used while capturing, but rather it fires on its parent. Since the scope has already been cloned, there's no further effect on the child scope.
  2. Even if it were to fire on the correct scope, it's still applying data to the original scope instead of the new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core Bug Something isn't working
Projects
Archived in project
2 participants