\Drupal\strata\Telemetry Span

One timed operation, in the shape OpenTelemetry transports.

Wall-clock start and monotonic duration are recorded separately. OTLP wants unix nanoseconds for both ends of a span, but a wall clock can step - ntp, a leap second, a container resuming - and a span whose end is stamped from a stepped clock reports a negative duration. So the start is wall-clock, because a collector has to line the span up against everything else, and the duration comes from hrtime(), which only ever moves forward. The end is start plus duration.

Ids are random rather than derived. A trace id derived from the operation would collide across two flushes of the same shape, and a collector would splice unrelated work into one trace.

Summary

Methods
Properties
Constants
__construct
endNanos
seconds
isError
close
jsonSerialize
name
traceId
spanId
startNanos
durationNanos
attributes
status
message
parentId
OK
ERROR
NANOS_PER_SECOND
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

OK

OK = 1

A span that finished as expected.

ERROR

ERROR = 2

A span that finished because something failed.

NANOS_PER_SECOND

NANOS_PER_SECOND = 1000000000

Nanoseconds in a second.

Properties

$name

$name : string

Type

string

$traceId

$traceId : string

Type

string

$spanId

$spanId : string

Type

string

$startNanos

$startNanos : int

Type

int

$durationNanos

$durationNanos : int

Type

int

$attributes

$attributes : array

Type

array<string|int, mixed>

$status

$status : int

Type

int

$message

$message : string

Type

string

$parentId

$parentId : ?string

Type

string|null

Methods

__construct()

__construct(string  $name, string  $traceId, string  $spanId, int  $startNanos, int  $durationNanos = 0, array  $attributes = [], int  $status = \self::OK, string  $message = '', string|null  $parentId = null) : mixed

Constructs a span.

Parameters

string $name

What was timed, such as "strata.flush".

string $traceId

Thirty-two hex characters.

string $spanId

Sixteen hex characters.

int $startNanos

Unix nanoseconds the span opened at.

int $durationNanos

How long it took, from a monotonic clock.

array $attributes

What the operation was about.

int $status

Either OK or ERROR.

string $message

Why it failed, when it did.

string|null $parentId

The enclosing span's id, or NULL for a root span.

Returns

mixed —

endNanos()

endNanos() : int

When the span closed.

Returns

int —

Unix nanoseconds.

seconds()

seconds() : float

How long the operation took.

Returns

float —

Seconds.

isError()

isError() : bool

Whether the operation failed.

Returns

bool —

TRUE when the status is ERROR.

close()

close(int  $durationNanos, array  $attributes = [], int  $status = \self::OK, string  $message = '') : self

The same span, closed after a measured duration.

Parameters

int $durationNanos

How long it took.

array $attributes

Attributes to merge in, which is where a result's counts are added.

int $status

Either OK or ERROR.

string $message

Why it failed, when it did.

Returns

self —

The closed span.

jsonSerialize()

jsonSerialize() : array

{@inheritdoc}

Returns

array —