# Metric Instruments — OpenTelemetry

Source: https://www.skillbyai.com/en/opentelemetry/m-instruments

> Counters, histograms and gauges.

## Choose the instrument by behaviour

A **meter** creates instruments: **Counter** (monotonic, such as requests processed), **UpDownCounter** (can decrease, such as items in a queue), **Histogram** (distributions such as latency) and **Gauge** (current values), plus **asynchronous (observable)** variants whose values are read by a callback at collection time (CPU usage, pool size). Measurements carry attributes, and the SDK aggregates them before export. Zero-code instrumentation already emits standard HTTP and runtime metrics.

## Beyond traces

The same SDKs produce metrics and correlate logs with traces.

![Three ideas: metric instruments, log correlation, linking metrics to traces.](assets/figures/opentelemetry/section-4-map.svg) — Figure 4.1 — Instruments, log correlation and exemplars.

## Creating metrics in Python

OpenTelemetry metrics API (a sketch).

```python
from opentelemetry import metrics

meter = metrics.get_meter("orders.checkout")

orders = meter.create_counter("app.orders.placed", unit="{order}",
                              description="Orders placed")
latency = meter.create_histogram("app.checkout.duration", unit="s",
                                 description="Checkout processing time")

def record(order, seconds):
    orders.add(1, {"payment.method": order.payment_method})
    latency.record(seconds, {"app.customer.tier": order.tier})
```

## Keep metric attributes bounded

Attributes multiply time series just as Prometheus labels do; never use IDs as metric attributes.

**Quiz:** Which instrument fits checkout latency?

- [x] Histogram
- [ ] Counter
- [ ] UpDownCounter
- [ ] Resource

*Answer:* Histogram. Distributions need histograms.
