UNPKG

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