Skip to content

Commit

Permalink
sentry flush는 미들웨어 1개로 대응
Browse files Browse the repository at this point in the history
  • Loading branch information
if1live committed Oct 3, 2023
1 parent 915ea31 commit e4c51cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ app.onError(async (err, c) => {
const extractStatusCode = (err: any) => err.status ?? err.statusCode ?? 500;
const status = extractStatusCode(err);

// 관심있는 에러만 센트리로 취급
// 관심있는 에러만 센트리로 보낸다
if (status >= 500) {
Sentry.captureException(err);
await Sentry.flush(3000);
}

interface ErrorModel {
Expand Down Expand Up @@ -73,7 +72,11 @@ app.use("*", compress());

app.use("*", async (_, next) => {
await next();
await Sentry.flush(3000);

// https://github.com/getsentry/sentry-javascript/blob/develop/packages/serverless/src/awslambda.ts
// flushTimeout은 sentry serverless 정책 가져옴
const flushTimeout = 2000;
await Sentry.flush(flushTimeout).catch((e) => console.error(e));
});

app.get("/", async (c) => {
Expand Down

0 comments on commit e4c51cf

Please sign in to comment.