-
Notifications
You must be signed in to change notification settings - Fork 324
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
urlconnection plugin: HttpURLConnection exceptions are captured also handled by the application. #2976
Comments
I tried same example with OTEL agent, there it shows the span itself as failure, but does not capture it as error, meaning http://localhost:5601/app/apm/services/App/errors being empty. So this describes expected behaviour best i guess. And i guess the "magic" lies in here https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionInstrumentation.java#L126
Sidenote: due to elastic/apm-data#12 we can't really switch to OTEL. |
This is an enhancement request to get similar behaviour to otel agent. We'd need to add an option for this to maintain backward compatibility and not break existing behaviour, but it seems not a lot of work. I've raised it for consideration to include in upcoming work |
@jackshirazi is it really enhancement only? Cause the situation, that an exception which is handled being still captured as an error to APM sounds not right, or does it? Maybe i am missing some point here. And i fear there could be more such situations in other plugins (as mentioned we phase one in aws-sdk as well) if the underlying implementation is throwing at a lower level and handling at an upper one and the instrumentation is in-between. But thanks for considering! |
The way I see it, if an implementation is throwing an exception, that's an error worth capturing. If there should be no error, there should be no exception. The dev can choose a different implementation - or register a bug with the 3rd party if the exception is incorrectly thrown. To have the APM decide one exception is an error but another isn't, is not generally possible. As for exceptions that are handled, the agent can only really instrument the implementation and not the code using that implementation. Going up the stack above the implementation to see what happens to the exception would be a huge overhead, and even harder, where do we decide to stop? All exceptions are handled at some point (or the application terminates). The OTel instrumentation you pointed at doesn't look to see if you've handled the exception, it's just an opinionated view that these exceptions are not worthy of being reported because other clients don't throw exceptions in that state. I can guarantee more than one application is doing the opposite and explicitly throwing an exception for 4xx/5xx codes where the http client doesn't. Finally, it's generally not recommended to use exceptions as a normal code path instead of an exceptional code path. So it's better to see when these exceptions are being generated. This is particularly the case for "shift-left" moves when you want to see what exceptions - including the ones that the application is handling - are generated so that you can decide how to make the application more resilient not just by handling exceptions but more importantly by changing things so that fewer are generated. I'm not stuck on this being an enhancement, but I don't see anything convincing me it's a bug |
Yep, i totally agree to these.
In that case it is hard, because so many libraries rely on With the HttpURLConnection the problem is: It is part of JDK, so not really sth. we can solve easily. The catch is already done inside JDK, that's why the called
I guess/think that, that is the reason why OTel choose the way of just ignoring it. Anyway, thanks for putting it as a candidate, appreciate that. |
If you really want a quick fix, you can instrument HttpURLConnection yourself, our community plugin makes that very easy to plugin to the agent (examples) |
Thanks for the hint, i'll have a look at that. |
To me it would feel most natural to only collect exceptions as error-documents if the exception makes it to the user and is not catched within the library we instrument. ( So because in this case the exception is an implementation detail of how If users want statistics about outoing request success / failure, they should rather look at the |
Extending on what @JonasKunz says above, we decided that the best approach would be to leave the current instrumentation for We think this may be a better approach because Does this sound reasonable? |
@eyalkoren actually when i did this PR, i was really thinking similar thing "what if someone calls But i totally get the point. I haven't checked so far, if I can checkout during next weekend if i can provide an implementation based on what you described. |
@eyalkoren So it seems that |
Describe the bug
Also the application handles all exceptions, especially expected ones the agent is reporting them to APM.
Steps to reproduce
Simple Spring Boot Web application
(Using Servlet with
RequestMapping
is just used to trigger the code inside a Spring Boot application).gives following console output
But the agent runs into https://github.com/elastic/apm-agent-java/blob/main/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java#L132 and reports the exception to APM
Different example using an url which response with 401, results into an
java.io.IOException
to be reported to APM, alsoExpected behavior
Since everything runs as expected and exceptions are handled, there shouldn't be any exception reported towards APM (which as follow up results in an alert, if someone is creating alerts based on occurring exceptions)
Debug logs
Log for the 404 example.
reproducer.log
Other remarks
We have observed same behaviour with AWS SDK S3 instrumentation, also there exceptions are captured also handled later on. Which means we have detected errors in APM, also the code handled and just works fine.
The text was updated successfully, but these errors were encountered: