Skip to content

Commit 9d2feb2

Browse files
committed
reduce diff
1 parent aef9a61 commit 9d2feb2

File tree

8 files changed

+91
-91
lines changed

8 files changed

+91
-91
lines changed

instrumentation/jdbc/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/scalaexecutors/SlickTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.javaagent.instrumentation.jdbc.slick
6+
package io.opentelemetry.javaagent.instrumentation.scalaexecutors
77

88
import io.opentelemetry.api.trace.{SpanKind, Tracer}
99
import io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.jdbc;
7+
8+
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry;
9+
import java.io.PrintWriter;
10+
import java.sql.Connection;
11+
import java.sql.SQLException;
12+
import java.sql.SQLFeatureNotSupportedException;
13+
import java.util.logging.Logger;
14+
import javax.sql.DataSource;
15+
16+
class ConnectionWrapper {
17+
18+
// hack since JdbcTelemetry only supports wrapping data sources
19+
static Connection wrap(Connection connection, JdbcTelemetry telemetry) throws SQLException {
20+
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
21+
return dataSource.getConnection();
22+
}
23+
24+
private ConnectionWrapper() {}
25+
26+
private static class SingleConnectionDataSource implements DataSource {
27+
private final Connection delegate;
28+
29+
SingleConnectionDataSource(Connection delegate) {
30+
this.delegate = delegate;
31+
}
32+
33+
@Override
34+
public Connection getConnection() {
35+
return delegate;
36+
}
37+
38+
@Override
39+
public Connection getConnection(String username, String password) {
40+
return getConnection();
41+
}
42+
43+
@Override
44+
public PrintWriter getLogWriter() {
45+
return null;
46+
}
47+
48+
@Override
49+
public void setLogWriter(PrintWriter out) {}
50+
51+
@Override
52+
public void setLoginTimeout(int seconds) {}
53+
54+
@Override
55+
public int getLoginTimeout() {
56+
return 0;
57+
}
58+
59+
@Override
60+
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
61+
throw new SQLFeatureNotSupportedException();
62+
}
63+
64+
@Override
65+
public <T> T unwrap(Class<T> iface) throws SQLException {
66+
if (iface.isInstance(delegate)) {
67+
return iface.cast(delegate);
68+
}
69+
throw new SQLFeatureNotSupportedException();
70+
}
71+
72+
@Override
73+
public boolean isWrapperFor(Class<?> iface) {
74+
return iface.isInstance(delegate);
75+
}
76+
}
77+
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ protected InstrumentationExtension testing() {
3232

3333
@Override
3434
protected Connection wrap(Connection connection) throws SQLException {
35-
// if (connection instanceof OpenTelemetryConnection) {
36-
// return connection;
37-
// }
38-
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
39-
return dataSource.getConnection();
35+
return ConnectionWrapper.wrap(connection, telemetry);
4036
}
4137

4238
@Override
4339
protected DataSource wrap(DataSource dataSource) {
44-
// if (dataSource instanceof OpenTelemetryDataSource) {
45-
// return dataSource;
46-
// }
4740
return telemetry.wrap(dataSource);
4841
}
4942
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
1212
import java.sql.Connection;
1313
import java.sql.SQLException;
14-
import javax.sql.DataSource;
1514
import org.junit.jupiter.api.extension.RegisterExtension;
1615

1716
class PreparedStatementParametersTest extends AbstractPreparedStatementParametersTest {
@@ -24,7 +23,6 @@ class PreparedStatementParametersTest extends AbstractPreparedStatementParameter
2423
.setDataSourceInstrumenterEnabled(true)
2524
.setTransactionInstrumenterEnabled(true)
2625
.setCaptureQueryParameters(true)
27-
.setStatementSanitizationEnabled(false)
2826
.build();
2927

3028
@Override
@@ -34,10 +32,6 @@ protected InstrumentationExtension testing() {
3432

3533
@Override
3634
protected Connection wrap(Connection connection) throws SQLException {
37-
// if (connection instanceof OpenTelemetryConnection) {
38-
// return connection;
39-
// }
40-
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
41-
return dataSource.getConnection();
35+
return ConnectionWrapper.wrap(connection, telemetry);
4236
}
4337
}

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

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

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@
1313
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
1414
import java.sql.Connection;
1515
import java.sql.SQLException;
16-
import javax.sql.DataSource;
1716
import org.junit.jupiter.api.extension.RegisterExtension;
1817

1918
class SqlCommenterTest extends AbstractSqlCommenterTest {
2019

2120
@RegisterExtension
2221
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
2322

23+
private static final JdbcTelemetry telemetry;
24+
25+
static {
26+
JdbcTelemetryBuilder builder = JdbcTelemetry.builder(testing.getOpenTelemetry());
27+
Experimental.setEnableSqlCommenter(builder, true);
28+
telemetry = builder.build();
29+
}
30+
2431
@Override
2532
protected InstrumentationExtension testing() {
2633
return testing;
2734
}
2835

2936
@Override
3037
protected Connection wrap(Connection connection) throws SQLException {
31-
JdbcTelemetryBuilder builder = JdbcTelemetry.builder(testing.getOpenTelemetry());
32-
Experimental.setEnableSqlCommenter(builder, true);
33-
JdbcTelemetry telemetry = builder.build();
34-
DataSource dataSource = telemetry.wrap(new SingleConnectionDataSource(connection));
35-
return dataSource.getConnection();
38+
return ConnectionWrapper.wrap(connection, telemetry);
3639
}
3740
}

instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/ProxyStatementFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public static <T> T proxy(
5959
// in the same package as the package private interface
6060
// by default we ignore jdk proxies, having the proxy in a different package ensures it gets
6161
// instrumented
62-
String expectedPackage = TestInterface.class.getPackage().getName();
63-
if (!proxy.getClass().getName().startsWith(expectedPackage)) {
62+
if (!proxy.getClass().getName().startsWith("io.opentelemetry.instrumentation.jdbc.testing")) {
6463
throw new IllegalStateException("proxy is in wrong package");
6564
}
6665

instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/TestClassLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
2323
if (clazz != null) {
2424
return clazz;
2525
}
26-
String instrumentationPackage = TestInterface.class.getPackage().getName();
27-
if (name.startsWith(instrumentationPackage)) {
26+
if (name.startsWith("io.opentelemetry.instrumentation.jdbc.testing")) {
2827
try {
2928
return findClass(name);
3029
} catch (ClassNotFoundException exception) {

0 commit comments

Comments
 (0)