From 63468157fc58b2178db9ff5ef299723d56b87651 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Fri, 24 Nov 2023 22:07:48 +0100 Subject: [PATCH] Fix latest dep tests after the recent Spring release (#9947) --- .../javaagent/build.gradle.kts | 4 ++ .../v5_0/ApacheHttpClientTest.java | 5 +++ .../javaagent/build.gradle.kts | 21 ++++------ .../testing/build.gradle.kts | 4 ++ .../v5_0/server/SpringWebfluxTest.java | 38 +++++++++++-------- .../ControllerSpringWebFluxServerTest.java | 7 ++-- ...ayedControllerSpringWebFluxServerTest.java | 2 +- ...DelayedHandlerSpringWebFluxServerTest.java | 2 +- .../base/HandlerSpringWebFluxServerTest.java | 7 ++-- ...iateControllerSpringWebFluxServerTest.java | 2 +- ...mediateHandlerSpringWebFluxServerTest.java | 2 +- .../server/base/ServerTestController.java | 4 +- .../server/base/ServerTestRouteFactory.java | 4 +- .../server/base/SpringWebFluxServerTest.java | 2 +- .../v5_0}/server/base/package-info.java | 2 +- .../server/SpringWebFluxTestApplication.java | 5 +-- .../v5_3/TestWebfluxSpringBootApp.java | 23 +++++------ .../javaagent/build.gradle.kts | 2 + .../src/test/groovy/ServletFilterTest.groovy | 35 +++++++++++++++++ .../test/groovy/SpringBootBasedTest.groovy | 21 ++++++++++ .../CommonLibraryIgnoredTypesConfigurer.java | 25 ++++++++++++ 21 files changed, 156 insertions(+), 61 deletions(-) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/ControllerSpringWebFluxServerTest.java (91%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/DelayedControllerSpringWebFluxServerTest.java (95%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/DelayedHandlerSpringWebFluxServerTest.java (95%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/HandlerSpringWebFluxServerTest.java (91%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/ImmediateControllerSpringWebFluxServerTest.java (95%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/ImmediateHandlerSpringWebFluxServerTest.java (96%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/ServerTestController.java (95%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/ServerTestRouteFactory.java (95%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/SpringWebFluxServerTest.java (97%) rename instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0}/server/base/package-info.java (62%) create mode 100644 javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/CommonLibraryIgnoredTypesConfigurer.java diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts index f594bab91e72..db08d0675a96 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts @@ -15,6 +15,10 @@ dependencies { } tasks { + withType().configureEach { + systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) + } + val testStableSemconv by registering(Test::class) { jvmArgs("-Dotel.semconv-stability.opt-in=http") } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientTest.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientTest.java index cea57cc51900..2a7147537aa3 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientTest.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientTest.java @@ -202,6 +202,11 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { super.configure(optionsBuilder); // apparently apache http client does not report the 302 status code? optionsBuilder.setResponseCodeOnRedirectError(null); + + if (Boolean.getBoolean("testLatestDeps")) { + optionsBuilder.disableTestHttps(); + optionsBuilder.disableTestRemoteConnection(); + } } } diff --git a/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.0/javaagent/build.gradle.kts b/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.0/javaagent/build.gradle.kts index b6e0f261e88a..df17718e19ff 100644 --- a/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.0/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.0/javaagent/build.gradle.kts @@ -21,6 +21,9 @@ dependencies { testImplementation(project(":instrumentation:spring:spring-cloud-gateway:spring-cloud-gateway-common:testing")) testLibrary("org.springframework.boot:spring-boot-starter-test:2.0.0.RELEASE") + + latestDepTestLibrary("org.springframework.cloud:spring-cloud-starter-gateway:2.1.+") + latestDepTestLibrary("org.springframework.boot:spring-boot-starter-test:2.1.+") } tasks.withType().configureEach { @@ -33,19 +36,9 @@ tasks.withType().configureEach { systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) } -val latestDepTest = findProperty("testLatestDeps") as Boolean - -if (latestDepTest) { - // spring 6 requires java 17 - otelJava { - minJavaVersionSupported.set(JavaVersion.VERSION_17) - } -} else { - // spring 5 requires old logback (and therefore also old slf4j) - configurations.testRuntimeClasspath { - resolutionStrategy { - force("ch.qos.logback:logback-classic:1.2.11") - force("org.slf4j:slf4j-api:1.7.36") - } +configurations.testRuntimeClasspath { + resolutionStrategy { + force("ch.qos.logback:logback-classic:1.2.11") + force("org.slf4j:slf4j-api:1.7.36") } } diff --git a/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.2/testing/build.gradle.kts b/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.2/testing/build.gradle.kts index 28dadbb0416e..add9577e8be3 100644 --- a/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.2/testing/build.gradle.kts +++ b/instrumentation/spring/spring-cloud-gateway/spring-cloud-gateway-2.2/testing/build.gradle.kts @@ -13,6 +13,10 @@ dependencies { testLibrary("org.springframework.cloud:spring-cloud-starter-gateway:2.2.0.RELEASE") testLibrary("org.springframework.boot:spring-boot-starter-test:2.2.0.RELEASE") + + // spring-cloud-gateway hasn't yet updated to spring 6.2/boot 3.2 + latestDepTestLibrary("org.springframework.boot:spring-boot-starter-webflux:3.1.+") + latestDepTestLibrary("org.springframework.boot:spring-boot-starter-test:3.1.+") } tasks.withType().configureEach { diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java index 2cf40ededd1c..57c56683eb21 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java @@ -36,6 +36,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.sdk.testing.assertj.EventDataAssert; import io.opentelemetry.sdk.testing.assertj.TraceAssert; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.testing.internal.armeria.client.WebClient; @@ -484,28 +485,33 @@ void get404Test() { .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(0)) .hasStatus(StatusData.error()) - .hasEventsSatisfyingExactly( - event -> - event - .hasName(EXCEPTION_EVENT_NAME) - .hasAttributesSatisfyingExactly( - equalTo( - EXCEPTION_TYPE, - "org.springframework.web.server.ResponseStatusException"), - satisfies( - EXCEPTION_MESSAGE, - val -> - val.containsAnyOf( - "Response status 404", "404 NOT_FOUND")), - satisfies( - EXCEPTION_STACKTRACE, - val -> val.isInstanceOf(String.class)))) + .hasEventsSatisfyingExactly(SpringWebfluxTest::resource404Exception) .hasAttributesSatisfyingExactly( equalTo( stringKey("spring-webflux.handler.type"), "org.springframework.web.reactive.resource.ResourceWebHandler")))); } + private static void resource404Exception(EventDataAssert event) { + if (Boolean.getBoolean("testLatestDeps")) { + event + .hasName(EXCEPTION_EVENT_NAME) + .hasAttributesSatisfyingExactly( + equalTo( + EXCEPTION_TYPE, + "org.springframework.web.reactive.resource.NoResourceFoundException"), + satisfies(EXCEPTION_MESSAGE, val -> val.isInstanceOf(String.class)), + satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class))); + } else { + event + .hasName(EXCEPTION_EVENT_NAME) + .hasAttributesSatisfyingExactly( + equalTo(EXCEPTION_TYPE, "org.springframework.web.server.ResponseStatusException"), + equalTo(EXCEPTION_MESSAGE, "Response status 404"), + satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class))); + } + } + @Test void basicPostTest() { String echoString = "TEST"; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ControllerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java similarity index 91% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ControllerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java index 54bbe7360b1a..c3ac74a4af9f 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ControllerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; @@ -52,8 +52,9 @@ protected SpanDataAssert assertHandlerSpan( .hasAttributesSatisfyingExactly( equalTo( EXCEPTION_TYPE, - "org.springframework.web.server.ResponseStatusException"), - equalTo(EXCEPTION_MESSAGE, "404 NOT_FOUND"), + "org.springframework.web.reactive.resource.NoResourceFoundException"), + equalTo( + EXCEPTION_MESSAGE, "404 NOT_FOUND \"No static resource notFound.\""), satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); } else { span.hasEventsSatisfyingExactly( diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedControllerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedControllerSpringWebFluxServerTest.java similarity index 95% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedControllerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedControllerSpringWebFluxServerTest.java index 4237b4455fb5..1ef1302dca70 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedControllerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedControllerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.time.Duration; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedHandlerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedHandlerSpringWebFluxServerTest.java similarity index 95% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedHandlerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedHandlerSpringWebFluxServerTest.java index b889416e8c33..d513e13d18a0 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/DelayedHandlerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/DelayedHandlerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.time.Duration; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/HandlerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java similarity index 91% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/HandlerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java index 6f1837ebfe25..d33cb788e9c7 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/HandlerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; @@ -50,8 +50,9 @@ protected SpanDataAssert assertHandlerSpan( .hasAttributesSatisfyingExactly( equalTo( EXCEPTION_TYPE, - "org.springframework.web.server.ResponseStatusException"), - equalTo(EXCEPTION_MESSAGE, "404 NOT_FOUND"), + "org.springframework.web.reactive.resource.NoResourceFoundException"), + equalTo( + EXCEPTION_MESSAGE, "404 NOT_FOUND \"No static resource notFound.\""), satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); } else { span.hasEventsSatisfyingExactly( diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateControllerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateControllerSpringWebFluxServerTest.java similarity index 95% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateControllerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateControllerSpringWebFluxServerTest.java index 8327904044a2..ccdecadb5478 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateControllerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateControllerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.util.function.Supplier; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateHandlerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateHandlerSpringWebFluxServerTest.java similarity index 96% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateHandlerSpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateHandlerSpringWebFluxServerTest.java index 94d515e62e18..6e0dbc0e95fe 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ImmediateHandlerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ImmediateHandlerSpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeTrue; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestController.java similarity index 95% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestController.java index d8ab437ae9d5..812c976457c1 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestController.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; -import static server.base.SpringWebFluxServerTest.NESTED_PATH; +import static io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base.SpringWebFluxServerTest.NESTED_PATH; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.net.URI; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestRouteFactory.java similarity index 95% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestRouteFactory.java index b1742c4cfff4..7d91a7aa48b4 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ServerTestRouteFactory.java @@ -3,13 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; +import static io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base.SpringWebFluxServerTest.NESTED_PATH; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; import static org.springframework.web.reactive.function.server.RequestPredicates.path; import static org.springframework.web.reactive.function.server.RouterFunctions.nest; import static org.springframework.web.reactive.function.server.RouterFunctions.route; -import static server.base.SpringWebFluxServerTest.NESTED_PATH; import io.opentelemetry.api.trace.Span; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/SpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/SpringWebFluxServerTest.java similarity index 97% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/SpringWebFluxServerTest.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/SpringWebFluxServerTest.java index 9efe2589b978..c1403355d593 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/SpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/SpringWebFluxServerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/package-info.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/package-info.java similarity index 62% rename from instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/package-info.java rename to instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/package-info.java index 679f71c0a4af..f915cf01d493 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/base/package-info.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/package-info.java @@ -2,4 +2,4 @@ * The classes in this package are specific to tests that extend {@link * io.opentelemetry.instrumentation.test.base.HttpServerTest}. */ -package server.base; +package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/SpringWebFluxTestApplication.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/SpringWebFluxTestApplication.java index 401388e2345a..0151501226ed 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/SpringWebFluxTestApplication.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/server/SpringWebFluxTestApplication.java @@ -17,7 +17,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.BodyInserters; @@ -27,9 +26,7 @@ import reactor.core.publisher.Mono; @SpringBootApplication -@ComponentScan( - basePackages = {"server"}, - excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "server.base.*")) +@ComponentScan(basePackages = {"server"}) public class SpringWebFluxTestApplication { private static final Tracer tracer = GlobalOpenTelemetry.getTracer("test"); 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 5437f2e481f6..717bba794b1d 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 @@ -71,8 +71,8 @@ Flux success() { @RequestMapping("/query") @ResponseBody - String query_param(@RequestParam("some") String param) { - return controller(QUERY_PARAM, () -> "some=" + param); + Mono query_param(@RequestParam("some") String param) { + return Mono.just(controller(QUERY_PARAM, () -> "some=" + param)); } @RequestMapping("/redirect") @@ -102,20 +102,21 @@ Flux> exception() throws Exception { } @RequestMapping("/captureHeaders") - ResponseEntity capture_headers( + Mono> capture_headers( @RequestHeader("X-Test-Request") String testRequestHeader) { - return controller( - CAPTURE_HEADERS, - () -> - ResponseEntity.ok() - .header("X-Test-Response", testRequestHeader) - .body(CAPTURE_HEADERS.getBody())); + return Mono.just( + controller( + CAPTURE_HEADERS, + () -> + ResponseEntity.ok() + .header("X-Test-Response", testRequestHeader) + .body(CAPTURE_HEADERS.getBody()))); } @RequestMapping("/path/{id}/param") @ResponseBody - String path_param(@PathVariable("id") int id) { - return controller(PATH_PARAM, () -> String.valueOf(id)); + Mono path_param(@PathVariable("id") int id) { + return Mono.just(controller(PATH_PARAM, () -> String.valueOf(id))); } @RequestMapping("/child") diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/build.gradle.kts b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/build.gradle.kts index 9c4425b96814..f196226a3986 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/build.gradle.kts @@ -50,4 +50,6 @@ tasks.withType().configureEach { // required on jdk17 jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") + + systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy index 644a6a44d21c..42d94ca6ba6a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy @@ -4,6 +4,13 @@ */ import filter.AbstractServletFilterTest +import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.sdk.trace.data.SpanData + +import static io.opentelemetry.api.trace.SpanKind.INTERNAL class ServletFilterTest extends AbstractServletFilterTest { @@ -14,4 +21,32 @@ class ServletFilterTest extends AbstractServletFilterTest { Class filterConfigClass() { ServletFilterConfig } + + @Override + void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) { + if (Boolean.getBoolean("testLatestDeps") && endpoint == ServerEndpoint.NOT_FOUND) { + trace.span(index) { + name "ResourceHttpRequestHandler.handleRequest" + kind INTERNAL + childOf((SpanData) parent) + status StatusCode.ERROR + errorEventWithAnyMessage Class.forName("org.springframework.web.servlet.resource.NoResourceFoundException") + } + } else { + super.handlerSpan(trace, index, parent, method, endpoint) + } + } + + @Override + void responseSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) { + if (Boolean.getBoolean("testLatestDeps") && endpoint == ServerEndpoint.NOT_FOUND) { + trace.span(index) { + name ~/\.sendError$/ + kind SpanKind.INTERNAL + // not verifying the parent span, in the latest version the responseSpan is the child of the SERVER span, not the handler span + } + } else { + super.responseSpan(trace, index, parent, method, endpoint) + } + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy index 9b647b549687..a37e190e5194 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy @@ -4,10 +4,31 @@ */ import boot.AbstractSpringBootBasedTest +import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.sdk.trace.data.SpanData + +import static io.opentelemetry.api.trace.SpanKind.INTERNAL class SpringBootBasedTest extends AbstractSpringBootBasedTest { Class securityConfigClass() { SecurityConfig } + + @Override + void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) { + if (Boolean.getBoolean("testLatestDeps") && endpoint == ServerEndpoint.NOT_FOUND) { + trace.span(index) { + name "ResourceHttpRequestHandler.handleRequest" + kind INTERNAL + childOf((SpanData) parent) + status StatusCode.ERROR + errorEventWithAnyMessage Class.forName("org.springframework.web.servlet.resource.NoResourceFoundException") + } + } else { + super.handlerSpan(trace, index, parent, method, endpoint) + } + } } diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/CommonLibraryIgnoredTypesConfigurer.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/CommonLibraryIgnoredTypesConfigurer.java new file mode 100644 index 000000000000..1bcacdf2b816 --- /dev/null +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/CommonLibraryIgnoredTypesConfigurer.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.tooling.ignore; + +import com.google.auto.service.AutoService; +import io.opentelemetry.javaagent.extension.ignore.IgnoredTypesBuilder; +import io.opentelemetry.javaagent.extension.ignore.IgnoredTypesConfigurer; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; + +/** + * Unlike the {@link AdditionalLibraryIgnoredTypesConfigurer}, this one is applied to all tests. It + * should only contain classes that are included in the most commonly used libraries in test (e.g. + * Spring Boot). + */ +@AutoService(IgnoredTypesConfigurer.class) +public class CommonLibraryIgnoredTypesConfigurer implements IgnoredTypesConfigurer { + + @Override + public void configure(IgnoredTypesBuilder builder, ConfigProperties config) { + builder.ignoreClass("org.springframework.boot.autoconfigure.ssl.FileWatcher$WatcherThread"); + } +}