Class ObservationExecChainHandler

java.lang.Object
io.micrometer.core.instrument.binder.httpcomponents.hc5.ObservationExecChainHandler
All Implemented Interfaces:
org.apache.hc.client5.http.async.AsyncExecChainHandler, org.apache.hc.client5.http.classic.ExecChainHandler

public class ObservationExecChainHandler extends Object implements org.apache.hc.client5.http.classic.ExecChainHandler, org.apache.hc.client5.http.async.AsyncExecChainHandler
Instruments the Apache HTTP Client 5 for both classic and async variants using the ExecChainHandler and AsyncExecChainHandler contracts. This instrumentation accepts custom convetion implementations and will use the default one if none was provided.

For a "classic" client, it can be configured as an interceptor in the chain:

 CloseableHttpClient client = HttpClientBuilder.create()
   .addExecInterceptorLast("micrometer", new ObservationExecChainHandler(observationRegistry))
   .build()
 

For an "async" client, it can also be configured as an interceptor in the chain:

 CloseableHttpAsyncClient client = HttpAsyncClients.custom()
   .addExecInterceptorLast("micrometer", new ObservationExecChainHandler(observationRegistry))
   .build();
 

Note that the ObservationExecChainHandler must always be inserted after the retry interceptor, preferably last.

Since:
1.12.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    ObservationExecChainHandler(io.micrometer.observation.ObservationRegistry observationRegistry)
     
    ObservationExecChainHandler(io.micrometer.observation.ObservationRegistry observationRegistry, ApacheHttpClientObservationConvention observationConvention)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.hc.core5.http.ClassicHttpResponse
    execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.client5.http.classic.ExecChain.Scope scope, org.apache.hc.client5.http.classic.ExecChain chain)
     
    void
    execute(org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.nio.AsyncEntityProducer entityProducer, org.apache.hc.client5.http.async.AsyncExecChain.Scope scope, org.apache.hc.client5.http.async.AsyncExecChain chain, org.apache.hc.client5.http.async.AsyncExecCallback asyncExecCallback)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ObservationExecChainHandler

      public ObservationExecChainHandler(io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable ApacheHttpClientObservationConvention observationConvention)
    • ObservationExecChainHandler

      public ObservationExecChainHandler(io.micrometer.observation.ObservationRegistry observationRegistry)
  • Method Details

    • execute

      public void execute(org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.nio.AsyncEntityProducer entityProducer, org.apache.hc.client5.http.async.AsyncExecChain.Scope scope, org.apache.hc.client5.http.async.AsyncExecChain chain, org.apache.hc.client5.http.async.AsyncExecCallback asyncExecCallback) throws org.apache.hc.core5.http.HttpException, IOException
      Specified by:
      execute in interface org.apache.hc.client5.http.async.AsyncExecChainHandler
      Throws:
      org.apache.hc.core5.http.HttpException
      IOException
    • execute

      public org.apache.hc.core5.http.ClassicHttpResponse execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.client5.http.classic.ExecChain.Scope scope, org.apache.hc.client5.http.classic.ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException
      Specified by:
      execute in interface org.apache.hc.client5.http.classic.ExecChainHandler
      Throws:
      IOException
      org.apache.hc.core5.http.HttpException