Skip to content

Commit

Permalink
Update the Propagators to be an actual container.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosalberto committed Nov 22, 2019
1 parent 70e0164 commit 8cc6b84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
36 changes: 11 additions & 25 deletions api/src/main/java/io/opentelemetry/OpenTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import io.opentelemetry.context.propagation.DefaultHttpExtractor;
import io.opentelemetry.context.propagation.DefaultHttpInjector;
import io.opentelemetry.context.propagation.HttpExtractor;
import io.opentelemetry.context.propagation.HttpInjector;
import io.opentelemetry.context.propagation.Propagators;
import io.opentelemetry.distributedcontext.CorrelationContextManager;
import io.opentelemetry.distributedcontext.DefaultCorrelationContextManager;
import io.opentelemetry.distributedcontext.spi.CorrelationContextManagerProvider;
Expand Down Expand Up @@ -53,29 +52,8 @@ public final class OpenTelemetry {
private final TracerFactory tracerFactory;
private final Meter meter;
private final CorrelationContextManager contextManager;

public static final class Propagators {
private static volatile HttpInjector httpInjector = new DefaultHttpInjector();
private static volatile HttpExtractor httpExtractor = new DefaultHttpExtractor();

public static HttpExtractor getHttpExtractor() {
return httpExtractor;
}

public static void setHttpExtractor(HttpExtractor httpExtractor) {
Propagators.httpExtractor = httpExtractor;
}

public static HttpInjector getHttpInjector() {
return httpInjector;
}

public static void setHttpInjector(HttpInjector httpInjector) {
Propagators.httpInjector = httpInjector;
}

private Propagators() {}
}
private volatile Propagators propagators =
Propagators.create(new DefaultHttpInjector(), new DefaultHttpExtractor());

/**
* Returns a singleton {@link TracerFactory}.
Expand Down Expand Up @@ -113,6 +91,14 @@ public static CorrelationContextManager getCorrelationContextManager() {
return getInstance().contextManager;
}

public static Propagators getPropagators() {
return getInstance().propagators;
}

public static void setPropagators(Propagators propagators) {
getInstance().propagators = propagators;
}

/** Lazy loads an instance. */
private static OpenTelemetry getInstance() {
if (instance == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.ChainedPropagators;
import io.opentelemetry.context.propagation.DefaultHttpInjector;
import io.opentelemetry.context.propagation.Propagators;
import io.opentelemetry.distributedcontext.propagation.DefaultCorrelationContextExtractor;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.SpanContext;
Expand Down Expand Up @@ -145,10 +147,13 @@ public void init(FilterConfig filterConfig) throws ServletException {
skipPattern = (Pattern) contextAttribute;
}

// Initialize the extractor.
OpenTelemetry.Propagators.setHttpExtractor(
ChainedPropagators.chain(
new HttpTraceContextExtractor(), new DefaultCorrelationContextExtractor()));
// Initialize the propagators.
Propagators propagators =
Propagators.create(
new DefaultHttpInjector(),
ChainedPropagators.chain(
new HttpTraceContextExtractor(), new DefaultCorrelationContextExtractor()));
OpenTelemetry.setPropagators(propagators);
}

@Override
Expand Down Expand Up @@ -177,7 +182,8 @@ public void doFilter(
* instance.
*/
Context ctx =
OpenTelemetry.Propagators.getHttpExtractor()
OpenTelemetry.getPropagators()
.getHttpExtractor()
.extract(Context.current(), httpRequest, HttpServletRequestGetter.getInstance());
SpanContext extractedContext = ctx.getValue(ContextKeys.getSpanContextKey());

Expand Down

0 comments on commit 8cc6b84

Please sign in to comment.