Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dd-java-agent/instrumentation/jedis/jedis-3.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ addTestSuiteForDir('latestDepTest', 'test')
dependencies {
compileOnly group: 'redis.clients', name: 'jedis', version: '3.3.0'

testImplementation group: 'com.github.codemonstur', name: 'embedded-redis', version: '1.4.3'
testImplementation group: 'redis.clients', name: 'jedis', version: '3.3.0'
testImplementation group: 'redis.clients', name: 'jedis', version: '3.0.0'
testImplementation (group: 'com.github.codemonstur', name: 'embedded-redis', version: '1.4.3') {
// Excluding redis client to avoid conflicts in instrumentation code.
exclude group: 'redis.clients', module: 'jedis'
}
// ensures jedis-1.4 instrumentation does not load with jedis 3.0+ by failing
// the tests in the event it does. The tests will end up with double spans
testImplementation project(':dd-java-agent:instrumentation:jedis:jedis-1.4')
Expand Down
133 changes: 0 additions & 133 deletions dd-java-agent/instrumentation/jedis/jedis-3.0/gradle.lockfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import redis.clients.jedis.Connection;

public class JedisClientDecorator extends DBTypeProcessingDatabaseClientDecorator<Connection> {
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();

private static final String REDIS = "redis";
public static final CharSequence COMPONENT_NAME = UTF8BytesString.create("redis-command");
public static final CharSequence OPERATION_NAME =
UTF8BytesString.create(SpanNaming.instance().namingSchema().cache().operation(REDIS));
private static final String SERVICE_NAME =
SpanNaming.instance().namingSchema().cache().service(REDIS);
private static final CharSequence COMPONENT_NAME = UTF8BytesString.create("redis-command");
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();

@Override
protected String[] instrumentationNames() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package datadog.trace.instrumentation.jedis30;

import static datadog.trace.agent.tooling.bytebuddy.matcher.ClassLoaderMatchers.hasClassNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jedis30.JedisClientDecorator.COMPONENT_NAME;
import static datadog.trace.instrumentation.jedis30.JedisClientDecorator.DECORATE;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
Expand All @@ -14,6 +17,7 @@
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatcher;
import redis.clients.jedis.Connection;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.commands.ProtocolCommand;
Expand All @@ -27,25 +31,31 @@ public JedisInstrumentation() {
}

@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".JedisClientDecorator",
};
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// Only match Jedis 3.x which has ProtocolCommand but not CommandObject (4.x+).
return hasClassNamed("redis.clients.jedis.commands.ProtocolCommand")
.and(not(hasClassNamed("redis.clients.jedis.CommandObject")));
}

@Override
public String instrumentedType() {
return "redis.clients.jedis.Connection";
}

@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".JedisClientDecorator",
};
}

@Override
public void methodAdvice(MethodTransformer transformer) {
transformer.applyAdvice(
isMethod()
.and(named("sendCommand"))
.and(takesArgument(0, named("redis.clients.jedis.commands.ProtocolCommand"))),
JedisInstrumentation.class.getName() + "$JedisAdvice");
// FIXME: This instrumentation only incorporates sending the command, not processing the result.
}

public static class JedisAdvice {
Expand All @@ -56,15 +66,13 @@ public static AgentScope onEnter(
if (CallDepthThreadLocalMap.incrementCallDepth(Connection.class) > 0) {
return null;
}
final AgentSpan span = startSpan("redis-command", JedisClientDecorator.OPERATION_NAME);
final AgentSpan span =
startSpan(COMPONENT_NAME.toString(), JedisClientDecorator.OPERATION_NAME);
DECORATE.afterStart(span);
DECORATE.onConnection(span, thiz);

if (command instanceof Protocol.Command) {
DECORATE.onStatement(span, ((Protocol.Command) command).name());
} else {
// Protocol.Command is the only implementation in the Jedis lib as of 3.1 but this will save
// us if that changes
DECORATE.onStatement(span, new String(command.getRaw()));
}
return activateSpan(span);
Expand Down
Loading
Loading