Skip to main content

telemetry_rust/middleware/aws/operations/
mod.rs

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