diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java index 75aa3c4fcde2..5ca4bb72c6e4 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java @@ -7,6 +7,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientExperimentalMetrics; @@ -40,6 +41,9 @@ */ public final class DefaultHttpClientInstrumenterBuilder { + // copied from PeerIncubatingAttributes + private static final AttributeKey PEER_SERVICE = AttributeKey.stringKey("peer.service"); + private final String instrumentationName; private final OpenTelemetry openTelemetry; @@ -83,7 +87,7 @@ public DefaultHttpClientInstrumenterBuilder addAttributeExtra } @CanIgnoreReturnValue - public DefaultHttpClientTelemetryBuilder setStatusExtractor( + public DefaultHttpClientInstrumenterBuilder setStatusExtractor( Function< SpanStatusExtractor, ? extends SpanStatusExtractor> @@ -174,6 +178,13 @@ public DefaultHttpClientInstrumenterBuilder setPeerServiceRes HttpClientPeerServiceAttributesExtractor.create(attributesGetter, peerServiceResolver)); } + /** Sets the {@code peer.service} attribute for http client spans. */ + @CanIgnoreReturnValue + public DefaultHttpClientInstrumenterBuilder setPeerService( + String peerService) { + return addAttributeExtractor(AttributesExtractor.constant(PEER_SERVICE, peerService)); + } + @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder setBuilderCustomizer( Consumer> builderCustomizer) { @@ -211,6 +222,10 @@ public OpenTelemetry getOpenTelemetry() { return openTelemetry; } + public String getInstrumentationName() { + return instrumentationName; + } + @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder configure(CommonConfig config) { set(config::getKnownHttpRequestMethods, this::setKnownMethods); diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java index b229a7126e48..88e2735ae4e7 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java @@ -59,6 +59,7 @@ public final class DefaultHttpServerInstrumenterBuilder { private final HttpServerRouteBuilder httpServerRouteBuilder; private final HttpServerAttributesGetter attributesGetter; private boolean emitExperimentalHttpServerMetrics = false; + private Consumer> builderCustomizer = b -> {}; public DefaultHttpServerInstrumenterBuilder( String instrumentationName, @@ -168,6 +169,13 @@ public DefaultHttpServerInstrumenterBuilder setSpanNameExtrac return this; } + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setBuilderCustomizer( + Consumer> builderCustomizer) { + this.builderCustomizer = builderCustomizer; + return this; + } + public Instrumenter build() { InstrumenterBuilder builder = builder(); @@ -177,7 +185,7 @@ public Instrumenter build() { return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); } - private InstrumenterBuilder builder() { + public InstrumenterBuilder builder() { SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); @@ -195,6 +203,7 @@ private InstrumenterBuilder builder() { .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(attributesGetter)) .addOperationMetrics(HttpServerExperimentalMetrics.get()); } + builderCustomizer.accept(builder); return builder; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java index 1d0c440192cb..3526ca01436a 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java @@ -20,11 +20,10 @@ public final class ApacheHttpClientTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-4.3"; - private final DefaultHttpClientInstrumenterBuilder - clientBuilder; + private final DefaultHttpClientInstrumenterBuilder builder; ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { - clientBuilder = + builder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClientHttpAttributesGetter.INSTANCE); } @@ -37,7 +36,7 @@ public final class ApacheHttpClientTelemetryBuilder { public ApacheHttpClientTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - clientBuilder.addAttributeExtractor(attributesExtractor); + builder.addAttributeExtractor(attributesExtractor); return this; } @@ -48,7 +47,7 @@ public ApacheHttpClientTelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - clientBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -59,7 +58,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List r */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - clientBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -78,7 +77,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setKnownMethods(Set knownMethods) { - clientBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -91,7 +90,7 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Set knownMethods @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -102,7 +101,7 @@ public ApacheHttpClientTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -112,6 +111,6 @@ public ApacheHttpClientTelemetryBuilder setSpanNameExtractor( */ public ApacheHttpClientTelemetry build() { return new ApacheHttpClientTelemetry( - clientBuilder.build(), clientBuilder.getOpenTelemetry().getPropagators()); + builder.build(), builder.getOpenTelemetry().getPropagators()); } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java index 8dbf7215c8be..e9a5eb273de0 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java @@ -21,10 +21,10 @@ public final class ApacheHttpClient5TelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-5.2"; private final DefaultHttpClientInstrumenterBuilder - clientBuilder; + builder; ApacheHttpClient5TelemetryBuilder(OpenTelemetry openTelemetry) { - clientBuilder = + builder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClient5HttpAttributesGetter.INSTANCE); } @@ -37,7 +37,7 @@ public final class ApacheHttpClient5TelemetryBuilder { public ApacheHttpClient5TelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - clientBuilder.addAttributeExtractor(attributesExtractor); + builder.addAttributeExtractor(attributesExtractor); return this; } @@ -48,7 +48,7 @@ public ApacheHttpClient5TelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - clientBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -60,7 +60,7 @@ public ApacheHttpClient5TelemetryBuilder setCapturedRequestHeaders(List @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setCapturedResponseHeaders( List responseHeaders) { - clientBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -79,7 +79,7 @@ public ApacheHttpClient5TelemetryBuilder setCapturedResponseHeaders( */ @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setKnownMethods(Set knownMethods) { - clientBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -92,7 +92,7 @@ public ApacheHttpClient5TelemetryBuilder setKnownMethods(Set knownMethod @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -103,7 +103,7 @@ public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -113,6 +113,6 @@ public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor( */ public ApacheHttpClient5Telemetry build() { return new ApacheHttpClient5Telemetry( - clientBuilder.build(), clientBuilder.getOpenTelemetry().getPropagators()); + builder.build(), builder.getOpenTelemetry().getPropagators()); } } diff --git a/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java b/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java index 3590c094f43b..4845c528e7e1 100644 --- a/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java +++ b/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java @@ -8,11 +8,11 @@ import com.linecorp.armeria.client.HttpClient; import com.linecorp.armeria.server.HttpService; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; -import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetry; import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import java.util.function.Function; // Holds singleton references to decorators to match against during suppression. @@ -24,8 +24,9 @@ public final class ArmeriaSingletons { static { ArmeriaTelemetryBuilder builder = ArmeriaTelemetry.builder(GlobalOpenTelemetry.get()); - DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); - DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); + CommonConfig config = AgentCommonConfig.get(); + ArmeriaInstrumenterBuilderUtil.getClientBuilderExtractor().apply(builder).configure(config); + ArmeriaInstrumenterBuilderUtil.getServerBuilderExtractor().apply(builder).configure(config); ArmeriaTelemetry telemetry = builder.build(); CLIENT_DECORATOR = telemetry.newClientDecorator(); diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java index 80fd9e9557ae..196d2b80dc97 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java @@ -11,55 +11,37 @@ import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaHttpClientAttributesGetter; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; import java.util.List; import java.util.Set; import java.util.function.Function; -import javax.annotation.Nullable; public final class ArmeriaTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; - // copied from PeerIncubatingAttributes - private static final AttributeKey PEER_SERVICE = AttributeKey.stringKey("peer.service"); - - @Nullable private String peerService; private final DefaultHttpClientInstrumenterBuilder clientBuilder; private final DefaultHttpServerInstrumenterBuilder serverBuilder; + static { + ArmeriaInstrumenterBuilderUtil.setClientBuilderExtractor( + ArmeriaTelemetryBuilder::getClientBuilder); + ArmeriaInstrumenterBuilderUtil.setServerBuilderExtractor( + ArmeriaTelemetryBuilder::getServerBuilder); + } + @SuppressWarnings({"rawtypes", "unchecked"}) ArmeriaTelemetryBuilder(OpenTelemetry openTelemetry) { - clientBuilder = - new DefaultHttpClientInstrumenterBuilder( - INSTRUMENTATION_NAME, - openTelemetry, - (HttpClientAttributesGetter) ArmeriaHttpClientAttributesGetter.INSTANCE) - .setHeaderSetter(ClientRequestContextSetter.INSTANCE) - .setBuilderCustomizer( - builder -> { - if (peerService != null) { - builder.addAttributesExtractor( - AttributesExtractor.constant(PEER_SERVICE, peerService)); - } - }); - serverBuilder = - new DefaultHttpServerInstrumenterBuilder<>( - INSTRUMENTATION_NAME, - openTelemetry, - (HttpServerAttributesGetter) ArmeriaHttpServerAttributesGetter.INSTANCE) - .setHeaderGetter(RequestContextGetter.INSTANCE); + clientBuilder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); + serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); } @SuppressWarnings({"unchecked", "rawtypes"}) @@ -101,7 +83,7 @@ public ArmeriaTelemetryBuilder addClientAttributeExtractor( /** Sets the {@code peer.service} attribute for http client spans. */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setPeerService(String peerService) { - this.peerService = peerService; + clientBuilder.setPeerService(peerService); return this; } @@ -225,4 +207,14 @@ public ArmeriaTelemetryBuilder setServerSpanNameExtractor( public ArmeriaTelemetry build() { return new ArmeriaTelemetry(clientBuilder.build(), serverBuilder.build()); } + + private DefaultHttpClientInstrumenterBuilder + getClientBuilder() { + return clientBuilder; + } + + private DefaultHttpServerInstrumenterBuilder + getServerBuilder() { + return serverBuilder; + } } diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java index ec6d00b8d6e2..b86986a57f66 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java @@ -16,11 +16,7 @@ import java.util.List; import javax.annotation.Nullable; -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public enum ArmeriaHttpClientAttributesGetter +enum ArmeriaHttpClientAttributesGetter implements HttpClientAttributesGetter { INSTANCE; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java similarity index 95% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java index 1f5891d9c43f..75d727c60578 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.HttpStatus; @@ -12,7 +12,6 @@ import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.RequestContextAccess; import java.net.InetSocketAddress; import java.util.List; import javax.annotation.Nullable; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java new file mode 100644 index 000000000000..7924f91afb14 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.common.logging.RequestLog; +import com.linecorp.armeria.server.ServiceRequestContext; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class ArmeriaInstrumenterBuilderFactory { + private ArmeriaInstrumenterBuilderFactory() {} + + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static DefaultHttpServerInstrumenterBuilder + getServerBuilder(OpenTelemetry openTelemetry) { + return new DefaultHttpServerInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + (HttpServerAttributesGetter) ArmeriaHttpServerAttributesGetter.INSTANCE) + .setHeaderGetter(RequestContextGetter.INSTANCE); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static DefaultHttpClientInstrumenterBuilder + getClientBuilder(OpenTelemetry openTelemetry) { + return new DefaultHttpClientInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + (HttpClientAttributesGetter) ArmeriaHttpClientAttributesGetter.INSTANCE) + .setHeaderSetter(ClientRequestContextSetter.INSTANCE); + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java new file mode 100644 index 000000000000..a9a7d8b43b09 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java @@ -0,0 +1,67 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.common.logging.RequestLog; +import com.linecorp.armeria.server.ServiceRequestContext; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; +import java.util.function.Function; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class ArmeriaInstrumenterBuilderUtil { + private ArmeriaInstrumenterBuilderUtil() {} + + @Nullable + private static Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + clientBuilderExtractor; + + @Nullable + private static Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor; + + @Nullable + public static Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + getClientBuilderExtractor() { + return clientBuilderExtractor; + } + + public static void setClientBuilderExtractor( + Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + clientBuilderExtractor) { + ArmeriaInstrumenterBuilderUtil.clientBuilderExtractor = clientBuilderExtractor; + } + + @Nullable + public static Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + getServerBuilderExtractor() { + return serverBuilderExtractor; + } + + public static void setServerBuilderExtractor( + Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor) { + ArmeriaInstrumenterBuilderUtil.serverBuilderExtractor = serverBuilderExtractor; + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java similarity index 89% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java index 91ce53e54805..1a225fd7108b 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.client.ClientRequestContext; import io.opentelemetry.context.propagation.TextMapSetter; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java index acaf7fd9cfa0..1a7830758fd6 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java @@ -13,11 +13,7 @@ import java.net.SocketAddress; import javax.annotation.Nullable; -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public final class RequestContextAccess { +final class RequestContextAccess { @Nullable private static final MethodHandle remoteAddress = findAccessorOrNull("remoteAddress"); @Nullable private static final MethodHandle localAddress = findAccessorOrNull("localAddress"); diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java similarity index 93% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java index 5163333591a0..5cae10de6578 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.server.ServiceRequestContext; import io.netty.util.AsciiString; diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index c562658cba85..99e364af89b5 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -30,13 +30,13 @@ class KtorServerTracing private constructor( ) { class Configuration { - internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder + internal lateinit var builder: DefaultHttpServerInstrumenterBuilder internal var spanKindExtractor: (SpanKindExtractor) -> SpanKindExtractor = { a -> a } fun setOpenTelemetry(openTelemetry: OpenTelemetry) { - this.serverBuilder = + this.builder = DefaultHttpServerInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, @@ -47,7 +47,7 @@ class KtorServerTracing private constructor( fun setStatusExtractor( extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { - serverBuilder.setStatusExtractor { prevExtractor -> + builder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, request: ApplicationRequest, response: ApplicationResponse?, @@ -64,22 +64,22 @@ class KtorServerTracing private constructor( } fun addAttributeExtractor(extractor: AttributesExtractor) { - serverBuilder.addAttributesExtractor(extractor) + builder.addAttributesExtractor(extractor) } fun setCapturedRequestHeaders(requestHeaders: List) { - serverBuilder.setCapturedRequestHeaders(requestHeaders) + builder.setCapturedRequestHeaders(requestHeaders) } fun setCapturedResponseHeaders(responseHeaders: List) { - serverBuilder.setCapturedResponseHeaders(responseHeaders) + builder.setCapturedResponseHeaders(responseHeaders) } fun setKnownMethods(knownMethods: Set) { - serverBuilder.setKnownMethods(knownMethods) + builder.setKnownMethods(knownMethods) } - internal fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized + internal fun isOpenTelemetryInitialized(): Boolean = this::builder.isInitialized } private fun start(call: ApplicationCall): Context? { @@ -111,7 +111,7 @@ class KtorServerTracing private constructor( } val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( - configuration.serverBuilder.builder(), + configuration.builder.builder(), ApplicationRequestGetter, configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index 69e15f25e5dd..f1b54532f728 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -13,10 +13,10 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.instrumentation.ktor.v2_0.internal.KtorBuilderUtil; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import kotlin.Unit; @@ -55,7 +55,7 @@ public static class SetupFunction implements Function1 diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt new file mode 100644 index 000000000000..10bb56d5a720 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0.internal + +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +object KtorBuilderUtil { + lateinit var clientBuilderExtractor: (KtorClientTracingBuilder) -> DefaultHttpClientInstrumenterBuilder + lateinit var serverBuilderExtractor: (KtorServerTracing.Configuration) -> DefaultHttpServerInstrumenterBuilder +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 1f879a597fdf..e6bd2e2fc2cf 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -27,6 +27,7 @@ import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.internal.KtorBuilderUtil import kotlinx.coroutines.withContext class KtorServerTracing private constructor( @@ -34,6 +35,12 @@ class KtorServerTracing private constructor( ) { class Configuration { + companion object { + init { + KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder } + } + } + internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder internal var spanKindExtractor: diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java index 31bad69e3bbb..5d97acc910e9 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java @@ -5,16 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.kubernetesclient; -import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient; - import io.kubernetes.client.openapi.ApiResponse; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; import okhttp3.Request; @@ -28,28 +24,23 @@ public class KubernetesClientSingletons { private static final ContextPropagators CONTEXT_PROPAGATORS; static { - KubernetesHttpAttributesGetter httpAttributesGetter = new KubernetesHttpAttributesGetter(); - - InstrumenterBuilder> instrumenterBuilder = - Instrumenter.>builder( - GlobalOpenTelemetry.get(), + INSTRUMENTER = + new DefaultHttpClientInstrumenterBuilder<>( "io.opentelemetry.kubernetes-client-7.0", - request -> KubernetesRequestDigest.parse(request).toString()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getClientRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getClientResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()); - - if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { - instrumenterBuilder.addAttributesExtractor(new KubernetesExperimentalAttributesExtractor()); - } - - // Initialize with .newInstrumenter(alwaysClient()) instead of .newClientInstrumenter(..) - // because Request is immutable so context must be injected manually - INSTRUMENTER = instrumenterBuilder.buildInstrumenter(alwaysClient()); + GlobalOpenTelemetry.get(), + new KubernetesHttpAttributesGetter()) + .configure(AgentCommonConfig.get()) + .setBuilderCustomizer( + instrumenterBuilder -> { + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + instrumenterBuilder.addAttributesExtractor( + new KubernetesExperimentalAttributesExtractor()); + } + }) + .setSpanNameExtractor( + requestSpanNameExtractor -> + request -> KubernetesRequestDigest.parse(request).toString()) + .build(); CONTEXT_PROPAGATORS = GlobalOpenTelemetry.getPropagators(); } diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilder.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilder.java deleted file mode 100644 index 3ffe71f3227a..000000000000 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.netty.v4.common.internal.client; - -import com.google.errorprone.annotations.CanIgnoreReturnValue; -import io.netty.handler.codec.http.HttpResponse; -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; -import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceResolver; -import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public class NettyClientInstrumenterBuilder - extends DefaultHttpClientInstrumenterBuilder { - private PeerServiceResolver peerServiceResolver; - - public NettyClientInstrumenterBuilder(String instrumentationName, OpenTelemetry openTelemetry) { - super(instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter()); - setHeaderSetter(HttpRequestHeadersSetter.INSTANCE); - } - - @CanIgnoreReturnValue - @Override - public NettyClientInstrumenterBuilder setPeerServiceResolver( - PeerServiceResolver peerServiceResolver) { - this.peerServiceResolver = peerServiceResolver; - super.setPeerServiceResolver(peerServiceResolver); - return this; - } - - public PeerServiceResolver getPeerServiceResolver() { - return peerServiceResolver; - } -} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java new file mode 100644 index 000000000000..b7f4f7c5ee82 --- /dev/null +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java @@ -0,0 +1,27 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.netty.v4.common.internal.client; + +import io.netty.handler.codec.http.HttpResponse; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class NettyClientInstrumenterBuilderFactory { + private NettyClientInstrumenterBuilderFactory() {} + + public static DefaultHttpClientInstrumenterBuilder create( + String instrumentationName, OpenTelemetry openTelemetry) { + + return new DefaultHttpClientInstrumenterBuilder<>( + instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter()) + .setHeaderSetter(HttpRequestHeadersSetter.INSTANCE); + } +} diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java index 64646e2351ef..70a4adf62683 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterFactory.java @@ -7,7 +7,7 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.HttpResponse; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientPeerServiceAttributesExtractor; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; @@ -23,12 +23,12 @@ */ public final class NettyClientInstrumenterFactory { - private final NettyClientInstrumenterBuilder builder; + private final DefaultHttpClientInstrumenterBuilder builder; private final NettyConnectionInstrumentationFlag connectionTelemetryState; private final NettyConnectionInstrumentationFlag sslTelemetryState; public NettyClientInstrumenterFactory( - NettyClientInstrumenterBuilder builder, + DefaultHttpClientInstrumenterBuilder builder, NettyConnectionInstrumentationFlag connectionTelemetryState, NettyConnectionInstrumentationFlag sslTelemetryState) { this.builder = builder; @@ -50,13 +50,10 @@ public NettyConnectionInstrumenter createConnectionInstrumenter() { NettyConnectHttpAttributesGetter getter = NettyConnectHttpAttributesGetter.INSTANCE; InstrumenterBuilder builder = - Instrumenter.builder( - this.builder.getOpenTelemetry(), - this.builder.getInstrumentationName(), - NettyConnectionRequest::spanName) - .addAttributesExtractor( - HttpClientPeerServiceAttributesExtractor.create( - getter, this.builder.getPeerServiceResolver())); + Instrumenter.builder( + this.builder.getOpenTelemetry(), + this.builder.getInstrumentationName(), + NettyConnectionRequest::spanName); if (connectionTelemetryFullyEnabled) { // when the connection telemetry is fully enabled, CONNECT spans are created for every diff --git a/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/client/NettyClientSingletons.java b/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/client/NettyClientSingletons.java index 856a83f48622..0d5c8124de69 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/client/NettyClientSingletons.java +++ b/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/client/NettyClientSingletons.java @@ -12,20 +12,20 @@ import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; -import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumenter; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettySslInstrumenter; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; -import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; public final class NettyClientSingletons { private static final boolean connectionTelemetryEnabled = - InstrumentationConfig.get() + AgentInstrumentationConfig.get() .getBoolean("otel.instrumentation.netty.connection-telemetry.enabled", false); private static final boolean sslTelemetryEnabled = - InstrumentationConfig.get() + AgentInstrumentationConfig.get() .getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false); private static final Instrumenter INSTRUMENTER; @@ -33,9 +33,10 @@ public final class NettyClientSingletons { private static final NettySslInstrumenter SSL_INSTRUMENTER; static { - NettyClientInstrumenterBuilder builder = - new NettyClientInstrumenterBuilder("io.opentelemetry.netty-4.0", GlobalOpenTelemetry.get()); - DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); + DefaultHttpClientInstrumenterBuilder builder = + NettyClientInstrumenterBuilderFactory.create( + "io.opentelemetry.netty-4.0", GlobalOpenTelemetry.get()) + .configure(AgentCommonConfig.get()); NettyClientInstrumenterFactory factory = new NettyClientInstrumenterFactory( diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyClientSingletons.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyClientSingletons.java index af17cf8d4e6a..2f556d27a5f1 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyClientSingletons.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyClientSingletons.java @@ -12,21 +12,21 @@ import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; -import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumenter; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettySslInstrumenter; import io.opentelemetry.instrumentation.netty.v4_1.internal.client.NettyClientHandlerFactory; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; -import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; public final class NettyClientSingletons { private static final boolean connectionTelemetryEnabled = - InstrumentationConfig.get() + AgentInstrumentationConfig.get() .getBoolean("otel.instrumentation.netty.connection-telemetry.enabled", false); private static final boolean sslTelemetryEnabled = - InstrumentationConfig.get() + AgentInstrumentationConfig.get() .getBoolean("otel.instrumentation.netty.ssl-telemetry.enabled", false); private static final Instrumenter INSTRUMENTER; @@ -35,9 +35,10 @@ public final class NettyClientSingletons { private static final NettyClientHandlerFactory CLIENT_HANDLER_FACTORY; static { - NettyClientInstrumenterBuilder builder = - new NettyClientInstrumenterBuilder("io.opentelemetry.netty-4.1", GlobalOpenTelemetry.get()); - DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); + DefaultHttpClientInstrumenterBuilder builder = + NettyClientInstrumenterBuilderFactory.create( + "io.opentelemetry.netty-4.1", GlobalOpenTelemetry.get()) + .configure(AgentCommonConfig.get()); NettyClientInstrumenterFactory factory = new NettyClientInstrumenterFactory( builder, @@ -48,7 +49,7 @@ public final class NettyClientSingletons { SSL_INSTRUMENTER = factory.createSslInstrumenter(); CLIENT_HANDLER_FACTORY = new NettyClientHandlerFactory( - INSTRUMENTER, CommonConfig.get().shouldEmitExperimentalHttpClientTelemetry()); + INSTRUMENTER, AgentCommonConfig.get().shouldEmitExperimentalHttpClientTelemetry()); } public static Instrumenter instrumenter() { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java index a231198bbdf4..ca9087190b01 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java +++ b/instrumentation/netty/netty-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_1/NettyServerSingletons.java @@ -6,16 +6,18 @@ package io.opentelemetry.javaagent.instrumentation.netty.v4_1; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetry; import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetryBuilder; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.instrumentation.netty.v4_1.internal.server.NettyServerInstrumenterBuilderUtil; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; public final class NettyServerSingletons { static { NettyServerTelemetryBuilder builder = NettyServerTelemetry.builder(GlobalOpenTelemetry.get()); - DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); + NettyServerInstrumenterBuilderUtil.getBuilderExtractor() + .apply(builder) + .configure(AgentCommonConfig.get()); SERVER_TELEMETRY = builder.build(); } diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java index 2600d3b1d9c7..9431131551d1 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java @@ -8,11 +8,12 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; -import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumentationFlag; import java.util.List; @@ -22,11 +23,12 @@ /** A builder of {@link NettyClientTelemetry}. */ public final class NettyClientTelemetryBuilder { - private final NettyClientInstrumenterBuilder builder; + private final DefaultHttpClientInstrumenterBuilder builder; private boolean emitExperimentalHttpClientEvents = false; NettyClientTelemetryBuilder(OpenTelemetry openTelemetry) { - builder = new NettyClientInstrumenterBuilder("io.opentelemetry.netty-4.1", openTelemetry); + builder = + NettyClientInstrumenterBuilderFactory.create("io.opentelemetry.netty-4.1", openTelemetry); } @CanIgnoreReturnValue diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java index 78a37111f0b5..126075cb7239 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java @@ -14,19 +14,23 @@ import io.opentelemetry.instrumentation.netty.v4.common.internal.server.HttpRequestHeadersGetter; import io.opentelemetry.instrumentation.netty.v4.common.internal.server.NettyHttpServerAttributesGetter; import io.opentelemetry.instrumentation.netty.v4_1.internal.ProtocolEventHandler; +import io.opentelemetry.instrumentation.netty.v4_1.internal.server.NettyServerInstrumenterBuilderUtil; import java.util.List; import java.util.Set; /** A builder of {@link NettyServerTelemetry}. */ public final class NettyServerTelemetryBuilder { - private final DefaultHttpServerInstrumenterBuilder - serverBuilder; + private final DefaultHttpServerInstrumenterBuilder builder; private boolean emitExperimentalHttpServerEvents = false; + static { + NettyServerInstrumenterBuilderUtil.setBuilderExtractor(NettyServerTelemetryBuilder::getBuilder); + } + NettyServerTelemetryBuilder(OpenTelemetry openTelemetry) { - serverBuilder = + builder = new DefaultHttpServerInstrumenterBuilder<>( "io.opentelemetry.netty-4.1", openTelemetry, new NettyHttpServerAttributesGetter()) .setHeaderGetter(HttpRequestHeadersGetter.INSTANCE); @@ -52,7 +56,7 @@ public NettyServerTelemetryBuilder setEmitExperimentalHttpServerEvents( @CanIgnoreReturnValue public NettyServerTelemetryBuilder setCapturedRequestHeaders( List capturedRequestHeaders) { - serverBuilder.setCapturedRequestHeaders(capturedRequestHeaders); + builder.setCapturedRequestHeaders(capturedRequestHeaders); return this; } @@ -64,7 +68,7 @@ public NettyServerTelemetryBuilder setCapturedRequestHeaders( @CanIgnoreReturnValue public NettyServerTelemetryBuilder setCapturedResponseHeaders( List capturedResponseHeaders) { - serverBuilder.setCapturedResponseHeaders(capturedResponseHeaders); + builder.setCapturedResponseHeaders(capturedResponseHeaders); return this; } @@ -83,7 +87,7 @@ public NettyServerTelemetryBuilder setCapturedResponseHeaders( */ @CanIgnoreReturnValue public NettyServerTelemetryBuilder setKnownMethods(Set knownMethods) { - serverBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -96,16 +100,20 @@ public NettyServerTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public NettyServerTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } /** Returns a new {@link NettyServerTelemetry} with the given configuration. */ public NettyServerTelemetry build() { return new NettyServerTelemetry( - serverBuilder.build(), + builder.build(), emitExperimentalHttpServerEvents ? ProtocolEventHandler.Enabled.INSTANCE : ProtocolEventHandler.Noop.INSTANCE); } + + private DefaultHttpServerInstrumenterBuilder getBuilder() { + return builder; + } } diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/server/NettyServerInstrumenterBuilderUtil.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/server/NettyServerInstrumenterBuilderUtil.java new file mode 100644 index 000000000000..94561e0b2b23 --- /dev/null +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/server/NettyServerInstrumenterBuilderUtil.java @@ -0,0 +1,41 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.netty.v4_1.internal.server; + +import io.netty.handler.codec.http.HttpResponse; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; +import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetryBuilder; +import java.util.function.Function; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class NettyServerInstrumenterBuilderUtil { + + private static Function< + NettyServerTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor; + + private NettyServerInstrumenterBuilderUtil() {} + + public static void setBuilderExtractor( + Function< + NettyServerTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor) { + NettyServerInstrumenterBuilderUtil.builderExtractor = builderExtractor; + } + + public static Function< + NettyServerTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + getBuilderExtractor() { + return builderExtractor; + } +} diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java index 2d625179bb9d..0e313882a08e 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettySingletons.java @@ -5,15 +5,17 @@ package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0; +import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; +import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumentationFlag; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumenter; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; -import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpClientInstrumenters; import reactor.netty.http.client.HttpClientRequest; import reactor.netty.http.client.HttpClientResponse; @@ -23,7 +25,7 @@ public final class ReactorNettySingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.reactor-netty-1.0"; private static final boolean connectionTelemetryEnabled = - InstrumentationConfig.get() + AgentInstrumentationConfig.get() .getBoolean("otel.instrumentation.reactor-netty.connection-telemetry.enabled", false); private static final Instrumenter INSTRUMENTER; @@ -36,9 +38,10 @@ public final class ReactorNettySingletons { new ReactorNettyHttpClientAttributesGetter(), HttpClientRequestHeadersSetter.INSTANCE); - NettyClientInstrumenterBuilder builder = - new NettyClientInstrumenterBuilder(INSTRUMENTATION_NAME, GlobalOpenTelemetry.get()); - DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure(CommonConfig.get(), builder); + DefaultHttpClientInstrumenterBuilder builder = + NettyClientInstrumenterBuilderFactory.create( + INSTRUMENTATION_NAME, GlobalOpenTelemetry.get()) + .configure(AgentCommonConfig.get()); NettyClientInstrumenterFactory instrumenterFactory = new NettyClientInstrumenterFactory( builder, diff --git a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java index 153bdae98191..fbdb30e05d47 100644 --- a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java +++ b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteGetter; -import io.opentelemetry.instrumentation.restlet.v1_1.RestletTelemetry; +import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory; import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.restlet.data.Request; @@ -21,7 +21,7 @@ public final class RestletSingletons { static { INSTRUMENTER = JavaagentHttpServerInstrumenters.create( - RestletTelemetry.builder(GlobalOpenTelemetry.get())); + RestletTelemetryBuilderFactory.create(GlobalOpenTelemetry.get())); } public static Instrumenter instrumenter() { diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index bd167efda907..0f7630e5a9c4 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -20,15 +21,10 @@ /** A builder of {@link RestletTelemetry}. */ public final class RestletTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-1.1"; - - private final DefaultHttpServerInstrumenterBuilder serverBuilder; + private final DefaultHttpServerInstrumenterBuilder builder; RestletTelemetryBuilder(OpenTelemetry openTelemetry) { - serverBuilder = - new DefaultHttpServerInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RestletHttpAttributesGetter.INSTANCE) - .setHeaderGetter(RestletHeadersGetter.INSTANCE); + builder = RestletTelemetryBuilderFactory.create(openTelemetry); } /** @@ -38,7 +34,7 @@ public final class RestletTelemetryBuilder { @CanIgnoreReturnValue public RestletTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - serverBuilder.addAttributesExtractor(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -49,7 +45,7 @@ public RestletTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - serverBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -60,7 +56,7 @@ public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHea */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - serverBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -79,7 +75,7 @@ public RestletTelemetryBuilder setCapturedResponseHeaders(List responseH */ @CanIgnoreReturnValue public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { - serverBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -92,7 +88,7 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -101,7 +97,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( public RestletTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - serverBuilder.setSpanNameExtractor(spanNameExtractorTransformer); + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -110,6 +106,6 @@ public RestletTelemetryBuilder setSpanNameExtractor( * RestletTelemetryBuilder}. */ public RestletTelemetry build() { - return new RestletTelemetry(serverBuilder.build()); + return new RestletTelemetry(builder.build()); } } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java similarity index 92% rename from instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java rename to instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java index 13d06f8ce1b9..7f137049d502 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.restlet.v1_1; +package io.opentelemetry.instrumentation.restlet.v1_1.internal; import io.opentelemetry.context.propagation.TextMapGetter; import java.util.Locale; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java similarity index 95% rename from instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java rename to instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java index 8378b494045e..64d52656d373 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.restlet.v1_1; +package io.opentelemetry.instrumentation.restlet.v1_1.internal; -import static io.opentelemetry.instrumentation.restlet.v1_1.RestletHeadersGetter.getHeaders; +import static io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletHeadersGetter.getHeaders; import com.noelios.restlet.http.HttpCall; import com.noelios.restlet.http.HttpRequest; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java new file mode 100644 index 000000000000..a4a1f1cc2890 --- /dev/null +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.restlet.v1_1.internal; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import org.restlet.data.Request; +import org.restlet.data.Response; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class RestletTelemetryBuilderFactory { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-1.1"; + + private RestletTelemetryBuilderFactory() {} + + public static DefaultHttpServerInstrumenterBuilder create( + OpenTelemetry openTelemetry) { + return new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, RestletHttpAttributesGetter.INSTANCE) + .setHeaderGetter(RestletHeadersGetter.INSTANCE); + } +} diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index f4e5486d9054..d234f84e7a62 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -22,10 +22,10 @@ /** A builder of {@link RestletTelemetry}. */ public final class RestletTelemetryBuilder { - private final DefaultHttpServerInstrumenterBuilder serverBuilder; + private final DefaultHttpServerInstrumenterBuilder builder; RestletTelemetryBuilder(OpenTelemetry openTelemetry) { - serverBuilder = + builder = new DefaultHttpServerInstrumenterBuilder<>( "io.opentelemetry.restlet-2.0", openTelemetry, RestletHttpAttributesGetter.INSTANCE) .setHeaderGetter(new RestletHeadersGetter()); @@ -38,7 +38,7 @@ public final class RestletTelemetryBuilder { @CanIgnoreReturnValue public RestletTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - serverBuilder.addAttributesExtractor(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -49,7 +49,7 @@ public RestletTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - serverBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -60,7 +60,7 @@ public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHea */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - serverBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -79,7 +79,7 @@ public RestletTelemetryBuilder setCapturedResponseHeaders(List responseH */ @CanIgnoreReturnValue public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { - serverBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -92,7 +92,7 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -101,7 +101,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( public RestletTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - serverBuilder.setSpanNameExtractor(spanNameExtractorTransformer); + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -110,6 +110,6 @@ public RestletTelemetryBuilder setSpanNameExtractor( * RestletTelemetryBuilder}. */ public RestletTelemetry build() { - return new RestletTelemetry(serverBuilder.build()); + return new RestletTelemetry(builder.build()); } } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index 6bd6b26e7918..4f2a7d9d8ef0 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -14,7 +14,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import java.util.ArrayList; import java.util.List; @@ -76,7 +76,7 @@ public Instrumenter, ServletResponseContext(accessor); SpanNameExtractor> spanNameExtractor = HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(CommonConfig.get().getKnownHttpRequestMethods()) + .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) .build(); return build(instrumentationName, accessor, spanNameExtractor, httpAttributesGetter); diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java index ce1874437fac..3eab8e96bf61 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java @@ -21,14 +21,14 @@ /** A builder of {@link SpringWebTelemetry}. */ public final class SpringWebTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-web-3.1"; - private final DefaultHttpClientInstrumenterBuilder clientBuilder; + private final DefaultHttpClientInstrumenterBuilder builder; static { WebTelemetryUtil.setBuilderExtractor(SpringWebTelemetryBuilder::getBuilder); } SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { - clientBuilder = + builder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE) .setHeaderSetter(HttpRequestSetter.INSTANCE); @@ -45,7 +45,7 @@ private DefaultHttpClientInstrumenterBuilder ge @CanIgnoreReturnValue public SpringWebTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - clientBuilder.addAttributeExtractor(attributesExtractor); + builder.addAttributeExtractor(attributesExtractor); return this; } @@ -56,7 +56,7 @@ public SpringWebTelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - clientBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -67,7 +67,7 @@ public SpringWebTelemetryBuilder setCapturedRequestHeaders(List requestH */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - clientBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -76,7 +76,7 @@ public SpringWebTelemetryBuilder setCapturedResponseHeaders(List respons public SpringWebTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -95,7 +95,7 @@ public SpringWebTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setKnownMethods(Set knownMethods) { - clientBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -108,7 +108,7 @@ public SpringWebTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -117,6 +117,6 @@ public SpringWebTelemetryBuilder setEmitExperimentalHttpClientMetrics( * SpringWebTelemetryBuilder}. */ public SpringWebTelemetry build() { - return new SpringWebTelemetry(clientBuilder.build()); + return new SpringWebTelemetry(builder.build()); } } diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java index 0e85630ed3c8..b350c9dcffab 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java @@ -28,7 +28,8 @@ public static Instrumenter create( return create(instrumentationName, httpAttributesGetter, headerGetter, customizer -> {}); } - public static Instrumenter create(Object builder) { + public static Instrumenter create( + DefaultHttpServerInstrumenterBuilder builder) { return create(builder, customizer -> {}); } @@ -45,10 +46,11 @@ public static Instrumenter create( } public static Instrumenter create( - Object builder, - Consumer> instrumenterBuilderConsumer) { - return DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure( - CommonConfig.get(), builder) - .build(instrumenterBuilderConsumer); + DefaultHttpServerInstrumenterBuilder builder, + Consumer> builderCustomizer) { + return builder + .configure(AgentCommonConfig.get()) + .setBuilderCustomizer(builderCustomizer) + .build(); } }