Skip to content

Transient EventProcessor not getting picked up 3.23.0 and newer #2529

Closed

Description

@arthursilvakorp

Package

Sentry.AspNetCore

.NET Flavor

.NET Core

.NET Version

6.0

OS

Windows

SDK Version

3.23.0 or higher

Self-Hosted Sentry Version

No response

Steps to Reproduce

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.

Steps to reproduce:

  • Clone the following repository: https://github.com/arthursilvakorp/sentry-background-job
  • 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
3 22 - 1

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:

3.23.0+ version
3 23

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀on Aug 3, 2023
  2. self-assigned this
    on Aug 4, 2023
  3. bitsandfoxes commented on Aug 4, 2023

    @bitsandfoxes
    Contributor

    Thanks for raising the issue and providing a repro. We'll take a look.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀on Aug 4, 2023
  5. bitsandfoxes commented on Aug 4, 2023

    @bitsandfoxes
    Contributor

    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:

    builder.WebHost.UseSentry( options => options.AddEventProcessor(new MyEventProcessor()));
    
  6. removed their assignment
    on Oct 23, 2023
  7. bitsandfoxes commented on Dec 4, 2023

    @bitsandfoxes
    Contributor

    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();
    
  8. 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
  9. jamescrosswell commented on Dec 4, 2023

    @jamescrosswell
    Collaborator

    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.

  10. bitsandfoxes commented on Jun 27, 2024

    @bitsandfoxes
    Contributor

    There's another repro in: #3454

  11. jamescrosswell commented on Jul 10, 2024

    @jamescrosswell
    Collaborator

    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...

  12. jamescrosswell commented on Jul 10, 2024

    @jamescrosswell
    Collaborator

    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:

    return loggerConfiguration.Sink(new SentrySink(options, sdkDisposable), minimumOverall);

    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.

  13. jamescrosswell commented on Jul 12, 2024

    @jamescrosswell
    Collaborator

    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 SentryOptions directly.

  14. added
    Wont FixThis will not be worked on
    and removed
    BugSomething isn't working
    on Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions