npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icecreambar

v5.0.1

Published

hapi plugin for rollbar error logging

Downloads

14

Readme

logo

ice cream bar Build Status

hapi plugin for Rollbar error logging

quick and easy

let accessToken = process.env.ROLLBAR_SERVER_ITEM_ACCESS_TOKEN;

server.register({
  register: require('icecreambar'),
  options: { accessToken }
}, function (err) {

  if (err) { throw err; }

  var rollbar = server.plugins.icecreambar;
  rollbar.handleUncaughtExceptions(accessToken, { exitOnUncaughtException: true });
});

thorough example

// http://hapijs.com/api#server
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 3000 });

server.route({
  method: 'get',
  path: '/foo',
  handler: function(request, reply) {

    // implicitly trigger an error to be recorded to Rollbar via `rollbar.handleError`:
    reply(new Error('ruh-roh!'));

    // access the underlying rollbar library directly
    var rollbar = server.plugins.icecreambar;

    // implicitly log [stuff] to rollbar's recordMessage
    // leveraging hapi's built in logging system
    // http://hapijs.com/api#serverlogtags-data-timestamp
    server.log(['rollbarMessage'], 'Interesting thing just happened [somewhere in the server]');
    request.log(['rollbarMessage'], 'Interesting thing just happened [in the current request]');

    // implicitly log [stuff] to rollbar's handleError
    // leveraging hapi's built in logging system
    // http://hapijs.com/api#serverlogtags-data-timestamp
    server.log(['rollbarError'], new Error('ruh-roh, bad server'));
    request.log(['rollbarError'], new Error('ruh-roh, bad request'));

    // access the underlying rollbar library directly
    var rollbar = server.plugins.icecreambar;
    // and then proceed to do what you'd like with it...

    // respond to the client
    reply('ok');
  }
});

let accessToken = process.env.ROLLBAR_SERVER_ITEM_ACCESS_TOKEN;

server.register({
  register: require('icecreambar'),
  options: { accessToken }
}, function (err) {

  if (err) { throw err; }
  server.start();
});

person tracking

The personTracking option toggles passing user identifiers to Rollbar with errors and messages. To enable this feature, include personTracking: true in your options object. By default, this feature inspects request.auth.credentials for id, email and username parameters to send along with Rollbar requests. If your application uses different key names then you can configure them via an object as follows;


let accessToken = process.env.ROLLBAR_SERVER_ITEM_ACCESS_TOKEN;

server.register({
  register: require('icecreambar'),
  options: {
    accessToken,
    personTracking: {
      // define your request.auth.credentials attribute names if they differ from the defaults, for example:
      email: 'my_email_key_name',
      id: 'my_id_key_name',
      username: 'my_user_name_key_name'
    }

    /* Defaults to {
      email: 'email_address',
      id: 'identifier',
      username: 'user_name'
    } */
    personTracking: true
  }
}, function (err) {

  if (err) { throw err; }
  server.start();
});

uncaught exceptions

This feature should only be registered on the project level; i.e., do not enable it in your plugin(s), as the result could be unexpeted error reporting and/or duplicated errors. To leverage this feature, either require the rollbar module directly or access a registered instance (e.g. server.plugins.icecreambar). Either way, it'll look something like this:

var rollbar = require('rollbar'); // this requires `rollbar` is installed to your `node_modules` folder
var rollbar = server.plugins.icecreambar; // this requires that you've registered `icecreambar` without a scope, or explicitly named the scope `default`. you can substitute `default` for any registered scope.

rollbar.handleUncaughtExceptions('POST_SERVER_ITEM_ACCESS_TOKEN', { exitOnUncaughtException: true });

important

As of version 4.0.0 this module no longer supports scopes and can only be registered once. There is only one rollbar instance -- server.plugins.icecreambar. icecreambar.default continues to exist as a deprecated alias.