First you use trace_port to get PortFun as follows:
1> PortFun = dbg:trace_port(file,{"/tmp/trace",wrap,atom_to_list(node()),10000000,20}).
Then use dbg: tracer to start the tracer, which will route messages:
2> dbg:tracer(port, PortFun).
Trace output can be obtained using trace_client:
1> Pid = dbg: trace_client (file, FileName).
..
dbg output here ...
..
2> dbg: stop_trace_client (Pid).