Distributed Tracing with X-Ray, Application Signals and Synthetics
Overview
Metrics tell you that something is slow; logs tell you what a component said; traces tell you where in a chain of services the time went. AWS X-Ray follows a single request across load balancers, APIs, Lambda functions, containers and databases and draws a service map with latency and error rates for each hop.
Think of a parcel with a tracking number. Each depot scans it and records the time. When delivery is late you read the scans and see that the parcel sat for two days at depot four. X-Ray is the tracking system; CloudWatch Application Signals adds service-level objectives on top, and CloudWatch Synthetics sends a fake customer through your application every few minutes to catch problems before real customers do.
For SOA-C03 you should know how to enable tracing for serverless, compute and container workloads and use the output to find bottlenecks.
Key Concepts
- Trace = one request; made of segments (per service) and subsegments (downstream calls, SQL queries). A trace ID is propagated in the
X-Amzn-Trace-Idheader. - Service map visualises nodes and edges with latency, error, fault and throttle percentages; trace analytics and groups filter by annotations.
- Instrumentation: X-Ray SDK, or preferably AWS Distro for OpenTelemetry (ADOT) with the X-Ray exporter; the X-Ray daemon (or ADOT collector) forwards segments.
- Lambda active tracing is a function setting (
--tracing-config Mode=Active); API Gateway stages and Step Functions also have a tracing toggle; ALB adds the trace header. - Sampling rules control cost: default is the first request each second plus 5% of additional requests; customise by service, URL and rate.
- CloudWatch Application Signals auto-instruments supported runtimes on EKS, ECS, EC2 and Lambda to show golden signals and SLOs.
- CloudWatch Synthetics canaries are scripts (Node.js or Python, Selenium or Puppeteer) that run on a schedule to test endpoints, APIs and user flows, with alarms on failure.
- CloudWatch RUM collects real-user browser performance; ServiceLens / Application Signals connect traces, logs and metrics in a single view.
Detailed Notes
Which tool answers which question
| Question | Tool |
|---|---|
| Which downstream call is slowing this API? | X-Ray trace and service map |
| Is the service meeting its latency/availability objective? | Application Signals SLOs |
| Is the login page up right now from outside? | Synthetics canary |
| How do real browsers experience the site? | CloudWatch RUM |
| What error did the code log? | CloudWatch Logs Insights |
Enabling tracing
| Compute | How to enable |
|---|---|
| Lambda | aws lambda update-function-configuration --function-name f --tracing-config Mode=Active; execution role needs AWSXRayDaemonWriteAccess (or xray:PutTraceSegments and xray:PutTelemetryRecords) |
| API Gateway (REST) | Stage setting Enable X-Ray tracing |
| ECS | Run the ADOT / X-Ray daemon sidecar; task role needs X-Ray write permissions; expose UDP/2000 for the daemon |
| EKS | Deploy the ADOT add-on or CloudWatch Observability add-on with Application Signals |
| EC2 / on-premises | Install the X-Ray daemon or ADOT collector; instance role with write access |
| Elastic Beanstalk | Option setting XRayEnabled |
aws lambda update-function-configuration --function-name orders --tracing-config Mode=Active
aws xray get-service-graph --start-time 2025-01-01T00:00:00Z --end-time 2025-01-01T01:00:00Z
aws xray get-trace-summaries --start-time 2025-01-01T00:00:00Z --end-time 2025-01-01T01:00:00Z \
--filter-expression 'responsetime > 2 AND service("orders")'
from aws_xray_sdk.core import xray_recorder, patch_all
patch_all() # instruments boto3, requests, SQL drivers
@xray_recorder.capture("calculate_total")
def calculate_total(order):
xray_recorder.current_subsegment().put_annotation("customer_tier", order.tier)
return sum(i.price for i in order.items)
Annotations are indexed key-value pairs you can filter on; metadata is not indexed.
Sampling and cost
Custom sampling rules (JSON) define reservoir and fixed rate:
{ "SamplingRule": { "RuleName": "checkout", "Priority": 10, "FixedRate": 0.2, "ReservoirSize": 5,
"ServiceName": "checkout", "ServiceType": "*", "Host": "*", "HTTPMethod": "POST", "URLPath": "/checkout/*",
"ResourceARN": "*", "Version": 1 } }
Raise the rate for critical paths and lower it for noisy health checks.
Synthetics canaries
aws synthetics create-canary --name login-check --artifact-s3-location s3://ops-canary-artifacts/ \
--execution-role-arn arn:aws:iam::111122223333:role/CanaryRole --schedule Expression="rate(5 minutes)" \
--runtime-version syn-nodejs-puppeteer-9.1 --code Handler=index.handler,S3Bucket=ops-canary-code,S3Key=login.zip
A canary publishes SuccessPercent and Duration metrics to the CloudWatchSynthetics namespace. Alarm on SuccessPercent < 100 for two datapoints and attach an SNS action. Canaries support heartbeat, API, broken-link and visual blueprints, and can run in a VPC to test private endpoints.
Troubleshooting tracing
| Problem | Cause |
|---|---|
| No traces from Lambda | Active tracing off, or role lacks X-Ray write permissions |
| Broken service map between services | Trace header not propagated (custom HTTP client, SQS without trace header support) |
| Missing traces on container | Daemon sidecar not reachable, UDP 2000 blocked, wrong region |
| Few traces visible | Sampling rate too low for the traffic level |
Real World Example
Scenario – intermittent checkout latency. Customers occasionally wait 8 seconds at checkout, yet every individual service shows healthy averages. The operator enables active tracing on API Gateway and Lambda, and adds ADOT sidecars to the ECS payment service.
The X-Ray service map shows 2% of requests spend 7 seconds in a call to a third-party fraud API, with retries. Application Signals now holds an SLO of 99% of checkouts under 2 seconds, and a Synthetics canary runs the full purchase flow every 5 minutes. The team adds a timeout and circuit breaker, and the alarm on canary SuccessPercent pages them before customers notice similar issues.
Architecture Diagram
- 1A request enters API Gateway, which adds a trace ID header.
- 2Lambda and downstream calls emit segments and subsegments.
- 3X-Ray assembles a trace and updates the service map.
- 4Application Signals evaluates SLOs from the same telemetry.
- 5Synthetics canaries and alarms catch regressions before users do.
Best Practices
- ✓Prefer ADOT / OpenTelemetry instrumentation for portability and auto-instrumentation.
- ✓Enable active tracing on Lambda, API Gateway and Step Functions in production; grant only X-Ray write permissions.
- ✓Tune sampling rules per route to balance visibility and cost.
- ✓Add annotations (customer tier, order type) so traces are searchable.
- ✓Run Synthetics canaries for critical user journeys and alarm on
SuccessPercent.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Find the slow hop in a microservice chain -> X-Ray service map.
- Lambda tracing -> Active tracing plus X-Ray permissions on the execution role.
- Proactive scripted checks of a website or API -> CloudWatch Synthetics canaries.
- Real user browser performance -> CloudWatch RUM; SLOs on golden signals -> Application Signals.
Finished this lesson?
0 of 46 lessons done · 0% of the course

