Skip to content

SentryEvent class does not contain a property that stores the scoped ServiceProvider #488

@LucasRomankiu

Description

@LucasRomankiu

Please mark the type framework used:

  • ASP.NET MVC
  • ASP.NET Web API (OWIN)
  • [X ] ASP.NET Core
  • WPF
  • WinForms
  • Xamarin
  • Other:

Please mark the type of the runtime used:

  • .NET Framework
  • Mono
  • [X ] .NET Core
  • Version: 3.1

Please mark the NuGet packages used:

  • Sentry
  • Sentry.Serilog
  • Sentry.NLog
  • Sentry.Log4Net
  • Sentry.Extensions.Logging
  • [X ] Sentry.AspNetCore
  • Version: 2.1.6

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:

                void CaptureException(Exception e)
                {
                    var evt = new SentryEvent(e);

                    // ServiceProvider is the new property to be implemented that is responsible for storing the IServiceProvider
                    evt.ServiceProvider = context.RequestServices;

                    _logger?.LogTrace("Sending event '{SentryEvent}' to Sentry.", evt);

                    var id = hub.CaptureEvent(evt);

                    _logger?.LogInformation("Event '{id}' queued.", id);
                }

Is this a valid change? Is there another way of doing it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionFurther information is requested
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions