11/* eslint-disable @typescript-eslint/no-explicit-any */
2- import { configureScope , getCurrentHub } from '@sentry/browser' ;
2+ import { addGlobalEventProcessor , configureScope , getCurrentHub } from '@sentry/browser' ;
33import type { Scope } from '@sentry/types' ;
44import { 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
5151export 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';
7177const ACTION_BREADCRUMB_TYPE = 'info' ;
7278
7379const 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
0 commit comments