(reg prometheus.Registerer, clientName string, rt http.RoundTripper)
| 281 | } |
| 282 | |
| 283 | func instrumentRoundTripper(reg prometheus.Registerer, clientName string, rt http.RoundTripper) http.RoundTripper { |
| 284 | reg = prometheus.WrapRegistererWith(prometheus.Labels{"client": clientName}, reg) |
| 285 | |
| 286 | requestDuration := promauto.With(reg).NewHistogramVec( |
| 287 | prometheus.HistogramOpts{ |
| 288 | Name: "http_client_request_duration_seconds", |
| 289 | Help: "Tracks the latencies for HTTP requests.", |
| 290 | Buckets: []float64{0.1, 0.3, 0.6, 1, 3, 6, 9, 20}, |
| 291 | }, |
| 292 | []string{"method", "code"}, |
| 293 | ) |
| 294 | requestsTotal := promauto.With(reg).NewCounterVec( |
| 295 | prometheus.CounterOpts{ |
| 296 | Name: "http_client_requests_total", |
| 297 | Help: "Tracks the number of HTTP requests.", |
| 298 | }, []string{"method", "code"}, |
| 299 | ) |
| 300 | responseInflight := promauto.With(reg).NewGauge( |
| 301 | prometheus.GaugeOpts{ |
| 302 | Name: "http_client_requests_inflight", |
| 303 | Help: "Tracks the number of client requests currently in progress.", |
| 304 | }, |
| 305 | ) |
| 306 | |
| 307 | var base http.RoundTripper |
| 308 | base = promhttp.InstrumentRoundTripperCounter( |
| 309 | requestsTotal, |
| 310 | promhttp.InstrumentRoundTripperInFlight( |
| 311 | responseInflight, |
| 312 | promhttp.InstrumentRoundTripperDuration(requestDuration, rt, promhttp.WithExemplarFromContext(getExemplarFn)), |
| 313 | ), |
| 314 | promhttp.WithExemplarFromContext(getExemplarFn), |
| 315 | ) |
| 316 | |
| 317 | // Wrap with tracing. This will be visited as a first middleware. |
| 318 | return tracinghttp.NewTripperware().WrapRoundTipper(clientName, base) |
| 319 | } |
no test coverage detected