Skip to content

Commit

Permalink
Update opentracing bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Oct 13, 2023
1 parent da0b080 commit b6d9f5c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
15 changes: 8 additions & 7 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import (
iBaggage "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)

var (
noopTracer = trace.NewNoopTracerProvider().Tracer("")
noopTracer = noop.NewTracerProvider().Tracer("")
noopSpan = func() trace.Span {
_, s := noopTracer.Start(context.Background(), "")
return s
Expand Down Expand Up @@ -317,8 +318,10 @@ type BridgeTracer struct {
propagator propagation.TextMapPropagator
}

var _ ot.Tracer = &BridgeTracer{}
var _ ot.TracerContextWithSpanExtension = &BridgeTracer{}
var (
_ ot.Tracer = &BridgeTracer{}
_ ot.TracerContextWithSpanExtension = &BridgeTracer{}
)

// NewBridgeTracer creates a new BridgeTracer. The new tracer forwards
// the calls to the OpenTelemetry Noop tracer, so it should be
Expand Down Expand Up @@ -829,15 +832,13 @@ func newTextMapWrapperForInject(carrier interface{}) (*textMapWrapper, error) {
return t, nil
}

type textMapWriter struct {
}
type textMapWriter struct{}

func (t *textMapWriter) Set(key string, value string) {
// maybe print a warning log.
}

type textMapReader struct {
}
type textMapReader struct{}

func (t *textMapReader) ForeachKey(handler func(key, val string) error) error {
return nil // maybe print a warning log.
Expand Down
20 changes: 15 additions & 5 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"
)

//nolint:revive // ignoring missing comments for unexported global variables in an internal package.
Expand All @@ -44,6 +46,8 @@ type MockContextKeyValue struct {
}

type MockTracer struct {
embedded.Tracer

FinishedSpans []*MockSpan
SpareTraceIDs []trace.TraceID
SpareSpanIDs []trace.SpanID
Expand All @@ -54,8 +58,10 @@ type MockTracer struct {
rand *rand.Rand
}

var _ trace.Tracer = &MockTracer{}
var _ migration.DeferredContextSetupTracerExtension = &MockTracer{}
var (
_ trace.Tracer = &MockTracer{}
_ migration.DeferredContextSetupTracerExtension = &MockTracer{}
)

func NewMockTracer() *MockTracer {
return &MockTracer{
Expand Down Expand Up @@ -182,6 +188,8 @@ type MockEvent struct {
}

type MockSpan struct {
embedded.Span

mockTracer *MockTracer
officialTracer trace.Tracer
spanContext trace.SpanContext
Expand All @@ -195,8 +203,10 @@ type MockSpan struct {
Events []MockEvent
}

var _ trace.Span = &MockSpan{}
var _ migration.OverrideTracerSpanExtension = &MockSpan{}
var (
_ trace.Span = &MockSpan{}
_ migration.OverrideTracerSpanExtension = &MockSpan{}
)

func (s *MockSpan) SpanContext() trace.SpanContext {
return s.spanContext
Expand Down Expand Up @@ -291,4 +301,4 @@ func (s *MockSpan) OverrideTracer(tracer trace.Tracer) {
s.officialTracer = tracer
}

func (s *MockSpan) TracerProvider() trace.TracerProvider { return trace.NewNoopTracerProvider() }
func (s *MockSpan) TracerProvider() trace.TracerProvider { return noop.NewTracerProvider() }
3 changes: 3 additions & 0 deletions bridge/opentracing/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import (
"sync"

"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

// TracerProvider is an OpenTelemetry TracerProvider that wraps an OpenTracing
// Tracer.
type TracerProvider struct {
embedded.TracerProvider

bridge *BridgeTracer
provider trace.TracerProvider

Expand Down
3 changes: 2 additions & 1 deletion bridge/opentracing/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (

"go.opentelemetry.io/otel/bridge/opentracing/internal"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

type namedMockTracer struct {
name string
*internal.MockTracer
}

type namedMockTracerProvider struct{}
type namedMockTracerProvider struct{ embedded.TracerProvider }

var _ trace.TracerProvider = (*namedMockTracerProvider)(nil)

Expand Down
11 changes: 9 additions & 2 deletions bridge/opentracing/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import (

"go.opentelemetry.io/otel/bridge/opentracing/migration"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

// WrapperTracerProvider is an OpenTelemetry TracerProvider that wraps an
// OpenTracing Tracer, created by the deprecated NewWrappedTracerProvider.
//
// Deprecated: Use the TracerProvider from NewTracerProvider(...) instead.
type WrapperTracerProvider struct {
embedded.TracerProvider

wTracer *WrapperTracer
}

Expand Down Expand Up @@ -56,12 +59,16 @@ func NewWrappedTracerProvider(bridge *BridgeTracer, tracer trace.Tracer) *Wrappe
// aware how to operate in environment where OpenTracing API is also
// used.
type WrapperTracer struct {
embedded.Tracer

bridge *BridgeTracer
tracer trace.Tracer
}

var _ trace.Tracer = &WrapperTracer{}
var _ migration.DeferredContextSetupTracerExtension = &WrapperTracer{}
var (
_ trace.Tracer = &WrapperTracer{}
_ migration.DeferredContextSetupTracerExtension = &WrapperTracer{}
)

// NewWrapperTracer wraps the passed tracer and also talks to the
// passed bridge tracer when setting up the context with the new
Expand Down

0 comments on commit b6d9f5c

Please sign in to comment.