dd-trace-java icon indicating copy to clipboard operation
dd-trace-java copied to clipboard

Using akka streams to parallelize requests loses linked traces

Open Marcus-Rosti opened this issue 3 years ago • 3 comments

Trying to make multiple requests to a service. When I do it in a list , the context is preserved and the traces show up in datadog. Whereas if they're done via akka streams, the connection is lost and the traces are still there, but no longer connected to the route.

val reqs: Seq[HttpRequest] = Seq(req1, req2, req3)
val makeRequests: Seq[Future[HttpResponse]] = reqs.map(Http().singleRequest(_))
val completeReqs: Future[Seq[HttpResponse]] = Future.sequence(makeRequests)

works.

whereas

val reqs: Seq[HttpRequest] = Seq(req1, req2, req3)
val completeReqs: Future[Seq[HttpResponse]] = Source(reqs).mapAsync(1)(Http().singleRequest(_)).runWith(Sink.seq)

loses the traces.

Marcus-Rosti avatar Feb 18 '22 00:02 Marcus-Rosti

Hi @Marcus-Rosti - we don't yet support trace propagation over akka-streams, you would need to use manual instrumentation to do that: https://docs.datadoghq.com/tracing/setup_overview/custom_instrumentation/java/#adding-spans

mcculls avatar Feb 18 '22 11:02 mcculls

@mcculls what context would I have to add from the calling threard to actorsystem/materializer to keep the trace?

Marcus-Rosti avatar Feb 24 '22 19:02 Marcus-Rosti

@Marcus-Rosti, have you succeeded with trace propagation over akka-streams? I would appreciate it if you could share anything.

lvitaly avatar Feb 06 '23 15:02 lvitaly