Question

Difficulty: MediumInstrumenting Distributed Tracing with AWS X-Ray

A developer is instrumenting a Go-based microservice running on Amazon ECS with the EC2 launch type to trace incoming HTTP requests, downstream HTTP client calls, and calls to Amazon DynamoDB using AWS X-Ray. The X-Ray daemon is already running on the container host instances. Which of the following actions must the developer take to instrument the application and ensure downstream traces are recorded? (Select TWO.)

  1. Instrument the AWS SDK clients using the X-Ray SDK for Go and wrap the HTTP client's transport with the X-Ray RoundTripper.Answer
  2. Pass the Go context containing the active segment to downstream AWS SDK operations and HTTP client calls.Answer
  3. C
    Hardcode temporary AWS IAM credentials within the application's SDK client configuration to authorize calls to the X-Ray daemon.
  4. D
    Configure the AWS SDK clients without passing the Go context object, as the Go X-Ray SDK automatically registers a global listener that intercepts and correlates all downstream calls.
  5. E
    Configure the Amazon SQS queue's visibility timeout to be shorter than the database processing time to force X-Ray to flush trace segments.

Answer

To instrument the Go application for AWS X-Ray, the developer must instrument the AWS SDK clients and HTTP client transport, and explicitly pass the Go context containing the active segment to all downstream calls.
Instrumenting the SDK clients and HTTP transport with X-Ray SDK helpers enables subsegment generation for outgoing requests. Since Go lacks thread-local storage, context must be explicitly passed to propagate the active trace segment.

Step-by-Step Solution

1
Wrap the HTTP client transport with the X-Ray RoundTripper and initialize the AWS SDK clients with X-Ray instrumentation helper functions.
The application code is prepared to intercept outgoing AWS SDK and HTTP requests to generate X-Ray subsegments.
This establishes the handlers and interceptors required by the X-Ray SDK to record outgoing service details.
2
Ensure that the Go context.Context object representing the active request segment is passed into all downstream SDK calls and HTTP requests.
The trace ID and segment hierarchy are successfully propagated down the call chain.
Go does not have thread-local storage; therefore, trace context propagation relies entirely on passing context variables down the call stack.

Key Concept

Go X-Ray SDK Instrumentation and Context Propagation
Rate this question