-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathinstrumentation.go
More file actions
29 lines (26 loc) · 1.06 KB
/
instrumentation.go
File metadata and controls
29 lines (26 loc) · 1.06 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
package grpcclient
import (
otgrpc "github.com/opentracing-contrib/go-grpc"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
"github.com/grafana/dskit/middleware"
)
func Instrument(requestDuration *prometheus.HistogramVec, instrumentationLabelOptions ...middleware.InstrumentationOption) ([]grpc.UnaryClientInterceptor, []grpc.StreamClientInterceptor) {
var (
unary []grpc.UnaryClientInterceptor
stream []grpc.StreamClientInterceptor
)
if opentracing.IsGlobalTracerRegistered() {
unary = append(unary, otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()))
stream = append(stream, otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer()))
}
return append(unary,
middleware.ClientUserHeaderInterceptor,
middleware.UnaryClientInstrumentInterceptor(requestDuration, instrumentationLabelOptions...),
),
append(stream,
middleware.StreamClientUserHeaderInterceptor,
middleware.StreamClientInstrumentInterceptor(requestDuration, instrumentationLabelOptions...),
)
}