Skip to content

Commit

Permalink
Don't use singleton for propagator getters/setters (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored May 21, 2021
1 parent ccda31a commit f11bd75
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ protected void onEnd(
}
}

enum MapGetter implements TextMapGetter<Map<String, String>> {
INSTANCE;
class MapGetter implements TextMapGetter<Map<String, String>> {

@Override
public Iterable<String> keys(Map<String, String> carrier) {
Expand All @@ -109,7 +108,7 @@ void server() {
Instrumenter.<Map<String, String>, Map<String, String>>newBuilder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newServerInstrumenter(MapGetter.INSTANCE);
.newServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
SpanContext spanContext = Span.fromContext(context).getSpanContext();
Expand Down Expand Up @@ -151,7 +150,7 @@ void server_error() {
Instrumenter.<Map<String, String>, Map<String, String>>newBuilder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newServerInstrumenter(MapGetter.INSTANCE);
.newServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
SpanContext spanContext = Span.fromContext(context).getSpanContext();
Expand All @@ -175,7 +174,7 @@ void server_parent() {
Instrumenter.<Map<String, String>, Map<String, String>>newBuilder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newServerInstrumenter(MapGetter.INSTANCE);
.newServerInstrumenter(new MapGetter());

Map<String, String> request = new HashMap<>(REQUEST);
W3CTraceContextPropagator.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ApacheHttpClientInstrumenters {
.setSpanStatusExtractor(spanStatusExtractor)
.addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(new ApacheHttpClientNetAttributesExtractor())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.newClientInstrumenter(new HttpHeaderSetter());
}

public static Instrumenter<HttpMethod, Void> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;

enum HttpHeaderSetter implements TextMapSetter<HttpMethod> {
INSTANCE;
final class HttpHeaderSetter implements TextMapSetter<HttpMethod> {

@Override
public void set(HttpMethod carrier, String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class ApacheHttpClientInstrumenters {
.setSpanStatusExtractor(spanStatusExtractor)
.addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(new ApacheHttpClientNetAttributesExtractor())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.newClientInstrumenter(new HttpHeaderSetter());
}

public static Instrumenter<HttpUriRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import org.apache.http.client.methods.HttpUriRequest;

enum HttpHeaderSetter implements TextMapSetter<HttpUriRequest> {
INSTANCE;
final class HttpHeaderSetter implements TextMapSetter<HttpUriRequest> {

@Override
public void set(HttpUriRequest carrier, String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ArmeriaTracing build() {
serverInstrumenterBuilder.addRequestMetrics(HttpServerMetrics.get());

return new ArmeriaTracing(
clientInstrumenterBuilder.newClientInstrumenter(ClientRequestContextSetter.INSTANCE),
serverInstrumenterBuilder.newServerInstrumenter(RequestContextGetter.INSTANCE));
clientInstrumenterBuilder.newClientInstrumenter(new ClientRequestContextSetter()),
serverInstrumenterBuilder.newServerInstrumenter(new RequestContextGetter()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import org.checkerframework.checker.nullness.qual.Nullable;

enum ClientRequestContextSetter implements TextMapSetter<ClientRequestContext> {
INSTANCE;
final class ClientRequestContextSetter implements TextMapSetter<ClientRequestContext> {

@Override
public void set(@Nullable ClientRequestContext carrier, String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;

enum RequestContextGetter implements TextMapGetter<ServiceRequestContext> {
INSTANCE;
final class RequestContextGetter implements TextMapGetter<ServiceRequestContext> {

@Override
public Iterable<String> keys(@Nullable ServiceRequestContext carrier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class JmsInstrumenters {
Instrumenter.<MessageWithDestination, Void>newBuilder(
otel, INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(attributesExtractor)
.newProducerInstrumenter(MessagePropertySetter.INSTANCE);
.newProducerInstrumenter(new MessagePropertySetter());
// MessageConsumer does not do context propagation
CONSUMER_INSTRUMENTER =
Instrumenter.<MessageWithDestination, Void>newBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

enum MessagePropertySetter implements TextMapSetter<MessageWithDestination> {
INSTANCE;
final class MessagePropertySetter implements TextMapSetter<MessageWithDestination> {

private static final Logger log = LoggerFactory.getLogger(MessagePropertySetter.class);

Expand Down

0 comments on commit f11bd75

Please sign in to comment.