0

If a user calls service A, and service A then calls service B, tracing is simple using the correlation ID.

Now if service A calls service B multiple times, the same correlationID gets used for each of those calls, which makes tracing slightly tricky.

Is there any way to handle this?

Jerald Baker
  • 1,121
  • 1
  • 12
  • 48

1 Answers1

2

This task can be solved by adding some context information to your traces. Whole trace should have a single ID, let's name it TraceID. Is should be generated once, when the first request started execution, and added to trace context to be propagated to all child requests in a chain. Each subsequent call in a distributed request should have additional identifier, let's name it SpanID (it is also known as ActivityID is some systems). SpanID should be generated by each service individually for each request or inbound message. And finally, the parent SpanID simply named as ParentID should be stored in context to keep track of a parent request. The combination of a TraceID and ParentID can uniquely identify the parent request globally, regardless of what process it executed in. enter image description here

Here is a W3C standard describing HTTP headers and value format of distributed trace context: https://www.w3.org/TR/trace-context/. In accordance to specification, trace header named traceparent is composed by 4 fields: version - traceid - parentid/spanid - traceflags.

For example: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00

W3C trace context spec has ready to use implementations for commonly used languages, such as Java, .NET, Python and others.

Anthony
  • 500
  • 3
  • 14