2.0.0 • Published 8 years ago

node-sentry-error-reporter v2.0.0

Weekly downloads
28
License
MIT
Repository
github
Last release
8 years ago

node-sentry-error-reporter

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

NPM

Build status semantic-release

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.

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.

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

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 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.

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 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.

2.0.0

8 years ago

1.8.0

9 years ago

1.7.2

9 years ago

1.7.1

9 years ago

1.7.0

9 years ago

1.6.0

9 years ago

1.5.1

9 years ago

1.5.0

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago