Records a trace entry when tracing is enabled.
The lambda form matches the original TypeScript API and can be stored or passed around as a function reference.