Update lettuce-5 to new agent api
MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/ConnectionFutureAdvice.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/ConnectionFutureAdvice.java
package datadog.trace.instrumentation.lettuce;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.lettuce.core.ConnectionFuture;
import io.lettuce.core.RedisURI;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import net.bytebuddy.asm.Advice;
public class ConnectionFutureAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(@Advice.Argument(1) final RedisURI redisURI) {
- final Scope scope = GlobalTracer.get().buildSpan("redis.query").startActive(false);
- final Span span = scope.span();
+ public static AgentScope onEnter(@Advice.Argument(1) final RedisURI redisURI) {
+ final AgentSpan span = startSpan("redis.query");
DECORATE.afterStart(span);
DECORATE.onConnection(span, redisURI);
- return scope;
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope,
+ @Advice.Enter final AgentScope scope,
@Advice.Thrown final Throwable throwable,
@Advice.Return final ConnectionFuture<?> connectionFuture) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
if (throwable != null) {
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncBiFunction.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncBiFunction.java
@@ -2,7 +2,7 @@ package datadog.trace.instrumentation.lettuce;
import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.concurrent.CancellationException;
import java.util.function.BiFunction;
@@ -18,9 +18,9 @@ import java.util.function.BiFunction;
public class LettuceAsyncBiFunction<T extends Object, U extends Throwable, R extends Object>
implements BiFunction<T, Throwable, R> {
- private final Span span;
+ private final AgentSpan span;
- public LettuceAsyncBiFunction(final Span span) {
+ public LettuceAsyncBiFunction(final AgentSpan span) {
this.span = span;
}

MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsAdvice.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsAdvice.java
package datadog.trace.instrumentation.lettuce;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
import static datadog.trace.instrumentation.lettuce.LettuceInstrumentationUtil.doFinishSpanEarly;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.lettuce.core.protocol.AsyncCommand;
import io.lettuce.core.protocol.RedisCommand;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import net.bytebuddy.asm.Advice;
public class LettuceAsyncCommandsAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(@Advice.Argument(0) final RedisCommand command) {
+ public static AgentScope onEnter(@Advice.Argument(0) final RedisCommand command) {
- final Scope scope =
- GlobalTracer.get().buildSpan("redis.query").startActive(doFinishSpanEarly(command));
-
- final Span span = scope.span();
+ final AgentSpan span = startSpan("redis.query");
DECORATE.afterStart(span);
DECORATE.onCommand(span, command);
- return scope;
+
+ return activateSpan(span, doFinishSpanEarly(command));
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
@Advice.Argument(0) final RedisCommand command,
- @Advice.Enter final Scope scope,
+ @Advice.Enter final AgentScope scope,
@Advice.Thrown final Throwable throwable,
@Advice.Return final AsyncCommand<?, ?, ?> asyncCommand) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
if (throwable != null) {
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceClientDecorator.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceClientDecorator.java
@@ -3,9 +3,9 @@ package datadog.trace.instrumentation.lettuce;
import datadog.trace.agent.decorator.DatabaseClientDecorator;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.lettuce.core.RedisURI;
import io.lettuce.core.protocol.RedisCommand;
-import io.opentracing.Span;
import io.opentracing.tag.Tags;
public class LettuceClientDecorator extends DatabaseClientDecorator<RedisURI> {
@@ -47,19 +47,25 @@ public class LettuceClientDecorator extends DatabaseClientDecorator<RedisURI> {
}
@Override
- public Span onConnection(final Span span, final RedisURI connection) {
+ public AgentSpan onConnection(final AgentSpan span, final RedisURI connection) {
if (connection != null) {
- Tags.PEER_HOSTNAME.set(span, connection.getHost());
- Tags.PEER_PORT.set(span, connection.getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), connection.getHost());
+ span.setTag(Tags.PEER_PORT.getKey(), connection.getPort());
span.setTag("db.redis.dbIndex", connection.getDatabase());
- span.setTag(DDTags.RESOURCE_NAME, "CONNECT:" + connection.getHost()
- + ":" + connection.getPort() + "/" + connection.getDatabase());
+ span.setTag(
+ DDTags.RESOURCE_NAME,
+ "CONNECT:"
+ + connection.getHost()
+ + ":"
+ + connection.getPort()
+ + "/"
+ + connection.getDatabase());
}
return super.onConnection(span, connection);
}
- public Span onCommand(final Span span, final RedisCommand command) {
+ public AgentSpan onCommand(final AgentSpan span, final RedisCommand command) {
final String commandName = LettuceInstrumentationUtil.getCommandName(command);
span.setTag(
DDTags.RESOURCE_NAME, LettuceInstrumentationUtil.getCommandResourceName(commandName));

MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/rx/LettuceFluxTerminationRunnable.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/rx/LettuceFluxTerminationRunnable.java
package datadog.trace.instrumentation.lettuce.rx;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.lettuce.core.protocol.RedisCommand;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import java.util.function.Consumer;
import org.reactivestreams.Subscription;
import org.slf4j.LoggerFactory;
@@ -14,7 +14,7 @@ import reactor.core.publisher.SignalType;
public class LettuceFluxTerminationRunnable implements Consumer<Signal>, Runnable {
- private Span span = null;
+ private AgentSpan span = null;
private int numResults = 0;
private FluxOnSubscribeConsumer onSubscribeConsumer = null;
@@ -83,7 +83,7 @@ public class LettuceFluxTerminationRunnable implements Consumer<Signal>, Runnabl
@Override
public void accept(final Subscription subscription) {
- final Span span = GlobalTracer.get().buildSpan("redis.query").start();
+ final AgentSpan span = startSpan("redis.query");
owner.span = span;
DECORATE.afterStart(span);
DECORATE.onCommand(span, command);

MODIFY
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/rx/LettuceMonoDualConsumer.java
dd-java-agent/instrumentation/lettuce-5/src/main/java8/datadog/trace/instrumentation/lettuce/rx/LettuceMonoDualConsumer.java
package datadog.trace.instrumentation.lettuce.rx;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.lettuce.core.protocol.RedisCommand;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.slf4j.LoggerFactory;
@@ -14,7 +13,7 @@ import reactor.core.publisher.Mono;
public class LettuceMonoDualConsumer<R, T, U extends Throwable>
implements Consumer<R>, BiConsumer<T, Throwable> {
- private Span span = null;
+ private AgentSpan span = null;
private final RedisCommand command;
private final boolean finishSpanOnClose;
@@ -25,11 +24,12 @@ public class LettuceMonoDualConsumer<R, T, U extends Throwable>
@Override
public void accept(final R r) {
- final Scope scope = GlobalTracer.get().buildSpan("redis.query").startActive(finishSpanOnClose);
- span = scope.span();
+ span = startSpan("redis.query");
DECORATE.afterStart(span);
DECORATE.onCommand(span, command);
- scope.close();
+ if (finishSpanOnClose) {
+ span.finish();
+ }
}
@Override

Update lettuce-5 to new agent api