getsentry / sentry-react-native

Official Sentry SDK for React Native
https://sentry.io
MIT License
1.57k stars 337 forks source link

Errors not being tracked after EAS Update #4002

Closed alejandrocarebit closed 1 month ago

alejandrocarebit commented 2 months ago

OS:

Platform:

SDK:

SDK version: 5.27.0

react-native version: 0.0.0

Are you using Expo?

Are you using sentry.io or 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)


import * as Sentry from '@sentry/react-native';
import { isRunningInExpoGo } from 'expo';
import { useNavigationContainerRef } from 'expo-router';

const ref = useNavigationContainerRef();
  const routingInstrumentation = new Sentry.ReactNavigationInstrumentation();

  React.useEffect(() => {
    if (ref) {
      routingInstrumentation.registerNavigationContainer(ref);
    }
  }, [ref]);

Sentry.init({
  dsn: 'https://...@sentry.io/...'
   environment: Config.get("ENV"),
integrations: [
        new Sentry.ReactNativeTracing({
          routingInstrumentation,
          enableNativeFramesTracking: !isRunningInExpoGo(),
        }),
      ],
});

I have the following issue:

I have a React Native application created with Expo and use Expo EAS Build for my preview and production builds.

I have three environment variables:

EXPO_PUBLIC_API_URL: This changes based on whether the build is for preview or production. Two secret keys, one of which is SENTRY_AUTH_TOKEN. Locally, I use a .env file for environment variables when working in development, but I don't include SENTRY_AUTH_TOKEN there because Sentry isn't needed in development.

For EAS Build, I have added EXPO_PUBLIC_API_URL to eas.json as follows:

{
  "preview": {
    "channel": "preview",
    "distribution": "internal",
    "env": {
      "APP_VARIANT": "preview",
      "EXPO_PUBLIC_API_URL": "https://my-staging-url.com"
    }
  },
  "production": {
    "channel": "production",
    "autoIncrement": true,
    "env": {
      "APP_VARIANT": "production",
      "EXPO_PUBLIC_API_URL": "https://my-prod-url.com"
    }
  }
}

The other two environment variables have been added as secrets in the Expo dashboard being SENTRY_AUTH_TOKEN one of them. So far, everything works perfectly.

I have tested that errors are properly tracked in Sentry by throwing an error when pressing a button:

throw new Error("My Sentry error");

I'm now setting up Expo EAS Update based on the documentation:

When I run the command eas update --branch preview, I noticed that EAS Update takes the environment variables from my local .env file. However, it doesn't have access to the secrets from the Expo dashboard.

As a result, when I make an update, the app doesn't report errors to Sentry. I suspect it is because SENTRY_AUTH_TOKEN is undefined since EAS Update is not able to retrieve the secrets from the Expo dashboard. I've also uploaded the source maps successfully by running npx sentry-expo-upload-sourcemaps dist but get the same result.

The way I test it is the same as before, throwing an error when pressing a button but this time the error is not tracked by Sentry:

throw new Error("My Sentry error");

Steps to reproduce:

Actual result:

Errors are not being tracked anymore after updating the app via EAS Update.

Expected result:

I expect errors being tracked after the update, otherwise EAS Update is useless for me.

krystofwoldrich commented 2 months ago

Hi @alejandrocarebit, thank you for creating the issue, for full context this issue was created based on https://stackoverflow.com/questions/78842407/how-to-access-expo-dashboard-secrets-in-eas-update-for-sentry-integration-in-rea/78844262#78844262

Could you share a bit more details on what update strategy are you using?

Are you using https://docs.expo.dev/versions/latest/sdk/updates/#updatesreloadasync

alejandrocarebit commented 2 months ago

Hi Krystof,

Thanks for your answer. I'm using the standard strategy for React Native described in the Expo and Sentry docs:

  1. I installed the expo-updates dependency (version 0.25.21).

  2. I added these two new entries in my app.config.js:

updates: {
      url: 'https://u.expo.dev/my-id',
    },
    runtimeVersion: {
      policy: 'appVersion',
    },

3- I modified my metro.config.js file:

const { getSentryExpoConfig } = require('@sentry/react-native/metro');

const config = getSentryExpoConfig(__dirname);

module.exports = config;

4- I added two channels (preview/production) in my eas.json file:

{
  "preview": {
    "channel": "preview",
    "distribution": "internal",
    "env": {
      "APP_VARIANT": "preview",
      "EXPO_PUBLIC_API_URL": "https://my-staging-url.com"
    }
  },
  "production": {
    "channel": "production",
    "autoIncrement": true,
    "env": {
      "APP_VARIANT": "production",
      "EXPO_PUBLIC_API_URL": "https://my-prod-url.com"
    }
  }
}

Following these steps Expo Update works, the only issue I have is that errors are not being tracked in Sentry anymore after that.

krystofwoldrich commented 2 months ago

@alejandrocarebit Thank you for the confirmation. So no manual apis are used (https://docs.expo.dev/versions/latest/sdk/updates/#updatesreloadasync).

We will investigate this.

alejandrocarebit commented 2 months ago

Thanks a lot Krystof, I highly appreciate your help.

krystofwoldrich commented 2 months ago

Hi @alejandrocarebit, sadly I'm not able to reproduce the behavior.

I wanted to check are you able to reproduce the error also with Development Builds and Extensions Tab -> https://docs.expo.dev/eas-update/publish/#testing-a-published-update

Would you be able to share a reproducible example with us?

alejandrocarebit commented 2 months ago

Hi @krystofwoldrich,

Unfortunately I haven't been able to reproduce it with Development builds, it seems to work fine. This is weird, I'll try to reproduce it again in a preview / production build and share an example with you.

Thanks for your help.

krystofwoldrich commented 2 months ago

@alejandrocarebit Thank you.

krystofwoldrich commented 1 month ago

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.