Use namedOneOf instead of joining two named matchers (#11495)

This commit is contained in:
Steve Rao 2024-05-31 04:16:35 +08:00 committed by GitHub
parent 687bf2dedf
commit 6a11e50a7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 24 additions and 16 deletions

View File

@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.akkahttp.client;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import io.opentelemetry.context.Scope;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
@ -25,8 +26,9 @@ public class PoolMasterActorInstrumentation implements TypeInstrumentation {
public void transform(TypeTransformer transformer) {
// scala compiler mangles method names
transformer.applyAdviceToMethod(
named("akka$http$impl$engine$client$PoolMasterActor$$startPoolInterface")
.or(named("akka$http$impl$engine$client$PoolMasterActor$$startPoolInterfaceActor")),
namedOneOf(
"akka$http$impl$engine$client$PoolMasterActor$$startPoolInterface",
"akka$http$impl$engine$client$PoolMasterActor$$startPoolInterfaceActor"),
ClearContextAdvice.class.getName());
}

View File

@ -8,6 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.grizzly;
import static io.opentelemetry.javaagent.instrumentation.grizzly.GrizzlySingletons.instrumenter;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.context.Context;
@ -36,9 +37,10 @@ public class HttpCodecFilterInstrumentation implements TypeInstrumentation {
takesArgument(
1,
// this is for 2.3.20+
named("org.glassfish.grizzly.http.HttpHeader")
namedOneOf(
"org.glassfish.grizzly.http.HttpHeader",
// this is for 2.3 through 2.3.19
.or(named("org.glassfish.grizzly.http.HttpPacketParsing"))))
"org.glassfish.grizzly.http.HttpPacketParsing")))
.and(isPublic()),
HttpCodecFilterInstrumentation.class.getName() + "$HandleReadAdvice");
}

View File

@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v4_0;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import com.lambdaworks.redis.protocol.AsyncCommand;
import io.opentelemetry.context.Context;
@ -31,7 +32,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
transformer.applyAdviceToMethod(
isConstructor(), LettuceAsyncCommandInstrumentation.class.getName() + "$SaveContextAdvice");
transformer.applyAdviceToMethod(
named("complete").or(named("completeExceptionally")).or(named("cancel")),
namedOneOf("complete", "completeExceptionally", "cancel"),
LettuceAsyncCommandInstrumentation.class.getName() + "$RestoreContextAdvice");
}

View File

@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v5_0;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import io.lettuce.core.protocol.AsyncCommand;
import io.opentelemetry.context.Context;
@ -31,7 +32,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
transformer.applyAdviceToMethod(
isConstructor(), LettuceAsyncCommandInstrumentation.class.getName() + "$SaveContextAdvice");
transformer.applyAdviceToMethod(
named("complete").or(named("completeExceptionally")).or(named("cancel")),
namedOneOf("complete", "completeExceptionally", "cancel"),
LettuceAsyncCommandInstrumentation.class.getName() + "$RestoreContextAdvice");
}

View File

@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import io.lettuce.core.protocol.AsyncCommand;
import io.opentelemetry.context.Context;
@ -31,7 +32,7 @@ public class LettuceAsyncCommandInstrumentation implements TypeInstrumentation {
transformer.applyAdviceToMethod(
isConstructor(), LettuceAsyncCommandInstrumentation.class.getName() + "$SaveContextAdvice");
transformer.applyAdviceToMethod(
named("complete").or(named("completeExceptionally")).or(named("cancel")),
namedOneOf("complete", "completeExceptionally", "cancel"),
LettuceAsyncCommandInstrumentation.class.getName() + "$RestoreContextAdvice");
}

View File

@ -9,6 +9,7 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.returns;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@ -40,14 +41,14 @@ public abstract class AbstractNettyChannelPipelineInstrumentation implements Typ
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod()
.and(named("remove").or(named("replace")))
.and(namedOneOf("remove", "replace"))
.and(takesArgument(0, named("io.netty.channel.ChannelHandler"))),
AbstractNettyChannelPipelineInstrumentation.class.getName() + "$RemoveAdvice");
transformer.applyAdviceToMethod(
isMethod().and(named("remove").or(named("replace"))).and(takesArgument(0, String.class)),
isMethod().and(namedOneOf("remove", "replace")).and(takesArgument(0, String.class)),
AbstractNettyChannelPipelineInstrumentation.class.getName() + "$RemoveByNameAdvice");
transformer.applyAdviceToMethod(
isMethod().and(named("remove").or(named("replace"))).and(takesArgument(0, Class.class)),
isMethod().and(namedOneOf("remove", "replace")).and(takesArgument(0, Class.class)),
AbstractNettyChannelPipelineInstrumentation.class.getName() + "$RemoveByClassAdvice");
transformer.applyAdviceToMethod(
isMethod().and(named("removeFirst")).and(returns(named("io.netty.channel.ChannelHandler"))),

View File

@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.okhttp.v3_0;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.context.Context;
@ -29,8 +30,7 @@ public class OkHttp3DispatcherInstrumentation implements TypeInstrumentation {
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("enqueue")
.or(named("enqueue$okhttp"))
namedOneOf("enqueue", "enqueue$okhttp")
.and(takesArgument(0, implementsInterface(named(Runnable.class.getName())))),
OkHttp3DispatcherInstrumentation.class.getName() + "$AttachStateAdvice");
}

View File

@ -9,6 +9,7 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
@ -28,7 +29,7 @@ public class SystemInfoInstrumentation implements TypeInstrumentation {
isMethod()
.and(isPublic())
.and(isStatic())
.and(named("getCurrentPlatformEnum").or(named("getCurrentPlatform"))),
.and(namedOneOf("getCurrentPlatformEnum", "getCurrentPlatform")),
this.getClass().getName() + "$GetCurrentPlatformEnumAdvice");
}

View File

@ -8,6 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.ratpack;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.context.Scope;
@ -30,9 +31,7 @@ public class DefaultExecStarterInstrumentation implements TypeInstrumentation {
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("onComplete")
.or(named("onError"))
.or(named("onStart"))
namedOneOf("onComplete", "onError", "onStart")
.and(takesArgument(0, named("ratpack.func.Action"))),
DefaultExecStarterInstrumentation.class.getName() + "$WrapActionAdvice");
transformer.applyAdviceToMethod(