Expand description
CloudWatch Logs PutLogEvents (EMF) backend for metrique.
This crate provides CwLogsStream, an EntryIoStream implementation that serializes
metric entries as EMF JSON and submits them directly to CloudWatch Logs via PutLogEvents.
§Architecture
App threads → BackgroundQueue (metrique) → std thread calls CwLogsStream::next(&entry)
→ EMF serialize (reuses metrique-writer-format-emf)
→ batch until size/count limit hit: try_send(batch) over bounded channel
→ single async task: recv batch → client.put_log_events (async HTTP)§Runtime
The tokio_runtime feature is enabled by default and provides the default
TaskSpawner::tokio() spawner. With --no-default-features, callers must
provide a custom TaskSpawner with CwLogsStream::builder(). Custom
spawners must detach or otherwise keep the submitted future running after
the spawn callback returns.
For non-Tokio executors, configure the AWS client with a compatible
AsyncSleep. SDK timeouts and
retry delays use that sleep hook.
§Backpressure
When the submission channel is full (CloudWatch Logs is slow or down), batches are
dropped at submission time with a rate-limited warning. Drops are reported through
CwLogsStreamEvent::BatchDropped. Once the channel drains, normal submission resumes.
§Shutdown
CwLogsStream::builder() returns (CwLogsStream, CwLogsStreamHandle). Call
CwLogsStreamHandle::shutdown() to await drain of in-flight batches.
§Example
use metrique_writer_cloudwatch::{CwLogsStream, CwLogsStreamConfig};
use metrique_writer_core::EntryIoStream;
let sdk_config = aws_config::load_from_env().await;
let client = aws_sdk_cloudwatchlogs::Client::new(&sdk_config);
let (stream, handle) = CwLogsStream::builder()
.client(client)
.log_group_name("/my-app/metrics".to_string())
.log_stream_name("host-1".to_string())
.namespace("MyApp".to_string())
.default_dimensions(vec![vec![]])
.build();
// Pass `stream` to metrique's BackgroundQueue or ServiceMetrics::attach_to_stream()
// ...
// Graceful shutdown:
handle.shutdown().await;Structs§
- CwLogs
Stream - An
EntryIoStreamthat serializes entries as EMF JSON and submits them to CloudWatch Logs viaPutLogEventsin a background async task. - CwLogs
Stream Builder - Use builder syntax to set the inputs and finish with
build(). - CwLogs
Stream Config - Configuration for
CwLogsStream. - CwLogs
Stream Config Builder - Use builder syntax to set the inputs and finish with
build(). - CwLogs
Stream Handle - Handle for async shutdown of
CwLogsStream. - NoOp
Observer - Default no-op observer.
- Task
Spawner - A wrapper around a task spawner function.
Enums§
- CwLogs
Stream Event - Events emitted by
CwLogsStreamfor observability.
Traits§
- CwLogs
Stream Observer - Observer for
CwLogsStreamEvents. Implement this to collect internal metrics.
Type Aliases§
- Task
Spawner Fn - Type alias for a task spawner function.