#aws #cloud-watch #tracing #send

tracing-cloudwatch

tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs

6 releases

0.1.5 Feb 5, 2024
0.1.4 Oct 19, 2023
0.1.2 Jul 24, 2023
0.1.1 May 7, 2023

#175 in Debugging

Download history 47/week @ 2023-12-20 2/week @ 2023-12-27 56/week @ 2024-01-03 38/week @ 2024-01-10 90/week @ 2024-01-17 61/week @ 2024-01-24 69/week @ 2024-01-31 104/week @ 2024-02-07 655/week @ 2024-02-14 103/week @ 2024-02-21 98/week @ 2024-02-28 52/week @ 2024-03-06 154/week @ 2024-03-13 42/week @ 2024-03-20 52/week @ 2024-03-27 60/week @ 2024-04-03

329 downloads per month

MIT license

26KB
498 lines

tracing-cloudwatch

tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.

We have supported rusoto and the AWS SDK as AWS clients.

Usage

With AWS SDK

feature awssdk required

use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
async fn main() {
    let config = aws_config::load_from_env().await;
    let cw_client = aws_sdk_cloudwatchlogs::Client::new(&config);

    tracing_subscriber::registry::Registry::default()
        .with(
            tracing_cloudwatch::layer().with_client(
                cw_client,
                tracing_cloudwatch::ExportConfig::default()
                    .with_batch_size(5)
                    .with_interval(std::time::Duration::from_secs(1))
                    .with_log_group_name("tracing-cloudwatch")
                    .with_log_stream_name("stream-1"),
            )
            .with_code_location(true)
            .with_target(false),
        )
        .init();
}

With Rusoto

feature rusoto required

use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
async fn main() {
    let cw_client = rusoto_logs::CloudWatchLogsClient::new(rusoto_core::Region::ApNortheast1);

    tracing_subscriber::registry::Registry::default()
        .with(
            tracing_cloudwatch::layer().with_client(
                cw_client,
                tracing_cloudwatch::ExportConfig::default()
                    .with_batch_size(5)
                    .with_interval(std::time::Duration::from_secs(1))
                    .with_log_group_name("tracing-cloudwatch")
                    .with_log_stream_name("stream-1"),
            )
            .with_code_location(true)
            .with_target(false),
        )
        .init();
}

Required Permissions

Currently, following AWS IAM Permissions required

  • logs:PutLogEvents

CloudWatch Log Groups and Streams

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.

Retry and Timeout

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.
For instance, in the AWS SDK, you can set up these configurations using timeout_config and retry_config

License

This project is licensed under the MIT license.

Dependencies

~5–20MB
~262K SLoC