[counters] Fix the build and do some error handling.
[counters] Improve the documentation of the counters API.