Fix Spring filter instrumentation edge case (DataDog/dd-trace-java#1700)
MODIFY
instrumentation/spring/spring-webmvc-3.1/spring-webmvc-3.1-auto/src/main/java/io/opentelemetry/instrumentation/auto/springwebmvc/WebApplicationContextInstrumentation.java
instrumentation/spring/spring-webmvc-3.1/spring-webmvc-3.1-auto/src/main/java/io/opentelemetry/instrumentation/auto/springwebmvc/WebApplicationContextInstrumentation.java
@@ -34,6 +34,10 @@ import net.bytebuddy.matcher.ElementMatcher;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+/**
+ * This instrumentation adds the HandlerMappingResourceNameFilter definition to the spring context
+ * When the context is created, the filter will be added to the beginning of the filter chain
+ */
@AutoService(Instrumenter.class)
public class WebApplicationContextInstrumentation extends Instrumenter.Default {
public WebApplicationContextInstrumentation() {

MODIFY
instrumentation/spring/spring-webmvc-3.1/spring-webmvc-3.1-auto/src/test/groovy/test/filter/TestController.groovy
instrumentation/spring/spring-webmvc-3.1/spring-webmvc-3.1-auto/src/test/groovy/test/filter/TestController.groovy
package test.filter
+import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.ExceptionHandler
@@ -25,45 +26,49 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.view.RedirectView
+/**
+ * None of the methods in this controller should be called because they are intercepted
+ * by the filter
+ */
@Controller
class TestController {
@RequestMapping("/success")
@ResponseBody
String success() {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@RequestMapping("/query")
@ResponseBody
String query_param(@RequestParam("some") String param) {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@RequestMapping("/path/{id}/param")
@ResponseBody
String path_param(@PathVariable Integer id) {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@RequestMapping("/redirect")
@ResponseBody
RedirectView redirect() {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@RequestMapping("/error-status")
ResponseEntity error() {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@RequestMapping("/exception")
ResponseEntity exception() {
- // stub to test that route is captured when intercepted by filter
+ throw new Exception("This should not be called")
}
@ExceptionHandler
ResponseEntity handleException(Throwable throwable) {
- // stub to test that route is captured when intercepted by filter
+ new ResponseEntity(throwable.message, HttpStatus.INTERNAL_SERVER_ERROR)
}
}

Fix Spring filter instrumentation edge case (DataDog/dd-trace-java#1700)