EasyPost / easypost-java

EasyPost Shipping API Client Library for Java
https://easypost.com/docs/api
MIT License
54 stars 37 forks source link

[Feat]: Ability to extract metrics (for example for Spring based apps) easily by making sure the Requestor is pluggable #321

Closed nandorholozsnyak closed 3 months ago

nandorholozsnyak commented 3 months ago

Feature Request Is New

Description of the feature

Hello there,

I'm looking forward for a way to create metrics about the API calls towards to the EasyPost API.

With the SDK it seemed like we would be able to use the Request and Response hooks, but based on the codebase, response hooks are not initiated if the response contains any kind of error (more specifically if this is true:

if (rCode < HttpURLConnection.HTTP_OK || rCode >= HttpURLConnection.HTTP_MULT_CHOICE) {
    handleAPIError(rBody, rCode);
}

I tried to plug Micrometer a layer below into the com.easypost.http.Requestor#createEasyPostConnection method, but it is still not the best place, as we need a custom URLStreamHandler which still not the best solution. I like how it is almost fully dependency free, but at the same time it is a painpoint to use the low level HttpsURLConnection.

So my question is, what is the best way to capture the start and the end of any API call to have the response code, URL and basically everything that I would need for a standard http.client.requests metrics which includes these tags/labels (http_method, http_status_code, outcome,error,uri etc.).

nwithan8 commented 3 months ago

Hello, thanks for reaching out!

We can look into wiring up the response hooks to fire even if an HTTP error occurs, so you can capture and assess the response.

nandorholozsnyak commented 3 months ago

Hello, thanks for reaching out!

We can look into wiring up the response hooks to fire even if an HTTP error occurs, so you can capture and assess the response.

Hello there,

thank you for the quick answer, I could understand if it was made on purpose for not running those response hooks, but at the same time it could help us. If there are other integration/injection points to intercept these kind of data, I'm open for any of that.

nwithan8 commented 3 months ago

We have released an update that should allow the response hooks to fire even if there is an API error, available in v7.4.1

nandorholozsnyak commented 3 months ago

We have released an update that should allow the response hooks to fire even if there is an API error, available in v7.4.1

That was fast. Thank you.