telemetry_rust/middleware/aws/operations/
mod.rs

1use opentelemetry::trace::SpanKind;
2
3pub(super) use super::AwsSpanBuilder;
4
5mod dynamodb;
6mod firehose;
7mod sns;
8mod sqs;
9
10pub use dynamodb::DynamodbSpanBuilder;
11pub use firehose::FirehoseSpanBuilder;
12pub use sns::SnsSpanBuilder;
13pub use sqs::SqsSpanBuilder;
14
15/// Messaging operation type
16///
17/// Represents well-known `messaging.operation.type` values from
18/// [Semantic conventions specification](https://opentelemetry.io/docs/specs/semconv/registry/attributes/messaging/).
19pub enum MessagingOperationKind {
20    /// A message is created. “Create” spans always refer to a single message
21    /// and are used to provide a unique creation context for messages in batch sending scenarios.
22    Create,
23    /// One or more messages are processed by a consumer.
24    Process,
25    /// One or more messages are requested by a consumer. This operation refers to pull-based scenarios,
26    /// where consumers explicitly call methods of messaging SDKs to receive messages.
27    Receive,
28    /// One or more messages are provided for sending to an intermediary.
29    /// If a single message is sent, the context of the “Send” span can be used as the creation context
30    /// and no “Create” span needs to be created.
31    Send,
32    /// One or more messages are settled.
33    Settle,
34    /// Custom value representing control operations over messaging resources.
35    Control,
36}
37
38impl MessagingOperationKind {
39    /// Returns the string representation of the operation kind.
40    ///
41    /// This follows OpenTelemetry semantic conventions for messaging operations.
42    pub fn as_str(&self) -> &'static str {
43        match self {
44            MessagingOperationKind::Create => "create",
45            MessagingOperationKind::Process => "process",
46            MessagingOperationKind::Receive => "receive",
47            MessagingOperationKind::Send => "send",
48            MessagingOperationKind::Settle => "settle",
49            MessagingOperationKind::Control => "control",
50        }
51    }
52}
53
54impl std::fmt::Display for MessagingOperationKind {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        self.as_str().fmt(f)
57    }
58}
59
60impl From<MessagingOperationKind> for SpanKind {
61    #[inline]
62    fn from(kind: MessagingOperationKind) -> Self {
63        match kind {
64            MessagingOperationKind::Create => SpanKind::Producer,
65            MessagingOperationKind::Process => SpanKind::Consumer,
66            MessagingOperationKind::Receive => SpanKind::Consumer,
67            MessagingOperationKind::Settle => SpanKind::Producer,
68            MessagingOperationKind::Send => SpanKind::Producer,
69            MessagingOperationKind::Control => SpanKind::Client,
70        }
71    }
72}
73
74macro_rules! stringify_camel {
75    ($var: ident) => {
76        paste::paste! { stringify!([<$var:camel>]) }
77    };
78}
79
80pub(super) use stringify_camel;