You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transient EventProcessor not getting picked up 3.23.0 and newer #2529
I'm having an issue where I'm trying to update Sentry from 3.22.0 to 3.23.0+ and this causes the EventProcessor that handles a BackgroundJob to stop working. As a result, tags are no longer being sent to Sentry.io, even though the error itself is being captured.
Go to appsettings.json and change Dsn to your own.
Leave a breakpoint in the Process method of MyEventProcessor class.
Debug. The method is going to be called.
Update Sentry.AspNetCore and Sentry.Serilog from 3.22.0 to 3.23.0 or higher.
Debug. The method should keep being called, but it's not.
Expected Result
By updating Sentry to 3.23.0+, EventProcessor should keep being called and the tag "Tag Value Test" should be sent to Sentry.io, like in 3.22.0, as the screenshot shows:
3.22.0 version
Actual Result
By updating Sentry to 3.23.0+, EventProcessor stops being called and tag "Tag Value Test" is not sent to Sentry.io, as the screenshot shows:
As far as I can tell this happened with changes to the SentryMiddleware in #1979 I'm not sure yet if that was an intentional change or an uncaught side effect.
But to unblock you, you can add your global eventprocessor directly to the options like so instead:
To keep the context in one place: Adding an ISentryEventProcessor as transient does no longer work.
using Sentry.Extensibility;
using SentryBackgroundJobShowcase;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseSentry();
builder.Services
.AddHostedService<AddBackgroundJobHostedService>()
.AddTransient<ISentryEventProcessor, MyEventProcessor>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseRouting();
app.Run();
changed the title [-]EventProcessor stops working by updating Sentry version from 3.22.0 to 3.23.0[/-][+]Transient `EventProcessor` not getting picked up `3.23.0` and newer[/+]on Dec 4, 2023
One issue with requiring people to register event processors directly in the Options callback is that it's more difficult to inject dependencies into their custom event processors... so it would be nice if we could reintroduce support for registering these via DI rather than the options callback.
As far as I can tell this happened with changes to the SentryMiddleware in #1979 I'm not sure yet if that was an intentional change or an uncaught side effect.
It looks like it was moved to the middleware so processors could be registered on the scope to address:
Edit: and using @arthursilvakorp's sample project I can reproduce this if I move the logic back to the ApplicationBuilderExtensions... which I guess is good news. At least we understand now why the original change was made.
The only thing remaining now is to come up with a change that will fix both problems...
The original/existing solution to do all of this in the SentryMiddleware works because the SentryMiddleware gets created by the ServiceProvider (and so all of those providers just get injected automatically via the constructor, whether they're singleton, scoped or transient).
For the background service we can't do this because the Sink gets constructed explicitly:
Neither the Sink nor the Hub (which it depends on) have any idea about service providers...
We could maybe create some processor resolver Func in the Hub as an AsyncLocal and have the middleware wire the resolver up. I think that could work for singleton and transient dependencies.
It might result in unexpected behaviour for processors with Scoped lifetime when these run in the context of a background service... as that scenario effectively creates a Captive dependency.
I'll play around and see if I can get something working though.
Activity
bitsandfoxes commentedon Aug 4, 2023
Thanks for raising the issue and providing a repro. We'll take a look.
bitsandfoxes commentedon Aug 4, 2023
As far as I can tell this happened with changes to the
SentryMiddlewarein #1979 I'm not sure yet if that was an intentional change or an uncaught side effect.But to unblock you, you can add your global eventprocessor directly to the options like so instead:
bitsandfoxes commentedon Dec 4, 2023
To keep the context in one place: Adding an
ISentryEventProcessoras transient does no longer work.[-]EventProcessor stops working by updating Sentry version from 3.22.0 to 3.23.0[/-][+]Transient `EventProcessor` not getting picked up `3.23.0` and newer[/+]jamescrosswell commentedon Dec 4, 2023
One issue with requiring people to register event processors directly in the Options callback is that it's more difficult to inject dependencies into their custom event processors... so it would be nice if we could reintroduce support for registering these via DI rather than the options callback.
bitsandfoxes commentedon Jun 27, 2024
There's another repro in: #3454
jamescrosswell commentedon Jul 10, 2024
It looks like it was moved to the middleware so processors could be registered on the scope to address:
Edit: and using @arthursilvakorp's sample project I can reproduce this if I move the logic back to the
ApplicationBuilderExtensions... which I guess is good news. At least we understand now why the original change was made.The only thing remaining now is to come up with a change that will fix both problems...
jamescrosswell commentedon Jul 10, 2024
Tricky...
The original/existing solution to do all of this in the SentryMiddleware works because the SentryMiddleware gets created by the ServiceProvider (and so all of those providers just get injected automatically via the constructor, whether they're singleton, scoped or transient).
For the background service we can't do this because the Sink gets constructed explicitly:
sentry-dotnet/src/Sentry.Serilog/SentrySinkExtensions.cs
Line 350 in 351adea
Neither the Sink nor the Hub (which it depends on) have any idea about service providers...
We could maybe create some processor resolver Func in the Hub as an AsyncLocal and have the middleware wire the resolver up. I think that could work for singleton and transient dependencies.
It might result in unexpected behaviour for processors with Scoped lifetime when these run in the context of a background service... as that scenario effectively creates a Captive dependency.
I'll play around and see if I can get something working though.
jamescrosswell commentedon Jul 12, 2024
I'm out of ideas unfortunately. See comment in the PR that I had prepared to address this:
For the time being then, the only way to have custom providers in background workers is by adding these on the
SentryOptionsdirectly.