I am running Bugsnag in Angular 8.x and want to completely turn off reporting based on a property in environment.ts. I know how to pass the property, but I cannot figure out how to turn off reporting. What is the process for doing this?
Asked
Active
Viewed 361 times
2 Answers
2
I had a short look into Bugsnag docs for Angular: https://docs.bugsnag.com/platforms/javascript/angular/
And found out that bugsnag is used as a provider:
@NgModule({
providers: [ { provide: ErrorHandler, useFactory: errorHandlerFactory } ]
})
I would change by adding an if
where its possible to only add the provider for a specific environment:
const providers = [];
if (enviroment.production) {
providers.push({ provide: ErrorHandler, useFactory: errorHandlerFactory });
}
@NgModule({
providers,
})

rafaelwalter
- 136
- 4
1
For the prosperity, I let the 'official' solution here - because building dynamic providers seems not working in module.app :
Bugsnag.start({
apiKey: '**YOURKEY***',
enabledReleaseStages: ['production', 'staging'], // <=== Just enable for production and staging...
});
Here is the doc : https://docs.bugsnag.com/platforms/javascript/angular/configuration-options/#enabledreleasestages

Eric Cappannelli
- 11
- 1
-
How do you suggest it knows whether the current build is production or staging? – Muhammad bin Yusrat Sep 16 '20 at 15:10