An open API service indexing awesome lists of open source software.

https://github.com/bahmutov/node-sentry-error-reporter

Automatically reports Node crashes to Sentry if SENTRY_URL / SENTRY_DSN is in the environment
https://github.com/bahmutov/node-sentry-error-reporter

node raven sentry

Last synced: 2 days ago
JSON representation

Automatically reports Node crashes to Sentry if SENTRY_URL / SENTRY_DSN is in the environment

Awesome Lists containing this project

README

          

# node-sentry-error-reporter

> Automatically reports Node crashes to Sentry if SENTRY_URL is in the environment

[![NPM][npm-icon] ][npm-url]

[![Build status][ci-image] ][ci-url]
[![semantic-release][semantic-image] ][semantic-url]

## Install

npm i -S node-sentry-error-reporter

## Use

The goal is to have zero configuration reporter that handles global or app's errors
automatically.

Set environment variable `SENTRY_URL` if you need exception reporting.
Then just require the module and pass (if needed) a server object, for example an Express app.

```js
const reporter = require('node-sentry-error-reporter')
reporter()
// or if inside Express app
const app = express()
reporter(app)
```

If `NODE_ENV` is 'production' the errors will be forwarded to the Sentry server,
otherwise just printed to the console error stream.

## Report an error

The module returns a function you can use to report instances of error.

```js
const init = require('node-sentry-error-reporter')
const report = init()
report(new Error('something went wrong'))
```

The function `init` is memoized, thus you can call it from multiple modules, and it will
only init once.

You can pass additional details object after the error

```js
report(new Error('something went wrong'), {foo: 42})
```

## Release / version

This package tries to send "release" or "version" string with each error.
It is looked up from the environment settings under `VERSION`, `RELEASE`, etc. names,
or if not found, from the current folder's `package.json`.
See [src/find-version.js](src/find-version.js) source file.

## How to exit

If you are reporting an error and then exiting the Node process, you need to give the reporter
enough time to make HTTP post to the crash server. I would recommend at least 1 second delay.

```js
somethingFails()
.catch((error) => {
reportError(error, {other: details})
setTimeout(() => process.exit(-1), 1000)
}
})
```

### Small print

Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2016

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet /
[open issue](https://github.com/bahmutov/node-sentry-error-reporter/issues) on Github

## MIT License

Copyright (c) 2016 Gleb Bahmutov <gleb.bahmutov@gmail.com>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

[npm-icon]: https://nodei.co/npm/node-sentry-error-reporter.png?downloads=true
[npm-url]: https://npmjs.org/package/node-sentry-error-reporter
[ci-image]: https://travis-ci.org/bahmutov/node-sentry-error-reporter.png?branch=master
[ci-url]: https://travis-ci.org/bahmutov/node-sentry-error-reporter
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-url]: https://github.com/semantic-release/semantic-release