Skip to content

Commit

Permalink
Merge pull request #12101 from stuartwdouglas/lazy-jaeger
Browse files Browse the repository at this point in the history
Lazily init Jaeger
  • Loading branch information
jaikiran authored Sep 15, 2020
2 parents 16192a2 + eb89a24 commit 2a30fc4
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 2a30fc4

Please sign in to comment.