Phillipp
Intercepting HTTPoison/hackney requests
Hey,
I am currently building an api gateway. That means it receives a request and makes one or more requests to other sources and returns a response.
Now I want to add metrics about the outgoing requests to my Prometheus metrics. Things like hostname, path, method and response code.
That way, I am very flexible and can derive stats for certain actions instead of creating specialized metrics for each individual action.
Is there an easy way to intercept all HTTPoison calls after they are made so I don’t need to add telemetry calls in every function that uses HTTPoison? I also would like to avoid creating a wrapper module for HTTPoison just for the metrics.
Most Liked
alvises
I don’t have an answer about catching the function calls but…To me the wrapper module is the way to go. It helps you to decouple your code from HTTPoison dependency itself, leaving you the freedom to change the HTTP library in the future if you want, without refactoring the whole code. It would also much easier to test your code. And obviously it makes easy to integrate telemetry.
Phillipp
I often see no point in wrapping certain things just because I could eventuell change the underlaying library or framework. Practically this never gets done, at least in my experience. I also kinda dislike redoing apis that already exist because one often ends up with a very limited api that needs to be expanded later on when one wants to use a different functionality from the underlaying library.
I wonder if it wouldn’t make more sense to integrate telemetry into HTTPoison itself. Maybe the maintainer is up to it.
EDIT: Already a topic https://github.com/edgurgel/httpoison/issues/383
alvises
to me, in general, it’s more about decoupling from third-party libraries rather than add functionalities. This helps me a lot in testing.








