Skip to content

OtelMeterHandle

Real MeterHandle, wrapping an OpenTelemetry MeterInterface.

Instruments are created once per name and cached for the worker’s lifetime (recreating the Counter/Histogram/Gauge object on every recording call would be wasteful and risks metadata — unit/description — diverging between calls for the same instrument name).

Every recording is wrapped so a call site can never crash the request; see OtelSpanHandle for the same rationale.

final class OtelMeterHandle implements MeterHandle

ImplementsMeterHandle
SourceOtelMeterHandle.php

public function __construct(MeterInterface $meter): mixed

ParameterTypeDescription
$meterMeterInterface

Returns mixed

MethodDescription
[`addCounter(string $name, intfloat $increment = 1, array $attributes = []): void`](#addcounter)
recordGauge(string $name, float $value, array $attributes = []): voidRecords the current value of the gauge called $name, creating and caching the instrument on first use.
recordHistogram(string $name, float $value, array $attributes = []): voidRecords $value into the histogram called $name.

public function addCounter(string $name, int|float $increment = 1, array $attributes = []): void

Adds $increment to the counter called $name, creating and caching the instrument on first use.

Failures are swallowed as in OtelMeterHandle::recordHistogram().

ParameterTypeDescription
$namestring
$increment`int““float`
$attributesarray

public function recordGauge(string $name, float $value, array $attributes = []): void

Records the current value of the gauge called $name, creating and caching the instrument on first use.

Failures are swallowed as in OtelMeterHandle::recordHistogram().

ParameterTypeDescription
$namestring
$valuefloat
$attributesarray

public function recordHistogram(string $name, float $value, array $attributes = []): void

Records $value into the histogram called $name.

The histogram instrument is created on first use and cached under $name for the life of this handle. Attributes are sanitized, and any failure — creating the instrument or recording — is swallowed and logged at debug level rather than propagating to the call site.

ParameterTypeDescription
$namestring
$valuefloat
$attributesarray