captbaritone / raven-for-redux

A Raven middleware for Redux
295 stars 25 forks source link

Not working for new @sentry v4 beta versions #82

Closed mcrawshaw closed 4 years ago

mcrawshaw commented 6 years ago

API has changed. Uncaught TypeError: e.setDataCallback is not a function

captbaritone commented 6 years ago

Thanks for the heads up!

captbaritone commented 6 years ago

I've started looking into this and filed an issue with Sentry to see if we can get support for lazyily setting scope: https://github.com/getsentry/sentry-javascript/issues/1281#issuecomment-411194452

deammer commented 6 years ago

I don't know if this is useful, but I wrote a tiny middleware that logs breadcrumbs to Sentry:

import thunk from 'redux-thunk';
import { applyMiddleware, createStore, compose } from 'redux';
import { init, addBreadcrumb } from '@sentry/browser';

// Sentry middleware
 const sentryReporter = store => next => action => {
  addBreadcrumb({
    message: action.type,
    category: 'redux action',
    level: 'info',
    data: {
      payload: action.payload
    }
  });
  return next(action);
};

// Create the store with our Sentry middleware
const reduxStore = createStore(
  rootReducer,
  composeEnhancers(applyMiddleware(thunk, sentryReporter))
);

// Initialize Sentry
init({ dsn: '...' });

After reading the comments in getsentry/sentry-javascript#1281, I first wrote an "integration" that used store.dispatch() to log to Senty, but I felt like a middleware was cleaner. For reference:

class ReduxSentryIntegration {
  constructor() {
    this.name = 'ReduxSentryIntegration';
  }

  install(reduxStore) {
    this.reduxStore = reduxStore;
    reduxStore.subscribe(this.handleStoreChange);
  }

  handleStoreChange = () => {
    const state = this.reduxStore.getState();
    // ... log things to Sentry
  };
}

// To add the ReduxSentryIntegration:
import { init } from '@sentry/browser';

const store = createStore(rootReducer, compose(applyMiddleware(thunk)));

init({
  dsn: '...'
  integrations: (integrations) => {
     integrations.push(new ReduxSentryIntegration(store));
     return integrations;
  }
});
joan-saum commented 5 years ago

Any news about this issue @captbaritone ?

captbaritone commented 5 years ago

I don’t think I’ll be able to find time to work on this. If someone wants to open a PR, I can review, but this might be a good time for someone to fork. Sorry folks.

sweatherall commented 4 years ago

@captbaritone are there any updates? I just upgraded from react-native-sentry to @sentry/react-native and I am seeing the TypeError: Raven.setDataCallback is not a function in my Sentry logs, and actually it is preventing the app from even loading :(. We would love to continue to use raven/get the redux actions back in the breadcrumbs. LMK if there is anything to do! Thanks!

captbaritone commented 4 years ago

I've written a version that seems to work as part of my Webamp project: https://github.com/captbaritone/webamp/pull/956 it should be a drop-in replacement for raven-for-redux.

My plan is to ship it there to validate that it will work over here. If you want to copy paste that file into your project and see if it works, I'd love to hear what if any problems you encounter.

I think the only real hard work of adopting that code in this code base will be updating the tests, since the existing tests are tightly coupled to the internals of Raven.

captbaritone commented 4 years ago

Actually, this is a dupe of #93. Check out https://github.com/vidit-sh/redux-sentry-middleware it looks like the same idea I was going to do, except better.