public final class HttpClientObservationSupport extends Object
This helper can install:
ObservationRegistry)
which can be bridged to OpenTelemetry tracing, andMeterRegistry) such as
per-request latency timers, response counters, I/O counters, and
connection pool gauges.Optional dependencies
Micrometer and OpenTelemetry are optional dependencies. Use the
overloads that accept explicit registries (recommended) or the convenience
overloads that use Metrics.globalRegistry. When Micrometer is not
on the classpath, only the observation / metric features you actually call
will be required.
Typical usage (classic client)
ObservationRegistry obs = ObservationRegistry.create();
MeterRegistry meters = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
HttpClientBuilder b = HttpClients.custom();
HttpClientObservationSupport.enable(
b, obs, meters,
ObservingOptions.DEFAULT,
MetricConfig.DEFAULT);
CloseableHttpClient client = b.build();
What gets installed
obsReg is non-null)
that surrounds each execution with a start/stop span.ObservingOptions.MetricSet:
BASIC (latency timer + response counter), IO (bytes in/out counters),
and CONN_POOL (pool gauges; classic and async variants). Pool lease
timing is available when using meteredConnectionManager(org.apache.hc.client5.http.io.HttpClientConnectionManager, io.micrometer.core.instrument.MeterRegistry, org.apache.hc.client5.http.observation.ObservingOptions, org.apache.hc.client5.http.observation.MetricConfig) or
meteredAsyncConnectionManager(org.apache.hc.client5.http.nio.AsyncClientConnectionManager, io.micrometer.core.instrument.MeterRegistry, org.apache.hc.client5.http.observation.ObservingOptions, org.apache.hc.client5.http.observation.MetricConfig).Thread safety: This class is stateless. Methods may be called from any thread before the client is built.
| Modifier and Type | Method and Description |
|---|---|
static void |
enable(CachingHttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg)
Enables observations and default metrics on a caching async client builder using
Metrics.globalRegistry and MetricConfig.DEFAULT. |
static void |
enable(CachingHttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts)
Enables observations and metrics on a caching async client builder with an explicit
meter registry and default
MetricConfig. |
static void |
enable(CachingHttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Enables observations and metrics on a caching async client builder using explicit
registries and
MetricConfig. |
static void |
enable(CachingHttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
ObservingOptions opts)
Enables observations and metrics on a caching async client builder using
Metrics.globalRegistry and a custom ObservingOptions. |
static void |
enable(CachingHttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg)
Enables observations and default metrics on a caching classic client builder using
Metrics.globalRegistry and MetricConfig.DEFAULT. |
static void |
enable(CachingHttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts)
Enables observations and metrics on a caching classic client builder with an explicit
meter registry and default
MetricConfig. |
static void |
enable(CachingHttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Enables observations and metrics on a caching classic client builder using explicit
registries and
MetricConfig. |
static void |
enable(CachingHttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
ObservingOptions opts)
Enables observations and metrics on a caching classic client builder using
Metrics.globalRegistry and a custom ObservingOptions. |
static void |
enable(HttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg)
Enables observations and default metrics on an async client builder using
Metrics.globalRegistry and MetricConfig.DEFAULT. |
static void |
enable(HttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts)
Enables observations and metrics on an async client builder with an explicit
meter registry and default
MetricConfig. |
static void |
enable(HttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Enables observations and metrics on an async client builder using explicit
registries and
MetricConfig. |
static void |
enable(HttpAsyncClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
ObservingOptions opts)
Enables observations and metrics on an async client builder using
Metrics.globalRegistry and a custom ObservingOptions. |
static void |
enable(HttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg)
Enables observations and default metrics on a classic client builder using
Metrics.globalRegistry and MetricConfig.DEFAULT. |
static void |
enable(HttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts)
Enables observations and metrics on a classic client builder with an explicit
meter registry and default
MetricConfig. |
static void |
enable(HttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Enables observations and metrics on a classic client builder using explicit
registries and
MetricConfig. |
static void |
enable(HttpClientBuilder builder,
io.micrometer.observation.ObservationRegistry obsReg,
ObservingOptions opts)
Enables observations and metrics on a classic client builder using
Metrics.globalRegistry and a custom ObservingOptions. |
static AsyncClientConnectionManager |
meteredAsyncConnectionManager(AsyncClientConnectionManager delegate,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Wraps an async connection manager with Micrometer pool-lease metrics if
ObservingOptions.MetricSet.CONN_POOL is enabled. |
static HttpClientConnectionManager |
meteredConnectionManager(HttpClientConnectionManager delegate,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Wraps a classic connection manager with Micrometer pool-lease metrics if
ObservingOptions.MetricSet.CONN_POOL is enabled. |
static DnsResolver |
meteredDnsResolver(DnsResolver delegate,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Wraps a DNS resolver with Micrometer metrics if
ObservingOptions.MetricSet.DNS
is enabled. |
static TlsStrategy |
meteredTlsStrategy(TlsStrategy delegate,
io.micrometer.core.instrument.MeterRegistry meterReg,
ObservingOptions opts,
MetricConfig mc)
Wraps a TLS strategy with Micrometer metrics if
ObservingOptions.MetricSet.TLS
is enabled. |
public static void enable(HttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg)
Metrics.globalRegistry and MetricConfig.DEFAULT.builder - client builder to instrumentobsReg - observation registry; if null no observations are installedpublic static void enable(HttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, ObservingOptions opts)
Metrics.globalRegistry and a custom ObservingOptions.builder - client builder to instrumentobsReg - observation registry; if null no observations are installedopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(HttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts)
MetricConfig.builder - client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters withopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(HttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
MetricConfig.
Installs interceptors at the beginning of the execution chain.
builder - client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static void enable(CachingHttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg)
Metrics.globalRegistry and MetricConfig.DEFAULT.builder - caching client builder to instrumentobsReg - observation registry; if null no observations are installedpublic static void enable(CachingHttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, ObservingOptions opts)
Metrics.globalRegistry and a custom ObservingOptions.builder - caching client builder to instrumentobsReg - observation registry; if null no observations are installedopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(CachingHttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts)
MetricConfig.builder - caching client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters withopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(CachingHttpClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
MetricConfig.
Interceptors are installed after the caching element so that metrics/observations reflect the actual exchange.
builder - caching client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static void enable(HttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg)
Metrics.globalRegistry and MetricConfig.DEFAULT.builder - async client builder to instrumentobsReg - observation registry; if null no observations are installedpublic static void enable(HttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, ObservingOptions opts)
Metrics.globalRegistry and a custom ObservingOptions.builder - async client builder to instrumentobsReg - observation registry; if null no observations are installedopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(HttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts)
MetricConfig.builder - async client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters withopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(HttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
MetricConfig.builder - async client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static void enable(CachingHttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg)
Metrics.globalRegistry and MetricConfig.DEFAULT.builder - caching async client builder to instrumentobsReg - observation registry; if null no observations are installedpublic static void enable(CachingHttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, ObservingOptions opts)
Metrics.globalRegistry and a custom ObservingOptions.builder - caching async client builder to instrumentobsReg - observation registry; if null no observations are installedopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(CachingHttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts)
MetricConfig.builder - caching async client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters withopts - observation/metric options; when null ObservingOptions.DEFAULT is usedpublic static void enable(CachingHttpAsyncClientBuilder builder, io.micrometer.observation.ObservationRegistry obsReg, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
MetricConfig.
Interceptors are installed after the caching element.
builder - caching async client builder to instrumentobsReg - observation registry; if null no observations are installedmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static HttpClientConnectionManager meteredConnectionManager(HttpClientConnectionManager delegate, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
ObservingOptions.MetricSet.CONN_POOL is enabled. Otherwise returns
the delegate unchanged.delegate - connection manager to wrapmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static AsyncClientConnectionManager meteredAsyncConnectionManager(AsyncClientConnectionManager delegate, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
ObservingOptions.MetricSet.CONN_POOL is enabled. Otherwise returns
the delegate unchanged.delegate - connection manager to wrapmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static DnsResolver meteredDnsResolver(DnsResolver delegate, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
ObservingOptions.MetricSet.DNS
is enabled. Otherwise returns the delegate unchanged.delegate - underlying DNS resolvermeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedpublic static TlsStrategy meteredTlsStrategy(TlsStrategy delegate, io.micrometer.core.instrument.MeterRegistry meterReg, ObservingOptions opts, MetricConfig mc)
ObservingOptions.MetricSet.TLS
is enabled. Otherwise returns the delegate unchanged.delegate - TLS strategy to wrapmeterReg - meter registry to register meters with (must not be null)opts - observation/metric options; when null ObservingOptions.DEFAULT is usedmc - metric configuration; when null MetricConfig.DEFAULT is usedCopyright © 1999–2021 The Apache Software Foundation. All rights reserved.