Skip to content

Commit

Permalink
Remove deprecated opentelemetry interceptors (#1712)
Browse files Browse the repository at this point in the history
* remove deprecated opentelemtry interceprtors

Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>

* remove some excluded rules from golang config

Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>

---------

Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik authored Dec 27, 2024
1 parent 4a9b9a0 commit d442a26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 45 deletions.
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,3 @@ issues:
- path: pkg/tools/opa/policies.go
linters:
- revive
# TODO - remove deprecated opentelemetry functions - https://github.com/networkservicemesh/sdk/issues/1691
- path: pkg/tools/tracing/grpcoptions.go
linters:
- staticcheck
text: "SA1019: otelgrpc.*"
48 changes: 8 additions & 40 deletions pkg/tools/tracing/grpcoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2024 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,60 +22,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 d442a26

Please sign in to comment.