GithubHelp home page GithubHelp logo

redux-rollbar-middleware's Introduction

redux-rollbar-middleware

Redux middleware that integrates Rollbar. If exception happens during the action, it will send information to Rollbar:

  • about the error,
  • about the action that caused it
  • the whole redux store state

It allows to easily override sent state for sanitization (e.g. if you store password or credit card number in your applicationt state).

It demands basically no additional configuration except default Rollbar configuration options.

Installation

Run npm install --save redux-rollbar-middleware.

Add Rollbar.js initial configuration according to docs.

As an exmaple, you can copy following into your section and include Rollbar snippet (not included below):

<script>
  var _rollbarConfig = {
      accessToken: __YOUR_ACCESS_TOKEN__,
      captureUncaught: false,
      captureUnhandledRejections: false,
      payload: {
          environment: "production"
      }
  };
  // <!-- HERE SHOULD BE ROLLBAR SNIPPET, YOU WILL FIND IT ON ROLLBAR JS WEBSITE -->
</script>

Remember that this is only an example configuration, you can easily change everything in your Rollbar config.

Usage

Import rollbarMiddleware function from package:

import rollbarMiddleware from 'redux-rollbar-middleware';

Create middleware in your store creator:

export default function configureStore(initialState) {
  const rollbar = rollbarMiddleware();

  return createStore(
    rootReducer,
    initialState,
    applyMiddleware(rollbar)
  );
}

State sanitization

If you want to sanitize state before sending to Rollbar, pass the sanitization function to rollbarMiddleware function. It accepts current application state and should return a state that will be send to Rollbar.

For example, assume that you store credit card number in your billing object inside your application state:

{
  billing: {
    number: '1234 1234 1234 1234',
    (...)
  },
  (...)
}

To sanitize it, you should provide following function:

const stateSanitizer = function(state) {
  // make sure you don't change state tree
  const stateCopy = Object.assign({}, state);
  // make sure you don't change billing object (by reference)
  const billingCopy = Object.assign({}, stateCopy.billing);
  // override number in billing copy
  billingCopy.number = '######';
  // pass billing copy to state copy
  stateCopy.billing = billingCopy;
  // return sanitized state
  return stateCopy;
}

export default function configureStore(initialState) {
  const rollbar = rollbarMiddleware(stateSanitizer);

  return createStore(
    rootReducer,
    initialState,
    applyMiddleware(rollbar)
  );
}

Maintainers

License

The gem is available as open source under the terms of the MIT License.

redux-rollbar-middleware's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.