use http::Uri;
use crate::{KeyValue, StringValue, semconv};
use super::*;
pub enum SqsSpanBuilder {}
impl AwsSpanBuilder<'_> {
pub fn sqs(
operation_kind: MessagingOperationKind,
method: impl Into<StringValue>,
queue: Option<impl Into<StringValue>>,
) -> Self {
let mut attributes = vec![
KeyValue::new(semconv::MESSAGING_SYSTEM, "aws_sqs"),
KeyValue::new(semconv::MESSAGING_OPERATION_TYPE, operation_kind.as_str()),
];
if let Some(queue) = queue.map(Into::<StringValue>::into) {
let queue_url = queue.as_str().parse::<Uri>().ok();
let queue_name = queue_url
.as_ref()
.and_then(|uri| uri.path().split('/').next_back())
.unwrap_or(queue.as_str())
.to_owned();
attributes.push(KeyValue::new(
semconv::MESSAGING_DESTINATION_NAME,
queue_name,
));
if queue_url.is_some() {
attributes.push(KeyValue::new("aws.sqs.queue.url", queue));
}
}
Self::new(operation_kind.into(), "SQS", method, attributes)
}
}
macro_rules! sqs_global_operation {
($op: ident) => {
impl SqsSpanBuilder {
#[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " global operation.")]
#[inline]
pub fn $op<'a>() -> AwsSpanBuilder<'a> {
AwsSpanBuilder::sqs(
MessagingOperationKind::Control,
stringify_camel!($op),
None::<StringValue>,
)
}
}
};
}
macro_rules! sqs_messaging_operation {
($op: ident, $kind: expr) => {
impl SqsSpanBuilder {
#[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " messaging operation.")]
pub fn $op<'a>(queue: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
AwsSpanBuilder::sqs($kind, stringify_camel!($op), Some(queue))
}
}
};
}
macro_rules! sqs_queue_operation {
($op: ident) => {
impl SqsSpanBuilder {
#[doc = concat!("Creates a span builder for the SQS ", stringify!($op), " queue operation.")]
pub fn $op<'a>(queue: impl Into<StringValue>) -> AwsSpanBuilder<'a> {
AwsSpanBuilder::sqs(
MessagingOperationKind::Control,
stringify_camel!($op),
Some(queue),
)
}
}
};
}
sqs_messaging_operation!(receive_message, MessagingOperationKind::Receive);
sqs_messaging_operation!(send_message, MessagingOperationKind::Send);
sqs_messaging_operation!(send_message_batch, MessagingOperationKind::Send);
sqs_queue_operation!(add_permission);
sqs_queue_operation!(change_message_visibility);
sqs_queue_operation!(change_message_visibility_batch);
sqs_queue_operation!(create_queue);
sqs_queue_operation!(delete_message);
sqs_queue_operation!(delete_message_batch);
sqs_queue_operation!(delete_queue);
sqs_queue_operation!(get_queue_attributes);
sqs_queue_operation!(get_queue_url);
sqs_queue_operation!(list_dead_letter_source_queues);
sqs_queue_operation!(list_queue_tags);
sqs_queue_operation!(purge_queue);
sqs_queue_operation!(remove_permission);
sqs_queue_operation!(set_queue_attributes);
sqs_queue_operation!(tag_queue);
sqs_queue_operation!(untag_queue);
sqs_global_operation!(cancel_message_move_task);
sqs_global_operation!(list_message_move_tasks);
sqs_global_operation!(list_queues);
sqs_global_operation!(start_message_move_task);