tracing_s3/config/types.rs
1use anyhow::anyhow;
2
3/// Represents a buffer size limit in kilobytes.
4/// Used to control the maximum amount of log data to buffer in memory before flushing to S3.
5pub struct BufferSizeLimitKb(u64);
6
7impl BufferSizeLimitKb {
8 /// Creates a new BufferSizeLimitKb instance.
9 ///
10 /// # Arguments
11 /// * `size_limit` - The buffer size limit in kilobytes (1-50,000 KB)
12 ///
13 /// # Returns
14 /// * `Ok(BufferSizeLimitKb)` - If the size limit is valid
15 /// * `Err(anyhow::Error)` - If the size limit is 0 or greater than 50,000 KB
16 pub fn new(size_limit: u64) -> anyhow::Result<Self> {
17 if size_limit == 0 {
18 return Err(anyhow!("Value must be larger than 0"));
19 } else if size_limit > 50_000 {
20 return Err(anyhow!("Value must be smaller than 50,000 (50MB)"));
21 }
22 Ok(Self(size_limit))
23 }
24
25 /// Returns the inner buffer size limit value in kilobytes.
26 pub fn inner(&self) -> u64 {
27 self.0
28 }
29}
30
31/// Represents an object size limit in megabytes.
32/// Used to control the maximum size of individual log files in S3 before creating a new part.
33pub struct ObjectSizeLimitMb(u64);
34
35impl ObjectSizeLimitMb {
36 /// Creates a new ObjectSizeLimitMb instance.
37 ///
38 /// # Arguments
39 /// * `size_limit` - The object size limit in megabytes (1-50,000 MB)
40 ///
41 /// # Returns
42 /// * `Ok(ObjectSizeLimitMb)` - If the size limit is valid
43 /// * `Err(anyhow::Error)` - If the size limit is 0 or greater than 50,000 MB
44 pub fn new(size_limit: u64) -> anyhow::Result<Self> {
45 if size_limit == 0 {
46 return Err(anyhow!("Value must be larger than 0"));
47 } else if size_limit > 50_000 {
48 return Err(anyhow!("Value must be smaller than 50,000 (50GB)"));
49 }
50 Ok(Self(size_limit))
51 }
52
53 /// Returns the inner object size limit value in megabytes.
54 pub fn inner(&self) -> u64 {
55 self.0
56 }
57}
58
59/// Represents a cron interval in milliseconds.
60/// Used to control how frequently the background task flushes buffered logs to S3.
61pub struct CronIntervalInMs(u64);
62
63impl CronIntervalInMs {
64 /// Creates a new CronIntervalInMs instance.
65 ///
66 /// # Arguments
67 /// * `interval` - The cron interval in milliseconds (must be greater than 0)
68 ///
69 /// # Returns
70 /// * `Ok(CronIntervalInMs)` - If the interval is valid
71 /// * `Err(anyhow::Error)` - If the interval is 0
72 pub fn new(interval: u64) -> anyhow::Result<Self> {
73 if interval == 0 {
74 return Err(anyhow!("Value must be larger than 0"));
75 }
76 Ok(Self(interval))
77 }
78
79 /// Returns the inner cron interval value in milliseconds.
80 pub fn inner(&self) -> u64 {
81 self.0
82 }
83}
84
85/// Represents an S3 bucket name.
86/// Can be provided directly or resolved from environment variables.
87pub struct Bucket<'a>(pub Option<&'a str>);
88
89/// Represents a prefix for log file names.
90/// Used to organize and identify log files in the S3 bucket.
91pub struct Prefix<'a>(pub &'a str);
92
93/// Represents a postfix/extension for log file names.
94/// Typically used for file extensions like "log" / "json" / "jsonl".
95pub struct Postfix<'a>(pub &'a str);
96
97/// Represents a custom S3 endpoint URL.
98/// Optional parameter for using custom S3-compatible endpoints.
99pub struct Endpoint<'a>(pub Option<&'a str>);