Skip to content

Commit bdc098f

Browse files
traskotelbot[bot]
andauthored
Unify jdbc tests between javaagent and library instrumentation (#15137)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com>
1 parent ce90a0e commit bdc098f

File tree

23 files changed

+3121
-2954
lines changed

23 files changed

+3121
-2954
lines changed

instrumentation/jdbc/javaagent/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ dependencies {
2020
compileOnly("com.google.auto.value:auto-value-annotations")
2121
annotationProcessor("com.google.auto.value:auto-value")
2222

23-
// jdbc unit testing
2423
testLibrary("com.h2database:h2:1.3.169")
25-
// first version jdk 1.6 compatible
2624
testLibrary("org.apache.derby:derby:10.6.1.0")
2725
testLibrary("org.hsqldb:hsqldb:2.0.0")
2826

2927
testLibrary("org.apache.tomcat:tomcat-jdbc:7.0.19")
30-
// tomcat needs this to run
31-
testLibrary("org.apache.tomcat:tomcat-juli:7.0.19")
28+
testLibrary("org.apache.tomcat:tomcat-juli:7.0.19") // tomcat jdbc needs this
3229
testLibrary("com.zaxxer:HikariCP:2.4.0")
3330
testLibrary("com.mchange:c3p0:0.9.5")
3431
testLibrary("com.alibaba:druid:1.2.20")
@@ -42,7 +39,6 @@ dependencies {
4239
// these dependencies are for SlickTest
4340
testImplementation("org.scala-lang:scala-library:2.11.12")
4441
testImplementation("com.typesafe.slick:slick_2.11:3.2.0")
45-
testImplementation("com.h2database:h2:1.4.197")
4642
}
4743

4844
sourceSets {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void transform(TypeTransformer transformer) {
6060
transformer.applyAdviceToMethod(
6161
namedOneOf(
6262
"setBoolean",
63+
"setByte",
6364
"setShort",
6465
"setInt",
6566
"setLong",
@@ -155,7 +156,7 @@ public static void onExit(
155156
String str = null;
156157

157158
if (value instanceof Boolean
158-
// Short, Int, Long, Float, Double, BigDecimal
159+
// Byte, Short, Int, Long, Float, Double, BigDecimal
159160
|| value instanceof Number
160161
|| value instanceof String
161162
|| value instanceof Date
@@ -190,7 +191,7 @@ public static void onExit(
190191
String str = null;
191192

192193
if (value instanceof Boolean
193-
// Short, Int, Long, Float, Double, BigDecimal
194+
// Byte, Short, Int, Long, Float, Double, BigDecimal
194195
|| value instanceof Number
195196
|| value instanceof String
196197
|| value instanceof Date
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,28 @@
2929
import org.junit.jupiter.api.extension.RegisterExtension;
3030

3131
@SuppressWarnings("deprecation") // using deprecated semconv
32-
class DruicDataSourceTest {
32+
class DruidDataSourceTest {
3333

3434
@RegisterExtension
3535
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
3636

3737
private DataSource dataSource;
3838

3939
@BeforeEach
40-
void setUp() {
40+
void setUp() throws SQLException {
4141
DruidDataSource druidDataSource = new DruidDataSource();
4242
druidDataSource.setUrl("jdbc:h2:mem:test");
4343
druidDataSource.setDriverClassName("org.h2.Driver");
4444
druidDataSource.setUsername("sa");
4545
druidDataSource.setPassword("");
4646
druidDataSource.setMaxActive(1);
4747
this.dataSource = druidDataSource;
48+
49+
// Initialize the connection pool to trigger H2's internal schema setup
50+
// This prevents internal H2 spans from appearing in the test assertions
51+
testing.runWithSpan("parent", () -> dataSource.getConnection().close());
52+
testing.waitForTraces(1);
53+
testing.clearData();
4854
}
4955

5056
@AfterEach

0 commit comments

Comments
 (0)