Meter facade provides access to all OpenTelemetry metric instruments. It supports seven instrument types covering both synchronous (push) and asynchronous (observable/pull) recording patterns.
Instruments are cached by name within the same
Meter instance. Calling a creation method with the same name twice returns the existing instrument. Calling it with the same name but a different instrument type throws a RuntimeException.Synchronous instruments
Synchronous instruments record measurements at the point in code where the event occurs.counter()
Creates or retrieves a monotonically increasing Counter. Use for values that only ever go up, such as the number of requests processed or errors encountered.
Instrument name. Must be unique within this meter. Reusing the same name returns the cached instrument.
Unit of measure, e.g.
'requests', 'bytes', '{errors}'.Human-readable description of what this counter measures.
Optional advisory hints passed to the SDK.
The counter instrument. Call
->add(int|float $amount, iterable $attributes = []) to record a measurement.histogram()
Creates or retrieves a Histogram. Use for measuring distributions of values such as request durations or payload sizes.
Instrument name.
Unit of measure, e.g.
's' (seconds), 'ms' (milliseconds), 'By' (bytes).Human-readable description.
Optional advisory hints. Pass
ExplicitBucketBoundaries to customize histogram bucket boundaries.The histogram instrument. Call
->record(int|float $amount, iterable $attributes = []) to record a value.advisory:
gauge()
Creates or retrieves a Gauge. Use for values that can go up or down and represent a current state, such as memory usage, queue depth, or temperature.
Instrument name.
Unit of measure.
Human-readable description.
Optional advisory hints.
The gauge instrument. Call
->record(int|float $amount, iterable $attributes = []) to set the current value.upDownCounter()
Creates or retrieves an UpDownCounter. Like a counter but can also decrease — suitable for tracking values such as active connections or items in a pool.
Instrument name.
Unit of measure.
Human-readable description.
Optional advisory hints.
The up-down counter instrument. Call
->add(int|float $amount, iterable $attributes = []) with positive or negative values.Asynchronous (observable) instruments
Asynchronous instruments report measurements through a callback that the SDK calls on its collection cycle. Use these when the measurement is expensive to compute or when you are observing an external value.observableCounter()
Creates or retrieves an ObservableCounter. The SDK will call attached callbacks when it collects metrics.
Instrument name.
Unit of measure.
Human-readable description.
Optional advisory hints.
The observable counter instrument. Use
batchObserve() or attach a callback via the SDK to report values.observableGauge()
Creates or retrieves an ObservableGauge for asynchronous current-value reporting.
Instrument name.
Unit of measure.
Human-readable description.
Optional advisory hints.
The observable gauge instrument.
observableUpDownCounter()
Creates or retrieves an ObservableUpDownCounter for asynchronously reporting values that can increase or decrease.
Instrument name.
Unit of measure.
Human-readable description.
Optional advisory hints.
The observable up-down counter instrument.
batchObserve()
Registers a single callback that reports measurements for multiple asynchronous instruments at once. This is more efficient than registering one callback per instrument when measurements share an expensive data source.
An array of asynchronous instrument instances (observable counter, gauge, or up-down counter). All instruments must have been created by the same meter.
A callback that receives one
ObserverInterface argument per instrument, in the same order as $instruments. Call ->observe(int|float $value, iterable $attributes = []) on each observer.A token that can be used to detach the callback when it is no longer needed. Detach by calling
->detach() on the returned value.collect()
Forces the metric reader to collect and export all pending measurements immediately.
true if collection succeeded, false otherwise.Instrument caching
TheMeter implementation caches every instrument by name. Requesting the same name a second time returns the previously created instance without allocating a new one:
RuntimeException is thrown:
