class Span

This plain PHP class represents a single timed event within a Trace. Spans can be nested and form a trace tree. Often, a trace contains a root span that describes the end-to-end latency of an operation and, optionally, one or more subspans for its suboperations. Spans do not need to be contiguous. There may be gaps between spans in a trace.

Traits

Trait which provides helper methods for converting DateTime input formats.

Constants

ATTRIBUTE_HOST

ATTRIBUTE_PORT

ATTRIBUTE_METHOD

ATTRIBUTE_PATH

ATTRIBUTE_ROUTE

ATTRIBUTE_USER_AGENT

ATTRIBUTE_STATUS_CODE

KIND_UNSPECIFIED

KIND_SERVER

KIND_CLIENT

Methods

addAttributes(array $attributes)

Attach attributes to this object.

addAttribute(string $attribute, string $value)

Add an attribute to this span.

array
attributes()

Return the list of attributes for this object.

__construct(array $options = [])

Instantiate a new Span instance.

setStartTime(DateTimeInterface|int|float $when = null)

Set the start time for this span.

setEndTime(DateTimeInterface|int|float $when = null)

Set the end time for this span.

string
spanId()

Retrieve the ID of this span.

spanData()

Return a read-only version of this span.

attach()

Mark this span as attached.

bool
attached()

Returns whether or not this span has been attached.

addTimeEvents(array $timeEvents)

Add time events to this span.

addTimeEvent(TimeEvent $timeEvent)

Add a time event to this span.

addLinks(array $links)

Add links to this span.

addLink(Link $link)

Add a link to this span.

setStatus(int $code, string $message)

Set the status for this span.

Details

in AttributeTrait at line 32
addAttributes(array $attributes)

Attach attributes to this object.

Parameters

array $attributes Attributes in the form of $attribute => $value

at line 325
addAttribute(string $attribute, string $value)

Add an attribute to this span.

Parameters

string $attribute The name of the attribute to add
string $value The attribute value

in AttributeTrait at line 55
array attributes()

Return the list of attributes for this object.

Return Value

array

at line 186
__construct(array $options = [])

Instantiate a new Span instance.

Parameters

array $options [optional] Configuration options.

 @type string $spanId The ID of the span. If not provided,
       one will be generated automatically for you.
 @type string $name The name of the span.
 @type \DateTimeInterface|int|float $startTime Start time of the span in nanoseconds.
       If provided as an int or float, it is treated as a Unix timestamp.
 @type \DateTimeInterface|int|float $endTime End time of the span in nanoseconds.
       If provided as an int or float, it is treated as a Unix timestamp.
 @type string $parentSpanId ID of the parent span if any.
 @type array $attributes Associative array of $attribute => $value
       to attach to this span.
 @type Status $status The final status for this span.
 @type bool $sameProcessAsParentSpan True when the parentSpanId
       belongs to the same process as the current span.
 @type string $kind The span's type.

at line 248
setStartTime(DateTimeInterface|int|float $when = null)

Set the start time for this span.

Parameters

DateTimeInterface|int|float $when [optional] The start time of this span. Defaults to now. If provided as an int or float, it is expected to be a Unix timestamp.

at line 260
setEndTime(DateTimeInterface|int|float $when = null)

Set the end time for this span.

Parameters

DateTimeInterface|int|float $when [optional] The end time of this span. Defaults to now. If provided as an int or float, it is expected to be a Unix timestamp.

at line 270
string spanId()

Retrieve the ID of this span.

Return Value

string

at line 280
SpanData spanData()

Return a read-only version of this span.

Return Value

SpanData

at line 304
attach()

Mark this span as attached.

at line 314
bool attached()

Returns whether or not this span has been attached.

Return Value

bool

at line 336
addTimeEvents(array $timeEvents)

Add time events to this span.

Parameters

array $timeEvents

at line 348
addTimeEvent(TimeEvent $timeEvent)

Add a time event to this span.

Parameters

TimeEvent $timeEvent

Add links to this span.

Parameters

array $links

Add a link to this span.

Parameters

Link $link

at line 383
setStatus(int $code, string $message)

Set the status for this span.

Parameters

int $code The status code
string $message A developer-facing error message