From 68dd772872c0eeaaadcdcf90ab44be80ee312aca Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 25 Jun 2024 09:14:45 +0200 Subject: [PATCH 01/18] use DefaultHttpServerInstrumenterBuilder to configure spring starter --- .../DefaultHttpServerInstrumenterBuilder.java | 254 ++++++++++++++++++ .../ApacheHttpClientTelemetryBuilder.java | 19 +- .../ApacheHttpClient5TelemetryBuilder.java | 18 +- .../jdbc/DataSourcePostProcessor.java | 2 +- .../R2dbcInstrumentingPostProcessor.java | 2 +- ...bfluxInstrumentationAutoConfiguration.java | 12 +- .../webflux/WebClientBeanPostProcessor.java | 18 +- ...bMvc5InstrumentationAutoConfiguration.java | 9 +- ...bMvc6InstrumentationAutoConfiguration.java | 9 +- .../internal/InstrumentationConfigUtil.java | 21 -- .../properties/InstrumentationConfigUtil.java | 5 + ...itional-spring-configuration-metadata.json | 16 ++ ...xInstrumentationAutoConfigurationTest.java | 6 + .../WebClientBeanPostProcessorTest.java | 25 +- .../web/v3_1/SpringWebTelemetryBuilder.java | 18 +- .../webflux/v5_0/client/WebClientHelper.java | 23 +- .../v5_3/SpringWebfluxTelemetryBuilder.java | 127 ++------- .../internal/ClientInstrumenterFactory.java | 80 ------ .../v5_3/SpringWebMvcTelemetryBuilder.java | 71 +---- .../v6_0/SpringWebMvcTelemetryBuilder.java | 72 +---- .../smoketest/OtelSpringStarterSmokeTest.java | 2 +- .../AbstractOtelSpringStarterSmokeTest.java | 16 +- .../src/main/resources/application.yaml | 2 + ...actOtelReactiveSpringStarterSmokeTest.java | 15 +- .../spring/smoketest/SpringTestUtil.java | 43 +++ 25 files changed, 477 insertions(+), 408 deletions(-) create mode 100644 instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java delete mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationConfigUtil.java delete mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/ClientInstrumenterFactory.java create mode 100644 smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java 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 new file mode 100644 index 000000000000..4ed623e2ca5c --- /dev/null +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java @@ -0,0 +1,254 @@ +/* + * 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.api.OpenTelemetry; +import io.opentelemetry.context.propagation.TextMapGetter; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; +import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; +import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBuilder; +import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; +import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +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 DefaultHttpServerInstrumenterBuilder { + + private final String instrumentationName; + private final OpenTelemetry openTelemetry; + + private final List> additionalExtractors = + new ArrayList<>(); + private Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractorTransformer = Function.identity(); + private final HttpServerAttributesExtractorBuilder + httpAttributesExtractorBuilder; + private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; + + @Nullable private TextMapGetter headerGetter; + private Function, ? extends SpanNameExtractor> + spanNameExtractorTransformer = Function.identity(); + private final HttpServerRouteBuilder httpServerRouteBuilder; + private final HttpServerAttributesGetter attributesGetter; + private boolean emitExperimentalHttpServerMetrics = false; + + public DefaultHttpServerInstrumenterBuilder( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpServerAttributesGetter attributesGetter) { + this.instrumentationName = instrumentationName; + this.openTelemetry = openTelemetry; + httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(attributesGetter); + httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); + httpServerRouteBuilder = HttpServerRoute.builder(attributesGetter); + this.attributesGetter = attributesGetter; + } + + /** + * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented + * items. + */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder addAttributesExtractor( + AttributesExtractor attributesExtractor) { + additionalExtractors.add(attributesExtractor); + return this; + } + + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + this.statusExtractorTransformer = statusExtractor; + return this; + } + + /** + * Configures the HTTP request headers that will be captured as span attributes. + * + * @param requestHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setCapturedRequestHeaders( + List requestHeaders) { + httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + return this; + } + + /** + * Configures the HTTP response headers that will be captured as span attributes. + * + * @param responseHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setCapturedResponseHeaders( + List responseHeaders) { + httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + return this; + } + + /** + * Configures the instrumentation to recognize an alternative set of HTTP request methods. + * + *

By default, this instrumentation defines "known" methods as the ones listed in RFC9110 and the PATCH + * method defined in RFC5789. + * + *

Note: calling this method overrides the default known method sets completely; it does + * not supplement it. + * + * @param knownMethods A set of recognized HTTP request methods. + * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Set) + */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setKnownMethods( + Set knownMethods) { + httpAttributesExtractorBuilder.setKnownMethods(knownMethods); + httpSpanNameExtractorBuilder.setKnownMethods(knownMethods); + httpServerRouteBuilder.setKnownMethods(knownMethods); + return this; + } + + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setHeaderGetter( + @Nullable TextMapGetter headerGetter) { + this.headerGetter = headerGetter; + return this; + } + + /** + * Configures the instrumentation to emit experimental HTTP server metrics. + * + * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics + * are to be emitted. + */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder + setEmitExperimentalHttpServerMetrics(boolean emitExperimentalHttpServerMetrics) { + this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + return this; + } + + /** Sets custom {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder setSpanNameExtractor( + Function, ? extends SpanNameExtractor> + spanNameExtractorTransformer) { + this.spanNameExtractorTransformer = spanNameExtractorTransformer; + return this; + } + + public Instrumenter build() { + return build(b -> {}); + } + + public Instrumenter build( + Consumer> instrumenterBuilderConsumer) { + + InstrumenterBuilder builder = builder(); + instrumenterBuilderConsumer.accept(builder); + + if (headerGetter != null) { + return builder.buildServerInstrumenter(headerGetter); + } + return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); + } + + public InstrumenterBuilder builder() { + SpanNameExtractor spanNameExtractor = + spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); + + InstrumenterBuilder builder = + Instrumenter.builder( + openTelemetry, instrumentationName, spanNameExtractor) + .setSpanStatusExtractor( + statusExtractorTransformer.apply(HttpSpanStatusExtractor.create(attributesGetter))) + .addAttributesExtractor(httpAttributesExtractorBuilder.build()) + .addAttributesExtractors(additionalExtractors) + .addContextCustomizer(httpServerRouteBuilder.build()) + .addOperationMetrics(HttpServerMetrics.get()); + if (emitExperimentalHttpServerMetrics) { + builder + .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(attributesGetter)) + .addOperationMetrics(HttpServerExperimentalMetrics.get()); + } + + return builder; + } + + public OpenTelemetry getOpenTelemetry() { + return openTelemetry; + } + + @CanIgnoreReturnValue + public static + DefaultHttpServerInstrumenterBuilder unwrapAndConfigure( + CoreCommonConfig config, Object builder) { + DefaultHttpServerInstrumenterBuilder defaultBuilder = unwrapBuilder(builder); + set(config::getKnownHttpRequestMethods, defaultBuilder::setKnownMethods); + set(config::getServerRequestHeaders, defaultBuilder::setCapturedRequestHeaders); + set(config::getServerResponseHeaders, defaultBuilder::setCapturedResponseHeaders); + set( + config::shouldEmitExperimentalHttpServerTelemetry, + defaultBuilder::setEmitExperimentalHttpServerMetrics); + 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 + DefaultHttpServerInstrumenterBuilder unwrapBuilder(Object builder) { + if (builder instanceof DefaultHttpServerInstrumenterBuilder) { + return (DefaultHttpServerInstrumenterBuilder) builder; + } + try { + Field field = builder.getClass().getDeclaredField("serverBuilder"); + field.setAccessible(true); + return (DefaultHttpServerInstrumenterBuilder) field.get(builder); + } catch (Exception e) { + throw new IllegalStateException("Could not access builder field", e); + } + } +} 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 3526ca01436a..1d0c440192cb 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,10 +20,11 @@ public final class ApacheHttpClientTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-4.3"; - private final DefaultHttpClientInstrumenterBuilder builder; + private final DefaultHttpClientInstrumenterBuilder + clientBuilder; ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { - builder = + clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClientHttpAttributesGetter.INSTANCE); } @@ -36,7 +37,7 @@ public final class ApacheHttpClientTelemetryBuilder { public ApacheHttpClientTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - builder.addAttributeExtractor(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } @@ -47,7 +48,7 @@ public ApacheHttpClientTelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - builder.setCapturedRequestHeaders(requestHeaders); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -58,7 +59,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List r */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - builder.setCapturedResponseHeaders(responseHeaders); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -77,7 +78,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List */ @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setKnownMethods(Set knownMethods) { - builder.setKnownMethods(knownMethods); + clientBuilder.setKnownMethods(knownMethods); return this; } @@ -90,7 +91,7 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Set knownMethods @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -101,7 +102,7 @@ public ApacheHttpClientTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - builder.setSpanNameExtractor(spanNameExtractorTransformer); + clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -111,6 +112,6 @@ public ApacheHttpClientTelemetryBuilder setSpanNameExtractor( */ public ApacheHttpClientTelemetry build() { return new ApacheHttpClientTelemetry( - builder.build(), builder.getOpenTelemetry().getPropagators()); + clientBuilder.build(), clientBuilder.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 e9a5eb273de0..8dbf7215c8be 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 - builder; + clientBuilder; ApacheHttpClient5TelemetryBuilder(OpenTelemetry openTelemetry) { - builder = + clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClient5HttpAttributesGetter.INSTANCE); } @@ -37,7 +37,7 @@ public final class ApacheHttpClient5TelemetryBuilder { public ApacheHttpClient5TelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - builder.addAttributeExtractor(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } @@ -48,7 +48,7 @@ public ApacheHttpClient5TelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - builder.setCapturedRequestHeaders(requestHeaders); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -60,7 +60,7 @@ public ApacheHttpClient5TelemetryBuilder setCapturedRequestHeaders(List @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setCapturedResponseHeaders( List responseHeaders) { - builder.setCapturedResponseHeaders(responseHeaders); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -79,7 +79,7 @@ public ApacheHttpClient5TelemetryBuilder setCapturedResponseHeaders( */ @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setKnownMethods(Set knownMethods) { - builder.setKnownMethods(knownMethods); + clientBuilder.setKnownMethods(knownMethods); return this; } @@ -92,7 +92,7 @@ public ApacheHttpClient5TelemetryBuilder setKnownMethods(Set knownMethod @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -103,7 +103,7 @@ public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - builder.setSpanNameExtractor(spanNameExtractorTransformer); + clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -113,6 +113,6 @@ public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor( */ public ApacheHttpClient5Telemetry build() { return new ApacheHttpClient5Telemetry( - builder.build(), builder.getOpenTelemetry().getPropagators()); + clientBuilder.build(), clientBuilder.getOpenTelemetry().getPropagators()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/jdbc/DataSourcePostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/jdbc/DataSourcePostProcessor.java index d733caa22b43..f0884f171e1f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/jdbc/DataSourcePostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/jdbc/DataSourcePostProcessor.java @@ -8,7 +8,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry; -import io.opentelemetry.instrumentation.spring.autoconfigure.internal.InstrumentationConfigUtil; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import javax.sql.DataSource; import org.springframework.aop.scope.ScopedProxyUtils; diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java index d3bddb3d8055..95ad7aad333c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.r2dbc.v1_0.R2dbcTelemetry; -import io.opentelemetry.instrumentation.spring.autoconfigure.internal.InstrumentationConfigUtil; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryOptions; diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java index cfd5f5eb5ed7..7a0cc4f29d91 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; @@ -30,14 +30,14 @@ public SpringWebfluxInstrumentationAutoConfiguration() {} // static to avoid "is not eligible for getting processed by all BeanPostProcessors" warning @Bean static WebClientBeanPostProcessor otelWebClientBeanPostProcessor( - ObjectProvider openTelemetryProvider) { - return new WebClientBeanPostProcessor(openTelemetryProvider); + ObjectProvider openTelemetryProvider, + ObjectProvider configPropertiesProvider) { + return new WebClientBeanPostProcessor(openTelemetryProvider, configPropertiesProvider); } @Bean - WebFilter telemetryFilter(OpenTelemetry openTelemetry) { - return SpringWebfluxTelemetry.builder(openTelemetry) - .build() + WebFilter telemetryFilter(OpenTelemetry openTelemetry, ConfigProperties config) { + return WebClientBeanPostProcessor.getWebfluxTelemetry(openTelemetry, config) .createWebFilterAndRegisterReactorHook(); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index 1ee2c56c1da0..d1bb746a4b24 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -6,7 +6,9 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.webflux; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.web.reactive.function.client.WebClient; @@ -19,9 +21,20 @@ final class WebClientBeanPostProcessor implements BeanPostProcessor { private final ObjectProvider openTelemetryProvider; + private final ObjectProvider configPropertiesProvider; - WebClientBeanPostProcessor(ObjectProvider openTelemetryProvider) { + WebClientBeanPostProcessor( + ObjectProvider openTelemetryProvider, + ObjectProvider configPropertiesProvider) { this.openTelemetryProvider = openTelemetryProvider; + this.configPropertiesProvider = configPropertiesProvider; + } + + static SpringWebfluxTelemetry getWebfluxTelemetry( + OpenTelemetry openTelemetry, ConfigProperties config) { + return InstrumentationConfigUtil.configureBuilder( + config, SpringWebfluxTelemetry.builder(openTelemetry)) + .build(); } @Override @@ -38,7 +51,8 @@ public Object postProcessAfterInitialization(Object bean, String beanName) { private WebClient.Builder wrapBuilder(WebClient.Builder webClientBuilder) { SpringWebfluxTelemetry instrumentation = - SpringWebfluxTelemetry.create(openTelemetryProvider.getObject()); + getWebfluxTelemetry( + openTelemetryProvider.getObject(), configPropertiesProvider.getObject()); return webClientBuilder.filters(instrumentation::addClientTracingFilter); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index a57d2ab79df5..c4dad1e5ba22 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -7,7 +7,9 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import javax.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; @@ -22,7 +24,10 @@ public class SpringWebMvc5InstrumentationAutoConfiguration { @Bean - Filter otelWebMvcFilter(OpenTelemetry openTelemetry) { - return SpringWebMvcTelemetry.create(openTelemetry).createServletFilter(); + Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { + return InstrumentationConfigUtil.configureBuilder( + config, SpringWebMvcTelemetry.builder(openTelemetry)) + .build() + .createServletFilter(); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index ca68d0e90d19..4749cb6ed142 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -7,7 +7,9 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import jakarta.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; @@ -22,7 +24,10 @@ public class SpringWebMvc6InstrumentationAutoConfiguration { @Bean - Filter otelWebMvcFilter(OpenTelemetry openTelemetry) { - return SpringWebMvcTelemetry.create(openTelemetry).createServletFilter(); + Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { + return InstrumentationConfigUtil.configureBuilder( + config, SpringWebMvcTelemetry.builder(openTelemetry)) + .build() + .createServletFilter(); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationConfigUtil.java deleted file mode 100644 index 0fec424a5e85..000000000000 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationConfigUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.autoconfigure.internal; - -import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public class InstrumentationConfigUtil { - private InstrumentationConfigUtil() {} - - public static boolean isStatementSanitizationEnabled(ConfigProperties config, String key) { - return config.getBoolean( - key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true)); - } -} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 692f7296b375..234d3e77beeb 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -26,4 +26,9 @@ public static T configureBuilder( getBuilder.apply(builder).configure(new CommonConfig(new ConfigPropertiesBridge(config))); return builder; } + + public static boolean isStatementSanitizationEnabled(ConfigProperties config, String key) { + return config.getBoolean( + key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true)); + } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 19f162d812d0..22f7f24b3f9b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -312,6 +312,22 @@ "description": "Configures the instrumentation to recognize an alternative set of HTTP request methods. All other methods will be treated as _OTHER.", "defaultValue": "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT,TRACE" }, + { + "name": "otel.instrumentation.http.server.capture-request-headers", + "type": "java.util.List", + "description": "List of HTTP request headers to capture in HTTP servers." + }, + { + "name": "otel.instrumentation.http.server.capture-response-headers", + "type": "java.util.List", + "description": "List of HTTP response headers to capture in HTTP servers." + }, + { + "name": "otel.instrumentation.http.server.emit-experimental-telemetry", + "type": "java.lang.Boolean", + "description": "Enable the capture of experimental HTTP server telemetry. Add the http.request.body.size and http.response.body.size> attributes to spans, and record the http.server.request.size and http.server.response.size metrics.", + "defaultValue": false + }, { "name": "otel.instrumentation.jdbc.enabled", "type": "java.lang.Boolean", diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfigurationTest.java index aeecebf37807..ba1bca851cf7 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfigurationTest.java @@ -8,6 +8,9 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import java.util.Collections; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -17,6 +20,9 @@ class SpringWebfluxInstrumentationAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withBean(OpenTelemetry.class, OpenTelemetry::noop) + .withBean( + ConfigProperties.class, + () -> DefaultConfigProperties.createFromMap(Collections.emptyMap())) .withConfiguration( AutoConfigurations.of(SpringWebfluxInstrumentationAutoConfiguration.class)); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessorTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessorTest.java index 55abca473a01..7289ea828950 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessorTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessorTest.java @@ -8,6 +8,9 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import java.util.Collections; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -20,6 +23,8 @@ class WebClientBeanPostProcessorTest { static { beanFactory.registerSingleton("openTelemetry", OpenTelemetry.noop()); + beanFactory.registerSingleton( + "configProperties", DefaultConfigProperties.createFromMap(Collections.emptyMap())); } @Test @@ -27,7 +32,9 @@ class WebClientBeanPostProcessorTest { "when processed bean is NOT of type WebClient or WebClientBuilder should return Object") void returnsObject() { BeanPostProcessor underTest = - new WebClientBeanPostProcessor(beanFactory.getBeanProvider(OpenTelemetry.class)); + new WebClientBeanPostProcessor( + beanFactory.getBeanProvider(OpenTelemetry.class), + beanFactory.getBeanProvider(ConfigProperties.class)); assertThat(underTest.postProcessAfterInitialization(new Object(), "testObject")) .isExactlyInstanceOf(Object.class); @@ -37,7 +44,9 @@ void returnsObject() { @DisplayName("when processed bean is of type WebClient should return WebClient") void returnsWebClient() { BeanPostProcessor underTest = - new WebClientBeanPostProcessor(beanFactory.getBeanProvider(OpenTelemetry.class)); + new WebClientBeanPostProcessor( + beanFactory.getBeanProvider(OpenTelemetry.class), + beanFactory.getBeanProvider(ConfigProperties.class)); assertThat(underTest.postProcessAfterInitialization(WebClient.create(), "testWebClient")) .isInstanceOf(WebClient.class); @@ -47,7 +56,9 @@ void returnsWebClient() { @DisplayName("when processed bean is of type WebClientBuilder should return WebClientBuilder") void returnsWebClientBuilder() { BeanPostProcessor underTest = - new WebClientBeanPostProcessor(beanFactory.getBeanProvider(OpenTelemetry.class)); + new WebClientBeanPostProcessor( + beanFactory.getBeanProvider(OpenTelemetry.class), + beanFactory.getBeanProvider(ConfigProperties.class)); assertThat( underTest.postProcessAfterInitialization(WebClient.builder(), "testWebClientBuilder")) @@ -58,7 +69,9 @@ void returnsWebClientBuilder() { @DisplayName("when processed bean is of type WebClient should add exchange filter to WebClient") void addsExchangeFilterWebClient() { BeanPostProcessor underTest = - new WebClientBeanPostProcessor(beanFactory.getBeanProvider(OpenTelemetry.class)); + new WebClientBeanPostProcessor( + beanFactory.getBeanProvider(OpenTelemetry.class), + beanFactory.getBeanProvider(ConfigProperties.class)); WebClient webClient = WebClient.create(); Object processedWebClient = @@ -81,7 +94,9 @@ void addsExchangeFilterWebClient() { "when processed bean is of type WebClientBuilder should add ONE exchange filter to WebClientBuilder") void addsExchangeFilterWebClientBuilder() { BeanPostProcessor underTest = - new WebClientBeanPostProcessor(beanFactory.getBeanProvider(OpenTelemetry.class)); + new WebClientBeanPostProcessor( + beanFactory.getBeanProvider(OpenTelemetry.class), + beanFactory.getBeanProvider(ConfigProperties.class)); WebClient.Builder webClientBuilder = WebClient.builder(); underTest.postProcessAfterInitialization(webClientBuilder, "testWebClientBuilder"); 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 3eab8e96bf61..ce1874437fac 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 builder; + private final DefaultHttpClientInstrumenterBuilder clientBuilder; static { WebTelemetryUtil.setBuilderExtractor(SpringWebTelemetryBuilder::getBuilder); } SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { - builder = + clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE) .setHeaderSetter(HttpRequestSetter.INSTANCE); @@ -45,7 +45,7 @@ private DefaultHttpClientInstrumenterBuilder ge @CanIgnoreReturnValue public SpringWebTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - builder.addAttributeExtractor(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } @@ -56,7 +56,7 @@ public SpringWebTelemetryBuilder addAttributeExtractor( */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - builder.setCapturedRequestHeaders(requestHeaders); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -67,7 +67,7 @@ public SpringWebTelemetryBuilder setCapturedRequestHeaders(List requestH */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - builder.setCapturedResponseHeaders(responseHeaders); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -76,7 +76,7 @@ public SpringWebTelemetryBuilder setCapturedResponseHeaders(List respons public SpringWebTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - builder.setSpanNameExtractor(spanNameExtractorTransformer); + clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -95,7 +95,7 @@ public SpringWebTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setKnownMethods(Set knownMethods) { - builder.setKnownMethods(knownMethods); + clientBuilder.setKnownMethods(knownMethods); return this; } @@ -108,7 +108,7 @@ public SpringWebTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -117,6 +117,6 @@ public SpringWebTelemetryBuilder setEmitExperimentalHttpClientMetrics( * SpringWebTelemetryBuilder}. */ public SpringWebTelemetry build() { - return new SpringWebTelemetry(builder.build()); + return new SpringWebTelemetry(clientBuilder.build()); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java index b13e8a67a2e8..725ba7de4e13 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java @@ -5,17 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.client; -import static java.util.Collections.singletonList; - import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientPeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.ClientInstrumenterFactory; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientTracingFilter; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpClientInstrumenters; import java.util.List; -import java.util.function.Function; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; @@ -23,20 +18,8 @@ public final class WebClientHelper { private static final Instrumenter instrumenter = - ClientInstrumenterFactory.create( - GlobalOpenTelemetry.get(), - builder -> - builder - .setCapturedRequestHeaders(AgentCommonConfig.get().getClientRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getClientResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()), - builder -> builder.setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()), - Function.identity(), - singletonList( - HttpClientPeerServiceAttributesExtractor.create( - WebClientHttpAttributesGetter.INSTANCE, - AgentCommonConfig.get().getPeerServiceResolver())), - AgentCommonConfig.get().shouldEmitExperimentalHttpClientTelemetry()); + JavaagentHttpClientInstrumenters.create( + "io.opentelemetry.spring-webflux-5.3", WebClientHttpAttributesGetter.INSTANCE); public static void addFilter(List exchangeFilterFunctions) { for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index a24930d01695..139d3c9d8c18 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -7,26 +7,15 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; +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.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.ClientInstrumenterFactory; -import java.util.ArrayList; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import java.util.List; import java.util.Set; -import java.util.function.Consumer; import java.util.function.Function; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; @@ -36,38 +25,18 @@ public final class SpringWebfluxTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; - private final OpenTelemetry openTelemetry; - - private final List> - clientAdditionalExtractors = new ArrayList<>(); - private final List> - serverAdditionalExtractors = new ArrayList<>(); - - private final HttpServerAttributesExtractorBuilder - httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(WebfluxServerHttpAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpServerSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(WebfluxServerHttpAttributesGetter.INSTANCE); - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(WebfluxServerHttpAttributesGetter.INSTANCE); - - private Function< - SpanNameExtractor, ? extends SpanNameExtractor> - clientSpanNameExtractorTransformer = Function.identity(); - private Function< - SpanNameExtractor, - ? extends SpanNameExtractor> - serverSpanNameExtractorTransformer = Function.identity(); - - private Consumer> - clientExtractorConfigurer = builder -> {}; - private Consumer> clientSpanNameExtractorConfigurer = - builder -> {}; - private boolean emitExperimentalHttpClientTelemetry = false; - private boolean emitExperimentalHttpServerTelemetry = false; + private final DefaultHttpClientInstrumenterBuilder clientBuilder; + private final DefaultHttpServerInstrumenterBuilder + serverBuilder; SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + clientBuilder = + new DefaultHttpClientInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, WebClientHttpAttributesGetter.INSTANCE); + serverBuilder = + new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, WebfluxServerHttpAttributesGetter.INSTANCE) + .setHeaderGetter(WebfluxTextMapGetter.INSTANCE); } /** @@ -77,7 +46,7 @@ public final class SpringWebfluxTelemetryBuilder { @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder addClientAttributesExtractor( AttributesExtractor attributesExtractor) { - clientAdditionalExtractors.add(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } @@ -89,9 +58,7 @@ public SpringWebfluxTelemetryBuilder addClientAttributesExtractor( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedClientRequestHeaders( List requestHeaders) { - clientExtractorConfigurer = - clientExtractorConfigurer.andThen( - builder -> builder.setCapturedRequestHeaders(requestHeaders)); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -103,9 +70,7 @@ public SpringWebfluxTelemetryBuilder setCapturedClientRequestHeaders( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedClientResponseHeaders( List responseHeaders) { - clientExtractorConfigurer = - clientExtractorConfigurer.andThen( - builder -> builder.setCapturedResponseHeaders(responseHeaders)); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -116,7 +81,7 @@ public SpringWebfluxTelemetryBuilder setCapturedClientResponseHeaders( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder addServerAttributesExtractor( AttributesExtractor attributesExtractor) { - serverAdditionalExtractors.add(attributesExtractor); + serverBuilder.addAttributesExtractor(attributesExtractor); return this; } @@ -129,7 +94,7 @@ public SpringWebfluxTelemetryBuilder addServerAttributesExtractor( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedServerRequestHeaders( List requestHeaders) { - httpServerAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + serverBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -142,7 +107,7 @@ public SpringWebfluxTelemetryBuilder setCapturedServerRequestHeaders( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedServerResponseHeaders( List responseHeaders) { - httpServerAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + serverBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -162,13 +127,8 @@ public SpringWebfluxTelemetryBuilder setCapturedServerResponseHeaders( */ @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setKnownMethods(Set knownMethods) { - clientExtractorConfigurer = - clientExtractorConfigurer.andThen(builder -> builder.setKnownMethods(knownMethods)); - clientSpanNameExtractorConfigurer = - clientSpanNameExtractorConfigurer.andThen(builder -> builder.setKnownMethods(knownMethods)); - httpServerAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpServerSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + clientBuilder.setKnownMethods(knownMethods); + serverBuilder.setKnownMethods(knownMethods); return this; } @@ -181,7 +141,7 @@ public SpringWebfluxTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpClientTelemetry( boolean emitExperimentalHttpClientTelemetry) { - this.emitExperimentalHttpClientTelemetry = emitExperimentalHttpClientTelemetry; + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientTelemetry); return this; } @@ -194,7 +154,7 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpClientTelemetry( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( boolean emitExperimentalHttpServerTelemetry) { - this.emitExperimentalHttpServerTelemetry = emitExperimentalHttpServerTelemetry; + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerTelemetry); return this; } @@ -203,7 +163,7 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( Function, ? extends SpanNameExtractor> clientSpanNameExtractor) { - this.clientSpanNameExtractorTransformer = clientSpanNameExtractor; + clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; } @@ -214,7 +174,7 @@ public SpringWebfluxTelemetryBuilder setServerSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> serverSpanNameExtractor) { - this.serverSpanNameExtractorTransformer = serverSpanNameExtractor; + serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); return this; } @@ -223,40 +183,9 @@ public SpringWebfluxTelemetryBuilder setServerSpanNameExtractor( * SpringWebfluxTelemetryBuilder}. */ public SpringWebfluxTelemetry build() { - Instrumenter clientInstrumenter = - ClientInstrumenterFactory.create( - openTelemetry, - clientExtractorConfigurer, - clientSpanNameExtractorConfigurer, - clientSpanNameExtractorTransformer, - clientAdditionalExtractors, - emitExperimentalHttpClientTelemetry); - - Instrumenter serverInstrumenter = - buildServerInstrumenter(); - return new SpringWebfluxTelemetry( - clientInstrumenter, serverInstrumenter, openTelemetry.getPropagators()); - } - - private Instrumenter buildServerInstrumenter() { - WebfluxServerHttpAttributesGetter getter = WebfluxServerHttpAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - serverSpanNameExtractorTransformer.apply(httpServerSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(getter)) - .addAttributesExtractor(httpServerAttributesExtractorBuilder.build()) - .addAttributesExtractors(serverAdditionalExtractors) - .addContextCustomizer(httpServerRouteBuilder.build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (emitExperimentalHttpServerTelemetry) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(getter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - return builder.buildServerInstrumenter(WebfluxTextMapGetter.INSTANCE); + clientBuilder.build(), + serverBuilder.build(), + clientBuilder.getOpenTelemetry().getPropagators()); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/ClientInstrumenterFactory.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/ClientInstrumenterFactory.java deleted file mode 100644 index bb8217539da3..000000000000 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/ClientInstrumenterFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.webflux.v5_3.internal; - -import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientExperimentalMetrics; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; -import org.springframework.web.reactive.function.client.ClientRequest; -import org.springframework.web.reactive.function.client.ClientResponse; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -// client builder is separate so that it can be used by javaagent instrumentation -// which supports 5.0, without triggering the server instrumentation which depends on webflux 5.3 -public final class ClientInstrumenterFactory { - - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; - - public static Instrumenter create( - OpenTelemetry openTelemetry, - Consumer> - extractorConfigurer, - Consumer> spanNameExtractorConfigurer, - Function, ? extends SpanNameExtractor> - spanNameExtractorTransformer, - List> additionalExtractors, - boolean emitExperimentalHttpClientTelemetry) { - - WebClientHttpAttributesGetter httpAttributesGetter = WebClientHttpAttributesGetter.INSTANCE; - - HttpClientAttributesExtractorBuilder extractorBuilder = - HttpClientAttributesExtractor.builder(httpAttributesGetter); - extractorConfigurer.accept(extractorBuilder); - - HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(httpAttributesGetter); - spanNameExtractorConfigurer.accept(httpSpanNameExtractorBuilder); - SpanNameExtractor spanNameExtractor = - spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); - - InstrumenterBuilder clientBuilder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor(extractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addOperationMetrics(HttpClientMetrics.get()); - - if (emitExperimentalHttpClientTelemetry) { - clientBuilder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpClientExperimentalMetrics.get()); - } - - // headers are injected elsewhere; ClientRequest is immutable - return clientBuilder.buildInstrumenter(alwaysClient()); - } - - private ClientInstrumenterFactory() {} -} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index 67a3a000b3ae..500ea16b1b8b 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -7,21 +7,10 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -33,24 +22,14 @@ public final class SpringWebMvcTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webmvc-5.3"; - private final OpenTelemetry openTelemetry; - private final List> - additionalExtractors = new ArrayList<>(); - private final HttpServerAttributesExtractorBuilder - httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private Function< - SpanNameExtractor, - ? extends SpanNameExtractor> - spanNameExtractorTransformer = Function.identity(); - private boolean emitExperimentalHttpServerMetrics = false; + private final DefaultHttpServerInstrumenterBuilder + serverBuilder; SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + serverBuilder = + new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE) + .setHeaderGetter(JavaxHttpServletRequestGetter.INSTANCE); } /** @@ -60,7 +39,7 @@ public final class SpringWebMvcTelemetryBuilder { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + serverBuilder.addAttributesExtractor(attributesExtractor); return this; } @@ -71,7 +50,7 @@ public SpringWebMvcTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + serverBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -82,7 +61,7 @@ public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List reque */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + serverBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -93,7 +72,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { - this.spanNameExtractorTransformer = spanNameExtractor; + serverBuilder.setSpanNameExtractor(spanNameExtractor); return this; } @@ -112,9 +91,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { - httpAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + serverBuilder.setKnownMethods(knownMethods); return this; } @@ -127,7 +104,7 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -136,26 +113,6 @@ public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( * SpringWebMvcTelemetryBuilder}. */ public SpringWebMvcTelemetry build() { - SpringWebMvcHttpAttributesGetter httpAttributesGetter = - SpringWebMvcHttpAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addContextCustomizer(httpServerRouteBuilder.build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (emitExperimentalHttpServerMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - - return new SpringWebMvcTelemetry( - builder.buildServerInstrumenter(JavaxHttpServletRequestGetter.INSTANCE)); + return new SpringWebMvcTelemetry(serverBuilder.build()); } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 9b3e3b9e4e48..801c01b05375 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -7,23 +7,12 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -32,25 +21,14 @@ public final class SpringWebMvcTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webmvc-6.0"; - - private final OpenTelemetry openTelemetry; - private final List> - additionalExtractors = new ArrayList<>(); - private final HttpServerAttributesExtractorBuilder - httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(SpringWebMvcHttpAttributesGetter.INSTANCE); - private Function< - SpanNameExtractor, - ? extends SpanNameExtractor> - spanNameExtractorTransformer = Function.identity(); - private boolean emitExperimentalHttpServerMetrics = false; + private final DefaultHttpServerInstrumenterBuilder + serverBuilder; SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + serverBuilder = + new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE) + .setHeaderGetter(JakartaHttpServletRequestGetter.INSTANCE); } /** @@ -60,7 +38,7 @@ public final class SpringWebMvcTelemetryBuilder { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + serverBuilder.addAttributesExtractor(attributesExtractor); return this; } @@ -71,7 +49,7 @@ public SpringWebMvcTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + serverBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -82,7 +60,7 @@ public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List reque */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + serverBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -93,7 +71,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { - this.spanNameExtractorTransformer = spanNameExtractor; + serverBuilder.setSpanNameExtractor(spanNameExtractor); return this; } @@ -112,9 +90,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { - httpAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + serverBuilder.setKnownMethods(knownMethods); return this; } @@ -127,7 +103,7 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -136,26 +112,6 @@ public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( * SpringWebMvcTelemetryBuilder}. */ public SpringWebMvcTelemetry build() { - SpringWebMvcHttpAttributesGetter httpAttributesGetter = - SpringWebMvcHttpAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addContextCustomizer(httpServerRouteBuilder.build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (emitExperimentalHttpServerMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - - return new SpringWebMvcTelemetry( - builder.buildServerInstrumenter(JakartaHttpServletRequestGetter.INSTANCE)); + return new SpringWebMvcTelemetry(serverBuilder.build()); } } diff --git a/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java index 84e97bdf84d5..f78a206eb0fe 100644 --- a/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java @@ -51,7 +51,7 @@ void restClient() { private static void assertClient(TraceAssert traceAssert) { traceAssert.hasSpansSatisfyingExactly( - span -> AbstractOtelSpringStarterSmokeTest.assertClientSpan(span, "/ping"), + span -> SpringTestUtil.assertClientSpan(span, "/ping"), span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"), span -> withSpanAssert(span)); } diff --git a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java index e3c48ca0d25c..3ef0e6d4c654 100644 --- a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java @@ -23,6 +23,7 @@ import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.ClientAttributes; +import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.ServerAttributes; import io.opentelemetry.semconv.UrlAttributes; @@ -34,7 +35,6 @@ import java.util.List; import org.assertj.core.api.AbstractCharSequenceAssert; import org.assertj.core.api.AbstractIterableAssert; -import org.assertj.core.api.AbstractLongAssert; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; @@ -155,8 +155,7 @@ void shouldSendTelemetry() { ServerAttributes.SERVER_PORT, integerAssert -> integerAssert.isNotZero())), serverSpan -> - serverSpan - .hasKind(SpanKind.SERVER) + SpringTestUtil.assertServerSpan(serverSpan, "/ping") .hasResourceSatisfying( r -> r.hasAttribute( @@ -235,18 +234,9 @@ void restTemplate() { testing.waitAndAssertTraces( traceAssert -> traceAssert.hasSpansSatisfyingExactly( - span -> assertClientSpan(span, "/ping"), + span -> SpringTestUtil.assertClientSpan(span, "/ping"), span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"), span -> withSpanAssert(span))); } - - public static void assertClientSpan(SpanDataAssert span, String path) { - span.hasKind(SpanKind.CLIENT) - .hasAttributesSatisfying( - satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), - // this attribute is set by the experimental http instrumentation - satisfies( - HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isPositive)); - } } diff --git a/smoke-tests-otel-starter/spring-boot-common/src/main/resources/application.yaml b/smoke-tests-otel-starter/spring-boot-common/src/main/resources/application.yaml index df0764948302..1995223b3841 100644 --- a/smoke-tests-otel-starter/spring-boot-common/src/main/resources/application.yaml +++ b/smoke-tests-otel-starter/spring-boot-common/src/main/resources/application.yaml @@ -11,6 +11,8 @@ otel: http: client: emit-experimental-telemetry: true + server: + emit-experimental-telemetry: true propagators: - b3 resource: diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java index 7bc32e819fcc..166df2467dd0 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java @@ -8,8 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.semconv.HttpAttributes; -import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -52,17 +50,8 @@ void webClientAndWebFluxAndR2dbc() { trace.hasSpansSatisfyingExactly(span -> span.hasName("CREATE TABLE testdb.player")), trace -> trace.hasSpansSatisfyingExactly( - span -> - span.hasKind(SpanKind.CLIENT) - .hasName("GET") - .hasAttributesSatisfying( - a -> assertThat(a.get(UrlAttributes.URL_FULL)).endsWith("/webflux")), - span -> - span.hasKind(SpanKind.SERVER) - .hasName("GET /webflux") - .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") - .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) - .hasAttribute(HttpAttributes.HTTP_ROUTE, "/webflux"), + span -> SpringTestUtil.assertClientSpan(span, "/webflux"), + span -> SpringTestUtil.assertServerSpan(span, "/webflux"), span -> span.hasKind(SpanKind.CLIENT) .satisfies( diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java new file mode 100644 index 000000000000..60f1bc1aca33 --- /dev/null +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java @@ -0,0 +1,43 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.spring.smoketest; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.semconv.HttpAttributes; +import io.opentelemetry.semconv.UrlAttributes; +import org.assertj.core.api.AbstractLongAssert; + +public class SpringTestUtil { + + private static final AttributeKey BODY_SIZE = + AttributeKey.longKey("http.response.body.size"); + + private SpringTestUtil() {} + + public static void assertClientSpan(SpanDataAssert span, String path) { + span.hasKind(SpanKind.CLIENT) + .hasAttributesSatisfying( + OpenTelemetryAssertions.satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), + // this attribute is set by the experimental http instrumentation + OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isPositive)); + } + + @CanIgnoreReturnValue + public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) { + span.hasKind(SpanKind.SERVER) + .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") + .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) + .hasAttribute(HttpAttributes.HTTP_ROUTE, route) + .hasAttributesSatisfying( + // this attribute is set by the experimental http instrumentation + OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isPositive)); + return span; + } +} From ca5e13c1be88bef4082b7573e1bbd0cf3da8c1f0 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 25 Jun 2024 09:50:28 +0200 Subject: [PATCH 02/18] use DefaultHttpServerInstrumenterBuilder to configure spring starter --- .../SpringWebMvcInstrumentation5AutoConfigurationTest.java | 6 ++++++ .../SpringWebMvcInstrumentation6AutoConfigurationTest.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation5AutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation5AutoConfigurationTest.java index fffc164eabfd..fd3144b46e5b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation5AutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation5AutoConfigurationTest.java @@ -9,6 +9,9 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import java.util.Collections; import javax.servlet.Filter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,6 +23,9 @@ class SpringWebMvcInstrumentation5AutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withBean(OpenTelemetry.class, OpenTelemetry::noop) + .withBean( + ConfigProperties.class, + () -> DefaultConfigProperties.createFromMap(Collections.emptyMap())) .withConfiguration( AutoConfigurations.of(SpringWebMvc5InstrumentationAutoConfiguration.class)); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation6AutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation6AutoConfigurationTest.java index 4b37d5819b10..d84df1a203ef 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation6AutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvcInstrumentation6AutoConfigurationTest.java @@ -9,7 +9,10 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import jakarta.servlet.Filter; +import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -20,6 +23,9 @@ class SpringWebMvcInstrumentation6AutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withBean(OpenTelemetry.class, OpenTelemetry::noop) + .withBean( + ConfigProperties.class, + () -> DefaultConfigProperties.createFromMap(Collections.emptyMap())) .withConfiguration( AutoConfigurations.of(SpringWebMvc6InstrumentationAutoConfiguration.class)); From 113f33e5d8e36083b052762955a91313fee332ac Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 25 Jun 2024 11:06:58 +0200 Subject: [PATCH 03/18] use DefaultHttpServerInstrumenterBuilder to configure spring starter --- .../DefaultHttpServerInstrumenterBuilder.java | 5 +++-- .../webflux/WebClientBeanPostProcessor.java | 2 +- ...bMvc5InstrumentationAutoConfiguration.java | 2 +- ...bMvc6InstrumentationAutoConfiguration.java | 2 +- .../properties/InstrumentationConfigUtil.java | 19 ++++++++++++++++++- 5 files changed, 24 insertions(+), 6 deletions(-) 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 4ed623e2ca5c..41a7139d47e8 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 @@ -243,12 +243,13 @@ DefaultHttpServerInstrumenterBuilder unwrapBuilder(Object bui if (builder instanceof DefaultHttpServerInstrumenterBuilder) { return (DefaultHttpServerInstrumenterBuilder) builder; } + Class builderClass = builder.getClass(); try { - Field field = builder.getClass().getDeclaredField("serverBuilder"); + Field field = builderClass.getDeclaredField("serverBuilder"); field.setAccessible(true); return (DefaultHttpServerInstrumenterBuilder) field.get(builder); } catch (Exception e) { - throw new IllegalStateException("Could not access builder field", e); + throw new IllegalStateException("Could not access serverBuilder field in " + builderClass, e); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index d1bb746a4b24..aa40bfd52e63 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -32,7 +32,7 @@ final class WebClientBeanPostProcessor implements BeanPostProcessor { static SpringWebfluxTelemetry getWebfluxTelemetry( OpenTelemetry openTelemetry, ConfigProperties config) { - return InstrumentationConfigUtil.configureBuilder( + return InstrumentationConfigUtil.configureClientAndServerBuilder( config, SpringWebfluxTelemetry.builder(openTelemetry)) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index c4dad1e5ba22..6f33f4d41980 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -25,7 +25,7 @@ public class SpringWebMvc5InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { - return InstrumentationConfigUtil.configureBuilder( + return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry)) .build() .createServletFilter(); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index 4749cb6ed142..ea9e0bfe82ad 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -25,7 +25,7 @@ public class SpringWebMvc6InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { - return InstrumentationConfigUtil.configureBuilder( + return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry)) .build() .createServletFilter(); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 234d3e77beeb..02fbb96f6b30 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -7,6 +7,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; 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.sdk.autoconfigure.spi.ConfigProperties; import java.util.function.Function; @@ -19,7 +20,16 @@ public class InstrumentationConfigUtil { private InstrumentationConfigUtil() {} @CanIgnoreReturnValue - public static T configureBuilder( + public static T configureClientAndServerBuilder(ConfigProperties config, T builder) { + DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure( + new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); + DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure( + new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); + return builder; + } + + @CanIgnoreReturnValue + public static T configureClientBuilder( ConfigProperties config, T builder, Function> getBuilder) { @@ -27,6 +37,13 @@ public static T configureBuilder( return builder; } + @CanIgnoreReturnValue + public static T configureServerBuilder(ConfigProperties config, T builder) { + DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure( + new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); + return builder; + } + public static boolean isStatementSanitizationEnabled(ConfigProperties config, String key) { return config.getBoolean( key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true)); From 07dc6e1860f65b0ed9831ab8a5e2c2bb21c075d9 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 25 Jun 2024 12:54:11 +0200 Subject: [PATCH 04/18] use DefaultHttpServerInstrumenterBuilder to configure spring starter --- .../src/main/resources/application.yaml | 5 +++++ .../io/opentelemetry/spring/smoketest/SpringTestUtil.java | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml index f0568098a28b..26b301f52d79 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml @@ -3,6 +3,11 @@ otel: common: db-statement-sanitizer: enabled: false + http: + client: + emit-experimental-telemetry: true + server: + emit-experimental-telemetry: true spring: r2dbc: diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java index 60f1bc1aca33..fe937ec5ac14 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java @@ -26,7 +26,7 @@ public static void assertClientSpan(SpanDataAssert span, String path) { .hasAttributesSatisfying( OpenTelemetryAssertions.satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), // this attribute is set by the experimental http instrumentation - OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isPositive)); + OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isNotNegative)); } @CanIgnoreReturnValue @@ -37,7 +37,7 @@ public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) .hasAttribute(HttpAttributes.HTTP_ROUTE, route) .hasAttributesSatisfying( // this attribute is set by the experimental http instrumentation - OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isPositive)); + OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isNotNegative)); return span; } } From 12081b5a120024aba7a9708bddb221a659f11505 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 27 Jun 2024 09:09:18 +0200 Subject: [PATCH 05/18] remove need for reflection --- .../DefaultHttpServerInstrumenterBuilder.java | 38 ++++--------------- .../ApacheHttpClientTelemetryBuilder.java | 19 +++++----- .../ApacheHttpClient5TelemetryBuilder.java | 18 ++++----- .../web/RestClientBeanPostProcessor.java | 2 +- .../web/RestTemplateInstrumentation.java | 2 +- .../webflux/WebClientBeanPostProcessor.java | 6 ++- ...bMvc5InstrumentationAutoConfiguration.java | 3 +- ...bMvc6InstrumentationAutoConfiguration.java | 3 +- .../properties/InstrumentationConfigUtil.java | 32 +++++++++++----- .../web/v3_1/SpringWebTelemetryBuilder.java | 18 ++++----- .../v5_3/SpringWebfluxTelemetryBuilder.java | 15 ++++++++ .../v5_3/internal/SpringWebfluxUtil.java | 34 +++++++++++++++++ .../v5_3/SpringWebMvcTelemetryBuilder.java | 28 +++++++++----- .../webmvc/v5_3/internal/SpringMvcUtil.java | 26 +++++++++++++ .../v6_0/SpringWebMvcTelemetryBuilder.java | 28 +++++++++----- .../webmvc/v6_0/internal/SpringMvcUtil.java | 26 +++++++++++++ 16 files changed, 206 insertions(+), 92 deletions(-) create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java create mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java create mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java 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 41a7139d47e8..22ba811cb6d4 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 @@ -26,7 +26,6 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -212,17 +211,15 @@ public OpenTelemetry getOpenTelemetry() { } @CanIgnoreReturnValue - public static - DefaultHttpServerInstrumenterBuilder unwrapAndConfigure( - CoreCommonConfig config, Object builder) { - DefaultHttpServerInstrumenterBuilder defaultBuilder = unwrapBuilder(builder); - set(config::getKnownHttpRequestMethods, defaultBuilder::setKnownMethods); - set(config::getServerRequestHeaders, defaultBuilder::setCapturedRequestHeaders); - set(config::getServerResponseHeaders, defaultBuilder::setCapturedResponseHeaders); + public DefaultHttpServerInstrumenterBuilder configure( + CoreCommonConfig config) { + set(config::getKnownHttpRequestMethods, this::setKnownMethods); + set(config::getServerRequestHeaders, this::setCapturedRequestHeaders); + set(config::getServerResponseHeaders, this::setCapturedResponseHeaders); set( config::shouldEmitExperimentalHttpServerTelemetry, - defaultBuilder::setEmitExperimentalHttpServerMetrics); - return defaultBuilder; + this::setEmitExperimentalHttpServerMetrics); + return this; } private static void set(Supplier supplier, Consumer consumer) { @@ -231,25 +228,4 @@ private static void set(Supplier supplier, Consumer consumer) { 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 - DefaultHttpServerInstrumenterBuilder unwrapBuilder(Object builder) { - if (builder instanceof DefaultHttpServerInstrumenterBuilder) { - return (DefaultHttpServerInstrumenterBuilder) builder; - } - Class builderClass = builder.getClass(); - try { - Field field = builderClass.getDeclaredField("serverBuilder"); - field.setAccessible(true); - return (DefaultHttpServerInstrumenterBuilder) field.get(builder); - } catch (Exception e) { - throw new IllegalStateException("Could not access serverBuilder field in " + builderClass, e); - } - } } 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/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java index 469fdfadd741..afc7df6824b6 100644 --- a/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java @@ -56,7 +56,7 @@ private static RestClient addRestClientInterceptorIfNotPresent( static ClientHttpRequestInterceptor getInterceptor( OpenTelemetry openTelemetry, ConfigProperties config) { - return InstrumentationConfigUtil.configureBuilder( + return InstrumentationConfigUtil.configureClientBuilder( config, SpringWebTelemetry.builder(openTelemetry), WebTelemetryUtil.getBuilderExtractor()) 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 deb84cfcc23b..6cd79283afae 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 @@ -24,7 +24,7 @@ static RestTemplate addIfNotPresent( RestTemplate restTemplate, OpenTelemetry openTelemetry, ConfigProperties config) { ClientHttpRequestInterceptor instrumentationInterceptor = - InstrumentationConfigUtil.configureBuilder( + InstrumentationConfigUtil.configureClientBuilder( config, SpringWebTelemetry.builder(openTelemetry), WebTelemetryUtil.getBuilderExtractor()) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index aa40bfd52e63..d7b6f30ff3d9 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -33,7 +34,10 @@ final class WebClientBeanPostProcessor implements BeanPostProcessor { static SpringWebfluxTelemetry getWebfluxTelemetry( OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureClientAndServerBuilder( - config, SpringWebfluxTelemetry.builder(openTelemetry)) + config, + SpringWebfluxTelemetry.builder(openTelemetry), + SpringWebfluxUtil.GET_CLIENT_BUILDER, + SpringWebfluxUtil.GET_SERVER_BUILDER) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index 6f33f4d41980..c237b2a46afb 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -9,6 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetry; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import javax.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -26,7 +27,7 @@ public class SpringWebMvc5InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( - config, SpringWebMvcTelemetry.builder(openTelemetry)) + config, SpringWebMvcTelemetry.builder(openTelemetry), SpringMvcUtil.GET_BUILDER) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index ea9e0bfe82ad..0c5b38bbaf04 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -9,6 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetry; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import jakarta.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -26,7 +27,7 @@ public class SpringWebMvc6InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( - config, SpringWebMvcTelemetry.builder(openTelemetry)) + config, SpringWebMvcTelemetry.builder(openTelemetry), SpringMvcUtil.GET_BUILDER) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 02fbb96f6b30..6651ccf6317e 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -20,30 +20,42 @@ public class InstrumentationConfigUtil { private InstrumentationConfigUtil() {} @CanIgnoreReturnValue - public static T configureClientAndServerBuilder(ConfigProperties config, T builder) { - DefaultHttpClientInstrumenterBuilder.unwrapAndConfigure( - new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); - DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure( - new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); + public static + T configureClientAndServerBuilder( + ConfigProperties config, + T builder, + Function> + getClientBuilder, + Function> + getServerBuilder) { + CoreCommonConfig commonConfig = getConfig(config); + getClientBuilder.apply(builder).configure(commonConfig); + getServerBuilder.apply(builder).configure(commonConfig); return builder; } @CanIgnoreReturnValue - public static T configureClientBuilder( + public static T configureClientBuilder( ConfigProperties config, T builder, Function> getBuilder) { - getBuilder.apply(builder).configure(new CommonConfig(new ConfigPropertiesBridge(config))); + getBuilder.apply(builder).configure(getConfig(config)); return builder; } @CanIgnoreReturnValue - public static T configureServerBuilder(ConfigProperties config, T builder) { - DefaultHttpServerInstrumenterBuilder.unwrapAndConfigure( - new CoreCommonConfig(new ConfigPropertiesBridge(config)), builder); + public static T configureServerBuilder( + ConfigProperties config, + T builder, + Function> getBuilder) { + getBuilder.apply(builder).configure(getConfig(config)); return builder; } + private static CoreCommonConfig getConfig(ConfigProperties config) { + return new CoreCommonConfig(new ConfigPropertiesBridge(config)); + } + public static boolean isStatementSanitizationEnabled(ConfigProperties config, String key) { return config.getBoolean( key, config.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true)); 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/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index 139d3c9d8c18..e417c9497e5b 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import java.util.List; import java.util.Set; @@ -29,6 +30,11 @@ public final class SpringWebfluxTelemetryBuilder { private final DefaultHttpServerInstrumenterBuilder serverBuilder; + static { + SpringWebfluxUtil.GET_CLIENT_BUILDER = SpringWebfluxTelemetryBuilder::getClientBuilder; + SpringWebfluxUtil.GET_SERVER_BUILDER = SpringWebfluxTelemetryBuilder::getServerBuilder; + } + SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( @@ -188,4 +194,13 @@ public SpringWebfluxTelemetry build() { serverBuilder.build(), clientBuilder.getOpenTelemetry().getPropagators()); } + + private DefaultHttpClientInstrumenterBuilder getClientBuilder() { + return clientBuilder; + } + + private DefaultHttpServerInstrumenterBuilder + getServerBuilder() { + return serverBuilder; + } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java new file mode 100644 index 000000000000..4a4d8bb16a24 --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java @@ -0,0 +1,34 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3.internal; + +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetryBuilder; +import java.util.function.Function; +import org.springframework.web.reactive.function.client.ClientRequest; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.server.ServerWebExchange; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class SpringWebfluxUtil { + private SpringWebfluxUtil() {} + + @SuppressWarnings("ConstantField") + public static Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + GET_CLIENT_BUILDER; + + @SuppressWarnings("ConstantField") + public static Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + GET_SERVER_BUILDER; +} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index 500ea16b1b8b..ad699ef8e99a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.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.spring.webmvc.v5_3.internal.SpringMvcUtil; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -23,10 +24,14 @@ public final class SpringWebMvcTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webmvc-5.3"; private final DefaultHttpServerInstrumenterBuilder - serverBuilder; + builder; + + static { + SpringMvcUtil.GET_BUILDER = SpringWebMvcTelemetryBuilder::getBuilder; + } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { - serverBuilder = + builder = new DefaultHttpServerInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE) .setHeaderGetter(JavaxHttpServletRequestGetter.INSTANCE); @@ -39,7 +44,7 @@ public final class SpringWebMvcTelemetryBuilder { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - serverBuilder.addAttributesExtractor(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -50,7 +55,7 @@ public SpringWebMvcTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - serverBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -61,7 +66,7 @@ public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List reque */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - serverBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -72,7 +77,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { - serverBuilder.setSpanNameExtractor(spanNameExtractor); + builder.setSpanNameExtractor(spanNameExtractor); return this; } @@ -91,7 +96,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { - serverBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -104,7 +109,7 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -113,6 +118,11 @@ public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( * SpringWebMvcTelemetryBuilder}. */ public SpringWebMvcTelemetry build() { - return new SpringWebMvcTelemetry(serverBuilder.build()); + return new SpringWebMvcTelemetry(builder.build()); + } + + public DefaultHttpServerInstrumenterBuilder + getBuilder() { + return builder; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java new file mode 100644 index 000000000000..547f99e96bbd --- /dev/null +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal; + +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetryBuilder; +import java.util.function.Function; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class SpringMvcUtil { + private SpringMvcUtil() {} + + @SuppressWarnings("ConstantField") + public static Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + GET_BUILDER; +} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 801c01b05375..a8361c014672 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.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.spring.webmvc.v6_0.internal.SpringMvcUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -22,10 +23,14 @@ public final class SpringWebMvcTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webmvc-6.0"; private final DefaultHttpServerInstrumenterBuilder - serverBuilder; + builder; + + static { + SpringMvcUtil.GET_BUILDER = SpringWebMvcTelemetryBuilder::getBuilder; + } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { - serverBuilder = + builder = new DefaultHttpServerInstrumenterBuilder<>( INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE) .setHeaderGetter(JakartaHttpServletRequestGetter.INSTANCE); @@ -38,7 +43,7 @@ public final class SpringWebMvcTelemetryBuilder { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - serverBuilder.addAttributesExtractor(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -49,7 +54,7 @@ public SpringWebMvcTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - serverBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -60,7 +65,7 @@ public SpringWebMvcTelemetryBuilder setCapturedRequestHeaders(List reque */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - serverBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -71,7 +76,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { - serverBuilder.setSpanNameExtractor(spanNameExtractor); + builder.setSpanNameExtractor(spanNameExtractor); return this; } @@ -90,7 +95,7 @@ public SpringWebMvcTelemetryBuilder setSpanNameExtractor( */ @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { - serverBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -103,7 +108,7 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -112,6 +117,11 @@ public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( * SpringWebMvcTelemetryBuilder}. */ public SpringWebMvcTelemetry build() { - return new SpringWebMvcTelemetry(serverBuilder.build()); + return new SpringWebMvcTelemetry(builder.build()); + } + + public DefaultHttpServerInstrumenterBuilder + getBuilder() { + return builder; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java new file mode 100644 index 000000000000..41499a45f0cc --- /dev/null +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal; + +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetryBuilder; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +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 SpringMvcUtil { + private SpringMvcUtil() {} + + @SuppressWarnings("ConstantField") + public static Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + GET_BUILDER; +} From 9cf2a02e5aca960404b4829f886b170adab448ed Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 27 Jun 2024 09:55:36 +0200 Subject: [PATCH 06/18] fix compile --- .../mongo/MongoClientInstrumentationAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java index 0eee74e37965..7885c2088aea 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java @@ -9,7 +9,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.mongo.v3_1.MongoTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; -import io.opentelemetry.instrumentation.spring.autoconfigure.internal.InstrumentationConfigUtil; +import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; From c298fffcc7f010fd33313a8fbd7056632167cf0a Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 27 Jun 2024 10:17:45 +0200 Subject: [PATCH 07/18] fix rebase --- .../spring/smoketest/SpringTestUtil.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java index fe937ec5ac14..3f17e76d8383 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java @@ -5,39 +5,36 @@ package io.opentelemetry.spring.smoketest; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; + import com.google.errorprone.annotations.CanIgnoreReturnValue; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.UrlAttributes; +import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; import org.assertj.core.api.AbstractLongAssert; public class SpringTestUtil { - private static final AttributeKey BODY_SIZE = - AttributeKey.longKey("http.response.body.size"); - private SpringTestUtil() {} public static void assertClientSpan(SpanDataAssert span, String path) { span.hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - OpenTelemetryAssertions.satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), + satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), // this attribute is set by the experimental http instrumentation - OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isNotNegative)); + satisfies(HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); } @CanIgnoreReturnValue public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) { - span.hasKind(SpanKind.SERVER) + return span.hasKind(SpanKind.SERVER) .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) .hasAttribute(HttpAttributes.HTTP_ROUTE, route) .hasAttributesSatisfying( // this attribute is set by the experimental http instrumentation - OpenTelemetryAssertions.satisfies(BODY_SIZE, AbstractLongAssert::isNotNegative)); - return span; + satisfies(HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); } } From 80172bd698f0d48a7b5f17ac60ac85117ce80b0e Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 27 Jun 2024 12:05:52 +0200 Subject: [PATCH 08/18] remove need for reflection --- .../internal/properties/InstrumentationConfigUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 6651ccf6317e..0b29ea1539d9 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -20,13 +20,13 @@ public class InstrumentationConfigUtil { private InstrumentationConfigUtil() {} @CanIgnoreReturnValue - public static + public static T configureClientAndServerBuilder( ConfigProperties config, T builder, - Function> + Function> getClientBuilder, - Function> + Function> getServerBuilder) { CoreCommonConfig commonConfig = getConfig(config); getClientBuilder.apply(builder).configure(commonConfig); From 471e6627db559a116204fff4da967a5c3a10e22e Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 2 Jul 2024 17:04:15 +0200 Subject: [PATCH 09/18] fix rebase --- .../DefaultHttpServerInstrumenterBuilder.java | 5 +-- .../webflux/WebClientBeanPostProcessor.java | 4 +- ...bMvc5InstrumentationAutoConfiguration.java | 4 +- ...bMvc6InstrumentationAutoConfiguration.java | 4 +- .../properties/InstrumentationConfigUtil.java | 6 +-- .../v5_3/SpringWebfluxTelemetryBuilder.java | 4 +- .../v5_3/internal/SpringWebfluxUtil.java | 38 ++++++++++++++++--- .../v5_3/SpringWebMvcTelemetryBuilder.java | 2 +- .../webmvc/v5_3/internal/SpringMvcUtil.java | 18 ++++++++- .../v6_0/SpringWebMvcTelemetryBuilder.java | 2 +- .../webmvc/v6_0/internal/SpringMvcUtil.java | 18 ++++++++- .../AbstractOtelSpringStarterSmokeTest.java | 3 -- .../spring/smoketest/SpringTestUtil.java | 8 +++- 13 files changed, 88 insertions(+), 28 deletions(-) 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 22ba811cb6d4..273bbb0f11d0 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 @@ -8,7 +8,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; @@ -211,8 +211,7 @@ public OpenTelemetry getOpenTelemetry() { } @CanIgnoreReturnValue - public DefaultHttpServerInstrumenterBuilder configure( - CoreCommonConfig config) { + public DefaultHttpServerInstrumenterBuilder configure(CommonConfig config) { set(config::getKnownHttpRequestMethods, this::setKnownMethods); set(config::getServerRequestHeaders, this::setCapturedRequestHeaders); set(config::getServerResponseHeaders, this::setCapturedResponseHeaders); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index d7b6f30ff3d9..b90180bf8add 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -36,8 +36,8 @@ static SpringWebfluxTelemetry getWebfluxTelemetry( return InstrumentationConfigUtil.configureClientAndServerBuilder( config, SpringWebfluxTelemetry.builder(openTelemetry), - SpringWebfluxUtil.GET_CLIENT_BUILDER, - SpringWebfluxUtil.GET_SERVER_BUILDER) + SpringWebfluxUtil.getClientBuilderExtractor(), + SpringWebfluxUtil.getServerBuilderExtractor()) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index c237b2a46afb..ce7f1aee28c7 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -27,7 +27,9 @@ public class SpringWebMvc5InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( - config, SpringWebMvcTelemetry.builder(openTelemetry), SpringMvcUtil.GET_BUILDER) + config, + SpringWebMvcTelemetry.builder(openTelemetry), + SpringMvcUtil.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index 0c5b38bbaf04..b53bea2173f9 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -27,7 +27,9 @@ public class SpringWebMvc6InstrumentationAutoConfiguration { @Bean Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( - config, SpringWebMvcTelemetry.builder(openTelemetry), SpringMvcUtil.GET_BUILDER) + config, + SpringWebMvcTelemetry.builder(openTelemetry), + SpringMvcUtil.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 0b29ea1539d9..03ad464f4ce9 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -28,7 +28,7 @@ T configureClientAndServerBuilder( getClientBuilder, Function> getServerBuilder) { - CoreCommonConfig commonConfig = getConfig(config); + CommonConfig commonConfig = getConfig(config); getClientBuilder.apply(builder).configure(commonConfig); getServerBuilder.apply(builder).configure(commonConfig); return builder; @@ -52,8 +52,8 @@ public static T configureServerBuilder( return builder; } - private static CoreCommonConfig getConfig(ConfigProperties config) { - return new CoreCommonConfig(new ConfigPropertiesBridge(config)); + private static CommonConfig getConfig(ConfigProperties config) { + return new CommonConfig(new ConfigPropertiesBridge(config)); } public static boolean isStatementSanitizationEnabled(ConfigProperties config, String key) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index e417c9497e5b..c6e214310ee3 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -31,8 +31,8 @@ public final class SpringWebfluxTelemetryBuilder { serverBuilder; static { - SpringWebfluxUtil.GET_CLIENT_BUILDER = SpringWebfluxTelemetryBuilder::getClientBuilder; - SpringWebfluxUtil.GET_SERVER_BUILDER = SpringWebfluxTelemetryBuilder::getServerBuilder; + SpringWebfluxUtil.setClientBuilderExtractor(SpringWebfluxTelemetryBuilder::getClientBuilder); + SpringWebfluxUtil.setServerBuilderExtractor(SpringWebfluxTelemetryBuilder::getServerBuilder); } SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java index 4a4d8bb16a24..be57a610c9a0 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java @@ -20,15 +20,43 @@ public class SpringWebfluxUtil { private SpringWebfluxUtil() {} - @SuppressWarnings("ConstantField") - public static Function< + private static Function< SpringWebfluxTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> - GET_CLIENT_BUILDER; + clientBuilderExtractor; + + private static Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor; - @SuppressWarnings("ConstantField") public static Function< SpringWebfluxTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> - GET_SERVER_BUILDER; + getServerBuilderExtractor() { + return serverBuilderExtractor; + } + + public static void setServerBuilderExtractor( + Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor) { + SpringWebfluxUtil.serverBuilderExtractor = serverBuilderExtractor; + } + + public static Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + getClientBuilderExtractor() { + return clientBuilderExtractor; + } + + public static void setClientBuilderExtractor( + Function< + SpringWebfluxTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + clientBuilderExtractor) { + SpringWebfluxUtil.clientBuilderExtractor = clientBuilderExtractor; + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index ad699ef8e99a..c310f2c2b59b 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -27,7 +27,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcUtil.GET_BUILDER = SpringWebMvcTelemetryBuilder::getBuilder; + SpringMvcUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java index 547f99e96bbd..19b872baca1f 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java @@ -18,9 +18,23 @@ public class SpringMvcUtil { private SpringMvcUtil() {} - @SuppressWarnings("ConstantField") + private static Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor; + public static Function< SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> - GET_BUILDER; + getBuilderExtractor() { + return builderExtractor; + } + + public static void setBuilderExtractor( + Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor) { + SpringMvcUtil.builderExtractor = builderExtractor; + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index a8361c014672..bf737466e255 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -26,7 +26,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcUtil.GET_BUILDER = SpringWebMvcTelemetryBuilder::getBuilder; + SpringMvcUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java index 41499a45f0cc..b88a6e6f009a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java @@ -18,9 +18,23 @@ public class SpringMvcUtil { private SpringMvcUtil() {} - @SuppressWarnings("ConstantField") + private static Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor; + public static Function< SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> - GET_BUILDER; + getBuilderExtractor() { + return builderExtractor; + } + + public static void setBuilderExtractor( + Function< + SpringWebMvcTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + builderExtractor) { + SpringMvcUtil.builderExtractor = builderExtractor; + } } diff --git a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java index 3ef0e6d4c654..c0f1a6867fd8 100644 --- a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java @@ -21,15 +21,12 @@ import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.ClientAttributes; -import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.ServerAttributes; import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; -import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; import io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes; import java.util.Collections; import java.util.List; diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java index 3f17e76d8383..7765a505d0b7 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java @@ -24,7 +24,9 @@ public static void assertClientSpan(SpanDataAssert span, String path) { .hasAttributesSatisfying( satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), // this attribute is set by the experimental http instrumentation - satisfies(HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); + satisfies( + HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, + AbstractLongAssert::isNotNegative)); } @CanIgnoreReturnValue @@ -35,6 +37,8 @@ public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) .hasAttribute(HttpAttributes.HTTP_ROUTE, route) .hasAttributesSatisfying( // this attribute is set by the experimental http instrumentation - satisfies(HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); + satisfies( + HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, + AbstractLongAssert::isNotNegative)); } } From eb3da665c8ae7ea9a0f31227c0007c3419747232 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 5 Jul 2024 12:04:32 +0200 Subject: [PATCH 10/18] pr review --- .../webflux/WebClientBeanPostProcessor.java | 6 ++--- ...bMvc5InstrumentationAutoConfiguration.java | 4 +-- ...bMvc6InstrumentationAutoConfiguration.java | 4 +-- .../v5_3/SpringWebfluxTelemetryBuilder.java | 8 +++--- ...l.java => SpringWebfluxBuilderHolder.java} | 8 +++--- .../v5_3/SpringWebMvcTelemetryBuilder.java | 4 +-- ...cUtil.java => SpringMvcBuilderHolder.java} | 6 ++--- .../v6_0/SpringWebMvcTelemetryBuilder.java | 4 +-- ...cUtil.java => SpringMvcBuilderHolder.java} | 6 ++--- .../smoketest/OtelSpringStarterSmokeTest.java | 2 +- .../AbstractOtelSpringStarterSmokeTest.java | 5 ++-- ...actOtelReactiveSpringStarterSmokeTest.java | 4 +-- ...gTestUtil.java => HttpSpanDataAssert.java} | 27 +++++++++++++++---- 13 files changed, 54 insertions(+), 34 deletions(-) rename instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/{SpringWebfluxUtil.java => SpringWebfluxBuilderHolder.java} (89%) rename instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/{SpringMvcUtil.java => SpringMvcBuilderHolder.java} (89%) rename instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/{SpringMvcUtil.java => SpringMvcBuilderHolder.java} (89%) rename smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/{SpringTestUtil.java => HttpSpanDataAssert.java} (66%) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index b90180bf8add..78115bf55706 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxUtil; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderHolder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -36,8 +36,8 @@ static SpringWebfluxTelemetry getWebfluxTelemetry( return InstrumentationConfigUtil.configureClientAndServerBuilder( config, SpringWebfluxTelemetry.builder(openTelemetry), - SpringWebfluxUtil.getClientBuilderExtractor(), - SpringWebfluxUtil.getServerBuilderExtractor()) + SpringWebfluxBuilderHolder.getClientBuilderExtractor(), + SpringWebfluxBuilderHolder.getServerBuilderExtractor()) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index ce7f1aee28c7..5be32ae97910 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetry; -import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcUtil; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderHolder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import javax.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -29,7 +29,7 @@ Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry), - SpringMvcUtil.getBuilderExtractor()) + SpringMvcBuilderHolder.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index b53bea2173f9..3c47f682df9c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetry; -import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcUtil; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderHolder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import jakarta.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -29,7 +29,7 @@ Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry), - SpringMvcUtil.getBuilderExtractor()) + SpringMvcBuilderHolder.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index c6e214310ee3..3ba7fe8ebc74 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -13,7 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxUtil; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderHolder; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import java.util.List; import java.util.Set; @@ -31,8 +31,10 @@ public final class SpringWebfluxTelemetryBuilder { serverBuilder; static { - SpringWebfluxUtil.setClientBuilderExtractor(SpringWebfluxTelemetryBuilder::getClientBuilder); - SpringWebfluxUtil.setServerBuilderExtractor(SpringWebfluxTelemetryBuilder::getServerBuilder); + SpringWebfluxBuilderHolder.setClientBuilderExtractor( + SpringWebfluxTelemetryBuilder::getClientBuilder); + SpringWebfluxBuilderHolder.setServerBuilderExtractor( + SpringWebfluxTelemetryBuilder::getServerBuilder); } SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java similarity index 89% rename from instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java index be57a610c9a0..2979b8854449 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxUtil.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java @@ -17,8 +17,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringWebfluxUtil { - private SpringWebfluxUtil() {} +public class SpringWebfluxBuilderHolder { + private SpringWebfluxBuilderHolder() {} private static Function< SpringWebfluxTelemetryBuilder, @@ -42,7 +42,7 @@ public static void setServerBuilderExtractor( SpringWebfluxTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor) { - SpringWebfluxUtil.serverBuilderExtractor = serverBuilderExtractor; + SpringWebfluxBuilderHolder.serverBuilderExtractor = serverBuilderExtractor; } public static Function< @@ -57,6 +57,6 @@ public static void setClientBuilderExtractor( SpringWebfluxTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor) { - SpringWebfluxUtil.clientBuilderExtractor = clientBuilderExtractor; + SpringWebfluxBuilderHolder.clientBuilderExtractor = clientBuilderExtractor; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index c310f2c2b59b..a8d71c1f5a9a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -11,7 +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.spring.webmvc.v5_3.internal.SpringMvcUtil; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderHolder; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -27,7 +27,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); + SpringMvcBuilderHolder.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java similarity index 89% rename from instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java rename to instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java index 19b872baca1f..e377384b121d 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java @@ -15,8 +15,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcUtil { - private SpringMvcUtil() {} +public class SpringMvcBuilderHolder { + private SpringMvcBuilderHolder() {} private static Function< SpringWebMvcTelemetryBuilder, @@ -35,6 +35,6 @@ public static void setBuilderExtractor( SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> builderExtractor) { - SpringMvcUtil.builderExtractor = builderExtractor; + SpringMvcBuilderHolder.builderExtractor = builderExtractor; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index bf737466e255..4795d8b5d818 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -11,7 +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.spring.webmvc.v6_0.internal.SpringMvcUtil; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderHolder; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -26,7 +26,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); + SpringMvcBuilderHolder.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java similarity index 89% rename from instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java rename to instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java index b88a6e6f009a..6187cdfd8182 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java @@ -15,8 +15,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcUtil { - private SpringMvcUtil() {} +public class SpringMvcBuilderHolder { + private SpringMvcBuilderHolder() {} private static Function< SpringWebMvcTelemetryBuilder, @@ -35,6 +35,6 @@ public static void setBuilderExtractor( SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> builderExtractor) { - SpringMvcUtil.builderExtractor = builderExtractor; + SpringMvcBuilderHolder.builderExtractor = builderExtractor; } } diff --git a/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java index f78a206eb0fe..f01bafb6e22e 100644 --- a/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java @@ -51,7 +51,7 @@ void restClient() { private static void assertClient(TraceAssert traceAssert) { traceAssert.hasSpansSatisfyingExactly( - span -> SpringTestUtil.assertClientSpan(span, "/ping"), + span -> HttpSpanDataAssert.create(span).assertClientGetRequest("/ping"), span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"), span -> withSpanAssert(span)); } diff --git a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java index c0f1a6867fd8..4e802dd3bccb 100644 --- a/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java @@ -152,7 +152,8 @@ void shouldSendTelemetry() { ServerAttributes.SERVER_PORT, integerAssert -> integerAssert.isNotZero())), serverSpan -> - SpringTestUtil.assertServerSpan(serverSpan, "/ping") + HttpSpanDataAssert.create(serverSpan) + .assertServerGetRequest("/ping") .hasResourceSatisfying( r -> r.hasAttribute( @@ -231,7 +232,7 @@ void restTemplate() { testing.waitAndAssertTraces( traceAssert -> traceAssert.hasSpansSatisfyingExactly( - span -> SpringTestUtil.assertClientSpan(span, "/ping"), + span -> HttpSpanDataAssert.create(span).assertClientGetRequest("/ping"), span -> span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"), span -> withSpanAssert(span))); diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java index 166df2467dd0..8de8f4fc0ac5 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java @@ -50,8 +50,8 @@ void webClientAndWebFluxAndR2dbc() { trace.hasSpansSatisfyingExactly(span -> span.hasName("CREATE TABLE testdb.player")), trace -> trace.hasSpansSatisfyingExactly( - span -> SpringTestUtil.assertClientSpan(span, "/webflux"), - span -> SpringTestUtil.assertServerSpan(span, "/webflux"), + span -> HttpSpanDataAssert.create(span).assertClientGetRequest("/webflux"), + span -> HttpSpanDataAssert.create(span).assertServerGetRequest("/webflux"), span -> span.hasKind(SpanKind.CLIENT) .satisfies( diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java similarity index 66% rename from smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java rename to smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java index 7765a505d0b7..6c8306ca609b 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/SpringTestUtil.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java @@ -9,17 +9,28 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.testing.assertj.ResourceAssert; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; +import java.util.function.Consumer; import org.assertj.core.api.AbstractLongAssert; -public class SpringTestUtil { +public class HttpSpanDataAssert { - private SpringTestUtil() {} + private final SpanDataAssert span; - public static void assertClientSpan(SpanDataAssert span, String path) { + private HttpSpanDataAssert(SpanDataAssert span) { + this.span = span; + } + + public static HttpSpanDataAssert create(SpanDataAssert serverSpan) { + return new HttpSpanDataAssert(serverSpan); + } + + @CanIgnoreReturnValue + public HttpSpanDataAssert assertClientGetRequest(String path) { span.hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( satisfies(UrlAttributes.URL_FULL, a -> a.endsWith(path)), @@ -27,11 +38,12 @@ public static void assertClientSpan(SpanDataAssert span, String path) { satisfies( HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); + return this; } @CanIgnoreReturnValue - public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) { - return span.hasKind(SpanKind.SERVER) + public HttpSpanDataAssert assertServerGetRequest(String route) { + span.hasKind(SpanKind.SERVER) .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) .hasAttribute(HttpAttributes.HTTP_ROUTE, route) @@ -40,5 +52,10 @@ public static SpanDataAssert assertServerSpan(SpanDataAssert span, String route) satisfies( HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, AbstractLongAssert::isNotNegative)); + return this; + } + + public SpanDataAssert hasResourceSatisfying(Consumer resource) { + return span.hasResourceSatisfying(resource); } } From 1c3c41cd2cc793d703c541fabd14d056dd11a9c6 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 5 Jul 2024 14:00:04 +0200 Subject: [PATCH 11/18] Update instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json Co-authored-by: Lauri Tulmin --- .../META-INF/additional-spring-configuration-metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 22f7f24b3f9b..3b309aae4739 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -325,7 +325,7 @@ { "name": "otel.instrumentation.http.server.emit-experimental-telemetry", "type": "java.lang.Boolean", - "description": "Enable the capture of experimental HTTP server telemetry. Add the http.request.body.size and http.response.body.size> attributes to spans, and record the http.server.request.size and http.server.response.size metrics.", + "description": "Enable the capture of experimental HTTP server telemetry. Add the http.request.body.size and http.response.body.size attributes to spans, and record the http.server.request.body.size and http.server.response.body.size metrics.", "defaultValue": false }, { From 19f3d9aaa9de646ec4ae152fbc871ecd1ff6e913 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 5 Jul 2024 14:04:58 +0200 Subject: [PATCH 12/18] pr review --- .../webflux/WebClientBeanPostProcessor.java | 6 +++--- .../SpringWebMvc5InstrumentationAutoConfiguration.java | 4 ++-- .../SpringWebMvc6InstrumentationAutoConfiguration.java | 4 ++-- .../spring/webflux/v5_0/client/WebClientHelper.java | 2 +- .../webflux/v5_3/SpringWebfluxTelemetryBuilder.java | 6 +++--- ...uxBuilderHolder.java => SpringWebfluxBuilderUtil.java} | 8 ++++---- .../spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java | 4 ++-- ...ingMvcBuilderHolder.java => SpringMvcBuilderUtil.java} | 6 +++--- .../spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java | 4 ++-- ...ingMvcBuilderHolder.java => SpringMvcBuilderUtil.java} | 6 +++--- 10 files changed, 25 insertions(+), 25 deletions(-) rename instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/{SpringWebfluxBuilderHolder.java => SpringWebfluxBuilderUtil.java} (89%) rename instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/{SpringMvcBuilderHolder.java => SpringMvcBuilderUtil.java} (89%) rename instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/{SpringMvcBuilderHolder.java => SpringMvcBuilderUtil.java} (89%) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java index 78115bf55706..d4a995da8297 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderHolder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -36,8 +36,8 @@ static SpringWebfluxTelemetry getWebfluxTelemetry( return InstrumentationConfigUtil.configureClientAndServerBuilder( config, SpringWebfluxTelemetry.builder(openTelemetry), - SpringWebfluxBuilderHolder.getClientBuilderExtractor(), - SpringWebfluxBuilderHolder.getServerBuilderExtractor()) + SpringWebfluxBuilderUtil.getClientBuilderExtractor(), + SpringWebfluxBuilderUtil.getServerBuilderExtractor()) .build(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java index 5be32ae97910..ccd077a42d09 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetry; -import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderHolder; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import javax.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -29,7 +29,7 @@ Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry), - SpringMvcBuilderHolder.getBuilderExtractor()) + SpringMvcBuilderUtil.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java index 3c47f682df9c..18dd08df56ef 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetry; -import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderHolder; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import jakarta.servlet.Filter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -29,7 +29,7 @@ Filter otelWebMvcFilter(OpenTelemetry openTelemetry, ConfigProperties config) { return InstrumentationConfigUtil.configureServerBuilder( config, SpringWebMvcTelemetry.builder(openTelemetry), - SpringMvcBuilderHolder.getBuilderExtractor()) + SpringMvcBuilderUtil.getBuilderExtractor()) .build() .createServletFilter(); } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java index 725ba7de4e13..99ee1a3f9273 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/WebClientHelper.java @@ -19,7 +19,7 @@ public final class WebClientHelper { private static final Instrumenter instrumenter = JavaagentHttpClientInstrumenters.create( - "io.opentelemetry.spring-webflux-5.3", WebClientHttpAttributesGetter.INSTANCE); + "io.opentelemetry.spring-webflux-5.0", WebClientHttpAttributesGetter.INSTANCE); public static void addFilter(List exchangeFilterFunctions) { for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index 3ba7fe8ebc74..e8387880cd32 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -13,7 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderHolder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderUtil; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import java.util.List; import java.util.Set; @@ -31,9 +31,9 @@ public final class SpringWebfluxTelemetryBuilder { serverBuilder; static { - SpringWebfluxBuilderHolder.setClientBuilderExtractor( + SpringWebfluxBuilderUtil.setClientBuilderExtractor( SpringWebfluxTelemetryBuilder::getClientBuilder); - SpringWebfluxBuilderHolder.setServerBuilderExtractor( + SpringWebfluxBuilderUtil.setServerBuilderExtractor( SpringWebfluxTelemetryBuilder::getServerBuilder); } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java similarity index 89% rename from instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java index 2979b8854449..1d2337fa99fb 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderHolder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java @@ -17,8 +17,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringWebfluxBuilderHolder { - private SpringWebfluxBuilderHolder() {} +public class SpringWebfluxBuilderUtil { + private SpringWebfluxBuilderUtil() {} private static Function< SpringWebfluxTelemetryBuilder, @@ -42,7 +42,7 @@ public static void setServerBuilderExtractor( SpringWebfluxTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor) { - SpringWebfluxBuilderHolder.serverBuilderExtractor = serverBuilderExtractor; + SpringWebfluxBuilderUtil.serverBuilderExtractor = serverBuilderExtractor; } public static Function< @@ -57,6 +57,6 @@ public static void setClientBuilderExtractor( SpringWebfluxTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor) { - SpringWebfluxBuilderHolder.clientBuilderExtractor = clientBuilderExtractor; + SpringWebfluxBuilderUtil.clientBuilderExtractor = clientBuilderExtractor; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index a8d71c1f5a9a..588263aff6e6 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -11,7 +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.spring.webmvc.v5_3.internal.SpringMvcBuilderHolder; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderUtil; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -27,7 +27,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcBuilderHolder.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); + SpringMvcBuilderUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java similarity index 89% rename from instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java rename to instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java index e377384b121d..75a6b8f94d51 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderHolder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java @@ -15,8 +15,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcBuilderHolder { - private SpringMvcBuilderHolder() {} +public class SpringMvcBuilderUtil { + private SpringMvcBuilderUtil() {} private static Function< SpringWebMvcTelemetryBuilder, @@ -35,6 +35,6 @@ public static void setBuilderExtractor( SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> builderExtractor) { - SpringMvcBuilderHolder.builderExtractor = builderExtractor; + SpringMvcBuilderUtil.builderExtractor = builderExtractor; } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 4795d8b5d818..7978664dd053 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -11,7 +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.spring.webmvc.v6_0.internal.SpringMvcBuilderHolder; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -26,7 +26,7 @@ public final class SpringWebMvcTelemetryBuilder { builder; static { - SpringMvcBuilderHolder.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); + SpringMvcBuilderUtil.setBuilderExtractor(SpringWebMvcTelemetryBuilder::getBuilder); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java similarity index 89% rename from instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java rename to instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java index 6187cdfd8182..1521270105ef 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderHolder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java @@ -15,8 +15,8 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcBuilderHolder { - private SpringMvcBuilderHolder() {} +public class SpringMvcBuilderUtil { + private SpringMvcBuilderUtil() {} private static Function< SpringWebMvcTelemetryBuilder, @@ -35,6 +35,6 @@ public static void setBuilderExtractor( SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> builderExtractor) { - SpringMvcBuilderHolder.builderExtractor = builderExtractor; + SpringMvcBuilderUtil.builderExtractor = builderExtractor; } } From 9dd253492af91441d9c13421c53f0f47d80d1b38 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 5 Jul 2024 16:11:07 +0200 Subject: [PATCH 13/18] make classes final --- .../internal/properties/InstrumentationConfigUtil.java | 2 +- .../spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java | 2 +- .../spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java | 2 +- .../spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java | 2 +- .../io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java index 03ad464f4ce9..747cf33dcb09 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java @@ -16,7 +16,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class InstrumentationConfigUtil { +public final class InstrumentationConfigUtil { private InstrumentationConfigUtil() {} @CanIgnoreReturnValue diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java index 1d2337fa99fb..ac892b3926ad 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java @@ -17,7 +17,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringWebfluxBuilderUtil { +public final class SpringWebfluxBuilderUtil { private SpringWebfluxBuilderUtil() {} private static Function< diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java index 75a6b8f94d51..03e07e533825 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java @@ -15,7 +15,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcBuilderUtil { +public final class SpringMvcBuilderUtil { private SpringMvcBuilderUtil() {} private static Function< diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java index 1521270105ef..e00568facdfe 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java @@ -15,7 +15,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public class SpringMvcBuilderUtil { +public final class SpringMvcBuilderUtil { private SpringMvcBuilderUtil() {} private static Function< diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java index 6c8306ca609b..b9f3fadc93ff 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java @@ -17,7 +17,7 @@ import java.util.function.Consumer; import org.assertj.core.api.AbstractLongAssert; -public class HttpSpanDataAssert { +public final class HttpSpanDataAssert { private final SpanDataAssert span; From d0f0307ce5d8ce9231d37fadcaafa72978763824 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 9 Jul 2024 16:30:23 +0200 Subject: [PATCH 14/18] use hasAttributesSatisfying --- .../opentelemetry/spring/smoketest/HttpSpanDataAssert.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java index b9f3fadc93ff..4f6018d46167 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/HttpSpanDataAssert.java @@ -5,6 +5,7 @@ package io.opentelemetry.spring.smoketest; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -44,10 +45,10 @@ public HttpSpanDataAssert assertClientGetRequest(String path) { @CanIgnoreReturnValue public HttpSpanDataAssert assertServerGetRequest(String route) { span.hasKind(SpanKind.SERVER) - .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") - .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) - .hasAttribute(HttpAttributes.HTTP_ROUTE, route) .hasAttributesSatisfying( + equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + equalTo(HttpAttributes.HTTP_ROUTE, route), // this attribute is set by the experimental http instrumentation satisfies( HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, From c8763b5125363f4bb9c8b060d99bef99927d41f5 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 10 Jul 2024 07:32:21 +0200 Subject: [PATCH 15/18] Update instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java Co-authored-by: Trask Stalnaker --- .../spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java index e00568facdfe..d60102acd19a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java @@ -18,6 +18,7 @@ public final class SpringMvcBuilderUtil { private SpringMvcBuilderUtil() {} + // allows access to the private field for the spring starter private static Function< SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> From be7e18d606a89e7d67103916b7da6237c38ce51a Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 10 Jul 2024 07:32:32 +0200 Subject: [PATCH 16/18] Update instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java Co-authored-by: Trask Stalnaker --- .../spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java index 03e07e533825..74ac99e33d8a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java @@ -18,6 +18,7 @@ public final class SpringMvcBuilderUtil { private SpringMvcBuilderUtil() {} + // allows access to the private field for the spring starter private static Function< SpringWebMvcTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> From 590a611bce5aadad6320853e4a250f2c2427c2ac Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 10 Jul 2024 07:45:10 +0200 Subject: [PATCH 17/18] use hasAttributesSatisfying --- .../spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java index ac892b3926ad..ec1d643b1d88 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java @@ -20,11 +20,13 @@ public final class SpringWebfluxBuilderUtil { private SpringWebfluxBuilderUtil() {} + // allows access to the private field for the spring starter private static Function< SpringWebfluxTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor; + // allows access to the private field for the spring starter private static Function< SpringWebfluxTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> From 5bf055ab133cead2f7be642db69284d08325a0d6 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 10 Jul 2024 18:15:19 +0200 Subject: [PATCH 18/18] pr review --- .../DefaultHttpServerInstrumenterBuilder.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) 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 273bbb0f11d0..b229a7126e48 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 @@ -169,14 +169,7 @@ public DefaultHttpServerInstrumenterBuilder setSpanNameExtrac } public Instrumenter build() { - return build(b -> {}); - } - - public Instrumenter build( - Consumer> instrumenterBuilderConsumer) { - InstrumenterBuilder builder = builder(); - instrumenterBuilderConsumer.accept(builder); if (headerGetter != null) { return builder.buildServerInstrumenter(headerGetter); @@ -184,7 +177,7 @@ public Instrumenter build( return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); } - public InstrumenterBuilder builder() { + private InstrumenterBuilder builder() { SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); @@ -206,10 +199,6 @@ public InstrumenterBuilder builder() { return builder; } - public OpenTelemetry getOpenTelemetry() { - return openTelemetry; - } - @CanIgnoreReturnValue public DefaultHttpServerInstrumenterBuilder configure(CommonConfig config) { set(config::getKnownHttpRequestMethods, this::setKnownMethods);