Elixir/Erlang - Trace when a message arrives in the mailbox

Fairly straight forward question, is it possible to trace messages arriving in (the mailbox of) a Process/GenServer? Note, this is different from tracing when a message is received (which would be once it leaves the mailbox and is handled). I've not found a way of doing this until now.


  • In erlang you have flags for it in dbg:p/2, s for sending and r for receiving:

    1> dbg:tracer().
    2> dbg:p(self(), r).
    (<0.80.0>) << {dbg,{ok,[{matched,nonode@nohost,1}]}}
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.183997>,319}
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.184000>,
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.184002>,ok}
    3> self() ! trace_me.
    (<0.80.0>) << {shell_cmd,<0.73.0>,
    (<0.80.0>) << trace_me
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.184006>,319}
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.184008>,
    (<0.80.0>) << {io_reply,#Ref<0.2586582558.1779957764.184011>,ok}