Metrics
Colotok reports accepted enqueue attempts, provider rejection and publish failures, and AsyncProvider retention-buffer size. These metrics do not by themselves confirm destination delivery.
MetricsCollector
MetricsCollector is an interface to collect metrics. You can implement this interface to send metrics to your monitoring system like Prometheus, InfluxDB, etc.
recordWriteDuration() is available for custom instrumentation, but Colotok has no built-in production invocation. A future built-in duration metric must first define whether it measures queue wait, handler time, publish time, or end-to-end time.
Runtime Emission Matrix
Event | Log count | Error | Buffer size | Write duration |
|---|---|---|---|---|
Accepted normal record | incremented after enqueue acceptance | none | updated by | not emitted |
Record filtered by level | none | none | none | not emitted |
Full rejection from default synchronous | none |
| none | not emitted |
Rejection after normal close or force shutdown | none |
| none | not emitted |
Rejection after provider failure | none |
| none | not emitted |
Async publish failure | no additional count |
| failed batch retained | not emitted |
Newest record dropped at the retention limit | no additional count |
| remains at the limit | not emitted |
| no self-count | no self-error | no self-update | not emitted |
Collector throws | best-effort metric is lost | no recursive error | no recursive update | not emitted |
The log count is recorded when the provider channel accepts a record, not after destination delivery. Filtered records and LogRecord.Metrics do not produce runtime metrics.
Writing Paths and Backpressure
Provider.write() performs a non-blocking enqueue attempt. With the default SUSPEND overflow policy it does not wait for capacity; when the channel is full, the newest record is rejected and the accepted FIFO prefix remains queued.
AsyncProvider.writeAsync() waits until channel capacity is available, so channel pressure alone does not produce a full rejection. Coroutine *Async calls targeting a regular Provider still delegate to its non-blocking write() path. Rejection after normal close is reported as provider_closed; a failed provider reports provider_failed and rethrows the failure to the async caller.
Metrics Selection Strategy
You can specify how to collect metrics for each provider using MetricsCollectorSpec.
Inherit
The provider inherits the global collector configured in ColotokLoggerContext. This is the default.
Explicit
The provider uses a specific collector. You can choose whether to also report to the global collector using the inheritParent flag.
NoOp
The base or external metrics collector is disabled for the provider. Internal metrics logging can still be enabled separately.
Internal Metrics Logging
By setting enableInternalMetricsLogging = true, you can output metrics events as LogRecord.Metrics to the provider itself. This is useful for debugging or monitoring without external infrastructure.
Internal metrics logging can be used alongside MetricsCollectorSpec. For example, you can report to a global Prometheus collector while also logging metrics events to a local file.
Internal metrics use the same provider level filter and channel. For AsyncProvider, they also use the same retention buffer. They can be rejected under capacity pressure, but LogRecord.Metrics does not emit further metrics, preventing recursive growth.