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

After upgrade sentry, app has the issue "App Start Span could not be finished. `Sentry.wrap` was called before `Sentry.init`."

Open erichou668 opened this issue 2 years ago • 20 comments

OS:

  • [ ] Windows
  • [ *] MacOS
  • [ ] Linux

Platform:

  • [* ] iOS
  • [ ] Android

SDK:

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

SDK version: 5.22.3

react-native version: 0.72.4

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: 'https://[email protected]/...'
  // other options
});

I have the following issue:

[Description] After upgrade sentry, app has the issue "App Start Span could not be finished. Sentry.wrap was called before Sentry.init." I use CodePush.getUpdateMetadata()

Steps to reproduce:

  • Step 1
  • Step 2

Actual result:

[Actual result]

Expected result:

[Expected result]

erichou668 avatar Jun 03 '24 07:06 erichou668

Hi @erichou668, thank you for the message,

can you share from what version of the Sentry RN SDK have you upgraded?

Could you share a code snippet explaining when and where do you call Sentry.wrap and where and when do you call Sentry.init?

krystofwoldrich avatar Jun 06 '24 11:06 krystofwoldrich

Closing this due to inactivity. If this is still an issue feel free to comment here or open a new issue if the context changed.

krystofwoldrich avatar Jun 21 '24 12:06 krystofwoldrich

I'm experiencing the same behaviour after upgrading from 5.5.0 to 5.25.0. The issue appears on both Android and iOS (I build using RN 0.71.8).

Here is what my App.js looks like

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

Sentry.init({ 
    dsn: myDSN, 
    attachScreenshot: true,
    beforeSend(event) {
      return event;
    },
  });

function App ()  {
    // ... My code here
    <Sentry.ErrorBoundary 
          fallback={({ error, componentStack, resetError }) => (
             // ... My code here
          )}
     >
            <MyComponent/>
     </Sentry.ErrorBoundary>
}

const SentryWrappedApp = Sentry.wrap(App);

export default SentryWrappedApp;

mednche avatar Jul 13 '24 00:07 mednche

I'm also experiencing this issue on a dev build with React Native and Expo. Just installed Sentry for the first time

AdamElitzur avatar Jul 15 '24 02:07 AdamElitzur

Same issue. Expo: 50.0.17, React Native: 0.73.6

BartoszDadok avatar Jul 25 '24 13:07 BartoszDadok

Facing this issue when testing using Expo Go app also. Expo: 50.0.19, React Native: 0.73.6 Edit: Tested on Expo: 51.0.24, React Native: 0.74.3 also, same issue happening. My initialization is exactly like @mednche except i am using Bugsnag's ErrorBoundary instead of Sentry's.

summerkiflain avatar Aug 02 '24 21:08 summerkiflain

Experiencing this as well, exact same situation as @mednche

SzyVsSi avatar Aug 06 '24 09:08 SzyVsSi

Also experiencing.

achall9 avatar Aug 06 '24 20:08 achall9

Also experiencing.

iamdavidmartin avatar Aug 20 '24 21:08 iamdavidmartin

Also experiencing.

kadirucsu avatar Aug 29 '24 11:08 kadirucsu

Same with Expo 51 / React Native 0.75!

delphinebugner avatar Sep 18 '24 09:09 delphinebugner

@krystofwoldrich could you please reopen this issue

Legion2 avatar Sep 20 '24 14:09 Legion2

My bad I'm not affected anymore, I found out what was wrong in my code 🤦‍♀

I had:

// In _layout.tsx
myCustomInitSentryFunction()

const RootLayout = () => { 
 // ...
}

export default Sentry.wrap(RootLayout);  // ✅ always called 

// In MyIsolatedSentry.ts
const myCustomInitSentryFunction = () => {
   if(!__DEV__) {
       Sentry.init( ... )  // 🐞 never called in dev 
   }}
...
}

So Sentry.wrap always had a warning in dev!

Let's refactor this and deactivate the wrap in dev, not just the init 😁

delphinebugner avatar Sep 20 '24 16:09 delphinebugner

Also experiencing.

CMLCNL avatar Sep 21 '24 10:09 CMLCNL

@delphinebugner Thanks! I totally missed that I was also not initing Sentry in __DEV__ mode but was wraping still.

markymc avatar Sep 25 '24 06:09 markymc

Here is the simple solution if anyone is looking for instead of

if (!__DEV__) {
  Sentry.init({
      //...other sentry config
  });
}

Do this

Sentry.init({
  enabled: !__DEV__,
  //...other sentry config
})```

gr8pathik avatar Oct 11 '24 16:10 gr8pathik

Here is the simple solution if anyone is looking for instead of

if (!__DEV__) {
  Sentry.init({
      //...other sentry config
  });
}

Do this

Sentry.init({
  enabled: !__DEV__,
  //...other sentry config
})```

wouldn't that mean i wouldn't be able to capture any error on dev also, what if i don't want that?

sleekLancelot avatar Mar 19 '25 16:03 sleekLancelot

This is all nice and dandy, but what if I need to call Sentry.init() after I used Sentry.wrap() for my app's root component?

My use case is that I need to dynamically set the dist and release values in Sentry.init() based on over-the-air updates fetched from my server:

  1. use Sentry.wrap(App) for my root component,
  2. in a hook in the App, check server for possible OTA updates -> returns release and dist
  3. call Sentry.init() with these release and dist values

Setting these values after initializing Sentry worked in previous versions (via Sentry.setRelease() / Sentry.setDist()), somehow that functionality was completely removed by now.

skizzo avatar Apr 09 '25 10:04 skizzo

I think this should get fixed. @krystofwoldrich can you please reopen?

The issue is that in development sentry is rightfully disabled, which causes it to throw this warning because the calls to .wrap aren't removed. The calls to .wrap shouldn't need to get removed. We shouldn't need to bifurcate exports and imports just because Sentry is throwing a custom warning without doing so. It's extra logic just to silence a warning that shouldn't exist.

shamilovtim avatar May 05 '25 14:05 shamilovtim

The following is the "fix" required to make the warning go away. One would note that it's silly to have to do this:

export default !__DEV__ ? Sentry.wrap(App) : App;

shamilovtim avatar May 05 '25 15:05 shamilovtim