Question

Difficulty: MediumInstrumenting Distributed Tracing with AWS X-Ray

A developer has a serverless application where an Amazon API Gateway REST API integrates with an AWS Lambda function. The Lambda function processes incoming HTTP requests, sends messages to an Amazon SQS queue, and writes records to an Amazon DynamoDB table. Active tracing is enabled on both the API Gateway stage and the Lambda function. However, in the AWS X-Ray service map, downstream calls to SQS and DynamoDB are missing, and some messages in the SQS queue are being processed multiple times by downstream consumers. Which of the following actions should the developer take to ensure that downstream DynamoDB and SQS calls are properly traced in AWS X-Ray?

  1. Instrument the AWS SDK client using the AWS X-Ray SDK in the Lambda function code to capture downstream calls.Answer
  2. B
    Increase the tracing sampling rate in the API Gateway stage settings and rely on the active tracing enablement on the Lambda function to automatically trace downstream SDK calls.
  3. C
    Configure the SQS queue's visibility timeout to be shorter than the Lambda function's timeout to ensure that trace context propagation is completed before the message is deleted.
  4. D
    Hardcode the IAM User access key and secret key in the AWS SDK client configuration within the Lambda function code to authorize X-Ray trace context propagation.

Answer

Instrument the AWS SDK client using the AWS X-Ray SDK in the Lambda function code to capture downstream calls.
The correct answer is to instrument the AWS SDK client using the AWS X-Ray SDK in the Lambda function code. Active tracing on AWS Lambda only traces the incoming invocation and function overhead. To trace downstream calls made to services like SQS or DynamoDB, the developer must explicitly wrap or patch the AWS SDK client using the AWS X-Ray SDK.

Step-by-Step Solution

1
Identify why downstream calls are missing from the AWS X-Ray service map.
Realize that active tracing on AWS Lambda only covers the Lambda service and function execution, but does not auto-instrument SDK clients inside the code.
To capture calls to downstream services like DynamoDB and SQS, the AWS SDK client inside the application code must be wrapped or patched by the AWS X-Ray SDK.
2
Apply X-Ray SDK client instrumentation in the Lambda function.
The AWS SDK client is instrumented (e.g., using AWSXRay.captureAWS in Node.js or patch_all() in Python).
This configuration allows the X-Ray SDK to intercept and trace outbound requests made by the AWS SDK client.
3
Ensure that the Lambda function execution role has appropriate permissions.
The Lambda execution role has the AWSXrayWriteOnlyAccess policy attached.
The function must have IAM permissions to write trace data to AWS X-Ray.

Key Concept

AWS X-Ray SDK instrumentation of AWS SDK clients is required to trace downstream calls from AWS Lambda.
Estimated Time:1m 30s
Rate this question