Skip to content

duron.tracing module

Span

Bases: Protocol

Protocol for tracing spans that represent units of work.

record

record(**kwargs)

Record an attribute on this span.

Parameters:

  • **kwargs (JSONValue, default: {} ) –

    JSON-serializable value to record

set_status

set_status(status, message=None)

Set the status of this span.

Parameters:

  • status (Literal['OK', 'ERROR']) –

    Either "OK" for successful completion or "ERROR" for failure

  • message (str | None, default: None ) –

    Optional status message, typically used with "ERROR" status to provide error details

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: