Closed rodoufu closed 1 year ago
I didn't look very closely at code, but I think you need to send SpanContext
together with messages.
Something like this.
For sender:
sender.send((msg, cx.span().span_context().clone())
For reciever:
while let((msg, span_context)) reciever.next() {
let parent_cx = Context::current().with_remote_span_context(span_context);
let cx = cx.with_span(create_new_span_with_parent_cx(parent_cx));
...
}
P.S. I'm not proficient with this, so I might be wrong, but this approach worked for me
P.P.S. Note, that you don't have to add with_context
on every future. You must only add it on "leaf-futures" (leaf future is basically any future that explicitly implements Future trait, non-leaf future is the one, generated by compiler from when you have async fn
)
The reasoning is that compiler generated futures will always run until it actually reaches leaf-future, in this case you need preserve contexts in case leaf future returns Pending
. In practice this means, that if you abstract all real async calls (actix, reqwest, tonic, etc...), then inside your "domain logic" you can forget about with_context
for the most part (except in hopefully rare cases where you use join, select, delay, etc... from futures or tokio crates, but for production -grade application you probably abstract those as well)
In addition to what @fraillt mentioned, I would also recommend not having the root
span that lives for the entire lifetime of the program. Jaeger cannot show spans before they have ended, so all children of that span will have a missing parent.
Closing for now, feel free to re-open if you run into more issues.
When I check the span in jeager I only get
process_orderbook_operation
, shouldn't it beroot
with a childprocess_orderbook
then its childprocess_orderbook_operation
. Also the spanprocess_orderbook_operation
have an warning sayinginvalid parent span IDs=83bedcedd0ebd940; skipping clock skew adjustment
I have the code that I adapted from https://github.com/open-telemetry/opentelemetry-rust/blob/main/examples/async/src/main.rs the full code is available at https://github.com/rodoufu/top-book