diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java index b33d2e7a8673..eacf266333bc 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java @@ -46,26 +46,32 @@ public static SqlClientAttributesExtractorBuilder dbTableAttribute; - private final SqlStatementSanitizer sanitizer; + private final boolean statementSanitizationEnabled; SqlClientAttributesExtractor( SqlClientAttributesGetter getter, AttributeKey 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()); diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java index b8e0838020f9..3e172e3d288e 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorBuilder.java @@ -58,6 +58,6 @@ public SqlClientAttributesExtractorBuilder setStatementSaniti */ public AttributesExtractor build() { return new SqlClientAttributesExtractor<>( - getter, dbTableAttribute, SqlStatementSanitizer.create(statementSanitizationEnabled)); + getter, dbTableAttribute, statementSanitizationEnabled); } }