Skip to content

Commit 48ca19a

Browse files
committed
more attempts
1 parent f375b2c commit 48ca19a

File tree

5 files changed

+32
-106
lines changed

5 files changed

+32
-106
lines changed

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ dependencies {
3737
testLibrary("org.springframework.boot:spring-boot-starter-test:3.0.0")
3838
testLibrary("org.springframework.boot:spring-boot-starter-web:3.0.0")
3939
testLibrary("org.springframework.boot:spring-boot-starter-security:3.0.0")
40-
41-
// // tests don't work with spring boot 4 yet
42-
// latestDepTestLibrary("org.springframework.boot:spring-boot-starter-test:3.+") // documented limitation
43-
// latestDepTestLibrary("org.springframework.boot:spring-boot-starter-web:3.+") // documented limitation
44-
// latestDepTestLibrary("org.springframework.boot:spring-boot-starter-security:3.+") // documented limitation
4540
}
4641

4742
// spring 6 requires java 17

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/HandlerAdapterInstrumentation.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,31 @@ public static AdviceScope enter(HttpServletRequest request, Object handler) {
7373
}
7474

7575
Context parentContext = Context.current();
76-
// TODO: Handle async context propagation for DeferredResult
77-
// Context storedAsyncContext = WebAsyncManagerInstrumentation.getAsyncContext(request);
78-
// if (storedAsyncContext != null) {
79-
// parentContext = storedAsyncContext;
80-
// }
76+
77+
// During async redispatches (e.g., after DeferredResult completes), we want to use
78+
// the context stored in the request attribute (which includes async work spans)
79+
// instead of the current context. We detect async redispatches using the servlet
80+
// DispatcherType.
81+
if (request.getDispatcherType() == jakarta.servlet.DispatcherType.ASYNC) {
82+
Object storedContext =
83+
request.getAttribute(
84+
"io.opentelemetry.javaagent.instrumentation.servlet.ServletHelper.Context");
85+
if (storedContext instanceof Context context) {
86+
parentContext = context;
87+
// The stored context was created in a different thread/phase, so we need to
88+
// re-initialize the ServletContextPath for this request to ensure the span
89+
// name includes the correct context path.
90+
// parentContext =
91+
// io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath.init(
92+
// parentContext,
93+
// req -> {
94+
// String contextPath = req.getContextPath();
95+
// return (contextPath == null || contextPath.isEmpty()) ? null :
96+
// contextPath;
97+
// },
98+
// request);
99+
}
100+
}
81101

82102
// don't start a new top-level span
83103
if (!Span.fromContext(parentContext).getSpanContext().isValid()) {

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/SpringWebMvcInstrumentationModule.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public String getModuleGroup() {
5151

5252
@Override
5353
public List<TypeInstrumentation> typeInstrumentations() {
54-
return asList(
55-
new DispatcherServletInstrumentation(),
56-
new HandlerAdapterInstrumentation());
57-
// new WebAsyncManagerInstrumentation());
54+
return asList(new DispatcherServletInstrumentation(), new HandlerAdapterInstrumentation());
5855
}
5956

6057
@Override

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/WebAsyncManagerInstrumentation.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/filter/ServletFilterTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ protected Class<?> filterConfigClass() {
5050
protected ConfigurableApplicationContext setupServer() {
5151
SpringApplication app =
5252
new SpringApplication(FilteredAppConfig.class, securityConfigClass(), filterConfigClass());
53+
5354
app.setDefaultProperties(
54-
Map.of("server.port", port, "spring.web.error.include-message", "always"));
55+
Map.of(
56+
"server.port",
57+
port,
58+
testLatestDeps ? "spring.web.error.include-message" : "server.error.include-message",
59+
"always"));
5560
return app.run();
5661
}
5762

0 commit comments

Comments
 (0)