-
Notifications
You must be signed in to change notification settings - Fork 693
Expand file tree
/
Copy pathinstrumentation.go
More file actions
41 lines (34 loc) · 1 KB
/
instrumentation.go
File metadata and controls
41 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package azure
import (
"net/http"
"strconv"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
azureRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "tempodb",
Name: "azure_request_duration_seconds",
Help: "Time spent doing Azure requests.",
Buckets: prometheus.ExponentialBuckets(0.005, 4, 6),
}, []string{"operation", "status_code"})
)
type instrumentedTransport struct {
observer prometheus.ObserverVec
next http.RoundTripper
}
func newInstrumentedTransport(next http.RoundTripper) http.RoundTripper {
return instrumentedTransport{
observer: azureRequestDuration,
next: next,
}
}
func (i instrumentedTransport) RoundTrip(req *http.Request) (*http.Response, error) {
start := time.Now()
resp, err := i.next.RoundTrip(req)
if err == nil {
i.observer.WithLabelValues(req.Method, strconv.Itoa(resp.StatusCode)).Observe(time.Since(start).Seconds())
}
return resp, err
}