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