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

[v9]: Not possible to remove information in beforeSend (make SentryEvent and related classes mutable) #2672

Open
ColinSchmale opened this issue Feb 7, 2025 · 5 comments

Comments

@ColinSchmale
Copy link

Platform

Flutter Web

Obfuscation

Enabled

Debug Info

Enabled

Doctor

Version

8.12.0

Steps to Reproduce

Use options.beforeSend to override a value like this:

await Sentry.init((options) {
  options.beforeSend = (event, hint) {
    return event.copyWith(serverName: null); // Don't send server names.
  };
});

Expected Result

The value is not sent (or null).

Actual Result

The value is sent and not null.

This is what the documentation says about how to remove information:

await Sentry.init((options) {
  options.beforeSend = (event, hint) {
    return event.copyWith(serverName: null); // Don't send server names.
  };
});

but when you take a look at the code, this cannot work:

  final String? serverName;

  @override
  SentryEvent copyWith({
    String? serverName,
  }) =>
      SentryEvent(
        serverName: serverName ?? this.serverName,

Replacing the geo object with an empty geo object does also not work. It seems that the data is overwritten afterwards.

await Sentry.init((options) {
  options.beforeSend = (event, hint) {
    return event.copyWith(
        user: event.user?.copyWith(
        geo: SentryGeo(),
      ),
    );
  };
});

What I ended up doing was masking the city value like this:

await Sentry.init((options) {
  options.beforeSend = (event, hint) {
    return event.copyWith(
        user: event.user?.copyWith(
        geo: SentryGeo(city: '****'),
      ),
    );
  };
});

Related to #980

Are you willing to submit a PR?

None

@buenaflor
Copy link
Contributor

hi, thanks for raising this. we'll look into this and see how we can provide an option to make this possible

@buenaflor
Copy link
Contributor

@ColinSchmale I believe setting it to an empty string "" also does the trick

@ColinSchmale
Copy link
Author

**** is also fine for me.

I mostly created this issue because the code in the documentation is wrong and maybe to also get some information why this happens and if my solution is okay.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 10, 2025
@buenaflor
Copy link
Contributor

buenaflor commented Feb 10, 2025

yeah we gotta update the docs definitely

it's been like this way before my time but afaict it is intended that way. so your method is right, setting null won't do anything you have to set it to some value e.g empty string or how you did it

I don't think it's ideal from a dx perspective but let's see what we can do there

@buenaflor buenaflor moved this from Needs Discussion to Backlog in Mobile & Cross Platform SDK Feb 11, 2025
@buenaflor buenaflor moved this from Backlog to Todo in Mobile & Cross Platform SDK Feb 11, 2025
@buenaflor buenaflor added this to the 9.0.0 milestone Feb 11, 2025
@buenaflor
Copy link
Contributor

buenaflor commented Feb 11, 2025

Since there is no practical use for having these immutable we've decided to refactor these into mutable data classes for the next major v9

@buenaflor buenaflor changed the title Not possible to remove information in beforeSend [v9]: Not possible to remove information in beforeSend Feb 12, 2025
@buenaflor buenaflor changed the title [v9]: Not possible to remove information in beforeSend [v9]: Not possible to remove information in beforeSend (make SentryEvent and related classes mutable) Feb 13, 2025
@buenaflor buenaflor self-assigned this Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Todo
Development

No branches or pull requests

2 participants