@@ -12,8 +12,8 @@ type PiniaPlugin = (context: {
12
12
13
13
type SentryPiniaPluginOptions = {
14
14
attachPiniaState ?: boolean ;
15
- actionTransformer : ( action : any ) => any ;
16
- stateTransformer : ( state : any ) => any ;
15
+ actionTransformer ? : ( action : any ) => any ;
16
+ stateTransformer ? : ( state : any ) => any ;
17
17
} ;
18
18
19
19
export const createSentryPiniaPlugin : ( options ?: SentryPiniaPluginOptions ) => PiniaPlugin = (
@@ -24,7 +24,7 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
24
24
} ,
25
25
) => {
26
26
const plugin : PiniaPlugin = ( { store } ) => {
27
- options . attachPiniaState &&
27
+ options . attachPiniaState !== false &&
28
28
getGlobalScope ( ) . addEventProcessor ( ( event , hint ) => {
29
29
try {
30
30
// Get current timestamp in hh:mm:ss
@@ -47,18 +47,20 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
47
47
48
48
store . $onAction ( context => {
49
49
context . after ( ( ) => {
50
- const transformedAction = options . actionTransformer ( context . name ) ;
50
+ const transformedActionName = options . actionTransformer
51
+ ? options . actionTransformer ( context . name ) || ''
52
+ : context . name ;
51
53
52
- if ( typeof transformedAction !== 'undefined' && transformedAction !== null ) {
54
+ if ( typeof transformedActionName !== 'undefined' && transformedActionName !== null ) {
53
55
addBreadcrumb ( {
54
56
category : 'action' ,
55
- message : transformedAction ,
57
+ message : transformedActionName ,
56
58
level : 'info' ,
57
59
} ) ;
58
60
}
59
61
60
62
/* Set latest state to scope */
61
- const transformedState = options . stateTransformer ( store . $state ) ;
63
+ const transformedState = options . stateTransformer ? options . stateTransformer ( store . $state ) : store . $state ;
62
64
const scope = getCurrentScope ( ) ;
63
65
64
66
if ( typeof transformedState !== 'undefined' && transformedState !== null ) {
0 commit comments