Key Concepts
The Metrics API consists of several core components:- MeterProvider: The entry point for obtaining
Meterinstances - Meter: Creates instruments for recording measurements
- Instruments: Record measurements synchronously or asynchronously
- Views: Customize how metrics are aggregated and exported
Instrument Categories
Instruments are categorized as either synchronous or asynchronous:Synchronous Instruments
Synchronous instruments are used inline with your application’s processing logic. They record measurements as events happen in your code.- Counter: Records monotonically increasing values (e.g., requests served, bytes sent)
- UpDownCounter: Records values that can increase or decrease (e.g., active connections, queue size)
- Histogram: Records a distribution of values (e.g., request duration, response size)
- Gauge: Records independent point-in-time values (e.g., CPU usage, memory consumption)
Asynchronous Instruments
Asynchronous instruments use callbacks that are invoked during metric collection. They’re ideal for values that are expensive to compute or are already being tracked elsewhere.- ObservableCounter: Observes monotonically increasing values via callback
- ObservableUpDownCounter: Observes values that can increase or decrease via callback
- ObservableGauge: Observes current values via callback
Getting Started
To use metrics in your application:- Create a
MeterProviderand register it globally - Obtain a
Meterfrom the provider - Create instruments from the meter
- Record measurements using the instruments
Choosing the Right Instrument
Counter
Use when values only increase (requests, errors, bytes sent)
UpDownCounter
Use when values can increase or decrease (active connections, queue depth)
Histogram
Use for distributions (latency, request size, temperature)
Gauge
Use for point-in-time values (CPU usage, memory, cache size)
Supported Data Types
Most instruments support multiple numeric types:u64- Unsigned 64-bit integeri64- Signed 64-bit integerf64- 64-bit floating point
Attributes
All measurements can be tagged with attributes (key-value pairs) that add dimensionality to your metrics:Next Steps
Meters
Learn about creating and configuring Meters
Instruments
Explore the different instrument types in detail
Views
Customize metric aggregation with Views
Observable Instruments
Use callbacks to report measurements asynchronously