Another ClassValue optimization (#4013)

* Another ClassValue optimization

* Spotless
This commit is contained in:
Trask Stalnaker 2021-08-30 09:02:59 -07:00 committed by GitHub
parent c91eda59b5
commit 436aeaf99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -8,6 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc;
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.implementsInterface;
import static io.opentelemetry.javaagent.instrumentation.springwebmvc.IsGrailsHandler.isGrailsHandler;
import static io.opentelemetry.javaagent.instrumentation.springwebmvc.SpringWebMvcSingletons.handlerInstrumenter;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -60,7 +61,7 @@ public class HandlerAdapterInstrumentation implements TypeInstrumentation {
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
// 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
return;
}

View File

@ -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() {}
}