scoutapp / scout_apm_elixir

ScoutAPM Elixir Agent. Supports Phoenix and other frameworks.
https://scoutapm.com
Other
36 stars 20 forks source link

crash when logging Ecto transactions that rollback #89

Closed bobics closed 5 years ago

bobics commented 5 years ago

I'm seeing a crash with the Scout Ecto logger in my Elixir app. I'm guessing the Scout Elixir library isn't handling all types of DBConnection.LogEntry.result values. In this particular case, we're using Ecto.Multi with multiple changes which is wrapped in a transaction. That transaction is designed to rollback in some cases. We're using Ecto 2, and scout_apm_elixir 0.4.15. Here's the stack trace:

** (EXIT from #PID<0.3733.0>) an exception was raised:
         ** (ArgumentError) cannot convert the given list to a string.

     To be converted to a string, a list must contain only:

       * strings
       * integers representing Unicode codepoints
       * or a list containing one of these three elements

     Please check the given list or call inspect/1 to get the list representation, got:

     [:rollback, :release]

             (elixir) lib/list.ex:826: List.to_string/1
             (scout_apm) lib/scout_apm/instruments/ecto_logger.ex:60: ScoutApm.Instruments.EctoLogger.query_name_log_entry/1
             (scout_apm) lib/scout_apm/instruments/ecto_logger.ex:22: ScoutApm.Instruments.EctoLogger.log/1
             (db_connection) lib/db_connection.ex:1186: DBConnection.log/6
             (db_connection) lib/db_connection.ex:1167: DBConnection.transaction_log/1
             (db_connection) lib/db_connection.ex:799: DBConnection.transaction/3
             (ecto) lib/ecto/repo/queryable.ex:23: Ecto.Repo.Queryable.transaction/4

Which points to this line: https://github.com/scoutapp/scout_apm_elixir/blob/v0.14.5/lib/scout_apm/instruments/ecto_logger.ex#L60

bobics commented 5 years ago

FYI, I ended up hacking a fix on my end by changing:

"#{command}"

to:

"#{inspect(command)}"

in lib/scout_apm/instruments/ecto_logger.ex