Refactored jedis-*
MODIFY
instrumentation/jedis-1.4/src/main/java/io/opentelemetry/auto/instrumentation/jedis/JedisClientDecorator.java
instrumentation/jedis-1.4/src/main/java/io/opentelemetry/auto/instrumentation/jedis/JedisClientDecorator.java
package io.opentelemetry.auto.instrumentation.jedis;
+import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.api.SpanTypes;
import io.opentelemetry.auto.decorator.DatabaseClientDecorator;
+import io.opentelemetry.trace.Tracer;
import redis.clients.jedis.Protocol;
public class JedisClientDecorator extends DatabaseClientDecorator<Protocol.Command> {
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();
+ public static final Tracer TRACER =
+ OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto.jedis-1.4");
+
@Override
protected String[] instrumentationNames() {
return new String[] {"jedis", "redis"};

MODIFY
instrumentation/jedis-1.4/src/main/java/io/opentelemetry/auto/instrumentation/jedis/JedisInstrumentation.java
instrumentation/jedis-1.4/src/main/java/io/opentelemetry/auto/instrumentation/jedis/JedisInstrumentation.java
package io.opentelemetry.auto.instrumentation.jedis;
-import static io.opentelemetry.auto.instrumentation.api.AgentTracer.activateSpan;
-import static io.opentelemetry.auto.instrumentation.api.AgentTracer.startSpan;
import static io.opentelemetry.auto.instrumentation.jedis.JedisClientDecorator.DECORATE;
+import static io.opentelemetry.auto.instrumentation.jedis.JedisClientDecorator.TRACER;
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
@@ -12,9 +11,9 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
-import io.opentelemetry.auto.instrumentation.api.AgentScope;
-import io.opentelemetry.auto.instrumentation.api.AgentSpan;
+import io.opentelemetry.auto.instrumentation.api.SpanScopePair;
import io.opentelemetry.auto.tooling.Instrumenter;
+import io.opentelemetry.trace.Span;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -63,19 +62,21 @@ public final class JedisInstrumentation extends Instrumenter.Default {
public static class JedisAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static AgentScope onEnter(@Advice.Argument(1) final Command command) {
- final AgentSpan span = startSpan("redis.query");
+ public static SpanScopePair onEnter(@Advice.Argument(1) final Command command) {
+ final Span span = TRACER.spanBuilder("redis.query").startSpan();
DECORATE.afterStart(span);
DECORATE.onStatement(span, command.name());
- return activateSpan(span, true);
+ return new SpanScopePair(span, TRACER.withSpan(span));
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
- DECORATE.onError(scope.span(), throwable);
- DECORATE.beforeFinish(scope.span());
- scope.close();
+ @Advice.Enter final SpanScopePair spanAndScope, @Advice.Thrown final Throwable throwable) {
+ final Span span = spanAndScope.getSpan();
+ DECORATE.onError(span, throwable);
+ DECORATE.beforeFinish(span);
+ span.end();
+ spanAndScope.getScope().close();
}
}
}

MODIFY
instrumentation/jedis-3.0/src/main/java/io/opentelemetry/auto/instrumentation/jedis30/JedisClientDecorator.java
instrumentation/jedis-3.0/src/main/java/io/opentelemetry/auto/instrumentation/jedis30/JedisClientDecorator.java
package io.opentelemetry.auto.instrumentation.jedis30;
+import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.api.SpanTypes;
import io.opentelemetry.auto.decorator.DatabaseClientDecorator;
+import io.opentelemetry.trace.Tracer;
import redis.clients.jedis.commands.ProtocolCommand;
public class JedisClientDecorator extends DatabaseClientDecorator<ProtocolCommand> {
public static final JedisClientDecorator DECORATE = new JedisClientDecorator();
+ public static final Tracer TRACER =
+ OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto.jedis-1.4");
+
@Override
protected String[] instrumentationNames() {
return new String[] {"jedis", "redis"};

MODIFY
instrumentation/jedis-3.0/src/main/java/io/opentelemetry/auto/instrumentation/jedis30/JedisInstrumentation.java
instrumentation/jedis-3.0/src/main/java/io/opentelemetry/auto/instrumentation/jedis30/JedisInstrumentation.java
package io.opentelemetry.auto.instrumentation.jedis30;
-import static io.opentelemetry.auto.instrumentation.api.AgentTracer.activateSpan;
-import static io.opentelemetry.auto.instrumentation.api.AgentTracer.startSpan;
import static io.opentelemetry.auto.instrumentation.jedis30.JedisClientDecorator.DECORATE;
+import static io.opentelemetry.auto.instrumentation.jedis30.JedisClientDecorator.TRACER;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -10,9 +9,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
-import io.opentelemetry.auto.instrumentation.api.AgentScope;
-import io.opentelemetry.auto.instrumentation.api.AgentSpan;
+import io.opentelemetry.auto.instrumentation.api.SpanScopePair;
import io.opentelemetry.auto.tooling.Instrumenter;
+import io.opentelemetry.trace.Span;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -57,8 +56,8 @@ public final class JedisInstrumentation extends Instrumenter.Default {
public static class JedisAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static AgentScope onEnter(@Advice.Argument(1) final ProtocolCommand command) {
- final AgentSpan span = startSpan("redis.query");
+ public static SpanScopePair onEnter(@Advice.Argument(1) final ProtocolCommand command) {
+ final Span span = TRACER.spanBuilder("redis.query").startSpan();
DECORATE.afterStart(span);
if (command instanceof Protocol.Command) {
DECORATE.onStatement(span, ((Protocol.Command) command).name());
@@ -67,15 +66,17 @@ public final class JedisInstrumentation extends Instrumenter.Default {
// us if that changes
DECORATE.onStatement(span, new String(command.getRaw()));
}
- return activateSpan(span, true);
+ return new SpanScopePair(span, TRACER.withSpan(span));
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
- DECORATE.onError(scope.span(), throwable);
- DECORATE.beforeFinish(scope.span());
- scope.close();
+ @Advice.Enter final SpanScopePair spanAndScope, @Advice.Thrown final Throwable throwable) {
+ final Span span = spanAndScope.getSpan();
+ DECORATE.onError(span, throwable);
+ DECORATE.beforeFinish(span);
+ span.end();
+ spanAndScope.getScope().close();
}
}
}

Refactored jedis-* (#113)