ForzaElixir / rollbax

Exception tracking and logging from Elixir to Rollbar
https://hexdocs.pm/rollbax
ISC License
243 stars 52 forks source link

Integrating with Phoenix #89

Closed tfwright closed 6 years ago

tfwright commented 6 years ago

Hi,

Thanks for creating this. I am trying to use it in Phoenix app. I added the config, and following the instructions here I added use Plug.ErrorHandler and the following function to lib/myapp_web/router.ex:

  defp handle_errors(conn, %{kind: kind, reason: reason, stack: stacktrace}) do
    Rollbax.report(kind, reason, stacktrace)
  end

To test, I added a raise in a controller action and when I access that action I see the "Internal server error" message. However the error does not get reported to rollbar. I see this in the server logs:

[error] GenServer Rollbax.Client terminating
** (UndefinedFunctionError) function Jason.encode_to_iodata/1 is undefined (module Jason is not available)
 Jason.encode_to_iodata(%{"access_token" .....[redact]
 (rollbax) lib/rollbax/client.ex:70: Rollbax.Client.handle_cast/2
(stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:686: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

Any guidance would be appreciated. Thanks.

tfwright commented 6 years ago

I fixed this by added {:jason, "~> 1.0"} to my deps.

whatyouhide commented 6 years ago

How are you depending on Rollbax? Jason is a Rollbax dependency so it should be fetched when you fetch Rollbax 🤔

tfwright commented 6 years ago

I added {:rollbax, "~> 0.9.0"}, to the deps function in mix.exs. I thought I ran mix deps.get right after that, but maybe I didn't? But the error made it seem as if the Rollbax module had been loaded but not Jason...

whatyouhide commented 6 years ago

Yeah the issue definitely says that. Is there any chance you could quickly throw a repo together that reproduces this error in isolation? I'll investigate :)

whatyouhide commented 6 years ago

Ping @tfwright :)

tfwright commented 6 years ago

Yes I'm a bit busy atm but when I have a chance I can do that

whatyouhide commented 6 years ago

I suspect this is just a problem of dependencies not being fetched correctly or something like that. If the error persists even if you remove the :jason direct dependency, run rm -rf _build && mix deps.clean --all && mix deps.get, then please comment here as soon as you have an app that reproduces this and I'll be happy to take a look :) Thanks! 💟

tfwright commented 6 years ago

Definitely seems to have been user error. I removed jason from deps and ran the commands you specified and rollbax worked fine. Sorry for the noise!