4

We have several NodeJS Lambdas with AWS X-Ray with the following general setup.

process.env.AWS_XRAY_DEBUG_MODE = 'TRUE'
process.env.AWS_XRAY_TRACING_NAME = 'api-extensions'
console.log('Enabled XRAY debug mode')

import AWSXRay from 'aws-xray-sdk-core'
import { inputHandler } from './lib/handler'
import Sentry from './lib/sentry'

if (process.env.AWS_XRAY_ENABLED) {
  AWSXRay.captureHTTPsGlobal(require('http'), true)
  AWSXRay.captureHTTPsGlobal(require('https'), true)
  AWSXRay.capturePromise() <----- causes the startup messages
}

export const handler = Sentry.wrapHandler(inputHandler)

All these lambda's give me one of the following errors on startup (during initialisation):

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

or

Missing AWS Lambda trace data for X-Ray. Expected _X_AMZN_TRACE_ID to be set

My understanding is that we need capturePromise() for our axios dependency.|

I'm wondering where those messages come from and how I can fix them.

Relevant details (will add on demand/request):

  • AWS_XRAY_ENABLED is set
  • package version: aws-xray-sdk-core": "3.3.1"
Whyhankee
  • 822
  • 10
  • 14

2 Answers2

0

You should verify that the role the Lambda is using has sufficient xray: * permissions for the resource:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "xray:PutTraceSegments",
                "xray:PutTelemetryRecords",
                "xray:GetSamplingRules",
                "xray:GetSamplingTargets",
                "xray:GetSamplingStatisticSummaries"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Brian
  • 1
  • 2
0

AWS Support told me that if I wanted to just ignore it I could use this env var in the lambda:

AWS_XRAY_CONTEXT_MISSING: 'IGNORE_ERROR',

I have some code in a package that creates a Postgres connection and adds some Xray tracing but has a bug that causes this error about subsegments. Easier to just ignore the error than refactor.

jcollum
  • 43,623
  • 55
  • 191
  • 321