elixir_agent
elixir_agent copied to clipboard
@trace attribute rewriting ignored cons arguments
Describe the bug
When adding @trace
to a function with an ignored list tail the macro creates an improper list with :__ignored__
as the tail instead of creating an ignored tail variable.
Below is an example module that produces the issue
defmodule Test do
use NewRelic.Tracer
@trace :example
def example([a | _ignored]) do
IO.inspect([a])
end
This code will raise warnings in dialyzer which say that the list is improper
And then below I logged out what the Tracer build_call_args/1 returns with and without the rewrite_call_term postwalk
with trace
"[[a | :__ignored__]]"
without trace
"[[a | _ignored]]"
Environment
- Elixir & Erlang version (
elixir -v
): Elixir 1.12.1 (compiled with Erlang/OTP 22) - Agent version (
mix deps | grep new_relic_agent
): 1.27.4 - macOS 11.6
This one is interesting, we need to "re write" the arguments of the function so we can log the function call itself. The :__ignored__
atom is stuck in there to avoid compiler warnings
The code is here:
- https://github.com/newrelic/elixir_agent/blob/master/lib/new_relic/tracer/macro.ex#L251 Tests are here:
- https://github.com/newrelic/elixir_agent/blob/master/test/tracer_macro_test.exs#L18
I'm not sure what to re-write it to here, but it should be possible to craft a test for this, detect the situation & do something else.