node_exporter for host metrics, kube-state-metrics for Kubernetes object state, and application exporters for app-specific metrics. This article (and the next) demystifies how to go from zero metrics to instrumenting an application so it exposes multiple metrics directly to Prometheus.
When you instrument an application you do two things:
- Compute metrics in your application and keep the current value for each time series in memory.
- Expose an HTTP metrics endpoint that Prometheus scrapes to read those values.


- Define your metric at module scope (outside request handlers or event loops). Provide a stable metric name, a
help/description string, and optional label keys. For histograms you can predefine bucket boundaries. - Update the metric from application logic when relevant events occur (requests, errors, queue lengths, business events).
- Expose a metrics HTTP endpoint so Prometheus can scrape the current values.
Conceptually, counters, gauges, and histograms differ; in code, the difference is which methods you call. Client libraries manage the time series and format the endpoint output into the OpenMetrics/Prometheus exposition format, but they do not prevent cardinality explosions caused by high-cardinality labels — design labels carefully.
Label cardinality is a common pitfall. Avoid using unbounded values (e.g., user IDs, UUIDs, or timestamps) as label values. Prefer aggregations or buckets for high-cardinality attributes to keep the number of time series manageable.
Histogram.time() can measure function or request latency automatically.
Security and deployment tips
- Expose metrics on a separate port or an internal-only endpoint to prevent public access.
- Scrape metrics with appropriate authentication or network policies in production.
- Monitor the cardinality and churn of time series — high cardinality increases memory use and query cost.
If you accidentally use high-cardinality labels (like user IDs or request UUIDs), Prometheus storage and query performance can degrade rapidly. Audit label usage before deploying instrumentation to production.
- Prometheus exposition formats: https://prometheus.io/docs/instrumenting/exposition_formats/
- Prometheus documentation: https://prometheus.io/docs/
- OpenTelemetry project: https://opentelemetry.io/