Skip to content

Commit 2c9de9d

Browse files
authored
Disable data source instrumentation in jdbc library instrumentation (#15074)
1 parent 1e2cf79 commit 2c9de9d

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public final class JdbcTelemetryBuilder {
1919

2020
private final OpenTelemetry openTelemetry;
21-
private boolean dataSourceInstrumenterEnabled = true;
21+
private boolean dataSourceInstrumenterEnabled = false;
2222
private boolean statementInstrumenterEnabled = true;
2323
private boolean statementSanitizationEnabled = true;
2424
private boolean transactionInstrumenterEnabled = false;
@@ -34,7 +34,7 @@ public final class JdbcTelemetryBuilder {
3434
this.openTelemetry = openTelemetry;
3535
}
3636

37-
/** Configures whether spans are created for JDBC Connections. Enabled by default. */
37+
/** Configures whether spans are created for JDBC Connections. Disabled by default. */
3838
@CanIgnoreReturnValue
3939
public JdbcTelemetryBuilder setDataSourceInstrumenterEnabled(boolean enabled) {
4040
this.dataSourceInstrumenterEnabled = enabled;

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/datasource/JdbcTelemetryTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void buildWithDefaults() throws SQLException {
6060
trace ->
6161
trace.hasSpansSatisfyingExactly(
6262
span -> span.hasName("parent"),
63-
span -> span.hasName("TestDataSource.getConnection"),
6463
span ->
6564
span.hasName("SELECT dbname")
6665
.hasAttribute(equalTo(maybeStable(DB_STATEMENT), "SELECT ?;"))));
@@ -99,7 +98,6 @@ void error() throws SQLException {
9998
trace ->
10099
trace.hasSpansSatisfyingExactly(
101100
span -> span.hasName("parent"),
102-
span -> span.hasName("TestDataSource.getConnection"),
103101
span ->
104102
span.hasName("SELECT dbname")
105103
.hasAttributesSatisfyingExactly(
@@ -164,6 +162,7 @@ void buildWithDataSourceInstrumenterDisabled() throws SQLException {
164162
void buildWithStatementInstrumenterDisabled() throws SQLException {
165163
JdbcTelemetry telemetry =
166164
JdbcTelemetry.builder(testing.getOpenTelemetry())
165+
.setDataSourceInstrumenterEnabled(true)
167166
.setStatementInstrumenterEnabled(false)
168167
.build();
169168

@@ -180,10 +179,10 @@ void buildWithStatementInstrumenterDisabled() throws SQLException {
180179
}
181180

182181
@Test
183-
void buildWithTransactionInstrumenterDisabled() throws SQLException {
182+
void buildWithTransactionInstrumenterEnabled() throws SQLException {
184183
JdbcTelemetry telemetry =
185184
JdbcTelemetry.builder(testing.getOpenTelemetry())
186-
.setTransactionInstrumenterEnabled(false)
185+
.setTransactionInstrumenterEnabled(true)
187186
.build();
188187

189188
DataSource dataSource = telemetry.wrap(new TestDataSource());
@@ -200,7 +199,8 @@ void buildWithTransactionInstrumenterDisabled() throws SQLException {
200199
trace ->
201200
trace.hasSpansSatisfyingExactly(
202201
span -> span.hasName("parent"),
203-
span -> span.hasName("TestDataSource.getConnection")));
202+
span -> span.hasName("COMMIT"),
203+
span -> span.hasName("ROLLBACK")));
204204
}
205205

206206
@Test
@@ -219,7 +219,6 @@ void buildWithSanitizationDisabled() throws SQLException {
219219
trace ->
220220
trace.hasSpansSatisfyingExactly(
221221
span -> span.hasName("parent"),
222-
span -> span.hasName("TestDataSource.getConnection"),
223222
span ->
224223
span.hasName("SELECT dbname")
225224
.hasAttribute(equalTo(maybeStable(DB_STATEMENT), "SELECT 1;"))));
@@ -258,7 +257,6 @@ void batchStatement() throws SQLException {
258257
trace ->
259258
trace.hasSpansSatisfyingExactly(
260259
span -> span.hasName("parent"),
261-
span -> span.hasName("TestDataSource.getConnection"),
262260
span ->
263261
span.hasName(
264262
SemconvStability.emitStableDatabaseSemconv()

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/datasource/OpenTelemetryDataSourceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class OpenTelemetryDataSourceTest {
4141
@ParameterizedTest
4242
@MethodSource("getConnectionMethodsArguments")
4343
void shouldEmitGetConnectionSpans(GetConnectionFunction getConnection) throws SQLException {
44-
JdbcTelemetry telemetry = JdbcTelemetry.create(testing.getOpenTelemetry());
44+
JdbcTelemetry telemetry =
45+
JdbcTelemetry.builder(testing.getOpenTelemetry())
46+
.setDataSourceInstrumenterEnabled(true)
47+
.build();
4548
DataSource dataSource = telemetry.wrap(new TestDataSource());
4649

4750
Connection connection = testing.runWithSpan("parent", () -> getConnection.call(dataSource));

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/jdbc/DataSourcePostProcessor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
7474
configPropertiesProvider
7575
.getObject()
7676
.getBoolean(
77-
"otel.instrumentation.jdbc.experimental.transaction.enabled", false));
77+
"otel.instrumentation.jdbc.experimental.transaction.enabled", false))
78+
.setDataSourceInstrumenterEnabled(
79+
configPropertiesProvider
80+
.getObject()
81+
.getBoolean(
82+
"otel.instrumentation.jdbc.experimental.datasource.enabled", false));
7883
Experimental.setEnableSqlCommenter(
7984
builder,
8085
configPropertiesProvider

instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@
369369
"description": "Enables experimental instrumentation to create spans for COMMIT and ROLLBACK operations.",
370370
"defaultValue": false
371371
},
372+
{
373+
"name": "otel.instrumentation.jdbc.experimental.datasource.enabled",
374+
"type": "java.lang.Boolean",
375+
"description": "Enables experimental instrumentation to create spans for <code>DataSource.getConnection</code> calls.",
376+
"defaultValue": false
377+
},
372378
{
373379
"name": "otel.instrumentation.jdbc.experimental.sqlcommenter.enabled",
374380
"type": "java.lang.Boolean",

smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ void databaseQuery() {
288288
traceAssert ->
289289
traceAssert.hasSpansSatisfyingExactly(
290290
span -> span.hasName("server"),
291-
span -> span.satisfies(s -> assertThat(s.getName()).endsWith(".getConnection")),
292291
span ->
293292
span.hasKind(SpanKind.CLIENT)
294293
.hasAttribute(

0 commit comments

Comments
 (0)