A Rust example demonstrating AWS SNS → SQS messaging with OpenTelemetry distributed tracing propagated via message attributes. Traces are sent to Datadog.
This project includes:
- Producer: Publishes messages to an SNS topic, injecting trace context into message attributes
- Consumer: Polls messages from an SQS queue (subscribed to the SNS topic), extracting and continuing the trace context
- opentelemetry-aws-messaging: A small crate providing
Injector/Extractorimplementations for SNS and SQS message attributes
- Rust toolchain
- AWS CLI configured with SSO or credentials
AWS_PROFILEenvironment variable set
export AWS_PROFILE=your-profile
./setup.shThis creates:
- An SNS topic and SQS queue (names defined in
setup.sh) - A subscription linking them (with raw message delivery enabled)
- A
.envfile with the resource ARNs
Simple pub/sub demo (no tracing, publishes 3 messages then consumes them):
./run.shWith distributed tracing (run producer and consumer in separate terminals):
Terminal 1:
./run-consumer.shTerminal 2:
./run-producer.shType messages in the producer terminal and see them received in the consumer with linked traces in Datadog.
./cleanup.sh| Variable | Description |
|---|---|
AWS_PROFILE |
AWS CLI profile to use |
SNS_TOPIC_ARN |
ARN of the SNS topic (set by setup.sh) |
SQS_QUEUE_URL |
URL of the SQS queue (set by setup.sh) |
DD_SERVICE |
Datadog service name (set by run scripts) |
DD_LOG_LEVEL |
Set to DEBUG to enable verbose logging from the Datadog tracing library |
| Script | Description |
|---|---|
setup.sh |
Creates SNS topic, SQS queue, subscription with raw message delivery, queue policy, and generates .env file. Runs a test message to verify setup. |
run.sh |
Runs the simple pub/sub demo without tracing (src/main.rs) |
run-producer.sh |
Runs the interactive producer with DD_SERVICE=sns-producer |
run-consumer.sh |
Runs the consumer with DD_SERVICE=sns-consumer |
cleanup.sh |
Deletes SNS subscriptions, topic, SQS queue, and removes .env file |
├── src/
│ ├── main.rs # Simple pub/sub demo (no tracing)
│ ├── producer.rs # Interactive SNS publisher with tracing
│ └── consumer.rs # SQS consumer with tracing
├── opentelemetry-aws-messaging/
│ ├── src/
│ │ ├── lib.rs # Library exports
│ │ ├── sns.rs # SNS message attributes injector
│ │ └── sqs.rs # SQS message attributes extractor
│ └── Cargo.toml
├── setup.sh
├── cleanup.sh
├── run.sh
├── run-producer.sh
└── run-consumer.sh