Album69
  • About
  • Life
  • Travel
  • Tech
  • Galleries
  • SAP-C02 Notes
  • DOP-C02 Notes
X GitHub LinkedIn YouTube

Xray General

Domains 2, 3. X-Ray is the distributed tracing service. Know service maps, sampling, annotations, and integration with Lambda, ECS, and API Gateway.

Domain 3: Continuous Improvement
October 9, 2026

Exam relevance: Domains 2, 3. X-Ray is the distributed tracing service. Know service maps, sampling, annotations, and integration with Lambda, ECS, and API Gateway.


1. Overview

AWS X-Ray provides distributed tracing for applications. It tracks requests as they travel through microservices, Lambda functions, databases, and external APIs — helping identify latency bottlenecks and errors.

Problems it solves:

  • Latency is high but you don’t know which service is slow
  • Errors occur but you can’t trace them across services
  • No visibility into downstream dependency performance

2. Core Concepts

ConceptDescription
TraceEnd-to-end record of a request across all services
SegmentData from a single service (one segment per service)
SubsegmentGranular data within a segment (DB call, HTTP call, custom)
Service mapVisual graph of services and their connections
AnnotationKey-value pair indexed for filtering (searchable)
MetadataKey-value pair not indexed (for debugging, not filtering)
SamplingPercentage of requests traced (reduces cost and overhead)

3. Service Map

  • Visual representation of your application’s architecture
  • Shows: services, connections, latency, error rates, throttle rates
  • Color-coded: green (healthy), yellow (slow), red (errors)
  • Drill down into any node to see traces

4. Sampling

  • By default: first request per second + 5% of additional requests
  • Custom sampling rules: define rate by service, URL, method, host
  • Higher sampling = more visibility, higher cost
  • Use reservoir (fixed number per second) + rate (percentage above reservoir)
{
  "version": 2,
  "rules": [{
    "description": "High-value transactions",
    "host": "*",
    "http_method": "POST",
    "url_path": "/api/payment*",
    "fixed_target": 10,
    "rate": 0.5
  }]
}

5. Integration with AWS Services

ServiceIntegration
LambdaBuilt-in — enable Active Tracing in function config
API GatewayEnable X-Ray tracing on stage
ECSAdd X-Ray daemon as sidecar container
EC2Install X-Ray daemon, instrument SDK
Elastic BeanstalkEnable via configuration option
App MeshNative integration
SNS / SQSTrace propagation via message attributes

Lambda Active Tracing

# SAM template
Properties:
  Tracing: Active  # Enables X-Ray for Lambda

Lambda automatically creates a segment. Add subsegments for downstream calls using the X-Ray SDK.


6. X-Ray SDK

Instrument application code to create custom segments and subsegments:

from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all

patch_all()  # Auto-instrument AWS SDK calls, HTTP requests

@xray_recorder.capture('process_order')
def process_order(order_id):
    # Creates a subsegment named 'process_order'
    xray_recorder.put_annotation('orderId', order_id)
    xray_recorder.put_metadata('orderDetails', {...})
    # ... business logic

7. X-Ray Groups

  • Filter traces by expression (e.g., service("payment-service") AND responsetime > 2)
  • Create CloudWatch alarms on group metrics
  • Use for: SLO monitoring, alerting on specific service degradation

8. CloudWatch ServiceLens

  • Unified view combining X-Ray traces, CloudWatch metrics, and CloudWatch Logs
  • Service map with health indicators
  • Drill from service map → traces → logs in one workflow
  • Recommended interface for production observability

9. Exam Scenarios

Scenario 1: A microservices application has high latency but the team cannot identify which service is causing it. What is the solution?

Enable AWS X-Ray across all services. Use the service map to visualize the request flow and identify which service has the highest response time. Drill into traces for that service to find the specific operation causing latency.

Scenario 2: A company wants to trace requests through API Gateway → Lambda → DynamoDB and identify slow DynamoDB queries. What is required?

Enable X-Ray tracing on the API Gateway stage. Enable Active Tracing on the Lambda function. The AWS SDK for DynamoDB is automatically instrumented when using patch_all() in the X-Ray SDK. X-Ray creates subsegments for each DynamoDB call showing latency.

Scenario 3: A high-traffic application cannot afford to trace 100% of requests. How should sampling be configured?

Configure custom sampling rules in X-Ray. Set a reservoir of 5 requests per second (always trace) plus 1% of additional requests. For critical paths (e.g., payment), set a higher rate. This balances visibility with cost.


10. Exam Tips

  • Annotations = indexed, searchable — use for filtering traces (orderId, userId, environment)
  • Metadata = not indexed — use for debugging details not needed for filtering
  • Active Tracing on Lambda = one config change, no code changes needed
  • X-Ray daemon is required for EC2 and ECS — it buffers and sends trace data to X-Ray
  • ServiceLens = unified view of metrics + traces + logs — the recommended production interface
  • X-Ray does not replace CloudWatch — they complement each other (metrics vs traces)
  • Sampling is critical for high-traffic applications — 100% tracing is expensive

11. Official References

  • X-Ray Developer Guide
  • X-Ray Sampling
  • CloudWatch ServiceLens
  • X-Ray with Lambda

      What's in this sap-c02

      • 1. Overview
      • 2. Core Concepts
      • 3. Service Map
      • 4. Sampling
      • 5. Integration with AWS Services
        • Lambda Active Tracing
      • 6. X-Ray SDK
      • 7. X-Ray Groups
      • 8. CloudWatch ServiceLens
      • 9. Exam Scenarios
      • 10. Exam Tips
      • 11. Official References
      © Album69 2026
      X GitHub LinkedIn YouTube