Skip to content

Commit

Permalink
Lazily init Jaeger
Browse files Browse the repository at this point in the history
Jaeger will always be initilized due to MP context
propagation. This change delays init till it is actually used.
  • Loading branch information
stuartwdouglas committed Sep 15, 2020
1 parent 3579849 commit eb89a24
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.jaegertracing.Configuration;
import io.jaegertracing.internal.JaegerTracer;
import io.jaegertracing.spi.MetricsFactory;
import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
import io.opentracing.SpanContext;
Expand All @@ -17,6 +18,35 @@ public class QuarkusJaegerTracer implements Tracer {
private boolean logTraceContext;
private MetricsFactory metricsFactory;

private final ScopeManager scopeManager = new ScopeManager() {

volatile ScopeManager delegate;

@Override
public Scope activate(Span span, boolean b) {
return sm().activate(span, b);
}

@Override
public Scope active() {
if (delegate == null) {
return null;
}
return sm().active();
}

ScopeManager sm() {
if (delegate == null) {
synchronized (this) {
if (delegate == null) {
delegate = getScopeManager();
}
}
}
return delegate;
}
};

void setLogTraceContext(boolean logTraceContext) {
this.logTraceContext = logTraceContext;
}
Expand Down Expand Up @@ -44,7 +74,7 @@ private Tracer tracer() {
tracer = Configuration.fromEnv()
.withMetricsFactory(metricsFactory)
.getTracerBuilder()
.withScopeManager(getScopeManager())
.withScopeManager(scopeManager)
.build();
}
}
Expand Down Expand Up @@ -77,7 +107,7 @@ public <C> SpanContext extract(Format<C> format, C carrier) {

@Override
public ScopeManager scopeManager() {
return tracer().scopeManager();
return scopeManager;
}

@Override
Expand Down

0 comments on commit eb89a24

Please sign in to comment.