From 26ff4a9090a87101a19785d737b8ea20595a2e5d Mon Sep 17 00:00:00 2001 From: Andrea Marziali Date: Tue, 26 Nov 2024 19:45:11 +0100 Subject: [PATCH] fix latest spring webmvc --- .../spring-webmvc-6.0/build.gradle | 2 +- .../spring-webmvc-6.0/gradle.lockfile | 2 +- .../boot/SpringBootBasedTest.groovy | 13 +++++++++ .../UrlHandlerMappingTest.groovy | 28 ++++++++++++------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/dd-java-agent/instrumentation/spring-webmvc-6.0/build.gradle b/dd-java-agent/instrumentation/spring-webmvc-6.0/build.gradle index 65762be0bb6..f37139560e6 100644 --- a/dd-java-agent/instrumentation/spring-webmvc-6.0/build.gradle +++ b/dd-java-agent/instrumentation/spring-webmvc-6.0/build.gradle @@ -49,7 +49,7 @@ dependencies { testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.0.0' testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '3.0.0' testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '3.0.0' - testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' + testImplementation group: 'com.google.code.gson', name: 'gson', version: '+' latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.+' latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '3.+' diff --git a/dd-java-agent/instrumentation/spring-webmvc-6.0/gradle.lockfile b/dd-java-agent/instrumentation/spring-webmvc-6.0/gradle.lockfile index 7fe17b4fca8..569459c6f0f 100644 --- a/dd-java-agent/instrumentation/spring-webmvc-6.0/gradle.lockfile +++ b/dd-java-agent/instrumentation/spring-webmvc-6.0/gradle.lockfile @@ -45,7 +45,7 @@ com.google.auto.service:auto-service-annotations:1.0-rc7=annotationProcessor,com com.google.auto.service:auto-service:1.0-rc7=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor com.google.auto:auto-common:0.10=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,compileClasspath,latestDepTestAnnotationProcessor,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,spotbugs,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath -com.google.code.gson:gson:2.10.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath +com.google.code.gson:gson:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath com.google.code.gson:gson:2.9.1=spotbugs com.google.errorprone:error_prone_annotations:2.2.0=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor com.google.guava:failureaccess:1.0.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor diff --git a/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/boot/SpringBootBasedTest.groovy b/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/boot/SpringBootBasedTest.groovy index a56022c05ee..d3b2c80236b 100644 --- a/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/boot/SpringBootBasedTest.groovy +++ b/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/boot/SpringBootBasedTest.groovy @@ -15,6 +15,7 @@ import datadog.trace.agent.test.base.HttpServer import datadog.trace.agent.test.base.HttpServerTest import datadog.trace.api.ConfigDefaults import datadog.trace.api.DDSpanTypes +import datadog.trace.api.DDTags import datadog.trace.api.iast.IastContext import datadog.trace.api.iast.InstrumentationBridge import datadog.trace.api.iast.SourceTypes @@ -152,6 +153,18 @@ class SpringBootBasedTest extends HttpServerTest true } + @Override + Map expectedExtraErrorInformation(ServerEndpoint endpoint) { + System.err.println("CALLED") + // latest DispatcherServlet throws if no handlers have been found + if (endpoint == NOT_FOUND && isLatestDepTest) { + return [(DDTags.ERROR_STACK): { String }, + (DDTags.ERROR_MSG) : {String}, + (DDTags.ERROR_TYPE) :{String}] + } + return super.expectedExtraErrorInformation(endpoint) + } + @Override Serializable expectedServerSpanRoute(ServerEndpoint endpoint) { switch (endpoint) { diff --git a/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/urlhandlermapping/UrlHandlerMappingTest.groovy b/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/urlhandlermapping/UrlHandlerMappingTest.groovy index 538baff4293..19fde0ed138 100644 --- a/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/urlhandlermapping/UrlHandlerMappingTest.groovy +++ b/dd-java-agent/instrumentation/spring-webmvc-6.0/src/test/groovy/datadog/trace/instrumentation/springweb6/urlhandlermapping/UrlHandlerMappingTest.groovy @@ -1,10 +1,17 @@ package datadog.trace.instrumentation.springweb6.urlhandlermapping +import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION +import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND +import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM +import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static java.util.Collections.singletonMap + import datadog.trace.agent.test.asserts.TraceAssert import datadog.trace.agent.test.base.HttpServer import datadog.trace.agent.test.base.HttpServerTest import datadog.trace.api.ConfigDefaults import datadog.trace.api.DDSpanTypes +import datadog.trace.api.DDTags import datadog.trace.api.iast.InstrumentationBridge import datadog.trace.api.iast.SourceTypes import datadog.trace.api.iast.propagation.PropagationModule @@ -19,13 +26,6 @@ import org.springframework.boot.SpringApplication import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext import org.springframework.context.ConfigurableApplicationContext -import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.LOGIN -import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS -import static java.util.Collections.singletonMap - /** * Test instrumentation of UriTemplateVariablesHandlerInterceptor * (used by AbstractUrlHandlerMapping). @@ -135,12 +135,20 @@ class UrlHandlerMappingTest extends HttpServerTest expectedExtraErrorInformation(ServerEndpoint endpoint) { + // latest DispatcherServlet throws if no handlers have been found + if (endpoint == NOT_FOUND && isLatestDepTest) { + return [(DDTags.ERROR_STACK): { String }, + (DDTags.ERROR_MSG): {String}, + (DDTags.ERROR_TYPE):{String}] + } + return super.expectedExtraErrorInformation(endpoint) + } + @Override Serializable expectedServerSpanRoute(ServerEndpoint endpoint) { switch (endpoint) { - case LOGIN: - case NOT_FOUND: - return null case PATH_PARAM: return testPathParam() default: