diff --git a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/AdviceUtils.java b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/AdviceUtils.java index 956f3e7b04..9e37d09575 100644 --- a/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/AdviceUtils.java +++ b/agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/AdviceUtils.java @@ -16,13 +16,11 @@ package io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent; -import static io.opentelemetry.trace.TracingContextUtils.getSpan; - import io.grpc.Context; import io.opentelemetry.OpenTelemetry; import io.opentelemetry.auto.bootstrap.ContextStore; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.context.ContextUtils; +import io.opentelemetry.context.Scope; import io.opentelemetry.trace.Tracer; /** Helper utils for Runnable/Callable instrumentation */ @@ -39,22 +37,14 @@ public class AdviceUtils { * @param task's type * @return scope if scope was started, or null */ - public static SpanWithScope startTaskScope( - final ContextStore contextStore, final T task) { + public static Scope startTaskScope(final ContextStore contextStore, final T task) { State state = contextStore.get(task); if (state != null) { Context parentContext = state.getAndResetParentContext(); if (parentContext != null) { - return new SpanWithScope( - getSpan(parentContext), ContextUtils.withScopedContext(parentContext)); + return ContextUtils.withScopedContext(parentContext); } } return null; } - - public static void endTaskScope(final SpanWithScope spanWithScope) { - if (spanWithScope != null) { - spanWithScope.closeScope(); - } - } } diff --git a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/AkkaForkJoinTaskInstrumentation.java b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/AkkaForkJoinTaskInstrumentation.java index 5e17cfdc47..6e4bc1d38a 100644 --- a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/AkkaForkJoinTaskInstrumentation.java +++ b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/AkkaForkJoinTaskInstrumentation.java @@ -31,8 +31,8 @@ import io.opentelemetry.auto.bootstrap.ContextStore; import io.opentelemetry.auto.bootstrap.InstrumentationContext; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.AdviceUtils; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.State; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -93,17 +93,17 @@ public final class AkkaForkJoinTaskInstrumentation extends Instrumenter.Default * need to use that state. */ @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope enter(@Advice.This final ForkJoinTask thiz) { + public static Scope enter(@Advice.This final ForkJoinTask thiz) { ContextStore contextStore = InstrumentationContext.get(ForkJoinTask.class, State.class); - SpanWithScope scope = AdviceUtils.startTaskScope(contextStore, thiz); + Scope scope = AdviceUtils.startTaskScope(contextStore, thiz); if (thiz instanceof Runnable) { ContextStore runnableContextStore = InstrumentationContext.get(Runnable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); + Scope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -112,10 +112,10 @@ public final class AkkaForkJoinTaskInstrumentation extends Instrumenter.Default if (thiz instanceof Callable) { ContextStore callableContextStore = InstrumentationContext.get(Callable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); + Scope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -125,8 +125,10 @@ public final class AkkaForkJoinTaskInstrumentation extends Instrumenter.Default } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void exit(@Advice.Enter final SpanWithScope scope) { - AdviceUtils.endTaskScope(scope); + public static void exit(@Advice.Enter final Scope scope) { + if (scope != null) { + scope.close(); + } } } } diff --git a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/CallableInstrumentation.java b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/CallableInstrumentation.java index 969cc7c907..48201630ce 100644 --- a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/CallableInstrumentation.java +++ b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/CallableInstrumentation.java @@ -27,8 +27,8 @@ import io.opentelemetry.auto.bootstrap.ContextStore; import io.opentelemetry.auto.bootstrap.InstrumentationContext; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.AdviceUtils; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.State; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import java.util.Map; import java.util.concurrent.Callable; import net.bytebuddy.asm.Advice; @@ -64,15 +64,17 @@ public final class CallableInstrumentation extends Instrumenter.Default { public static class CallableAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope enter(@Advice.This final Callable thiz) { + public static Scope enter(@Advice.This final Callable thiz) { ContextStore contextStore = InstrumentationContext.get(Callable.class, State.class); return AdviceUtils.startTaskScope(contextStore, thiz); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void exit(@Advice.Enter final SpanWithScope scope) { - AdviceUtils.endTaskScope(scope); + public static void exit(@Advice.Enter final Scope scope) { + if (scope != null) { + scope.close(); + } } } } diff --git a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/JavaForkJoinTaskInstrumentation.java b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/JavaForkJoinTaskInstrumentation.java index 8cabc6f42b..0929d908ec 100644 --- a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/JavaForkJoinTaskInstrumentation.java +++ b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/JavaForkJoinTaskInstrumentation.java @@ -28,8 +28,8 @@ import io.opentelemetry.auto.bootstrap.ContextStore; import io.opentelemetry.auto.bootstrap.InstrumentationContext; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.AdviceUtils; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.State; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -84,17 +84,17 @@ public final class JavaForkJoinTaskInstrumentation extends Instrumenter.Default * need to use that state. */ @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope enter(@Advice.This final ForkJoinTask thiz) { + public static Scope enter(@Advice.This final ForkJoinTask thiz) { ContextStore contextStore = InstrumentationContext.get(ForkJoinTask.class, State.class); - SpanWithScope scope = AdviceUtils.startTaskScope(contextStore, thiz); + Scope scope = AdviceUtils.startTaskScope(contextStore, thiz); if (thiz instanceof Runnable) { ContextStore runnableContextStore = InstrumentationContext.get(Runnable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); + Scope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -103,10 +103,10 @@ public final class JavaForkJoinTaskInstrumentation extends Instrumenter.Default if (thiz instanceof Callable) { ContextStore callableContextStore = InstrumentationContext.get(Callable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); + Scope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -116,8 +116,10 @@ public final class JavaForkJoinTaskInstrumentation extends Instrumenter.Default } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void exit(@Advice.Enter final SpanWithScope scope) { - AdviceUtils.endTaskScope(scope); + public static void exit(@Advice.Enter final Scope scope) { + if (scope != null) { + scope.close(); + } } } } diff --git a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/RunnableInstrumentation.java b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/RunnableInstrumentation.java index 3fd5e0beb2..4e70fdce06 100644 --- a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/RunnableInstrumentation.java +++ b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/RunnableInstrumentation.java @@ -27,8 +27,8 @@ import io.opentelemetry.auto.bootstrap.ContextStore; import io.opentelemetry.auto.bootstrap.InstrumentationContext; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.AdviceUtils; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.State; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import java.util.Map; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -63,15 +63,17 @@ public final class RunnableInstrumentation extends Instrumenter.Default { public static class RunnableAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope enter(@Advice.This final Runnable thiz) { + public static Scope enter(@Advice.This final Runnable thiz) { ContextStore contextStore = InstrumentationContext.get(Runnable.class, State.class); return AdviceUtils.startTaskScope(contextStore, thiz); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void exit(@Advice.Enter final SpanWithScope scope) { - AdviceUtils.endTaskScope(scope); + public static void exit(@Advice.Enter final Scope scope) { + if (scope != null) { + scope.close(); + } } } } diff --git a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/ScalaForkJoinTaskInstrumentation.java b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/ScalaForkJoinTaskInstrumentation.java index aa250e1301..c5087c56b7 100644 --- a/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/ScalaForkJoinTaskInstrumentation.java +++ b/instrumentation/java-concurrent/src/main/java/io/opentelemetry/auto/instrumentation/javaconcurrent/ScalaForkJoinTaskInstrumentation.java @@ -29,8 +29,8 @@ import io.opentelemetry.auto.bootstrap.ContextStore; import io.opentelemetry.auto.bootstrap.InstrumentationContext; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.AdviceUtils; import io.opentelemetry.auto.bootstrap.instrumentation.java.concurrent.State; -import io.opentelemetry.auto.instrumentation.api.SpanWithScope; import io.opentelemetry.auto.tooling.Instrumenter; +import io.opentelemetry.context.Scope; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -93,17 +93,17 @@ public final class ScalaForkJoinTaskInstrumentation extends Instrumenter.Default * need to use that state. */ @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope enter(@Advice.This final ForkJoinTask thiz) { + public static Scope enter(@Advice.This final ForkJoinTask thiz) { ContextStore contextStore = InstrumentationContext.get(ForkJoinTask.class, State.class); - SpanWithScope scope = AdviceUtils.startTaskScope(contextStore, thiz); + Scope scope = AdviceUtils.startTaskScope(contextStore, thiz); if (thiz instanceof Runnable) { ContextStore runnableContextStore = InstrumentationContext.get(Runnable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); + Scope newScope = AdviceUtils.startTaskScope(runnableContextStore, (Runnable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -112,10 +112,10 @@ public final class ScalaForkJoinTaskInstrumentation extends Instrumenter.Default if (thiz instanceof Callable) { ContextStore callableContextStore = InstrumentationContext.get(Callable.class, State.class); - SpanWithScope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); + Scope newScope = AdviceUtils.startTaskScope(callableContextStore, (Callable) thiz); if (null != newScope) { if (null != scope) { - newScope.closeScope(); + newScope.close(); } else { scope = newScope; } @@ -125,8 +125,10 @@ public final class ScalaForkJoinTaskInstrumentation extends Instrumenter.Default } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void exit(@Advice.Enter final SpanWithScope scope) { - AdviceUtils.endTaskScope(scope); + public static void exit(@Advice.Enter final Scope scope) { + if (scope != null) { + scope.close(); + } } } }