Snippet: Disabling Sentry for Test environments in Ionic

Spread the love

First, we need to setup Environment variables in Ionic, unfortunately, there is no easy recommended way of doing that, here’s an open issue.
Github user fiznool has provided with a really nice solution with 0 dependencies. This is my preferred approach. There are a bunch of other methods on the issue as well, so do check them out. Once you setup your environment variables, you can simply check whether the environment type is dev or production.
The environment variable ENV already has this information, and we can access it to disable Sentry for non-prod environments:

if (ENV.environment === 'prod') {
    Sentry.create({ dsn: 'YOUR DSN here' });
} else {
    // pass
}

Steps for installing Sentry for Ionic: https://docs.sentry.io/clients/cordova/ionic/

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *