8000 raven-node/docs/index.rst at remove-env · jakedahm/raven-node · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
109 lines (72 loc) · 2.88 KB

index.rst

File metadata and controls

109 lines (72 loc) · 2.88 KB
.. sentry:edition:: self

    raven-node
    ==========

.. sentry:edition:: hosted, on-premise

    .. class:: platform-node

    Node.js
    =======

raven-node is a Sentry's officially supported Node.js SDK.

Note: If you're using JavaScript in the browser, you'll need raven-js.

Installation

Raven is distributed via npm:

$ npm install raven --save

Configuring the Client

Next you need to initialize the Raven client and configure it to use your Sentry DSN:

var raven = require('raven');
var client = new raven.Client('___DSN___');

You can optionally pass an object of configuration options as the 2nd argument to Client. For more information, see :doc:`config`.

Reporting Errors

To get started passing errors to Raven, it is recommended to initialize Raven's global error handler using patchGlobal. This will cause any uncaught exception which would bubble up to the Node runtime to be captured and processed by Raven.

client.patchGlobal();
Additionally, you can manually capture and report potentially problematic code with try...catch and
captureException:
try {
    doSomething(a[0])
} catch(e) {
    client.captureException(e)
}

The captureException method optionally takes an object of configuration options as the 2nd argument. For more information, and to learn about other methods provided by the Raven API, see :doc:`usage`.

Adding Context

While a user is logged in, you can tell Sentry to associate errors with user data. This data is then submitted with each error which allows you to figure out which users are affected.

client.setUserContext({
    email: 'matt@example.com',
    id: '123'
})

If at any point, the user becomes unauthenticated, you can call client.setUserContext() with no arguments to remove their data.

Other similar methods are client.setExtraContext and client.setTagsContext. See :ref:`raven-node-additional-context` for more info.

Middleware and Integrations

If you're using Node.js with a web server framework/library like Connect, Express, or Koa, it is recommended to configure one of Raven's server middleware integrations. See doc:integrations/index.

Deep Dive

For more detailed information about how to get most out of Raven.js there is additional documentation available that covers all the rest:

.. toctree::
   :maxdepth: 2
   :titlesonly:

   config
   usage
   integrations/index
   coffeescript

Resources:

0