mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 09:12:28 +00:00
interceptors: migrate to otel and add logging interceptor
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@ -1,41 +1,40 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"go.linka.cloud/grpc-toolkit/interceptors"
|
||||
)
|
||||
|
||||
type tracing struct {
|
||||
opts []otgrpc.Option
|
||||
opts []otelgrpc.Option
|
||||
}
|
||||
|
||||
func NewInterceptors(opts ...otgrpc.Option) interceptors.Interceptors {
|
||||
func NewInterceptors(opts ...otelgrpc.Option) interceptors.Interceptors {
|
||||
return tracing{opts: opts}
|
||||
}
|
||||
|
||||
func NewClientInterceptors(opts ...otgrpc.Option) interceptors.ClientInterceptors {
|
||||
func NewClientInterceptors(opts ...otelgrpc.Option) interceptors.ClientInterceptors {
|
||||
return tracing{opts: opts}
|
||||
}
|
||||
|
||||
func (t tracing) UnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
||||
return otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer(), t.opts...)
|
||||
return otelgrpc.UnaryClientInterceptor(t.opts...)
|
||||
}
|
||||
|
||||
func (t tracing) StreamClientInterceptor() grpc.StreamClientInterceptor {
|
||||
return otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer(), t.opts...)
|
||||
return otelgrpc.StreamClientInterceptor(t.opts...)
|
||||
}
|
||||
|
||||
func NewServerInterceptors(opts ...otgrpc.Option) interceptors.ServerInterceptors {
|
||||
func NewServerInterceptors(opts ...otelgrpc.Option) interceptors.ServerInterceptors {
|
||||
return tracing{opts: opts}
|
||||
}
|
||||
|
||||
func (t tracing) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
||||
return otgrpc.OpenTracingServerInterceptor(opentracing.GlobalTracer(), t.opts...)
|
||||
return otelgrpc.UnaryServerInterceptor(t.opts...)
|
||||
}
|
||||
|
||||
func (t tracing) StreamServerInterceptor() grpc.StreamServerInterceptor {
|
||||
return otgrpc.OpenTracingStreamServerInterceptor(opentracing.GlobalTracer(), t.opts...)
|
||||
return otelgrpc.StreamServerInterceptor(t.opts...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user