From 365e39933b0633f0d540db974acbf9c9e4b0f0e9 Mon Sep 17 00:00:00 2001 From: Euro Lew Date: Fri, 1 Nov 2024 13:48:53 +0000 Subject: [PATCH] docs: exporter metrics example --- docs/self-managed/concepts/exporters.md | 19 ++++++++++++++++++- .../self-managed/concepts/exporters.md | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/self-managed/concepts/exporters.md b/docs/self-managed/concepts/exporters.md index a6dc88b2ae..be9af05b89 100644 --- a/docs/self-managed/concepts/exporters.md +++ b/docs/self-managed/concepts/exporters.md @@ -66,7 +66,24 @@ heavy work during instantiation/configuration. ### Metrics -The exporter is provided with a Micrometer [MeterRegistry](https://docs.micrometer.io/micrometer/reference/concepts/registry.html) in the `Exporter#configure(Context)` method through the configuration. Any metrics to be exported should interact with the registry. +The exporter is provided with a Micrometer [MeterRegistry](https://docs.micrometer.io/micrometer/reference/concepts/registry.html) in the `Exporter#configure(Context)` method through the configuration. Any metrics to be exported should interact with the registry, for example: + +```java +public class SomeExporter implements Exporter { + @Override + public void configure(final Context context) { + // ... + registry = context.getMeterRegistry(); + // ... + } + + public void flush() { + try (final var ignored = Timer.resource(registry, "meter.name")) { + exportBulk(); + } + } +} +``` When an exporter is validated, it is only provided with an in-memory register which is then discarded. diff --git a/versioned_docs/version-8.6/self-managed/concepts/exporters.md b/versioned_docs/version-8.6/self-managed/concepts/exporters.md index a6dc88b2ae..be9af05b89 100644 --- a/versioned_docs/version-8.6/self-managed/concepts/exporters.md +++ b/versioned_docs/version-8.6/self-managed/concepts/exporters.md @@ -66,7 +66,24 @@ heavy work during instantiation/configuration. ### Metrics -The exporter is provided with a Micrometer [MeterRegistry](https://docs.micrometer.io/micrometer/reference/concepts/registry.html) in the `Exporter#configure(Context)` method through the configuration. Any metrics to be exported should interact with the registry. +The exporter is provided with a Micrometer [MeterRegistry](https://docs.micrometer.io/micrometer/reference/concepts/registry.html) in the `Exporter#configure(Context)` method through the configuration. Any metrics to be exported should interact with the registry, for example: + +```java +public class SomeExporter implements Exporter { + @Override + public void configure(final Context context) { + // ... + registry = context.getMeterRegistry(); + // ... + } + + public void flush() { + try (final var ignored = Timer.resource(registry, "meter.name")) { + exportBulk(); + } + } +} +``` When an exporter is validated, it is only provided with an in-memory register which is then discarded.