Tracing API calls
On top of logging, which simply describes the events in a developer-friendly manner, you might need to get metrics that can get aggregated by dashboard tools. These metrics might include requests per second, distribution of status (Ok
, Internal
, and so on), and many others. In this section, we are going to instrument our code with OpenTelemetry and Prometheus so that tools such as Grafana can be used to create dashboards.
The first thing to understand is that we are going to run an HTTP server for Prometheus metrics. Prometheus exposes the metrics to external tools on the /metrics
route so that the tools wanting to query the data get a sense of all the kinds of metrics available.
So, to create such a server, we are going to get a dependency on Prometheus’ Go library. We are going to do that by getting the dependency on the go-grpc-middleware/providers/prometheus
. The Prometheus Go
library is a transitive dependency of this one and we still need to be...