Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -43,36 +43,53 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class EventAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.This ComponentPageElementImpl componentPageElementImpl,
@Advice.Argument(0) String eventType,
@Advice.Local("otelRequest") TapestryRequest request,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = Java8BytecodeBridge.currentContext();

request = new TapestryRequest(eventType, componentPageElementImpl.getCompleteId());
if (!instrumenter().shouldStart(parentContext, request)) {
return;
public static class AdviceScope {
private final TapestryRequest request;
private final Context context;
private final Scope scope;

private AdviceScope(TapestryRequest request, Context context, Scope scope) {
this.request = request;
this.context = context;
this.scope = scope;
}

@Nullable
public static AdviceScope start(
ComponentPageElementImpl componentPageElement, String eventType) {
Context parentContext = Context.current();

TapestryRequest request =
new TapestryRequest(eventType, componentPageElement.getCompleteId());
if (!instrumenter().shouldStart(parentContext, request)) {
return null;
}

Context context = instrumenter().start(parentContext, request);
return new AdviceScope(request, context, context.makeCurrent());
}

context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();
public void end(Throwable throwable) {
scope.close();

instrumenter().end(context, request, null, throwable);
}
}

@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope onEnter(
@Advice.This ComponentPageElementImpl componentPageElementImpl,
@Advice.Argument(0) String eventType) {
return AdviceScope.start(componentPageElementImpl, eventType);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Thrown Throwable throwable,
@Advice.Local("otelRequest") TapestryRequest request,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
return;
@Advice.Thrown Throwable throwable, @Advice.Enter @Nullable AdviceScope adviceScope) {
if (adviceScope != null) {
adviceScope.end(throwable);
}
scope.close();

instrumenter().end(context, request, null, throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class TapestryInstrumentationModule extends InstrumentationModule {
public class TapestryInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public TapestryInstrumentationModule() {
super("tapestry", "tapestry-5.4");
Expand All @@ -33,4 +35,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
new InitializeActivePageNameInstrumentation(),
new ComponentPageElementImplInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Loading