diff --git a/bridge/opentracing/bridge.go b/bridge/opentracing/bridge.go index 50ff21a191a..cc3d7d19c7f 100644 --- a/bridge/opentracing/bridge.go +++ b/bridge/opentracing/bridge.go @@ -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 @@ -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 @@ -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. diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 64e95604278..d3a8d91a30a 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -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. @@ -44,6 +46,8 @@ type MockContextKeyValue struct { } type MockTracer struct { + embedded.Tracer + FinishedSpans []*MockSpan SpareTraceIDs []trace.TraceID SpareSpanIDs []trace.SpanID @@ -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{ @@ -182,6 +188,8 @@ type MockEvent struct { } type MockSpan struct { + embedded.Span + mockTracer *MockTracer officialTracer trace.Tracer spanContext trace.SpanContext @@ -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 @@ -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() } diff --git a/bridge/opentracing/provider.go b/bridge/opentracing/provider.go index 941e277baf8..90bad0bd516 100644 --- a/bridge/opentracing/provider.go +++ b/bridge/opentracing/provider.go @@ -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 diff --git a/bridge/opentracing/provider_test.go b/bridge/opentracing/provider_test.go index 8af3796e031..1a4dd5ca5b5 100644 --- a/bridge/opentracing/provider_test.go +++ b/bridge/opentracing/provider_test.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/otel/bridge/opentracing/internal" "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/otel/trace/embedded" ) type namedMockTracer struct { @@ -26,7 +27,7 @@ type namedMockTracer struct { *internal.MockTracer } -type namedMockTracerProvider struct{} +type namedMockTracerProvider struct{ embedded.TracerProvider } var _ trace.TracerProvider = (*namedMockTracerProvider)(nil) diff --git a/bridge/opentracing/wrapper.go b/bridge/opentracing/wrapper.go index 3e348c45523..1e065e3bc62 100644 --- a/bridge/opentracing/wrapper.go +++ b/bridge/opentracing/wrapper.go @@ -19,6 +19,7 @@ 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 @@ -26,6 +27,8 @@ import ( // // Deprecated: Use the TracerProvider from NewTracerProvider(...) instead. type WrapperTracerProvider struct { + embedded.TracerProvider + wTracer *WrapperTracer } @@ -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