Skip to content

Commit cd1f516

Browse files
committed
ws
1 parent 24ff6eb commit cd1f516

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/v2_0/AnnotatedMethodInstrumentation.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.opentelemetry.javaagent.bootstrap.CallDepth;
1919
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2020
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
21+
import javax.annotation.Nullable;
2122
import net.bytebuddy.asm.Advice;
2223
import net.bytebuddy.description.type.TypeDescription;
2324
import net.bytebuddy.matcher.ElementMatcher;
@@ -51,42 +52,56 @@ public void transform(TypeTransformer transformer) {
5152
@SuppressWarnings("unused")
5253
public static class AnnotatedMethodAdvice {
5354

55+
public static class AdviceScope {
56+
public CallDepth callDepth;
57+
public SpringWsRequest request;
58+
public Context context;
59+
public Scope scope;
60+
61+
public AdviceScope(
62+
CallDepth callDepth, SpringWsRequest request, Context context, Scope scope) {
63+
this.callDepth = callDepth;
64+
this.request = request;
65+
this.context = context;
66+
this.scope = scope;
67+
}
68+
69+
public void exit(@Nullable Throwable throwable) {
70+
if (callDepth.decrementAndGet() > 0) {
71+
return;
72+
}
73+
scope.close();
74+
instrumenter().end(context, request, null, throwable);
75+
}
76+
}
77+
78+
@Nullable
5479
@Advice.OnMethodEnter(suppress = Throwable.class)
55-
public static void startSpan(
56-
@Advice.Origin("#t") Class<?> codeClass,
57-
@Advice.Origin("#m") String methodName,
58-
@Advice.Local("otelCallDepth") CallDepth callDepth,
59-
@Advice.Local("otelRequest") SpringWsRequest request,
60-
@Advice.Local("otelContext") Context context,
61-
@Advice.Local("otelScope") Scope scope) {
62-
callDepth = CallDepth.forClass(PayloadRoot.class);
80+
public static AdviceScope startSpan(
81+
@Advice.Origin("#t") Class<?> codeClass, @Advice.Origin("#m") String methodName) {
82+
83+
CallDepth callDepth = CallDepth.forClass(PayloadRoot.class);
6384
if (callDepth.getAndIncrement() > 0) {
64-
return;
85+
return new AdviceScope(callDepth, null, null, null);
6586
}
6687

6788
Context parentContext = currentContext();
68-
request = SpringWsRequest.create(codeClass, methodName);
89+
SpringWsRequest request = SpringWsRequest.create(codeClass, methodName);
6990
if (!instrumenter().shouldStart(parentContext, request)) {
70-
return;
91+
return null;
7192
}
7293

73-
context = instrumenter().start(parentContext, request);
74-
scope = context.makeCurrent();
94+
Context context = instrumenter().start(parentContext, request);
95+
return new AdviceScope(callDepth, request, context, parentContext.makeCurrent());
7596
}
7697

7798
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
7899
public static void stopSpan(
79-
@Advice.Thrown Throwable throwable,
80-
@Advice.Local("otelCallDepth") CallDepth callDepth,
81-
@Advice.Local("otelRequest") SpringWsRequest request,
82-
@Advice.Local("otelContext") Context context,
83-
@Advice.Local("otelScope") Scope scope) {
84-
if (callDepth.decrementAndGet() > 0 || scope == null) {
85-
return;
100+
@Advice.Thrown @Nullable Throwable throwable,
101+
@Advice.Enter @Nullable AdviceScope adviceScope) {
102+
if (adviceScope != null) {
103+
adviceScope.exit(throwable);
86104
}
87-
88-
scope.close();
89-
instrumenter().end(context, request, null, throwable);
90105
}
91106
}
92107
}

instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/v2_0/SpringWsInstrumentationModule.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 SpringWsInstrumentationModule extends InstrumentationModule {
18+
public class SpringWsInstrumentationModule extends InstrumentationModule
19+
implements ExperimentalInstrumentationModule {
1820
public SpringWsInstrumentationModule() {
1921
super("spring-ws", "spring-ws-2.0");
2022
}
@@ -29,4 +31,9 @@ public boolean defaultEnabled(ConfigProperties config) {
2931
// this instrumentation only produces controller telemetry
3032
return super.defaultEnabled(config) && ExperimentalConfig.get().controllerTelemetryEnabled();
3133
}
34+
35+
@Override
36+
public boolean isIndyReady() {
37+
return true;
38+
}
3239
}

0 commit comments

Comments
 (0)