Video in progress

What does the `http.client.requests` metric measure, and how do you tell "our service is slow" apart from "the external API we call is slow"?

http.client.requests is a Timer for every outgoing call made by Spring's instrumented clients (RestClient, RestTemplate, WebClient), with the tags client.name, uri, method, status and outcome. If you put service latency and downstream latency on one graph, you can see right away where the time goes.

📖 Answer

http.server.requests measures the requests that come in to you, and http.client.requests measures the ones you send out. With both on one panel, most arguments end:

# our endpoint p99
histogram_quantile(0.99, sum by (le) (rate(http_server_requests_seconds_bucket{uri="/checkout"}[5m])))

# external payment gateway p99
histogram_quantile(0.99, sum by (le) (rate(http_client_requests_seconds_bucket{client_name="pay.gateway.uz"}[5m])))

Checkout p99 is 1.8 s and the gateway p99 is 1.6 s: the problem is not with us, but we are passing it straight through to the user (time to think about timeouts, a cache or an async design).

This metric only appears on correctly created clients:

@Bean
RestClient paymentClient(RestClient.Builder builder) {   // auto-configured builder
    return builder.baseUrl("https://pay.gateway.uz").build();
}

A client created with RestClient.create() or new RestTemplate() stays without metrics and without traces.

Traps:

  • URI cardinality: the uri tag is taken from the template. If you build a string like client.get().uri("/users/" + id), every ID becomes its own series. Write it as uri("/users/{id}", id).
  • Timeouts: calls that fail on a connection timeout show up with status="CLIENT_ERROR" or outcome="UNKNOWN". Count those in the error ratio too.
  • Retry: a retry library has each attempt measured separately; to get the total time the user sees, you need your own Observation wrapped around the retry.

The same idea applies to JDBC and Redis calls: the latency and error ratio of every external dependency should be visible on their own.