Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract sql operation even when the sanitizer is disabled #11472

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,32 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
}

private static final String SQL_CALL = "CALL";
// sanitizer is also used to extract operation and table name, so we have it always enable here
private static final SqlStatementSanitizer sanitizer = SqlStatementSanitizer.create(true);

private final AttributeKey<String> dbTableAttribute;
private final SqlStatementSanitizer sanitizer;
private final boolean statementSanitizationEnabled;

SqlClientAttributesExtractor(
SqlClientAttributesGetter<REQUEST> getter,
AttributeKey<String> dbTableAttribute,
SqlStatementSanitizer sanitizer) {
boolean statementSanitizationEnabled) {
super(getter);
this.dbTableAttribute = dbTableAttribute;
this.sanitizer = sanitizer;
this.statementSanitizationEnabled = statementSanitizationEnabled;
}

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
String rawStatement = getter.getRawStatement(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawStatement);
String operation = sanitizedStatement.getOperation();
internalSet(attributes, DB_STATEMENT, sanitizedStatement.getFullStatement());
internalSet(
attributes,
DB_STATEMENT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawStatement);
internalSet(attributes, DB_OPERATION, operation);
if (!SQL_CALL.equals(operation)) {
internalSet(attributes, dbTableAttribute, sanitizedStatement.getMainIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setStatementSaniti
*/
public AttributesExtractor<REQUEST, RESPONSE> build() {
return new SqlClientAttributesExtractor<>(
getter, dbTableAttribute, SqlStatementSanitizer.create(statementSanitizationEnabled));
getter, dbTableAttribute, statementSanitizationEnabled);
}
}
Loading