Skip to content

Commit dc25a11

Browse files
authored
Fix JDBC muzzle: avoid defining helper classes as inner classes of instrumentations (#10106)
1 parent aff0473 commit dc25a11

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package datadog.trace.instrumentation.jdbc;
2+
3+
import java.util.concurrent.SynchronousQueue;
4+
import java.util.concurrent.TimeUnit;
5+
6+
public class HikariBlockedTrackingSynchronousQueue<T> extends SynchronousQueue<T> {
7+
public HikariBlockedTrackingSynchronousQueue() {
8+
// This assumes the initialization of the SynchronousQueue in ConcurrentBag doesn't change
9+
super(true);
10+
}
11+
12+
@Override
13+
public T poll(long timeout, TimeUnit unit) throws InterruptedException {
14+
HikariBlockedTracker.setBlocked();
15+
return super.poll(timeout, unit);
16+
}
17+
}

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/HikariConcurrentBagHandoffQueueInstrumentation.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import datadog.trace.agent.tooling.InstrumenterModule;
1010
import datadog.trace.api.InstrumenterConfig;
1111
import java.util.concurrent.SynchronousQueue;
12-
import java.util.concurrent.TimeUnit;
1312
import net.bytebuddy.asm.Advice;
1413
import net.bytebuddy.description.type.TypeDescription;
1514
import net.bytebuddy.matcher.ElementMatcher;
@@ -46,9 +45,7 @@ public ElementMatcher<TypeDescription> structureMatcher() {
4645
@Override
4746
public String[] helperClassNames() {
4847
return new String[] {
49-
packageName + ".HikariBlockedTracker",
50-
packageName
51-
+ ".HikariConcurrentBagHandoffQueueInstrumentation$BlockedTrackingSynchronousQueue",
48+
packageName + ".HikariBlockedTracker", packageName + ".HikariBlockedTrackingSynchronousQueue",
5249
};
5350
}
5451

@@ -64,20 +61,7 @@ public static class ConstructorAdvice {
6461
static void after(
6562
@Advice.FieldValue(value = "handoffQueue", readOnly = false)
6663
SynchronousQueue handoffQueue) {
67-
handoffQueue = new BlockedTrackingSynchronousQueue<>();
68-
}
69-
}
70-
71-
public static class BlockedTrackingSynchronousQueue<T> extends SynchronousQueue<T> {
72-
public BlockedTrackingSynchronousQueue() {
73-
// This assumes the initialization of the SynchronousQueue in ConcurrentBag doesn't change
74-
super(true);
75-
}
76-
77-
@Override
78-
public T poll(long timeout, TimeUnit unit) throws InterruptedException {
79-
HikariBlockedTracker.setBlocked();
80-
return super.poll(timeout, unit);
64+
handoffQueue = new HikariBlockedTrackingSynchronousQueue<>();
8165
}
8266
}
8367
}

0 commit comments

Comments
 (0)