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 https://github.com/edgurgel/httpoison/issues/383

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.

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.

Phillipp

Phillipp

Ok, but do you wrap Ecto, Phoenix, or even Telemetry itself? At some point and for certain things it makes not much sense to wrap them.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement