Yes, there can be multiple transactions at a time, and the ability to track which transaction/span is currently active (and also parent/child relationships) is called context-propagation and it's a broad topic.
In general, if the span/transaction remains active on a given thread, then we use a thread-based context propagation with a stack of activated spans/transactions.
When the span/transaction is delegated to another thread, then we keep the link by wrapping the delegated task or using an intermediate object in a key/value map to be able to retrieve the context.
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.