Asynchronous work may outlive the request that scheduled it, run on another thread or process, or combine several independent inputs. Carry the causal context explicitly rather than relying on thread-local state.

Asynchronous tasks

  1. Capture the active OpenTelemetry context when scheduling the task.
  2. Make that context active while the worker performs causally nested work.
  3. Create and end spans around the scheduled operation and its meaningful steps.
  4. Restore or detach context when the task finishes so it does not leak into unrelated work.

For a durable job that starts much later or should not be a child of the scheduling span, start a new trace and add a link to the scheduling context when appropriate.

Batch workloads

For a batch with one causal parent, create a batch span and record a bounded message count or batch size attribute. When a batch combines independent messages or requests, keep their contexts as links where supported rather than selecting one arbitrary parent. For very large batches, check SDK link limits and avoid high-cardinality per-item attributes.


Propagate context through the task or message metadata using the configured OpenTelemetry propagator. See Instrument Messaging and Queues for broker workflows.