Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -17,9 +17,9 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute;
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 All @@ -46,39 +46,50 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class InvokeActionOnlyAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.This ActionInvocation actionInvocation,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = Java8BytecodeBridge.currentContext();
public static class AdviceScope {
private final Context context;
private final Scope scope;

HttpServerRoute.update(
parentContext,
CONTROLLER,
StrutsServerSpanNaming.SERVER_SPAN_NAME,
actionInvocation.getProxy());
public AdviceScope(Context context, Scope scope) {
this.context = context;
this.scope = scope;
}

if (!instrumenter().shouldStart(parentContext, actionInvocation)) {
return;
@Nullable
public static AdviceScope start(ActionInvocation actionInvocation) {
Context parentContext = Context.current();
HttpServerRoute.update(
parentContext,
CONTROLLER,
StrutsServerSpanNaming.SERVER_SPAN_NAME,
actionInvocation.getProxy());

if (!instrumenter().shouldStart(parentContext, actionInvocation)) {
return null;
}
Context context = instrumenter().start(parentContext, actionInvocation);
return new AdviceScope(context, context.makeCurrent());
}

context = instrumenter().start(parentContext, actionInvocation);
scope = context.makeCurrent();
public void end(ActionInvocation actionInvocation, @Nullable Throwable throwable) {
scope.close();
instrumenter().end(context, actionInvocation, null, throwable);
}
}

@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope onEnter(@Advice.This ActionInvocation actionInvocation) {
return AdviceScope.start(actionInvocation);
}

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

instrumenter().end(context, actionInvocation, null, throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
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;

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

public Struts2InstrumentationModule() {
super("struts", "struts-2.3");
Expand All @@ -23,4 +25,9 @@ public Struts2InstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new ActionInvocationInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute;
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 @@ -46,39 +46,50 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class InvokeActionOnlyAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.This ActionInvocation actionInvocation,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = Java8BytecodeBridge.currentContext();
public static class AdviceScope {
private final Context context;
private final Scope scope;

HttpServerRoute.update(
parentContext,
CONTROLLER,
StrutsServerSpanNaming.SERVER_SPAN_NAME,
actionInvocation.getProxy());
public AdviceScope(Context context, Scope scope) {
this.context = context;
this.scope = scope;
}

if (!instrumenter().shouldStart(parentContext, actionInvocation)) {
return;
@Nullable
public static AdviceScope start(ActionInvocation actionInvocation) {
Context parentContext = Context.current();
HttpServerRoute.update(
parentContext,
CONTROLLER,
StrutsServerSpanNaming.SERVER_SPAN_NAME,
actionInvocation.getProxy());

if (!instrumenter().shouldStart(parentContext, actionInvocation)) {
return null;
}
Context context = instrumenter().start(parentContext, actionInvocation);
return new AdviceScope(context, context.makeCurrent());
}

context = instrumenter().start(parentContext, actionInvocation);
scope = context.makeCurrent();
public void end(ActionInvocation actionInvocation, @Nullable Throwable throwable) {
scope.close();
instrumenter().end(context, actionInvocation, null, throwable);
}
}

@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope onEnter(@Advice.This ActionInvocation actionInvocation) {
return AdviceScope.start(actionInvocation);
}

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

instrumenter().end(context, actionInvocation, 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 Struts2InstrumentationModule extends InstrumentationModule {
public class Struts2InstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public Struts2InstrumentationModule() {
super("struts", "struts-7.0");
Expand All @@ -31,4 +33,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new ActionInvocationInstrumentation());
}

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