UNPKG

1.94 kBMarkdownView Raw
1<p align="center">
2 <a href="https://sentry.io" target="_blank" align="center">
3 <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4 </a>
5 <br />
6</p>
7
8# Official Sentry SDK for NodeJS
9
10[![npm version](https://img.shields.io/npm/v/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
11[![npm dm](https://img.shields.io/npm/dm/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
12[![npm dt](https://img.shields.io/npm/dt/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
13[![typedoc](https://img.shields.io/badge/docs-typedoc-blue.svg)](http://getsentry.github.io/sentry-javascript/)
14
15## Links
16
17- [Official SDK Docs](https://docs.sentry.io/quickstart/)
18- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
19
20## Usage
21
22To use this SDK, call `init(options)` as early as possible in the main entry module. This will initialize the SDK and
23hook into the environment. Note that you can turn off almost all side effects using the respective options.
24
25```javascript
26// ES5 Syntax
27const Sentry = require('@sentry/node');
28// ES6 Syntax
29import * as Sentry from '@sentry/node';
30
31Sentry.init({
32 dsn: '__DSN__',
33 // ...
34});
35```
36
37To set context information or send manual events, use the exported functions of `@sentry/node`. Note that these
38functions will not perform any action before you have called `init()`:
39
40```javascript
41// Set user information, as well as tags and further extras
42Sentry.configureScope(scope => {
43 scope.setExtra('battery', 0.7);
44 scope.setTag('user_mode', 'admin');
45 scope.setUser({ id: '4711' });
46 // scope.clear();
47});
48
49// Add a breadcrumb for future events
50Sentry.addBreadcrumb({
51 message: 'My Breadcrumb',
52 // ...
53});
54
55// Capture exceptions, messages or manual events
56Sentry.captureMessage('Hello, world!');
57Sentry.captureException(new Error('Good bye'));
58Sentry.captureEvent({
59 message: 'Manual',
60 stacktrace: [
61 // ...
62 ],
63});
64```