Skip to main content

telemetry_rust/middleware/aws/operations/
mod.rs

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