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.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
Take a look at our specific guides to get started.
Install
Add @sentry/node as a dependency:
npm install --save @sentry/nodeConfigure
const Sentry = require("@sentry/node");
Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0" });Usage
try {
// ...
} catch (e) {
Sentry.captureException(e);
}Monitor Performance
To get started with performance monitoring with Node.js, first install these packages:
npm install --save @sentry/node @sentry/tracingTo send traces, set the tracesSampleRate to a nonzero value. The following configuration will capture 100% of all your transactions:
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.
const transaction = Sentry.startTransaction({
op: "test",
name: "My First Test Transaction",
});
setTimeout(() => {
try {
foo();
} catch (e) {
Sentry.captureException(e);
} finally {
transaction.finish();
}
}, 99);- Package:
- npm:@sentry/node
- Version:
- 5.25.0
- Repository:
- https://github.com/getsentry/sentry-javascript