-
Notifications
You must be signed in to change notification settings - Fork 40
/
http.go
44 lines (36 loc) · 1006 Bytes
/
http.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
package perf
import (
"net/http"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/stats/view"
)
// See https://opencensus.io/guides/http/go/net_http/server/
func registerHTTPViews() error {
if err := view.Register(ochttp.DefaultServerViews...); err != nil {
return err
}
if err := view.Register(ochttp.DefaultClientViews...); err != nil {
return err
}
return nil
}
// WrapHTTPHandlerForStats wraps a http handler with stats collection writing to opencensus.
//
// Example:
//
// httpHandler := goji.NewMux()
// hanlderWithStats = perf.WrapHTTPHandlerForStats(httpHandler)
func WrapHTTPHandlerForStats(h http.Handler) http.Handler {
return &ochttp.Handler{
Handler: h,
IsPublicEndpoint: true,
}
}
// NewRoundTripperWithStats creates a new RoundTripper with stats collecting writing to opencensus.
//
// Example:
//
// client := &http.Client{Transport: perf.NewRoundTripperWithStats()},
func NewRoundTripperWithStats() http.RoundTripper {
return new(ochttp.Transport)
}