-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Async Servlet span end logic to fix race condition on Undertow #2992
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a2dc390
Attach servlet async listener with asyncStart instrumentation
agoallikmaa 3f57b9a
Exclude Spring packages containing servlet request classes from globa…
agoallikmaa 0af651b
Exclude Tapestry HSR proxy with global ignore
agoallikmaa 308ff19
Improve comments.
agoallikmaa 26ce952
Fix for Liberty - request response when adding async listener
agoallikmaa a0377ee
Removed unused methods
agoallikmaa 4fafd7f
Explicit response to async listeners on all servlet engines
agoallikmaa b2552fa
Attach response to request on Jetty
agoallikmaa 287b0f2
Fix broken build due to rebase, improved a comment
agoallikmaa 995eba1
Address PR comments
agoallikmaa 512dc97
Added a comment.
agoallikmaa 763aef7
Addressed PR comments
agoallikmaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ava/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3AsyncStartAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import static io.opentelemetry.instrumentation.servlet.v3_0.Servlet3HttpServerTracer.tracer; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap; | ||
import javax.servlet.AsyncContext; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.http.HttpServletRequest; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
public class Servlet3AsyncStartAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void startAsyncEnter() { | ||
// This allows to detect the outermost invocation of startAsync in method exit | ||
trask marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CallDepthThreadLocalMap.incrementCallDepth(AsyncContext.class); | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void startAsyncExit(@Advice.This ServletRequest servletRequest) { | ||
int callDepth = CallDepthThreadLocalMap.decrementCallDepth(AsyncContext.class); | ||
|
||
if (callDepth != 0) { | ||
// This is not the outermost invocation, ignore. | ||
return; | ||
} | ||
|
||
if (servletRequest instanceof HttpServletRequest) { | ||
HttpServletRequest request = (HttpServletRequest) servletRequest; | ||
|
||
if (!tracer().isAsyncListenerAttached(request)) { | ||
tracer().attachAsyncListener(request); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
...java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/TagSettingAsyncListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add calls to
setAsyncListenerResponse
in each app server instrumentation, or can we do it once in servlet instrumentation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since it is possible for requests to be handled entirely within app server handlers without servlet advices ever triggering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can those requests have servlet async listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jetty handlers and Tomcat valves both expose the
ServletRequest
and are allowed to generate the response without a servlet ever being invoked. I have not tested usingstartAsync
in them, but the documentation does not say that either of them would only support synchronous responses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add comments to the code explaining this? otherwise worried these lines could be removed thinking they aren't really needed, and I don't think we have any tests that it would break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added those comments for all the appservers.