PeriodicMetricReader

Drives collection cycles and hands the results to a MetricExporter.

TelemetryProvider has no lifecycle member and there is no ambient scope to inherit, so the reader owns its own: a SupervisorJob, so one bad cycle cannot silently end collection for the process lifetime, on Dispatchers.Default, which is daemon-backed on the JVM so a forgotten close leaks one coroutine rather than hanging shutdown.

Built by the caller and assigned to AggregatingTelemetryProvider.Builder.metricReader, or created implicitly by that builder's exporter shorthand:

PeriodicMetricReader(interval = 30.seconds) {
exporter = CloudWatchMetricExporter { namespace = "MyApp" }
}

Types

Link copied to clipboard
class Builder
Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun close()

Stop the timer, flush a final time, then release the exporter and the scope. Idempotent.

Link copied to clipboard
open suspend override fun flush()

Collect and export immediately. Safe to call concurrently, and after close - a flush racing shutdown is ordinary teardown, so a closed reader returns without publishing rather than throwing.