Skip to content

Use attachments to store the Redux state #6266

Closed
@renchap

Description

@renchap

Problem Statement

When using the current Redux middleware, the latest state is set in the scope's context:

/* Set latest state to scope */
const transformedState = options.stateTransformer(newState);
if (typeof transformedState !== 'undefined' && transformedState !== null) {
scope.setContext('state', { state: { type: 'redux', value: transformedState } });
} else {
scope.setContext('state', null);
}

This is a problem for big Redux states as the size of attributes in context is limited. But attachments are now added to the JS SDK, and are the perfect solution to this!

Solution Brainstorm

Instead of storing the state in the context, it should be an attachment as those can be much bigger. I have been using this in my app for some time and it work great:

Sentry.addGlobalEventProcessor((event, hint) => {
  hint.attachments = [
    {
      filename: "redux-state.json",
      data: JSON.stringify(store.getState(), undefined, 2),
    },
  ]

  return event
})

If you think this is a good idea, I can submit a PR for this. This could also be a middleware setting if you prefer, as well as the attachment name.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions