question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scopeManager#activate creates new scope every time it's called

See original GitHub issue

For 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:closed
  • Created 4 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
whiskeysierracommented, Jul 17, 2019

It’s more robust if you activate the same Span twice and get the same Scope instance activated than having 2 Scopes for this Span.

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.)

  1. L1: Activate span
  2. L2: Activate span
  3. L2: Close scope
  4. L1: Close scope

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) and scope 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.

1reaction
whiskeysierracommented, Jul 17, 2019

Seems like we could “detect” the currently active span without the concept of Scope

The thread local approach doesn’t work for reactive, non-blocking applications that work with an event loop.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found