Sentry-javascript: هل هذا ممكن الان؟ @ sentry / node Integration to التفاف مكالمات سجل bunyan كوصلة مسارات تنقل SO: https://stackoverflow.com/questions/53310580/sentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs

تم إنشاؤها على ١٥ نوفمبر ٢٠١٨  ·  3تعليقات  ·  مصدر: getsentry/sentry-javascript

كيف يمكنني إجراء تكامل @ sentry / node للالتفاف على مكالمات سجل بنيان على أنها فتات تنقل؟

طرد

@sentry/node 4.3.0

وصف

يحتوي تطبيق Sentry by defaults على تكامل لـ console.log لجعله جزءًا من مسارات التنقل:

الرابط: اسم الاستيراد: Sentry.Integrations.Console

كيف يمكننا جعله يعمل مع Bunyan logger أيضًا ، مثل:

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

تم الرد على السؤال الأصلي. لا تتردد في إعادة فتح الصفحة إذا كان لا يزال لديك المزيد من الأسئلة.

إذا كنت تستخدم الكتابة المطبوعة ، فقد تواجه بعض مشكلات المترجم لعدم توفير WriteableStream بالمثال أعلاه ، لذلك يمكنك استخدام المُنشئ Writeable على النحو التالي.

بالإضافة إلى ذلك:

  • المستوى المنبعث من Bunyan هو رقم ، وليس درجة خطيرة ، لذلك عليك تحويل القيمة باستخدام level: Sentry.Severity.fromString(nameFromLevel[chunk.level])
  • لا أريد تجاوز دفق بنيان الحالي ، لذا استخدم وظيفة addStream بدلاً من المرور في BunyanOptions
// 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 التقييمات