The trace library (common/trace.h) has a weird suspend API.
Starting from a clean context every newly created span is added to a current stack of spans.
Closing the top span removes it from the stack.
Then there is also a suspend function that removes the top element from the stack but it doesn't close it, allowing
to track concurrent spans with a shared parent.
This API is awkward to use with trace spans in plugins that live beyond one iteration of the io loop.
See for example #9137: adding traces to xpay we had to suspend the entire trace stack before handing control back
to the io loop and when we needed to modify the stack we had to bring it back entirely again element by element.
For example to add a new stack element on top of the payment span:
// global current trace is assumed to be NULL
// we get control back from the io loop, we resume the current payment
+ trace_span_resume(attempt->payment); // payment is the parent span
// start a new sub-trace for the rpc
+ trace_span_start("xpay/injectpaymentonion", attempt);
// before we hand control back to the io loop, we unwind the trace stack
+ trace_span_suspend(attempt);
+ trace_span_suspend(attempt->payment);
// global current trace is back to NULL
and to remove one
// global current trace is assumed to be NULL
// we get control back from the io loop, we resume the current payment
+ trace_span_resume(attempt->payment);
// also resume the trace of the RPC call
+ trace_span_resume(attempt);
// end the RPC trace
+ trace_span_end(attempt);
// again unwind the rest of the trace stack with only one element
+ trace_span_suspend(attempt->payment);
// global current trace is back to NULL
There are many footguns here.
I think it would be better if "suspend" would suspend the entire stack and we had a "suspend one" function for the top element alone.
While "resume x" brings back the entire stack with x on top.
The current suspend semantics was probably introduced in #8223
The trace library (
common/trace.h) has a weird suspend API.Starting from a clean context every newly created span is added to a current stack of spans.
Closing the top span removes it from the stack.
Then there is also a suspend function that removes the top element from the stack but it doesn't close it, allowing
to track concurrent spans with a shared parent.
This API is awkward to use with trace spans in plugins that live beyond one iteration of the io loop.
See for example #9137: adding traces to xpay we had to suspend the entire trace stack before handing control back
to the io loop and when we needed to modify the stack we had to bring it back entirely again element by element.
For example to add a new stack element on top of the payment span:
and to remove one
There are many footguns here.
I think it would be better if "suspend" would suspend the entire stack and we had a "suspend one" function for the top element alone.
While "resume x" brings back the entire stack with x on top.
The current suspend semantics was probably introduced in #8223