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

Starting a new span from a context.Context is too laborious #609

Closed
seh opened this issue Apr 1, 2020 · 5 comments
Closed

Starting a new span from a context.Context is too laborious #609

seh opened this issue Apr 1, 2020 · 5 comments
Milestone

Comments

@seh
Copy link
Contributor

seh commented Apr 1, 2020

After using the opentelemetry-go library for a few days, I find it to be tediously verbose compared to my touchstone: Honeycomb's beeline-go library. My focus is on the task I perform most frequently in my code: starting a new span from a context.Context.

In opentelemetry-go today, the call sequence looks approximately like either

trace.SpanFromContext(ctx).Tracer().Start(ctx, ...

or

trace.SpanFromContext(ctx).Tracer().WithSpan(ctx, ...

This winds up performing the exact same context.Context lookup three times—extract a Span to get the current Tracer, then use that Tracer to start a new Span, which in turn tries to find the current Span in that same context.Context twice (the extra lookup buried in parent.GetSpanContextAndLinks). The result induces no change to the Tracer in use.

By contrast, beeline-go offers the StartSpan function. It wraps up that first call sequence above more concisely and more efficiently. It's true that there's no notion of an active Tracer whose implementation could vary, but in most cases that possibility is not relevant in the application or library code being instrumented. Looking around in opentelemetry-go, I know that there's also global.Tracer(string), which could cut down on the search for the current Tracer, but that forces a map lookup and risks pulling in the wrong Tracer.

Was there ever a function considered for this library like beeline-go's StartSpan? For an API that aspires to only publish interfaces, I can see how offering a concrete function like that is an odd duck, but it could live in the SDK.

@seh
Copy link
Contributor Author

seh commented Apr 1, 2020

For those with access to the "Honeycomb Pollinators" Slack team, we discussed this topic over the last few days in the "discuss-opentelemetry-beta" channel.

@seh seh changed the title Starting a new span from a context.Contex is too laborious Starting a new span from a context.Context is too laborious Apr 1, 2020
@rghetia
Copy link
Contributor

rghetia commented Apr 2, 2020

The intention was to have tracer work like a logger in each component.

var (
   tr = global.Tracer("example.com/componentA")
)

func DoWork(ctx context.Context) {
    ctx, span := tr.Start(ctx, "Some work")
}

@seh
Copy link
Contributor Author

seh commented Apr 2, 2020

Thank you for the suggestion, @rghetia, and for the follow-on discussion on today's SIG call. I'll try using this pattern and report back here shortly.

@seh
Copy link
Contributor Author

seh commented Apr 5, 2020

The pattern that @rghetia has been working well for me. Thank you for the advice.

For now, I don't see the Tracer's name emitted in any span attributes. Is there any plan to do so?

@Aneurysm9
Copy link
Member

For now, I don't see the Tracer's name emitted in any span attributes. Is there any plan to do so?

I'm not aware of any current plans, nor am I aware of any reason not to do so. If you'd like to open a new issue with a proposal we can discuss at a future SIG meeting.

I'm going to close this issue as it appears to have been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants