Node.js

On this page, we provide concise information to get you up and running with Sentry's Node SDK, automatically reporting errors and exceptions in your application.

Take a look at our specific guides to get started.

Install

Add @sentry/node as a dependency:

Copied
npm install --save @sentry/node

Configure

Copied
const Sentry = require("@sentry/node");

Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0" });

Usage

Copied
try {
  // ...
} catch (e) {
  Sentry.captureException(e);
}

Monitor Performance

To get started with performance monitoring with Node.js, first install these packages:

Copied
npm install --save @sentry/node @sentry/tracing

To send traces, set the tracesSampleRate to a nonzero value. The following configuration will capture 100% of all your transactions:

Copied
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  // We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: 1.0,
});

Performance data is transmitted using a new event type called "transactions", which you can learn about in Distributed Tracing. To capture transactions, you must install the performance package and configure your SDK to set the tracesSampleRate option to a nonzero value. The example configuration above will transmit 100% of captured transactions. You will want to lower this value in production, otherwise you could burn through your quota quickly.

Verify Setup

Verify your setup by intentionally sending a transaction manually to Sentry. Make sure your sampling rate is at 1.0 so that your transaction captured and sent to Sentry.

Copied
const transaction = Sentry.startTransaction({
  op: "test",
  name: "My First Test Transaction",
});

setTimeout(() => {
  try {
    foo();
  } catch (e) {
    Sentry.captureException(e);
  } finally {
    transaction.finish();
  }
}, 99);
You can edit this page on GitHub.