diff --git a/go.mod b/go.mod index ed0a47e9c8..1e4cdf937f 100644 --- a/go.mod +++ b/go.mod @@ -15,12 +15,10 @@ require ( github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.6 github.com/google/uuid v1.1.2 - github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 github.com/nats-io/nats-streaming-server v0.22.1 github.com/nats-io/stan.go v0.10.0 github.com/networkservicemesh/api v1.0.1-0.20211110183123-3038992da61a github.com/open-policy-agent/opa v0.16.1 - github.com/opentracing/opentracing-go v1.2.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.4.0.20200528145730-dc11d0c74e85 diff --git a/go.sum b/go.sum index c42f31830b..ea6df686f8 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 h1:MJG/KsmcqMwFAkh8mTnAwhyKoB+sTAnY4CACC110tbU= -github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs= @@ -212,8 +210,6 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/open-policy-agent/opa v0.16.1 h1:BDADmi1Xl08aPcubaYgSEU0lJ/zrWDwmFMRXVPX856c= github.com/open-policy-agent/opa v0.16.1/go.mod h1:P0xUE/GQAAgnvV537GzA0Ikw4+icPELRT327QJPkaKY= -github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.3.0 h1:XtuXmOLIXLjiU2XduuWREDT0LOKtSgos/g7i7RYyoZQ= github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/pkg/tools/log/logger.go b/pkg/tools/log/logger.go index 3e58de77dc..5978ae55eb 100644 --- a/pkg/tools/log/logger.go +++ b/pkg/tools/log/logger.go @@ -29,19 +29,11 @@ const ( logKey contextKeyType = "Logger" telemetryEnv = "TELEMETRY" - telemetryOT = "opentracing" telemetryOTel = "opentelemetry" - // Opentracing enabled by default telemetryDefault = telemetryOTel ) -// IsOpentracingEnabled returns true if opentracing enabled -func IsOpentracingEnabled() bool { - return telemetryOT == getTelemetryEnv() -} - -// IsOpentelemetryEnabled returns true if opentelemetry enabled func IsOpentelemetryEnabled() bool { return telemetryOTel == getTelemetryEnv() } diff --git a/pkg/tools/log/spanlogger/span.go b/pkg/tools/log/spanlogger/span.go index acbdbcd547..1a76c802f5 100644 --- a/pkg/tools/log/spanlogger/span.go +++ b/pkg/tools/log/spanlogger/span.go @@ -20,14 +20,12 @@ import ( "context" "fmt" - "github.com/opentracing/opentracing-go" - opentracinglog "github.com/opentracing/opentracing-go/log" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" opentelemetry "go.opentelemetry.io/otel/trace" ) -// Span - unified interface for opentracing/opentelemetry spans +// Span - unified interface for opentelemetry spans type Span interface { Log(level, format string, v ...interface{}) LogObject(k, v interface{}) @@ -37,46 +35,6 @@ type Span interface { ToString() string } -// Opentracing span -type otSpan struct { - span opentracing.Span -} - -func (otsp *otSpan) Log(level, format string, v ...interface{}) { - otsp.span.LogFields( - opentracinglog.String("event", level), - opentracinglog.String("message", fmt.Sprintf(format, v...)), - ) -} - -func (otsp *otSpan) LogObject(k, v interface{}) { - otsp.span.LogFields(opentracinglog.Object(k.(string), v)) -} - -func (otsp *otSpan) WithField(k, v interface{}) Span { - otsp.span = otsp.span.SetTag(k.(string), v) - return otsp -} - -func (otsp *otSpan) ToString() string { - if spanStr := fmt.Sprintf("%v", otsp.span); spanStr != "{}" { - return spanStr - } - return "" -} - -func (otsp *otSpan) Finish() { - otsp.span.Finish() -} - -func newOTSpan(ctx context.Context, operationName string, additionalFields map[string]interface{}) (c context.Context, s Span) { - span, ctx := opentracing.StartSpanFromContext(ctx, operationName) - for k, v := range additionalFields { - span = span.SetTag(k, v) - } - return ctx, &otSpan{span: span} -} - // Opentelemetry span type otelSpan struct { span opentelemetry.Span diff --git a/pkg/tools/log/spanlogger/spanlogger.go b/pkg/tools/log/spanlogger/spanlogger.go index d4721a7e92..6f9196b614 100644 --- a/pkg/tools/log/spanlogger/spanlogger.go +++ b/pkg/tools/log/spanlogger/spanlogger.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package spanlogger provides a set of utilities to assist in working with opentracing spans +// Package spanlogger provides a set of utilities to assist in working with spans package spanlogger import ( @@ -26,7 +26,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log" ) -// spanlogger - provides a way to log via opentracing spans +// spanlogger - provides a way to log via opentelemetry spans type spanLogger struct { span Span lock sync.RWMutex @@ -129,9 +129,7 @@ func (s *spanLogger) logf(level, format string, v ...interface{}) { // FromContext - creates a new spanLogger from context and operation func FromContext(ctx context.Context, operation string, fields map[string]interface{}) (context.Context, log.Logger, Span, func()) { var span Span - if log.IsOpentracingEnabled() { - ctx, span = newOTSpan(ctx, operation, fields) - } else if log.IsOpentelemetryEnabled() { + if log.IsOpentelemetryEnabled() { ctx, span = newOTELSpan(ctx, operation, fields) } newLog := &spanLogger{ diff --git a/pkg/tools/tracing/grpcoptions.go b/pkg/tools/tracing/grpcoptions.go index 3cbb08c04d..4d089eb623 100644 --- a/pkg/tools/tracing/grpcoptions.go +++ b/pkg/tools/tracing/grpcoptions.go @@ -16,7 +16,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package tracing provides a set of utilities to assist in working with opentracing and opentelemetry +// Package tracing provides a set of utilities to assist in working with opentelemetry package tracing import ( @@ -27,30 +27,12 @@ import ( "google.golang.org/grpc" "google.golang.org/protobuf/proto" - "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" - "github.com/opentracing/opentracing-go" - "github.com/networkservicemesh/sdk/pkg/tools/log" ) -// WithTracing - returns array of grpc.ServerOption that should be passed to grpc.Dial to enable opentracing/opentelemetry tracing +// WithTracing - returns array of grpc.ServerOption that should be passed to grpc.Dial to enable opentelemetry tracing func WithTracing() []grpc.ServerOption { - if log.IsOpentracingEnabled() { - interceptor := func( - ctx context.Context, - req interface{}, - info *grpc.UnaryServerInfo, - handler grpc.UnaryHandler, - ) (resp interface{}, err error) { - return otgrpc.OpenTracingServerInterceptor(opentracing.GlobalTracer())(ctx, proto.Clone(req.(proto.Message)), info, handler) - } - return []grpc.ServerOption{ - grpc.ChainUnaryInterceptor( - interceptor), - grpc.ChainStreamInterceptor( - otgrpc.OpenTracingStreamServerInterceptor(opentracing.GlobalTracer())), - } - } else if log.IsOpentelemetryEnabled() { + if log.IsOpentelemetryEnabled() { interceptor := func( ctx context.Context, req interface{}, @@ -71,26 +53,9 @@ func WithTracing() []grpc.ServerOption { } } -// WithTracingDial returns array of grpc.DialOption that should be passed to grpc.Dial to enable opentracing/opentelemetry tracing +// WithTracingDial returns array of grpc.DialOption that should be passed to grpc.Dial to enable opentelemetry tracing func WithTracingDial() []grpc.DialOption { - if log.IsOpentracingEnabled() { - interceptor := func( - ctx context.Context, - method string, - req, reply interface{}, - cc *grpc.ClientConn, - invoker grpc.UnaryInvoker, - opts ...grpc.CallOption, - ) error { - return otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer())(ctx, method, proto.Clone(req.(proto.Message)), reply, cc, invoker, opts...) - } - return []grpc.DialOption{ - grpc.WithChainUnaryInterceptor( - interceptor), - grpc.WithChainStreamInterceptor( - otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer())), - } - } else if log.IsOpentelemetryEnabled() { + if log.IsOpentelemetryEnabled() { interceptor := func( ctx context.Context, method string,