telemetry_rust/middleware/aws/operations/
sns.rs

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