aws Lambda 上的哨兵面包屑

Sentry Breadcrumb on 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());
}

抱歉,关于这方面的文档很少,但在 init 之后立即执行:

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

应该可以解决问题。