์ด๋ป๊ฒ @ sentry / node ํตํฉ์ ์ํํ์ฌ bunyan ๋ก๊ทธ ํธ์ถ์ ํ์ ๊ฒฝ๋ก๋ก ๋ํ ํ ์ ์์ต๋๊น?
@sentry/node
4.3.0
Sentry๋ ๊ธฐ๋ณธ์ ์ผ๋ก console.log ๋ฅผ ํตํฉํ์ฌ
๋งํฌ : ๊ฐ์ ธ ์ค๊ธฐ ์ด๋ฆ : Sentry.Integrations.Console
์ด๋ป๊ฒํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด bunyan ๋ก๊ฑฐ ์์๋ ์๋ํ๋๋ก ๋ง๋ค ์ ์์ต๋๋ค.
const koa = require('koa');
const app = new koa();
const bunyan = require('bunyan');
const log = bunyan.createLogger({
name: 'app',
..... other settings go here ....
});
const Sentry = require('@sentry/node');
Sentry.init({
dsn: MY_DSN_HERE,
integrations: integrations => {
// should anything be handled here & how?
return [...integrations];
},
release: 'xxxx-xx-xx'
});
app.on('error', (err) => {
Sentry.captureException(err);
});
// I am trying all to be part of sentry breadcrumbs
// but only console.log('foo'); is working
console.log('foo');
log.info('bar');
log.warn('baz');
log.debug('any');
log.error('many');
throw new Error('help!');
์ถ์ : ์ด๋ฏธ bunyan-sentry-stream์ ์๋ํ์ง๋ง @ sentry / node ์์๋ ์ฑ๊ณตํ์ง ๋ชปํ์ต๋๋ค. ํญ๋ชฉ์ ํ์ ๊ฒฝ๋ก๋ก ์ทจ๊ธํ๋ ๋์ ํธ์ํฉ๋๋ค.
SO ๋งํฌ : https://stackoverflow.com/questions/53310580/sentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs
https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + ๋๊ตฐ๊ฐ ์ด๋ฏธ SO์ ๋ต๋ณํ์ต๋๋ค.
var log = bunyan.createLogger({
name: 'myapp',
streams: [{
level: 'debug',
stream: {
write: function(record) {
Sentry.addBreadcrumb({
message: record.msg,
level: record.level
});
}
}]
});
์๋ ์ง๋ฌธ์ ๋ต๋ณํ์ต๋๋ค. ๋ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ์ธ์ ๋ ์ง ๋ค์์ฌ์ธ์.
typescript๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์์ ์์ ์์ WriteableStream์ ์ ๊ณตํ์ง ์์ ์ปดํ์ผ๋ฌ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ฏ๋ก ์๋์ ๊ฐ์ด Writeable ์์ฑ์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ถ๊ฐ์ ์ผ๋ก :
level: Sentry.Severity.fromString(nameFromLevel[chunk.level])
์ฌ์ฉํ์ฌ ๊ฐ์ ๋ณํํด์ผํฉ๋๋ค.// if you want some stronger typing around the bunyan log entry
interface BunyanChunk {
pid?: number;
level: number;
msg: string
// ... hostname?: string;
[custom: string]: unknown;
}
const appLogger = Bunyan.createLogger();
appLogger.addStream({
level: 'debug',
// use the Writable constructor and pass a write function
stream: new Writable({
write(c: string, encoding, next) {
const chunk: BunyanChunk = JSON.parse(c);
Sentry.addBreadcrumb({
message: chunk.msg,
// convert from a Bunyan level to a Sentry Severity
level: Sentry.Severity.fromString(Bunyan.nameFromLevel[chunk.level]),
});
next();
},
}),
});
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + ๋๊ตฐ๊ฐ ์ด๋ฏธ SO์ ๋ต๋ณํ์ต๋๋ค.