Search code examples
amazon-web-servicesaws-lambdaaws-xray

How do I stop "Missing AWS Lambda trace data for X-Ray" errors that happen after an INIT_START event?


The lambda's configs:

Logs and metrics (default): enabled
Active tracing: enabled
Enhanced monitoring: enabled

The role's permissions for xray:

"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries"

Whenever the lambda hits INIT_START:

INIT_START Runtime Version: nodejs:16.v13   Runtime Version 
ARN: arn:aws:lambda:us-east-2::runtime:redacted

I get an error in the logs:

undefined   ERROR   Error: Missing AWS Lambda trace data for X-Ray. 
Ensure Active Tracing is enabled and no subsegments are created outside the function handler.

Active tracing is enabled so I don't think that's the issue. There is no use of AWSXRay.getSegment. There are no other errors related to XRay in the logs, just the one after INIT_START.

What could be causing this? How do I track it down?


Solution

  • After sorting this out with AWS support there are two possible fixes:

    1. Find out all the places in your code where tracing is happening and confirm that it's being implemented properly -- fix if possible

    2. Set an env var AWS_XRAY_CONTEXT_MISSING with IGNORE_ERROR value in your code

    In my case the first one was in a codebase that was a bit out of my control and we weren't very concerned about the error so I used the env var to just ignore the error in my lambda.