LukeMathWalker/tracing-actix-web

Building a Manually Generated Root Span - Separate Thread / No ServiceRequest

chriskyndrid opened this issue · 2 comments

First, thanks for the excellent work on this crate. I'm using it extensively in my project, and it's very helpful.

I have a situation where some of my services have queue processors running in separate threads(and actually separate tokio runtime as well) that loop indefinitely looking for jobs to run. My database model Structs have much of their logic generated from macro's and there are various calls to tracing! events in these derived functions. When these functions are called from a process without the benefit of a root_span, the events show up as a single event in jaeger as I assume because there is no request context to associate a specific loop with a request (or in this case the loop event).

Is there a preferred method of generating a root_span externally, where the root_span itself would not have a request associated with it. Looking at the root_span_macro, I see the the call to:

$crate::root_span_macro::private::set_otel_parent(&$request, &span);

And following that a bit further into set_otel_parent, which is only visible in the tracing crate....

Anyway, I thought I'd inquire to see if there is an approach for this. I realize the purpose of the 'tracing-actix-web' crate includes 'actix-web' and it's sensible for much of the information to be derived from the ServiceRequest. But, I'm looking to leverage existing tools in play for this particular scenario.

Again, thank you for your work and any thoughts are appreciated.

Hi!
I'm afraid this crate is not suited for what you are trying to accomplish, but you can use it as a blueprint/example of what you need to build.
In other words - you need to create your own root span for your background work units and then make sure that it wraps the future where the work is actually happening.

Thank you for the feedback. I was hoping their might be a mechanism to inject a rootspan externally into the crate.

Have a wonderful day!