Skip to content

symfonic.observability.otel.propagation

propagation

ContextVar carriers for the OTEL exporter.

Stores the currently-active root span and the resolved tenant scope so child-span helpers can populate identity attributes without threading state through every emit site. Pure contextvars -- no OTEL imports.

RunSpanContext dataclass

RunSpanContext(
    run_id: str,
    tenant_id: str | None,
    session_id: str | None,
    entry_point: str,
)

Per-run state shared across child-span helpers.

The OTEL Context itself is propagated implicitly via contextvars by the OTEL SDK; this carrier holds the symfonic identifiers needed to populate symfonic.* attributes on every child span. Kept frozen so accidental mutation is impossible.

get_run_context

get_run_context() -> RunSpanContext | None

Return the currently-active run context, or None outside a run.

Source code in src/symfonic/observability/otel/propagation.py
def get_run_context() -> RunSpanContext | None:
    """Return the currently-active run context, or ``None`` outside a run."""
    return _current_run_context.get()

reset_run_context

reset_run_context(token: object) -> None

Reset the active run context using a token from set_run_context.

Source code in src/symfonic/observability/otel/propagation.py
def reset_run_context(token: object) -> None:
    """Reset the active run context using a token from ``set_run_context``."""
    _current_run_context.reset(token)  # type: ignore[arg-type]

set_run_context

set_run_context(ctx: RunSpanContext) -> object

Set the active run context; returns a token usable with reset.

Source code in src/symfonic/observability/otel/propagation.py
def set_run_context(ctx: RunSpanContext) -> object:
    """Set the active run context; returns a token usable with ``reset``."""
    return _current_run_context.set(ctx)