1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { configureScope , getCurrentHub } from '@sentry/browser' ;
2
+ import { addGlobalEventProcessor , configureScope , getCurrentHub } from '@sentry/browser' ;
3
3
import type { Scope } from '@sentry/types' ;
4
4
import { addNonEnumerableProperty } from '@sentry/utils' ;
5
5
@@ -49,6 +49,12 @@ type StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never>
49
49
) => Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext ;
50
50
51
51
export interface SentryEnhancerOptions < S = any > {
52
+ /**
53
+ * Redux state in attachments or not.
54
+ * @default true
55
+ */
56
+ attachReduxState ?: boolean ;
57
+
52
58
/**
53
59
* Transforms the state before attaching it to an event.
54
60
* Use this to remove any private data before sending it to Sentry.
@@ -71,6 +77,7 @@ const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
71
77
const ACTION_BREADCRUMB_TYPE = 'info' ;
72
78
73
79
const defaultOptions : SentryEnhancerOptions = {
80
+ attachReduxState : true ,
74
81
actionTransformer : action => action ,
75
82
stateTransformer : state => state || null ,
76
83
} ;
@@ -89,6 +96,15 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
89
96
90
97
return ( next : StoreEnhancerStoreCreator ) : StoreEnhancerStoreCreator =>
91
98
< 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
+
92
108
const sentryReducer : Reducer < S , A > = ( state , action ) : S => {
93
109
const newState = reducer ( state , action ) ;
94
110
0 commit comments