-
Notifications
You must be signed in to change notification settings - Fork 0
/
artemis.go
51 lines (38 loc) · 1.27 KB
/
artemis.go
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
42
43
44
45
46
47
48
49
50
51
package artemis
import (
"net/http"
"net/http/httptrace"
"time"
"github.com/prometheus/client_golang/prometheus"
)
type Tracer struct {
Metrics *TracingMetrics
}
func NewTracer(namespace string) *Tracer {
metrics := NewTracingMetrics(namespace)
collectors := metrics.GetCollectors()
prometheus.MustRegister(collectors...)
return &Tracer{
Metrics: metrics,
}
}
func (t *Tracer) RequestWithTracer(request *http.Request) *http.Request {
requestStart := time.Now()
httpTracer := NewHttpTracer(requestStart, t.Metrics, request.Method, request.URL.Host)
clientTrace := &httptrace.ClientTrace{
GetConn: httpTracer.GetConn,
GotConn: httpTracer.GotConn,
GotFirstResponseByte: httpTracer.GotFirstResponseByte,
DNSStart: httpTracer.DNSStart,
DNSDone: httpTracer.DNSDone,
ConnectStart: httpTracer.ConnStart,
ConnectDone: httpTracer.ConnDone,
TLSHandshakeStart: httpTracer.TLSHandshakeStart,
TLSHandshakeDone: httpTracer.TLSHandshakeDone,
WroteHeaders: httpTracer.WroteHeaders,
WroteRequest: httpTracer.WroteRequest,
}
clientTraceCtx := httptrace.WithClientTrace(request.Context(), clientTrace)
tracerRequest := request.WithContext(clientTraceCtx)
return tracerRequest
}