Context
After pushing changes today to unrelated lambdas, I somehow caused errors relating to Xray in a lambda function and not sure how to troubleshoot any further.
I’m using default automatic xray mode and the Lambda has tracing enabled with AWSXRayWriteOnlyAcesss (managed policy). I’ve also checked the imports and ‘aws-xray-sdk-core’ is properly imported with version ‘^3.5.4’
Code:
import AWSXRay from 'aws-xray-sdk-core';
export const handler = async (event, context) => {
const segment = AWSXRay.getSegment();
const handleError = async (err) => {
const handleErrorSegment = segment.addNewSubsegment("handleError");
const errorMessage = err?.message || err?.errorMessage || err;
handleErrorSegment.addMetadata("Error Message: ", errorMessage);
handleErrorSegment.close();
throw err;
};
try {
someFunctionHere(event);
} catch (err) {
return handleError(err);
}
Errors I’m getting
#1 error – beginning of the logs:
2024-06-06T17:27:22.352Z undefined ERROR _X_AMZN_TRACE_ID is missing required information
2024-06-06T17:27:22.352Z undefined ERROR _X_AMZN_TRACE_ID is missing required information
2024-06-06T17:27:22.353Z undefined ERROR Empty or non-string trace ID provided
#2 error – seems like it’s unable to create subsegment or doesn’t recongize addMetadata
2024-06-06T17:27:22.390Z dbe0fb0b-63e1-5c4e-8471-a5d090506516 ERROR Invoke Error
{ "errorType": "TypeError", "errorMessage": "Cannot read properties of undefined (reading 'addMetadata')", "stack": [ "TypeError: Cannot read properties of undefined (reading 'addMetadata')", " at handleError (file:///var/task/index.js:80:24)", " at triggerStepFunction (file:///var/task/index.js:43:5)", " at async Runtime.handler (file:///var/task/index.js:108:3)" ] }
Would love any guidance. I don’t know what changed after the last pipeline run, but everything I’ve shared above is directly from the last run.