Phillipp

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

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

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 Telemetry support · Issue #383 · edgurgel/httpoison · GitHub

alvises

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.

Last Post!

keathley

keathley

This doesn’t exactly answer your question but you might check out Tesla as an alternative to HTTPoison. It supports telemetry amongst other things and it’s a good model for building http clients.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement