\Drupal\strata\Telemetry OtlpPayload

Renders spans and metrics as OTLP over HTTP with a JSON body.

A pure transform with no client and no configuration beyond the resource attributes, so the wire shape is unit-testable without a collector. The protobuf encoding is the other OTLP transport and would need an extension or a generated stub library; the JSON one is accepted by every collector this would be pointed at and costs nothing to ship.

Ids travel as hex, not as bytes. OTLP/JSON specifies base16 for traceId and spanId, unlike the protobuf encoding which carries raw bytes. A collector fed base64 there accepts the request and then silently indexes the trace under the wrong id.

Integers travel as strings. Unix nanoseconds exceed what a JSON number can hold exactly in a consumer using doubles, so the specification requires fixed64 fields to be quoted. Sending them unquoted loses the low digits of every timestamp, which reorders spans inside a trace.

Summary

Methods
Properties
Constants
__construct
traces
metrics
resourceAttributes
No public properties found
TRACES_PATH
METRICS_PATH
SCOPE
No protected methods found
No protected properties found
No protected constants found
scope
attributes
serviceName
version
resource
No private constants found

Constant

TRACES_PATH

TRACES_PATH = '/v1/traces'

The path a collector accepts spans on.

METRICS_PATH

METRICS_PATH = '/v1/metrics'

The path a collector accepts metrics on.

SCOPE

SCOPE = 'strata'

The instrumentation scope every span and metric is attributed to.

Properties

$serviceName

$serviceName : string

Type

string

$version

$version : string

Type

string

$resource

$resource : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(string  $serviceName = 'strata', string  $version = '', array  $resource = []) : mixed

Constructs a payload renderer.

Parameters

string $serviceName

What the collector files this process under.

string $version

The module version, so a graph can be split across a deploy.

array $resource

Further resource attributes, such as the site id and the deployment environment.

Returns

mixed —

traces()

traces(list<\Drupal\strata\Telemetry\Span>  $spans) : array<string,mixed>

Renders spans.

Parameters

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

The spans.

Returns

array

An ExportTraceServiceRequest body.

metrics()

metrics(\Drupal\strata\Telemetry\MetricSet  $metrics, int  $nanos) : array<string,mixed>

Renders metrics.

Parameters

\Drupal\strata\Telemetry\MetricSet $metrics

The metrics.

int $nanos

Unix nanoseconds the readings were taken at.

Returns

array

An ExportMetricsServiceRequest body.

resourceAttributes()

resourceAttributes() : array<string,string>

The resource every span and metric is attributed to.

Returns

array

Attribute name keyed to value.

scope()

scope() : array<string,string>

The instrumentation scope.

Returns

array

The scope name and version.

attributes()

attributes(array  $attributes) : list<array<string,mixed>>

Renders attributes as OTLP key-value pairs.

Parameters

array $attributes

Name keyed to value.

Returns

list> —

The pairs, each with the value typed as OTLP requires.