avaje/avaje-http-client

ENH: Add HttpClientRequest label ... typically for grouping / using with metrics collection and reporting

Closed this issue · 0 comments

Set a label on the request

    HttpResponse<String> res = clientContext.request()
      .label("client_hello_retry")  // <!-- HERE
      .path("hello/retry")
      .GET()
      .asString();

Have a RequestIntercept implementation that reads the label() and uses it for metrics collection

  static class MyIntercept implements RequestIntercept {
    
    @Override
    public void afterResponse(HttpResponse<?> response, HttpClientRequest request) {
     
      long responseTimeMicros = request.responseTimeMicros();
      String label = request.label();

     // use label and responseTimeMicros to collect metrics to the metrics library
    }
  }