AWS Xray NodeJS:如何修复启动时“Missing AWS Lambda trace data for X-Ray”消息

46scxncf  于 2023-04-20  发布在  Node.js
关注(0)|答案(1)|浏览(106)

我们有几个带有AWS X-Ray的NodeJS Lambdas,一般设置如下。

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)

所有这些lambda在启动时(初始化期间)给予我以下错误之一:

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

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

我的理解是,我们需要capturePromise()作为axios依赖项。|
我想知道这些信息是从哪里来的,我如何修复它们。
相关详细信息(将根据需求/要求添加):

  • AWS_XRAY_ENABLED已设置
  • 软件包版本:aws-xray-sdk-core": "3.3.1"
gtlvzcf8

gtlvzcf81#

您应该验证Lambda正在使用的角色是否具有足够的xray:* 资源的权限:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "xray:PutTraceSegments",
                "xray:PutTelemetryRecords",
                "xray:GetSamplingRules",
                "xray:GetSamplingTargets",
                "xray:GetSamplingStatisticSummaries"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

相关问题