Nâng CaoAWS & Cloud iconAWS & Cloud

AWS X-Ray là gì? Giải thích distributed tracing và cách instrument ứng dụng Node.js/Lambda với X-Ray.

AWS X-Ray là distributed tracing service cho phép trace request path qua toàn bộ microservices architecture, identify performance bottleneck và debug errors trong distributed system.

  • Concepts: Trace — toàn bộ journey của 1 request (end-to-end); Segment — công việc của 1 service trong trace; Subsegment — breakdown chi tiết trong segment (downstream call, DB query, external HTTP); Annotation — key-value indexed data để filter traces; Metadata — arbitrary data không indexed; Sampling — chỉ trace một tỷ lệ % requests để kiểm soát cost (mặc định 5% + 1 request/s đầu tiên).
  • Instrument Node.js:
javascript
npm install aws-xray-sdk-core
// Prefer AWS SDK v3 with captureAWSv3Client:
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const AWSXRay = require('aws-xray-sdk-core');
const ddb = AWSXRay.captureAWSv3Client(new DynamoDBClient({}));
// Capture HTTP outbound:
AWSXRay.captureHTTPsGlobal(require('https'));
// Express middleware:
app.use(AWSXRay.express.openSegment('MyApp'));

Lambda tự động tích hợp nếu enable Active Tracing trong function config (Lambda tạo segment, bạn thêm subsegment).

  • X-Ray Service Map visualize toàn bộ dependencies, response time, error rate từng node.
  • X-Ray Analytics cho filter, compare, build group của traces.
  • Tích hợp với CloudWatch ServiceLens để combine metrics, logs và traces trong 1 view.
  • OpenTelemetry compatible qua AWS Distro for OpenTelemetry (ADOT) — cho phép switch provider sau.

Xem toàn bộ AWS & Cloud cùng filter theo level & chủ đề con.

Mở danh sách AWS & Cloud