From 6c7afce1371520f8f528be30f4c0ca0c7f6da031 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 29 May 2024 09:10:45 +0300 Subject: [PATCH] Extract sql operation even when the sanitizer is disabled (#11472) --- .../semconv/db/SqlClientAttributesExtractor.java | 16 +++++++++++----- .../db/SqlClientAttributesExtractorBuilder.java | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) 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); } }