sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Enabled option in Sentry init does not avoid sending native events to Sentry in Dev mode

Open roni-castro opened this issue 1 year ago • 1 comments

What React Native libraries do you use?

Expo (mobile only)

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

6.1.0

How does your development environment look like?

expo-env-info 1.2.0 environment info: System: OS: macOS 14.6.1 Shell: 5.9 - /bin/zsh Binaries: Node: 22.3.0 - ~/.nvm/versions/node/v22.3.0/bin/node Yarn: 1.22.22 - ~/.nvm/versions/node/v22.3.0/bin/yarn npm: 10.8.1 - ~/.nvm/versions/node/v22.3.0/bin/npm Watchman: 2024.10.07.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.15.2 - /Users/ronicastro/.rvm/rubies/ruby-3.1.0/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5 IDEs: Android Studio: 2024.1 AI-241.15989.150.2411.11948838 Xcode: 15.4/15F31d - /usr/bin/xcodebuild npmPackages: expo: ~51.0.38 => 51.0.38 expo-router: ~3.5.23 => 3.5.23 react: 18.2.0 => 18.2.0 react-dom: 18.2.0 => 18.2.0 react-native: 0.74.5 => 0.74.5 react-native-web: ~0.19.10 => 0.19.12 npmGlobalPackages: eas-cli: 12.6.2 Expo Workflow: bare

Sentry.init()

import * as Sentry from "@sentry/react-native";

const IS_NATIVE_BUILD =
  Constants.executionEnvironment === ExecutionEnvironment.StoreClient; // Only in native builds, not in Expo Go.

const navigationIntegration = Sentry.reactNavigationIntegration({
  enableTimeToInitialDisplay: IS_NATIVE_BUILD,
});

Sentry.init({
  enabled: !__DEV__,
  dsn: "https://1b27b8c56af5b5a47387fe0ecc726353@o4508241637146624.ingest.us.sentry.io/4508241637343232",
  tracesSampleRate: 1.0,
  // uncomment the line below to enable Spotlight (https://spotlightjs.com)
  // enableSpotlight: __DEV__,
  _experiments: {
    replaysSessionSampleRate: 1.0,
    replaysOnErrorSampleRate: 1.0,
  },
  integrations: [
    navigationIntegration,
    Sentry.httpClientIntegration(),
    Sentry.mobileReplayIntegration(),
  ],
  enableNativeFramesTracking: IS_NATIVE_BUILD,
});

Steps to Reproduce

  1. Set the enabled of Sentry.init to the value false or to !__DEV__ and also define the dsn to be a valid one, and run the app in dev mode.
  2. Comment any line in the integrations section of Sentry.init, and then uncomment it again with RN fast refresh activated.
  3. A native crash happens and the log is sent to Sentry in dev mode even with enabled: false

The app code can be downloaded here, and make sure to run the branch sentry-bug change

https://github.com/user-attachments/assets/e62f3179-d651-42b6-8e42-a6af6ec72721

Expected Result

The flag enabled: false to not send any error events to Sentry, including JS or native logs. Or update the docs mentioning this just works for JS events, not for native one.

At the moment, it appears that this is the only available solution for this problem of disabling sentry events in dev mode, though it's not very thoroughly documented.

Sentry.init({
  dsn: __DEV__
    ? ""
    : "https://1b27b8c56af5b5a47387fe0ecc726353@o4508241637146624.ingest.us.sentry.io/4508241637343232",
})

Actual Result

The native log is unexpectedly sent to Sentry, although any JS error is not. Sentry log

roni-castro avatar Nov 07 '24 16:11 roni-castro

Thank you for the report and the details @roni-castro,

I'm confirming this is a bug and the native events should also not be send when enabled: false.

krystofwoldrich avatar Nov 21 '24 12:11 krystofwoldrich