Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jsynowiec/good-sentry

Sentry broadcasting for good process monitor
https://github.com/jsynowiec/good-sentry

good hapi hapi-good hapi-raven hapi-sentry hapijs logging raven sentry sentry-client

Last synced: 3 months ago
JSON representation

Sentry broadcasting for good process monitor

Awesome Lists containing this project

README

        

# good-sentry

[Sentry](https://sentry.io) broadcasting for [good](https://github.com/hapijs/good) process monitor.

`good-sentry` is a write stream used to send [hapi](https://github.com/hapijs/hapi) server events to a Sentry server.

[![Current Version](https://img.shields.io/npm/v/good-sentry.svg)](https://www.npmjs.com/package/good-sentry)
[![Build Status](https://travis-ci.org/jsynowiec/good-sentry.svg?branch=master)](https://travis-ci.org/jsynowiec/good-sentry)
[![License][badge-license]][license]

## Usage
### `new GoodSentry ([options])`

Creates a new GoodSentry object with the following arguments:

- `[options]` - optional configuration object with the following keys
- `[dsn]` - Sentry project's Data Source Name. Defaults to `null` but expects `SENTRY_DSN` environment variable to be set.
- `[config]` - optional configuration object with the following keys
- `[name]` - The name of the logger used by Sentry. Defaults to hostname. Optionally set the name using `SENTRY_NAME` environment variable.
- `[logger]` - The name of the Sentry client. Defaults to ''.
- `[release]` - The version/release of your application. Defaults to ''. Optionally set the release using `SENTRY_RELEASE` environment variable.
- `[environment]` - The environment name of your application. Defaults to ''. Optionally set the environment using `SENTRY_ENVIRONMENT` environment variable.
- `[captureUncaught]` - Enable global error handling. Defaults to `false`.

### Tags

Because [Hapi tags](https://hapijs.com/tutorials/logging) are an array of strings and Sentry expects tags to be a k/v map, `good-sentry` sets all tags associated with an event to `tag: true` pairs. Those are nicely displayed in the tags section of Sentry web interface:

![Tags in Sentry](assets/sentry-issue-tags.png)

### Example Usage

```javascript
const Hapi = require('hapi');
const version = require('package.json').version;
const server = new Hapi.Server();
server.connection();

const options = {
reporters: {
mySentryReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*' }],
}, {
module: 'good-sentry',
args: [ {
dsn: 'https://:@sentry.io/',
config: {
name: 'myAwesomeHapiServer',
logger: 'mySentryReporter',
release: version,
environment: process.env.NODE_ENV,
},
captureUncaught: true,
}],
}],
},
};

server.register({
register: require('good'),
options,
}, (err) => {
server.start(() => {
server.log([], 'Sample debug event.');
server.log(['debug'], 'Sample tagged debug event.');
server.log(['info'], 'Sample info event.');
server.log(['warning', 'server'], 'Sample warning event with tags.');
server.log(['error', 'first-tag', 'second-tag'], 'Sample error event with tags.');

// Throw an error after 5 seconds
setTimeout(() => {
throw new Error('An uncaught error');
}, 5000);
});
});
```

This example sets up the reporter named mySentryReporter to listen for server events and send them to a Sentry project with additional settings.

## License
Released under the [MIT license][license].

[license]: https://raw.githubusercontent.com/jsynowiec/good-sentry/master/LICENSE
[badge-license]: https://img.shields.io/github/license/jsynowiec/good-sentry.svg