View module source on GitHub

_SpanStack Objects

@dataclass
class _SpanStack()

Stack of spans.

push

def push(span: Span) -> None

Push a span onto the stack.

pop

def pop() -> Optional[Span]

Pop a span from the stack.

current

def current() -> Optional[Span]

Get the current span from the stack.

current_span

def current_span() -> Optional[Span]

Get the current span from the stack.

span

def span(logger: Optional[Logger] = None,
         id: Optional[Union[str, Callable]] = None,
         trace_id: Optional[Union[str, Callable]] = None,
         name: Optional[str] = None,
         tags: Optional[dict] = None,
         evaluators: Optional[List[str]] = None,
         evaluator_variables: Optional[Dict[str, str]] = None)

Decorator for creating a span within a trace.

This decorator should be used within a function that is already decorated with @trace. It creates a new span and injects a tracer object into the decorated function.

Arguments:

NameTypeDescription
loggerLoggerThe Logger instance to use for logging.
idOptional[str] or Optional[Callable], optionalThe ID for the span. If callable, it will be called to generate the ID. Defaults to None.
trace_idOptional[str] or Optional[Callable], optionalThe trace ID to associate with this span. If callable, it will be called to generate the trace ID. Defaults to current_trace.
nameOptional[str], optionalThe name of the span. Defaults to None.
tagsOptional[dict], optionalAdditional tags to associate with the span. Defaults to None.

Returns:

NameDescription
CallableA decorator function that wraps the original function with span functionality.

Raises:

  • ValueError - If the decorator is used outside of a @trace decorated function.