I am migrating a Scala Play application to Dropwizard 1.0 using asynchronous Jersey back-end endpoints (using @Suspended AsyncResponse). Almost everything is running in a Future - DB calls (Slick 2.x), API calls to other services, etc. I’m using the 3.26.1 agent.
When it was running in Play, the agent was able to track the async activity just fine, but in the new framework New Relic reports clumps most of the processing under “AsyncProcessing”.
In hopes of improving granularity of reporting, I’ve made a custom ExecutionContext which allows me to wrap the async Future calls in my own logic, and I’m able to pass context from one thread to the next just fine, but I can’t find a way to help New Relic follow the chain of events.
For example, in the documentation for the @Trace asyc=true attribute, it says this should be possible:
“The user implicitly promises to register the object implementing traced method from within some existing New Relic Transaction before invoking the method and then to call the Transaction.startAsyncActivity API as the first action of the traced method.”
Unfortunately there is no “startAsyncActivity” method in the Transaction class, and I don’t see any reference to async in any of the other classes in the agent JAR.
Here’s how I would expect it to work, but the agent API seems to be missing some pieces.
- When I’m about to queue up work on a background thread, I can call NewRelic.getAgent.getTransaction to remember which transaction was active.
- When the background thread starts up, I’d like to call some kind of agent API like resumeTransaction and pass in the transaction that I know I belong to.
- When the background thread finishes, I’d like to call some kind of agent API like suspendTransaction to let it know that any work this thread does later does not belong to my original transaction.
I have seen other examples online where they mention a method registerAsyncActivity but that doesn’t seem to exist in the Transaction class in 3.26.1.
I’m able to track all the background work myself but am simply not able to help New Relic connect the dots.
Is there something I’m missing, that would allow me to reconnect a new thread (Future) to a transaction that was started on a prior thread?