Ale
Ale

Reputation: 2344

How to Access Expo Dashboard Secrets in EAS Update for Sentry Integration in React Native?

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:

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. So far, everything works perfectly.

I'm now setting up Expo EAS Update based on the documentation: https://docs.expo.dev/guides/using-sentry/#app-configuration

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 because SENTRY_AUTH_TOKEN is undefined. I also run the command npx sentry-expo-upload-sourcemaps dist but get the same result.

How can I ensure that EAS Update has access to the secrets from the Expo dashboard, specifically for SENTRY_AUTH_TOKEN, to properly report errors to Sentry?

I understand that Expo environment variables need to start with EXPO_PUBLIC_ to be recognised, so that's why I can't add it to my local .env file as I do with the other two.

Any ideas or suggestions?

Upvotes: 0

Views: 492

Answers (1)

Krystof Woldrich
Krystof Woldrich

Reputation: 126

The Secrets set in Expo Dashboard are only available in the EAS Builds. They are not pulled from EAS to your local environment.

If you create an EAS Update without the SENTRY_AUTH_TOKEN your application will report all errors, but because of the missing token source maps won't be uploaded for the update so you will see a stack trace pointing to the bundle instead of the original source code.

To upload the source maps using npx sentry-expo-upload-sourcemaps dist you need SENTRY_AUTH_TOKEN in your local environment. You can create the token like follows:

  1. Go to sentry.io
  2. Open Settings -> Developer Settings -> Auth Tokens
  3. Click Create New Token

More at https://docs.sentry.io/account/auth-tokens/

Disclaimer: I work at Sentry.

Upvotes: 1

Related Questions