Crates.io | tracing-s3 |
lib.rs | tracing-s3 |
version | 0.1.5 |
created_at | 2025-08-03 15:16:20.968244+00 |
updated_at | 2025-08-04 16:54:07.198082+00 |
description | AWS S3 (Express One) , sending trace logs to S3 |
homepage | |
repository | https://github.com/ohaddahan/tracing-s3.git |
max_upload_size | |
id | 1779803 |
size | 105,977 |
A Rust crate that provides a tracing layer for efficiently sending structured logs to AWS S3 Express One Zone buckets.
cargo add tracing-s3
use tracing_s3::{HttpLogLayer, TracingS3Config};
use tracing_s3::config::types::*;
use std::sync::Arc;
use tracing_subscriber::{layer::SubscriberExt, Registry};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Configure S3 logging
let config = TracingS3Config::new(
Some("us-west-2"), // AWS region
Some("your-access-key"), // AWS access key
Some("your-secret-key"), // AWS secret key
Bucket(Some("your-express-bucket")), // S3 Express bucket name
Prefix("app-logs"), // Log file prefix
Postfix("log"), // Log file extension
Endpoint(None), // Custom endpoint (optional)
ObjectSizeLimitMb::new(100)?, // Max file size in MB
CronIntervalInMs::new(5000)?, // Flush interval in ms
BufferSizeLimitKb::new(1024)?, // Buffer size in KB
).await?;
// Create the tracing layer
let s3_layer = HttpLogLayer::new(Arc::new(config));
// Set up tracing subscriber
let subscriber = Registry::default()
.with(s3_layer)
.with(tracing_subscriber::fmt::layer());
tracing::subscriber::set_global_default(subscriber)?;
// Your application code with tracing
tracing::info!("Application started");
tracing::warn!("This is a warning");
Ok(())
}
The crate supports the following environment variables:
S3_TRACING_AWS_REGION
- AWS region (default: "us-west-2")S3_TRACING_BUCKET
- S3 bucket nameS3_TRACING_AWS_ACCESS_KEY_ID
- AWS access key IDS3_TRACING_AWS_SECRET_ACCESS_KEY
- AWS secret access keyLogs are stored as JSON objects with the following structure:
{
"timestamp": "2024-01-01T12:00:00.000Z",
"level": "INFO",
"event": {
"fields": {
"message": "Your log message"
},
"target": "your_app",
"span": {
"name": "request_handler"
}
}
}
Log files are organized by date and partitioned when they exceed size limits:
2024-01-01/
├── 0/
│ └── app-logs-{uuid}.log
├── 1/
│ └── app-logs-{uuid}.log
└── ...