Skip to content

Conversation

@trask
Copy link
Member

@trask trask commented Jan 12, 2026

@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Jan 12, 2026
@trask trask changed the title Prepared statement no sanitization Skip query sanitization for prepared statements Jan 12, 2026
@trask trask changed the title Skip query sanitization for prepared statements Skip query sanitization for prepared statements under stable semconv flag Jan 12, 2026
@trask trask force-pushed the prepared-statement-no-sanitization branch 2 times, most recently from 5c413eb to 52c940f Compare January 12, 2026 23:14
@trask trask force-pushed the prepared-statement-no-sanitization branch 4 times, most recently from 09a4532 to aca641d Compare January 13, 2026 02:26
@trask trask marked this pull request as ready for review January 13, 2026 04:44
@trask trask requested a review from a team as a code owner January 13, 2026 04:44
Long batchSize = getter.getBatchSize(request);
boolean isBatch = batchSize != null && batchSize > 1;
boolean parameterizedQuery = getter.isParameterizedQuery(request);
boolean shouldSanitize = statementSanitizationEnabled && !parameterizedQuery;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this right now or should this be done along with switching to the stable semconv? Maybe
statementSanitizationEnabled && (!SemconvStability.emitStableDatabaseSemconv() || !parameterizedQuery)? Or maybe we should introduce a flag for future defaults so we could implement the planned changes for 3.0 straight away but have them disabled for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's only used in the experimental semconv block, I moved it down inside that block make it more clear now

@trask trask force-pushed the prepared-statement-no-sanitization branch from 1885a18 to dbdf02d Compare January 13, 2026 15:04
@trask trask force-pushed the prepared-statement-no-sanitization branch from fa17edf to 1e97c5b Compare January 16, 2026 02:30
PreparedStatement queries use placeholders and are already parameterized,
so they don't need sanitization. This change adds an isPreparedStatement
flag to DbRequest and SqlClientAttributesGetter to skip sanitization for
prepared statements while still sanitizing regular Statement queries.
@trask trask force-pushed the prepared-statement-no-sanitization branch from 1e97c5b to b6bcd8b Compare January 16, 2026 03:19
* of db.query.text</a>.
*/
// TODO: make this required to implement
default boolean isParameterizedQuery(REQUEST request) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering whether it would be better to name this method based on what it is used for e.g. IsQuerySanitizationNeeded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense, I'll send a follow-up PR to consider

@trask trask merged commit e707b8d into open-telemetry:main Jan 17, 2026
87 checks passed
@trask trask deleted the prepared-statement-no-sanitization branch January 17, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants