首页 > 解决方案 > aws Lambda 上的哨兵面包屑

问题描述

当 AWS Lambda 函数被冻结并重新启动(热启动)时,之前的面包屑消息仍然存在,并且在 Sentry 仪表板上我们可以看到旧消息。

似乎在 captureException 调用后没有清除面包屑。即使函数被重用,哪种方法是清除调用之间上下文的正确方法?

Sentry.init({
    dsn: process.env.dsn,
    environment: process.env.environment,
    release: process.env.release
});
try {
    Sentry.configureScope(scope => {
       scope.setTag('transaction', context.awsRequestId);
       scope.setTag('lambda', context.functionName);
    });

    Sentry.addBreadcrumb({
        category: 'store',
        message: 'Test',
        level: Sentry.Severity.Info
    });
    throw new Error('Something bad happened');
} catch (error) {
    context.callbackWaitsForEmptyEventLoop = false;

    Sentry.captureException(error);
    await Sentry.flush(context.getRemainingTimeInMillis());
}

标签: node.jsaws-lambdasentry

解决方案


对于这方面的稀疏文档感到抱歉,但在此之后立即执行init

Sentry.configureScope(scope => {
   scope.clear();
});

应该做的伎俩。


推荐阅读