¿Cómo puedo hacer la integración de @ sentry / node para envolver las llamadas de registro de bunyan como migas de pan?
@sentry/node
4.3.0
Sentry por defecto tiene integración para console.log para que sea parte de las rutas de navegación:
Enlace: Nombre de importación: Sentry.Integrations.Console
¿Cómo podemos hacer que funcione también para bunyan logger , 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!');
PD: Ya probé bunyan-sentry-stream pero no @ sentry / node , simplemente empuja las entradas en lugar de tratarlas como migas de pan.
https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + como alguien ya respondió en el SO:
var log = bunyan.createLogger({
name: 'myapp',
streams: [{
level: 'debug',
stream: {
write: function(record) {
Sentry.addBreadcrumb({
message: record.msg,
level: record.level
});
}
}]
});
La pregunta original fue respondida. No dude en reabrir si aún tiene más preguntas.
Si está utilizando mecanografiado, puede tener algunos problemas con el compilador por no proporcionar un WriteableStream con el ejemplo anterior, por lo tanto, puede usar el constructor Writeable como se muestra a continuación.
Adicionalmente:
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();
},
}),
});
Comentario más útil
https://docs.sentry.io/enriching-error-data/breadcrumbs/?platform=browser + como alguien ya respondió en el SO: