Don't use singleton for propagator getters/setters
MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java
@@ -86,8 +86,7 @@ class InstrumenterTest {
}
}
- enum MapGetter implements TextMapGetter<Map<String, String>> {
- INSTANCE;
+ class MapGetter implements TextMapGetter<Map<String, String>> {
@Override
public Iterable<String> keys(Map<String, String> carrier) {
@@ -109,7 +108,7 @@ class InstrumenterTest {
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();
@@ -151,7 +150,7 @@ class InstrumenterTest {
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();
@@ -175,7 +174,7 @@ class InstrumenterTest {
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()

MODIFY
instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientInstrumenters.java
instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientInstrumenters.java
@@ -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() {

MODIFY
instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/HttpHeaderSetter.java
instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/HttpHeaderSetter.java
@@ -9,8 +9,7 @@ import io.opentelemetry.context.propagation.TextMapSetter;
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) {

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientInstrumenters.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientInstrumenters.java
@@ -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() {

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpHeaderSetter.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpHeaderSetter.java
@@ -8,8 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
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) {

MODIFY
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java
@@ -86,7 +86,7 @@ public final class ArmeriaTracingBuilder {
serverInstrumenterBuilder.addRequestMetrics(HttpServerMetrics.get());
return new ArmeriaTracing(
- clientInstrumenterBuilder.newClientInstrumenter(ClientRequestContextSetter.INSTANCE),
- serverInstrumenterBuilder.newServerInstrumenter(RequestContextGetter.INSTANCE));
+ clientInstrumenterBuilder.newClientInstrumenter(new ClientRequestContextSetter()),
+ serverInstrumenterBuilder.newServerInstrumenter(new RequestContextGetter()));
}
}

MODIFY
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java
@@ -9,8 +9,7 @@ import com.linecorp.armeria.client.ClientRequestContext;
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) {

MODIFY
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java
@@ -12,8 +12,7 @@ import java.util.Collections;
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) {

MODIFY
instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsInstrumenters.java
instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsInstrumenters.java
@@ -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(

MODIFY
instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/MessagePropertySetter.java
instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/MessagePropertySetter.java
@@ -10,8 +10,7 @@ import javax.jms.JMSException;
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);

Don't use singleton for propagator getters/setters (#3054)