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

[Android] ReferenceError not being captured by Sentry #4321

Open
shanmukhdontuTWM opened this issue Nov 27, 2024 · 5 comments
Open

[Android] ReferenceError not being captured by Sentry #4321

shanmukhdontuTWM opened this issue Nov 27, 2024 · 5 comments

Comments

@shanmukhdontuTWM
Copy link

shanmukhdontuTWM commented Nov 27, 2024

What React Native libraries do you use?

React Navigation, Hermes

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

5.33.1

How does your development environment look like?

System:
  OS: macOS 14.7.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 1.37 GB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.4
    path: ~/.nvm/versions/node/v18.20.4/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.4/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK: Not Found
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: /undefined
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.21
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.5
    wanted: 0.72.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: false
  newArchEnabled: Not found

Sentry.init()

Sentry.init({
      dsn: String(getConfig().SENTRY_DSN),
      environment: String(getConfig().SENTRY_ENVIRONMENT || 'Development'),
      enableUserInteractionTracing: false,
      enableAppStartTracking: false,
      attachScreenshot: false,
      integrations: [
        reactNativeTracingIntegration({
          routingInstrumentation: routingInstrumentation,
        }),
      ],
      debug: false,
      release: deviceInfoModule.getVersion(),
      dist:
        deviceInfoModule.getBundleId() + '-' + deviceInfoModule.getVersion(),
      enabled: true,
    });

Steps to Reproduce

The app is getting initialized with sentry without any issue, and also the sentry crash test is working.
In a component inside the App, it does not have a function imported and is called, which is throwing a ReferenceError locally but the same issue is not populated in sentry. When i converted the function to async, it did the trick.
The app is within the sentry error boundary and we were expecting the crash to show up, even for synchronous functions but thats not the case.
Can someone help look into this?

Expected Result

The event should be logged on sentry dashboard, sentry should capture one.

Actual Result

Sentry not able to capture ReferenceError crashes inside a React native component

@lucas-zimerman
Copy link
Collaborator

lucas-zimerman commented Nov 29, 2024

Hi and thank you for opening this issue!, Could you share the logs from Sentry when debug is set to true?
Also, could you try checking if the problem persists on version 5.34.0?

Lastly, could you share a snippet on how you are calling this function?
Thank you for your patience.

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Nov 29, 2024
@lucas-zimerman lucas-zimerman moved this from Needs Discussion to Needs More Information in Mobile & Cross Platform SDK Nov 29, 2024
@shanmukhdontuTWM
Copy link
Author

shanmukhdontuTWM commented Dec 3, 2024

@lucas-zimerman Thanks for the prompt response!

 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: 83c00f9b82d42747
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (83c00f9b82d42747).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"
 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: 804914b1fee555d7
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (804914b1fee555d7).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"
 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: ab332ad29bccadc3
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (ab332ad29bccadc3).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"
 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: b4cd4921fa3d7207
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (b4cd4921fa3d7207).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"
 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: a2eca104f165c087
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (a2eca104f165c087).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"
 LOG  Sentry Logger [log]: Setting idle transaction on scope. Span ID: af0c5d74b4f9f189
 DEBUG  Sentry Logger [debug]: [NativeFrames] Fetching frames for root span start (af0c5d74b4f9f189).
 LOG  Sentry Logger [log]: [ReactNativeTracing] Starting navigation transaction "Route Change" on scope
 LOG  Sentry Logger [log]: [ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.
 **ERROR  ReferenceError: Property 'callFunction1' doesn't exist**
 LOG  Sentry Logger [log]: [Tracing] No active IdleTransaction
 LOG  Sentry Logger [log]: [Tracing] Discarding transaction because its trace was not chosen to be sampled.
 LOG  Sentry Logger [log]: Recording outcome: "sample_rate:transaction"

Here is the example code snippet

 const functionA = (
    var1: number,
    var2: number,
    var3: string,
  ) => {
    callFunction1({
      param1: {},
      param2: () => callFunction2(),
    });
  };

  useEffect(() => {
    if (
      !varA &&
      ((varQ === '' && !bool) || (varQ === '1' && bool))
    ) {
      const num = 1
      if (num) {
        functionA(
          var1,
          var2,
          var3,
        );
      }
    }
  }, []);

In the above code snippet, callFunction1 is not imported. functionA is called inside the useEffect, which is resulting in ReferenceError locally.
When we convert the functionA to async function, the error event is logged by Sentry and works fine.

Checking v5.34.0, will post the results shortly.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 3, 2024
@shanmukhdontuTWM
Copy link
Author

Package update from v5.33.1 -> v5.34.0 did not log the Sentry event as well.

@krystofwoldrich
Copy link
Member

Thank you for the details and testing it with the latest v5.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Dec 4, 2024
@krystofwoldrich krystofwoldrich moved this from Needs More Information to Needs Investigation in Mobile & Cross Platform SDK Dec 4, 2024
@krystofwoldrich
Copy link
Member

@lucas-zimerman Have you reproduced this error?

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

No branches or pull requests

3 participants