Skip to content

Commit 022186b

Browse files
committed
feat(vue): Apply stateTransformer to attachments in createSentryPiniaPlugin
1 parent b271bc8 commit 022186b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/vue/src/pinia.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
2626
},
2727
) => {
2828
const plugin: PiniaPlugin = ({ store }) => {
29+
let transformedState = store.$state;
30+
try {
31+
transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state;
32+
} catch (_) {
33+
// If stateTransformer throws, let's just use the unmodified state
34+
}
2935
options.attachPiniaState !== false &&
3036
getGlobalScope().addEventProcessor((event, hint) => {
3137
try {
@@ -37,7 +43,7 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
3743
...(hint.attachments || []),
3844
{
3945
filename,
40-
data: JSON.stringify(store.$state),
46+
data: JSON.stringify(transformedState),
4147
},
4248
];
4349
} catch (_) {
@@ -66,7 +72,6 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
6672
}
6773

6874
/* Set latest state to scope */
69-
const transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state;
7075
const scope = getCurrentScope();
7176
const currentState = scope.getScopeData().contexts.state;
7277

0 commit comments

Comments
 (0)