How do you trace issues across accounts with micro-services architecture?

We’re a small/medium team with

  • Several AWS accounts under one Org
  • 100+ SQS queues / SNS topics
  • Lambdas, ECS, and a few legacy bare-metal services
  • A bunch of API Gateway-fronted Lambdas

Whenever something breaks (messages in DLQ, 5xx, etc.) our general workflow looks like this:

  1. Sign in to the aws account.
  2. Find the DLQ.
  3. Find its primary queue.
  4. Figure out which producer sent the message (could be in a different account, could be lambda, ecs etc).
  5. if in different account → login to Account B.
  6. If Lambda → open the function → CloudWatch Logs → cloudwatch insights → search for the stack trace.
  7. If ECS → find the service / task → Logs → CloudWatch → insights.
  8. If that Lambda/ecs then calls an API Gateway or pushes to another queue in same or different account … repeat the steps.

It takes forever to figure out the underline root cause hoping from one account to account or sometimes even within same account.

I am curious if there’s a better way?


Related discussions:

Neat trick: Use AWS SNS to get a text message when a process completes
SQS lambda trigger now showing up!
AWS Expertise Needed: Looking to built an audio streaming service
Enterprise Service Bus == SNS/Attributes -> Subscriptions/Filters -> SQS consumers???
Can I send SMS to SNS and trigger a webhook or API GW endpoint?
Event bus, kinesis or sns + sqs?
Create CloudWatch Alarm for EC2 running over 2hr?
What are the use-cases for SQS short polling?
Are AWS SNS messages lost if the SNS topic's availability zone goes down, and how can I mitigate this?
S3 Event - SQS - worker architecture: How to replay old files
S3 Event Notifications - SNS
Long-Polling ReceiveMessage on SQS and false empty responses
Worldwide SMS for SNS now available
Amazon SNS now supports Attribute-based access controls (ABAC)
Conditionally rate-limiting an SQS queue based on a message's contents?
SQS Job Progress Bar
CIS 3.1 – is there a more unhelpfully useless alarm than this?
SQS as a Service - I've built a prototype over the weekend
Certificate Management for multiple customer domains for the same Cluster
Reason NOT to put FIFO SQS in front all async lambdas?
What are the CloudFormation options multiple-identical resource pipeline
Advice on lambda scaling improvement strategy
Why are they using EventBridge here, instead of CloudWatch + SNS?
IAM policy to send SMS through SNS
Why is the SQS queue search in the console by prefix only
CodeCommit to Slack
Is the SWF and SQS relationship similar to Celery and RabbitMQ?
Practical applications for SQS?
Lambda and DLQs during intermittent failures
Use SQS with CF and without Lambda?
Question about spot instances, termination warning?
Possible to publish all Cloudtrail events to a SNS topic?

Check out OpenTelemetry. Created for this use case.

Welcome to AWS jungle , your organisation need centralised log metrics and trace solutions

Xray

I am curious if there’s a better way?

Yes. Don’t use microservices. Especially if you’re a “small/medium” team.

If something’s failing in one service then you should know about it there and then.

If you have an account team, ask the SA to help you with an observability strategy.

Not the only solution, but most people will simply have a central log cluster (e.g. elastic stack with Kibana) and also a central cluster for metrics (e.g. Grafana), or use a third party like Datadog.

Sounds like you could benefit from Cloud watch’s cross account metrics and logs sharing feature. So you basically dedicate one monitoring account and let other accounts share their CW. As I recall the feature doesn’t even cost any extra.

Centralised logging, metrics and traces with something like new relic or datadog is how I’ve generally done it most places.

Can easily be done with Cloud Watch as well… no need to bring in 3rd party solutions if you don’t want to…

Each queue message and API request context should carry a trace ID in a unified manner, in the following ways:

Automatically extract and record X-Amzn-Trace-Id in each Lambda.

Add trace id as messageAttribute in SQS producer.

All log outputs must include trace id (implemented by wrapper or middleware).

This way you can:

Use trace id to search globally in Kibana / Datadog Logs / CloudWatch Insights.

Quickly locate “where the message comes from, what service it passes through, and where it fails”.

in addition to the other comments here, I’d also suggest using a correlationId or sessionId in all payloads. Say a UUIDv4.

We generate these at the earliest opportunity (either on the client passed into a REST endpoint and propagated from there, or, for back-end initiated processes, they create their own and send it on to logs, queues, etc).

Once you have this, all systems/lambdas/logs/queues/topics should propagate it downstream if they get it, and log it whenever there’s a problem (or even if there’s not).

Then, in your log aggregation tool you can just paste this id and it should just pull up all logs that have a match for it. This’ll make it easy to see the entire flow from beginning to end.

This sounds like great advice! Do you use cloudwatch for logging?

You could also introduce a central orchestrator like temporal or orbits.do (though that might be a bit of a stretch depending on how close it is to your current architecture) (disclaimer: working at orbits.do).
Such a way, you could manage the call to your microservices from one centralized place and have logs and traces from a central place, which can simplify debugging and monitoring.

Do you use AWS X-Ray (or some other distributed tracing solution?). That’s essentially what you’re looking for.

Yup.

Yeah you can, is why I said it is how I usually do it. I much prefer to do it with an external tool than cloudwatch personally.

As mentioned, OpenTelemetry with context propagation on the app side. For traces you can use Grafana and tempo.