mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-25 12:26:26 +00:00
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package tracing
|
|
|
|
import (
|
|
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
|
"google.golang.org/grpc"
|
|
|
|
"go.linka.cloud/grpc-toolkit/interceptors"
|
|
)
|
|
|
|
type tracing struct {
|
|
opts []otelgrpc.Option
|
|
}
|
|
|
|
func NewInterceptors(opts ...otelgrpc.Option) interceptors.Interceptors {
|
|
return tracing{opts: opts}
|
|
}
|
|
|
|
func NewClientInterceptors(opts ...otelgrpc.Option) interceptors.ClientInterceptors {
|
|
return tracing{opts: opts}
|
|
}
|
|
|
|
func (t tracing) UnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
|
return otelgrpc.UnaryClientInterceptor(t.opts...)
|
|
}
|
|
|
|
func (t tracing) StreamClientInterceptor() grpc.StreamClientInterceptor {
|
|
return otelgrpc.StreamClientInterceptor(t.opts...)
|
|
}
|
|
|
|
func NewServerInterceptors(opts ...otelgrpc.Option) interceptors.ServerInterceptors {
|
|
return tracing{opts: opts}
|
|
}
|
|
|
|
func (t tracing) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
|
return otelgrpc.UnaryServerInterceptor(t.opts...)
|
|
}
|
|
|
|
func (t tracing) StreamServerInterceptor() grpc.StreamServerInterceptor {
|
|
return otelgrpc.StreamServerInterceptor(t.opts...)
|
|
}
|