dd-sdk-reactnative icon indicating copy to clipboard operation
dd-sdk-reactnative copied to clipboard

Unhandled Promise rejections are ignored and not sent to RUM/Error Tracking - NEED HELP!

Open ram95krishh opened this issue 10 months ago • 1 comments

Describe the bug

The problem I am trying to solve is a related to this issue

Problem: Unable to view unhandled rejections in my crash / error reporting tool : datadog. They just disappear.

Solution explored: I am looking into patching react native's promise polyfill to surface the unhandled rejection but as a paid customer I am baffled how datadog doesn't inherently support this.

Please suggest an optimal way to capture the unhandled promise rejection error and view it in RUM error tracking. Is this something datadog sdks would support inherently in the future?

Thanks in advance, Rama.

Reproduction steps

Fire such a function from any functional component in the app.

const unhandledRejectionFn = async() => {
    throw new Error('Unhandled Rejection');
  }

  useEffect(() => { 
    // most of our sdk instantiations happen in a non blocking fashion this way
    // need a way to be able to catch such rejections 
    void unhandledRejectionFn()
  }, [])

These unhandled rejections are not caught by datadog automatically.

SDK logs

No response

Expected behavior

No response

Affected SDK versions

2.4.3

Latest working SDK version

NA

Did you confirm if the latest SDK version fixes the bug?

Yes

Integration Methods

Yarn

React Native Version

0.75.5

Package.json Contents

{ "react-native": "0.75.5", "@datadog/mobile-react-native": "2.4.3",

iOS Setup

No response

Android Setup

No response

Device Information

No response

Other relevant information

No response

ram95krishh avatar Feb 19 '25 14:02 ram95krishh

Same issue here.

In a well made React app promise rejections are much more common than errors happening during render phase, but currently they are getting ignored by Datadog unless you surround them with try/catch like this:

try {
  await doSomething()
} catch (error) {
  DdRum.addError(error)
}

But this is easy to forget to do and introduces a ton of boilerplate when you have 1000s of async calls in the codebase.

On web we have unhandledrejection event that libraries like Sentry hook into. Datadog SDK should similarly add a promise rejection tracker via HermesInternal in React Native.

SimpleCreations avatar Feb 19 '25 14:02 SimpleCreations