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

uber-raven-with-uuid

v0.6.3-1

Published

A standalone (Node.js) client for Sentry

Downloads

2

Readme

Raven

Node v0.11 compatible


** Warning ** This package is not actively supported. It has been forked from uber-raven in order to update the node-uuid dependency.

DO NOT USE THIS PACKAGE UNLESS YOU KNOW WHAT YOU ARE DOING!


Log errors and stack traces in Sentry from within your Node.js applications. Includes middleware support for Connect/Express.

All processing and sending happens asynchronously to not slow things down if/when Sentry is down or slow.

Compatibility

  • 0.6.x
  • 0.8.x
  • 0.10.x
  • 0.11.x

Raven 0.6+ requires Sentry 6.0+

Installation

$ npm install raven

Methods

new raven.Client(String dsn[, Object options])
client.captureMessage(String message[[, Object options], Function callback])
client.captureError(Error error[[, Object options], Function callback])
client.captureQuery(String query[[, String type], Function callback])

Basic Usage

var raven = require('raven');
var client = new raven.Client('{{ SENTRY_DSN }}');

client.captureMessage('Hello, world!');

You can specify a level in the second optional parameter. Default level is error

There are 5 logging levels (in order):

  • debug (the least serious)
  • info
  • warning
  • error
  • fatal (the most serious)
var raven = require('raven');

var client = new raven.Client('{{ SENTRY_DSN }}');

client.captureMessage("Another message", {level: 'info'})

Adding extra info to messages

var raven = require('raven');

var client = new raven.Client('{{ SENTRY_DSN }}');

client.captureMessage("Another message", {level: 'info', extra: {'key': 'value'}})

Logging an error

client.captureError(new Error('Broke!'));

Logging a query

client.captureQuery('SELECT * FROM `awesome`', 'mysql');

Sentry Identifier

client.captureMessage('Hello, world!', function(result) {
    console.log(client.getIdent(result));
});
client.captureError(new Error('Broke!'), function(result) {
  console.log(client.getIdent(result));
});

Note: client.captureMessage will also return the result directly without the need for a callback, such as: var result = client.captureMessage('Hello, world!');

Events

If you really care if the event was logged or errored out, Client emits two events, logged and error:

client.on('logged', function(){
  console.log('Yay, it worked!');
});
client.on('error', function(e){
  console.log('oh well, Sentry is broke.');
})
client.captureMessage('Boom');

Error Event

The event error is augmented with the original Sentry response object as well as the response body and statusCode for easier debugging.

client.on('error', function(e){
  console.log(e.reason);  // raw response body, usually contains a message explaining the failure
  console.log(e.statusCode);  // status code of the http request
  console.log(e.response);  // entire raw http response object
});

Environment variables

SENTRY_DSN

Optionally declare the DSN to use for the client through the environment. Initializing the client in your app won't require setting the DSN.

SENTRY_NAME

Optionally set the name for the client to use. What is name?

SENTRY_SITE

Optionally set the site for the client to use. What is site?

Catching global errors

For those times when you don't catch all errors in your application. ;)

client.patchGlobal();
// or
raven.patchGlobal(client);
// or
raven.patchGlobal('{{ SENTRY_DSN }}');

It is recommended that you don't leave the process running after receiving an uncaughtException (http://nodejs.org/api/process.html#process_event_uncaughtexception), so an optional callback is provided to allow you to hook in something like:

client.patchGlobal(function() {
  console.log('Bye, bye, world.');
  process.exit(1);
});

The callback is called after the event has been sent to the Sentry server.

Integrations

Connect/Express middleware

The Raven middleware can be used as-is with either Connect or Express in the same way. Take note that in your middlewares, Raven must appear after your main handler to pick up any errors that may result from handling a request.

Connect

var connect = require('connect');
function mainHandler(req, res) {
  throw new Error('Broke!');
}
function onError(err, req, res, next) {
  // The error id is attached to `res.sentry` to be returned
  // and optionally displayed to the user for support.
  res.statusCode = 500;
  res.end(res.sentry+'\n');
}
connect(
  connect.bodyParser(),
  connect.cookieParser(),
  mainHandler,
  raven.middleware.connect('{{ SENTRY_DSN }}'),
  onError, // optional error handler if you want to display the error id to a user
).listen(3000);

Express

var app = require('express')();
app.use(app.router);
app.use(raven.middleware.express('{{ SENTRY_DSN }}'));
app.use(onError); // optional error handler if you want to display the error id to a user
app.get('/', function mainHandler(req, res) {
  throw new Error('Broke!');
});
app.listen(3000);

Note: raven.middleware.express or raven.middleware.connect must be added to the middleware stack before any other error handling middlewares or there's a chance that the error will never get to Sentry.

Coffeescript

In order to use raven-node with coffee-script or another library which overwrites Error.prepareStackTrace you might run into the exception "Traceback does not support Error.prepareStackTrace being defined already."

In order to not have raven-node (and the underlying raw-stacktrace library) require Traceback you can pass your own stackFunction in the options. For example:

var client = new raven.Client('{{ SENTRY_DSN }}', { stackFunction: {{ Your stack function }}});

So for example:

var client = new raven.Client('{{ SENTRY_DSN }}', {
  stackFunction: Error.prepareStackTrace
});

Disable Raven

Pass false as the DSN (or any falsey value).

client = new raven.Client(process.env.NODE_ENV === 'production' && '{{ SENTRY_DSN }}')

Note: We don't infer this from NODE_ENV automatically anymore. It's up to you to implement whatever logic you'd like.

Support

You can find me on IRC. I troll in #sentry on freenode.