Even though my question uses Elixir, I think this might be more of an Erlang question since the Elixir’s Logger.Translator
is not getting any metadata in error reports.
Question
How to get metadata passed to error reports?
For example, if my process has metadata set:
Logger.configure(metadata: :all)
spawn(fn ->
Logger.metadata(user_id: "123")
raise "oops"
end)
I want to get user_id
to be added to the error report. Right now it’s not being added.
What happens?
Here’s the report that I get:
08:27:31.269 erl_level=error node=nonode@nohost pid=<0.370.0> Process #PID<0.370.0> raised an exception
** (RuntimeError) oops
... stacktrace
Tracing Logger.Translator
shows that it’s not getting user_id
or any other custom metadata from :logger_proxy
:
# 12:27:31 #PID<0.71.0> (:logger_proxy)
# Logger.Translator.translate(:debug, :error, :format, {'Error in process ~p with exit value:~n~p~n', [#PID<0.370.0>, {%RuntimeError{message: "oops"}, [{E, :"-crash/0-fun-0-", 0, [file: 'lib/e.ex', line: 22, error_info: %{module: Exception}]}]}]})
What do I expect?
I expect the metadata to be added to the error report:
note the added user_id
08:27:31.269 user_id=123 erl_level=error node=nonode@nohost pid=<0.370.0> Process #PID<0.370.0> raised an exception
** (RuntimeError) oops
... stacktrace