【发布时间】:2019-07-11 04:32:59
【问题描述】:
我正在尝试在 AWS Lambda (nodejs 8.10) 上配置哨兵,但异常不会发送到哨兵。我的感觉是时间问题:在数据发送到哨兵之前终止 lambda。
在 AWS Lambda 上集成哨兵的正确方法是什么?
谢谢!
【问题讨论】:
标签: node.js aws-lambda sentry
我正在尝试在 AWS Lambda (nodejs 8.10) 上配置哨兵,但异常不会发送到哨兵。我的感觉是时间问题:在数据发送到哨兵之前终止 lambda。
在 AWS Lambda 上集成哨兵的正确方法是什么?
谢谢!
【问题讨论】:
标签: node.js aws-lambda sentry
更新:Sentry 自动报告 Node/Lambda 上的异常。见docs
您必须使用函数flush 确保发送当前排队的所有事件:
Sentry.captureException(new Error('test'));
await Sentry.flush();
http://getsentry.github.io/sentry-javascript/modules/node.html#flush
【讨论】:
安装哨兵/节点
npm i @sentry/node
将此代码添加到 lambda 的顶部
const Sentry = require("@sentry/node");
Sentry.init({
dsn: "https://0dc9558ffb934657b6c3b97182b4338d@sentry.io/182963" // your_dsn_key_here
});
使用哨兵对象
try {
//Logic here
} catch (error) {
Sentry.captureException("Error on getLogsById");
}
【讨论】:
安装哨兵模块
npm install @sentry/node
请参阅下面的示例以使用 Sentry 配置 AWS Lambda 函数。
// Import the Sentry module.
const Sentry = require("@sentry/node");
// Configure the Sentry SDK.
Sentry.init({
dsn: "your dsn",
});
exports.handler = function (event, context) {
try {
textFunctionCall(); // Call undefined function.
} catch (e) {
Sentry.captureException(e); // using this function exception captured in Sentry dashboard.
Sentry.flush(2000);
}
const response = {
statusCode: 200,
body: "Hello, exception captured",
};
return response;
};
https://docs.sentry.io/platforms/node/serverless/#aws-lambda
Sentry中仍然没有捕获错误,然后安装波纹管节点模块这些是依赖项。
npm install lru-cache
npm install lru_map
npm install tslib
【讨论】: