How to map, trace and display AWS X-Ray GoLang Lambda to lambda service

0 votes

Here I have Lamdba function 1 and that invokes lambda function 2 in Go. I want to see these 2 functions joined in the service map.

I have created a custom segment eg called "parent" and the create a subsegment from this context eg called "child". Then using client.InvokeWithContext to invoke the function 2 passing the "child" segment context.

sess := session.Must(session.NewSession())
client := lambda.New(sess, &aws.Config{Region: aws.String(region)})

xray.Configure(xray.Config{LogLevel: "trace"})
xray.AWS(client.Client)

ctx, seg := xray.BeginSegment(context.Background(), "Parent")
ctx, subseg := xray.BeginSubsegment(ctx, "Child")
result, _ := client.InvokeWithContext(ctx, 
    lambda.InvokeInput{FunctionName: aws.String(functionName), Payload: nil})
subseg.Close(nil)   
seg.Close(nil)

Problem is that this creates trace parent -> child in sevice map but also has function 1 too.

What is the best way to join these 2 functions on the service map please ?

Oct 15, 2018 in AWS by findingbugs
• 4,750 points
259 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You don't need to add a subsegment for the "child" call unless you want to add annotation/metadata.

The API gateway adds a trace ID called X-Amzn-Trace-Id to the header of incoming requests, which X-ray picks up. If you forward that trace ID in your call from lambda 1 to lambda 2, then X-ray will visually represent the calls with an arrow from lambda 1 to lambda 2 in the overview and include the trace details of lambda 2 when viewing the trace details of lambda 1.

As long as you forward the top trace ID through the call chain, X-ray will correctly visualize the call chain from service to service with nodes and arrows.

From https://aws.amazon.com/xray/faqs/:

Q: What is a trace?

An X-Ray trace is a set of data points that share the same trace ID. For example, when a client makes a request to your application, it is assigned a unique trace ID. As the request makes its way through services in your application, the services relay information regarding the request back to X-Ray using this unique trace ID. The piece of information relayed by each service in your application to X-Ray is a segment, and a trace is a collection of segments.

https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader

https://docs.aws.amazon.com/xray/latest/devguide/xray-services-apigateway.html

answered Oct 15, 2018 by Priyaj
• 56,140 points

Related Questions In AWS

0 votes
1 answer

Is AWS Lambda code isolated to others and how?

AWS Lambda functions execute in a container ...READ MORE

answered Jan 21 in AWS by Fitinai
25 views
0 votes
1 answer

How do I invoke another lambda async and pass context to it?

I tried several times trying to pass ...READ MORE

answered Apr 27, 2018 in AWS by Cloud gunner
• 4,250 points
1,154 views
0 votes
1 answer

How to get AWS account/service cost using CloudWatch API?

You can check this link for a ...READ MORE

answered Jul 13, 2018 in AWS by Priyaj
• 56,140 points
135 views
0 votes
1 answer
0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 56,140 points
1,059 views
0 votes
1 answer
0 votes
1 answer

how to import numpy and pandas inside aws lambda function?

The problem is that your local numpy ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 56,140 points
1,543 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.