AsyncProcessing with KTor and Coroutines

I am messing around with KTor and Coroutines. Based on the code if found from Marshall Pierce I was able to get transactions traced and named in New Relic, but it was missing the link to the automatically detected Jetty transactions (agent feature).

I figured I could get that working and ended up with a hack, basically duplicating JettyKtorHandler from KTor and adding tokens+linking. I know, not nice. But I was really hoping to get this working. And I am sooooo close… :stuck_out_tongue_winking_eye:

With this in place I am getting:

  • Single transactions reported per request
  • The correct naming of the transaction
  • Full trace of all the operations performed

BUT: New Relic is getting “double” time per request reported. The “real” time with the trace of the operations performed plus a section (matching the size) that just says “AsyncProcessing”. I have tried with a bunch of combinations of @Trace(async=true/false, dispatch=true/false) but honestly getting a bit lost.

Anyone that has seen similar behaviour and/or can help me pinpoint what is going on here? Since I am getting “one” transaction I know the linking across Coroutines are working, I am just seeing double time…

Hello anderssv.ztl,

Usually, when you see the over-exaggerated time, it would usually mean that the custom instrumentation you are using isn’t being placed in the correct places in your code. This will lead the agent to end the transaction tracing at the wrong time for the transaction. When it comes to coroutines, you would usually want to look for an invokeOnCompletion method that’s used by the framework and expire the token there.

Didn’t help if I tried to move the .expire() call around. Seems the whole “bulk” of the AsyncProcessing came in before my code (probably somewhere in the Jetty agent integration). I just ended up disabling the Jetty agent feature again and limiting to measuring the parts of the call we can control in KTor. Thanks anyway. :slight_smile:

Thanks for letting us know your workaround @anderssv.ztl!