Sentry-javascript: É possível agora? @ sentry / node integration para envolver chamadas de log de bunyan como link SO breadcrumbs: https://stackoverflow.com/questions/53310580/sentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs

Criado em 15 nov. 2018  ·  3Comentários  ·  Fonte: getsentry/sentry-javascript

Como posso fazer integração @ sentry / node para envolver chamadas de log bunyan como breadcrumbs?

Pacote

@sentry/node 4.3.0

Descrição

Por padrão, o Sentry tem integração com console.log para torná-lo parte do breadcrumbs:

Link: Nome da importação: Sentry.Integrations.Console

Como podemos fazê-lo funcionar para o logger de bunyan também, como:

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!');

PS Eu já tentei bunyan-sentry-stream, mas sem sucesso com @ sentry / node , ele apenas envia entradas em vez de tratá-las como migalhas de pão.

Link do SO: https://stackoverflow.com/questions/53310580/sentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs

Question

Comentários muito úteis

https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + como alguém já respondeu no SO:

var log = bunyan.createLogger({
  name: 'myapp',
  streams: [{
  level: 'debug',
  stream: {
    write: function(record) {
      Sentry.addBreadcrumb({
        message: record.msg,
        level: record.level
      });
    }
  }]
});

Todos 3 comentários

https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + como alguém já respondeu no SO:

var log = bunyan.createLogger({
  name: 'myapp',
  streams: [{
  level: 'debug',
  stream: {
    write: function(record) {
      Sentry.addBreadcrumb({
        message: record.msg,
        level: record.level
      });
    }
  }]
});

A pergunta original foi respondida. Sinta-se à vontade para reabrir se ainda tiver mais perguntas.

Se você estiver usando o texto digitado, poderá ter alguns problemas de compilador por não fornecer um WriteableStream com o exemplo acima, portanto, você pode usar o construtor Gravável conforme abaixo.

Além disso:

  • o nível emitido por Bunyan é um número, não uma gravidade Senty, portanto, você deve converter o valor usando level: Sentry.Severity.fromString(nameFromLevel[chunk.level])
  • Não quero substituir o fluxo Bunyan existente, então use a função addStream em vez de passar 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();
    },
  }),
});
Esta página foi útil?
0 / 5 - 0 avaliações