in apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/main/java/co/elastic/apm/agent/springwebmvc/AbstractSpringTransactionNameInstrumentation.java [107:156]
public static <HttpServletRequest> void updateTransactionNameFromHandler(ServletRequestAdapter<HttpServletRequest, ?> adapter, HttpServletRequest request, Object handler) {
final Transaction<?> transaction = tracer.currentTransaction();
if (transaction == null) {
return;
}
final String className;
final String methodName;
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = ((HandlerMethod) handler);
className = handlerMethod.getBeanType().getSimpleName();
methodName = handlerMethod.getMethod().getName();
} else {
className = handler.getClass().getSimpleName();
methodName = null;
}
if (!className.isEmpty() && methodName != null) {
TransactionNameUtils.setNameFromClassAndMethod(
className,
methodName,
transaction.getAndOverrideName(PRIORITY_HIGH_LEVEL_FRAMEWORK)
);
} else if (webConfig.isUsePathAsName()) {
// When method name or class name are not known, we treat the calculated name as a fallback only, thus using lower priority.
// If delegating to a Servlet, this still allows the better servlet naming default.
TransactionNameUtils.setNameFromHttpRequestPath(
adapter.getMethod(request),
adapter.getServletPath(request),
adapter.getPathInfo(request),
transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK + 1),
webConfig.getUrlGroups()
);
} else if (!className.isEmpty()) {
// if we are here, then method name is null, thus using lower priority
TransactionNameUtils.setNameFromClassAndMethod(
className,
methodName,
transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK + 1)
);
} else {
// Class name is empty - probably an anonymous handler class
StringBuilder transactionName = transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK + 1);
if (transactionName != null) {
transactionName.append(adapter.getMethod(request)).append(" unknown route");
}
}
transaction.setFrameworkName(FRAMEWORK_NAME);
transaction.setFrameworkVersion(VersionUtils.getVersion(HandlerMethod.class, "org.springframework", "spring-web"));
}