Another ClassValue optimization (#4013)
* Another ClassValue optimization * Spotless
This commit is contained in:
parent
c91eda59b5
commit
436aeaf99a
|
@ -8,6 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc;
|
||||||
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER;
|
import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER;
|
||||||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
|
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
|
||||||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
|
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
|
||||||
|
import static io.opentelemetry.javaagent.instrumentation.springwebmvc.IsGrailsHandler.isGrailsHandler;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.springwebmvc.SpringWebMvcSingletons.handlerInstrumenter;
|
import static io.opentelemetry.javaagent.instrumentation.springwebmvc.SpringWebMvcSingletons.handlerInstrumenter;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
|
@ -60,7 +61,7 @@ public class HandlerAdapterInstrumentation implements TypeInstrumentation {
|
||||||
@Advice.Local("otelContext") Context context,
|
@Advice.Local("otelContext") Context context,
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
@Advice.Local("otelScope") Scope scope) {
|
||||||
// TODO (trask) should there be a way to customize Instrumenter.shouldStart()?
|
// TODO (trask) should there be a way to customize Instrumenter.shouldStart()?
|
||||||
if (handler.getClass().getName().startsWith("org.grails.")) {
|
if (isGrailsHandler(handler)) {
|
||||||
// skip creating handler span for grails, grails instrumentation will take care of it
|
// skip creating handler span for grails, grails instrumentation will take care of it
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.springwebmvc;
|
||||||
|
|
||||||
|
public final class IsGrailsHandler {
|
||||||
|
|
||||||
|
private static final ClassValue<Boolean> cache =
|
||||||
|
new ClassValue<Boolean>() {
|
||||||
|
@Override
|
||||||
|
protected Boolean computeValue(Class<?> type) {
|
||||||
|
return type.getName().startsWith("org.grails.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean isGrailsHandler(Object handler) {
|
||||||
|
return cache.get(handler.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IsGrailsHandler() {}
|
||||||
|
}
|
Loading…
Reference in New Issue