Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.44 KB

java-httpclient.adoc

File metadata and controls

41 lines (30 loc) · 1.44 KB

Java HttpClient instrumentation

Since Java 11, an HttpClient is provided as part of the JDK. See this introduction to it. Micrometer provides instrumentation of this via a micrometer-java11 module. This module requires Java 11 or later.

For Gradle, add the following implementation:

implementation 'io.micrometer:micrometer-java11'

For Maven, add the following dependency:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-java11</artifactId>
</dependency>

Create an HttpClient as you normally would. For example:

link:{include-micrometer-java11-test}/io/micrometer/java11/instrument/binder/jdk/MicrometerHttpClientTests.java[role=include]

You can instrument this HttpClient as follows with an ObservationRegistry:

link:{include-micrometer-java11-test}/io/micrometer/java11/instrument/binder/jdk/MicrometerHttpClientTests.java[role=include]

Alternatively, if you are not using an ObservationRegistry, you can instrument with only a MeterRegistry as follows:

link:{include-micrometer-java11-test}/io/micrometer/java11/instrument/binder/jdk/MicrometerHttpClientTests.java[role=include]