I'm trying to get a toy example up and running with an AWS Lambda function, f
, that's triggered by a message on one SQS queue, sqs
, publishes to another queue sqs'
, and then a worker, f'
reads from sqs'
and processes the message where the entire "request" is traced with X-Ray.
sqs -> f -> sqs' -> f'
Currently, I have the queues in place and the functions writing and receiving from the queue. I also have X-Ray tracing the request from the the first function f
to the sqs queue.
My current challenge is: how do I propagate the trace to the final worker so I can see the entire process in x-ray.
Here are my current functions:
public class Hello implements RequestHandler<SQSEvent, Void> {
String OUTPUT_QUEUE_URL = "...";
private AmazonSQS sqs = AmazonSQSClientBuilder.standard()
.withRequestHandlers(new TracingHandler(AWSXRay.getGlobalRecorder()))
.build();
public Void handleRequest(SQSEvent event, Context context)
{
for(SQSMessage msg : event.getRecords()){
System.out.println(new String(msg.getBody()));
}
SendMessageRequest send_msg_request = new SendMessageRequest()
.withQueueUrl(OUTPUT_QUEUE_URL)
.withMessageBody("hello world")
.withDelaySeconds(5);
sqs.sendMessage(send_msg_request);
return null;
}
}
public class World implements RequestHandler<SQSEvent, Void>{
public Void handleRequest(SQSEvent event, Context context)
{
for(SQSMessage msg : event.getRecords()){
System.out.println(new String(msg.getBody()));
}
return null;
}
}