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. Operation-local spans are tracked by key without becoming current on the Hub.

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.

Scope
pushScope()

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

void
trackLocalSpan(string $key, Span $span)

Track an operation-local span without making it current on the Hub.

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.

Span|null
maybeFinishLocalSpan(string $key, SpanStatus|null $status = null)

Finish an operation-local span by key if one exists.

Details

at line 26
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 45
protected Scope pushScope()

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

Return Value

Scope

at line 59
protected void trackLocalSpan(string $key, Span $span)

Track an operation-local span without making it current on the Hub.

Parameters

string $key
Span $span

Return Value

void

at line 70
protected Span|null maybePopSpan()

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

Return Value

Span|null

at line 93
protected void maybePopScope()

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

Return Value

void

at line 109
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

at line 129
protected Span|null maybeFinishLocalSpan(string $key, SpanStatus|null $status = null)

Finish an operation-local span by key if one exists.

Parameters

string $key
SpanStatus|null $status

Return Value

Span|null