Skip to content

Distributed Tracing

Cleary, Paul edited this page Nov 9, 2015 · 1 revision

Money supports tracing across distributed systems by passing a trace context in a custom HTTP Header.

The header takes the form:

X-MoneyTrace: trace-id=%s;parent-id=%s;span-id=%s

  • trace-id - this is the unique id for the entire trace. If a single trace is sent down 10 different systems, generating 50 unique trace spans, they will all share the same TraceId. This is the origin, or root, of the trace tree.
  • parent-id - this is the direct ancestor of the current trace span
  • span-id - or "Self", this is the identifier for the current trace span that is in context

Note: Each ID must be a unique random LONG, so the entire trace span identifier consists of 3 unique LONGs. We use a Random Long for each of the IDs. While there maybe collision, the likelihood of all three IDs being repeated within the same time window is very small. This keeps the overhead of generating and passing the values to a minimum

The following example uses simple numbers for demonstration purposes. A "real" example of a trace header would look like "X-MoneyTrace: trace-id=-931713569499083109;parent-id=-5722794285453614155;span-id=1898818534231861520"

In the above example, you can see the first system making an HTTP Request to a second system, and the second system in turn makes a request to a third system. On each HTTP Request, we have the custom X-MoneyTrace header:

  • The first system passes the ID as X-MoneyTrace: trace-id=10;parent-id=21;span-id=32. The TraceId is 10, that will be the same for the entire trace. The ParentId is 21, which is the direct parent span. The SpanId is 32, and that is the current span that is in context when the HTTP request is made to the second system.
  • The second system calls a third system as part of the same trace, using the ID X-MoneyTrace: trace-id=10;parent-id=32;span-id=74. The TraceId is the same that was passed from the first system (10). The ParentId is the SpanId of the trace header that was passed to the second system (32). The SpanId is a new id that was generated for the new HTTP Request going to the third system.