SentryEventProcessors not working with ASP.NET and Serilog using ILoggerFactory

103 Views Asked by At

After upgrading the Sentry NuGet packages from v3.22.0 to v3.23.1 in my ASP.NET application, I'm experiencing issues with the event flow and processors of Sentry in background contexts such as Background Jobs and Background Services. Previously, when an exception occurred within these contexts, I used Log.Error to log the exception, and the event was sent to Sentry, passing through the SentryEventProcessors before reaching the final destination. However, in the new version, although the event is still being sent to Sentry, it doesn't go through the processors, and I need to manually configure them using SentrySdk.ConfigureScope(s => s.AddEventProcessor(processor)). Furthermore, within the Background Service, the events don't even reach Sentry, unlike in controllers where the processor flow works correctly. I couldn't find any information about this change in the repository's changelog. Below is a code snippet illustrating the issue. I realized this by updating the packages to the latest version, but I noticed that this occurs from v3.22.0 to v3.23.0. Has anyone encountered this problem or knows how to address the event flow and processors issue in the background context with Sentry?

        private static void LogException(Exception exception, IServiceProvider serviceProvider,
            IBackgroundJobExecutionContext context)
        {
            // var processor = serviceProvider.GetRequiredService<ISentryEventProcessor>();
            // SentrySdk.ConfigureScope(s => s.AddEventProcessor(processor));
            var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
            var logger = loggerFactory.CreateLogger(context.ConcreteJobType);
            logger.LogError(exception, "Error while processing {ConcreteJobType}", context.ConcreteJobType);
        }

I'm using ILoggerFactory to get the logger. This same code inside a controller works normally. sentry-dotnet changelog

I would like to be able to update package versions without having to, in certain scopes, manually configure processors and other data for Sentry.

0

There are 0 best solutions below