aws / aws/aws-xray-sdk-node

Lambda Node 14 - Error: Missing AWS Lambda trace data for X-Ray. Expected _X_AMZN_TRACE_ID to be set

Open
#383 6 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

I am trying to set up some custom subsegments to gather timings of operations.

Code below:

```
const AWS = require('aws-sdk');
const AWSXRay = require('aws-xray-sdk');
const xmljs = require('xml-js');

const segment = AWSXRay.getSegment();

const self = {
handler: async (event, context) => {
try {
const xmlsegment = segment.addNewSubsegment('XML');
const data = xmljs.xml2js(event.body, {compact: true});
xmlsegment.close();
}
}

module.exports = self;
```

When hitting the API endpoint, I'm getting "Error: Missing AWS Lambda trace data for X-Ray. Expected _X_AMZN_TRACE_ID to be set" in the logs.

I am following the information here https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-subsegments.html#xray-sdk-nodejs-subsegments-lambda

Contributor guide

Open the contributing guide

Research direction

Start with the shown Lambda handler, especially AWSXRay.getSegment() and the custom subsegment creation, and compare its execution context with the linked AWS X-Ray Lambda subsegments documentation. Done means the endpoint creates and closes the XML subsegment without the missing _X_AMZN_TRACE_ID error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
cloud, observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.