tracing_cloudwatch/lib.rs
1//! tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.
2//!
3//! We have supported [rusoto](https://github.com/rusoto/rusoto) and the [AWS SDK](https://github.com/awslabs/aws-sdk-rust) as AWS clients.
4//!
5//! ## Usage
6//!
7//! ### With Rusoto
8//!
9//! feature `rusoto` required
10//!
11//! ```rust
12//! use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
13//!
14//! #[tokio::main]
15//! async fn main() {
16//! let cw_client = rusoto_logs::CloudWatchLogsClient::new(rusoto_core::Region::ApNortheast1);
17//!
18//! tracing_subscriber::registry::Registry::default()
19//! .with(
20//! tracing_cloudwatch::layer().with_client(
21//! cw_client,
22//! tracing_cloudwatch::ExportConfig::default()
23//! .with_batch_size(5)
24//! .with_interval(std::time::Duration::from_secs(1))
25//! .with_log_group_name("tracing-cloudwatch")
26//! .with_log_stream_name("stream-1"),
27//! ),
28//! )
29//! .init();
30//! }
31//! ```
32//!
33//! ### With AWS SDK
34//!
35//! feature `awssdk` required
36//!
37//! ```rust
38//! use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
39//!
40//! #[tokio::main]
41//! async fn main() {
42//! let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
43//! let cw_client = aws_sdk_cloudwatchlogs::Client::new(&config);
44//!
45//! tracing_subscriber::registry::Registry::default()
46//! .with(
47//! tracing_cloudwatch::layer().with_client(
48//! cw_client,
49//! tracing_cloudwatch::ExportConfig::default()
50//! .with_batch_size(5)
51//! .with_interval(std::time::Duration::from_secs(1))
52//! .with_log_group_name("tracing-cloudwatch")
53//! .with_log_stream_name("stream-1"),
54//! ),
55//! )
56//! .init();
57//! }
58//! ```
59//!
60//! ## Required Permissions
61//!
62//! Currently, following AWS IAM Permissions required
63//!
64//! * `logs:PutLogEvents`
65//!
66//! ## CloudWatch Log Groups and Streams
67//!
68//! This crate does not create a log group and log stream, so if the specified log group and log stream does not exist, it will raise an error.
69//!
70//! ## Retry and Timeout
71//!
72//! We haven't implemented any custom retry logic or timeout settings within the crate. We assume that these configurations are handled through the SDK Client.
73//! For instance, in the AWS SDK, you can set up these configurations using [`timeout_config`](https://docs.rs/aws-sdk-cloudwatchlogs/0.28.0/aws_sdk_cloudwatchlogs/config/struct.Builder.html#method.timeout_config) and [`retry_config`](https://docs.rs/aws-sdk-cloudwatchlogs/0.28.0/aws_sdk_cloudwatchlogs/config/struct.Builder.html#method.retry_config)
74
75mod client;
76mod dispatch;
77mod export;
78mod layer;
79
80pub use client::CloudWatchClient;
81pub use export::{ExportConfig, LogDestination};
82pub use layer::{layer, CloudWatchLayer};