telemetry_rust/middleware/aws/operations/
mod.rs

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