MCPcopy
hub / github.com/prometheus/client_golang / instrumentRoundTripper

Function instrumentRoundTripper

tutorials/whatsup/reference/main.go:283–319  ·  view source on GitHub ↗
(reg prometheus.Registerer, clientName string, rt http.RoundTripper)

Source from the content-addressed store, hash-verified

281}
282
283func 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}

Callers 1

runMainFunction · 0.70

Calls 9

WrapRegistererWithFunction · 0.92
WithFunction · 0.92
WithExemplarFromContextFunction · 0.92
NewGaugeMethod · 0.80
NewHistogramVecMethod · 0.45
NewCounterVecMethod · 0.45

Tested by

no test coverage detected