{"id":17887,"library":"raven-for-redux","title":"Sentry Raven Middleware for Redux","description":"raven-for-redux is a Redux middleware designed to integrate Redux state and actions with Sentry's error tracking platform through the legacy raven-js client. It intercepts dispatched actions, logging their types as breadcrumbs and attaching the last action and current Redux state as additional context to all errors, not just reducer exceptions. As of version 1.4.0, it requires raven-js version 3.9.0 or higher, with a known bug triggered by raven-js 3.14.0. The library differentiates itself by allowing the Sentry Raven client to be injected, providing flexible configuration, and offering options to filter action breadcrumbs and define user context mappings from the Redux state. Its release cadence has been infrequent, and its primary dependency, raven-js, is officially deprecated in favor of `@sentry/browser`, making this package suitable only for projects using older Sentry integrations.","status":"deprecated","version":"1.4.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/captbaritone/raven-for-redux","tags":["javascript","middleware","raven","redux","error","logging","context"],"install":[{"cmd":"npm install raven-for-redux","lang":"bash","label":"npm"},{"cmd":"yarn add raven-for-redux","lang":"bash","label":"yarn"},{"cmd":"pnpm add raven-for-redux","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for Redux store integration and middleware application.","package":"redux","optional":false},{"reason":"The core Sentry JavaScript client library that this middleware integrates with. Note that raven-js itself is deprecated by Sentry.","package":"raven-js","optional":false}],"imports":[{"note":"The main middleware factory function is a default export in JavaScript. TypeScript users should use `import * as createRavenMiddleware`.","wrong":"import { createRavenMiddleware } from 'raven-for-redux';","symbol":"createRavenMiddleware","correct":"import createRavenMiddleware from 'raven-for-redux';"},{"note":"For TypeScript projects utilizing DefinitelyTyped typings, the 'import * as' syntax is required for correct type inference due to the way the module is structured.","wrong":"import createRavenMiddleware from 'raven-for-redux';","symbol":"createRavenMiddleware (TypeScript)","correct":"import * as createRavenMiddleware from 'raven-for-redux';"},{"note":"The Raven object from the 'raven-js' package is a direct dependency of the middleware. `raven-js` is a legacy Sentry client and is largely CommonJS-style, but also supports ESM imports in modern bundlers.","wrong":"const Raven = require('raven-js');","symbol":"Raven","correct":"import Raven from 'raven-js';"}],"quickstart":{"code":"import Raven from \"raven-js\";\nimport { createStore, applyMiddleware, combineReducers } from \"redux\";\nimport createRavenMiddleware from \"raven-for-redux\";\n\n// Mock reducer for demonstration\nconst initialState = { count: 0, user: { id: 1, name: 'Guest' } };\nfunction reducer(state = initialState, action) {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { ...state, count: state.count + 1 };\n    case 'LOGIN':\n      return { ...state, user: action.payload };\n    default:\n      return state;\n  }\n}\n\n// Initialize Raven (or mock it for local development without a DSN)\nconst SENTRY_DSN = process.env.SENTRY_DSN ?? \"https://examplePublicKey@o0.ingest.sentry.io/0\";\n// In a real application, you would always provide a valid DSN.\nRaven.config(SENTRY_DSN).install();\n\nconst store = createStore(\n    reducer,\n    applyMiddleware(\n        // Middlewares that intercept or emit actions should generally precede raven-for-redux.\n        createRavenMiddleware(Raven, {\n            breadcrumbMessageFromAction: action => action.type,\n            breadcrumbDataFromAction: action => ({ actionPayload: action.payload }),\n            stateContext: state => ({ user: state.user }),\n            actionFilter: action => action.type !== 'IGNORE_THIS_ACTION'\n        })\n    )\n);\n\n// Dispatch some actions to generate breadcrumbs\nstore.dispatch({ type: 'INCREMENT' });\nstore.dispatch({ type: 'LOGIN', payload: { id: 123, name: 'Alice' } });\nstore.dispatch({ type: 'INCREMENT' });\nstore.dispatch({ type: 'IGNORE_THIS_ACTION' }); // This action will be filtered out\n\n// Simulate an error to capture state and breadcrumbs\ntry {\n  throw new Error(\"Simulated error during user interaction!\");\n} catch (e) {\n  Raven.captureException(e);\n}\n\nconsole.log('Final State:', store.getState());\n// In a real app, console.logs would typically be replaced by actual Sentry reports.\n","lang":"javascript","description":"This example demonstrates how to integrate `raven-for-redux` with a Redux store, capturing actions as Sentry breadcrumbs and attaching state context to errors. It includes a mock reducer, Raven initialization, and an example of error capturing with custom options."},"warnings":[{"fix":"Consider migrating your Sentry integration to the `@sentry/browser` and `@sentry/redux` packages for continued support and new features. This package will not work with modern Sentry SDKs.","message":"The underlying Sentry client, `raven-js`, is officially deprecated by Sentry. New projects should migrate to `@sentry/browser` and `@sentry/redux` for modern Sentry integration.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Avoid using `raven-js` version 3.14.0. Downgrade to an earlier 3.x version or upgrade to a later version if available and compatible. The best long-term solution is to migrate to `@sentry/browser`.","message":"A specific bug exists in `raven-js` version 3.14.0 that can be triggered by `raven-for-redux`, potentially preventing breadcrumbs or errors from being reported correctly.","severity":"gotcha","affected_versions":"=3.14.0 (for raven-js)"},{"fix":"Ensure `createRavenMiddleware` is the last middleware applied in your `applyMiddleware` chain if other middlewares modify or generate actions.","message":"`raven-for-redux` middleware should be placed *after* other Redux middlewares (like `redux-thunk` or `redux-promise`) that might intercept, transform, or emit new actions. Incorrect placement can lead to actions not being logged or incorrect state being attached.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be selective about the data returned by `breadcrumbDataFromAction`, including only necessary, non-sensitive, and small pieces of information to avoid performance issues and Sentry data caps.","message":"The `breadcrumbDataFromAction` option, while powerful, should be used with caution. Logging large or sensitive portions of the action object or state can negatively impact performance and Sentry event size limits.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `import * as createRavenMiddleware from 'raven-for-redux';` instead of `import createRavenMiddleware from 'raven-for-redux';` in TypeScript files to correctly utilize the provided typings.","message":"When using TypeScript with `raven-for-redux`'s DefinitelyTyped bindings, the import style for `createRavenMiddleware` differs from typical ES module default imports.","severity":"gotcha","affected_versions":">=1.0.0 (with TypeScript)"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `Raven.config('<YOUR_DSN>').install();` is called and completes successfully before creating the middleware, and that the initialized `Raven` object is passed as the first argument to `createRavenMiddleware`.","cause":"The `Raven` object was not correctly initialized or passed as the first argument to `createRavenMiddleware`.","error":"TypeError: Cannot read properties of undefined (reading 'config') at createRavenMiddleware"},{"fix":"Downgrade your `raven-js` dependency to a version other than 3.14.0, or preferably, migrate your Sentry integration to the actively maintained `@sentry/browser` package.","cause":"This symptom commonly occurs if `raven-js` version 3.14.0 is being used, which has a known bug impacting `raven-for-redux`.","error":"Sentry: Breadcrumbs or errors are not being reported, or are malformed in Sentry dashboard."},{"fix":"Reorder your middlewares so that `createRavenMiddleware` is placed after any other middlewares that modify actions or state (e.g., `redux-thunk`, `redux-promise`, `redux-saga`).","cause":"The `raven-for-redux` middleware is likely placed too early in the Redux `applyMiddleware` chain, causing it to capture state or actions before other middlewares have processed them.","error":"Actions appear in Sentry breadcrumbs without expected modifications from other middlewares, or the attached state context is incorrect/stale."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}