Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Use io.opentracing.GlobalTracer instead of singleton in Configuration#255

Merged
vprithvi merged 6 commits intomasterfrom
use-global-tracer
Oct 9, 2017
Merged

Use io.opentracing.GlobalTracer instead of singleton in Configuration#255
vprithvi merged 6 commits intomasterfrom
use-global-tracer

Conversation

@vprithvi
Copy link
Copy Markdown
Contributor

@vprithvi vprithvi commented Oct 6, 2017

  • Register the tracer created by com.uber.jaeger.Configuration#getTracer
    with opentracing's GlobalTracer mechanism so that opentracing instrumentations
    may find it.

  • Disable the lazily loaded singleton field by default.

This is a prerequisite for #257

@ghost ghost assigned vprithvi Oct 6, 2017
@ghost ghost added the review label Oct 6, 2017
@vprithvi vprithvi requested review from a team, black-adder, pavolloffay and yurishkuro and removed request for yurishkuro October 6, 2017 21:10
- Register the tracer created by com.uber.jaeger.Configuration#getTracer
  with opentracing's GlobalTracer mechanism so that opentracing instrumentations
  may find it.

- Disable the lazily loaded singleton field by default.

Signed-off-by: Prithvi Raj <p.r@uber.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 6, 2017

Codecov Report

Merging #255 into master will increase coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #255      +/-   ##
============================================
+ Coverage     81.97%   82.15%   +0.17%     
- Complexity      524      528       +4     
============================================
  Files            87       87              
  Lines          2003     2006       +3     
  Branches        237      237              
============================================
+ Hits           1642     1648       +6     
+ Misses          262      259       -3     
  Partials         99       99
Impacted Files Coverage Δ Complexity Δ
...e/src/main/java/com/uber/jaeger/Configuration.java 81.69% <100%> (+1.11%) 31 <6> (+2) ⬆️
...java/com/uber/jaeger/dropwizard/Configuration.java 37.5% <0%> (-12.5%) 2% <0%> (-1%)
.../uber/jaeger/samplers/RemoteControlledSampler.java 92.95% <0%> (+1.4%) 19% <0%> (+1%) ⬆️
...com/uber/jaeger/samplers/ProbabilisticSampler.java 81.81% <0%> (+4.54%) 12% <0%> (+1%) ⬆️
.../com/uber/jaeger/samplers/HttpSamplingManager.java 100% <0%> (+6.66%) 5% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1241e9...bdf915e. Read the comment docs.

GlobalTracer.register(tracer);
log.info("Initialized and registered global tracer={}", tracer);
return tracer;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems unnecessary complicated - why not keep the single getTracer method and in the lazy init path (otherwise unchanged) just add if (!disableGlobalTracer) { GlobalTracer.register(tracer);}? Everything else keeps working off the local tracer var.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wrote it this way because I wanted to remove tracer from jaeger config in a future release, and instead depend on opentracing's GlobalTracer for management of the singleton.

Do you think we need to continue support holding on to a tracer in the config?

The only case where I see this being useful is for advanced users who need multiple tracers in the same application. I expect that such users to use getTracerBuilder and not maintain multiple copies of JaegerConfiguration.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if or when we decide on that separation (I am not convinced of its value), we can do that, but right now I don't see a value in this big change that can be instead achieved with just 3 lines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

String serviceName,
SamplerConfiguration samplerConfig,
ReporterConfiguration reporterConfig) {
this(serviceName, samplerConfig, reporterConfig, true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

didn't we want to default this to disableGlobalTracer = false?

also, let's stop adding constructors and add a builder, which we should've done in the first place. The new constructor below should be private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While I agree, I think it should be part of a separate commit

SamplerConfiguration.fromEnv(),
ReporterConfiguration.fromEnv());
ReporterConfiguration.fromEnv(),
Boolean.valueOf(getProperty(JAEGER_DISABLE_GLOBAL_TRACER)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use getPropertyAsBoolean

@yurishkuro
Copy link
Copy Markdown
Member

please link to the relevant issue (iirc this is a pre-requisite)

* Use {@link GlobalTracer} to store the tracer instead of
* storing an instance of the tracer in {@link #tracer}.
*/
private final boolean disableGlobalTracer;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment should be negated: "Do not use.."

Signed-off-by: Prithvi Raj <p.r@uber.com>
@yurishkuro
Copy link
Copy Markdown
Member

While I agree, I think it should be part of a separate commit

if you want to do a separate pr, it's fine, but right now you're adding a new public constructor that we won't be able to hide later for backwards compatibility.

Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
Copy link
Copy Markdown
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.

lgtm

return Boolean.valueOf(value);
}
return null;
return Boolean.valueOf(getProperty(name));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're changing the semantics of the method, previously it could return null, now it performs defaulting of null string to false. It still works given how it's used in this class, but by accident. I would rename it to getPropertyAsBool and return bool, and add a comment about defaulting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, I didn't see any cases where it was necessary to differentiate null from false. I'll update as you recommended.


System.clearProperty(TEST_PROPERTY);

// Hack to reset opentracing's global tracer
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't call it a hack

@Test
public void testDefaultGlobalTracer() {
Configuration config = new Configuration("Test");
config.getTracer();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe assertNotNull? Otherwise it looks weird.

} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
Tracer tracer = new Tracer.Builder("world service", reporter, new ConstSampler(true)).build();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice! don't know what ^^ was about.

tracer = getTracerBuilder().build();
log.info("Initialized tracer={}", tracer);

if (!(disableGlobalTracer || GlobalTracer.isRegistered())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The same tracer instance can be registered multiple times.

I am wondering whether it would be better to remove GlobalTracer.isRegistered() check and propagate potential issues with multiple registered traces at process start time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, you mean that if somebody accidentally calls fromEnv() many times, it'll lead to drift between the GlobalTracer and the local tracer.

I agree, I think it is better to error out. I'll update the code.

Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
@vprithvi vprithvi merged commit a5e2a85 into master Oct 9, 2017
@ghost ghost removed the review label Oct 9, 2017
@vprithvi vprithvi deleted the use-global-tracer branch October 9, 2017 15:55
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.

4 participants