This Release Candidate proposes an approach to managed Span propagation without enforcing Span lifetime handling through (in-code) reference counting.
- Decouple active Span propagation from Span.finish().
- Remove ActiveSpan/ActiveSpanManager reference counting.
ScopereplacesActiveSpan, removing theContinuationconcept.ScopeManagerreplacesActiveSpanSource, and is expected to be passed to theTraceron initialization time.ScopeManager.activate()is used to activateSpanobjects, and can optionally receive afinishOnCloseflag, to either close theSpanor not onScope.close().BaseSpanwas removed for clarity, at the expense of extra typing when traversing from Span to Scope.Scopeis left with only two meaningful methods:span()andclose().ThreadLocalScopeManagerreplacesThreadLocalActiveSpanSource, keeping the thread-local storage for activeSpan, without the reference counting used forSpanlifetime handling.
- By default, using a
try (Scope scope = ...also finishes the relatedSpan. - To not finish the span when the scope closes, you must call
ScopeManager.activate(span, false)instead.
The inclusion of Continuations and automatic reference counting in 0.30.0 was contentious. The lack of Continuation in the Scope will require some thought on possible migration paths for current users. For most use cases, where the call site to finish is known, the migration should be trivial, but it is possible that there are non-trivial cases.
Furthermore, though they complicate the API, Continuations may have indeed been a requirement for an OpenTracing API that can handle all scenarios. A very important part of testing and exercising this Release Candidate will be around this issue. If Continuations can be proven to be necessary, a follow up Release Candidate will be issued which returns to that pattern.