Soru

Zorluk: Çok zorInstrumenting Distributed Tracing with AWS X-Ray

A developer is troubleshooting a distributed application. The flow begins with an Amazon API Gateway HTTP API that integrates with an AWS Lambda function. The Lambda function performs some processing and sends an HTTP request to an internal Java-based microservice running on Amazon ECS on AWS Fargate behind an Application Load Balancer (ALB). The Java microservice then writes records to an Amazon DynamoDB table.

Active tracing is enabled on both the API Gateway and the Lambda function. However, in the AWS X-Ray console, the developer observes that:
1. The trace map shows the Lambda function's execution segment, but the Java microservice and the subsequent DynamoDB calls are represented as a separate, disconnected trace map.
2. The DynamoDB calls themselves are missing from the X-Ray service map entirely.

Which two actions should the developer take to resolve these issues and establish continuous, end-to-end trace propagation?

  1. In the Lambda function's code, ensure the outgoing HTTP client is instrumented with the AWS X-Ray SDK, or manually retrieve the current trace entity and inject the X-Amzn-Trace-Id header into the HTTP request sent to the ALB.Cevap
  2. In the ECS task definition, add a container definition for the aws-xray-daemon, ensure the ECS task role has the xray:PutTraceSegments and xray:PutTelemetryRecords permissions, and configure the Java microservice's AWS SDK clients with the X-Ray SDK's TracingInterceptor.Cevap
  3. C
    Configure the ECS task execution role with the xray:PutTraceSegments permission, and configure the Java application to send tracing segments directly to the ALB's DNS name using the X-Ray daemon cluster-wide endpoint.
  4. D
    Change the API Gateway integration type to a Lambda custom integration, and configure a mapping template to extract the X-Amzn-Trace-Id header from API Gateway and pass it as a JSON payload property to the Lambda handler.
  5. E
    Increase the Lambda function's timeout and memory settings to allow the execution context to remain warm long enough for the X-Ray SDK to buffer and flush tracing segments to the daemon before the function container terminates.

Cevap

To establish end-to-end trace propagation, the Lambda function must propagate the X-Ray trace header (X-Amzn-Trace-Id) in its outgoing HTTP requests, and the ECS Fargate tasks must run the X-Ray daemon as a sidecar container with the correct IAM Task Role permissions while instrumenting downstream SDK calls.
The correct actions require propagating the trace header from the Lambda function and configuring the X-Ray daemon sidecar and SDK client in ECS Fargate. First, the Lambda function must send the trace context downstream by instrumenting the outgoing HTTP client to add the X-Amzn-Trace-Id header. Second, because Fargate is serverless, the X-Ray daemon cannot be run at the EC2 host level, so it must be added as a sidecar container in the task definition. The application's ECS task role must have permissions to upload the traces, and the AWS SDK clients inside the Java microservice must be instrumented with the TracingInterceptor to record the downstream DynamoDB calls.

Adım Adım Çözüm

1
Identify the trace gap between the Lambda function and the downstream ECS microservice.
Determine that trace context propagation is missing over the custom HTTP client call to the ALB.
X-Ray context is not automatically propagated across custom HTTP boundaries unless the outgoing HTTP client is instrumented or the header is manually injected.
2
Determine the requirement for running the X-Ray daemon on AWS ECS Fargate.
Specify the X-Ray daemon container as a sidecar in the ECS Task Definition.
Because ECS Fargate does not allow host-level daemon execution, the daemon must run alongside the application in each task.
3
Identify the correct IAM role and permissions needed for the ECS container to publish traces.
Assign xray:PutTraceSegments and xray:PutTelemetryRecords to the ECS Task Role.
The Task Role gives permissions to the running application and sidecar containers, whereas the Task Execution Role is only used by the ECS agent for tasks like pulling images.
4
Instrument the downstream calls from the Java microservice to DynamoDB.
Configure the Java AWS SDK client with the X-Ray SDK's TracingInterceptor.
Without SDK client instrumentation, the AWS SDK calls are not monitored by X-Ray, causing DynamoDB segments to be missing from the trace.

Anahtar Kavram

AWS X-Ray distributed tracing context propagation across HTTP boundaries and daemon sidecar configuration on ECS Fargate.
Tahmini Süre:3m 0s
Bu soruyu puanla