Here you capture the current span in the constructor, but you should instead capture and store the Context.current() instead.
Then, when you execute the run() method, you should make the stored context the current one.
The difference here is that due to asynchronous execution the span for which you store a reference might be already ended when you make it current, whereas a context is just a context and just provides the context propagation.
What also needs to be checked here is that all the calls to the constructor are within the expected scope (when there is already a parent span), as the calls to the constructor become caller-sensitive.
What I meant by that is that when the constructor is called Context.current() returns something different than the value of Context.root(), otherwise there is nothing to propagate, and the spans that will be created from that will be top-level spans.
In your application this might be implicit, if you get top-level spans where you expect to have child spans of a parent span, then that could be the issue here.
In short, try it by just propagating the context, I'm probably overthinking what could be wrong here :-).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.