I’m confused by this, because all of the code samples in the metrics docs use this identical pattern:
private final Timer responses = metrics.timer(name(RequestHandler.class, "responses"));
public String handleRequest(Request request, Response response) {
final Timer.Context context = responses.time();
try {
// etc;
return "OK";
} finally {
context.stop();
}
}
Why would you not want to measure the cases where an exception was thrown inside the code block being timed? If you are not updating the Timer on exceptions, then you would miss out when timeouts or other exceptions cause the block being measure to be latent.