redux-sentry

1.4.1 • Public • Published

Redux sentry

Includes middleware that logs all your store and actions on exception to Sentry with raven-js

Table of Contents

Installation

Install redux-sentry package from npm:

npm i --save redux-sentry

Usage

redux-sentry can be used in cases:

  • Raven has been initialized before
/* 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
/* 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 = {})

import createSentryMiddleware from 'redux-sentry';

Middleware that logs all your store and actions on exception to Sentry with raven-js

dsn {String}

DSNData Source Name. Unique name generated for the project by you Sentry.

configuration {Object} optional

Raven configuration object. Full list of keys can be found here.

username {String} optional

Default: Guest username used for setting user context.

Raven.setUserContext({ username });

transform {Object} optional

Default:

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

Package Sidebar

Install

npm i redux-sentry

Weekly Downloads

4

Version

1.4.1

License

MIT

Last publish

Collaborators

  • blackheart
  • dench
  • evilj0e