{"id":28088903,"url":"https://github.com/ymgyt/tracing-cloudwatch","last_synced_at":"2025-05-13T12:52:13.508Z","repository":{"id":162270908,"uuid":"636331722","full_name":"ymgyt/tracing-cloudwatch","owner":"ymgyt","description":"AWS Cloudwatch layer for tracing-subscriber","archived":false,"fork":false,"pushed_at":"2025-03-25T11:06:26.000Z","size":52,"stargazers_count":18,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T11:49:24.739Z","etag":null,"topics":["cloudwatch-logs","rust","tracing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ymgyt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-04T15:50:44.000Z","updated_at":"2025-03-25T11:05:10.000Z","dependencies_parsed_at":"2023-10-11T11:31:48.492Z","dependency_job_id":"ec4f1929-8146-4279-9ee8-e53230c826b3","html_url":"https://github.com/ymgyt/tracing-cloudwatch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymgyt%2Ftracing-cloudwatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymgyt%2Ftracing-cloudwatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymgyt%2Ftracing-cloudwatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymgyt%2Ftracing-cloudwatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ymgyt","download_url":"https://codeload.github.com/ymgyt/tracing-cloudwatch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253947622,"owners_count":21988942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudwatch-logs","rust","tracing"],"created_at":"2025-05-13T12:52:12.729Z","updated_at":"2025-05-13T12:52:13.501Z","avatar_url":"https://github.com/ymgyt.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tracing-cloudwatch\n\ntracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.\n\nWe have supported [rusoto](https://github.com/rusoto/rusoto) and the [AWS SDK](https://github.com/awslabs/aws-sdk-rust) as AWS clients.\n\n## Usage\n\n### With AWS SDK\n\nfeature `awssdk` required\n\n```rust\nuse tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};\n\n#[tokio::main]\nasync fn main() {\n    let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;\n    let cw_client = aws_sdk_cloudwatchlogs::Client::new(\u0026config);\n\n    tracing_subscriber::registry::Registry::default()\n        .with(\n            tracing_cloudwatch::layer().with_client(\n                cw_client,\n                tracing_cloudwatch::ExportConfig::default()\n                    .with_batch_size(5)\n                    .with_interval(std::time::Duration::from_secs(1))\n                    .with_log_group_name(\"tracing-cloudwatch\")\n                    .with_log_stream_name(\"stream-1\"),\n            )\n            .with_code_location(true)\n            .with_target(false),\n        )\n        .init();\n}\n```\n\n#### Chronological order\n\nWhen aggregating logs from multiple places (or integrations such as [tracing-gstreamer](https://crates.io/crates/tracing-gstreamer)), messages can become unordered. This causes a `InvalidParameterException: Log events in a single PutLogEvents request must be in chronological order.` error from the CloudWatch client. To mediate this, you may enable the `ordered_logs` feature. Take into consideration that this can possibly increase processing time significantly depending on the number of events in the batch. Your milage may vary!\n\nThere is some additional context in https://github.com/ymgyt/tracing-cloudwatch/issues/40\n\n### With Rusoto\n\nfeature `rusoto` required\n\n```rust\nuse tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};\n\n#[tokio::main]\nasync fn main() {\n    let cw_client = rusoto_logs::CloudWatchLogsClient::new(rusoto_core::Region::ApNortheast1);\n\n    tracing_subscriber::registry::Registry::default()\n        .with(\n            tracing_cloudwatch::layer().with_client(\n                cw_client,\n                tracing_cloudwatch::ExportConfig::default()\n                    .with_batch_size(5)\n                    .with_interval(std::time::Duration::from_secs(1))\n                    .with_log_group_name(\"tracing-cloudwatch\")\n                    .with_log_stream_name(\"stream-1\"),\n            )\n            .with_code_location(true)\n            .with_target(false),\n        )\n        .init();\n}\n```\n\n### Using pre-configured `tracing_subsriber::fmt::Layer`\n\nYou can specify a pre-configured [`fmt::Layer`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Layer.html) to control the log format.\nFor example, the following example outputs the logs in JSON format.\n\n```rust\ntracing_subscriber::registry::Registry::default()\n    .with(tracing_cloudwatch::layer()\n        .with_fmt_layer(\n            tracing_subscriber::fmt::layer()\n                .json()\n                .without_time()\n        )\n    )\n    .init();\n```\n\n## Required Permissions\n\nCurrently, following AWS IAM Permissions required\n\n- `logs:PutLogEvents`\n\n## CloudWatch Log Groups and Streams\n\nThis 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.\n\n## Retry and Timeout\n\nWe haven't implemented any custom retry logic or timeout settings within the crate. We assume that these configurations are handled through the SDK Client.  \nFor 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)\n\n## License\n\nThis project is licensed under the [MIT license.](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymgyt%2Ftracing-cloudwatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fymgyt%2Ftracing-cloudwatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymgyt%2Ftracing-cloudwatch/lists"}