Skip to content

Commit 09544aa

Browse files
committed
single returned scope
1 parent d9d3beb commit 09544aa

File tree

10 files changed

+55
-68
lines changed

10 files changed

+55
-68
lines changed

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfJaxRsInvokerInstrumentation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.opentelemetry.context.Scope;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1414
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
15+
import javax.annotation.Nullable;
1516
import net.bytebuddy.asm.Advice;
1617
import net.bytebuddy.description.type.TypeDescription;
1718
import net.bytebuddy.matcher.ElementMatcher;
@@ -37,17 +38,16 @@ public void transform(TypeTransformer transformer) {
3738
@SuppressWarnings("unused")
3839
public static class InvokeAdvice {
3940

41+
@Nullable
4042
@Advice.OnMethodEnter(suppress = Throwable.class)
41-
public static void onEnter(
42-
@Advice.Argument(0) Exchange exchange, @Advice.Local("otelScope") Scope scope) {
43+
public static Scope onEnter(@Advice.Argument(0) Exchange exchange) {
44+
4345
Context context = CxfSpanName.INSTANCE.updateServerSpanName(exchange);
44-
if (context != null) {
45-
scope = context.makeCurrent();
46-
}
46+
return context != null ? context.makeCurrent() : null;
4747
}
4848

4949
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
50-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
50+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5151
if (scope != null) {
5252
scope.close();
5353
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfRsHttpListenerInstrumentation.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
17+
import javax.annotation.Nullable;
1718
import net.bytebuddy.asm.Advice;
1819
import net.bytebuddy.description.type.TypeDescription;
1920
import net.bytebuddy.matcher.ElementMatcher;
@@ -36,17 +37,15 @@ public void transform(TypeTransformer transformer) {
3637
@SuppressWarnings("unused")
3738
public static class InvokeAdvice {
3839

40+
@Nullable
3941
@Advice.OnMethodEnter(suppress = Throwable.class)
40-
public static void onEnter(
41-
@Advice.FieldValue("pattern") String pattern, @Advice.Local("otelScope") Scope scope) {
42+
public static Scope onEnter(@Advice.FieldValue("pattern") String pattern) {
4243
Context context = JaxrsContextPath.init(Java8BytecodeBridge.currentContext(), pattern);
43-
if (context != null) {
44-
scope = context.makeCurrent();
45-
}
44+
return context != null ? context.makeCurrent() : null;
4645
}
4746

4847
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
49-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
48+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5049
if (scope != null) {
5150
scope.close();
5251
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfServletControllerInstrumentation.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
19+
import javax.annotation.Nullable;
1920
import javax.servlet.http.HttpServletRequest;
2021
import net.bytebuddy.asm.Advice;
2122
import net.bytebuddy.description.type.TypeDescription;
@@ -41,20 +42,19 @@ public void transform(TypeTransformer transformer) {
4142
@SuppressWarnings("unused")
4243
public static class InvokeAdvice {
4344

45+
@Nullable
4446
@Advice.OnMethodEnter(suppress = Throwable.class)
45-
public static void onEnter(
46-
@Advice.Argument(0) HttpServletRequest httpServletRequest,
47-
@Advice.Local("otelScope") Scope scope) {
47+
public static Scope onEnter(@Advice.Argument(0) HttpServletRequest httpServletRequest) {
48+
4849
Context context =
4950
JaxrsContextPath.init(
5051
Java8BytecodeBridge.currentContext(), httpServletRequest.getServletPath());
51-
if (context != null) {
52-
scope = context.makeCurrent();
53-
}
52+
53+
return context != null ? context.makeCurrent() : null;
5454
}
5555

5656
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
57-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
57+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5858
if (scope != null) {
5959
scope.close();
6060
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JerseyServletContainerInstrumentation.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ public void transform(TypeTransformer transformer) {
4040
@SuppressWarnings("unused")
4141
public static class ServiceAdvice {
4242

43+
@Nullable
4344
@Advice.OnMethodEnter(suppress = Throwable.class)
44-
public static void onEnter(
45-
@Advice.Argument(0) HttpServletRequest httpServletRequest,
46-
@Advice.Local("otelScope") Scope scope) {
45+
public static Scope onEnter(@Advice.Argument(0) HttpServletRequest httpServletRequest) {
4746
Context context =
4847
JaxrsContextPath.init(
4948
Java8BytecodeBridge.currentContext(), httpServletRequest.getServletPath());
50-
if (context != null) {
51-
scope = context.makeCurrent();
52-
}
49+
return context != null ? context.makeCurrent() : null;
5350
}
5451

5552
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
56-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
53+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5754
if (scope != null) {
5855
scope.close();
5956
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/Resteasy30ServletContainerDispatcherInstrumentation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
17+
import javax.annotation.Nullable;
1718
import net.bytebuddy.asm.Advice;
1819
import net.bytebuddy.description.type.TypeDescription;
1920
import net.bytebuddy.matcher.ElementMatcher;
@@ -35,19 +36,17 @@ public void transform(TypeTransformer transformer) {
3536
@SuppressWarnings("unused")
3637
public static class ServiceAdvice {
3738

39+
@Nullable
3840
@Advice.OnMethodEnter(suppress = Throwable.class)
39-
public static void onEnter(
40-
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix,
41-
@Advice.Local("otelScope") Scope scope) {
41+
public static Scope onEnter(
42+
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix) {
4243
Context context =
4344
JaxrsContextPath.init(Java8BytecodeBridge.currentContext(), servletMappingPrefix);
44-
if (context != null) {
45-
scope = context.makeCurrent();
46-
}
45+
return context != null ? context.makeCurrent() : null;
4746
}
4847

4948
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
50-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
49+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5150
if (scope != null) {
5251
scope.close();
5352
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasyResourceLocatorInvokerInstrumentation.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
18+
import javax.annotation.Nullable;
1819
import net.bytebuddy.asm.Advice;
1920
import net.bytebuddy.description.type.TypeDescription;
2021
import net.bytebuddy.matcher.ElementMatcher;
@@ -40,10 +41,9 @@ public void transform(TypeTransformer transformer) {
4041
@SuppressWarnings("unused")
4142
public static class InvokeOnTargetObjectAdvice {
4243

44+
@Nullable
4345
@Advice.OnMethodEnter(suppress = Throwable.class)
44-
public static void onEnter(
45-
@Advice.This ResourceLocatorInvoker resourceInvoker,
46-
@Advice.Local("otelScope") Scope scope) {
46+
public static Scope onEnter(@Advice.This ResourceLocatorInvoker resourceInvoker) {
4747

4848
Context currentContext = Java8BytecodeBridge.currentContext();
4949

@@ -55,13 +55,11 @@ public static void onEnter(
5555
// append current path to jax-rs context path so that it would be present in the final path
5656
Context context =
5757
JaxrsContextPath.init(currentContext, JaxrsContextPath.prepend(currentContext, name));
58-
if (context != null) {
59-
scope = context.makeCurrent();
60-
}
58+
return context != null ? context.makeCurrent() : null;
6159
}
6260

6361
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
64-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
62+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
6563
if (scope != null) {
6664
scope.close();
6765
}

instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasyServletContainerDispatcherInstrumentation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
17+
import javax.annotation.Nullable;
1718
import net.bytebuddy.asm.Advice;
1819
import net.bytebuddy.description.type.TypeDescription;
1920
import net.bytebuddy.matcher.ElementMatcher;
@@ -35,19 +36,17 @@ public void transform(TypeTransformer transformer) {
3536
@SuppressWarnings("unused")
3637
public static class ServiceAdvice {
3738

39+
@Nullable
3840
@Advice.OnMethodEnter(suppress = Throwable.class)
39-
public static void onEnter(
40-
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix,
41-
@Advice.Local("otelScope") Scope scope) {
41+
public static Scope onEnter(
42+
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix) {
4243
Context context =
4344
JaxrsContextPath.init(Java8BytecodeBridge.currentContext(), servletMappingPrefix);
44-
if (context != null) {
45-
scope = context.makeCurrent();
46-
}
45+
return context != null ? context.makeCurrent() : null;
4746
}
4847

4948
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
50-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
49+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5150
if (scope != null) {
5251
scope.close();
5352
}

instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/JerseyServletContainerInstrumentation.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1818
import jakarta.servlet.http.HttpServletRequest;
19+
import javax.annotation.Nullable;
1920
import net.bytebuddy.asm.Advice;
2021
import net.bytebuddy.description.type.TypeDescription;
2122
import net.bytebuddy.matcher.ElementMatcher;
@@ -40,20 +41,17 @@ public void transform(TypeTransformer transformer) {
4041
@SuppressWarnings("unused")
4142
public static class ServiceAdvice {
4243

44+
@Nullable
4345
@Advice.OnMethodEnter(suppress = Throwable.class)
44-
public static void onEnter(
45-
@Advice.Argument(0) HttpServletRequest httpServletRequest,
46-
@Advice.Local("otelScope") Scope scope) {
46+
public static Scope onEnter(@Advice.Argument(0) HttpServletRequest httpServletRequest) {
4747
Context context =
4848
JaxrsContextPath.init(
4949
Java8BytecodeBridge.currentContext(), httpServletRequest.getServletPath());
50-
if (context != null) {
51-
scope = context.makeCurrent();
52-
}
50+
return context != null ? context.makeCurrent() : null;
5351
}
5452

5553
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
56-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
54+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5755
if (scope != null) {
5856
scope.close();
5957
}

instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/ResteasyResourceLocatorInvokerInstrumentation.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
18+
import javax.annotation.Nullable;
1819
import net.bytebuddy.asm.Advice;
1920
import net.bytebuddy.description.type.TypeDescription;
2021
import net.bytebuddy.matcher.ElementMatcher;
@@ -40,10 +41,9 @@ public void transform(TypeTransformer transformer) {
4041
@SuppressWarnings("unused")
4142
public static class InvokeOnTargetObjectAdvice {
4243

44+
@Nullable
4345
@Advice.OnMethodEnter(suppress = Throwable.class)
44-
public static void onEnter(
45-
@Advice.This ResourceLocatorInvoker resourceInvoker,
46-
@Advice.Local("otelScope") Scope scope) {
46+
public static Scope onEnter(@Advice.This ResourceLocatorInvoker resourceInvoker) {
4747

4848
Context currentContext = Java8BytecodeBridge.currentContext();
4949

@@ -55,13 +55,11 @@ public static void onEnter(
5555
// append current path to jax-rs context path so that it would be present in the final path
5656
Context context =
5757
JaxrsContextPath.init(currentContext, JaxrsContextPath.prepend(currentContext, name));
58-
if (context != null) {
59-
scope = context.makeCurrent();
60-
}
58+
return context != null ? context.makeCurrent() : null;
6159
}
6260

6361
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
64-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
62+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
6563
if (scope != null) {
6664
scope.close();
6765
}

instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v3_0/ResteasyServletContainerDispatcherInstrumentation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath;
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
17+
import javax.annotation.Nullable;
1718
import net.bytebuddy.asm.Advice;
1819
import net.bytebuddy.description.type.TypeDescription;
1920
import net.bytebuddy.matcher.ElementMatcher;
@@ -35,19 +36,17 @@ public void transform(TypeTransformer transformer) {
3536
@SuppressWarnings("unused")
3637
public static class ServiceAdvice {
3738

39+
@Nullable
3840
@Advice.OnMethodEnter(suppress = Throwable.class)
39-
public static void onEnter(
40-
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix,
41-
@Advice.Local("otelScope") Scope scope) {
41+
public static Scope onEnter(
42+
@Advice.FieldValue("servletMappingPrefix") String servletMappingPrefix) {
4243
Context context =
4344
JaxrsContextPath.init(Java8BytecodeBridge.currentContext(), servletMappingPrefix);
44-
if (context != null) {
45-
scope = context.makeCurrent();
46-
}
45+
return context != null ? context.makeCurrent() : null;
4746
}
4847

4948
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
50-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
49+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
5150
if (scope != null) {
5251
scope.close();
5352
}

0 commit comments

Comments
 (0)