newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
199 stars 143 forks source link

Async Tracing for Scala broken when using Promises #2053

Open jmreardon-yoppworks opened 3 weeks ago

jmreardon-yoppworks commented 3 weeks ago

Description

I am trying to use the Scala instrumentation and asyncTrace to track a transaction in Scala code. One of the Futures is ultimately backed by a Scala Promise that is completed by another thread pool. When I have one of these futures in the chain offlatMaps, subsequent operations are not captured in the transaction.

Similar behavior happens if a Future started outside the transaction is included in the flatMap chain.

(Specifically, the Future is the result of an Akka Stream, but I can reproduce the issue without using Akka).

Expected Behavior

I expect my async traces to work regardless of how the Futures involved in it are created/completed.

Steps to Reproduce

This repository reproduces the issue: https://github.com/jmreardon-yoppworks/new-relic-promises

During my testing I found I could recover the transaction by explicitly linking the transaction with a token, but I needed to nest a Future oddly to make it work.

Your Environment

Mac OS Intel

workato-integration[bot] commented 3 weeks ago

https://new-relic.atlassian.net/browse/NR-314323