Skip to content

Commit 5554651

Browse files
committed
eval: blind regeneration of jedis-3.0 (reference)
Blind regen against dd-trace-java skill at b994882 (includes skill PR #11927). Toolkit run: jedis3_blind_regen.log, run_id 20260727-002431-fab584. Not intended to be merged as-is.
1 parent b994882 commit 5554651

8 files changed

Lines changed: 327 additions & 508 deletions

File tree

dd-java-agent/instrumentation/jedis/jedis-3.0/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ addTestSuiteForDir('latestDepTest', 'test')
2020
dependencies {
2121
compileOnly group: 'redis.clients', name: 'jedis', version: '3.3.0'
2222

23-
testImplementation group: 'com.github.codemonstur', name: 'embedded-redis', version: '1.4.3'
24-
testImplementation group: 'redis.clients', name: 'jedis', version: '3.3.0'
23+
testImplementation group: 'redis.clients', name: 'jedis', version: '3.0.0'
24+
testImplementation (group: 'com.github.codemonstur', name: 'embedded-redis', version: '1.4.3') {
25+
// Excluding redis client to avoid conflicts in instrumentation code.
26+
exclude group: 'redis.clients', module: 'jedis'
27+
}
2528
// ensures jedis-1.4 instrumentation does not load with jedis 3.0+ by failing
2629
// the tests in the event it does. The tests will end up with double spans
2730
testImplementation project(':dd-java-agent:instrumentation:jedis:jedis-1.4')

dd-java-agent/instrumentation/jedis/jedis-3.0/gradle.lockfile

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

dd-java-agent/instrumentation/jedis/jedis-3.0/src/main/java/datadog/trace/instrumentation/jedis30/JedisClientDecorator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
import redis.clients.jedis.Connection;
88

99
public class JedisClientDecorator extends DBTypeProcessingDatabaseClientDecorator<Connection> {
10-
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();
11-
1210
private static final String REDIS = "redis";
11+
public static final CharSequence COMPONENT_NAME = UTF8BytesString.create("redis-command");
1312
public static final CharSequence OPERATION_NAME =
1413
UTF8BytesString.create(SpanNaming.instance().namingSchema().cache().operation(REDIS));
1514
private static final String SERVICE_NAME =
1615
SpanNaming.instance().namingSchema().cache().service(REDIS);
17-
private static final CharSequence COMPONENT_NAME = UTF8BytesString.create("redis-command");
16+
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();
1817

1918
@Override
2019
protected String[] instrumentationNames() {

dd-java-agent/instrumentation/jedis/jedis-3.0/src/main/java/datadog/trace/instrumentation/jedis30/JedisInstrumentation.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package datadog.trace.instrumentation.jedis30;
22

3+
import static datadog.trace.agent.tooling.bytebuddy.matcher.ClassLoaderMatchers.hasClassNamed;
34
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
56
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
7+
import static datadog.trace.instrumentation.jedis30.JedisClientDecorator.COMPONENT_NAME;
68
import static datadog.trace.instrumentation.jedis30.JedisClientDecorator.DECORATE;
79
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
10+
import static net.bytebuddy.matcher.ElementMatchers.not;
811
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
912

1013
import com.google.auto.service.AutoService;
@@ -14,6 +17,7 @@
1417
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1518
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1619
import net.bytebuddy.asm.Advice;
20+
import net.bytebuddy.matcher.ElementMatcher;
1721
import redis.clients.jedis.Connection;
1822
import redis.clients.jedis.Protocol;
1923
import redis.clients.jedis.commands.ProtocolCommand;
@@ -27,44 +31,51 @@ public JedisInstrumentation() {
2731
}
2832

2933
@Override
30-
public String[] helperClassNames() {
31-
return new String[] {
32-
packageName + ".JedisClientDecorator",
33-
};
34+
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
35+
// Only match Jedis 3.x which has ProtocolCommand but not CommandObject (4.x+).
36+
return hasClassNamed("redis.clients.jedis.commands.ProtocolCommand")
37+
.and(not(hasClassNamed("redis.clients.jedis.CommandObject")));
3438
}
3539

3640
@Override
3741
public String instrumentedType() {
3842
return "redis.clients.jedis.Connection";
3943
}
4044

45+
@Override
46+
public String[] helperClassNames() {
47+
return new String[] {
48+
packageName + ".JedisClientDecorator",
49+
};
50+
}
51+
4152
@Override
4253
public void methodAdvice(MethodTransformer transformer) {
4354
transformer.applyAdvice(
4455
isMethod()
4556
.and(named("sendCommand"))
46-
.and(takesArgument(0, named("redis.clients.jedis.commands.ProtocolCommand"))),
57+
.and(
58+
takesArgument(
59+
0, named("redis.clients.jedis.commands.ProtocolCommand"))),
4760
JedisInstrumentation.class.getName() + "$JedisAdvice");
48-
// FIXME: This instrumentation only incorporates sending the command, not processing the result.
4961
}
5062

5163
public static class JedisAdvice {
5264

5365
@Advice.OnMethodEnter(suppress = Throwable.class)
5466
public static AgentScope onEnter(
55-
@Advice.Argument(0) final ProtocolCommand command, @Advice.This final Connection thiz) {
67+
@Advice.Argument(0) final ProtocolCommand command,
68+
@Advice.This final Connection thiz) {
5669
if (CallDepthThreadLocalMap.incrementCallDepth(Connection.class) > 0) {
5770
return null;
5871
}
59-
final AgentSpan span = startSpan("redis-command", JedisClientDecorator.OPERATION_NAME);
72+
final AgentSpan span =
73+
startSpan(COMPONENT_NAME.toString(), JedisClientDecorator.OPERATION_NAME);
6074
DECORATE.afterStart(span);
6175
DECORATE.onConnection(span, thiz);
62-
6376
if (command instanceof Protocol.Command) {
6477
DECORATE.onStatement(span, ((Protocol.Command) command).name());
6578
} else {
66-
// Protocol.Command is the only implementation in the Jedis lib as of 3.1 but this will save
67-
// us if that changes
6879
DECORATE.onStatement(span, new String(command.getRaw()));
6980
}
7081
return activateSpan(span);

0 commit comments

Comments
 (0)