0

I would like to use Opbeat with Totaljs. Do you have an idea how to use this tool with Total?

Thank you

Beta
  • 5
  • 2

1 Answers1

0

While i haven't tried i believe the way to use Opbeat in Total.js is as follows

Place bellow code above require('total.js').http(....) or basicly at the very top of the file where this line require('total.js').http(....) is used.

// globally available OPBEAT can be used throughout the application
global.OPBEAT = require('opbeat').start({
  // see documentations for more info
  appId: '<app id>',
  organizationId: '<org id>',
  secretToken: '<token>'
});

require('total.js').http(....);

for logging errors or whatever you want you can use any of framework events

but since the framework doesn't emit event in case of error the easiest you can do is to overwrite bellow function, place the code bellow in some definition file

Framework.prototype.onError = function(err, name, uri) {

    OPBEAT.captureError(err);

    // original code can be left as is
    console.log('======= ' + (new Date().format('yyyy-MM-dd HH:mm:ss')) + ': ' + (name ? name + ' ---> ' : '') + err.toString() + (uri ? ' (' + parser.format(uri) + ')' : ''), err.stack);
    return this;
};

EDIT

one of these may be needed for showing the URL in Opbeat dashboard

F.on('request', function(req, res) {

    OPBEAT.setTransactionName(req.method + ' ' + req.url);

});

F.on( 'controller', function( controller, name ) {

  OPBEAT.setTransactionName(controller.route.method + ' ' + controller.route.url);

});
Molda
  • 5,619
  • 2
  • 23
  • 39