class SpanContext

SpanContext encapsulates your current context within your request's trace. It includes 3 fields: the traceId, the current spanId, and an enabled flag which indicates whether or not the request is being traced.

Example:

use OpenCensus\Trace\Tracer;

$context = Tracer::spanContext();
echo $context; // output the header format for using the current context in a remote call

Traits

Trait which provides helper methods for generating trace identifiers.

Methods

__construct(string $traceId = null, string|null $spanId = null, bool|null $enabled = null, bool $fromHeader = false)

Creates a new SpanContext instance

string
traceId()

Fetch the current traceId.

string
spanId()

Fetch the current spanId.

setSpanId(string|null $spanId)

Set the current spanId.

bool
enabled()

Whether or not the request is being traced.

setEnabled(bool|null $enabled)

Set whether or not the request is being traced.

bool
fromHeader()

Whether or not this context was detected from a request header.

Details

at line 66
__construct(string $traceId = null, string|null $spanId = null, bool|null $enabled = null, bool $fromHeader = false)

Creates a new SpanContext instance

Parameters

string $traceId The current traceId. If not set, one will be generated for you.
string|null $spanId The current spanId. Defaults to null.
bool|null $enabled Whether or not tracing is enabled on this request. Defaults to null.
bool $fromHeader Whether or not the context was detected from an incoming header. Defaults to false.

at line 79
string traceId()

Fetch the current traceId.

Return Value

string

at line 89
string spanId()

Fetch the current spanId.

Return Value

string

at line 99
setSpanId(string|null $spanId)

Set the current spanId.

Parameters

string|null $spanId The spanId to set.

at line 109
bool enabled()

Whether or not the request is being traced.

Return Value

bool

at line 119
setEnabled(bool|null $enabled)

Set whether or not the request is being traced.

Parameters

bool|null $enabled

at line 129
bool fromHeader()

Whether or not this context was detected from a request header.

Return Value

bool