From a6d702109e96c44bf2cff341c9e421412c1ba864 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Thu, 26 Dec 2024 14:05:56 +1100 Subject: [PATCH 1/2] remove deprecated opentelemtry interceprtors Signed-off-by: NikitaSkrynnik --- pkg/tools/tracing/grpcoptions.go | 46 +++++--------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/pkg/tools/tracing/grpcoptions.go b/pkg/tools/tracing/grpcoptions.go index 01a6e5436..d765d2ab4 100644 --- a/pkg/tools/tracing/grpcoptions.go +++ b/pkg/tools/tracing/grpcoptions.go @@ -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 } From 03a8b86dc357c6f95fce1c0b3ac60e7dae1f3fd7 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Thu, 26 Dec 2024 14:08:24 +1100 Subject: [PATCH 2/2] remove some excluded rules from golang config Signed-off-by: NikitaSkrynnik --- .golangci.yml | 5 ----- pkg/tools/tracing/grpcoptions.go | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6816afee2..b4c064e1e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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.*" diff --git a/pkg/tools/tracing/grpcoptions.go b/pkg/tools/tracing/grpcoptions.go index d765d2ab4..d933d9e67 100644 --- a/pkg/tools/tracing/grpcoptions.go +++ b/pkg/tools/tracing/grpcoptions.go @@ -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");