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);