Sentry-javascript: ์ง€๊ธˆ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๊นŒ? @ sentry / node ํ†ตํ•ฉ์„ ํ†ตํ•ด bunyan ๋กœ๊ทธ ํ˜ธ์ถœ์„ breadcrumbs SO ๋งํฌ๋กœ ๋ž˜ํ•‘ : https://stackoverflow.com/questions/53310580/sentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs

์— ๋งŒ๋“  2018๋…„ 11์›” 15์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: getsentry/sentry-javascript

์–ด๋–ป๊ฒŒ @ 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

Question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

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
      });
    }
  }]
});

๋ชจ๋“  3 ๋Œ“๊ธ€

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 ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ :

  • Bunyan์—์„œ ๋‚ด ๋ณด๋‚ธ ์ˆ˜์ค€์€ Senty ์‹ฌ๊ฐ๋„๊ฐ€ ์•„๋‹Œ ์ˆซ์ž์ด๋ฏ€๋กœ level: Sentry.Severity.fromString(nameFromLevel[chunk.level]) ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ’์„ ๋ณ€ํ™˜ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
  • ๊ธฐ์กด bunyan ์ŠคํŠธ๋ฆผ์„ ์žฌ์ •์˜ํ•˜๊ณ  ์‹ถ์ง€ ์•Š์œผ๋ฏ€๋กœ BunyanOptions๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋Œ€์‹  addStream ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.
// 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();
    },
  }),
});
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