0
votes

I'm trying out the .Net agent in Elastic APM and I'm using a C# application which is created using a framework called ASP.net Boilerplate. I've added the core libraries as mentioned in the documentation and added the settings in appsettings.json. This enables the default instrumentation and I got traces in the APM visualized through Kibana.

Currently I've got a node.js application running and I publish a message to a RabbitMQ queue with the traceparent in the message payload. The C# app reads the published message. I need to create a transaction or span using this traceparent / trace id so that Kibana would show the trace among the distributed systems.

I want to know if there is a way to create a transaction (or span) using a traceparent that is being sent from another system not using a HTTP protocol. I've checked the Elastic APM agent documentation -> Public API for information but couldnt find any information on this. Is there a way? Thanks.

2

2 Answers

1
votes

I want to know if there is a way to create a transaction (or span) using a traceparent that is being sent from another system not using a HTTP protocol.

Yes, this is possible and there is an API for it. This part of the documentation explains it.

So you'll need to do this when you start your transaction - I imagine in your scenario this will be when you read a message from RabbitMQ.

When you start the transaction there is an optional parameter called distributedTracingData - if you pass it, then the transaction will reuse the traceid which you passed through RabbitMQ, and this way the new transaction will be part of the whole trace. If you don't pass this parameter, a new traceid will be generated and a new trace will be started.

Another comment that may help: you pass the trace id into the method where you start the transaction and each span will inherit this trace id within a transaction - so you control this on the transaction level and accordingly you don't pass it into a span.

Here is a small code snippet on how this would look:

serializedDistributedTracingData = //read this from the message which you get RabbitMq

var transaction2 = Agent.Tracer.StartTransaction("RadFromQueue", "RabbitMQRead",
     DistributedTracingData.TryDeserializeFromString(serializedDistributedTracingData));
1
votes

@gregkalapos, again thank you for the information. I checked how to acquire the neccessary trace information as in node.js agent documentation and when I debugged noticed that it was the trace id. Next in the C# consumer end I placed a code snippet as mentioned in the .Net agent and gave it a run. Kibana displayed the transactions from two different services in a single trace as I hoped it would.