Skip to content

Commit 41814e6

Browse files
committed
myfaces-3.0
1 parent 3b7ee3c commit 41814e6

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

instrumentation/jsf/jsf-myfaces-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/v3_0/ActionListenerImplInstrumentation.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1616
import io.opentelemetry.javaagent.instrumentation.jsf.jakarta.JsfRequest;
1717
import jakarta.faces.event.ActionEvent;
18+
import javax.annotation.Nullable;
1819
import net.bytebuddy.asm.Advice;
1920
import net.bytebuddy.description.type.TypeDescription;
2021
import net.bytebuddy.matcher.ElementMatcher;
@@ -36,34 +37,48 @@ public void transform(TypeTransformer transformer) {
3637
@SuppressWarnings("unused")
3738
public static class ProcessActionAdvice {
3839

39-
@Advice.OnMethodEnter(suppress = Throwable.class)
40-
public static void onEnter(
41-
@Advice.Argument(0) ActionEvent event,
42-
@Advice.Local("otelRequest") JsfRequest request,
43-
@Advice.Local("otelContext") Context context,
44-
@Advice.Local("otelScope") Scope scope) {
45-
Context parentContext = Java8BytecodeBridge.currentContext();
40+
public static class AdviceScope {
41+
private final JsfRequest request;
42+
private final Context context;
43+
private final Scope scope;
44+
45+
private AdviceScope(JsfRequest request, Context context, Scope scope) {
46+
this.request = request;
47+
this.context = context;
48+
this.scope = scope;
49+
}
4650

47-
request = new JsfRequest(event);
48-
if (!request.shouldStartSpan() || !instrumenter().shouldStart(parentContext, request)) {
49-
return;
51+
@Nullable
52+
public static AdviceScope start(@Advice.Argument(0) ActionEvent event) {
53+
Context parentContext = Java8BytecodeBridge.currentContext();
54+
JsfRequest request = new JsfRequest(event);
55+
if (!request.shouldStartSpan() || !instrumenter().shouldStart(parentContext, request)) {
56+
return null;
57+
}
58+
Context context = instrumenter().start(parentContext, request);
59+
Scope scope = context.makeCurrent();
60+
return new AdviceScope(request, context, scope);
5061
}
5162

52-
context = instrumenter().start(parentContext, request);
53-
scope = context.makeCurrent();
63+
public void end(Throwable throwable) {
64+
scope.close();
65+
instrumenter().end(context, request, null, throwable);
66+
}
67+
}
68+
69+
@Nullable
70+
@Advice.OnMethodEnter(suppress = Throwable.class)
71+
public static AdviceScope onEnter(@Advice.Argument(0) ActionEvent event) {
72+
return AdviceScope.start(event);
5473
}
5574

5675
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
5776
public static void stopSpan(
58-
@Advice.Thrown Throwable throwable,
59-
@Advice.Local("otelRequest") JsfRequest request,
60-
@Advice.Local("otelContext") Context context,
61-
@Advice.Local("otelScope") Scope scope) {
62-
if (scope == null) {
63-
return;
77+
@Advice.Thrown @Nullable Throwable throwable,
78+
@Advice.Enter @Nullable AdviceScope adviceScope) {
79+
if (adviceScope != null) {
80+
adviceScope.end(throwable);
6481
}
65-
scope.close();
66-
instrumenter().end(context, request, null, throwable);
6782
}
6883
}
6984
}

instrumentation/jsf/jsf-myfaces-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/v3_0/MyFacesInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import com.google.auto.service.AutoService;
1111
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1212
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
13+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1314
import java.util.List;
1415

1516
@AutoService(InstrumentationModule.class)
16-
public class MyFacesInstrumentationModule extends InstrumentationModule {
17+
public class MyFacesInstrumentationModule extends InstrumentationModule
18+
implements ExperimentalInstrumentationModule {
1719
public MyFacesInstrumentationModule() {
1820
super("jsf-myfaces", "jsf-myfaces-3.0");
1921
}
@@ -23,4 +25,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
2325
return asList(
2426
new ActionListenerImplInstrumentation(), new RestoreViewExecutorInstrumentation());
2527
}
28+
29+
@Override
30+
public boolean isIndyReady() {
31+
return true;
32+
}
2633
}

0 commit comments

Comments
 (0)