Emit events from the API internals

This will make it simple to instrument in next-metrics.