Histogram implements Instrument
Histogram instrument for recording value distributions.
Histograms track the statistical distribution of measurements, including count, sum, min, max values, and bucket distributions.
Example usage:
$histogram = $meter->createHistogram('http.request.duration', 'ms', 'Request duration');
$histogram->record(42.5, ['http.method' => 'GET']);
$histogram->record(128.3, ['http.method' => 'GET']);
// On collect: count=2, sum=170.8, min=42.5, max=128.3, plus bucket counts
Tags
Interfaces
- Instrument
- Base interface for metric instruments.
Constants
- DEFAULT_BOUNDARIES = [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0]
- Default bucket boundaries (milliseconds, suitable for latency measurements).
Methods
- __construct() : mixed
- boundaries() : array<string|int, float>
- Get the configured bucket boundaries.
- collect() : array<string|int, Metric>
- Collect aggregated metrics for export.
- description() : string|null
- Get the instrument description.
- name() : string
- Get the instrument name.
- record() : void
- Record a value in the histogram.
- unit() : string|null
- Get the unit of measurement.
Constants
DEFAULT_BOUNDARIES
Default bucket boundaries (milliseconds, suitable for latency measurements).
public
array<string|int, float>
DEFAULT_BOUNDARIES
= [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0]
Methods
__construct()
public
__construct(string $name, resource $resource, InstrumentationScope $scope, ClockInterface $clock[, AggregationTemporality $temporality = AggregationTemporality::CUMULATIVE ][, ExemplarFilter $exemplarFilter = new TraceBasedExemplarFilter() ][, null|string $unit = null ][, null|string $description = null ][, array<string|int, float> $boundaries = self::DEFAULT_BOUNDARIES ]) : mixed
Parameters
- $name : string
-
Instrument name
- $resource : resource
-
The resource context for this instrument
- $scope : InstrumentationScope
-
Instrumentation scope that created this instrument
- $clock : ClockInterface
-
Clock for timestamps
- $temporality : AggregationTemporality = AggregationTemporality::CUMULATIVE
-
Aggregation temporality
- $exemplarFilter : ExemplarFilter = new TraceBasedExemplarFilter()
-
Filter for exemplar sampling
- $unit : null|string = null
-
Unit of measurement
- $description : null|string = null
-
Human-readable description
- $boundaries : array<string|int, float> = self::DEFAULT_BOUNDARIES
-
Explicit bucket boundaries (strictly increasing)
boundaries()
Get the configured bucket boundaries.
public
boundaries() : array<string|int, float>
Return values
array<string|int, float>collect()
Collect aggregated metrics for export.
public
collect() : array<string|int, Metric>
Returns all aggregated metrics since the last collection, then resets the internal aggregation state.
Return values
array<string|int, Metric> —Aggregated metrics ready for export
description()
Get the instrument description.
public
description() : string|null
Return values
string|nullname()
Get the instrument name.
public
name() : string
Return values
stringrecord()
Record a value in the histogram.
public
record(float|int $value[, array<string, bool|float|int|string> $attributes = [] ][, null|SpanContext $context = null ]) : void
Parameters
- $value : float|int
-
Value to record
- $attributes : array<string, bool|float|int|string> = []
-
Categorization attributes
- $context : null|SpanContext = null
-
Optional span context for exemplar capture
unit()
Get the unit of measurement.
public
unit() : string|null