Skip to content

Commit

Permalink
Use class literals where possible (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Mar 31, 2021
1 parent 9a5c652 commit 97d58d7
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
.and(named("loadClass"))
.and(
takesArguments(1)
.and(takesArgument(0, named("java.lang.String")))
.and(takesArgument(0, String.class))
.or(
takesArguments(2)
.and(takesArgument(0, named("java.lang.String")))
.and(takesArgument(1, named("boolean")))))
.and(takesArgument(0, String.class))
.and(takesArgument(1, boolean.class))))
.and(isPublic().or(isProtected()))
.and(not(isStatic())),
ClassLoaderInstrumentation.class.getName() + "$LoadClassAdvice");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand Down Expand Up @@ -52,7 +53,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
.and(
takesArgument(
0, named("com.couchbase.client.deps.io.netty.channel.ChannelHandlerContext")))
.and(takesArgument(2, named("java.util.List"))),
.and(takesArgument(2, List.class)),
CouchbaseNetworkInstrumentation.class.getName() + "$CouchbaseNetworkAdvice");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
isMethod()
.and(namedOneOf("performRequestAsync", "performRequestAsyncNoCatch"))
.and(takesArguments(7))
.and(takesArgument(0, named("java.lang.String"))) // method
.and(takesArgument(1, named("java.lang.String"))) // endpoint
.and(takesArgument(0, String.class)) // method
.and(takesArgument(1, String.class)) // endpoint
.and(takesArgument(5, named("org.elasticsearch.client.ResponseListener"))),
Elasticsearch5RestClientInstrumentationModule.class.getName()
+ "$ElasticsearchRestClientAdvice");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
map.put(
isMethod()
.and(named("existsValue").or(named("query")).or(named("selectValue")))
.and(takesArgument(0, named("java.lang.String"))),
.and(takesArgument(0, String.class)),
GeodeInstrumentationModule.class.getName() + "$QueryAdvice");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -68,7 +69,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
.and(isPublic())
.and(named("executeAsync"))
.and(takesArguments(1))
.and(takesArgument(0, (named("java.util.concurrent.Executor")))),
.and(takesArgument(0, Executor.class)),
GoogleHttpClientInstrumentationModule.class.getName() + "$GoogleHttpClientAsyncAdvice");

return transformers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
.and(isPrivate())
.and(named("notifyFailure"))
.and(takesArgument(0, named("org.glassfish.grizzly.filterchain.FilterChainContext")))
.and(takesArgument(1, named("java.lang.Throwable"))),
.and(takesArgument(1, Throwable.class)),
DefaultFilterChainAdvice.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor

// Handle the non-generic 'get' separately.
transformers.put(
isMethod()
.and(named("get"))
.and(returns(named("java.lang.Object")))
.and(takesArgument(0, named("java.lang.String"))),
isMethod().and(named("get")).and(returns(Object.class)).and(takesArgument(0, String.class)),
SessionInstrumentation.class.getName() + "$SessionMethodAdvice");

// These methods return some object that we want to instrument, and so the Advice will pin the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
SessionInstrumentation.class.getName() + "$SessionMethodAdvice");
// Handle the non-generic 'get' separately.
transformers.put(
isMethod()
.and(named("get"))
.and(returns(named("java.lang.Object")))
.and(takesArgument(0, named("java.lang.String"))),
isMethod().and(named("get")).and(returns(Object.class)).and(takesArgument(0, String.class)),
SessionInstrumentation.class.getName() + "$SessionMethodAdvice");

// These methods return some object that we want to instrument, and so the Advice will pin the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
named("handle")
.and(takesArgument(0, named("java.lang.String")))
.and(takesArgument(0, String.class))
.and(takesArgument(1, named("org.eclipse.jetty.server.Request")))
.and(takesArgument(2, named("javax.servlet.http.HttpServletRequest")))
.and(takesArgument(3, named("javax.servlet.http.HttpServletResponse")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
isMethod()
.and(not(isAbstract()))
.and(named("request"))
.and(takesArgument(0, named("java.lang.String")))
.and(takesArgument(1, named("java.lang.String")))
.and(takesArgument(2, named("java.util.Map")))
.and(takesArgument(0, String.class))
.and(takesArgument(1, String.class))
.and(takesArgument(2, Map.class))
.and(returns(named("khttp.responses.Response"))),
KHttpAdvice.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -35,15 +36,15 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
transformers.put(
isMethod()
.and(named("createMono"))
.and(takesArgument(0, named("java.util.function.Supplier")))
.and(takesArgument(0, Supplier.class))
.and(returns(named("reactor.core.publisher.Mono"))),
LettuceMonoCreationAdvice.class.getName());
transformers.put(
isMethod()
.and(nameStartsWith("create"))
.and(nameEndsWith("Flux"))
.and(isPublic())
.and(takesArgument(0, named("java.util.function.Supplier")))
.and(takesArgument(0, Supplier.class))
.and(returns(named("reactor.core.publisher.Flux"))),
LettuceFluxCreationAdvice.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
isMethod()
.and(named("invoke"))
.and(takesArgument(0, named("java.rmi.Remote")))
.and(takesArgument(1, named("java.lang.reflect.Method"))),
.and(takesArgument(1, Method.class)),
RmiClientInstrumentationModule.class.getName() + "$RmiClientAdvice");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
.and(isPublic())
.and(named("handle"))
.and(takesArgument(0, named("org.springframework.web.server.ServerWebExchange")))
.and(takesArgument(1, named("java.lang.Object")))
.and(takesArgument(1, Object.class))
.and(takesArguments(2)),
HandlerAdapterAdvice.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
isConstructor().and(takesArgument(0, named("io.vertx.core.Handler"))),
VertxRxInstrumentationModule.class.getName() + "$AsyncResultSingleHandlerAdvice");
result.put(
isConstructor().and(takesArgument(0, named("java.util.function.Consumer"))),
isConstructor().and(takesArgument(0, Consumer.class)),
VertxRxInstrumentationModule.class.getName() + "$AsyncResultSingleConsumerAdvice");
return result;
}
Expand Down

0 comments on commit 97d58d7

Please sign in to comment.