Skip to content

Commit 956f076

Browse files
committed
jaxws-jws-api
1 parent c881c08 commit 956f076

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsInstrumentation.java

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2626
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2727
import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsRequest;
28+
import javax.annotation.Nullable;
2829
import javax.jws.WebService;
2930
import net.bytebuddy.asm.Advice;
3031
import net.bytebuddy.description.type.TypeDescription;
@@ -62,42 +63,52 @@ public void transform(TypeTransformer transformer) {
6263
@SuppressWarnings("unused")
6364
public static class JwsAnnotationsAdvice {
6465

65-
@Advice.OnMethodEnter(suppress = Throwable.class)
66-
public static void startSpan(
67-
@Advice.This Object target,
68-
@Advice.Origin("#m") String methodName,
69-
@Advice.Local("otelCallDepth") CallDepth callDepth,
70-
@Advice.Local("otelRequest") JaxWsRequest request,
71-
@Advice.Local("otelContext") Context context,
72-
@Advice.Local("otelScope") Scope scope) {
73-
callDepth = CallDepth.forClass(WebService.class);
74-
if (callDepth.getAndIncrement() > 0) {
75-
return;
66+
public static class AdviceScope {
67+
private final CallDepth callDepth;
68+
private final JaxWsRequest request;
69+
private final Context context;
70+
private final Scope scope;
71+
72+
private AdviceScope(CallDepth callDepth, JaxWsRequest request, Context context, Scope scope) {
73+
this.callDepth = callDepth;
74+
this.request = request;
75+
this.context = context;
76+
this.scope = scope;
77+
}
78+
79+
public static AdviceScope start(CallDepth callDepth, Object target, String methodName) {
80+
if (callDepth.getAndIncrement() > 0) {
81+
return new AdviceScope(callDepth, null, null, null);
82+
}
83+
Context parentContext = currentContext();
84+
JaxWsRequest request = new JaxWsRequest(target.getClass(), methodName);
85+
if (!instrumenter().shouldStart(parentContext, request)) {
86+
return new AdviceScope(callDepth, null, null, null);
87+
}
88+
Context context = instrumenter().start(parentContext, request);
89+
return new AdviceScope(callDepth, request, context, context.makeCurrent());
7690
}
7791

78-
Context parentContext = currentContext();
79-
request = new JaxWsRequest(target.getClass(), methodName);
80-
if (!instrumenter().shouldStart(parentContext, request)) {
81-
return;
92+
public void end(Throwable throwable) {
93+
if (callDepth.decrementAndGet() > 0 || scope == null) {
94+
return;
95+
}
96+
scope.close();
97+
instrumenter().end(context, request, null, throwable);
8298
}
99+
}
83100

84-
context = instrumenter().start(parentContext, request);
85-
scope = context.makeCurrent();
101+
@Advice.OnMethodEnter(suppress = Throwable.class)
102+
public static AdviceScope startSpan(
103+
@Advice.This Object target, @Advice.Origin("#m") String methodName) {
104+
CallDepth callDepth = CallDepth.forClass(WebService.class);
105+
return AdviceScope.start(callDepth, target, methodName);
86106
}
87107

88108
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
89109
public static void stopSpan(
90-
@Advice.Thrown Throwable throwable,
91-
@Advice.Local("otelCallDepth") CallDepth callDepth,
92-
@Advice.Local("otelRequest") JaxWsRequest request,
93-
@Advice.Local("otelContext") Context context,
94-
@Advice.Local("otelScope") Scope scope) {
95-
if (callDepth.decrementAndGet() > 0 || scope == null) {
96-
return;
97-
}
98-
99-
scope.close();
100-
instrumenter().end(context, request, null, throwable);
110+
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter AdviceScope adviceScope) {
111+
adviceScope.end(throwable);
101112
}
102113
}
103114
}

instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import io.opentelemetry.javaagent.bootstrap.internal.ExperimentalConfig;
1010
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1111
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
12+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1213
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1314
import java.util.Collections;
1415
import java.util.List;
1516

1617
@AutoService(InstrumentationModule.class)
17-
public class JwsInstrumentationModule extends InstrumentationModule {
18+
public class JwsInstrumentationModule extends InstrumentationModule
19+
implements ExperimentalInstrumentationModule {
1820

1921
public JwsInstrumentationModule() {
2022
super("jaxws-jws-api", "jaxws-jws-api-1.1", "jaxws");
@@ -30,4 +32,9 @@ public boolean defaultEnabled(ConfigProperties config) {
3032
// this instrumentation only produces controller telemetry
3133
return super.defaultEnabled(config) && ExperimentalConfig.get().controllerTelemetryEnabled();
3234
}
35+
36+
@Override
37+
public boolean isIndyReady() {
38+
return true;
39+
}
3340
}

0 commit comments

Comments
 (0)