Implement tracing across multiple processes and workers in your Python app.
contextvars
), this automatic propagation does not extend across process boundaries or when work is explicitly dispatched to new, independent execution contexts.
with tracing.create_span(...)
), the SDK automatically sets the current span and trace in a context-local variable. However, when you:
multiprocessing
).threading
typically handles this better than multiprocessing
).trace_id
or parent_id
from the originating process. You must explicitly pass this context.
group_id
to logically link these independent traces together, allowing you to see all related activity in the Traces page, even if they don’t form a single, continuous trace hierarchy. This is ideal for scenarios where workers process independent units of work concurrently.
group_id
, trace_id
and span_id
of the parent span in the originating process.Scope
object directly in your worker process as this scope may well be shared across jobs leading to incorrect tracing and leaking of tracing data.
multiprocessing.Process
) will have its own tracing queue manager. Ensure tracing.init()
is called within each worker’s entry point if you expect it to send tracing data. This typically means calling tracing.init()
at the start of the function that the worker executes.with tracing.create_span(...)
) handle this automatically within their scope.