telemetry_rust/middleware/aws/operations/
sqs.rs1use http::Uri;
5
6use crate::{KeyValue, StringValue, semconv};
7
8use super::*;
9
10pub enum SqsSpanBuilder {}
16
17impl AwsSpanBuilder<'_> {
18 pub fn sqs(
29 operation_kind: MessagingOperationKind,
30 method: impl Into<StringValue>,
31 queue: Option<impl Into<StringValue>>,
32 ) -> Self {
33 let mut attributes = vec![
34 KeyValue::new(semconv::MESSAGING_SYSTEM, "aws_sqs"),
35 KeyValue::new(semconv::MESSAGING_OPERATION_TYPE, operation_kind.as_str()),
36 ];
37 if let Some(queue) = queue.map(Into::<StringValue>::into) {
38 let queue_url = queue.as_str().parse::<Uri>().ok();
39 let queue_name = queue_url
40 .as_ref()
41 .and_then(|uri| uri.path().split('/').next_back())
42 .unwrap_or(queue.as_str())
43 .to_owned();
44 attributes.push(KeyValue::new(
45 semconv::MESSAGING_DESTINATION_NAME,
46 queue_name,
47 ));
48 if queue_url.is_some() {
49 attributes.push(KeyValue::new("aws.sqs.queue.url", queue));
50 }
51 }
52 Self::new(operation_kind.into(), "SQS", method, attributes)
53 }
54}
55
56macro_rules! sqs_global_operation {
57 ($op: ident) => {
58 impl SqsSpanBuilder {
59 #[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " global operation.")]
60 #[inline]
61 pub fn $op<'a>() -> AwsSpanBuilder<'a> {
62 AwsSpanBuilder::sqs(
63 MessagingOperationKind::Control,
64 stringify_camel!($op),
65 None::<StringValue>,
66 )
67 }
68 }
69 };
70}
71
72macro_rules! sqs_messaging_operation {
73 ($op: ident, $kind: expr) => {
74 impl SqsSpanBuilder {
75 #[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " messaging operation.")]
76 pub fn $op<'a>(queue: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
81 AwsSpanBuilder::sqs($kind, stringify_camel!($op), Some(queue))
82 }
83 }
84 };
85}
86
87macro_rules! sqs_queue_operation {
88 ($op: ident) => {
89 impl SqsSpanBuilder {
90 #[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " queue operation.")]
91 pub fn $op<'a>(queue: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
96 AwsSpanBuilder::sqs(
97 MessagingOperationKind::Control,
98 stringify_camel!($op),
99 Some(queue),
100 )
101 }
102 }
103 };
104}
105
106sqs_messaging_operation!(receive_message, MessagingOperationKind::Receive);
108sqs_messaging_operation!(send_message, MessagingOperationKind::Send);
109sqs_messaging_operation!(send_message_batch, MessagingOperationKind::Send);
110
111sqs_queue_operation!(add_permission);
113sqs_queue_operation!(change_message_visibility);
114sqs_queue_operation!(change_message_visibility_batch);
115sqs_queue_operation!(create_queue);
116sqs_queue_operation!(delete_message);
117sqs_queue_operation!(delete_message_batch);
118sqs_queue_operation!(delete_queue);
119sqs_queue_operation!(get_queue_attributes);
120sqs_queue_operation!(get_queue_url);
121sqs_queue_operation!(list_dead_letter_source_queues);
122sqs_queue_operation!(list_queue_tags);
123sqs_queue_operation!(purge_queue);
124sqs_queue_operation!(remove_permission);
125sqs_queue_operation!(set_queue_attributes);
126sqs_queue_operation!(tag_queue);
127sqs_queue_operation!(untag_queue);
128
129sqs_global_operation!(cancel_message_move_task);
131sqs_global_operation!(list_message_move_tasks);
132sqs_global_operation!(list_queues);
133sqs_global_operation!(start_message_move_task);