SentryEvent class does not contain a property that stores the scoped ServiceProvider #893
Replies: 3 comments
-
Consider creating an EventProcessor instead and registering it in the DI container. Here's an example registering it: here's an example processor: |
Beta Was this translation helpful? Give feedback.
-
I tried using the processors, and it works really well. But i'm having some problems related to using scoped services inside the
This means that i won't be able to inject scoped dependencies inside my ISentryEventProcessor, and since this is a backgroundJob there's no httpContext available. Is there any way to circumvent/fix this? |
Beta Was this translation helpful? Give feedback.
-
This seems related to #318 In your case there might be a work around, something like: using Sentry;
[BackgroundJobQueueFilter]
[AutomaticRetry(Attempts = 3)]
public async Task Execute(BaseBackgroundJobInfo args, IJobCancellationToken jobCancellationToken = null)
{
using (var scope = _serviceProvider.CreateScope())
{
var hub = scope.Resolve<IHub>()
using (hub.PushScope())
{
hub.ConfigureScope(s => {
s.AddEventProcessor(scope.Resolve<WhateverScopedDependency>());
});
// Now if events are captured below this point, the processor added above will be executed
var context = GetBackgroundJobExecutionContext(scope.ServiceProvider, args);
await ResolveAmbientData(scope.ServiceProvider);
await SetMultiTenancyProperties(scope.ServiceProvider);
await MediateStartupTasksAsync(scope.ServiceProvider);
await _backgroundJobExecutor.ExecuteAsync(context, jobCancellationToken);
}
}
} I didn't run this but I hope it explains the work around I'm suggesting. It will create a Sentry scope, you can add the event processor you want in that scope, so while inside the And since you have the correct scoped service provider, it should work as you expect. The solution to #318 still would need to be worked on. Maybe we need to do what I suggested above inside the |
Beta Was this translation helpful? Give feedback.
-
Please mark the type framework used:
Please mark the type of the runtime used:
Please mark the NuGet packages used:
Hello, i am trying to use the Sentry.AspNetCore for logging exceptions. But right now i'm facing a issue, i'm trying to put informations in my tags by modyfing the BeforeSend property and the problem is that the SentryEvent class does not contain a property for the scoped serviceProvider that contains the informations that i needed in the first place.
options.BeforeSend = sentryEvent => { sentryEvent.ServiceProvider; return sentryEvent; };
I believe that we are able to get the service provider by changing the InvokeAsync method inside the SentryMiddleware class with the following change:
Is this a valid change? Is there another way of doing it?
Beta Was this translation helpful? Give feedback.
All reactions