Skip to content

Commit

Permalink
remove deprecated opentelemtry interceprtors
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Dec 26, 2024
1 parent 4a9b9a0 commit a6d7021
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions pkg/tools/tracing/grpcoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,26 @@
package tracing

import (
"context"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
)

// WithTracing - returns array of grpc.ServerOption that should be passed to grpc.Dial to enable opentelemetry tracing
func WithTracing() []grpc.ServerOption {
opts := []grpc.ServerOption{}
if opentelemetry.IsEnabled() {
interceptor := func(
ctx context.Context,
req interface{},
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (resp interface{}, err error) {
return otelgrpc.UnaryServerInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))(ctx, proto.Clone(req.(proto.Message)), info, handler)
}
return []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
interceptor),
grpc.ChainStreamInterceptor(
otelgrpc.StreamServerInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))),
}
}
return []grpc.ServerOption{
grpc.EmptyServerOption{},
opts = append(opts, grpc.StatsHandler(otelgrpc.NewServerHandler()))
}
return opts
}

// WithTracingDial returns array of grpc.DialOption that should be passed to grpc.Dial to enable opentelemetry tracing
func WithTracingDial() []grpc.DialOption {
opts := []grpc.DialOption{}
if opentelemetry.IsEnabled() {
interceptor := func(
ctx context.Context,
method string,
req, reply interface{},
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
) error {
return otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))(ctx, method, proto.Clone(req.(proto.Message)), reply, cc, invoker, opts...)
}
return []grpc.DialOption{
grpc.WithChainUnaryInterceptor(
interceptor),
grpc.WithChainStreamInterceptor(
otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))),
}
}
return []grpc.DialOption{
grpc.EmptyDialOption{},
opts = append(opts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
}
return opts
}

0 comments on commit a6d7021

Please sign in to comment.