aws / aws/aws-xray-sdk-node

Lambda- successive invocations reusing first invocation's facade segment

Open
#405 4 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
JavaScript
Stars
280
Forks
157
PR merge metrics
No merged PRs in 30d

Description

Successive invocations of a lambda are adding to the trace of the initial invocation. I presume I've got this set up incorrectly but I'm struggling to identify what it is.

The first invocation trace looks like:

![image](https://user-images.githubusercontent.com/6352812/114011894-a4d90a80-985d-11eb-8993-a9b94a8a073d.png)

A later one looks like this:

![image](https://user-images.githubusercontent.com/6352812/114011991-b9b59e00-985d-11eb-94af-e9f29c4a1586.png)

Simplified code:
```
const AWSXRay = require("aws-xray-sdk");
const AWS = AWSXRay.captureAWS(require("aws-sdk"));
const AWS_EXECUTION_ENV = process.env.AWS_EXECUTION_ENV;

async function processLocation(event) {
AWSXRay.setContextMissingStrategy(() => {});
xrayEnabled = !!AWS_EXECUTION_ENV;

if (xrayEnabled) {
let facadeSegment = AWSXRay.getSegment();
console.log("Starting segment is called: " + facadeSegment.name);
let segment = facadeSegment.addNewSubsegment("Root");
AWSXRay.setSegment(segment);
segment.addMetadata("event data", JSON.stringify(event));
}
```

The log statement outputs:

![image](https://user-images.githubusercontent.com/6352812/114012541-5c6e1c80-985e-11eb-9d3a-0a00a706a102.png)

Any pointers?

Later in the lambda I call `AWSXRay.setSegment(subSegment);` before making parallel HTTP calls otherwise I found the auto-instrumented segments using `captureHTTPsGlobal` wouldn't attach to the correct parent segments. It's around here that it smells bad to me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.