diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/HttpClientInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/HttpClientInstrumenterBuilder.java new file mode 100644 index 000000000000..c2dfaae9de8c --- /dev/null +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/HttpClientInstrumenterBuilder.java @@ -0,0 +1,61 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.incubator.builder.internal; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; +import java.lang.reflect.Field; +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class HttpClientInstrumenterBuilder { + private HttpClientInstrumenterBuilder() {} + + @CanIgnoreReturnValue + public static DefaultHttpClientTelemetryBuilder configure( + CoreCommonConfig config, Object builder) { + DefaultHttpClientTelemetryBuilder defaultBuilder = unwrapBuilder(builder); + set(config::getKnownHttpRequestMethods, defaultBuilder::setKnownMethods); + set(config::getClientRequestHeaders, defaultBuilder::setCapturedRequestHeaders); + set(config::getClientResponseHeaders, defaultBuilder::setCapturedResponseHeaders); + set(config::getPeerServiceResolver, defaultBuilder::setPeerServiceResolver); + set( + config::shouldEmitExperimentalHttpClientTelemetry, + defaultBuilder::setEmitExperimentalHttpClientMetrics); + return defaultBuilder; + } + + private static void set(Supplier supplier, Consumer consumer) { + T t = supplier.get(); + if (t != null) { + consumer.accept(t); + } + } + + /** + * This method is used to access the builder field of the builder object. + * + *

This approach allows us to re-use the existing builder classes from the library modules + */ + @SuppressWarnings("unchecked") + private static + DefaultHttpClientTelemetryBuilder unwrapBuilder(Object builder) { + if (builder instanceof DefaultHttpClientTelemetryBuilder) { + return (DefaultHttpClientTelemetryBuilder) builder; + } + try { + Field field = builder.getClass().getDeclaredField("builder"); + field.setAccessible(true); + return (DefaultHttpClientTelemetryBuilder) field.get(builder); + } catch (Exception e) { + throw new IllegalStateException("Could not access builder field", e); + } + } +} diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CommonConfigSetter.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CommonConfigSetter.java similarity index 87% rename from instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CommonConfigSetter.java rename to instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CommonConfigSetter.java index 0bce3e18e6bd..0153dda07640 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CommonConfigSetter.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CommonConfigSetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.incubator.internal.config; +package io.opentelemetry.instrumentation.api.incubator.config.internal; import java.util.function.Consumer; import java.util.function.Supplier; diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreCommonConfig.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreCommonConfig.java similarity index 98% rename from instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreCommonConfig.java rename to instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreCommonConfig.java index 7bf1b58f2af6..2bffed675c85 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreCommonConfig.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreCommonConfig.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.incubator.internal.config; +package io.opentelemetry.instrumentation.api.incubator.config.internal; import static java.util.Collections.emptyMap; diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreInstrumentationConfig.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreInstrumentationConfig.java similarity index 98% rename from instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreInstrumentationConfig.java rename to instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreInstrumentationConfig.java index e375cba5da3e..d786940f0305 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/CoreInstrumentationConfig.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CoreInstrumentationConfig.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.incubator.internal.config; +package io.opentelemetry.instrumentation.api.incubator.config.internal; import static java.util.Collections.emptyList; diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/EnduserConfig.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/EnduserConfig.java similarity index 97% rename from instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/EnduserConfig.java rename to instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/EnduserConfig.java index 9f56241aed18..9799cfe0f287 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/config/EnduserConfig.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/EnduserConfig.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.incubator.internal.config; +package io.opentelemetry.instrumentation.api.incubator.config.internal; import java.util.Objects; diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/instrumenter/HttpClientInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/instrumenter/HttpClientInstrumenterBuilder.java deleted file mode 100644 index a2e12e1ed1f1..000000000000 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/internal/instrumenter/HttpClientInstrumenterBuilder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.incubator.internal.instrumenter; - -import com.google.errorprone.annotations.CanIgnoreReturnValue; -import io.opentelemetry.instrumentation.api.incubator.builder.AbstractHttpClientTelemetryBuilder; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreCommonConfig; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public class HttpClientInstrumenterBuilder { - private HttpClientInstrumenterBuilder() {} - - @CanIgnoreReturnValue - public static > T configure( - CoreCommonConfig config, T builder) { - set(config::getKnownHttpRequestMethods, builder::setKnownMethods); - set(config::getClientRequestHeaders, builder::setCapturedRequestHeaders); - set(config::getClientResponseHeaders, builder::setCapturedResponseHeaders); - set(config::getPeerServiceResolver, builder::setPeerServiceResolver); - set( - config::shouldEmitExperimentalHttpClientTelemetry, - builder::setEmitExperimentalHttpClientMetrics); - return builder; - } - - private static void set(Supplier supplier, Consumer consumer) { - T t = supplier.get(); - if (t != null) { - consumer.accept(t); - } - } -} diff --git a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationInstrumentation.java b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationInstrumentation.java index 2e19864a8bdc..d2af3bc923a2 100644 --- a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationInstrumentation.java +++ b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationInstrumentation.java @@ -17,7 +17,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod; import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; diff --git a/instrumentation/log4j/log4j-appender-2.17/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v2_17/Log4jHelper.java b/instrumentation/log4j/log4j-appender-2.17/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v2_17/Log4jHelper.java index 5d3807e0673a..940b22a5a5cf 100644 --- a/instrumentation/log4j/log4j-appender-2.17/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v2_17/Log4jHelper.java +++ b/instrumentation/log4j/log4j-appender-2.17/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v2_17/Log4jHelper.java @@ -9,7 +9,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.logs.LogRecordBuilder; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.instrumentation.log4j.appender.v2_17.internal.ContextDataAccessor; import io.opentelemetry.instrumentation.log4j.appender.v2_17.internal.LogEventMapper; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; diff --git a/instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackSingletons.java b/instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackSingletons.java index 981852c54cbf..d54e814d06c7 100644 --- a/instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackSingletons.java +++ b/instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackSingletons.java @@ -7,7 +7,7 @@ import static java.util.Collections.emptyList; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.instrumentation.logback.appender.v1_0.internal.LoggingEventMapper; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; import java.util.List; diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/MicrometerSingletons.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/MicrometerSingletons.java index 860dcb918024..5f70e3645b18 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/MicrometerSingletons.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/MicrometerSingletons.java @@ -7,7 +7,7 @@ import io.micrometer.core.instrument.MeterRegistry; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.instrumentation.micrometer.v1_5.OpenTelemetryMeterRegistry; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java index 89f5b109bc82..8da60c916175 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java @@ -7,9 +7,10 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.internal.instrumenter.HttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.HttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.CommonConfigUtil; import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry; +import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetryBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.util.List; import org.springframework.http.client.ClientHttpRequestInterceptor; @@ -23,11 +24,9 @@ private RestTemplateInstrumentation() {} static RestTemplate addIfNotPresent( RestTemplate restTemplate, OpenTelemetry openTelemetry, ConfigProperties config) { - ClientHttpRequestInterceptor instrumentationInterceptor = - HttpClientInstrumenterBuilder.configure( - CommonConfigUtil.getCommonConfig(config), SpringWebTelemetry.builder(openTelemetry)) - .build() - .newInterceptor(); + SpringWebTelemetryBuilder builder = SpringWebTelemetry.builder(openTelemetry); + HttpClientInstrumenterBuilder.configure(CommonConfigUtil.getCommonConfig(config), builder); + ClientHttpRequestInterceptor instrumentationInterceptor = builder.build().newInterceptor(); List restTemplateInterceptors = restTemplate.getInterceptors(); if (restTemplateInterceptors.stream() diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/CommonConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/CommonConfigUtil.java index a02e281d5655..10ff981f2345 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/CommonConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/CommonConfigUtil.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreCommonConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; /** diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/ConfigPropertiesBridge.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/ConfigPropertiesBridge.java index 37a7bbbf9b4f..f2b69d7e29be 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/ConfigPropertiesBridge.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/ConfigPropertiesBridge.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import java.time.Duration; diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java index 6ec149352bca..3961170a6d88 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/CommonConfig.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.bootstrap.internal; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreCommonConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/DeprecatedConfigProperties.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/DeprecatedConfigProperties.java index be9dd9247139..33419774e9f0 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/DeprecatedConfigProperties.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/DeprecatedConfigProperties.java @@ -8,7 +8,7 @@ import static java.util.Collections.emptyList; import static java.util.logging.Level.WARNING; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import java.util.List; import java.util.logging.Logger; diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/EmptyInstrumentationConfig.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/EmptyInstrumentationConfig.java index 1942c6aaa191..4251d19ff45b 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/EmptyInstrumentationConfig.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/EmptyInstrumentationConfig.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.bootstrap.internal; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import java.time.Duration; import java.util.List; import java.util.Map; diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ExperimentalConfig.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ExperimentalConfig.java index 255ce114706b..4f0b57fd75cb 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ExperimentalConfig.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ExperimentalConfig.java @@ -7,7 +7,7 @@ import static java.util.Collections.emptyList; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import java.util.List; /** diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/InstrumentationConfig.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/InstrumentationConfig.java index fc1c7fb75095..bb3af4668d72 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/InstrumentationConfig.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/InstrumentationConfig.java @@ -7,7 +7,7 @@ import static java.util.Objects.requireNonNull; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import java.util.logging.Logger; /** diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenterBuilder.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenterBuilder.java index 129dc556bc2c..71ad0c1f6d8d 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenterBuilder.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenterBuilder.java @@ -8,13 +8,12 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientTelemetryBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.HttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; -import java.lang.reflect.Field; import java.util.Optional; import java.util.function.Consumer; -import java.util.function.Supplier; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -50,44 +49,7 @@ public static Instrumenter createWithCust public static Instrumenter createWithCustomizer( Object builder, Consumer> instrumenterBuilderConsumer) { - CommonConfig config = CommonConfig.get(); - DefaultHttpClientTelemetryBuilder defaultBuilder = unwrapBuilder(builder); - set(config::getKnownHttpRequestMethods, defaultBuilder::setKnownMethods); - set(config::getClientRequestHeaders, defaultBuilder::setCapturedRequestHeaders); - set(config::getClientResponseHeaders, defaultBuilder::setCapturedResponseHeaders); - // is not exposed in the public API - set(config::getPeerServiceResolver, defaultBuilder::setPeerServiceResolver); - set( - config::shouldEmitExperimentalHttpClientTelemetry, - defaultBuilder::setEmitExperimentalHttpClientMetrics); - // is not exposed in the public API - return defaultBuilder.instrumenter(instrumenterBuilderConsumer); - } - - /** - * This method is used to access the builder field of the builder object. - * - *

This approach allows us to re-use the existing builder classes from the library modules - */ - @SuppressWarnings("unchecked") - private static - DefaultHttpClientTelemetryBuilder unwrapBuilder(Object builder) { - if (builder instanceof DefaultHttpClientTelemetryBuilder) { - return (DefaultHttpClientTelemetryBuilder) builder; - } - try { - Field field = builder.getClass().getDeclaredField("builder"); - field.setAccessible(true); - return (DefaultHttpClientTelemetryBuilder) field.get(builder); - } catch (Exception e) { - throw new IllegalStateException("Could not access builder field", e); - } - } - - private static void set(Supplier supplier, Consumer consumer) { - T t = supplier.get(); - if (t != null) { - consumer.accept(t); - } + return HttpClientInstrumenterBuilder.configure(CommonConfig.get(), builder) + .instrumenter(instrumenterBuilderConsumer); } } diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesBridge.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesBridge.java index d0aa2c97eec5..12812e63e4e1 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesBridge.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesBridge.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.tooling.config; -import io.opentelemetry.instrumentation.api.incubator.internal.config.CoreInstrumentationConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreInstrumentationConfig; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import java.time.Duration;