Use io.opentracing.GlobalTracer instead of singleton in Configuration#255
Use io.opentracing.GlobalTracer instead of singleton in Configuration#255
Conversation
- 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>
fd57f29 to
8104f26
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
| GlobalTracer.register(tracer); | ||
| log.info("Initialized and registered global tracer={}", tracer); | ||
| return tracer; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| String serviceName, | ||
| SamplerConfiguration samplerConfig, | ||
| ReporterConfiguration reporterConfig) { | ||
| this(serviceName, samplerConfig, reporterConfig, true); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))); |
|
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; |
There was a problem hiding this comment.
This comment should be negated: "Do not use.."
Signed-off-by: Prithvi Raj <p.r@uber.com>
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>
| return Boolean.valueOf(value); | ||
| } | ||
| return null; | ||
| return Boolean.valueOf(getProperty(name)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
| @Test | ||
| public void testDefaultGlobalTracer() { | ||
| Configuration config = new Configuration("Test"); | ||
| config.getTracer(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
nice! don't know what ^^ was about.
| tracer = getTracerBuilder().build(); | ||
| log.info("Initialized tracer={}", tracer); | ||
|
|
||
| if (!(disableGlobalTracer || GlobalTracer.isRegistered())) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
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