\Drupal\strata\Telemetry OtlpExporter

Posts spans and metrics to an OTLP endpoint.

A failed export is a warning, never an error, and is never retried. Telemetry describes what already happened; a collector that is down does not make the flush that just succeeded a failure, and a retry queue for observability data would mean an unreachable collector slowly filling the site's own queue table with duplicate readings of a moment that has passed.

The endpoint is the collector's base URL and the signal paths are appended, which is what the OTEL_EXPORTER_OTLP_ENDPOINT convention specifies. A site that configured the full traces URL instead gets it used as-is, since appending a second /v1/traces would silently 404.

Summary

Methods
Properties
Constants
__construct
isEnabled
exportSpans
exportMetrics
drain
url
No public properties found
TIMEOUT
No protected methods found
No protected properties found
No protected constants found
send
http
payload
logger
endpoint
headers
No private constants found

Constant

TIMEOUT

TIMEOUT = 5

Seconds to wait for the collector.

Short on purpose. The export runs at the end of a request or a cron run, and a collector that takes longer than this is one nothing should be waiting on.

Properties

$http

$http : \GuzzleHttp\ClientInterface

Type

ClientInterface

$payload

$payload : \Drupal\strata\Telemetry\OtlpPayload

Type

OtlpPayload

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

$endpoint

$endpoint : string

Type

string

$headers

$headers : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(\GuzzleHttp\ClientInterface  $http, \Drupal\strata\Telemetry\OtlpPayload  $payload, \Psr\Log\LoggerInterface  $logger, string  $endpoint = '', array  $headers = []) : mixed

Constructs an exporter.

Parameters

\GuzzleHttp\ClientInterface $http

The HTTP client.

\Drupal\strata\Telemetry\OtlpPayload $payload

Renders the wire shape.

\Psr\Log\LoggerInterface $logger

Records an export that did not land.

string $endpoint

The collector's base URL, or an empty string to export nothing.

array $headers

Headers every export carries, which is where an API key goes.

Returns

mixed —

isEnabled()

isEnabled() : bool

Whether an endpoint is configured.

Returns

bool —

TRUE when exports will be attempted.

exportSpans()

exportSpans(list<\Drupal\strata\Telemetry\Span>  $spans) : bool

Exports spans.

Parameters

list<\Drupal\strata\Telemetry\Span> $spans

The spans.

Returns

bool —

TRUE when the collector accepted them, or there was nothing to send.

exportMetrics()

exportMetrics(\Drupal\strata\Telemetry\MetricSet  $metrics, int|null  $nanos = null) : bool

Exports metrics.

Parameters

\Drupal\strata\Telemetry\MetricSet $metrics

The metrics.

int|null $nanos

Unix nanoseconds to stamp them with, or NULL for now.

Returns

bool —

TRUE when the collector accepted them, or there was nothing to send.

drain()

drain(\Drupal\strata\Telemetry\Tracer  $tracer) : bool

Drains a tracer and exports what it held.

Parameters

\Drupal\strata\Telemetry\Tracer $tracer

The tracer.

Returns

bool —

TRUE when the collector accepted the spans, or there were none.

url()

url(string  $path) : string

The URL one signal is posted to.

Parameters

string $path

The signal path.

Returns

string —

The URL.

send()

send(string  $path, array  $body) : bool

Posts one body.

Parameters

string $path

The signal path.

array $body

The rendered payload.

Returns

bool —

TRUE when the collector answered with a 2xx.