angular_sentry 0.0.9
angular_sentry: ^0.0.9 copied to clipboard

Helper to implements sentry with Angular

angular_sentry #

Helper to implements sentry.io with Angular.

Usage #

Inject Angular Sentry #

import "package:angular/angular.dart";
import "package:angular_sentry/angular_sentry.dart";

// ignore: uri_has_not_been_generated
import 'main.template.dart' as ng;

const sentryModule = Module(provide: [
  ClassProvider(ExceptionHandler, useClass: AngularSentry),
]);

@GenerateInjector([sentryModule])
const scannerApp = ng.scannerApp$Injector;

Init Sentry and run your app #

Future<void> main() async {
  await Sentry.init(
    (options) {
      options.dsn = 'https://example@sentry.io/add-your-dsn-here';
      options.environment = 'production';
      options.release = '1.0.0';
    },
    appRunner: initApp,
  );
}

void initApp() {
  runApp(ng.AppComponentNgFactory, createInjector: scannerApp);
}

Advanced #

Implement your own class using AngularSentry

class AppSentry extends AngularSentry {
  @override
  Event transformEvent(SentryEvent e) {
    return super.transformEvent(e).copyWith(
      user: new User(id: '1', ipAddress: '0.0.0.0'),
      extra: {"location_url": window.location.href},
    );
  }

  @override
  void capture(exception, [trace, String reason]) {
    if (exception is ClientException) {
      logError("Network error");
    } else {
      super.capture(exception, trace, reason);
    }
  }
}

const sentryModule = Module(provide: [
  FactoryProvider(SentryClient, sentryProdider),
  ClassProvider(ExceptionHandler, useClass: AppSentry),
]);

main() {
  runApp(appComponentNgFactory, createInjector: scannerApp);
}
1
likes
80
pub points
53%
popularity

Helper to implements sentry with Angular

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

angular, logging, meta, sentry

More

Packages that depend on angular_sentry