elixir_agent icon indicating copy to clipboard operation
elixir_agent copied to clipboard

Add HTTPoison as optional dependency

Open andrewhr opened this issue 3 years ago • 3 comments

We have a few libraries wrapping HTTPoison that optionally instrument if NewRelic is present during compilation. Due the lack of this optional dependency here, the compilation process is not deterministic and may end up with cases where both libraries are included (our wrapper and NewRelic) and still have no instrumentation.

andrewhr avatar May 04 '21 14:05 andrewhr

Mind sharing a snippet of code that demonstrates how you are optionally instrumenting?

binaryseed avatar May 06 '21 19:05 binaryseed

Would you mind sharing an example of how you are instrumenting so I can think about this one?

binaryseed avatar Jun 15 '21 00:06 binaryseed

Hey @binaryseed, sorry as I don't have access to the code anymore.

The problem arise from a scenario like that:

  • app -> client_lib -> (optional) new_relic_agent
  • app -> client_lib -> httpoison
  • app -> new_relic_agent

Inside the client_lib there was some flavour of conditional compilation, like Code.ensure_loaded?(NewRelic.Instrumented.HTTPoison), to include the proper module for Distributed Tracing headers. This conditional compilation exists because not all services use NewRelic.

AFAICT the order of compilation is not guaranteed and I assume happens to be alphabetical so httpoison often compiles before in most cases. But in case like the above, assuming client_lib compiles after new_relic_agent that means when the agent will not be able to see httpoison yet and so this module doesn't exists. Which leads client_lib's own conditional to break as well.

I that case we had a "silent failure", just missing metrics until we realised what happened. I think if wasn't about our layer of conditional compilation, what we may had instead was a broken build.

The optional dependency seems in line with the approach taken by other instrumented third-parties, that's why I've reached for that.

PS: sorry for the long delay to reply 🙇

andrewhr avatar Aug 27 '21 16:08 andrewhr

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 02 '23 20:05 CLAassistant