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