minimise impact on instrumentation point bytecode size
MODIFY
dd-java-agent/instrumentation/lettuce-4.0/src/main/java/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsInstrumentation.java
dd-java-agent/instrumentation/lettuce-4.0/src/main/java/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsInstrumentation.java
@@ -29,7 +29,8 @@ public class LettuceAsyncCommandsInstrumentation extends Instrumenter.Default {
return new String[] {
packageName + ".LettuceClientDecorator",
packageName + ".LettuceAsyncBiFunction",
- packageName + ".LettuceInstrumentationUtil"
+ packageName + ".LettuceInstrumentationUtil",
+ packageName + ".InstrumentationPoints"
};
}

MODIFY
dd-java-agent/instrumentation/lettuce-4.0/src/main/java/datadog/trace/instrumentation/lettuce/LettuceClientInstrumentation.java
dd-java-agent/instrumentation/lettuce-4.0/src/main/java/datadog/trace/instrumentation/lettuce/LettuceClientInstrumentation.java
@@ -26,7 +26,9 @@ public final class LettuceClientInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
- packageName + ".LettuceClientDecorator", packageName + ".LettuceInstrumentationUtil"
+ packageName + ".LettuceClientDecorator",
+ packageName + ".LettuceInstrumentationUtil",
+ packageName + ".InstrumentationPoints"
};
}

ADD
dd-java-agent/instrumentation/lettuce-4.0/src/main/java8/datadog/trace/instrumentation/lettuce/InstrumentationPoints.java
+package datadog.trace.instrumentation.lettuce;
+
+import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
+import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
+import static datadog.trace.instrumentation.lettuce.LettuceInstrumentationUtil.doFinishSpanEarly;
+
+import com.lambdaworks.redis.RedisURI;
+import com.lambdaworks.redis.protocol.AsyncCommand;
+import com.lambdaworks.redis.protocol.RedisCommand;
+import datadog.trace.bootstrap.instrumentation.api.AgentScope;
+import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
+import net.bytebuddy.asm.Advice;
+
+@SuppressWarnings("rawtypes")
+public class InstrumentationPoints {
+
+ public static AgentScope onEnter(RedisCommand command) {
+ AgentSpan span = startSpan("redis.query");
+ DECORATE.afterStart(span);
+ DECORATE.onCommand(span, command);
+ return activateSpan(span, doFinishSpanEarly(command));
+ }
+
+ public static void onReturn(RedisCommand command,
+ AgentScope scope,
+ Throwable throwable,
+ AsyncCommand<?, ?, ?> asyncCommand) {
+ AgentSpan span = scope.span();
+ if (throwable != null) {
+ DECORATE.onError(span, throwable);
+ DECORATE.beforeFinish(span);
+ span.finish();
+ } else if (!doFinishSpanEarly(command)) {
+ asyncCommand.handleAsync(new LettuceAsyncBiFunction<>(span));
+ }
+ scope.close();
+ }
+
+ public static AgentScope onEnter(RedisURI redisURI) {
+ AgentSpan span = startSpan("redis.query");
+ DECORATE.afterStart(span);
+ DECORATE.onConnection(span, redisURI);
+ return activateSpan(span, false);
+ }
+
+ public static void onReturn(AgentScope scope, Throwable throwable) {
+ AgentSpan span = scope.span();
+ if (throwable != null) {
+ DECORATE.onError(span, throwable);
+ DECORATE.beforeFinish(span);
+ }
+ span.finish();
+ scope.close();
+ }
+}

MODIFY
dd-java-agent/instrumentation/lettuce-4.0/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsAdvice.java
dd-java-agent/instrumentation/lettuce-4.0/src/main/java8/datadog/trace/instrumentation/lettuce/LettuceAsyncCommandsAdvice.java
package datadog.trace.instrumentation.lettuce;
-import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
-import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
-import static datadog.trace.instrumentation.lettuce.LettuceInstrumentationUtil.doFinishSpanEarly;
import com.lambdaworks.redis.protocol.AsyncCommand;
import com.lambdaworks.redis.protocol.RedisCommand;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
-import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import net.bytebuddy.asm.Advice;
public class LettuceAsyncCommandsAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope onEnter(@Advice.Argument(0) final RedisCommand command) {
- final AgentSpan span = startSpan("redis.query");
- DECORATE.afterStart(span);
- DECORATE.onCommand(span, command);
- return activateSpan(span, doFinishSpanEarly(command));
+ return InstrumentationPoints.onEnter(command);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Argument(0) final RedisCommand command,
- @Advice.Enter final AgentScope scope,
- @Advice.Thrown final Throwable throwable,
- @Advice.Return final AsyncCommand<?, ?, ?> asyncCommand) {
- final AgentSpan span = scope.span();
- if (throwable != null) {
- DECORATE.onError(span, throwable);
- DECORATE.beforeFinish(span);
- span.finish();
- scope.close();
- return;
+ @Advice.Argument(0) RedisCommand command,
+ @Advice.Enter AgentScope scope,
+ @Advice.Thrown Throwable throwable,
+ @Advice.Return AsyncCommand<?, ?, ?> asyncCommand) {
+ InstrumentationPoints.onReturn(command, scope, throwable, asyncCommand);
}
- // close spans on error or normal completion
- if (!doFinishSpanEarly(command)) {
- asyncCommand.handleAsync(new LettuceAsyncBiFunction<>(span));
- }
- scope.close();
- }
}

MODIFY
dd-java-agent/instrumentation/lettuce-4.0/src/main/java8/datadog/trace/instrumentation/lettuce/RedisConnectionAdvice.java
dd-java-agent/instrumentation/lettuce-4.0/src/main/java8/datadog/trace/instrumentation/lettuce/RedisConnectionAdvice.java
package datadog.trace.instrumentation.lettuce;
-import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
-import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
-import static datadog.trace.instrumentation.lettuce.LettuceClientDecorator.DECORATE;
-
import com.lambdaworks.redis.RedisURI;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
-import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import net.bytebuddy.asm.Advice;
public class RedisConnectionAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope onEnter(@Advice.Argument(1) RedisURI redisURI) {
- AgentSpan span = startSpan("redis.query");
- DECORATE.afterStart(span);
- DECORATE.onConnection(span, redisURI);
- return activateSpan(span, false);
+ return InstrumentationPoints.onEnter(redisURI);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onReturn(@Advice.Enter AgentScope scope, @Advice.Thrown Throwable throwable) {
- AgentSpan span = scope.span();
- try {
- if (throwable != null) {
- DECORATE.onError(span, throwable);
- DECORATE.beforeFinish(span);
- }
- } finally {
- span.finish();
- scope.close();
- }
+ InstrumentationPoints.onReturn(scope, throwable);
}
}

minimise impact on instrumentation point bytecode size