Hello, possibly dumb question here. I’m deploying my phoenix app with a release. I’ve found that in production, for some (all?) errors, I don’t see a stack trace (or any detail at all) on stdout. I thought it might be a systemd problem, but it turns out that any time I run the app as a release, the stack trace is not printed, whereas in IEx on my local dev machine, it is.
To replicate the issue, I injected a BadMatch error in one of my templates. Running it with iex -S mix phx.server
and exercising the “bug” on my dev machine (Fedora FWIW), I get the following console output:
15:26:52.021 request_id=Fv2qoZqEAPV4uO4AAADi [info] Sent 500 in 9ms
15:26:52.021 request_id=Fv2qoZqEAPV4uO4AAADi [debug] Converted error {:badmatch, {:error, "hi"}} to 500 response
15:26:52.022 [error] #PID<0.772.0> running JotWeb.Endpoint (connection #PID<0.771.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /users/settings?request_logger=SFMyNTY.g2gDbQAAAAQtNGt1bgYAPfcYuYEBYgABUYA.GBfMET2R40_SNjDu0eC-a1acKXxITltZS1QGwGLKyCs
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: {:error, "hi"}
(jot 0.1.0) lib/jot_web/templates/user_settings/edit.html.heex:15: anonymous fn/2 in JotWeb.UserSettingsView."edit.html"/1
(phoenix_live_view 0.17.9) lib/phoenix_live_view/engine.ex:124: Phoenix.HTML.Safe.Phoenix.LiveView.Rendered.to_iodata/1
(yada blah, snip)
Running the same project as a release (Debian production clone), I only get the first two log messages.
07:46:48.765 request_id=Fv2k9K6WIU86lpIAAAHB [info] Sent 500 in 15ms
07:46:48.765 request_id=Fv2k9K6WIU86lpIAAAHB [debug] Converted error {:badmatch, {:error, "hi"}} to 500 response
(crickets)
So I’d like to understand why this is, and figure out how to get stack traces from production crashes. My hazy guess, after a bit of investigation, is that Plug/Phoenix logs the errors I do see via telemetry, sends 500, then rethrows. IEx sees the rethrow as an unhandled exception, and helpfully prints it. The release runtime, uh, doesn’t.
I’m sure there are docs that explain this well enough, but my google-fu is inadequate to find them, so I’d love pointers. I’m also open to creative, low-effort ways to get better production error messages; I’m thinking about how to do really robust logging, but not too picky at this stage, as I’m at extreme risk of letting perfect be the enemy of good enough.
Thanks!