Repository navigation
Description
Part of #5420.
The SDK attaches database statements exactly as the application sent them. Any literal inlined into the SQL, such as WHERE email = '[email protected]', goes to Sentry unchanged. Parameterized commands are fine, because their values aren't in the text. That covers EF Core's captured variables and @id-style ADO.NET parameters.
The data collection spec expects statements to be sanitized or parameterized, and to always be collected. #5433 had planned to gate the raw statement on DatabaseQueryData until we had a sanitizer. #5933 decided against that and closed #5433, so this issue tracks the sanitizing itself.
Where statements are attached
- SqlClient (
SentrySqlListener):Command.CommandTextbecomes thedb.queryspan description. - EF Core command spans (
EFCommandDiagnosticSourceHelper): the command text becomes thedb.queryspan description. - EF Core query-compile spans (
EFQueryCompilerDiagnosticSourceHelper): the description is the LINQ query expression, not SQL. Constants written in the LINQ query appear in it, so it needs handling of its own. - EF6 spans (
SentryQueryPerformanceListener): the command text becomes the span description. - EF6 breadcrumbs (
SentryCommandInterceptor→SentryQueryLogger): the command text is the breadcrumb message.
Proposal
Before attaching a statement, replace its string and numeric literals with ? and strip its comments. This is what sentry-go does.
Open questions
- Lexer. Do we write a small SQL lexer, or take a dependency? Adding a package dependency needs a maintainer decision.
- Dialects. Quoting differs between databases: SQL Server's
[ident]andN'...', PostgreSQL's$$...$$, MySQL's backticks, SQLite's quoting rules. sentry-go handles these per database. - Failure. If a statement can't be lexed, do we drop it or keep it? The safe choice is to drop it, but then the span loses its description.
- Rollout. Sanitizing changes the span descriptions every app sends today. Do we ship it as the default, or behind an option first?
- Query summary. Should this also produce
db.query.summaryand the operation name, the structural metadata the spec always collects? sentry-java plans that separately in Generate low-cardinality SQL summaries for database spans sentry-java#5981.
Prior art
- sentry-go sanitizes every statement in its
sqlintegration. A SQL lexer replaces literals with?and strips comments before the statement becomes the span description anddb.query.text. - sentry-java and sentry-python attach statements as the driver received them, like we do today.
- ref: remove the experimental DataCollectionOptions.DatabaseQueryData until .NET collects query data #5933's description compares the three SDKs' handling of database data in more detail.
Activity
linear-code commentedon Nov 18, 2026
NET-940
feat: DataCollection now sanitizes SQL statements on SqlClient, EF Co…