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

Incorrect behavior for default unimplemented API span Tracer method #1892

Closed
MrAlias opened this issue May 7, 2021 · 1 comment · Fixed by #1900
Closed

Incorrect behavior for default unimplemented API span Tracer method #1892

MrAlias opened this issue May 7, 2021 · 1 comment · Fixed by #1900
Assignees
Labels
area:trace Part of OpenTelemetry tracing bug Something isn't working
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented May 7, 2021

Description

Spans created prior to an SDK being set have a Tracer method will always return a noopTracer instead of a delegating tracer.

Environment

  • opentelemetry-go version: v0.20.0

Steps To Reproduce

package otel

import (
	"context"
	"testing"

	"go.opentelemetry.io/otel/internal/trace/noop"
	"go.opentelemetry.io/otel/trace"
)

type testTracerProvider struct {
	tracers map[string]trace.Tracer
}

func newTestTracerProvider() *testTracerProvider {
	return &testTracerProvider{tracers: make(map[string]trace.Tracer)}
}

func (t *testTracerProvider) Tracer(name string, _ ...trace.TracerOption) trace.Tracer {
	tracer, ok := t.tracers[name]
	if ok {
		return tracer
	}

	tracer = &testTracer{name: name}
	t.tracers[name] = tracer
	return tracer
}

type testTracer struct {
	name string
}

func (*testTracer) Start(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span) {
	return noop.Tracer.Start(ctx, name, opts...)
}

func TestTracerDelegation(t *testing.T) {
	defaultTracer := Tracer("test")
	_, span := defaultTracer.Start(context.Background(), "test")

	tp := newTestTracerProvider()
	tracer := tp.Tracer("test")
	SetTracerProvider(tp)
	if got, ok := span.Tracer().(*testTracer); !ok {
		t.Errorf("set tracer not delegated: got %T, want %T", span.Tracer(), tracer)
	} else if got != tracer {
		t.Errorf("incorrect tracer delegation: got %#v, want %#v", got, tracer)
	}
}

Expected behavior

The Tracer returned from the span's method should be the delegating Tracer that will create non-noop spans after the delegation.

@MrAlias MrAlias added bug Something isn't working area:trace Part of OpenTelemetry tracing labels May 7, 2021
@MrAlias MrAlias added this to the RC1 milestone May 7, 2021
@MrAlias MrAlias self-assigned this May 7, 2021
@MrAlias
Copy link
Contributor Author

MrAlias commented May 10, 2021

As was pointed out in this comment it is likely a better approach to just remove the Tracer method from the Span interface and implementation. A consequence of this will be that there will not be a one-to-one mapping of OpenTracing spans, which also have this method, and OTel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant