Sentryでエラー発生時に追加のパラメータを付与する
AWS LambdaでSentryを使うようにしているが、エラー発生時にアプリケーション独自のパラメータを付与したくて対応方法を調べた。
Sentry.withScopeを使って、scope.setExtraに独自のパラメータを設定できる。
const handler = async (event, context) => {
const userId = 'xxxx';
try {
someFunction();
} catch (error) {
Sentry.withScope((scope) => {
scope.setExtra('userId', userId);
Sentry.captureException(error);
});
await Sentry.flush(2500);
}
}