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

Enabling NOOP classes to work with pre-existing production code #263

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

natehart
Copy link
Contributor

In special circumstances, code may automatically generate spans,
negating the need to always check if Tracer.activeSpan() is null. Under these
circumstances, the Noop Tracer and ScopeManager will cause NPEs when they return
null values when their active methods are accessed via the GlobalTracer. This
prevents code from running successfully when using Noop Tracers.

This minor change allows users to depend that their code will genuinely Noop
under all use cases.

Signed-off-by: Nate Hart nhart@tableau.com

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add license headers

@natehart
Copy link
Contributor Author

@yurishkuro I made a minor change to the MockTracer to work with the type assumptions baked into the tests. Not only does this allow the tests to propagate MockSpans as expected, but it brings the Propagator constructor closer into line with the no-argument constructor's default values. You may want to put eyes on it before I merge in case I changed a very intentional design decision.

@coveralls
Copy link

coveralls commented Mar 28, 2018

Coverage Status

Coverage decreased (-8.1%) to 73.368% when pulling cc63126 on natehart:nhart/npe_fix into 806b026 on opentracing:master.

@@ -59,7 +59,7 @@ public MockTracer(ScopeManager scopeManager, Propagator propagator) {
* Create a new MockTracer that passes through any calls to inject() and/or extract().
*/
public MockTracer(Propagator propagator) {
this(NoopScopeManager.INSTANCE, propagator);
this(new ThreadLocalScopeManager(), propagator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be done as another PR? It's completely unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but we'll have to merge that one first.

The MockTracer assumes that ScopeManager.active() either returns null or a scope that with a MockSpan. Since we are now returning a NoopScope (and thus a NoopSpan) from the NoopScopeManager, it tries to cast the NoopSpan to a MockSpan and blows up. We won't be able to get the Mock tests to pass until we remove the NoopScopeManager from the Mocks.

@natehart natehart force-pushed the nhart/npe_fix branch 3 times, most recently from 7da5d5e to 35f6009 Compare March 29, 2018 15:41
In special circumstances, code may be written to automatically create spans,
negating the need to always check if Tracer.activeSpan() is null. Under these
circumstances, the Noop Tracer and ScopeManager will cause NPEs when they return
null values when their `active` values are accessed from the GlobalTracer. This
prevents code from running successfully when using Noop Tracers.

This minor change allows users to depend that their code will genuinely Noop
under all use cases.
@natehart
Copy link
Contributor Author

@yurishkuro I've done some digging into why code coverage is dropping so drastically, but I can't figure out where the problem is. I bet there is some null check in a test somewhere that was assuming a null return, but I'll be darned if I can figure out where it is. Unfortunately, I don't have any more time to spend on this. Merge it if you think it's worthwhile, otherwise you can close the PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants