I'm using sentry with react native. I can set the environment when I init:
const env = 'staging'
Sentry.init({
environment: env,
dsn: 'blah',
enableInExpoDevelopment: true
});
But if I want to change the environment later? Do I need to call init again? Or is this something that can be passed up per event?
For capturing events I use something like:
Sentry.Native.captureMessage(eventName, context)
You only need to initialize Sentry one time.
When pushing your changes to main branch, don't forget to also change Sentry's environment to "production" and also your app's version, that will help you debug which version is having issues.
Related
I got a react-native app already ready and works but the app points on a prod api so to avoid problems I wanted that she points on a rest api, so how can I reconfigure it, I have only an environment file.js that contains the URL api, and this file is called in the API service
I tried react-native config but didn't know how to make it work,
All I want is to duplicate that env file because he contains all necessary URLs, so I want to have file named envProd and another named envStaging they should be similar the only different part is the URL of my api , so when I want to run the app i precise which file I want to choose to run with
If the API URL's are the only difference, you don't need to create two separate config files. Instead, you can make use of the inbuild __DEV__ global variable in JavaScript to determine if you're using React Native packager (dev mode) or not (production).
Ref: https://facebook.github.io/react-native/docs/javascript-environment.html
So, something like below.
var apiURL = __DEV__ == true ? 'development.api.com' : 'prod.api.com';
I am finding switching environments quite hard to manage.
__DEV__ is awesome for local disabling stuff when in development. Won't work for any of the builds though.
For staging vs production seems that configuring react-native-config is the best. Unfortunately, next to being somewhat hard to configure binaries need to get recompiled separately for each environment. This means - one update - two build with uploads to whatever provider you use. It can get more complex if you use something like codepush too.
possible solution
Create a hidden feature in your app that allows to toggle the environment from the within the app. This way you can have one build, give it to testers. They switch env to staging and later you only need to promote it as a production build.
This could be something like tap 10 times on an empty space somewhere - the more creative you get the better :)
Good luck
const _Environments = {
production: {
API_BASE: 'https://api.test.com/',
USERNAME: 'admin',
PASSWORD: '1234',
},
development: {
API_BASE: 'https://dev.api.test.com/',
USERNAME: 'admin',
PASSWORD: '1234',
},
};
function getEnvironment() {
// Insert logic here to get the current platform (e.g. staging, production, etc)
var platform = __DEV__ ? 'development' : 'production';
// ...now return the correct environment
return _Environments[platform];
}
export const Environment = getEnvironment();
Try this. using yargs you can replace static import content with dynamic scripts.
I'm running a vue.js application in a Docker container. I have some configuration set via environment variables (e.g. API base url). I want to be able to use these variables in my application in browser. How can I pass them?
I tried to add these variables to one of the config/*.env.js files like that (config/dev.env.js):
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
backendBase: process.env.BACKEND_BASE
})
Then I run application using npm run dev but process.env object is always empty (NODE_ENV is also not available)
I came across the exact same problem recently. If you are running the dev server using a watcher I think it doesn't pick the config change up correctly. I stopped my dev server, rebuilt production as well (no idea if that helps but just in case) and then started the dev server up again and all was ok.
To access the above settings you should be able to use process.env in your code
console.log(process.env.NODE_ENV)
I think only variables prefixed with VUE_APP get packaged up by Vue.
From: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables
Note that only variables that start with VUE_APP_ will be statically
embedded into the client bundle with webpack.DefinePlugin.
I tested locally.
.env in root:
APP_TEST=foo
VUE_APP_TEST=bar
In main.js:
// imports and other stuff
new Vue({
render: h => h(App),
}).$mount('#app');
console.log(process.env.APP_TEST, 'APP_TEST');
console.log(process.env.VUE_APP_TEST, 'VUE_APP_TEST');
Output:
undefined APP_TEST
bar VUE_APP_TEST
You'll need to run another build if you make changes to your envvars.
Working with:
"react-native": "0.51"
When I console.log in Remote JS Debugger, the source of the log is always:
console.js:35
It ignores the actual line where the log was made from. This used to work as expected. Is there a way to make it work again?
I found that this was actually caused by having React Native Sentry installed.
To resolve this whilst in development mode I disabled Sentry, which arguably makes more sense as I only want to be tracking production errors there.
// Only run Sentry in production
if (!__DEV__) {
Sentry.config(_CONFIG_URL_HERE_).install();
}
If you don't want to disable Sentry, add this to your Sentry init:
Sentry.init({
dsn: '__YOUR_DSN__',
integrations: [new Sentry.Integrations.Breadcrumbs({
console: false
})]
})
I'm using React-Native 0.33.
Lots of modules I depend on have debug logs, which use the NPM debug() module. They require an ENV var to be set, i,e. "export DEBUG=*" to enable the logs.
React-Native doesn't really allow setting ENV vars. I've tried doing process.env.DEBUG='*' in code, and it doesn't work.
How do you guys enable debug logging for modules you depend on in RN?
At the very beginning of your app launch in index.ios.js before you import any of your modules, you could do something like
const debug = require('debug');
debug.enable('*'); // or use specific subkeys
This will make sure that that subsequent calls like below will actually generate a debug function that logs something
const debug = require('debug')('mykey');
debug('Testing debug works');
I'm using a node package API client in my react-native project that uses the process.env.NODE_ENV to determine whether to return development or production data. I'd like to test it in my dev environment (simulator) against the production database (it's read-only and the data greatly differs between dev and prod).
From what I can tell from this:
https://github.com/reactjs/react-redux/issues/39#issuecomment-131415769
process.env.NODE_ENV is set to development by default when the dev flag is true.
I've tried setting the NODE_ENV to production in my environment but it isn't picked up in the actual simulator (it still says development).
Is there some way to specify this when starting up or using run-*?
In your AppDelegate.m startup (before calling jsBundleForBundleRoot), add this:
[RCTBundleURLProvider sharedSettings].enableDev = false;
Or for Android, it should be something like this (untested):
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("js_dev_mode_debug", false);
Note that these change the defaults, which I believe exist beyond the execution of your app. So you'll probably need to run them again with true to reset them back to the default values.