@sentry/node integration to wrap bunyan log calls as breadcrumbs










1















Sentry by defaults has integration for console.log to make it part of breadcrumbs:



Link: Import name: Sentry.Integrations.Console



How can we make it to work for bunyan logger as well, like:



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


P.S. I have already tried bunyan-sentry-stream but no success with @sentry/node, it just pushes entries instead of treating them as breadcrumbs.










share|improve this question


























    1















    Sentry by defaults has integration for console.log to make it part of breadcrumbs:



    Link: Import name: Sentry.Integrations.Console



    How can we make it to work for bunyan logger as well, like:



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


    P.S. I have already tried bunyan-sentry-stream but no success with @sentry/node, it just pushes entries instead of treating them as breadcrumbs.










    share|improve this question
























      1












      1








      1








      Sentry by defaults has integration for console.log to make it part of breadcrumbs:



      Link: Import name: Sentry.Integrations.Console



      How can we make it to work for bunyan logger as well, like:



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


      P.S. I have already tried bunyan-sentry-stream but no success with @sentry/node, it just pushes entries instead of treating them as breadcrumbs.










      share|improve this question














      Sentry by defaults has integration for console.log to make it part of breadcrumbs:



      Link: Import name: Sentry.Integrations.Console



      How can we make it to work for bunyan logger as well, like:



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


      P.S. I have already tried bunyan-sentry-stream but no success with @sentry/node, it just pushes entries instead of treating them as breadcrumbs.







      javascript node.js logging sentry bunyan






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 0:01









      Zeeshan Hassan MemonZeeshan Hassan Memon

      5,02832446




      5,02832446






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Bunyan supports custom streams, and those streams are just function calls. See https://github.com/trentm/node-bunyan#streams



          Below is an example custom stream that simply writes to the console. It would be straight forward to use this example to instead write to the Sentry module, likely calling Sentry.addBreadcrumb() or similar function.



          Please note though that the variable record in my example below is a JSON string, so you would likely want to parse it to get the log level, message, and other data out of it for submission to Sentry.




          level: 'debug',
          stream:
          (function ()
          return
          write: function(record)
          console.log('Hello: ' + record);


          )()






          share|improve this answer


















          • 1





            thanks - it worked :)

            – Zeeshan Hassan Memon
            Nov 15 '18 at 21:39










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310580%2fsentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Bunyan supports custom streams, and those streams are just function calls. See https://github.com/trentm/node-bunyan#streams



          Below is an example custom stream that simply writes to the console. It would be straight forward to use this example to instead write to the Sentry module, likely calling Sentry.addBreadcrumb() or similar function.



          Please note though that the variable record in my example below is a JSON string, so you would likely want to parse it to get the log level, message, and other data out of it for submission to Sentry.




          level: 'debug',
          stream:
          (function ()
          return
          write: function(record)
          console.log('Hello: ' + record);


          )()






          share|improve this answer


















          • 1





            thanks - it worked :)

            – Zeeshan Hassan Memon
            Nov 15 '18 at 21:39















          2














          Bunyan supports custom streams, and those streams are just function calls. See https://github.com/trentm/node-bunyan#streams



          Below is an example custom stream that simply writes to the console. It would be straight forward to use this example to instead write to the Sentry module, likely calling Sentry.addBreadcrumb() or similar function.



          Please note though that the variable record in my example below is a JSON string, so you would likely want to parse it to get the log level, message, and other data out of it for submission to Sentry.




          level: 'debug',
          stream:
          (function ()
          return
          write: function(record)
          console.log('Hello: ' + record);


          )()






          share|improve this answer


















          • 1





            thanks - it worked :)

            – Zeeshan Hassan Memon
            Nov 15 '18 at 21:39













          2












          2








          2







          Bunyan supports custom streams, and those streams are just function calls. See https://github.com/trentm/node-bunyan#streams



          Below is an example custom stream that simply writes to the console. It would be straight forward to use this example to instead write to the Sentry module, likely calling Sentry.addBreadcrumb() or similar function.



          Please note though that the variable record in my example below is a JSON string, so you would likely want to parse it to get the log level, message, and other data out of it for submission to Sentry.




          level: 'debug',
          stream:
          (function ()
          return
          write: function(record)
          console.log('Hello: ' + record);


          )()






          share|improve this answer













          Bunyan supports custom streams, and those streams are just function calls. See https://github.com/trentm/node-bunyan#streams



          Below is an example custom stream that simply writes to the console. It would be straight forward to use this example to instead write to the Sentry module, likely calling Sentry.addBreadcrumb() or similar function.



          Please note though that the variable record in my example below is a JSON string, so you would likely want to parse it to get the log level, message, and other data out of it for submission to Sentry.




          level: 'debug',
          stream:
          (function ()
          return
          write: function(record)
          console.log('Hello: ' + record);


          )()







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 4:26









          Nicholas BlasgenNicholas Blasgen

          482412




          482412







          • 1





            thanks - it worked :)

            – Zeeshan Hassan Memon
            Nov 15 '18 at 21:39












          • 1





            thanks - it worked :)

            – Zeeshan Hassan Memon
            Nov 15 '18 at 21:39







          1




          1





          thanks - it worked :)

          – Zeeshan Hassan Memon
          Nov 15 '18 at 21:39





          thanks - it worked :)

          – Zeeshan Hassan Memon
          Nov 15 '18 at 21:39



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310580%2fsentry-node-integration-to-wrap-bunyan-log-calls-as-breadcrumbs%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20