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

Configuration of release name and distribution

Open birdofpreyru opened this issue 3 years ago • 9 comments

Problem Statement

Currently, the only way to override defaults for the plugin is via SENTRY_RELEASE and SENTRY_DIST environment variables. I believe, this is against the Gradle's best practices for project configuration, and it creates pratical problems when app version and build number come from the app's build.gradle file, as there is no clean way to override from within build.gradle the values which Sentry's Gradle Plugin will get from System.getenv(...) call during configuration.

Solution Brainstorm

I suggest to add a way to provide custom release name and build number to the plugin via gradle properties. I am mostly noob in Gradle and Java, thus I'll leave implementation details for more knowledgeble people :)

birdofpreyru avatar Jul 28 '22 18:07 birdofpreyru

Thanks for raising this. It makes sense to me, but I'll defer this to folks here that have more opinions on this 👍

bruno-garcia avatar Jul 28 '22 18:07 bruno-garcia

@birdofpreyru are you using this on a React Native build? Could you please share a bit more information on how you are using the sentry android gradle plugin?

adinauer avatar Aug 17 '22 14:08 adinauer

Hi @adinauer , yes I use it for RN build, everything is pretty standard in my project(s).

The problem I encountered was this: the package / bundle names of a project were different for Android and iOS, and as they are used for default release names by Sentry, for each my release I was getting two different releases tracked in Sentry (one for Android and one for iOS).

At the same time, I just recently figured out that Sentry releases are cross-project, and decided to clean-up my projects integration with Sentry by naming releases like [email protected]. As per this document, the best approach to do so is to set SENTRY_RELEASE environment variable.

For XCode builds it seems easy: with a slight modification of Sentry-related build phases, I can set SENTRY_RELEASE variable where necessary, while using the app version and build number, stored by XCode in other environment variables.

For Android builds, it seems somewhat more tricky: in my best understanding, it is not possible to set an environment variable from Gradle script, and I wanted it because the code version and build numbers are hardcoded into Gradle script, and I want to use them inside Sentry release name. Sure, I did a workaround moving the version / build numbers and setting SENTRY_RELEASE variable into a bash script that launches Gradle. However, it feels easier if Sentry Android Gradle plugin would allow to set release name from within the Gradle script.

birdofpreyru avatar Aug 17 '22 15:08 birdofpreyru

This plugin (SAGP) is only responsible for uploading proguard/r8 mappings and debug symbols, moving this issue to https://github.com/getsentry/sentry-react-native Today you can call Sentry.init with a custom release/dist, https://docs.sentry.io/platforms/react-native/sourcemaps/#using-custom-release-and-distribution and later upload source maps manually, using sentry-cli or using the env. var. as described.

I agree, we could also offer the release/dist directly in the Gradle configuration, it's a nice to have.

marandaneto avatar Sep 02 '22 05:09 marandaneto

@marandaneto sure, though as the documentation page you pointed says:

Before disabling the automatic source maps upload, you can set the release and dist as environment variables, SENTRY_RELEASE and SENTRY_DIST respectively. The script that performs the automatic source maps upload will use those values instead the default ones, and they will match the given release and dist. This ensures that the given custom release and dist values are used.

To which I agree, as it is easier just to set these env vars, than to figure out how to correctly configure CLI for source maps upload. And, even if somebody is to upload them manually, the first step for android is to "remove the Gradle integration", at which point one thinks "why it is not possible to just configure that integration the Gradle way to use desired values" ;)

birdofpreyru avatar Sep 02 '22 08:09 birdofpreyru

Its already possible to do some sort of config with project.ext.sentryCli on Gradle, so this one can fit in there.

marandaneto avatar Dec 07 '22 08:12 marandaneto

I have a related question, in the docs it says When you set a custom release and dist in a React Native app, the automatic source maps upload script will no longer work because it does not detect custom values. You will need to manually upload source maps What happens if I do not set those values? what is the default?

a7madgamal avatar Sep 09 '23 13:09 a7madgamal

got my answer after peeking into the source code

        release.putString("id", packageInfo.packageName);
        release.putString("version", packageInfo.versionName);
        release.putString("build", String.valueOf(packageInfo.versionCode));

a7madgamal avatar Sep 09 '23 13:09 a7madgamal

@a7madgamal Sentry uses the package name and version code by default as you found it in the source code.

https://github.com/getsentry/sentry-react-native/blob/e64a66fe09c19d131d989cb8f49df365df6eb17f/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java#L251-L257

krystofwoldrich avatar Sep 11 '23 09:09 krystofwoldrich