trait TracksPushedScopesAndSpans

Track pushed scopes and spans using coroutine-local storage.

State is stored in coroutine Context (keyed by the using class name) so that singleton features sharing this trait remain safe under concurrent coroutines.

Constants

SPANS_CONTEXT_PREFIX

Context key prefix for per-class span tracking state.

Methods

void
pushSpan(Span $span)

Push a span onto the coroutine-local stack and set it as current on the hub.

void
pushScope()

Push a scope onto the hub and track the count in coroutine-local storage.

Span|null
maybePopSpan()

Pop a span from the coroutine-local stack and restore the parent span.

void
maybePopScope()

Pop a scope from the hub if one was pushed in this coroutine.

Span|null
maybeFinishSpan(SpanStatus|null $status = null)

Finish the current span if one exists on the coroutine-local stack.

Details

at line 24
protected void pushSpan(Span $span)

Push a span onto the coroutine-local stack and set it as current on the hub.

Parameters

Span $span

Return Value

void

at line 42
protected void pushScope()

Push a scope onto the hub and track the count in coroutine-local storage.

Return Value

void

at line 53
protected Span|null maybePopSpan()

Pop a span from the coroutine-local stack and restore the parent span.

Return Value

Span|null

at line 76
protected void maybePopScope()

Pop a scope from the hub if one was pushed in this coroutine.

Return Value

void

at line 94
protected Span|null maybeFinishSpan(SpanStatus|null $status = null)

Finish the current span if one exists on the coroutine-local stack.

Parameters

SpanStatus|null $status

Return Value

Span|null