envoyproxydistributed-tracing

Why do we need to initiate Tracing in Envoy as it has had x-request-id


I just read the doc of Envoy about Tracing but I'm confused by how it works.

The doc says:

How to initiate a trace

The HTTP connection manager that handles the request must have the tracing object set. There are several ways tracing can be initiated:

  • By an external client via the x-client-trace-id header.
  • By an internal service via the x-envoy-force-trace header.
  • Randomly sampled via the random_sampling runtime setting.

As my understanding, Envoy would generate x-request-id for each request. If so, why do we still need to use x-client-trace-id or x-envoy-force-trace to initiate a trace? Isn't x-request-id enough?

Besides, as my understanding, x-request-id is used as the traceid. Am I right? If I'm right, I kind of don't understand how Tracing works because a call flow may have more than one Envoy, if each Envoy generates its own x-request-id, how could we trace a request because its traceid can be changed. Here is an example:

client ---> Envoy(generate a x-request-id) ---> server1 ---> Envoy(generate another x-request-id) ---> server2.

As you see, one request can have different x-request-ids in one flow. In this case, how could it be traced?

I've read the doc of Envoy but I still can't figure out how Tracing works.


Solution

  • Besides, as my understanding, x-request-id is used as the traceid. Am I right?

    This understanding is wrong.

    request-id and trace-id is totally different thing (Created for different purpose.).

    request-id is issued per request and each value is different, but trace-id is the same value per trace.

    https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-client-trace-id says

    as of 2024-03-14

    If an external client sets this header, Envoy will join the provided trace ID with the internally generated x-request-id. x-client-trace-id needs to be globally unique and generating a uuid4 is recommended. If this header is set, it has similar effect to x-envoy-force-trace. See the tracing.client_enabled runtime configuration setting.

    If I visualize what is said,

    
    external client =(trace_id := x-client-trace-id) =>
     Envoy =(traced_id, x-request-id A) => 
     server1 =(trace_id, x-request-id B)=> 
     Envoy =(trace_id, x-request-id C) =>
     ...
    

    this is my understanding, although I didn't actually checked by running Envoy.