Skip to content

Commit

Permalink
Another ClassValue optimization (#4013)
Browse files Browse the repository at this point in the history
* Another ClassValue optimization

* Spotless
  • Loading branch information
trask committed Aug 30, 2021
1 parent c91eda5 commit 436aeaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static void nameResourceAndStartSpan(
@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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
}

0 comments on commit 436aeaf

Please sign in to comment.