View stacktrace in production

I can’t seem to get stacktraces in production. I have these lines in prod.exs:

config :logger,
  level: String.to_existing_atom(System.get_env("LOG_LEVEL", "info"))
config :logger, truncate: :infinity
config :phoenix, :stacktrace_depth, 20

And LOG_LEVEL is set to debug. App is not publicly available, so I want to see my debug logs while I can.

I can see my debug logs in production, but I can’t see a stacktrace, at least for some kind of errors.

I can see for example Converted Ecto.Cast to 400 or something like that, but there is no stacktrace. I debugged that error and found that I was using mixed keys, but the question is where is stacktrace? Do I need to enable something for it?

prod.exs is evaluated at compile time, not runtime. And stacktraces are sent with error level, so these should be visible with info level set.

What error exactly you are throwing? Because some errors are handled by Plug and these do not print stacktrace.

I’m not throwing anything. What do you mean by some errors are handled by Plug? Is there any documentation on them?

The error, as I mentioned, was an Ecto.CastError, caused by using mixed keys in a changeset.

Then indeed it is handled by phoenix_ecto integration library. It is all done by Plug.Exception which converts exceptions that implement this protocol or have :plug_code field into proper responses and do not produce the stacktrace. In development this behaviour is disabled to simplify debugging, but in production it is enabled by default.


I see. Thanks!

So, what’s the correct way to know what caused these exceptions? We’re not getting stacktrace, and I guess it would not also appear in third-party services like Logflare (since it’s handling exceptions, logger application does not notice them).