Skip to content

Commit c8482b9

Browse files
committed
Make actionTransformer and stateTransformer optional
1 parent cf1b89f commit c8482b9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/vue/src/pinia.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ type PiniaPlugin = (context: {
1212

1313
type SentryPiniaPluginOptions = {
1414
attachPiniaState?: boolean;
15-
actionTransformer: (action: any) => any;
16-
stateTransformer: (state: any) => any;
15+
actionTransformer?: (action: any) => any;
16+
stateTransformer?: (state: any) => any;
1717
};
1818

1919
export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => PiniaPlugin = (
@@ -24,7 +24,7 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
2424
},
2525
) => {
2626
const plugin: PiniaPlugin = ({ store }) => {
27-
options.attachPiniaState &&
27+
options.attachPiniaState !== false &&
2828
getGlobalScope().addEventProcessor((event, hint) => {
2929
try {
3030
// Get current timestamp in hh:mm:ss
@@ -47,18 +47,20 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
4747

4848
store.$onAction(context => {
4949
context.after(() => {
50-
const transformedAction = options.actionTransformer(context.name);
50+
const transformedActionName = options.actionTransformer
51+
? options.actionTransformer(context.name) || ''
52+
: context.name;
5153

52-
if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
54+
if (typeof transformedActionName !== 'undefined' && transformedActionName !== null) {
5355
addBreadcrumb({
5456
category: 'action',
55-
message: transformedAction,
57+
message: transformedActionName,
5658
level: 'info',
5759
});
5860
}
5961

6062
/* Set latest state to scope */
61-
const transformedState = options.stateTransformer(store.$state);
63+
const transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state;
6264
const scope = getCurrentScope();
6365

6466
if (typeof transformedState !== 'undefined' && transformedState !== null) {

0 commit comments

Comments
 (0)