telemetry_rust/middleware/aws/operations/
sns.rs

1/// AWS SNS operations
2///
3/// API Reference: https://docs.aws.amazon.com/sns/latest/api/API_Operations.html
4use crate::{KeyValue, StringValue, semconv};
5
6use super::*;
7
8/// Builder for SNS-specific OpenTelemetry spans.
9///
10/// This enum serves as a namespace for SNS operation span builders.
11/// Each operation provides a specific method to create properly configured
12/// spans with SNS-specific messaging attributes.
13pub enum SnsSpanBuilder {}
14
15impl AwsSpanBuilder<'_> {
16    /// Creates an SNS operation span builder.
17    ///
18    /// This method creates a span builder configured for SNS operations with
19    /// appropriate messaging semantic attributes.
20    ///
21    /// # Arguments
22    ///
23    /// * `operation_kind` - The type of messaging operation being performed
24    /// * `method` - The SNS operation method name
25    /// * `topic_arn` - Optional topic ARN for operations that target specific topics
26    pub fn sns(
27        operation_kind: MessagingOperationKind,
28        method: impl Into<StringValue>,
29        topic_arn: Option<impl Into<StringValue>>,
30    ) -> Self {
31        let mut attributes = vec![
32            KeyValue::new(semconv::MESSAGING_SYSTEM, "aws_sns"),
33            KeyValue::new(semconv::MESSAGING_OPERATION_TYPE, operation_kind.as_str()),
34        ];
35        if let Some(topic_arn) = topic_arn {
36            attributes.push(KeyValue::new(
37                semconv::MESSAGING_DESTINATION_NAME,
38                topic_arn.into(),
39            ))
40        }
41        Self::new(operation_kind.into(), "SNS", method, attributes)
42    }
43}
44
45macro_rules! sns_global_operation {
46    ($op: ident) => {
47        impl SnsSpanBuilder {
48            #[doc = concat!("Creates a span builder for the SNS ", stringify!($op), " global operation.")]
49            #[inline]
50            pub fn $op<'a>() -> AwsSpanBuilder<'a> {
51                AwsSpanBuilder::sns(
52                    MessagingOperationKind::Control,
53                    stringify_camel!($op),
54                    None::<StringValue>,
55                )
56            }
57        }
58    };
59}
60
61macro_rules! sns_publish_operation {
62    ($op: ident, $kind: expr) => {
63        impl SnsSpanBuilder {
64            #[doc = concat!("Creates a span builder for the SNS ", stringify!($op), " operation.")]
65            ///
66            /// # Arguments
67            ///
68            /// * `topic_arn` - The ARN of the SNS topic
69            pub fn $op<'a>(topic_arn: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
70                AwsSpanBuilder::sns($kind, stringify_camel!($op), Some(topic_arn))
71            }
72        }
73    };
74}
75
76macro_rules! sns_topic_operation {
77    ($op: ident) => {
78        impl SnsSpanBuilder {
79            #[doc = concat!("Creates a span builder for the SNS ", stringify!($op), " topic operation.")]
80            ///
81            /// # Arguments
82            ///
83            /// * `topic_arn` - The ARN of the SNS topic
84            pub fn $op<'a>(topic_arn: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
85                AwsSpanBuilder::sns(
86                    MessagingOperationKind::Control,
87                    stringify_camel!($op),
88                    Some(topic_arn),
89                )
90            }
91        }
92    };
93}
94
95// publish operation
96sns_publish_operation!(publish, MessagingOperationKind::Create);
97sns_publish_operation!(publish_batch, MessagingOperationKind::Send);
98
99// global operations
100sns_global_operation!(check_if_phone_number_is_opted_out);
101sns_global_operation!(create_platform_application);
102sns_global_operation!(create_platform_endpoint);
103sns_global_operation!(create_sms_sandbox_phone_number);
104sns_global_operation!(create_topic);
105sns_global_operation!(delete_endpoint);
106sns_global_operation!(delete_platform_application);
107sns_global_operation!(delete_sms_sandbox_phone_number);
108sns_global_operation!(get_data_protection_policy);
109sns_global_operation!(get_endpoint_attributes);
110sns_global_operation!(get_platform_application_attributes);
111sns_global_operation!(get_sms_attributes);
112sns_global_operation!(get_sms_sandbox_account_status);
113sns_global_operation!(get_subscription_attributes);
114sns_global_operation!(list_endpoints_by_platform_application);
115sns_global_operation!(list_origination_numbers);
116sns_global_operation!(list_phone_numbers_opted_out);
117sns_global_operation!(list_platform_applications);
118sns_global_operation!(list_sms_sandbox_phone_numbers);
119sns_global_operation!(list_subscriptions);
120sns_global_operation!(list_tags_for_resource);
121sns_global_operation!(list_topics);
122sns_global_operation!(opt_in_phone_number);
123sns_global_operation!(put_data_protection_policy);
124sns_global_operation!(set_endpoint_attributes);
125sns_global_operation!(set_platform_application_attributes);
126sns_global_operation!(set_sms_attributes);
127sns_global_operation!(set_subscription_attributes);
128sns_global_operation!(tag_resource);
129sns_global_operation!(unsubscribe);
130sns_global_operation!(untag_resource);
131sns_global_operation!(verify_sms_sandbox_phone_number);
132
133// control plane topic operations
134sns_topic_operation!(add_permission);
135sns_topic_operation!(confirm_subscription);
136sns_topic_operation!(delete_topic);
137sns_topic_operation!(get_topic_attributes);
138sns_topic_operation!(list_subscriptions_by_topic);
139sns_topic_operation!(remove_permission);
140sns_topic_operation!(set_topic_attributes);
141sns_topic_operation!(subscribe);