Skip to main content

telemetry_rust/middleware/aws/operations/
s3.rs

1/// AWS S3 operations
2///
3/// API Reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations_Amazon_Simple_Storage_Service.html
4use crate::{KeyValue, StringValue, semconv};
5
6use super::*;
7
8/// Builder for S3-specific OpenTelemetry spans.
9///
10/// This enum serves as a namespace for S3 operation span builders.
11/// Each operation provides a specific method to create properly configured
12/// spans with S3-specific attributes following OpenTelemetry semantic conventions
13/// for object stores.
14pub enum S3SpanBuilder {}
15
16impl AwsSpanBuilder<'_> {
17    /// Creates an S3 operation span builder.
18    ///
19    /// This method creates a span builder configured for S3 operations with
20    /// appropriate semantic attributes according to OpenTelemetry conventions
21    /// for object stores.
22    ///
23    /// # Arguments
24    ///
25    /// * `method` - The S3 operation method name (e.g., "GetObject", "PutObject")
26    /// * `bucket` - Optional bucket name for operations that target specific buckets
27    /// * `key` - Optional object key for operations that target specific objects
28    pub fn s3(
29        method: impl Into<StringValue>,
30        bucket: Option<impl Into<StringValue>>,
31        key: Option<impl Into<StringValue>>,
32    ) -> Self {
33        let mut attributes = Vec::new();
34        if let Some(bucket) = bucket {
35            attributes.push(KeyValue::new(semconv::AWS_S3_BUCKET, bucket.into()));
36        }
37        if let Some(key) = key {
38            attributes.push(KeyValue::new(semconv::AWS_S3_KEY, key.into()));
39        }
40        Self::client("S3", method, attributes)
41    }
42}
43
44macro_rules! s3_global_operation {
45    ($op: ident) => {
46        impl S3SpanBuilder {
47            #[doc = concat!("Creates a span builder for the S3 ", stringify!($op), " global operation.")]
48            #[inline]
49            pub fn $op<'a>() -> AwsSpanBuilder<'a> {
50                AwsSpanBuilder::s3(
51                    stringify_camel!($op),
52                    None::<StringValue>,
53                    None::<StringValue>,
54                )
55            }
56        }
57    };
58}
59
60macro_rules! s3_bucket_operation {
61    ($op: ident) => {
62        impl S3SpanBuilder {
63            #[doc = concat!("Creates a span builder for the S3 ", stringify!($op), " bucket operation.")]
64            ///
65            /// # Arguments
66            ///
67            /// * `bucket` - The name of the S3 bucket
68            pub fn $op<'a>(bucket: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
69                AwsSpanBuilder::s3(
70                    stringify_camel!($op),
71                    Some(bucket),
72                    None::<StringValue>,
73                )
74            }
75        }
76    };
77}
78
79macro_rules! s3_object_operation {
80    ($op: ident) => {
81        impl S3SpanBuilder {
82            #[doc = concat!("Creates a span builder for the S3 ", stringify!($op), " object operation.")]
83            ///
84            /// # Arguments
85            ///
86            /// * `bucket` - The name of the S3 bucket
87            /// * `key` - The key of the S3 object
88            pub fn $op<'a>(
89                bucket: impl Into<StringValue>,
90                key: impl Into<StringValue>,
91            ) -> AwsSpanBuilder<'a> {
92                AwsSpanBuilder::s3(stringify_camel!($op), Some(bucket), Some(key))
93            }
94        }
95    };
96}
97
98// global operations
99s3_global_operation!(list_buckets);
100s3_global_operation!(list_directory_buckets);
101
102// bucket management operations
103s3_bucket_operation!(create_bucket);
104s3_bucket_operation!(delete_bucket);
105s3_bucket_operation!(head_bucket);
106s3_bucket_operation!(create_session);
107
108// object data operations
109s3_object_operation!(copy_object);
110s3_object_operation!(delete_object);
111s3_object_operation!(get_object);
112s3_object_operation!(head_object);
113s3_object_operation!(put_object);
114s3_object_operation!(rename_object);
115s3_object_operation!(restore_object);
116s3_object_operation!(select_object_content);
117s3_object_operation!(get_object_torrent);
118
119// batch delete operation
120s3_bucket_operation!(delete_objects);
121
122// object listing operations
123s3_bucket_operation!(list_objects);
124s3_bucket_operation!(list_objects_v2);
125s3_bucket_operation!(list_object_versions);
126
127// multipart upload operations
128s3_object_operation!(create_multipart_upload);
129s3_object_operation!(upload_part);
130s3_object_operation!(upload_part_copy);
131s3_object_operation!(complete_multipart_upload);
132s3_object_operation!(abort_multipart_upload);
133s3_bucket_operation!(list_multipart_uploads);
134s3_object_operation!(list_parts);
135
136// object ACL operations
137s3_object_operation!(get_object_acl);
138s3_object_operation!(put_object_acl);
139s3_object_operation!(get_object_attributes);
140
141// object tagging operations
142s3_object_operation!(get_object_tagging);
143s3_object_operation!(put_object_tagging);
144s3_object_operation!(delete_object_tagging);
145
146// object lock and retention operations
147s3_object_operation!(get_object_legal_hold);
148s3_object_operation!(put_object_legal_hold);
149s3_object_operation!(get_object_retention);
150s3_object_operation!(put_object_retention);
151s3_bucket_operation!(get_object_lock_configuration);
152s3_bucket_operation!(put_object_lock_configuration);
153
154// bucket ACL and policy operations
155s3_bucket_operation!(get_bucket_acl);
156s3_bucket_operation!(put_bucket_acl);
157s3_bucket_operation!(get_bucket_policy);
158s3_bucket_operation!(put_bucket_policy);
159s3_bucket_operation!(delete_bucket_policy);
160s3_bucket_operation!(get_bucket_policy_status);
161
162// bucket CORS operations
163s3_bucket_operation!(get_bucket_cors);
164s3_bucket_operation!(put_bucket_cors);
165s3_bucket_operation!(delete_bucket_cors);
166
167// bucket encryption operations
168s3_bucket_operation!(get_bucket_encryption);
169s3_bucket_operation!(put_bucket_encryption);
170s3_bucket_operation!(delete_bucket_encryption);
171
172// bucket lifecycle operations
173s3_bucket_operation!(get_bucket_lifecycle_configuration);
174s3_bucket_operation!(put_bucket_lifecycle_configuration);
175s3_bucket_operation!(delete_bucket_lifecycle);
176
177// bucket replication operations
178s3_bucket_operation!(get_bucket_replication);
179s3_bucket_operation!(put_bucket_replication);
180s3_bucket_operation!(delete_bucket_replication);
181
182// bucket tagging operations
183s3_bucket_operation!(get_bucket_tagging);
184s3_bucket_operation!(put_bucket_tagging);
185s3_bucket_operation!(delete_bucket_tagging);
186
187// bucket versioning operations
188s3_bucket_operation!(get_bucket_versioning);
189s3_bucket_operation!(put_bucket_versioning);
190
191// bucket website operations
192s3_bucket_operation!(get_bucket_website);
193s3_bucket_operation!(put_bucket_website);
194s3_bucket_operation!(delete_bucket_website);
195
196// bucket logging operations
197s3_bucket_operation!(get_bucket_logging);
198s3_bucket_operation!(put_bucket_logging);
199
200// bucket notification operations
201s3_bucket_operation!(get_bucket_notification_configuration);
202s3_bucket_operation!(put_bucket_notification_configuration);
203
204// bucket location operations
205s3_bucket_operation!(get_bucket_location);
206
207// bucket accelerate operations
208s3_bucket_operation!(get_bucket_accelerate_configuration);
209s3_bucket_operation!(put_bucket_accelerate_configuration);
210
211// bucket request payment operations
212s3_bucket_operation!(get_bucket_request_payment);
213s3_bucket_operation!(put_bucket_request_payment);
214
215// bucket ownership controls
216s3_bucket_operation!(get_bucket_ownership_controls);
217s3_bucket_operation!(put_bucket_ownership_controls);
218s3_bucket_operation!(delete_bucket_ownership_controls);
219
220// bucket analytics configuration operations
221s3_bucket_operation!(get_bucket_analytics_configuration);
222s3_bucket_operation!(put_bucket_analytics_configuration);
223s3_bucket_operation!(delete_bucket_analytics_configuration);
224s3_bucket_operation!(list_bucket_analytics_configurations);
225
226// bucket intelligent tiering configuration operations
227s3_bucket_operation!(get_bucket_intelligent_tiering_configuration);
228s3_bucket_operation!(put_bucket_intelligent_tiering_configuration);
229s3_bucket_operation!(delete_bucket_intelligent_tiering_configuration);
230s3_bucket_operation!(list_bucket_intelligent_tiering_configurations);
231
232// bucket inventory configuration operations
233s3_bucket_operation!(get_bucket_inventory_configuration);
234s3_bucket_operation!(put_bucket_inventory_configuration);
235s3_bucket_operation!(delete_bucket_inventory_configuration);
236s3_bucket_operation!(list_bucket_inventory_configurations);
237
238// bucket metrics configuration operations
239s3_bucket_operation!(get_bucket_metrics_configuration);
240s3_bucket_operation!(put_bucket_metrics_configuration);
241s3_bucket_operation!(delete_bucket_metrics_configuration);
242s3_bucket_operation!(list_bucket_metrics_configurations);
243
244// public access block operations
245s3_bucket_operation!(get_public_access_block);
246s3_bucket_operation!(put_public_access_block);
247s3_bucket_operation!(delete_public_access_block);
248
249// bucket metadata operations
250s3_bucket_operation!(create_bucket_metadata_configuration);
251s3_bucket_operation!(create_bucket_metadata_table_configuration);
252s3_bucket_operation!(delete_bucket_metadata_configuration);
253s3_bucket_operation!(delete_bucket_metadata_table_configuration);
254s3_bucket_operation!(get_bucket_metadata_configuration);
255s3_bucket_operation!(get_bucket_metadata_table_configuration);
256s3_bucket_operation!(update_bucket_metadata_inventory_table_configuration);
257s3_bucket_operation!(update_bucket_metadata_journal_table_configuration);
258
259// S3 Object Lambda operation
260s3_global_operation!(write_get_object_response);