duron.tracing
module
Span
Tracer
Tracer(trace_id, /, *, run_id=None)
Create a new Tracer with the given trace_id and optional run_id.
trace_id
should be unique and remain constant across retries of the same
task. run_id
should be unique for each a task run.
Parameters:
-
trace_id
(str
) –The trace identifier
-
run_id
(str | None
, default:None
) –The run identifier. If None, a random id will be generated.
setup_tracing
setup_tracing(level=logging.INFO, *, logger=None)
Configure logging integration to capture log messages as trace events.
Installs a logging handler that emits log records as trace events, attaching them to the current span if one exists. This enables correlation of log messages with trace spans.
Parameters:
-
level
(int
, default:INFO
) –Minimum logging level to capture (default: logging.INFO)
-
logger
(Logger | None
, default:None
) –Target logger to configure. If None, configures the root logger.
Raises:
-
RuntimeError
–if the logging handler is already configured.
span
span(name, metadata=None)
Create a new tracing span within the current tracer context.
Parameters:
-
name
(str
) –Human-readable name for the span (e.g., "fetch_user", "process_data")
-
metadata
(Mapping[str, JSONValue] | None
, default:None
) –Optional attributes to attach to the span. Must be JSON-serializable.
Returns:
-
AbstractContextManager[Span]
–A context manager that enters the span on entry and exits on exit.