| 1 | # EDC extensions for instrumentation with Micrometer |
| 2 | |
| 3 | EDC provides extensions for instrumentation with the [Micrometer](https://micrometer.io/) metrics library to automatically collect metrics from the host system, JVM, and frameworks and libraries used in EDC (including OkHttp, Jetty, Jersey and ExecutorService). |
| 4 | |
| 5 | See [sample 04.3](https://github.com/eclipse-edc/Samples/blob/main/transfer/transfer-04-open-telemetry/README.md) for an example of an instrumented EDC consumer. |
| 6 | |
| 7 | ## Micrometer Extension |
| 8 | |
| 9 | This extension provides support for instrumentation for some core EDC components: |
| 10 | - JVM metrics |
| 11 | - [OkHttp](https://square.github.io/okhttp/) client metrics |
| 12 | - [ExecutorService](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ExecutorService.html) metrics |
| 13 | |
| 14 | ## Jetty Micrometer Extension |
| 15 | |
| 16 | This extension provides support for instrumentation for the [Jetty](https://www.eclipse.org/jetty/) web server, which is enabled when using the `JettyExtension`. |
| 17 | |
| 18 | ## Jersey Micrometer Extension |
| 19 | |
| 20 | This extension provides support for instrumentation for the [Jersey](https://eclipse-ee4j.github.io/jersey/) framework, which is enabled when using the `JerseyExtension`. |
| 21 | |
| 22 | ## Instrumenting ExecutorServices |
| 23 | |
| 24 | Instrumenting ExecutorServices requires using the `ExecutorInstrumentation` service to create a wrapper around the service to be instrumented: |
| 25 | |
| 26 | ```java |
| 27 | ExecutorInstrumentation executorInstrumentation = context.getService(ExecutorInstrumentation.class); |
| 28 | |
| 29 | // instrument a ScheduledExecutorService |
| 30 | ScheduledExecutorService executor = executorInstrumentation.instrument(Executors.newScheduledThreadPool(10), "name"); |
| 31 | ``` |
| 32 | |
| 33 | Without any further configuration, a noop implementation of `ExecutorInstrumentation` is used. We recommend using the implementation provided in the Micrometer Extension that uses Micrometer's [ExecutorServiceMetrics](https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm/ExecutorServiceMetrics.java) to record ExecutorService metrics. |
| 34 | |
| 35 | ## Configuration |
| 36 | |
| 37 | The following properties can use used to configure which metrics will be collected. |
| 38 | |
| 39 | - `edc.metrics.enabled`: enables/disables metrics collection globally |
| 40 | - `edc.metrics.system.enabled`: enables/disables collection of system metrics (class loader, memory, garbage collection, processor and thread metrics) |
| 41 | - `edc.metrics.okhttp.enabled`: enables/disables collection of metrics for the OkHttp client |
| 42 | - `edc.metrics.executor.enabled`: enables/disables collection of metrics for the instrumented ExecutorServices |
| 43 | - `edc.metrics.jetty.enabled`: enables/disables collection of Jetty metrics |
| 44 | - `edc.metrics.jersey.enabled`: enables/disables collection of Jersey metrics |
| 45 | |
| 46 | Default values are always "true", switch to "false" to disable the corresponding feature. |