Skip to content

Commit 11dde45

Browse files
committed
address review comments
1 parent ff5aa12 commit 11dde45

File tree

14 files changed

+125
-47
lines changed

14 files changed

+125
-47
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CommonConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public CommonConfig(InstrumentationConfig config) {
8989
statementSanitizationEnabled =
9090
config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true);
9191
sqlCommenterEnabled =
92-
config.getBoolean("otel.instrumentation.common.db-sqlcommenter.enabled", false);
92+
config.getBoolean(
93+
"otel.instrumentation.common.experimental.db-sqlcommenter.enabled", false);
9394
emitExperimentalHttpClientTelemetry =
9495
config.getBoolean("otel.instrumentation.http.client.emit-experimental-telemetry", false);
9596
redactQueryParameters =

instrumentation/jdbc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
| `otel.instrumentation.jdbc.statement-sanitizer.enabled` | Boolean | `true` | Enables the DB statement sanitization. |
66
| `otel.instrumentation.jdbc.experimental.capture-query-parameters` | Boolean | `false` | Enable the capture of query parameters as span attributes. Enabling this option disables the statement sanitization. <p>WARNING: captured query parameters may contain sensitive information such as passwords, personally identifiable information or protected health info. |
77
| `otel.instrumentation.jdbc.experimental.transaction.enabled` | Boolean | `false` | Enables experimental instrumentation to create spans for COMMIT and ROLLBACK operations. |
8-
| `otel.instrumentation.jdbc.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |
8+
| `otel.instrumentation.jdbc.experimental.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |

instrumentation/jdbc/javaagent/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tasks {
7171
includeTestsMatching("SqlCommenterTest")
7272
}
7373
include("**/SqlCommenterTest.*")
74-
jvmArgs("-Dotel.instrumentation.jdbc.sqlcommenter.enabled=true")
74+
jvmArgs("-Dotel.instrumentation.jdbc.experimental.sqlcommenter.enabled=true")
7575
}
7676

