1

I have a requirement where the complete flow of different async requests is related with one trackingId across different services which communicate asynchronously with the help of messages, And I need to have a single traceId for all requests related to one flow or trackingId.

And I am facing issues with getting/setting TraceContext from/into Tracer, I wrote below code but it creates a new traceId for each request.

TraceContext traceContext = (TraceContext) contextMap.get(trackingId);
if (traceContext == null)
{
    tracing.tracer().startScopedSpan(trackingId);
    traceContext = tracing.currentTraceContext().get();
} else
{
    tracing.tracer().startScopedSpanWithParent(trackingId, traceContext);
}

contextMap.put(trackingId, traceContext);
Naresh Joshi
  • 4,188
  • 35
  • 45

1 Answers1

0

I'm not 100% sure what do you want to achieve here, as far as I can understand, what you described is the default behavior, please see the docs.

The tracing context is propagated out of the box, so all the related spans have the same traceId, please see the docs how you can set this up for messaging, there is also a sample project for messaging.

Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • I am aware of that but how you will change traceId for different trackingId and keep it the same for the same trackingId across services. – Naresh Joshi Jan 13 '21 at 04:17
  • I'm not sure I understand this sentence. What do you mean by trackingId? There is traceId and spanId, there's no trackingId. – Jonatan Ivanov Jan 13 '21 at 08:52
  • It is mentioned in the question, I have a requirement where the complete flow of different async requests is related with one trackingId across different services which communicate asynchronously with the help of messages, And I need to have a single traceId for all requests related to one flow or trackingId. – Naresh Joshi Jan 13 '21 at 11:05