scopeManager#activate creates new scope every time it's called
See original GitHub issueFor me, it was intuitive that if I activate a span that is already active then nothing happens. Turns out, I leak Scope
instances if I do that.
Span span = ...
Scope scope1 = tracer.scopeManager().activate(span);
Scope scope2 = tracer.scopeManager().activate(span);
Scope scope3 = tracer.scopeManager().activate(span);
Would be great if scope1
, scope2
, and scope3
would be the same Scope instance. It is bit more code for the library but it is also a bit more user-friendly.
Found out about it in https://github.com/AxonFramework/extension-tracing/pull/17
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
ScopeManager (OpenTracing API 0.32.0-RC1 API) - javadoc.io
The ScopeManager interface abstracts both the activation of Span instances via activate(Span, boolean) and access to an active Span / Scope via active()...
Read more >dd-trace - Datadog has moved
This method works very similarly to tracer.trace() except it wraps a function so that tracer.trace() is called automatically every time the function is...
Read more >Cinnamon API 2.17.0 - com.lightbend.cinnamon.opentracing ...
new TracerSpecific() ... def activateScope(scopeManager: ScopeManager, span: Span, scope: Scope): Unit. Called ... Called when a new SpanContext is created.
Read more >Jaeger and OpenTracing java.lang.NoSuchMethodError: 'io ...
ScopeManager.active() is removed from Opentracing on OT version 0.31 and below. The latest version of this library is compatible with open ...
Read more >opentracing-python - Read the Docs
API to continue an active trace, creating a Span object in the process. ... If there is a Scope, it will act as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, it’s not. Here is why:
(L1 and L2 are two different layers in your application, e.g. two classes and L1 calls L2.)
The scope is closed after 3. Now in L1 before step 4, the layer has a reasonable expectation that the span that it activated is still active, but it no longer is. 💥
What you’re trying is to introduce an unnecessary entangling of span lifecycle (
start
+finish
) andscope management
(activate
+close
). Those two are orthogonal concerns and are better be kept apart. You can see this reflected in the most recent API versions because all methods that couple both concepts together are now removed:startActive()
.activate(span, closeOnFinish)
Whether you create a new span or use the currently active span is independent of whether you activate this span afterwards. If you couple them you’d violate the Principle of Least Knowledge because suddenly your inner layers need to know whether it’s safe to close the scopes that they obtain.
Now, when you keep those two things apart, as they are now you don’t have any of those problems. Every layer can choose to activate a span or not without the need to know about the outer/upper layer and without the fear of breaking anyone.
The thread local approach doesn’t work for reactive, non-blocking applications that work with an event loop.