2

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?

ebakunin
  • 3,621
  • 7
  • 30
  • 49

2 Answers2

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