tracing-actix-web icon indicating copy to clipboard operation
tracing-actix-web copied to clipboard

How to send trace id to user for debugging?

Open npuichigo opened this issue 2 years ago • 2 comments

Hi @LukeMathWalker, I'm a reader of your zero-to-production book and interested in telemetry with trace id to handle production debugging. I run the opentelemetry example in this repo, but I have no idea how to use the trace id for debugging.

I think the process would be:

  1. the service response includes the trace id for user.
  2. Once the user faces an error, he/she can tell me the trace id
  3. I can search the provided trace id in Jaeger to find the invocation.

I don't know if I misunderstand the use case.

npuichigo avatar Nov 01 '23 06:11 npuichigo

Hey!

You can get the trace id that's associated with the current span using tracing-opentelemetry.
If you do it from a middleware, you can then inject it into the response (e.g. as a header).

LukeMathWalker avatar Nov 01 '23 07:11 LukeMathWalker

@LukeMathWalker Thanks for this tracing Library. I am wondering wouldn't it be better to have the middleware automatically injected the RequestId in the response Header. Imagine we have 20 web endpoints. And for each of them, we may have if conditions that's returning different types of Responses with different HttpError codes. It's very cumbersome to manually inject it for each of these scenarios. I am wondering please, if you could inject it automatically in the response header similarly to a crate that does it for Actix Web: https://crates.io/crates/actix-request-identifier

this crate above just inserts an "X-Request-Id". Couldn't you do the same please in a pull request? This will make developer experience greater using it and its debugging life much simpler. Thanks image

douggynix avatar May 31 '24 05:05 douggynix