This package provides a Redux middleware designed to integrate Redux state and actions with Sentry's unified APIs (`@sentry/browser` and `@sentry/node`). It captures dispatched actions as Sentry breadcrumbs and attaches the last action and current Redux state as additional context to error reports. The package is a rewrite of `raven-for-redux` to support newer Sentry SDKs. The latest published version is 0.2.2, released on September 7, 2018, indicating it is no longer actively maintained and has been superseded by Sentry's official Redux integration, `Sentry.createReduxEnhancer`.
npm install redux-sentry-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up `redux-sentry-middleware` with a Redux store, initializing Sentry, and using the middleware to capture actions and state. It includes examples of `breadcrumbDataFromAction`, `actionTransformer`, and `stateTransformer` to manage what data is sent to Sentry, including handling sensitive information and simulating an error.
Migrate to Sentry's official Redux integration, `Sentry.createReduxEnhancer`, which is actively maintained and designed for current Sentry SDK versions.
Carefully transform your action data within `breadcrumbDataFromAction` to ensure it is a flat object with string values. Only include essential, non-sensitive information.
Implement these transformers to filter or truncate large or sensitive data, returning a new, modified object rather than mutating the original. Increase Sentry's `normalizeDepth` during initialization if your state is genuinely deep and needs to be captured.
When applying middleware using `applyMiddleware`, ensure `redux-sentry-middleware` is positioned appropriately in the array based on your desired error reporting and action flow. The Sentry blog suggests it should be the first argument to `applyMiddleware` if you want it to capture errors from other middleware. However, the README for this specific package suggests preceding it with intercepting middlewares. This might imply different behavior than newer official Sentry enhancers. For modern Sentry integrations, `Sentry.createReduxEnhancer` is typically passed directly to `createStore` or `configureStore` as an enhancer, not via `applyMiddleware`.
Ensure `Sentry.init()` has been called successfully before creating the middleware and that you are using a version of `@sentry/browser` or `@sentry/node` compatible with this middleware (likely older versions, pre-v7).
Confirm that `createSentryMiddleware` is imported as a default export (`import createSentryMiddleware from 'redux-sentry-middleware';`) and that it is called with the `Sentry` object as the first argument: `createSentryMiddleware(Sentry, options?)`.
Review your `actionTransformer` and `stateTransformer` to ensure they return relevant, serializable data within Sentry's size limits. For `breadcrumbDataFromAction`, verify that the returned object is 'flat' (only string values). Consider increasing `normalizeDepth` in your `Sentry.init` call if your state is very deep and important for debugging.