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

Some beforeSend event changes are ignored on Android #2896

Closed
5 of 11 tasks
avr6ude opened this issue Mar 15, 2023 · 2 comments
Closed
5 of 11 tasks

Some beforeSend event changes are ignored on Android #2896

avr6ude opened this issue Mar 15, 2023 · 2 comments

Comments

@avr6ude
Copy link

avr6ude commented Mar 15, 2023

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @sentry/react-native (>= 1.0.0)
  • react-native-sentry (<= 0.43.2)

SDK version: 5.1.1

react-native version: 0.70.5

Are you using Expo?

  • Yes
  • No

Are you using sentry.io or on-premise?

  • sentry.io (SaaS)
  • on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

[Link to issue]

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: env.SENTRY_DSN,
  tracesSampleRate: 1.0,
  environment: __DEV__ ? 'development' : 'production',
  beforeSend(event) {
    delete event.user
    delete event.contexts?.device
    delete event.environment
    delete event.contexts?.os?.version
    delete event.contexts?.os?.kernel_version

    return event
  },
  ignoreErrors: ['HTTPClientError', 'ReferenceError', 'TypeError'],
});

I have following issue:

App running on Android ignores delete flags. That causes Sentry to log things I don't want (like device info) on Android. Works flawlessly on iOS.

Steps to reproduce:

  • Delete information you don't want to be sent
  • Invoke an event that Sentry captures
  • Look at the logs for Android and iOS

Actual result:

delete is ignored on Android

Expected result:

delete should not be ignored

@kahest kahest moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK Mar 15, 2023
@krystofwoldrich krystofwoldrich moved this from Needs Investigation to Needs Discussion in Mobile & Cross Platform SDK Mar 15, 2023
@krystofwoldrich
Copy link
Member

krystofwoldrich commented Mar 15, 2023

Hi, thank you for the details.

This is caused by the way we currently enrich the contexts on Android. We send the event from JS to Android after the JS beforeSend and there we add the information.

Some of the values can be removed by providing some placeholder value like <retracted>.

This won't work for contexts.os as Android will add the value always.

  beforeSend: (event: Sentry.Event) => {
    event.user = {
      id: '<retracted>',
    }
    event.environment = '<retracted>'
    event.contexts = event.contexts || {}
    event.contexts.device = {
      type: '<retracted>',
    }
    // This won't work as Android will add a new os object to the contexts
    // event.contexts.os = event.contexts.os || {}
    // event.contexts.os.version = '<retracted>'
    // event.contexts.os.kernel_version = '<retracted>'
    return event;
  },

@krystofwoldrich krystofwoldrich changed the title delete is ignored on Android Some beforeSend event changes are ignored on Android Mar 15, 2023
@krystofwoldrich
Copy link
Member

Closing this as we track it in getsentry/team-mobile#11

@github-project-automation github-project-automation bot moved this from Needs Discussion to Done in Mobile & Cross Platform SDK Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants