2021-11-21 13:58:49 +00:00
|
|
|
package tracing
|
|
|
|
|
|
|
|
import (
|
2024-10-17 15:15:05 +00:00
|
|
|
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
2021-11-21 13:58:49 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2023-07-07 23:33:10 +00:00
|
|
|
"go.linka.cloud/grpc-toolkit/interceptors"
|
2021-11-21 13:58:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type tracing struct {
|
2024-10-17 15:15:05 +00:00
|
|
|
opts []otelgrpc.Option
|
2021-11-21 13:58:49 +00:00
|
|
|
}
|
|
|
|
|
2024-10-17 15:15:05 +00:00
|
|
|
func NewInterceptors(opts ...otelgrpc.Option) interceptors.Interceptors {
|
2021-11-21 13:58:49 +00:00
|
|
|
return tracing{opts: opts}
|
|
|
|
}
|
|
|
|
|
2024-10-17 15:15:05 +00:00
|
|
|
func NewClientInterceptors(opts ...otelgrpc.Option) interceptors.ClientInterceptors {
|
2021-11-21 13:58:49 +00:00
|
|
|
return tracing{opts: opts}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t tracing) UnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
2024-10-17 15:15:05 +00:00
|
|
|
return otelgrpc.UnaryClientInterceptor(t.opts...)
|
2021-11-21 13:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t tracing) StreamClientInterceptor() grpc.StreamClientInterceptor {
|
2024-10-17 15:15:05 +00:00
|
|
|
return otelgrpc.StreamClientInterceptor(t.opts...)
|
2021-11-21 13:58:49 +00:00
|
|
|
}
|
|
|
|
|
2024-10-17 15:15:05 +00:00
|
|
|
func NewServerInterceptors(opts ...otelgrpc.Option) interceptors.ServerInterceptors {
|
2021-11-21 13:58:49 +00:00
|
|
|
return tracing{opts: opts}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t tracing) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
2024-10-17 15:15:05 +00:00
|
|
|
return otelgrpc.UnaryServerInterceptor(t.opts...)
|
2021-11-21 13:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t tracing) StreamServerInterceptor() grpc.StreamServerInterceptor {
|
2024-10-17 15:15:05 +00:00
|
|
|
return otelgrpc.StreamServerInterceptor(t.opts...)
|
2021-11-21 13:58:49 +00:00
|
|
|
}
|