I am using nodeJS APM agent with a custom integration, for monitoring incomming UDP data in my application.
I am currently splitting my application, with 2 services in charge of different treatment. I was wondering how can I link the transaction generated in both application into a single trace.
Yes, you can link the two transactions together into one trace by ensuring that you pass on the current traceparent from the outgoing service (service A) and read it again in the receiving service (service B). This happens automatically with HTTP based services, but if you use raw TCP or UDP, you need to pass this information along manually.
I assume you use the agent API to manually start a new transaction in service A. During an active transaction, you can always call agent.currentTraceparent, to get the current traceparent string. You need to send this to service B inside your regular UDP request. Then when you start a new transaction in service B using agent.startTransaction(), you need to pass in the traceparent as a childOf option.
Service A example:
agent.startTransaction('my-service-a-transaction')
const traceparent = agent.currentTraceparent
// Somehow send the traceparent as a "header" to service B
sendMetadata(`traceparent: ${traceparent}\n`)
Service B example:
// Somehow read the traceparent from the incoming request
const traceparent = readTraceparentFromUDPPacket()
// Use the traceparent to initialize the new transaction
agent.startTransaction('my-service-b-transaction', { childOf: traceparent })
// continue program as normal...
Do you advise to use this mechanism inside a single service, where the message could be stored and be dequeud later ? I mean, ending a transaction just before queing the data and beginning a new one at the dequeuing.
I mean that if I add some labels (tags) on my transaction in service A and some others in my transaction in service B, is there a way to display all the labels for the entire trace ? From Elastic point of view, I've got 2 different documents, is it possible to "merge" them in a certain way ?
It should be, if I did well:
Service A (blue one, sad_preprod-eu):
Hi Thanks for using Elastic APM with such an interesting use case.
With respect to this question
When I display the full trace on Kibana, all the traces start at 0ms. Is it the expected behavior ?
Perhaps take a look at this repo, it is Java but I think it is similar, trying to trace across messages and services and get the correct Distributed Trace "Waterfall" result in the UI.
If this this is more your desired behavior I understand there is an issue in the Kibana UI regarding these types of traces starting at 0ms instead of "Following / Waterfall" with the correct timelines.
If so it may be related to
Which appears to be merged as part of this PR
So hopefully that will be part of an soon / upcoming release
Regarding seeing all labels across all transactions in a trace, that's currently not supported and currently not on our roadmap. But I'll take it as a +1 for this feature
@N.Lassimonne if you try my pipeline repo now you should get this result!
Please clone a new copy as I have made some updates.
So now the distributed trace looks like this, I just tested this today with 7.2 the major issue has been fixed, I think there may still be a minor issue but take a look! So you might want to give it a try with your Node.js example
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.