导出/记录到错误跟踪服务

Export / Log to error tracking service

有没有一种方法可以在生产环境中以编程方式导出商店状态/操作,然后可以将其导入回到开发工具中?

例如,我可以设置中间件来捕获当前状态并将其发送到(Trackjs、Sentry、Rollbar)之类的东西,但它缺少所有以前的状态和动作。

我想以与从 Redux Dev Tools 导出相同的格式捕获。

从开发工具导出示例

 {"monitorState":{},"actionsById":{"0":{"type":"PERFORM_ACTION","action":{"type":"@@INIT"},"timestamp":1471017239656},"1":{"type":"PERFORM_ACTION","action":{"type":"INCREMENT"},"timestamp":1471017242004}},"nextActionId":2,"stagedActionIds":[0,1],"skippedActionIds":[],"committedState":5,"currentStateIndex":1,"computedStates":[{"state":5},{"state":6}]}

目前正在开发中,但您现在可以在扩展程序中推送操作历史记录请参阅https://github.com/zalmoxisus/remotedev-server/pull/20

另一种选择是 将操作作为数组保存到 JSON 文件中,然后将它们导回。

https://github.com/zalmoxisus/redux-devtools-extension/issues/173

开始有可能

logger.js

let actions = []
export function logActions (stateSanitizer) {
  return store => next => action => {
    actions.push(action)
    return next(action)
  }
}

这些操作可以保存到文件或数据库中,并可以导入回开发工具中。

示例操作

[{
    "type": "INCREMENT"
  }, {
    "type": "DECREMENT"
  }, {
    "type": "DECREMENT"
  }, {
    "type": "DECREMENT"
  }, {
    "type": "DECREMENT"
  }]

我创建了这个 repo,它在操作中演示了这个 https://github.com/timarney/redux-trackjs-logger 它使用中间件来记录发生错误时的操作。

我维护一个名为 Raven for Redux 的 Redux 中间件,它将 Redux 数据附加到 Sentry 错误报告。目前它向每个错误报告添加以下上下文:

  1. 完整的状态对象。
  2. 完整的最后一个动作对象。
  3. 导致当前状态的所有操作的 type。这些添加为 "breadcrumbs".

Sentry 博客有一篇文章对其进行了更详细的描述:https://blog.sentry.io/2016/08/24/redux-middleware-error-logging.html

您可以在此处找到作为 NPM 包的中间件:https://github.com/captbaritone/raven-for-redux