Skip to content

Commit

Permalink
remove opentracing
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Jan 11, 2022
1 parent 62ed3bb commit 1937927
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 102 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 0 additions & 8 deletions pkg/tools/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
44 changes: 1 addition & 43 deletions pkg/tools/log/spanlogger/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions pkg/tools/log/spanlogger/spanlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down
45 changes: 5 additions & 40 deletions pkg/tools/tracing/grpcoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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{},
Expand All @@ -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,
Expand Down

0 comments on commit 1937927

Please sign in to comment.