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, mixed $value)

Attach a single attribute to this object.

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.

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

in AttributeTrait at line 45
addAttribute(string $attribute, mixed $value)

Attach a single attribute to this object.

Parameters

string $attribute The name of the attribute.
mixed $value The value of the attribute. Will be cast to a string

in AttributeTrait at line 55
array attributes()

Return the list of attributes for this object.

Return Value

array

at line 169
__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 227
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 239
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 249
string spanId()

Retrieve the ID of this span.

Return Value

string

at line 259
SpanData spanData()

Return a read-only version of this span.

Return Value

SpanData

at line 285
addTimeEvents(array $timeEvents)

Add time events to this span.

Parameters

array $timeEvents

at line 297
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 330
setStatus(int $code, string $message)

Set the status for this span.

Parameters

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