Access the currently active span and trace in your application’s execution context.
contextvars
to automatically manage the active span and trace within your application’s execution flow. This allows you to easily retrieve information about the current operation without explicitly passing objects around.
You can retrieve the currently active span or trace in the execution context using the following helper methods:
tracing.current_span()
Span
instance representing the operation currently active in the local execution context. This is typically the innermost span created by tracing.create_span()
.
tracing.current_trace()
Trace
instance representing the overall workflow currently active in the local execution context. This will be the trace established by tracing.create_trace()
.
current_span()
and current_trace()
can be used to inspect the active context within nested operations:
span_id
or trace_id
without needing to pass them explicitly.create_span()
and create_trace()
.