Skip to content

Sentry does not log failed db queries on EF Core 7 #2044

Open
@mattjohnsonpint

Description

@mattjohnsonpint

Using Entity Framework Core 7 (on either .NET 6 or .NET 7), when an error occurs in a database query, Sentry will capture the exception, but it will not correctly capture the query that caused the exception like it does on EF Core 6 and lower.

Initially this was logged as an issue with the EF Core team however later Matt concludes it's related to an issue with SqlClient when an OUTPUT clause is present (or when batch statements are executed):

Currently, diagnostic events are supported on SqlConnection, SqlCommand, and SqlTrnsaction. When an OUTPUT clause is used in an insert expression by calling the ExecuteReader() function, the exception defers to the SqlDataReader.Read() function call, which is out of scope of diagnostic support in SqlClient at the moment.

The fact we discovered this in EFCore 7 is incidental as EFCore 7 changed the way inserts are handled when capturing the inserted IDs to use OUTPUT statements rather than selecting identity records.

There's no known workaround at this time. We'll keep this issue open to track the problem in Sentry until it is resolved upstream by Microsoft.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions