Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated opentelemetry interceptors #1712

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading