sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

Filter out EF Core internal log in Sentry.Extensions.Logging

Open bruno-garcia opened this issue 4 years ago • 3 comments

Please mark the NuGet packages used:

  • [x] Sentry.Extensions.Logging

By default the package should exclude an internal error log from EF Core. It logs as error (with a stack trace that is not helpful) right before throwing.

The user code would anyway log that error once it captures the exception. Or Sentry would log that anyway if unhandled.

c.AddLogEntryFilter((category, level, eventId, exception)
    => eventId.Id == 10000 
       && string.Equals(eventId.Name, "Microsoft.EntityFrameworkCore.Update.SaveChangesFailed", StringComparison.Ordinal)
       && string.Equals(category,"Microsoft.EntityFrameworkCore.Database.Command", StringComparison.Ordinal));

Thanks @kanadaj for raising and proposing the filter.

bruno-garcia avatar Jun 22 '20 16:06 bruno-garcia

@bruno-garcia This might need an integration test (we'd want to monitor the behaviour inside an asp.net core request both with and without a try-catch in the Action), but I believe there isn't one set up currently so this might be a problem.

kanadaj avatar Jun 22 '20 16:06 kanadaj

@bruno-garcia I think the "stack trace that is not helpful" part of this is related to #455

Cooksauce avatar Jun 25 '20 19:06 Cooksauce

Yes. The Sentry SDK is doing it's job and logging something as it was provided to it. EF Core though is logging in the middle which doesn't include the stack trace. This issue suggest just dropping that log entry altogether (since it'll be logged once rethrown)

bruno-garcia avatar Jun 25 '20 22:06 bruno-garcia