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

Add trace log for HTTP error responses #5795

Merged
merged 4 commits into from
May 16, 2024

Conversation

optionsome
Copy link
Member

@optionsome optionsome commented Apr 8, 2024

Summary

Removes OtpHttpClient's own logger and passes in loggers from where it's used from. Adds a trace log for http responses in case there is an error response coming from an external API.

Issue

closes #5761

Unit tests

New tests will not be added.

Documentation

Not needed

Changelog

Not sure if needed

@optionsome optionsome requested a review from a team as a code owner April 8, 2024 12:43
@abyrd
Copy link
Member

abyrd commented Apr 9, 2024

Discussed in today's meeting: it's not clear how to proceed. The original concern that was voiced about logging here is that the HttpClient is a "framework class" that could be used in many different places throughout the project. Turning on trace-level logging could produce an overwhelming amount of messages that are not limited to the one usage site that one is trying to debug. The original implication was that framework-like classes should return enough information (or throw exceptions specific enough) so the caller can log errors in a more context-specific way. There were some reasons why this didn't work in this particular case: it would result in too much boilerplate logging calls and checked exception handling at every call site, and the return types would have to be overly complex or incur significant overhead for logging facilities that are rarely used. So the remaining solution was to pass the caller's logger into the framework's methods. However, this goes against most people's expectations when the loggers are assigned names that are the fully-qualified names of classes. We observed that it's common for Java library code (e.g. database or HTTP tooling) to emit its own debugging log messages using its own logger, and that the (sometimes surprisingly complex) Java logging world is apparently designed to work this way (each library calls a logging API which are all routed to the top level application's logging implementation). So what we are looking for is widespread Java conventions for debug and trace level logging within a library (or project-specific framework code) where logging messages can be filtered by call site or use case.

@optionsome
Copy link
Member Author

I've now done refactoring based on last weeks discussion but there are few classes I'm still slightly unhappy with as I've explained in #5795 (comment) .

Copy link

codecov bot commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 54.38596% with 52 lines in your changes are missing coverage. Please review.

Project coverage is 67.86%. Comparing base (0bed0f2) to head (2edd276).
Report is 90 commits behind head on dev-2.x.

❗ Current head 2edd276 differs from pull request most recent head fd8b26c. Consider uploading reports for the commit fd8b26c to get more accurate results

Files Patch % Lines
...rg/opentripplanner/framework/io/OtpHttpClient.java 15.78% 16 Missing ⚠️
...ipplanner/framework/io/JsonDataListDownloader.java 12.50% 7 Missing ⚠️
...tripplanner/framework/io/OtpHttpClientFactory.java 82.50% 7 Missing ⚠️
...ehicleparking/hslpark/HslFacilitiesDownloader.java 28.57% 5 Missing ⚠️
.../ext/vehicleparking/hslpark/HslHubsDownloader.java 28.57% 5 Missing ⚠️
...irectory/VehicleRentalServiceDirectoryFetcher.java 0.00% 3 Missing ⚠️
...er/ext/siri/updater/SiriETGooglePubsubUpdater.java 0.00% 2 Missing ⚠️
...t/siri/updater/azure/AbstractAzureSiriUpdater.java 0.00% 2 Missing ⚠️
...ner/datastore/https/HttpsDataSourceRepository.java 33.33% 2 Missing ⚠️
...entripplanner/ext/siri/updater/SiriHttpLoader.java 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #5795   +/-   ##
==========================================
  Coverage      67.85%   67.86%           
- Complexity     16546    16562   +16     
==========================================
  Files           1906     1909    +3     
  Lines          72291    72388   +97     
  Branches        7444     7446    +2     
==========================================
+ Hits           49055    49128   +73     
- Misses         20716    20739   +23     
- Partials        2520     2521    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@t2gran t2gran requested a review from vpaturet April 25, 2024 13:33
@t2gran t2gran added this to the 2.6 (next release) milestone Apr 25, 2024
@optionsome optionsome merged commit dac395d into opentripplanner:dev-2.x May 16, 2024
5 checks passed
@optionsome optionsome deleted the http-error-logging branch May 16, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to log response body of HTTP calls if there is an error
5 participants