MAX_SPANS
MAX_SPANS = 2048
Spans held before further ones are counted and dropped.
Opens and closes spans, and holds them until something exports them.
A tracer that posted each span as it closed would put an outbound HTTP call inside a flush, which is the thing telemetry is supposed to be measuring. So spans accumulate in memory and are drained by whoever is exporting; on a request that is the end of the request, and on cron it is the end of the run.
The buffer is capped. A long-running command that traced a million subjects would otherwise spend more memory on the measurement than on the work. Past the cap, spans are counted and dropped, and the count is exported as its own metric so the gap is visible rather than silent.
$spans : list<\Drupal\strata\Telemetry\Span>
Closed spans waiting to be exported.
measure(string $name, callable $work, array$attributes = []) : mixed
Times a callable and records a span around it.
An exception is recorded on the span and then rethrown. Telemetry never changes what the program does; a tracer that swallowed the failure it just measured would be worse than no tracer at all.
| string | $name | What is being timed. |
| callable | $work | The work. |
| array |
$attributes | What the operation is about. |
Whatever the callable threw.
Whatever the callable returned.
close(\Drupal\strata\Telemetry\Span $span, int $durationNanos, array$attributes = [], int $status = \Drupal\strata\Telemetry\Span::OK, string $message = '') : void
Closes a span and buffers it.
| \Drupal\strata\Telemetry\Span | $span | The span start() returned. |
| int | $durationNanos | How long it took, from |
| array |
$attributes | Attributes to add now the result is known. |
| int | $status | Either Span::OK or Span::ERROR. |
| string | $message | Why it failed, when it did. |