@sentry/node
4.6.3
์๋ก์ด Sentry SDK๋ฅผ ์๋ฒ๋ฆฌ์ค ์ํคํ ์ฒ์ ํตํฉํ๋ ค๊ณ ํฉ๋๋ค. captureException์ ํธ์ถํ๋ ๋ชจ๋ ํธ๋ค๋ฌ ์ฃผ์์ ์ผ๋ฐ์ ์ธ try-catch๊ฐ ์์ต๋๋ค. ๊ฐ๋จํ ๋งํด์ ์ด๊ฒ์ด ์ฐ๋ฆฌ ์ฝ๋์ ๋ชจ์ต์ ๋๋ค(์ ๋ ๋น์ฆ๋์ค ๋ก์ง๊ณผ ๋ง์ ์ ํธ๋ฆฌํฐ ๋ฉ์๋๋ฅผ ์๋ตํ์ต๋๋ค).
Sentry.init({
dsn: process.env.sentryUrl,
environment: process.env.NODE_ENV,
// debugging issue where we only get an event once
beforeSend: (event, _) => { console.log(event.exception); return event }
});
async function wrapper(...) {
try {
handler(...)
} catch(error) {
Sentry.configureScope(scope => {
scope.setTag("test", "Hello, world")
})
const eventId = Sentry.captureException(error)
// debugging, log event id to see if captureException works
console.log(eventId)
const flushResult = await Sentry.flush(1000)
console.log(flushResult) // see if flush succeeded
}
}
ํธ๋ค๋ฌ๊ฐ ํญ์ ์ค๋ฅ๋ฅผ ๋์ง๊ฒ ํ์ต๋๋ค. ์ฒซ ๋ฒ์งธ ์์ฒญ์ ์ํํ๋ฉด ๋ชจ๋ ๊ฒ์ด Sentry์์ ์ ์์ ์ผ๋ก ๋๋ฉ๋๋ค. ๋ ๋ฒ์งธ ์์ฒญ์์๋ ์๋ฌด ์ผ๋ ์ผ์ด๋์ง ์์ต๋๋ค. CloudWatch๋ฅผ ๋ณด๋ฉด ์ด๊ฒ์ด ๋ด๊ฐ ์ฐพ์ ๊ฒ์ ๋๋ค. ํธ์๋ฅผ ์ํด ์ฃผ์์ ์ถ๊ฐํ์ต๋๋ค.
/// the eventId from captureException
2019-02-26T13:47:22.584Z: 8cf83e38081a4672841a6f795ce8105a
/// the middleware defined in Sentry.init
2019-02-26T13:47:23.153Z: { values: [ { stacktrace: [Object], type: 'Error', value: 'This is an error' } ] }
/// result of Sentry.flush
2019-02-26T13:47:23.294Z: true
/// the eventId from captureException
2019-02-26T13:47:24.761Z fbc2c8b2a4d5447380a0f92dd87896f6
/// result of Sentry.flush
2019-02-26T13:47:24.963Z: true
๋ณด์๋ค์ํผ ๋ ๋ฒ์งธ ์์ฒญ์์ beforeSend
๋ฏธ๋ค์จ์ด์ ๋๋ฌํ์ง ์์ผ๋ฏ๋ก Sentry์ ์ ํ ์ ์ก๋์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค.
Sentry.getCurrentHub().getClient().captureException(error)
ํ๋ฉด ๋งค๋ฒ Sentry์ ์์ธ๋ฅผ ๋ณด๋ด์ง๋ง Sentry.configureScope
๊ตฌ์ฑ๋ ๋ฒ์๋ ์ด๋ฒคํธ์ ์ ์ฉ๋์ง ์์ต๋๋ค.
์ด๊ฒ์ ๋ก์ปฌ์์ ์ฌํํด ๋ณด์์ง๋ง AWS Lambda์ ๋ฐฐํฌํ ๋๋ง ๋ฐ์ํฉ๋๋ค.
์ค๋ณต ์ ๊ฑฐ๋ ๊ฐ๋ฅ์ฑ์ด ์์ต๋๋ค.
init
ํธ์ถ์์ debug: true
๋ฅผ ์ฌ์ฉํ์ฌ ์งํ ์ํฉ์ ํ์ธํ ์ ์์ต๋๋ค.
์ค์ ๋ก ์ค๋ณต ์ ๊ฑฐ๋๋ ๊ฒฝ์ฐ ๋ค์์ ์ฌ์ฉํ์ฌ ์ด ํตํฉ์ ์ ๊ฑฐํ ์ ์์ต๋๋ค.
Sentry.init({
integrations: integrations => {
return integrations.filter(integration => integration.name !== 'Dedupe');
}
});
ํฅ๋ฏธ๋ก์ด. ๋น์ทํ ๋ฌธ์ ๋ฅผ ์ฐพ๊ณ ์ด๊ฒ์ ์ฐพ์์ต๋๋ค. ์ ๊ฑฐ ์ค๋ณต ์ ๊ฑฐ๊ฐ ๋๋ฅผ ์ํด ๊ณ ์ณค์ต๋๋ค.
๋ฒ๊ทธ๊ฐ ์๋๋ฏ๋ก ๋ซ์ต๋๋ค.
๋ํ ๋ค์ ์ฃผ์ ๋ฒ์ ์์๋ Dedupe
์ ํ ์ฌํญ์ผ๋ก ๋ง๋ค๋ฉฐ, ์ด๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ณต ์ ๊ฑฐ๊ฐ ์์์ ์๋ฏธํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ค๋ณต ์ ๊ฑฐ๋ ๊ฐ๋ฅ์ฑ์ด ์์ต๋๋ค.
init
ํธ์ถ์์debug: true
๋ฅผ ์ฌ์ฉํ์ฌ ์งํ ์ํฉ์ ํ์ธํ ์ ์์ต๋๋ค.์ค์ ๋ก ์ค๋ณต ์ ๊ฑฐ๋๋ ๊ฒฝ์ฐ ๋ค์์ ์ฌ์ฉํ์ฌ ์ด ํตํฉ์ ์ ๊ฑฐํ ์ ์์ต๋๋ค.
https://docs.sentry.io/platforms/node/default-integrations/