7777
val testStableSemconv by registering(Test::class) {

instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class JdbcSingletons {
3232
private static final boolean SQLCOMMENTER_ENABLED =
3333
AgentInstrumentationConfig.get()
3434
.getBoolean(
35-
"otel.instrumentation.jdbc.sqlcommenter.enabled",
35+
"otel.instrumentation.jdbc.experimental.sqlcommenter.enabled",
3636
AgentCommonConfig.get().isSqlCommenterEnabled());
3737
public static final boolean CAPTURE_QUERY_PARAMETERS;
3838

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ public final class OpenTelemetryDriver implements Driver {
6262
private static final AtomicBoolean REGISTERED = new AtomicBoolean();
6363
private static final List<Driver> DRIVER_CANDIDATES = new CopyOnWriteArrayList<>();
6464

65+
// XXX value proeprty?
6566
private static final boolean sqlCommenterEnabled =
66-
ConfigPropertiesUtil.getBoolean("otel.instrumentation.common.db-sqlcommenter.enabled", false);
67+
ConfigPropertiesUtil.getBoolean(
68+
"otel.instrumentation.jdbc.experimental.sqlcommenter.enabled",
69+
ConfigPropertiesUtil.getBoolean(
70+
"otel.instrumentation.common.experimental.db-sqlcommenter.enabled", false));
6771

6872
static {
6973
try {

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/datasource/JdbcTelemetryBuilder.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.errorprone.annotations.CanIgnoreReturnValue;
99
import io.opentelemetry.api.OpenTelemetry;
1010
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
11+
import io.opentelemetry.instrumentation.jdbc.datasource.internal.Experimental;
1112
import io.opentelemetry.instrumentation.jdbc.internal.DbRequest;
1213
import io.opentelemetry.instrumentation.jdbc.internal.JdbcInstrumenterFactory;
1314
import io.opentelemetry.instrumentation.jdbc.internal.dbinfo.DbInfo;
@@ -24,6 +25,11 @@ public final class JdbcTelemetryBuilder {
2425
private boolean captureQueryParameters = false;
2526
private boolean sqlCommenterEnabled = false;
2627

28+
static {
29+
Experimental.internalSetEnableSqlCommenter(
30+
(builder, sqlCommenterEnabled) -> builder.sqlCommenterEnabled = sqlCommenterEnabled);
31+
}
32+
2733
JdbcTelemetryBuilder(OpenTelemetry openTelemetry) {
2834
this.openTelemetry = openTelemetry;
2935
}
@@ -69,19 +75,6 @@ public JdbcTelemetryBuilder setCaptureQueryParameters(boolean enabled) {
6975
return this;
7076
}
7177

72-
/**
73-
* Sets whether to augment sql query with comment containing the tracing information. See <a
74-
* href="https://google.github.io/sqlcommenter/">sqlcommenter</a> for more info.
75-
*
76-
* <p>WARNING: augmenting queries with tracing context will make query texts unique, which may
77-
* have adverse impact on database performance. Consult with database experts before enabling.
78-
*/
79-
@CanIgnoreReturnValue
80-
public JdbcTelemetryBuilder setEnableSqlCommenter(boolean sqlCommenterEnabled) {
81-
this.sqlCommenterEnabled = sqlCommenterEnabled;
82-
return this;
83-
}
84-
8578
/** Returns a new {@link JdbcTelemetry} with the settings of this {@link JdbcTelemetryBuilder}. */
8679
public JdbcTelemetry build() {
8780
Instrumenter<DataSource, DbInfo> dataSourceInstrumenter =
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.jdbc.datasource.internal;
7+
8+
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetryBuilder;
9+
import java.util.function.BiConsumer;
10+
import javax.annotation.Nullable;
11+
12+
/**
13+
* This class is internal and experimental. Its APIs are unstable and can change at any time. Its
14+
* APIs (or a version of them) may be promoted to the public stable API in the future, but no
15+
* guarantees are made.
16+
*/
17+
public final class Experimental {
18+
19+
@Nullable private static volatile BiConsumer<JdbcTelemetryBuilder, Boolean> setEnableSqlCommenter;
20+
21+
/**
22+
* Sets whether to augment sql query with comment containing the tracing information. See <a
23+
* href="https://google.github.io/sqlcommenter/">sqlcommenter</a> for more info.
24+
*
25+
* <p>WARNING: augmenting queries with tracing context will make query texts unique, which may
26+
* have adverse impact on database performance. Consult with database experts before enabling.
27+
*/
28+
public static void setEnableSqlCommenter(
29+
JdbcTelemetryBuilder builder, boolean sqlCommenterEnabled) {
30+
if (setEnableSqlCommenter != null) {
31+
setEnableSqlCommenter.accept(builder, sqlCommenterEnabled);
32+
}
33+
}
34+
35+
public static void internalSetEnableSqlCommenter(
36+
BiConsumer<JdbcTelemetryBuilder, Boolean> setEnableSqlCommenter) {
37+
Experimental.setEnableSqlCommenter = setEnableSqlCommenter;
38+
}
39+
40+
private Experimental() {}
41+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Settings for the R2DBC instrumentation
22

3-
| System property | Type | Default | Description |
4-
|----------------------------------------------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5-
| `otel.instrumentation.r2dbc.statement-sanitizer.enabled` | Boolean | `true` | Enables the DB statement sanitization. |
6-
| `otel.instrumentation.r2dbc.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |
3+
| System property | Type | Default | Description |
4+
|----------------------------------------------------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| `otel.instrumentation.r2dbc.statement-sanitizer.enabled` | Boolean | `true` | Enables the DB statement sanitization. |
6+
| `otel.instrumentation.r2dbc.experimental.sqlcommenter.enabled` | Boolean | `false` | Enables augmenting queries with a comment containing the tracing information. See [sqlcommenter](https://google.github.io/sqlcommenter/) for more info. WARNING: augmenting queries with tracing context will make query texts unique, which may have adverse impact on database performance. Consult with database experts before enabling. |

instrumentation/r2dbc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/r2dbc/v1_0/R2dbcSingletons.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class R2dbcSingletons {
2424
.setEnableSqlCommenter(
2525
AgentInstrumentationConfig.get()
2626
.getBoolean(
27-
"otel.instrumentation.r2dbc.sqlcommenter.enabled",
27+
"otel.instrumentation.r2dbc.experimental.sqlcommenter.enabled",
2828
AgentCommonConfig.get().isSqlCommenterEnabled()))
2929
.addAttributesExtractor(
3030
PeerServiceAttributesExtractor.create(

instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/R2dbcTelemetryBuilder.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1111
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
1212
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.DbExecution;
13+
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.Experimental;
1314
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.R2dbcInstrumenterBuilder;
1415
import java.util.function.Function;
1516

@@ -22,6 +23,11 @@ public final class R2dbcTelemetryBuilder {
2223
spanNameExtractorTransformer = Function.identity();
2324
private boolean sqlCommenterEnabled;
2425

26+
static {
27+
Experimental.internalSetEnableSqlCommenter(
28+
(builder, sqlCommenterEnabled) -> builder.sqlCommenterEnabled = sqlCommenterEnabled);
29+
}
30+
2531
R2dbcTelemetryBuilder(OpenTelemetry openTelemetry) {
2632
instrumenterBuilder = new R2dbcInstrumenterBuilder(openTelemetry);
2733
}
@@ -53,19 +59,6 @@ public R2dbcTelemetryBuilder setSpanNameExtractor(
5359
return this;
5460
}
5561

56-
/**
57-
* Sets whether to augment sql query with comment containing the tracing information. See <a
58-
* href="https://google.github.io/sqlcommenter/">sqlcommenter</a> for more info.
59-
*
60-
* <p>WARNING: augmenting queries with tracing context will make query texts unique, which may
61-
* have adverse impact on database performance. Consult with database experts before enabling.
62-
*/
63-
@CanIgnoreReturnValue
64-
public R2dbcTelemetryBuilder setEnableSqlCommenter(boolean sqlCommenterEnabled) {
65-
this.sqlCommenterEnabled = sqlCommenterEnabled;
66-
return this;
67-
}
68-
6962
/**
7063
* Returns a new {@link R2dbcTelemetry} with the settings of this {@link R2dbcTelemetryBuilder}.
7164
*/

0 commit comments

Comments
 (0)