Skip to content
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

Record exception for async servlet invocations #4677

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Nov 19, 2021

Resolves #807 this should be the last remaining instrumentation in that issue.

Comment on lines 161 to 162
// we expect this request to fail with http 500 but is succeeds with http 200
// when using -PtestLatestDeps=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do u know if this is a limitation of jetty, our instrumentation, or our tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard to say. My guess is that our test is weird and could very well depend on unspecified behaviour. Test first completes an AsyncContext and then lets exception propagate out of servlet. It might be better to not complete AsyncContext and rely on timeout (if AsyncContext isn't completed container will close it with timeout). In that case the behaviour should be better defined, but timeout has its own issues. There is always the problem that we'd need to make the timeout as short as possible to not waste time but still have it long enough so that test doesn't timeout before the exception is thrown even when running under load.
The tests that are currently failing also exhibit weirdness, apparently on tomcat10 exception test can break the subsequent test.

Comment on lines +38 to +39
Throwable throwable = servletHelper.getAsyncException(requestContext.request());
instrumenter.end(context, requestContext, responseContext, throwable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does an exception thrown from a Runnable executed under AsyncContext.start(Runnable) always lead to servlet failure?

Copy link
Contributor Author

@laurit laurit Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. If the response has already been sent then exception can not turn it back. This behaviour is the same for regular servlets. So it is possible to have requests that were ok from http client's perspective, but failed (got an exception) from server's perspective.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point 👍

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

throw new ServletException(endpoint.body)
}
}
} finally {
// complete at the end so the server span will end after the controller span
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@trask
Copy link
Member

trask commented Nov 22, 2021

💯

@trask trask merged commit c53c8a0 into open-telemetry:main Nov 22, 2021
@laurit laurit deleted the servlet-async-exception branch November 22, 2021 20:17
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Record exception for asyn servlet invocations

* add back accidentally commented out line

* rearrange test so that it passes on both jetty and tomcat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Certain instrumentation does not record exception in many tests
3 participants