-
Notifications
You must be signed in to change notification settings - Fork 0
/
interceptors.go
41 lines (31 loc) · 1.2 KB
/
interceptors.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
package tracing
import (
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
"go.linka.cloud/grpc-toolkit/interceptors"
)
type tracing struct {
opts []otgrpc.Option
}
func NewInterceptors(opts ...otgrpc.Option) interceptors.Interceptors {
return tracing{opts: opts}
}
func NewClientInterceptors(opts ...otgrpc.Option) interceptors.ClientInterceptors {
return tracing{opts: opts}
}
func (t tracing) UnaryClientInterceptor() grpc.UnaryClientInterceptor {
return otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer(), t.opts...)
}
func (t tracing) StreamClientInterceptor() grpc.StreamClientInterceptor {
return otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer(), t.opts...)
}
func NewServerInterceptors(opts ...otgrpc.Option) interceptors.ServerInterceptors {
return tracing{opts: opts}
}
func (t tracing) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
return otgrpc.OpenTracingServerInterceptor(opentracing.GlobalTracer(), t.opts...)
}
func (t tracing) StreamServerInterceptor() grpc.StreamServerInterceptor {
return otgrpc.OpenTracingStreamServerInterceptor(opentracing.GlobalTracer(), t.opts...)
}