io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0.ResteasyResourceMethodInvokerInstrumentation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-jaxrs-2.0-resteasy-common Show documentation
Show all versions of opentelemetry-javaagent-jaxrs-2.0-resteasy-common Show documentation
Instrumentation of Java libraries using OpenTelemetry.
The newest version!
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.jboss.resteasy.core.ResourceMethodInvoker;
public class ResteasyResourceMethodInvokerInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher typeMatcher() {
return named("org.jboss.resteasy.core.ResourceMethodInvoker");
}
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("invokeOnTarget")
.and(takesArgument(0, named("org.jboss.resteasy.spi.HttpRequest")))
.and(takesArgument(1, named("org.jboss.resteasy.spi.HttpResponse")))
.and(takesArgument(2, Object.class)),
ResteasyResourceMethodInvokerInstrumentation.class.getName() + "$InvokeOnTargetAdvice");
}
@SuppressWarnings("unused")
public static class InvokeOnTargetAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(@Advice.This ResourceMethodInvoker resourceInvoker) {
String name =
VirtualField.find(ResourceMethodInvoker.class, String.class).get(resourceInvoker);
ResteasySpanName.INSTANCE.updateServerSpanName(Java8BytecodeBridge.currentContext(), name);
}
}
}