Add WebClient metrics support
This commit adds support for Actuator Metrics for WebClient. This support mirrors the current behavior for `RestTemplate`, reusing the same metric name `"http.client.requests"` and tags. `WebClient` is instrumented by a `MetricsWebClientFilterFunction` which is applied by a `WebClientCustomizer`. This instrumentation happens automatically only if you create an instance of `WebClient` using an auto-configured `WebClient.Builder` bean. This infrastructure is reusing de facto the `MeterFilter` that has been added for `RestTemplate` in order to limit the "uri" tag cardinality. Closes gh-12228
This commit is contained in:
@@ -1713,16 +1713,22 @@ To customize the tags, provide a `@Bean` that implements `WebFluxTagsProvider`.
|
||||
|
||||
|
||||
|
||||
[[production-ready-metrics-rest-template]]
|
||||
==== RestTemplate Metrics
|
||||
The instrumentation of any `RestTemplate` created using the auto-configured
|
||||
`RestTemplateBuilder` is enabled. It is also possible to apply
|
||||
`MetricsRestTemplateCustomizer` manually.
|
||||
[[production-ready-metrics-http-clients]]
|
||||
==== HTTP Client Metrics
|
||||
Spring Boot Actuator manages the instrumentation of both `RestTemplate` and `WebClient`.
|
||||
For that, you have to get injected with an auto-configured builder
|
||||
and use it to create instances:
|
||||
|
||||
* `RestTemplateBuilder` for `RestTemplate`
|
||||
* `WebClient.Builder` for `WebClient`
|
||||
|
||||
It is also possible to apply manually the customizers responsible for this instrumentation,
|
||||
namely `MetricsRestTemplateCustomizer` and `MetricsWebClientCustomizer`.
|
||||
|
||||
By default, metrics are generated with the name, `http.client.requests`. The name can be
|
||||
customized by setting the `management.metrics.web.client.requests-metric-name` property.
|
||||
|
||||
By default, metrics generated by an instrumented `RestTemplate` are tagged with the
|
||||
By default, metrics generated by an instrumented client are tagged with the
|
||||
following information:
|
||||
|
||||
* `method`, the request's method (for example, `GET` or `POST`).
|
||||
@@ -1731,9 +1737,10 @@ example, `/api/person/{id}`).
|
||||
* `status`, the response's HTTP status code (for example, `200` or `500`).
|
||||
* `clientName`, the host portion of the URI.
|
||||
|
||||
To customize the tags, provide a `@Bean` that implements
|
||||
`RestTemplateExchangeTagsProvider`. There are convenience static functions in
|
||||
`RestTemplateExchangeTags`.
|
||||
To customize the tags, and depending on your choice of client, you can provide
|
||||
a `@Bean` that implements `RestTemplateExchangeTagsProvider` or
|
||||
`WebClientExchangeTagsProvider`. There are convenience static functions in
|
||||
`RestTemplateExchangeTags` and `WebClientExchangeTags`.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user