我正在尝试在我当前的项目中使用 AWS X-ray(使用 Node.js 和无服务器框架)。我正在尝试将 X 射线连接到我的 lambda 函数之一,我遇到了问题
Error: Failed to get the current sub/segment from the context.
at Object.contextMissingRuntimeError [as contextMissing] (/.../node_modules/aws-xray-sdk-core/lib/context_utils.js:21:15)
at Object.getSegment (/.../node_modules/aws-xray-sdk-core/lib/context_utils.js:92:45)
at Object.resolveSegment (/.../node_modules/aws-xray-sdk-core/lib/context_utils.js:73:19).....
下面的代码:
import { DynamoDB } from "aws-sdk";
import AWSXRay from 'aws-xray-sdk';
export const handler = async (event, context, callback) => {
const dynamo = new DynamoDB.DocumentClient({
service: new DynamoDB({ region })
});
AWSXRay.captureAWSClient(dynamo.service);
try {
// call dynamoDB function
} catch(err) {
//...
}
}
对于这个问题,我使用来自 https://forums.aws.amazon.com/thread.jspa?messageID=821510褆的解决方案
我尝试的另一个解决方案来自https://forums.aws.amazon.com/thread.jspa?messageID=829923ꧣ
代码就像
import AWSXRay from 'aws-xray-sdk';
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
export const handler = async (event, context, callback) => {
const dynamo = new AWS.DynamoDB.DocumentClient({region});
//....
}
还是行不通...
感谢任何形式的帮助。