From 3ca45a4ec011cc5c8bdbbb7d7c72c8af371ac4c7 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 8 Dec 2024 09:42:23 -0800 Subject: [PATCH 01/12] Split Webflux into client and server --- ...bfluxInstrumentationAutoConfiguration.java | 2 +- .../webflux/WebClientBeanPostProcessor.java | 25 ++-- .../properties/InstrumentationConfigUtil.java | 15 --- .../v5_3/SpringWebfluxClientTelemetry.java | 54 ++++++++ .../SpringWebfluxClientTelemetryBuilder.java | 121 +++++++++++++++++ .../v5_3/SpringWebfluxServerTelemetry.java | 54 ++++++++ .../SpringWebfluxServerTelemetryBuilder.java | 122 ++++++++++++++++++ .../webflux/v5_3/SpringWebfluxTelemetry.java | 29 ++++- .../v5_3/SpringWebfluxTelemetryBuilder.java | 77 ++++++++--- .../webflux/v5_3/internal/Experimental.java | 86 ++++++++++++ .../internal/SpringWebfluxBuilderUtil.java | 15 ++- ...pringWebfluxClientInstrumentationTest.java | 10 +- .../v5_3/TestWebfluxSpringBootApp.java | 7 +- 13 files changed, 556 insertions(+), 61 deletions(-) create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java index bdf00acf732b..76288e4952df 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/SpringWebfluxInstrumentationAutoConfiguration.java @@ -40,7 +40,7 @@ static WebClientBeanPostProcessor otelWebClientBeanPostProcessor( @Bean WebFilter telemetryFilter(OpenTelemetry openTelemetry, ConfigProperties config) { - return WebClientBeanPostProcessor.getWebfluxTelemetry(openTelemetry, config) + return WebClientBeanPostProcessor.getWebfluxServerTelemetry(openTelemetry, config) .createWebFilterAndRegisterReactorHook(); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java index 90dde820c4a9..22d06fe358c3 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -7,7 +7,8 @@ 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.SpringWebfluxClientTelemetry; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxServerTelemetry; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import org.springframework.beans.factory.ObjectProvider; @@ -31,12 +32,20 @@ final class WebClientBeanPostProcessor implements BeanPostProcessor { this.configPropertiesProvider = configPropertiesProvider; } - static SpringWebfluxTelemetry getWebfluxTelemetry( + static SpringWebfluxClientTelemetry getWebfluxClientTelemetry( OpenTelemetry openTelemetry, ConfigProperties config) { - return InstrumentationConfigUtil.configureClientAndServerBuilder( + return InstrumentationConfigUtil.configureClientBuilder( config, - SpringWebfluxTelemetry.builder(openTelemetry), - SpringWebfluxBuilderUtil.getClientBuilderExtractor(), + SpringWebfluxClientTelemetry.builder(openTelemetry), + SpringWebfluxBuilderUtil.getClientBuilderExtractor()) + .build(); + } + + static SpringWebfluxServerTelemetry getWebfluxServerTelemetry( + OpenTelemetry openTelemetry, ConfigProperties config) { + return InstrumentationConfigUtil.configureServerBuilder( + config, + SpringWebfluxServerTelemetry.builder(openTelemetry), SpringWebfluxBuilderUtil.getServerBuilderExtractor()) .build(); } @@ -54,9 +63,9 @@ public Object postProcessAfterInitialization(Object bean, String beanName) { } private WebClient.Builder wrapBuilder(WebClient.Builder webClientBuilder) { - SpringWebfluxTelemetry instrumentation = - getWebfluxTelemetry( + SpringWebfluxClientTelemetry instrumentation = + getWebfluxClientTelemetry( openTelemetryProvider.getObject(), configPropertiesProvider.getObject()); - return webClientBuilder.filters(instrumentation::addClientTracingFilter); + return webClientBuilder.filters(instrumentation::addTracingFilter); } } 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 747cf33dcb09..fb5e582bfaa5 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 @@ -19,21 +19,6 @@ public final class InstrumentationConfigUtil { private InstrumentationConfigUtil() {} - @CanIgnoreReturnValue - public static - T configureClientAndServerBuilder( - ConfigProperties config, - T builder, - Function> - getClientBuilder, - Function> - getServerBuilder) { - CommonConfig commonConfig = getConfig(config); - getClientBuilder.apply(builder).configure(commonConfig); - getServerBuilder.apply(builder).configure(commonConfig); - return builder; - } - @CanIgnoreReturnValue public static T configureClientBuilder( ConfigProperties config, diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java new file mode 100644 index 000000000000..94139e19949e --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientTracingFilter; +import java.util.List; +import org.springframework.web.reactive.function.client.ClientRequest; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.ExchangeFilterFunction; + +/** Entrypoint for instrumenting Spring Webflux HTTP clients. */ +public final class SpringWebfluxClientTelemetry { + + /** + * Returns a new {@link SpringWebfluxClientTelemetry} configured with the given {@link + * OpenTelemetry}. + */ + public static SpringWebfluxClientTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + /** + * Returns a new {@link SpringWebfluxClientTelemetryBuilder} configured with the given {@link + * OpenTelemetry}. + */ + public static SpringWebfluxClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new SpringWebfluxClientTelemetryBuilder(openTelemetry); + } + + private final Instrumenter clientInstrumenter; + private final ContextPropagators propagators; + + SpringWebfluxClientTelemetry( + Instrumenter clientInstrumenter, + ContextPropagators propagators) { + this.clientInstrumenter = clientInstrumenter; + this.propagators = propagators; + } + + public void addTracingFilter(List exchangeFilterFunctions) { + for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { + if (filterFunction instanceof WebClientTracingFilter) { + return; + } + } + exchangeFilterFunctions.add(new WebClientTracingFilter(clientInstrumenter, propagators)); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java new file mode 100644 index 000000000000..1255d3e729f0 --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java @@ -0,0 +1,121 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.Experimental; +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; +import java.util.function.Function; +import org.springframework.web.reactive.function.client.ClientRequest; +import org.springframework.web.reactive.function.client.ClientResponse; + +/** A builder of {@link SpringWebfluxClientTelemetry}. */ +public final class SpringWebfluxClientTelemetryBuilder { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; + + private final DefaultHttpClientInstrumenterBuilder builder; + private final OpenTelemetry openTelemetry; + + static { + SpringWebfluxBuilderUtil.setClientBuilderExtractor(builder -> builder.builder); + } + + SpringWebfluxClientTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = + DefaultHttpClientInstrumenterBuilder.create( + INSTRUMENTATION_NAME, openTelemetry, WebClientHttpAttributesGetter.INSTANCE); + this.openTelemetry = openTelemetry; + } + + /** + * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented + * items for WebClient. + */ + @CanIgnoreReturnValue + public SpringWebfluxClientTelemetryBuilder addAttributesExtractor( + AttributesExtractor attributesExtractor) { + builder.addAttributeExtractor(attributesExtractor); + return this; + } + + /** + * Configures the HTTP WebClient request headers that will be captured as span attributes. + * + * @param requestHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public SpringWebfluxClientTelemetryBuilder setCapturedRequestHeaders( + List requestHeaders) { + builder.setCapturedRequestHeaders(requestHeaders); + return this; + } + + /** + * Configures the HTTP WebClient response headers that will be captured as span attributes. + * + * @param responseHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public SpringWebfluxClientTelemetryBuilder setCapturedResponseHeaders( + List responseHeaders) { + builder.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 HttpClientAttributesExtractorBuilder#setKnownMethods(Set) + */ + @CanIgnoreReturnValue + public SpringWebfluxClientTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom client {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public SpringWebfluxClientTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + clientSpanNameExtractor) { + builder.setSpanNameExtractor(clientSpanNameExtractor); + return this; + } + + /** + * Can be used via the unstable method {@link + * Experimental#setEmitExperimentalTelemetry(SpringWebfluxClientTelemetryBuilder, boolean)}. + */ + void setEmitExperimentalHttpClientTelemetry(boolean emitExperimentalHttpClientTelemetry) { + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientTelemetry); + } + + /** + * Returns a new {@link SpringWebfluxClientTelemetry} with the settings of this {@link + * SpringWebfluxClientTelemetryBuilder}. + */ + public SpringWebfluxClientTelemetry build() { + return new SpringWebfluxClientTelemetry(builder.build(), openTelemetry.getPropagators()); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.java new file mode 100644 index 000000000000..f3c1dacca15f --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.java @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.reactor.v3_1.ContextPropagationOperator; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; + +/** Entrypoint for instrumenting Spring Webflux HTTP services. */ +public final class SpringWebfluxServerTelemetry { + + /** + * Returns a new {@link SpringWebfluxServerTelemetry} configured with the given {@link + * OpenTelemetry}. + */ + public static SpringWebfluxServerTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + /** + * Returns a new {@link SpringWebfluxServerTelemetryBuilder} configured with the given {@link + * OpenTelemetry}. + */ + public static SpringWebfluxServerTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new SpringWebfluxServerTelemetryBuilder(openTelemetry); + } + + // We use ServerWebExchange (which holds both the request and response) + // because we need it to get the HTTP route while instrumenting. + private final Instrumenter serverInstrumenter; + + SpringWebfluxServerTelemetry( + Instrumenter serverInstrumenter) { + this.serverInstrumenter = serverInstrumenter; + } + + public WebFilter createWebFilter() { + return new TelemetryProducingWebFilter(serverInstrumenter); + } + + public WebFilter createWebFilterAndRegisterReactorHook() { + registerReactorHook(); + return this.createWebFilter(); + } + + private static void registerReactorHook() { + ContextPropagationOperator.builder().build().registerOnEachOperator(); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java new file mode 100644 index 000000000000..7624b2c314db --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java @@ -0,0 +1,122 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.Experimental; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderUtil; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import org.springframework.web.server.ServerWebExchange; + +/** A builder of {@link SpringWebfluxServerTelemetry}. */ +public final class SpringWebfluxServerTelemetryBuilder { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; + + private final DefaultHttpServerInstrumenterBuilder builder; + + static { + SpringWebfluxBuilderUtil.setServerBuilderExtractor(builder -> builder.builder); + } + + SpringWebfluxServerTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = + DefaultHttpServerInstrumenterBuilder.create( + INSTRUMENTATION_NAME, + openTelemetry, + WebfluxServerHttpAttributesGetter.INSTANCE, + WebfluxTextMapGetter.INSTANCE); + } + + /** + * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented + * items. + */ + @CanIgnoreReturnValue + public SpringWebfluxServerTelemetryBuilder addAttributesExtractor( + AttributesExtractor attributesExtractor) { + builder.addAttributesExtractor(attributesExtractor); + return this; + } + + /** + * Configures the HTTP request headers that will be captured as span attributes from server + * instrumentation. + * + * @param requestHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public SpringWebfluxServerTelemetryBuilder setCapturedRequestHeaders( + List requestHeaders) { + builder.setCapturedRequestHeaders(requestHeaders); + return this; + } + + /** + * Configures the HTTP response headers that will be captured as span attributes from server + * instrumentation. + * + * @param responseHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public SpringWebfluxServerTelemetryBuilder setCapturedResponseHeaders( + List responseHeaders) { + builder.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 SpringWebfluxServerTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom server {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public SpringWebfluxServerTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + serverSpanNameExtractor) { + builder.setSpanNameExtractor(serverSpanNameExtractor); + return this; + } + + /** + * Can be used via the unstable method {@link + * Experimental#setEmitExperimentalTelemetry(SpringWebfluxServerTelemetryBuilder, boolean)}. + */ + void setEmitExperimentalHttpServerTelemetry(boolean emitExperimentalHttpServerTelemetry) { + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerTelemetry); + } + + /** + * Returns a new {@link SpringWebfluxTelemetry} with the settings of this {@link + * SpringWebfluxServerTelemetryBuilder}. + */ + public SpringWebfluxServerTelemetry build() { + return new SpringWebfluxServerTelemetry(builder.build()); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java index 27021d22ea40..622b671fb0b9 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java @@ -17,12 +17,22 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; -/** Entrypoint for instrumenting Spring Webflux HTTP clients. */ +/** + * Entrypoint for instrumenting Spring Webflux HTTP clients and services. + * + * @deprecated Use {@link SpringWebfluxClientTelemetry} and {@link SpringWebfluxServerTelemetry} + * instead. + */ +@Deprecated public final class SpringWebfluxTelemetry { /** * Returns a new {@link SpringWebfluxTelemetry} configured with the given {@link OpenTelemetry}. + * + * @deprecated Use {@link SpringWebfluxClientTelemetry#create(OpenTelemetry)} and {@link + * SpringWebfluxServerTelemetry#create(OpenTelemetry)} instead. */ + @Deprecated public static SpringWebfluxTelemetry create(OpenTelemetry openTelemetry) { return builder(openTelemetry).build(); } @@ -30,7 +40,11 @@ public static SpringWebfluxTelemetry create(OpenTelemetry openTelemetry) { /** * Returns a new {@link SpringWebfluxTelemetryBuilder} configured with the given {@link * OpenTelemetry}. + * + * @deprecated Use {@link SpringWebfluxClientTelemetry#builder(OpenTelemetry)} and {@link + * SpringWebfluxServerTelemetry#builder(OpenTelemetry)} instead. */ + @Deprecated public static SpringWebfluxTelemetryBuilder builder(OpenTelemetry openTelemetry) { return new SpringWebfluxTelemetryBuilder(openTelemetry); } @@ -50,6 +64,10 @@ public static SpringWebfluxTelemetryBuilder builder(OpenTelemetry openTelemetry) this.propagators = propagators; } + /** + * @deprecated Use {@link SpringWebfluxClientTelemetry#addTracingFilter(List)} instead. + */ + @Deprecated public void addClientTracingFilter(List exchangeFilterFunctions) { for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { if (filterFunction instanceof WebClientTracingFilter) { @@ -59,10 +77,19 @@ public void addClientTracingFilter(List exchangeFilterFu exchangeFilterFunctions.add(new WebClientTracingFilter(clientInstrumenter, propagators)); } + /** + * @deprecated Use {@link SpringWebfluxServerTelemetry#createWebFilter()} instead. + */ + @Deprecated public WebFilter createWebFilter() { return new TelemetryProducingWebFilter(serverInstrumenter); } + /** + * @deprecated Use {@link SpringWebfluxServerTelemetry#createWebFilterAndRegisterReactorHook()} + * instead. + */ + @Deprecated public WebFilter createWebFilterAndRegisterReactorHook() { registerReactorHook(); return this.createWebFilter(); 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 602ded9c1d4d..4d72324ad7cc 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.SpringWebfluxBuilderUtil; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.Experimental; import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; import java.util.List; import java.util.Set; @@ -22,7 +22,13 @@ import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.server.ServerWebExchange; -/** A builder of {@link SpringWebfluxTelemetry}. */ +/** + * A builder of {@link SpringWebfluxTelemetry}. + * + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder} and {@link + * SpringWebfluxServerTelemetryBuilder} instead. + */ +@Deprecated public final class SpringWebfluxTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; @@ -31,13 +37,6 @@ public final class SpringWebfluxTelemetryBuilder { serverBuilder; private final OpenTelemetry openTelemetry; - static { - SpringWebfluxBuilderUtil.setClientBuilderExtractor( - SpringWebfluxTelemetryBuilder::getClientBuilder); - SpringWebfluxBuilderUtil.setServerBuilderExtractor( - SpringWebfluxTelemetryBuilder::getServerBuilder); - } - SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = DefaultHttpClientInstrumenterBuilder.create( @@ -54,7 +53,11 @@ public final class SpringWebfluxTelemetryBuilder { /** * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented * items for WebClient. + * + * @deprecated Use {@link + * SpringWebfluxClientTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder addClientAttributesExtractor( AttributesExtractor attributesExtractor) { @@ -66,7 +69,10 @@ public SpringWebfluxTelemetryBuilder addClientAttributesExtractor( * Configures the HTTP WebClient request headers that will be captured as span attributes. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder#setCapturedRequestHeaders(List)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedClientRequestHeaders( List requestHeaders) { @@ -78,7 +84,10 @@ public SpringWebfluxTelemetryBuilder setCapturedClientRequestHeaders( * Configures the HTTP WebClient response headers that will be captured as span attributes. * * @param responseHeaders A list of HTTP header names. + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder#setCapturedResponseHeaders(List)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedClientResponseHeaders( List responseHeaders) { @@ -89,7 +98,11 @@ public SpringWebfluxTelemetryBuilder setCapturedClientResponseHeaders( /** * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented * items. + * + * @deprecated Use {@link + * SpringWebfluxServerTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder addServerAttributesExtractor( AttributesExtractor attributesExtractor) { @@ -102,7 +115,10 @@ public SpringWebfluxTelemetryBuilder addServerAttributesExtractor( * instrumentation. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link SpringWebfluxServerTelemetryBuilder#setCapturedRequestHeaders(List)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedServerRequestHeaders( List requestHeaders) { @@ -115,7 +131,10 @@ public SpringWebfluxTelemetryBuilder setCapturedServerRequestHeaders( * instrumentation. * * @param responseHeaders A list of HTTP header names. + * @deprecated Use {@link SpringWebfluxServerTelemetryBuilder#setCapturedResponseHeaders(List)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setCapturedServerResponseHeaders( List responseHeaders) { @@ -136,7 +155,10 @@ public SpringWebfluxTelemetryBuilder setCapturedServerResponseHeaders( * @param knownMethods A set of recognized HTTP request methods. * @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set) * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Set) + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder#setKnownMethods(Set)} and {@link + * SpringWebfluxServerTelemetryBuilder#setKnownMethods(Set)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setKnownMethods(Set knownMethods) { clientBuilder.setKnownMethods(knownMethods); @@ -149,7 +171,11 @@ public SpringWebfluxTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientTelemetry {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalTelemetry(SpringWebfluxClientTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpClientTelemetry( boolean emitExperimentalHttpClientTelemetry) { @@ -162,7 +188,11 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpClientTelemetry( * * @param emitExperimentalHttpServerTelemetry {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalTelemetry(SpringWebfluxServerTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( boolean emitExperimentalHttpServerTelemetry) { @@ -170,7 +200,13 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( return this; } - /** Sets custom client {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom client {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder#setSpanNameExtractor(Function)} + * instead. + */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( Function< @@ -181,7 +217,13 @@ public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( return this; } - /** Sets custom server {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom server {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link SpringWebfluxServerTelemetryBuilder#setSpanNameExtractor(Function)} + * instead. + */ + @Deprecated @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setServerSpanNameExtractor( Function< @@ -195,18 +237,13 @@ public SpringWebfluxTelemetryBuilder setServerSpanNameExtractor( /** * Returns a new {@link SpringWebfluxTelemetry} with the settings of this {@link * SpringWebfluxTelemetryBuilder}. + * + * @deprecated Use {@link SpringWebfluxClientTelemetryBuilder#build()} and {@link + * SpringWebfluxServerTelemetryBuilder#build()} instead. */ + @Deprecated public SpringWebfluxTelemetry build() { return new SpringWebfluxTelemetry( clientBuilder.build(), serverBuilder.build(), openTelemetry.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/Experimental.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java new file mode 100644 index 000000000000..aec6e27c9b28 --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java @@ -0,0 +1,86 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxClientTelemetryBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxServerTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +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. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalClientTelemetryMethod = + getEmitExperimentalClientTelemetryMethod(); + + @Nullable + private static final Method emitExperimentalServerTelemetryMethod = + getEmitExperimentalServerTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + SpringWebfluxClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalClientTelemetryMethod != null) { + try { + emitExperimentalClientTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + public void setEmitExperimentalTelemetry( + SpringWebfluxServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalServerTelemetryMethod != null) { + try { + emitExperimentalServerTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalClientTelemetryMethod() { + try { + Method method = + SpringWebfluxClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientTelemetry", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } + + @Nullable + private static Method getEmitExperimentalServerTelemetryMethod() { + try { + Method method = + SpringWebfluxServerTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerTelemetry", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} 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 ec1d643b1d88..e2e9ebf87b08 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 @@ -7,7 +7,8 @@ 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 io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxClientTelemetryBuilder; +import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxServerTelemetryBuilder; import java.util.function.Function; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; @@ -22,18 +23,18 @@ private SpringWebfluxBuilderUtil() {} // allows access to the private field for the spring starter private static Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor; // allows access to the private field for the spring starter private static Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor; public static Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> getServerBuilderExtractor() { return serverBuilderExtractor; @@ -41,14 +42,14 @@ private SpringWebfluxBuilderUtil() {} public static void setServerBuilderExtractor( Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor) { SpringWebfluxBuilderUtil.serverBuilderExtractor = serverBuilderExtractor; } public static Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> getClientBuilderExtractor() { return clientBuilderExtractor; @@ -56,7 +57,7 @@ public static void setServerBuilderExtractor( public static void setClientBuilderExtractor( Function< - SpringWebfluxTelemetryBuilder, + SpringWebfluxClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor) { SpringWebfluxBuilderUtil.clientBuilderExtractor = clientBuilderExtractor; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java index 6ed4170704ab..e8980ef3d9fb 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java @@ -21,13 +21,13 @@ class SpringWebfluxClientInstrumentationTest @Override protected WebClient.Builder instrument(WebClient.Builder builder) { - SpringWebfluxTelemetry instrumentation = - SpringWebfluxTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedClientRequestHeaders( + SpringWebfluxClientTelemetry instrumentation = + SpringWebfluxClientTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) - .setCapturedClientResponseHeaders( + .setCapturedResponseHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) .build(); - return builder.filters(instrumentation::addClientTracingFilter); + return builder.filters(instrumentation::addTracingFilter); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootApp.java index c0eb9a65d91e..77afcf9881c0 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootApp.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootApp.java @@ -52,10 +52,9 @@ static ConfigurableApplicationContext start(int port, String contextPath) { @Bean WebFilter telemetryFilter() { - return SpringWebfluxTelemetry.builder(GlobalOpenTelemetry.get()) - .setCapturedServerRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedServerResponseHeaders( - singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + return SpringWebfluxServerTelemetry.builder(GlobalOpenTelemetry.get()) + .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build() .createWebFilterAndRegisterReactorHook(); } From 26317754a032ce7863296a4dcb350aa59543dc3c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 14:19:14 -0800 Subject: [PATCH 02/12] Fix javadoc todo --- .../spring/webflux/v5_3/internal/Experimental.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java index aec6e27c9b28..c3d05e0967f7 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java @@ -15,11 +15,10 @@ 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. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); From 52101cb369a974c45b44246ed32110d013098334 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:08:03 -0800 Subject: [PATCH 03/12] remove reflection --- .../SpringWebfluxClientTelemetryBuilder.java | 4 +- .../SpringWebfluxServerTelemetryBuilder.java | 2 + .../webflux/v5_3/internal/Experimental.java | 64 +++++-------------- 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java index 1255d3e729f0..fa100d06b1cc 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java @@ -29,6 +29,8 @@ public final class SpringWebfluxClientTelemetryBuilder { static { SpringWebfluxBuilderUtil.setClientBuilderExtractor(builder -> builder.builder); + Experimental.setSetEmitExperimentalClientTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); } SpringWebfluxClientTelemetryBuilder(OpenTelemetry openTelemetry) { @@ -45,7 +47,7 @@ public final class SpringWebfluxClientTelemetryBuilder { @CanIgnoreReturnValue public SpringWebfluxClientTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - builder.addAttributeExtractor(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java index 7624b2c314db..11719ab2883b 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java @@ -26,6 +26,8 @@ public final class SpringWebfluxServerTelemetryBuilder { static { SpringWebfluxBuilderUtil.setServerBuilderExtractor(builder -> builder.builder); + Experimental.setSetEmitExperimentalServerTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); } SpringWebfluxServerTelemetryBuilder(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/Experimental.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java index c3d05e0967f7..28b22239cdc5 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java @@ -5,13 +5,9 @@ package io.opentelemetry.instrumentation.spring.webflux.v5_3.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxClientTelemetryBuilder; import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxServerTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -21,65 +17,35 @@ */ public class Experimental { - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); - @Nullable - private static final Method emitExperimentalClientTelemetryMethod = - getEmitExperimentalClientTelemetryMethod(); + private static BiConsumer + setEmitExperimentalClientTelemetry; @Nullable - private static final Method emitExperimentalServerTelemetryMethod = - getEmitExperimentalServerTelemetryMethod(); + private static BiConsumer + setEmitExperimentalServerTelemetry; public void setEmitExperimentalTelemetry( SpringWebfluxClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalClientTelemetryMethod != null) { - try { - emitExperimentalClientTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalClientTelemetry != null) { + setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); } } public void setEmitExperimentalTelemetry( SpringWebfluxServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalServerTelemetryMethod != null) { - try { - emitExperimentalServerTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalServerTelemetry != null) { + setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalClientTelemetryMethod() { - try { - Method method = - SpringWebfluxClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientTelemetry", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalClientTelemetry( + BiConsumer setEmitExperimentalClientTelemetry) { + Experimental.setEmitExperimentalClientTelemetry = setEmitExperimentalClientTelemetry; } - @Nullable - private static Method getEmitExperimentalServerTelemetryMethod() { - try { - Method method = - SpringWebfluxServerTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerTelemetry", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalServerTelemetry( + BiConsumer setEmitExperimentalServerTelemetry) { + Experimental.setEmitExperimentalServerTelemetry = setEmitExperimentalServerTelemetry; } } From f75952543271f39d05e011d5f70e04167473a82e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:55:04 -0800 Subject: [PATCH 04/12] volatile --- .../spring/webflux/v5_3/internal/Experimental.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java index 28b22239cdc5..429d0bdc63b2 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java @@ -18,11 +18,11 @@ public class Experimental { @Nullable - private static BiConsumer + private static volatile BiConsumer setEmitExperimentalClientTelemetry; @Nullable - private static BiConsumer + private static volatile BiConsumer setEmitExperimentalServerTelemetry; public void setEmitExperimentalTelemetry( From 1e112b00c8828baf22931469fdbabd3905577c69 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 20:30:59 -0800 Subject: [PATCH 05/12] static --- .../spring/webflux/v5_3/internal/Experimental.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java index 429d0bdc63b2..d20a6da4251f 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/Experimental.java @@ -15,7 +15,7 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { +public final class Experimental { @Nullable private static volatile BiConsumer @@ -25,14 +25,14 @@ public class Experimental { private static volatile BiConsumer setEmitExperimentalServerTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( SpringWebfluxClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalClientTelemetry != null) { setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); } } - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( SpringWebfluxServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalServerTelemetry != null) { setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); @@ -48,4 +48,6 @@ public static void setSetEmitExperimentalServerTelemetry( BiConsumer setEmitExperimentalServerTelemetry) { Experimental.setEmitExperimentalServerTelemetry = setEmitExperimentalServerTelemetry; } + + private Experimental() {} } From e141184d549d00e4ca271308a03b9b236efed15d Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 08:32:46 -0800 Subject: [PATCH 06/12] Remove unused --- .../webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java | 8 -------- .../webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java | 8 -------- 2 files changed, 16 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java index fa100d06b1cc..3c99207b9f8d 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.java @@ -105,14 +105,6 @@ public SpringWebfluxClientTelemetryBuilder setSpanNameExtractor( return this; } - /** - * Can be used via the unstable method {@link - * Experimental#setEmitExperimentalTelemetry(SpringWebfluxClientTelemetryBuilder, boolean)}. - */ - void setEmitExperimentalHttpClientTelemetry(boolean emitExperimentalHttpClientTelemetry) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientTelemetry); - } - /** * Returns a new {@link SpringWebfluxClientTelemetry} with the settings of this {@link * SpringWebfluxClientTelemetryBuilder}. diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java index 11719ab2883b..b00dec6ffefb 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetryBuilder.java @@ -106,14 +106,6 @@ public SpringWebfluxServerTelemetryBuilder setSpanNameExtractor( return this; } - /** - * Can be used via the unstable method {@link - * Experimental#setEmitExperimentalTelemetry(SpringWebfluxServerTelemetryBuilder, boolean)}. - */ - void setEmitExperimentalHttpServerTelemetry(boolean emitExperimentalHttpServerTelemetry) { - builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerTelemetry); - } - /** * Returns a new {@link SpringWebfluxTelemetry} with the settings of this {@link * SpringWebfluxServerTelemetryBuilder}. From 0b05aac3adbdcb070d6c85528a1375b7b3a4d5c7 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 08:36:18 -0800 Subject: [PATCH 07/12] test deprecated classes --- ...ngWebfluxClientInstrumentationOldTest.java | 33 +++++ ...ngWebfluxServerInstrumentationOldTest.java | 69 +++++++++ .../v5_3/TestWebfluxSpringBootOldApp.java | 139 ++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java create mode 100644 instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java new file mode 100644 index 000000000000..e8980ef3d9fb --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import io.opentelemetry.instrumentation.spring.webflux.client.AbstractSpringWebfluxClientInstrumentationTest; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import java.util.Collections; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.web.reactive.function.client.WebClient; + +class SpringWebfluxClientInstrumentationTest + extends AbstractSpringWebfluxClientInstrumentationTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary(); + + @Override + protected WebClient.Builder instrument(WebClient.Builder builder) { + SpringWebfluxClientTelemetry instrumentation = + SpringWebfluxClientTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) + .build(); + return builder.filters(instrumentation::addTracingFilter); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java new file mode 100644 index 000000000000..54a71116a581 --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java @@ -0,0 +1,69 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.context.ConfigurableApplicationContext; + +public final class SpringWebfluxServerInstrumentationTest + extends AbstractHttpServerTest { + + private static final String CONTEXT_PATH = "/test"; + + @RegisterExtension + static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forLibrary(); + + @Override + protected ConfigurableApplicationContext setupServer() { + return TestWebfluxSpringBootApp.start(port, CONTEXT_PATH); + } + + @Override + public void stopServer(ConfigurableApplicationContext applicationContext) { + applicationContext.close(); + } + + @Override + protected void configure(HttpServerTestOptions options) { + options.setContextPath(CONTEXT_PATH); + options.setTestPathParam(true); + options.setExpectedException(new RuntimeException(ServerEndpoint.EXCEPTION.getBody())); + + options.setExpectedHttpRoute( + (endpoint, method) -> { + if (endpoint == ServerEndpoint.PATH_PARAM) { + return CONTEXT_PATH + "/path/{id}/param"; + } + return expectedHttpRoute(endpoint, method); + }); + + options.disableTestNonStandardHttpMethod(); + } + + @Test + void noMono() { + ServerEndpoint endpoint = new ServerEndpoint("NO_MONO", "no-mono", 200, "success"); + String method = "GET"; + AggregatedHttpRequest request = request(endpoint, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody()); + + assertTheTraces(1, null, null, null, method, endpoint); + } +} diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java new file mode 100644 index 000000000000..77afcf9881c0 --- /dev/null +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java @@ -0,0 +1,139 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webflux.v5_3; + +import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; +import static java.util.Collections.singletonList; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import java.net.URI; +import java.util.Properties; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.server.WebFilter; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@SpringBootApplication +class TestWebfluxSpringBootApp { + + static ConfigurableApplicationContext start(int port, String contextPath) { + Properties props = new Properties(); + props.put("server.port", port); + props.put("spring.webflux.base-path", contextPath); + + SpringApplication app = new SpringApplication(TestWebfluxSpringBootApp.class); + app.setDefaultProperties(props); + return app.run(); + } + + @Bean + WebFilter telemetryFilter() { + return SpringWebfluxServerTelemetry.builder(GlobalOpenTelemetry.get()) + .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + .build() + .createWebFilterAndRegisterReactorHook(); + } + + @Controller + static class TestController { + + @RequestMapping("/success") + @ResponseBody + Flux success() { + return Flux.defer(() -> Flux.just(controller(SUCCESS, SUCCESS::getBody))); + } + + @RequestMapping("/no-mono") + @ResponseBody + String noMono() { + return controller(SUCCESS, SUCCESS::getBody); + } + + @RequestMapping("/query") + @ResponseBody + Mono query_param(@RequestParam("some") String param) { + return Mono.just(controller(QUERY_PARAM, () -> "some=" + param)); + } + + @RequestMapping("/redirect") + @ResponseBody + Mono redirect(ServerHttpResponse response) { + response.setStatusCode(HttpStatus.FOUND); + response.getHeaders().setLocation(URI.create("/redirected")); + return controller(REDIRECT, response::setComplete); + } + + @RequestMapping("/error-status") + Mono> error() { + return Mono.just( + controller( + ERROR, + () -> new ResponseEntity<>(ERROR.getBody(), HttpStatus.valueOf(ERROR.getStatus())))); + } + + @RequestMapping("/exception") + Flux> exception() throws Exception { + return Flux.just( + controller( + EXCEPTION, + () -> { + throw new RuntimeException(EXCEPTION.getBody()); + })); + } + + @RequestMapping("/captureHeaders") + Mono> capture_headers( + @RequestHeader("X-Test-Request") String testRequestHeader) { + return Mono.just( + controller( + CAPTURE_HEADERS, + () -> + ResponseEntity.ok() + .header("X-Test-Response", testRequestHeader) + .body(CAPTURE_HEADERS.getBody()))); + } + + @RequestMapping("/path/{id}/param") + @ResponseBody + Mono path_param(@PathVariable("id") int id) { + return Mono.just(controller(PATH_PARAM, () -> String.valueOf(id))); + } + + @RequestMapping("/child") + @ResponseBody + Mono indexed_child(@RequestParam("id") String id) { + return Mono.just( + controller( + INDEXED_CHILD, + () -> { + INDEXED_CHILD.collectSpanAttributes(name -> name.equals("id") ? id : null); + return INDEXED_CHILD.getBody(); + })); + } + } +} From 3e42d983e623881e43a0ba8da176d4b62b890312 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 08:53:59 -0800 Subject: [PATCH 08/12] test deprecated classes --- .../SpringWebfluxClientInstrumentationOldTest.java | 13 +++++++------ .../SpringWebfluxServerInstrumentationOldTest.java | 4 ++-- .../webflux/v5_3/TestWebfluxSpringBootOldApp.java | 12 +++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java index e8980ef3d9fb..82e9b968981c 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java @@ -13,7 +13,8 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.web.reactive.function.client.WebClient; -class SpringWebfluxClientInstrumentationTest +@SuppressWarnings("deprecation") +class SpringWebfluxClientInstrumentationOldTest extends AbstractSpringWebfluxClientInstrumentationTest { @RegisterExtension @@ -21,13 +22,13 @@ class SpringWebfluxClientInstrumentationTest @Override protected WebClient.Builder instrument(WebClient.Builder builder) { - SpringWebfluxClientTelemetry instrumentation = - SpringWebfluxClientTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedRequestHeaders( + SpringWebfluxTelemetry instrumentation = + SpringWebfluxTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedClientRequestHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) - .setCapturedResponseHeaders( + .setCapturedClientResponseHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) .build(); - return builder.filters(instrumentation::addTracingFilter); + return builder.filters(instrumentation::addClientTracingFilter); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java index 54a71116a581..16508e938e1d 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.ConfigurableApplicationContext; -public final class SpringWebfluxServerInstrumentationTest +public final class SpringWebfluxServerInstrumentationOldTest extends AbstractHttpServerTest { private static final String CONTEXT_PATH = "/test"; @@ -29,7 +29,7 @@ public final class SpringWebfluxServerInstrumentationTest @Override protected ConfigurableApplicationContext setupServer() { - return TestWebfluxSpringBootApp.start(port, CONTEXT_PATH); + return TestWebfluxSpringBootOldApp.start(port, CONTEXT_PATH); } @Override diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java index 77afcf9881c0..f9244f430fb4 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java @@ -37,24 +37,26 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +@SuppressWarnings("deprecation") @SpringBootApplication -class TestWebfluxSpringBootApp { +class TestWebfluxSpringBootOldApp { static ConfigurableApplicationContext start(int port, String contextPath) { Properties props = new Properties(); props.put("server.port", port); props.put("spring.webflux.base-path", contextPath); - SpringApplication app = new SpringApplication(TestWebfluxSpringBootApp.class); + SpringApplication app = new SpringApplication(TestWebfluxSpringBootOldApp.class); app.setDefaultProperties(props); return app.run(); } @Bean WebFilter telemetryFilter() { - return SpringWebfluxServerTelemetry.builder(GlobalOpenTelemetry.get()) - .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + return SpringWebfluxTelemetry.builder(GlobalOpenTelemetry.get()) + .setCapturedClientRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedClientResponseHeaders( + singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build() .createWebFilterAndRegisterReactorHook(); } From 7c6d14b774ba00493ac5fa3de8d9f43122066b86 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 08:58:05 -0800 Subject: [PATCH 09/12] test deprecated classes --- .../webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java | 2 +- .../webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java | 1 + .../spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java index 82e9b968981c..18b038d4265a 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.web.reactive.function.client.WebClient; -@SuppressWarnings("deprecation") +@SuppressWarnings("deprecation") // testing deprecated API class SpringWebfluxClientInstrumentationOldTest extends AbstractSpringWebfluxClientInstrumentationTest { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java index 16508e938e1d..79e3cd3d1650 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.ConfigurableApplicationContext; +@SuppressWarnings("deprecation") // testing deprecated API public final class SpringWebfluxServerInstrumentationOldTest extends AbstractHttpServerTest { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java index f9244f430fb4..6fb149aedeb1 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java @@ -37,7 +37,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -@SuppressWarnings("deprecation") +@Deprecated @SpringBootApplication class TestWebfluxSpringBootOldApp { From af10a0b45ac47ced514fa384fb1d273530bca94d Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 09:46:20 -0800 Subject: [PATCH 10/12] test deprecated classes --- .../v5_3/SpringWebfluxClientInstrumentationOldTest.java | 7 ++++--- .../v5_3/SpringWebfluxServerInstrumentationOldTest.java | 2 +- .../{ => old}/v5_3/TestWebfluxSpringBootOldApp.java | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) rename instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/{ => old}/v5_3/SpringWebfluxClientInstrumentationOldTest.java (81%) rename instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/{ => old}/v5_3/SpringWebfluxServerInstrumentationOldTest.java (97%) rename instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/{ => old}/v5_3/TestWebfluxSpringBootOldApp.java (96%) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxClientInstrumentationOldTest.java similarity index 81% rename from instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxClientInstrumentationOldTest.java index 18b038d4265a..3b346b42176d 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxClientInstrumentationOldTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.spring.webflux.v5_3; +package io.opentelemetry.instrumentation.spring.webflux.old.v5_3; import io.opentelemetry.instrumentation.spring.webflux.client.AbstractSpringWebfluxClientInstrumentationTest; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -22,8 +22,9 @@ class SpringWebfluxClientInstrumentationOldTest @Override protected WebClient.Builder instrument(WebClient.Builder builder) { - SpringWebfluxTelemetry instrumentation = - SpringWebfluxTelemetry.builder(testing.getOpenTelemetry()) + io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry instrumentation = + io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry.builder( + testing.getOpenTelemetry()) .setCapturedClientRequestHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) .setCapturedClientResponseHeaders( diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxServerInstrumentationOldTest.java similarity index 97% rename from instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxServerInstrumentationOldTest.java index 79e3cd3d1650..c5fb0b745e83 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationOldTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/SpringWebfluxServerInstrumentationOldTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.spring.webflux.v5_3; +package io.opentelemetry.instrumentation.spring.webflux.old.v5_3; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; import static org.assertj.core.api.Assertions.assertThat; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java similarity index 96% rename from instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java index 6fb149aedeb1..3126c9e89d6b 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/TestWebfluxSpringBootOldApp.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.spring.webflux.v5_3; +package io.opentelemetry.instrumentation.spring.webflux.old.v5_3; import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS; @@ -53,7 +53,8 @@ static ConfigurableApplicationContext start(int port, String contextPath) { @Bean WebFilter telemetryFilter() { - return SpringWebfluxTelemetry.builder(GlobalOpenTelemetry.get()) + return io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry.builder( + GlobalOpenTelemetry.get()) .setCapturedClientRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) .setCapturedClientResponseHeaders( singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) From 4e2bc5b56377ee06f1cfadd49d34ce843d76c1c3 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 09:52:16 -0800 Subject: [PATCH 11/12] fix --- .../spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java index 3126c9e89d6b..df8031e6d17c 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/old/v5_3/TestWebfluxSpringBootOldApp.java @@ -55,8 +55,8 @@ static ConfigurableApplicationContext start(int port, String contextPath) { WebFilter telemetryFilter() { return io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry.builder( GlobalOpenTelemetry.get()) - .setCapturedClientRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedClientResponseHeaders( + .setCapturedServerRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedServerResponseHeaders( singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build() .createWebFilterAndRegisterReactorHook(); From e3fd1903a8161132fdf53d261c26452333d34e7e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 10:13:35 -0800 Subject: [PATCH 12/12] Update docs and one more rename --- .../webflux/WebClientBeanPostProcessor.java | 2 +- .../spring-webflux-5.3/library/README.md | 10 ++++++---- .../webflux/v5_3/SpringWebfluxClientTelemetry.java | 2 +- .../spring/webflux/v5_3/SpringWebfluxTelemetry.java | 2 +- .../v5_3/SpringWebfluxClientInstrumentationTest.java | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java index 22d06fe358c3..13a74048d3eb 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java @@ -66,6 +66,6 @@ private WebClient.Builder wrapBuilder(WebClient.Builder webClientBuilder) { SpringWebfluxClientTelemetry instrumentation = getWebfluxClientTelemetry( openTelemetryProvider.getObject(), configPropertiesProvider.getObject()); - return webClientBuilder.filters(instrumentation::addTracingFilter); + return webClientBuilder.filters(instrumentation::addFilter); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/README.md b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/README.md index a3c7f07aff7c..c02da7e3382a 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/README.md +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/README.md @@ -9,6 +9,7 @@ For this instrumentation, the minimum supported version of Spring Webflux is 5.3 For Maven, add to your `pom.xml`: ```xml + io.opentelemetry.instrumentation @@ -59,23 +60,24 @@ import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemet @Configuration public class WebClientConfig { - private final SpringWebfluxTelemetry webfluxTelemetry; + private final SpringWebfluxClientTelemetry webfluxClientTelemetry; + private final SpringWebfluxServerTelemetry webfluxServerTelemetry; public WebClientConfig(OpenTelemetry openTelemetry) { - this.webfluxTelemetry = SpringWebfluxTelemetry.builder(openTelemetry).build(); + this.webfluxClientTelemetry = SpringWebfluxClientTelemetry.builder(openTelemetry).build(); } // Adds instrumentation to WebClients @Bean public WebClient.Builder webClient() { WebClient webClient = WebClient.create(); - return webClient.mutate().filters(webfluxTelemetry::addClientTracingFilter); + return webClient.mutate().filters(webfluxClientTelemetry::addFilter); } // Adds instrumentation to Webflux server @Bean public WebFilter webFilter() { - return webfluxTelemetry.createWebFilterAndRegisterReactorHook(); + return webfluxServerTelemetry.createWebFilterAndRegisterReactorHook(); } } ``` diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java index 94139e19949e..75bb07ce6f6a 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java @@ -43,7 +43,7 @@ public static SpringWebfluxClientTelemetryBuilder builder(OpenTelemetry openTele this.propagators = propagators; } - public void addTracingFilter(List exchangeFilterFunctions) { + public void addFilter(List exchangeFilterFunctions) { for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { if (filterFunction instanceof WebClientTracingFilter) { return; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java index 622b671fb0b9..eb534f4962c8 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetry.java @@ -65,7 +65,7 @@ public static SpringWebfluxTelemetryBuilder builder(OpenTelemetry openTelemetry) } /** - * @deprecated Use {@link SpringWebfluxClientTelemetry#addTracingFilter(List)} instead. + * @deprecated Use {@link SpringWebfluxClientTelemetry#addFilter(List)} instead. */ @Deprecated public void addClientTracingFilter(List exchangeFilterFunctions) { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java index e8980ef3d9fb..723c4fe63505 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientInstrumentationTest.java @@ -28,6 +28,6 @@ protected WebClient.Builder instrument(WebClient.Builder builder) { .setCapturedResponseHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) .build(); - return builder.filters(instrumentation::addTracingFilter); + return builder.filters(instrumentation::addFilter); } }