spandex-project / spandex

A platform agnostic tracing library
MIT License
335 stars 53 forks source link

[Question] current_trace_id and current_span_id are returning nil #138

Open kurt-bautista opened 2 years ago

kurt-bautista commented 2 years ago

I was able to set up spandex+spandex_phoenix+spandex_datadog correctly I think, as I'm able to see traces in Datadog

I am now trying to set up distributed tracing, but when I call MyApp.Tracer.current_trace_id so I can pass the correct headers, I get nil. Any ideas on why that is? Thanks in advance :)

GregMefford commented 2 years ago

It should be spandex_phoenix that initiates a span, either using the Telemetry hooks that Phoenix emits, or by putting use SpandexPhoenix in your Router or Endpoint module, depending on how you want it to work. The current span context is stored in the Process Dictionary, so if you cross a BEAM process boundary (e.g. Task.async or GenServer.call), you will have to manually pass that somehow across the boundary to continue the trace in the downstream process, similar to if it has been an RPC call to another microservice.

Without knowing more specifics, that's my best guess about what's going on, but let me know if that rings a bell for you or if you have more details you can share.

kurt-bautista commented 2 years ago

Yup that was it, we had a couple of async calls. Follow up question though, our application makes extensive use of LiveViews. Is there any way we could start/continue the trace through those? Or would we have to manually start a new trace/pass the span context to every LiveView? Would making use of an ETS strategy help us in any way?