Prometheus client_golang is the official Go client library for instrumenting applications with Prometheus metrics. It provides a metric registry that manages and exposes custom application metrics like counters, gauges, histograms, and summaries in Prometheus format for HTTP scraping by a Prometheus server. The library also includes a remote read client that sends PromQL queries to a Prometheus server over HTTP and retrieves time series data programmatically.
The library supports creating separate registries to isolate metric namespaces and control which metrics are exposed per scrape endpoint. It uses atomic operations and mutexes to allow concurrent metric updates from multiple goroutines without data races, and exposes a standard net/http handler that serializes registered metrics into Prometheus text format on each scrape request. Dynamic label sets per metric family enable multi-dimensional time series through label-value pairs, while metrics are registered by implementing a Collector interface that returns descriptor and channel pairs for scrape-time collection.
Additional capabilities include sending PromQL queries to a remote Prometheus server using the HTTP API and parsing the JSON response into Go data structures, computing streaming quantiles over a sliding time window using a configurable reservoir sampling algorithm, and pre-allocating histogram buckets at registration time with atomic counter increments for efficient latency recording.