{"library":"redux-sentry-middleware","title":"Redux Sentry Middleware","description":"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`.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install redux-sentry-middleware"],"cli":null},"imports":["import createSentryMiddleware from 'redux-sentry-middleware';","import * as Sentry from '@sentry/browser';\n// or\nimport * as Sentry from '@sentry/node';","import { applyMiddleware } from 'redux';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as Sentry from '@sentry/browser';\nimport { createStore, applyMiddleware, combineReducers } from 'redux';\nimport createSentryMiddleware from 'redux-sentry-middleware';\n\n// Initialize Sentry SDK\nSentry.init({\n  dsn: process.env.SENTRY_DSN ?? 'https://examplePublicKey@o0.ingest.sentry.io/0',\n  tracesSampleRate: 1.0,\n  // It's recommended to increase normalizeDepth for Redux states in Sentry\n  normalizeDepth: 10 // Or however deep your state context needs to be\n});\n\n// Example Reducer\nconst initialState = { count: 0, user: { name: 'Guest', id: null } };\nfunction counterReducer(state = initialState, action) {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { ...state, count: state.count + 1 };\n    case 'DECREMENT':\n      // Simulate an error for testing\n      if (action.payload === 'error') {\n        throw new Error('Intentional Redux error on DECREMENT');\n      }\n      return { ...state, count: state.count - 1 };\n    case 'SET_USER':\n      return { ...state, user: action.payload };\n    default:\n      return state;\n  }\n}\n\nconst rootReducer = combineReducers({ counter: counterReducer });\n\n// Create Sentry Middleware instance\nconst sentryMiddleware = createSentryMiddleware(Sentry, {\n  breadcrumbDataFromAction: action => {\n    // Log specific action data, ensuring it's flat and not too large\n    if (action.type === 'SET_USER') {\n      return { userId: action.payload.id, userName: action.payload.name };\n    }\n    return undefined;\n  },\n  actionTransformer: action => {\n    // Remove sensitive data from actions before sending to Sentry\n    if (action.type === 'SET_USER' && action.payload && action.payload.password) {\n      const { password, ...safePayload } = action.payload;\n      return { ...action, payload: safePayload };\n    }\n    return action;\n  },\n  stateTransformer: state => {\n    // Remove sensitive data from state before sending to Sentry\n    if (state.counter && state.counter.user && state.counter.user.sensitiveInfo) {\n      const { sensitiveInfo, ...safeUser } = state.counter.user;\n      return { ...state, counter: { ...state.counter, user: safeUser } };\n    }\n    return state;\n  }\n});\n\nexport const store = createStore(\n  rootReducer,\n  applyMiddleware(sentryMiddleware)\n);\n\n// Example usage\nstore.dispatch({ type: 'INCREMENT' });\nstore.dispatch({ type: 'SET_USER', payload: { id: 123, name: 'Alice', password: 'secret' } });\n\ntry {\n  store.dispatch({ type: 'DECREMENT', payload: 'error' });\n} catch (e) {\n  console.error('Caught expected error from Redux dispatch:', e.message);\n}\n\nconsole.log('Final state:', store.getState());","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}