Skip to content

Commit

Permalink
Extract sql operation even when the sanitizer is disabled (#11472)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed May 29, 2024
1 parent 3c3e905 commit 6c7afce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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);
}
}

0 comments on commit 6c7afce

Please sign in to comment.