https://github.com/auru/redux-sentry
Middleware that logs all your store and actions on exception to Sentry with raven-js
https://github.com/auru/redux-sentry
raven redux sentry
Last synced: 7 months ago
JSON representation
Middleware that logs all your store and actions on exception to Sentry with raven-js
- Host: GitHub
- URL: https://github.com/auru/redux-sentry
- Owner: auru
- License: mit
- Created: 2016-11-22T08:11:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T00:27:22.000Z (over 5 years ago)
- Last Synced: 2025-02-17T02:45:43.756Z (8 months ago)
- Topics: raven, redux, sentry
- Language: TypeScript
- Size: 156 KB
- Stars: 13
- Watchers: 5
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Redux sentry
> Includes middleware that logs all your store and actions on exception to Sentry with raven-js
# Table of Contents
* [Installation](#installation)
* [Usage](#usage)
* [Contributing](#contributing)
* [License](#license)# Installation
Install `redux-sentry` package from npm:
```bash
npm i --save redux-sentry
```# Usage
`redux-sentry` can be used in cases:
* Raven has been initialized before
```js
/* store.js */import { SENTRY_SETTINGS, VERSION } from './constants';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import createSentryMiddleware from 'redux-sentry';
const sentryMiddleware = createSentryMiddleware();
// Add sentry middleware to your list of middlewares
const middlewares = [ sentryMiddleware ];// Enhance your store by using sentry's enhancer
const toEnhance = [
applyMiddleware(...middlewares)
];// Put it all together
const enhancer = compose(...toEnhance);
const reducers = combineReducers({
// combined reducers
});const initialState = {}
const store = createStore(reducers, initialState, enhancer);
export default store;
```* Raven hasn't been initialized. It should be configured by params
```js
/* store.js */import { SENTRY_SETTINGS, VERSION } from './constants';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import createSentryMiddleware from 'redux-sentry';
const sentryMiddleware = createSentryMiddleware({
dsn: SENTRY_SETTINGS.DSN,
configuration: {
release: VERSION,
collectWindowErrors: true
},
username: parse(document.cookie).login
});// Add sentry middleware to your list of middlewares
const middlewares = [ sentryMiddleware ];// Enhance your store by using sentry's enhancer
const toEnhance = [
applyMiddleware(...middlewares)
];// Put it all together
const enhancer = compose(...toEnhance);
const reducers = combineReducers({
// combined reducers
});const initialState = {}
const store = createStore(reducers, initialState, enhancer);
export default store;
```# API
## `createSentryMiddleware({ dsn, configuration = {}, username }, transform = {})`
```js
import createSentryMiddleware from 'redux-sentry';
```Middleware that logs all your store and actions on exception to Sentry with raven-js
### `dsn` {String}
`DSN` – [Data Source Name](https://docs.sentry.io/quickstart/#about-the-dsn). Unique name generated for the project by you Sentry.### `configuration` {Object} *optional*
Raven configuration object. Full list of keys can be found [here](https://docs.sentry.io/clients/javascript/config/).### `username` {String} *optional*
**Default:** `Guest`
`username` used for [setting user context](https://docs.sentry.io/clients/javascript/usage/#tracking-users).```js
Raven.setUserContext({ username });
```### `transform` {Object} *optional*
**Default:**
```js
{
actionTransform: a => a,
stateTransform: a => a.toJS()
}
```
Functions used for cooking action object, store for Raven's `extra` field.
`stateTransform` uses toJS from immutable.js to convert state back to raw JavaScript object.# Contributing
* Provide [conventional commit messages](https://github.com/conventional-changelog/conventional-changelog-angular/blob/master/convention.md) by using `npm run commit` instead of `git commit`.
* **Core contributors:** use GitHub's *Rebase and merge* as a default way of merging PRs.# License
MIT © AuRu