Last active
August 29, 2015 14:02
-
-
Save vijaykramesh/b2eef9e79ed182b31bdc to your computer and use it in GitHub Desktop.
NewRelic transaction naming for Dropwizard
This file contains hidden or 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
public class TimedResourceMethodDispatchProvider implements ResourceMethodDispatchProvider { | |
final ResourceMethodDispatchProvider provider; | |
public TimedResourceMethodDispatchProvider(ResourceMethodDispatchProvider provider) { | |
this.provider = provider; | |
} | |
@Override | |
public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod) { | |
RequestDispatcher dispatcher = provider.create(abstractResourceMethod); | |
Timed timed = abstractResourceMethod.getAnnotation(Timed.class); | |
if (timed != null) { | |
String resourceName = abstractResourceMethod.getResource().getResourceClass().getSimpleName(); | |
String methodName = abstractResourceMethod.getMethod().getName(); | |
return new TimedRequestDispatcher(dispatcher, resourceName + "/" + methodName); | |
} | |
return dispatcher; | |
} | |
} | |
public class TimedResourceMethodDispatchAdapter implements ResourceMethodDispatchAdapter { | |
public TimedResourceMethodDispatchAdapter() { } | |
@Override | |
public ResourceMethodDispatchProvider adapt(ResourceMethodDispatchProvider provider) { | |
return new TimedResourceMethodDispatchProvider(provider); | |
} | |
} | |
public class TimedRequestDispatcher implements RequestDispatcher { | |
final RequestDispatcher dispatcher; | |
final String transactionName; | |
public TimedRequestDispatcher(RequestDispatcher dispatcher, String transactionName) { | |
this.dispatcher = dispatcher; | |
this.transactionName = transactionName; | |
} | |
@Override | |
public void dispatch(Object resource, HttpContext context) { | |
NewRelic.setTransactionName(null, transactionName); | |
dispatcher.dispatch(resource, context); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, does NewRelic.setTransactionName rely on ThreadLocal? I am guessing it does and hence won't work out of the box with non-blocking/multithreaded code (e.g. LinkedIn ParSeq or Netflix Hystrix).
But I might be wrong.