Question

Difficulty: EasyInstrumenting Distributed Tracing with AWS X-Ray

A developer has enabled active tracing on an AWS Lambda function that is triggered by an Amazon SQS queue. The Lambda function processes the messages and writes the results to an Amazon DynamoDB table. While reviewing the trace map in the AWS X-Ray console, the developer observes that the Lambda function execution is traced, but the downstream calls to DynamoDB do not appear in the traces. Which of the following actions should the developer take to resolve this issue?

  1. Instrument the AWS SDK client in the Lambda function code using the AWS X-Ray SDK.Answer
  2. B
    Initialize the AWS SDK client by hardcoding the AWS access key and secret access key in the function code.
  3. C
    Increase the Lambda function execution timeout to match the visibility timeout of the Amazon SQS queue.
  4. D
    Change the API Gateway integration type to use Lambda Proxy integration.

Answer

Instrument the AWS SDK client in the Lambda function code using the AWS X-Ray SDK.
The correct answer is to instrument the AWS SDK client using the AWS X-Ray SDK. Enabling active tracing on Lambda only configures the Lambda service to trace the function execution. To trace downstream HTTP/HTTPS calls to services like DynamoDB, the AWS SDK client within the function code must be wrapped or patched by the AWS X-Ray SDK.

Step-by-Step Solution

1
Identify the cause of the missing downstream service call subsegments in the AWS X-Ray trace map.
The Lambda service itself generates the main segment, but downstream calls (like DynamoDB) require the AWS SDK to be instrumented to record subsegments.
By default, the standard AWS SDK does not automatically send trace data to X-Ray unless instrumented.
2
Use the AWS X-Ray SDK to wrap or patch the AWS SDK client inside the Lambda function code.
Downstream calls made via the instrumented SDK client will now generate and propagate trace context to DynamoDB.
This is necessary to capture trace subsegments for outbound calls.

Key Concept

AWS SDK Instrumentation for AWS X-Ray
Rate this question