Skip to content

Instantly share code, notes, and snippets.

@paulo-ferraz-oliveira
Last active July 12, 2023 08:31
Show Gist options
  • Save paulo-ferraz-oliveira/32931a4c19451294d3637ce9126f5b1d to your computer and use it in GitHub Desktop.
Save paulo-ferraz-oliveira/32931a4c19451294d3637ce9126f5b1d to your computer and use it in GitHub Desktop.
Shows an (Elixir) example of tracing HTTPoison's :request and extracting from the call and the return value, using Fred Hebert's recon

Tracing in Elixir with :recon, and formatter

I tend to not remember how this is done, so here goes, for easier copy-paste effect:

:recon_trace.calls(
  {_mod = HTTPoison, _fun = :request, fn ([_, _, _, _, _]) -> :return_trace end},
  _calls = 10,
  [scope: :local,
   formatter: fn (tuple) ->
     # this must return iodata()
     case tuple do
       {:trace, _pid, :call, {_mod, _fun, [_, url, _, _, _]}} ->
         IO.inspect({:call, url}, limit: :infinity)
       {:trace, _pid, :return_from, {_mod, _fun, _arity = 5}, {:ok, return_value}} ->
         IO.inspect({:return_from, return_value.body}, limit: :infinity)
       _other ->
         :ok
     end
     ""
   end]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment