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

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.

startTime()

Retrieve the start time for this span.

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

Set the start time for this span.

endTime()

Retrieve the end 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.

string
parentSpanId()

Retrieve the ID of this span's parent if it exists.

string
name()

Retrieve the name of this span.

addTimeEvents(array $timeEvents)

Add time events to this span.

addTimeEvent(TimeEvent $timeEvent)

Add a time event to this span.

timeEvents()

Return the time events for this span.

addLinks(array $links)

Add links to this span.

addLink(Link $link)

Add a link to this span.

Link[]
links()

Return the links for this span.

setStatus(int $code, string $message)

Set the status for this span.

status()

Retrieve the final status for this span.

array
stackTrace()

Retrieve the stackTrace at the moment this span was created

bool
sameProcessAsParentSpan()

Whether or not this span is in the same process as its parent.

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 145
__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.

at line 196
DateTimeInterface startTime()

Retrieve the start time for this span.

Return Value

DateTimeInterface

at line 208
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 218
DateTimeInterface endTime()

Retrieve the end time for this span.

Return Value

DateTimeInterface

at line 230
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 240
string spanId()

Retrieve the ID of this span.

Return Value

string

at line 250
string parentSpanId()

Retrieve the ID of this span's parent if it exists.

Return Value

string

at line 260
string name()

Retrieve the name of this span.

Return Value

string

at line 270
addTimeEvents(array $timeEvents)

Add time events to this span.

Parameters

array $timeEvents

at line 282
addTimeEvent(TimeEvent $timeEvent)

Add a time event to this span.

Parameters

TimeEvent $timeEvent

at line 292
TimeEvent[] timeEvents()

Return the time events for this span.

Return Value

TimeEvent[]

Add links to this span.

Parameters

array $links

Add a link to this span.

Parameters

Link $link

Return the links for this span.

Return Value

Link[]

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

Set the status for this span.

Parameters

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

at line 345
Status status()

Retrieve the final status for this span.

Return Value

Status

at line 355
array stackTrace()

Retrieve the stackTrace at the moment this span was created

Return Value

array

at line 365
bool sameProcessAsParentSpan()

Whether or not this span is in the same process as its parent.

Return Value

bool