{"id":13475489,"url":"https://github.com/captbaritone/raven-for-redux","last_synced_at":"2025-04-04T10:02:47.026Z","repository":{"id":57332722,"uuid":"80491509","full_name":"captbaritone/raven-for-redux","owner":"captbaritone","description":"A Raven middleware for Redux","archived":false,"fork":false,"pushed_at":"2020-05-13T04:05:47.000Z","size":167,"stargazers_count":294,"open_issues_count":11,"forks_count":25,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-10T23:32:13.258Z","etag":null,"topics":["error-monitoring","raven","redux","redux-middleware","sentry"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/captbaritone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-31T04:37:53.000Z","updated_at":"2024-12-05T10:31:24.000Z","dependencies_parsed_at":"2022-09-26T16:31:25.627Z","dependency_job_id":null,"html_url":"https://github.com/captbaritone/raven-for-redux","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captbaritone%2Fraven-for-redux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captbaritone%2Fraven-for-redux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captbaritone%2Fraven-for-redux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captbaritone%2Fraven-for-redux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/captbaritone","download_url":"https://codeload.github.com/captbaritone/raven-for-redux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149937,"owners_count":20892044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-monitoring","raven","redux","redux-middleware","sentry"],"created_at":"2024-07-31T16:01:20.872Z","updated_at":"2025-04-04T10:02:47.000Z","avatar_url":"https://github.com/captbaritone.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":" [![Travis](https://img.shields.io/travis/captbaritone/raven-for-redux.svg)]() [![Codecov](https://img.shields.io/codecov/c/github/captbaritone/raven-for-redux.svg)]()\n.\n\n# Deprecated\n\nSentry now recommends using their new SDK `@sentry/browser` rather than Raven. Check out [redux-sentry-middleware](https://github.com/vidit-sh/redux-sentry-middleware) for an API compatible fork of this library that supports the new SDK!\n\n\n# Raven Middleware for Redux\n\n_Note:_ Requires Raven \u003e= 3.9.0. Raven 3.14.0 has [a bug](https://github.com/getsentry/raven-js/issues/925)\n which this library triggers\n\n\nLogs the type of each dispatched action to Raven as \"breadcrumbs\" and attaches\nyour last action and current Redux state as additional context.\n\nInspired by [redux-raven-middleware] but with a slightly [different approach](#improvements).\n\n## Installation\n\n    npm install --save raven-for-redux\n\n## Usage\n\n### Browser\n\n```JavaScript\n// store.js\n\nimport Raven from \"raven-js\"; // Or, you might already have this as `window.Raven`.\nimport { createStore, applyMiddleware } from \"redux\";\nimport createRavenMiddleware from \"raven-for-redux\";\n\nimport { reducer } from \"./my_reducer\";\n\nRaven.config(\"\u003cYOUR_DSN\u003e\").install();\n\nexport default createStore(\n    reducer,\n    applyMiddleware(\n        // Middlewares, like `redux-thunk` that intercept or emit actions should\n        // precede `raven-for-redux`.\n        createRavenMiddleware(Raven, {\n            // Optionally pass some options here.\n        })\n    )\n);\n```\n\nFor a working example, see the [example](./example/) directory.\n\n### TypeScript\n`raven-for-redux` has TypeScript bindings available through [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b7ca35ab023ba1758de9e07004adde71e911c28e/types/raven-for-redux/index.d.ts). Please note the import style below, as it differs from the JavaScript example and is required for these typings.\n```TypeScript\nimport * as Raven from \"raven-js\";\nimport * as createRavenMiddleware from \"raven-for-redux\";\nimport { applyMiddleware, createStore } from \"redux\";\n\n//... (same as JavaScript example, but now with proper typings)\n```\n\n## Improvements\n\nThis library makes, what I think are, a few improvements over\n`redux-raven-middlware`:\n\n1. Raven is injected rather than being setup inside the middleware. This allows\n   for more advanced configuration of Raven, as well as cases where Raven has\n   already been initialized. For example, if you include Raven as its own\n   `\u003cscript\u003e` tag.\n2. Adds your state and last action as context to _all_ errors, not just reducer\n   exceptions.\n3. Allows filtering action breadcrumbs before sending to Sentry\n4. Allows you to define a user context mapping from the state\n\n## API: `createRavenMiddleware(Raven, [options])`\n\n### Arguments\n\n* `Raven` _(Raven Object)_: A configured and \"installed\"\n  [Raven] object.\n* [`options`] _(Object)_: See below for detailed documentation.\n\n### Options\n\nWhile the default configuration should work for most use cases, Raven for Redux\ncan be configured by providing an options object with any of the following\noptional keys.\n\n#### `breadcrumbMessageFromAction` _(Function)_\n\nDefault: `action =\u003e action.type`\n\n`breadcrumbMessageFromAction` allows you to specify a transform function which is passed the `action` object and returns a `string` that will be used as the message of the breadcrumb.\n\nBy default `breadcrumbMessageFromAction` returns `action.type`.\n\nFinally, be careful not to mutate your `action` within this function.\n\nSee the Sentry [Breadcrumb documentation].\n\n#### `breadcrumbDataFromAction` _(Function)_\n\nDefault: `action =\u003e undefined`\n\nRaven allows you to attach additional context information to each breadcrumb\nin the form of a `data` object. `breadcrumbDataFromAction` allows you to specify\na transform function which is passed the `action` object and returns a `data`\nobject. Which will be logged to Sentry along with the breadcrumb.\n\n_Ideally_ we could log the entire content of each action. If we could, we\ncould perfectly replay the user's entire session to see what went wrong.\n\nHowever, the default implementation of this function returns `undefined`, which means\nno data is attached. This is because there are __a few gotchas__:\n\n* The data object must be \"flat\". In other words, each value of the object must be a string. The values may not be arrays or other objects.\n* Sentry limits the total size of your error report. If you send too much data,\n  the error will not be recorded. If you are going to attach data to your\n  breadcrumbs, be sure you understand the way it will affect the total size\n  of your report.\n\nFinally, be careful not to mutate your `action` within this function.\n\nSee the Sentry [Breadcrumb documentation].\n\n#### `actionTransformer` _(Function)_\n\nDefault: `action =\u003e action`\n\nIn some cases your actions may be extremely large, or contain sensitive data.\nIn those cases, you may want to transform your action before sending it to\nSentry. This function allows you to do so. It is passed the last dispatched\n`action` object, and should return a serializable value.\n\nBe careful not to mutate your `action` within this function.\n\nIf you have specified a [`dataCallback`] when you configured Raven, note that\n`actionTransformer` will be applied _before_ your specified `dataCallback`.\n\n#### `stateTransformer` _(Function)_\n\nDefault: `state =\u003e state`\n\nIn some cases your state may be extremely large, or contain sensitive data.\nIn those cases, you may want to transform your state before sending it to\nSentry. This function allows you to do so. It is passed the current state\nobject, and should return a serializable value.\n\nBe careful not to mutate your `state` within this function.\n\nIf you have specified a [`dataCallback`] when you configured Raven, note that\n`stateTransformer` will be applied _before_ your specified `dataCallback`.\n\n#### `breadcrumbCategory` _(String)_\n\nDefault: `\"redux-action\"`\n\nEach breadcrumb is assigned a category. By default all action breadcrumbs are\ngiven the category `\"redux-action\"`. If you would prefer a different category\nname, specify it here.\n\n#### `filterBreadcrumbActions` _(Function)_\n\nDefault: `action =\u003e true`\n\nIf your app has certain actions that you do not want to send to Sentry, pass\na filter function in this option. If the filter returns a truthy value, the\naction will be added as a breadcrumb, otherwise the action will be ignored.\nNote: even when the action has been filtered out, it may still be sent to\nSentry as part of the extra data, if it was the last action before an error.\n\nThis option was introduced in version 1.1.1.\n\n#### `getUserContext` _(Optional Function)_\n\nSignature: `state =\u003e userContext`\n\nRaven allows you to associcate a [user context] with each error report.\n`getUserContext` allows you to define a mapping from your Redux `state` to\nthe user context. When `getUserContext` is specified, the result of\n`getUserContext` will be used to derive the user context before sending an\nerror report. Be careful not to mutate your `state` within this function.\n\nIf you have specified a [`dataCallback`] when you configured Raven, note that\n`getUserContext` will be applied _before_ your specified `dataCallback`.\nWhen a `getUserContext` function is given, it will override any previously\nset user context.\n\nThis option was introduced in version 1.2.0.\n\n#### `getTags` _(Optional Function)_\n\nSignature: `state =\u003e tags`\n\nRaven allows you to associate [tags] with each report.\n`getTags` allows you to define a mapping from your Redux `state` to\nan object of tags (key → value). Be careful not to mutate your `state`\nwithin this function.\n\nThis option was introduced in version 1.3.1.\n\n## Changelog\n\n### 1.4.0\n\n* Add `breadcrumbMessageFromAction` method. ([#98])\n\n### 1.3.1\n\n* Add `getTags` option. ([#69])\n\n### 1.3.0\n\n* The Raven \"extras\" that we add are merged with existing extras rather than replacing them. ([#59])\n\n### 1.2.0\n\n* Add `getUserContext` option. ([#49])\n\n### 1.1.1\n\n* Add `filterBreadcrumbActions` option. ([#39])\n\n### 1.0.0\n\n* No changes. Just bringing the project out of beta.\n\n### 0.7.1\n\n* Refactor: Use implicit binding to track the state/last action. ([1def9a7])\n\n### 0.7.0\n\n* Return the next middleware's (or the actual `dispatch` function's) return value. ([#11])\n\n### 0.6.0\n\n* `actionTransformer` and `stateTransformer` are only run when reporting an error, rather than on every action. ([#8])\n\n\n[redux-raven-middleware]: https://github.com/ngokevin/redux-raven-middleware\n[Raven]: https://docs.sentry.io/clients/javascript/\n[Raven Breadcrumbs]: https://docs.sentry.io/clients/javascript/usage/#recording-breadcrumbs\n[Breadcrumb documentation]: https://docs.sentry.io/learn/breadcrumbs/\n[user context]: https://docs.sentry.io/learn/context/#capturing-the-user\n[`dataCallback`]: https://docs.sentry.io/clients/javascript/config/\n[tags]: https://docs.sentry.io/learn/context/#tagging-events\n[#11]: https://github.com/captbaritone/raven-for-redux/pull/11\n[#8]: https://github.com/captbaritone/raven-for-redux/pull/8\n[1def9a7]: https://github.com/captbaritone/raven-for-redux/commit/1def9a747d7b711ad93da531b8ff9d128c352b45\n[#39]: https://github.com/captbaritone/raven-for-redux/pull/39\n[#49]: https://github.com/captbaritone/raven-for-redux/pull/49\n[#59]: https://github.com/captbaritone/raven-for-redux/pull/59\n[#69]: https://github.com/captbaritone/raven-for-redux/pull/69\n[#98]: https://github.com/captbaritone/raven-for-redux/pull/98\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptbaritone%2Fraven-for-redux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptbaritone%2Fraven-for-redux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptbaritone%2Fraven-for-redux/lists"}