Skip to content

auru/redux-sentry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published