Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply stateTransformer to Attachments in createSentryPiniaPlugin #14441

Open
sircharlo opened this issue Nov 24, 2024 · 3 comments
Open

Apply stateTransformer to Attachments in createSentryPiniaPlugin #14441

sircharlo opened this issue Nov 24, 2024 · 3 comments

Comments

@sircharlo
Copy link

sircharlo commented Nov 24, 2024

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!

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 24, 2024
@mydea
Copy link
Member

mydea commented Nov 25, 2024

Hey, thanks for writing in. I believe this makes sense, I wonder if there are reasons not to do this. I will let @s1gr1d chime in there as she wrote this initially.

@s1gr1d
Copy link
Member

s1gr1d commented Nov 25, 2024

This sounds reasonable :)
And feel free to open a PR with tests for this. Thanks for suggesting this!

@sircharlo
Copy link
Author

PR opened: #14474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

4 participants