Skip to content

Commit c881c08

Browse files
committed
jaxws-2.0
1 parent e2d00a6 commit c881c08

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import com.google.auto.service.AutoService;
99
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1010
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
11+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1112
import java.util.Collections;
1213
import java.util.List;
1314

1415
@AutoService(InstrumentationModule.class)
15-
public class JaxWsInstrumentationModule extends InstrumentationModule {
16+
public class JaxWsInstrumentationModule extends InstrumentationModule
17+
implements ExperimentalInstrumentationModule {
1618

1719
public JaxWsInstrumentationModule() {
1820
super("jaxws", "jaxws-2.0");
@@ -22,4 +24,9 @@ public JaxWsInstrumentationModule() {
2224
public List<TypeInstrumentation> typeInstrumentations() {
2325
return Collections.singletonList(new WebServiceProviderInstrumentation());
2426
}
27+
28+
@Override
29+
public boolean isIndyReady() {
30+
return true;
31+
}
2532
}

instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/WebServiceProviderInstrumentation.java

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2121
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2222
import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsRequest;
23+
import javax.annotation.Nullable;
2324
import javax.xml.ws.Provider;
2425
import net.bytebuddy.asm.Advice;
2526
import net.bytebuddy.description.type.TypeDescription;
@@ -47,42 +48,52 @@ public void transform(TypeTransformer transformer) {
4748
@SuppressWarnings("unused")
4849
public static class InvokeAdvice {
4950

50-
@Advice.OnMethodEnter(suppress = Throwable.class)
51-
public static void startSpan(
52-
@Advice.This Object target,
53-
@Advice.Origin("#m") String methodName,
54-
@Advice.Local("otelCallDepth") CallDepth callDepth,
55-
@Advice.Local("otelRequest") JaxWsRequest request,
56-
@Advice.Local("otelContext") Context context,
57-
@Advice.Local("otelScope") Scope scope) {
58-
callDepth = CallDepth.forClass(Provider.class);
59-
if (callDepth.getAndIncrement() > 0) {
60-
return;
51+
public static class AdviceScope {
52+
private final CallDepth callDepth;
53+
private final JaxWsRequest request;
54+
private final Context context;
55+
private final Scope scope;
56+
57+
private AdviceScope(CallDepth callDepth, JaxWsRequest request, Context context, Scope scope) {
58+
this.callDepth = callDepth;
59+
this.request = request;
60+
this.context = context;
61+
this.scope = scope;
62+
}
63+
64+
public static AdviceScope start(CallDepth callDepth, Object target, String methodName) {
65+
if (callDepth.getAndIncrement() > 0) {
66+
return new AdviceScope(callDepth, null, null, null);
67+
}
68+
Context parentContext = currentContext();
69+
JaxWsRequest request = new JaxWsRequest(target.getClass(), methodName);
70+
if (!instrumenter().shouldStart(parentContext, request)) {
71+
return new AdviceScope(callDepth, null, null, null);
72+
}
73+
Context context = instrumenter().start(parentContext, request);
74+
return new AdviceScope(callDepth, request, context, context.makeCurrent());
6175
}
6276

63-
Context parentContext = currentContext();
64-
request = new JaxWsRequest(target.getClass(), methodName);
65-
if (!instrumenter().shouldStart(parentContext, request)) {
66-
return;
77+
public void end(Throwable throwable) {
78+
if (callDepth.decrementAndGet() > 0 || scope == null) {
79+
return;
80+
}
81+
scope.close();
82+
instrumenter().end(context, request, null, throwable);
6783
}
84+
}
6885

69-
context = instrumenter().start(parentContext, request);
70-
scope = context.makeCurrent();
86+
@Advice.OnMethodEnter(suppress = Throwable.class)
87+
public static AdviceScope startSpan(
88+
@Advice.This Object target, @Advice.Origin("#m") String methodName) {
89+
CallDepth callDepth = CallDepth.forClass(Provider.class);
90+
return AdviceScope.start(callDepth, target, methodName);
7191
}
7292

7393
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
7494
public static void stopSpan(
75-
@Advice.Thrown Throwable throwable,
76-
@Advice.Local("otelCallDepth") CallDepth callDepth,
77-
@Advice.Local("otelRequest") JaxWsRequest request,
78-
@Advice.Local("otelContext") Context context,
79-
@Advice.Local("otelScope") Scope scope) {
80-
if (callDepth.decrementAndGet() > 0 || scope == null) {
81-
return;
82-
}
83-
84-
scope.close();
85-
instrumenter().end(context, request, null, throwable);
95+
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter AdviceScope adviceScope) {
96+
adviceScope.end(throwable);
8697
}
8798
}
8899
}

0 commit comments

Comments
 (0)