Skip to content

Commit aef9a61

Browse files
committed
simplify
1 parent 5f09ad5 commit aef9a61

File tree

3 files changed

+29
-84
lines changed

3 files changed

+29
-84
lines changed

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/JdbcInstrumentationTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.jdbc;
77

8+
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry;
89
import io.opentelemetry.instrumentation.jdbc.testing.AbstractJdbcInstrumentationTest;
910
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
1011
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
@@ -18,8 +19,11 @@ class JdbcInstrumentationTest extends AbstractJdbcInstrumentationTest {
1819
@RegisterExtension
1920
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
2021

21-
private static final LibraryJdbcTestTelemetry telemetryHelper =
22-
new LibraryJdbcTestTelemetry(testing);
22+
private static final JdbcTelemetry telemetry =
23+
JdbcTelemetry.builder(testing.getOpenTelemetry())
24+
.setDataSourceInstrumenterEnabled(true)
25+
.setTransactionInstrumenterEnabled(true)
26+
.build();
2327

2428
@Override
2529
protected InstrumentationExtension testing() {
@@ -28,11 +32,18 @@ protected InstrumentationExtension testing() {
2832

2933
@Override
3034
protected Connection wrap(Connection connection) throws SQLException {
31-
return telemetryHelper.wrap(connection);
35+
// if (connection instanceof OpenTelemetryConnection) {
36+
// return connection;
37+
// }
38+
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
39+
return dataSource.getConnection();
3240
}
3341

3442
@Override
3543
protected DataSource wrap(DataSource dataSource) {
36-
return telemetryHelper.wrap(dataSource);
44+
// if (dataSource instanceof OpenTelemetryDataSource) {
45+
// return dataSource;
46+
// }
47+
return telemetry.wrap(dataSource);
3748
}
3849
}

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/LibraryJdbcTestTelemetry.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/PreparedStatementParametersTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55

66
package io.opentelemetry.instrumentation.jdbc;
77

8+
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry;
89
import io.opentelemetry.instrumentation.jdbc.testing.AbstractPreparedStatementParametersTest;
910
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
1011
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
1112
import java.sql.Connection;
1213
import java.sql.SQLException;
14+
import javax.sql.DataSource;
1315
import org.junit.jupiter.api.extension.RegisterExtension;
1416

1517
class PreparedStatementParametersTest extends AbstractPreparedStatementParametersTest {
1618

1719
@RegisterExtension
1820
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
1921

20-
private static final LibraryJdbcTestTelemetry telemetryHelper =
21-
new LibraryJdbcTestTelemetry(testing);
22+
private static final JdbcTelemetry telemetry =
23+
JdbcTelemetry.builder(testing.getOpenTelemetry())
24+
.setDataSourceInstrumenterEnabled(true)
25+
.setTransactionInstrumenterEnabled(true)
26+
.setCaptureQueryParameters(true)
27+
.setStatementSanitizationEnabled(false)
28+
.build();
2229

2330
@Override
2431
protected InstrumentationExtension testing() {
@@ -27,6 +34,10 @@ protected InstrumentationExtension testing() {
2734

2835
@Override
2936
protected Connection wrap(Connection connection) throws SQLException {
30-
return telemetryHelper.instrumentConnectionWithQueryParameters(connection);
37+
// if (connection instanceof OpenTelemetryConnection) {
38+
// return connection;
39+
// }
40+
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
41+
return dataSource.getConnection();
3142
}
3243
}

0 commit comments

Comments
 (0)