Skip to content

leftyio/angular_sentry

Repository files navigation

Dart

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: SentryUser(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);
}

Releases

No releases published

Packages

No packages published