Created
January 9, 2017 04:17
-
-
Save carey/0b4e0d0222a4cb2e4df8ecfdab41cc03 to your computer and use it in GitHub Desktop.
See Spring 2 controller names in New Relic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import org.springframework.util.ClassUtils; | |
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |
import org.springframework.web.servlet.mvc.Controller; | |
/** | |
* Sets a request attribute for New Relic if the current handler is uses the old | |
* Spring {@link Controller}-based handlers. | |
* | |
* @author Carey Evans | |
*/ | |
public class NewRelicControllerNameInterceptor extends HandlerInterceptorAdapter { | |
@Override | |
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | |
if (handler instanceof Controller) { | |
request.setAttribute("com.newrelic.agent.TRANSACTION_NAME", ClassUtils.getShortName(handler.getClass())); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment