Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Span.End should restore the context if it was started using StartScopedSpan #249

Open
SergeyKanzhelev opened this issue Mar 14, 2019 · 0 comments

Comments

@SergeyKanzhelev
Copy link
Member

Today the way to start and stop scoped spans is to use a code like this:

	// 4. Create a scoped span, a scoped span will automatically end when closed.
	// It implements AutoClosable, so it'll be closed when the try block ends.
	try (Scope scope = tracer.spanBuilder("main").startScopedSpan()) {
		System.out.println("About to do some busy work...");
		for (int i = 0; i < 10; i++) {
			doWork(i);
		}
	}

User have to propagate the Scope object between the start and stop points.

Code that semantically feels the same way will not restore context:

tracer.spanBuilder("main").startScopedSpan();
System.out.println("About to do some busy work...");
for (int i = 0; i < 10; i++) {
  doWork(i);
}
tracer.getCurrentSpan().End();

And the code above may be a reality when instrumenting libraries which only expose Start and Stop callbacks. The only viable way to propagate Scope object between those callbacks may be storing this Scope object in the context the same way as Span object already saved there. So the proposal is to simplify instrumentation of those libraries.

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

No branches or pull requests

1 participant