Skip to content

Commit 2172be8

Browse files
committed
feat(redux): Add 'attachReduxState' option
Introduces 'attachReduxState' (default: true) for controlling Redux state attachment to Sentry events. Fixes GH-6266
1 parent 32befda commit 2172be8

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/react/src/redux.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { configureScope, getCurrentHub } from '@sentry/browser';
2+
import { addGlobalEventProcessor, configureScope, getCurrentHub } from '@sentry/browser';
33
import type { Scope } from '@sentry/types';
44
import { addNonEnumerableProperty } from '@sentry/utils';
55

@@ -49,6 +49,12 @@ type StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never>
4949
) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;
5050

5151
export interface SentryEnhancerOptions<S = any> {
52+
/**
53+
* Redux state in attachments or not.
54+
* @default true
55+
*/
56+
attachReduxState?: boolean;
57+
5258
/**
5359
* Transforms the state before attaching it to an event.
5460
* Use this to remove any private data before sending it to Sentry.
@@ -71,6 +77,7 @@ const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
7177
const ACTION_BREADCRUMB_TYPE = 'info';
7278

7379
const defaultOptions: SentryEnhancerOptions = {
80+
attachReduxState: true,
7481
actionTransformer: action => action,
7582
stateTransformer: state => state || null,
7683
};
@@ -89,6 +96,15 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
8996

9097
return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>
9198
<S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {
99+
options.attachReduxState &&
100+
addGlobalEventProcessor((event, hint) => {
101+
hint.attachments = [
102+
...(hint.attachments || []),
103+
{ filename: 'reduxState.json', data: JSON.stringify(event.contexts && event.contexts.state) || ' ' },
104+
];
105+
return event;
106+
});
107+
92108
const sentryReducer: Reducer<S, A> = (state, action): S => {
93109
const newState = reducer(state, action);
94110

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,10 +4414,10 @@
44144414
fflate "^0.4.4"
44154415
mitt "^1.1.3"
44164416

4417-
"@sentry/[email protected].0":
4418-
version "0.6.0"
4419-
resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-0.6.0.tgz#70ad3740b2f90cdca1aff5fdbcd7306566a2f51e"
4420-
integrity sha512-gDPBkFxiOkc525U9pxnGMI5B2DAG0+UCsNuiNgl9+AieDcPSYTwdzfGHytxDZrQgPMvIHEnTAp1VlNB+6UxUGQ==
4417+
"@sentry/[email protected].1":
4418+
version "0.6.1"
4419+
resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-0.6.1.tgz#6c6a2ff3cdc98cd0ff1c30c59408cee9f067adf2"
4420+
integrity sha512-EecCJKp9ERM7J93DNDJTvkY78UiD/IfOjBdXWnaUVE0n619O7LfMVjwlXzxRJKl2x05dBE3lDraILLDGxCf6fg==
44214421
dependencies:
44224422
"@sentry/cli" "^2.17.0"
44234423
"@sentry/node" "^7.19.0"
@@ -4464,12 +4464,12 @@
44644464
proxy-from-env "^1.1.0"
44654465
which "^2.0.2"
44664466

4467-
"@sentry/vite-plugin@^0.6.0":
4468-
version "0.6.0"
4469-
resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-0.6.0.tgz#3902a5224d52b06d753a1deeb6b722bf6523840c"
4470-
integrity sha512-3J1ESvbI5okGJaSWm+gTAOOIa96u4ZwfI/C3n+0HSStz3e4vGiGUh59iNyb1/2m5HFgR5OLaHNfAvlyP8GM/ew==
4467+
"@sentry/vite-plugin@^0.6.1":
4468+
version "0.6.1"
4469+
resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-0.6.1.tgz#31eb744e8d87b1528eed8d41433647727a62e7c0"
4470+
integrity sha512-qkvKaSOcNhNWcdxRXLSs+8cF3ey0XIRmEzTl8U7sTTcZwuOMHsJB+HsYij6aTGaqsKfP8w1ozVt9szBAiL4//w==
44714471
dependencies:
4472-
"@sentry/bundler-plugin-core" "0.6.0"
4472+
"@sentry/bundler-plugin-core" "0.6.1"
44734473

44744474
44754475
version "1.19.0"

0 commit comments

Comments
 (0)