Skip to content

Apply stateTransformer to Attachments in createSentryPiniaPlugin #14441

@sircharlo

Description

@sircharlo

Problem Statement

Feature Request: Apply stateTransformer to Attachments in createSentryPiniaPlugin

First, thank you for createSentryPiniaPlugin—it's been a lifesaver!

Would it be possible to apply the stateTransformer not just to the context but also to the attachments? This would greatly reduce the size of the attachments when they contain items that don’t need to be in Sentry. Currently, we're hitting our monthly attachment cap just a few days after starting to use createSentryPiniaPlugin.

Solution Brainstorm

Potential Implementation:

try {
+ const transformedState = options.stateTransformer 
+   ? options.stateTransformer(store.$state) 
+   : store.$state;
  // Get current timestamp in hh:mm:ss
  const timestamp = new Date().toTimeString().split(' ')[0];
  const filename = `pinia_state_${store.$id}_${timestamp}.json`;

  hint.attachments = [
    ...(hint.attachments || []),
    {
      filename,
-     data: JSON.stringify(store.$state),
+     data: JSON.stringify(transformedState),
    },
  ];
} catch (_) {
  // empty
}

This adjustment would make the plugin more efficient by ensuring attachment size is minimized by excluding unnecessary data from the state with stateTransformer.

Let me know if you’d like me to submit a PR for this change.

Thanks again!

Metadata

Metadata

Assignees

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions