Skip to content

Commit 4fab6ab

Browse files
LikeTheSaladSylvainJugeotelbot[bot]
authored
Indy-ready - tapestry (#14990)
Co-authored-by: SylvainJuge <[email protected]> Co-authored-by: otelbot <[email protected]>
1 parent 8132c44 commit 4fab6ab

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/ComponentPageElementImplInstrumentation.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import io.opentelemetry.context.Context;
1515
import io.opentelemetry.context.Scope;
16-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1716
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1817
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
18+
import javax.annotation.Nullable;
1919
import net.bytebuddy.asm.Advice;
2020
import net.bytebuddy.description.type.TypeDescription;
2121
import net.bytebuddy.matcher.ElementMatcher;
@@ -43,36 +43,54 @@ public void transform(TypeTransformer transformer) {
4343
@SuppressWarnings("unused")
4444
public static class EventAdvice {
4545

46-
@Advice.OnMethodEnter(suppress = Throwable.class)
47-
public static void onEnter(
48-
@Advice.This ComponentPageElementImpl componentPageElementImpl,
49-
@Advice.Argument(0) String eventType,
50-
@Advice.Local("otelRequest") TapestryRequest request,
51-
@Advice.Local("otelContext") Context context,
52-
@Advice.Local("otelScope") Scope scope) {
53-
Context parentContext = Java8BytecodeBridge.currentContext();
54-
55-
request = new TapestryRequest(eventType, componentPageElementImpl.getCompleteId());
56-
if (!instrumenter().shouldStart(parentContext, request)) {
57-
return;
46+
public static class AdviceScope {
47+
private final TapestryRequest request;
48+
private final Context context;
49+
private final Scope scope;
50+
51+
private AdviceScope(TapestryRequest request, Context context, Scope scope) {
52+
this.request = request;
53+
this.context = context;
54+
this.scope = scope;
55+
}
56+
57+
@Nullable
58+
public static AdviceScope start(
59+
ComponentPageElementImpl componentPageElement, String eventType) {
60+
Context parentContext = Context.current();
61+
62+
TapestryRequest request =
63+
new TapestryRequest(eventType, componentPageElement.getCompleteId());
64+
if (!instrumenter().shouldStart(parentContext, request)) {
65+
return null;
66+
}
67+
68+
Context context = instrumenter().start(parentContext, request);
69+
return new AdviceScope(request, context, context.makeCurrent());
5870
}
5971

60-
context = instrumenter().start(parentContext, request);
61-
scope = context.makeCurrent();
72+
public void end(@Nullable Throwable throwable) {
73+
scope.close();
74+
75+
instrumenter().end(context, request, null, throwable);
76+
}
77+
}
78+
79+
@Nullable
80+
@Advice.OnMethodEnter(suppress = Throwable.class)
81+
public static AdviceScope onEnter(
82+
@Advice.This ComponentPageElementImpl componentPageElementImpl,
83+
@Advice.Argument(0) String eventType) {
84+
return AdviceScope.start(componentPageElementImpl, eventType);
6285
}
6386

6487
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
6588
public static void onExit(
66-
@Advice.Thrown Throwable throwable,
67-
@Advice.Local("otelRequest") TapestryRequest request,
68-
@Advice.Local("otelContext") Context context,
69-
@Advice.Local("otelScope") Scope scope) {
70-
if (scope == null) {
71-
return;
89+
@Advice.Thrown @Nullable Throwable throwable,
90+
@Advice.Enter @Nullable AdviceScope adviceScope) {
91+
if (adviceScope != null) {
92+
adviceScope.end(throwable);
7293
}
73-
scope.close();
74-
75-
instrumenter().end(context, request, null, throwable);
7694
}
7795
}
7896
}

instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/TapestryInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import java.util.List;
1516
import net.bytebuddy.matcher.ElementMatcher;
1617

1718
@AutoService(InstrumentationModule.class)
18-
public class TapestryInstrumentationModule extends InstrumentationModule {
19+
public class TapestryInstrumentationModule extends InstrumentationModule
20+
implements ExperimentalInstrumentationModule {
1921

2022
public TapestryInstrumentationModule() {
2123
super("tapestry", "tapestry-5.4");
@@ -33,4 +35,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
3335
new InitializeActivePageNameInstrumentation(),
3436
new ComponentPageElementImplInstrumentation());
3537
}
38+
39+
@Override
40+
public boolean isIndyReady() {
41+
return true;
42+
}
3643
}

0 commit comments

Comments
 (0)