Replies: 12 comments
-
Could you please, for now, try to get rid of this log with this filter: 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)); |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia My issue is not with the log entry, but with capturing the exception. I need the full stacktrace from the exception to be shown in Sentry. Right now, Sentry is cutting off part of the exception stacktrace. *Adding the log filter has no effect. (Because I'm capturing the exception with |
Beta Was this translation helpful? Give feedback.
-
Sentry ir reporting the stack trace correctly, as it received. The problem here is that EF is logging the error internally. The top of the stack is itself. The issue linked suggests a fix (don't log this exception, it'll be logged when rethrown so from the top of the stack, with the complete stacktrace |
Beta Was this translation helpful? Give feedback.
-
Forgive me, I'm not quite following what you're suggesting. EF throws the exception when Note: I did try your log filter suggestion and it did not change anything (which is what I expected - because I'm talking about capturing the exception not the log message from EF). |
Beta Was this translation helpful? Give feedback.
-
Could you please share a repro so we can look into it? |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia Here is a repro. After playing around with it, it appears Sentry is trying to merge the event from the error log message & the event from the error. When doing this, it keeps the stacktrace from the error log message instead of using the stack trace from the exception. IMO, this should either merge events (keeping/appending the stacktrace/s) or record two separate events. Right now, it's halfway merging in a non-intuitive way. Additionally, adding specific filters for these specific error messages seems like a maintenance nightmare. I think a more generalized configuration of how exceptions & error logs are merged would be a much better solution. *Note: You have to specify the *Note: I was able to filter the event by inverting the |
Beta Was this translation helpful? Give feedback.
-
OK, I ran your example (with an invalid connection string) which is enough to reproduce the error anyway. In Sentry I see 2 events. They are both triggered by the same exception. One of them has the top of the frame You can see that because it has a tag called This event also has the The second event is actually logged once EF Core rethrows that exception and it's captured above, with the complete stacktrace (some frames not visible because App Only is selected): So to clarify a few things: Sentry's SDK simply gets an Exception either by its public API ( This odd exception with "an incomplete stacktrace" is simply an internal That said I suggest we simply filter out messages coming out from that EF Core logger like: o.AddLogEntryFilter((category, level, eventId, exception)
=> eventId.Name == "Microsoft.EntityFrameworkCore.Update.SaveChangesFailed"
&& level == LogLevel.Error); |
Beta Was this translation helpful? Give feedback.
-
Thanks for looking into this. Can you clarify, without any filtering, this given situation should produce two, distinct Sentry events viewable in the Sentry web-app? |
Beta Was this translation helpful? Give feedback.
-
There should be two events, indeed. They will not be grouped together though. Sentry will use the stacktrace for grouping, when available. The frames that are marked |
Beta Was this translation helpful? Give feedback.
-
Basically the code in EF is here: catch (Exception exception)
{
DbContextDependencies.UpdateLogger.SaveChangesFailed(this, exception);
throw;
} So it logs and rethrows. We care about the rethrown error (the logged one isn't helpful) |
Beta Was this translation helpful? Give feedback.
-
@Cooksauce @bruno-garcia EF Core uses an internal logger to log the exception internally. Since Sentry subscribes to the logging system, this log reaches Sentry and gets sent as an error. Next, the error bubbles up, and Sentry catches that too; however I believe Sentry SDK might be de-duplicating the latter exception (the Sentry has an exception de-duplication filter). This means only the internal exception is sent to Sentry, which hasn't had the chance to bubble up to the user code, so the stacktrace ends up missing a part. The filter shared by Bruno is meant to stop the internal exception from being sent, so only the exception bubbling up to the user code is caught. Just add the code to your Sentry config method. 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)); |
Beta Was this translation helpful? Give feedback.
-
Sentry SDK doesn't de duplicate inner exceptions (by default, can opt in) for a few releases now so both events get to Sentry with the latest SDK. |
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:
Details
Sentry fails to properly handle the Stacktrace in
DbUpdateException
thrown EF Core with Npgsql provider.Half of the stacktrace (containing all of the application method calls) is completely dropped.
Sentry "Raw" Stacktrace (shown in Sentry web-app):
Actual Stacktrace (captured right before call to
SentrySdk.CaptureException(..)
):Beta Was this translation helpful? Give feedback.
All reactions