Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another ClassValue optimization #4013

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
}