我正在使用Angular:"@angular/core": "7.2.4",
和哨兵:"@sentry/browser": "4.6.3",
。
使用以下代码,我的应用程序正确抛出错误:
// import * as Sentry from '@sentry/browser';
//
// Sentry.init({
// dsn: 'mydsn',
// debug: true
// });
@Injectable()
export class SentryErrorHandler implements ErrorHandler {
constructor() {}
handleError(error) {
throw error;
// Sentry.captureException(error.originalError || error);
// throw error;
}
}
@NgModule({
declarations: [
AppComponent
],
imports: [
// imports
],
providers: [
{provide: ErrorHandler, useClass: SentryErrorHandler},
],
bootstrap: [AppComponent]
})
但是,一旦我取消对哨兵的评论,我的应用就会因错误而挂起,例如:
import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: 'mydsn',
debug: true
});
@Injectable()
export class SentryErrorHandler implements ErrorHandler {
constructor() {}
handleError(error) {
Sentry.captureException(error.originalError || error);
throw error;
}
}
@NgModule({
declarations: [
AppComponent
],
imports: [
// imports
],
providers: [
// {provide: ErrorHandler, useClass: SentryErrorHandler},
],
bootstrap: [AppComponent]
})
我将debug设置为true,控制台返回:
Sentry Logger [Log]: Integration installed: Dedupe
logger.js:30 Sentry Logger [Log]: Integration installed: InboundFilters
logger.js:30 Sentry Logger [Log]: Integration installed: FunctionToString
logger.js:30 Sentry Logger [Log]: Integration installed: ExtraErrorData
logger.js:30 Sentry Logger [Log]: Integration installed: TryCatch
logger.js:30 Sentry Logger [Log]: Integration installed: Breadcrumbs
logger.js:30 Sentry Logger [Log]: Integration installed: GlobalHandlers
logger.js:30 Sentry Logger [Log]: Integration installed: LinkedErrors
logger.js:30 Sentry Logger [Log]: Integration installed: UserAgent
在Google Chrome浏览器的任务管理器中,CPU峰值启动,然后页面最终崩溃。
我要测试的错误是放置任意的console.log(t);
,其中t
是未定义的变量。
我正在从本地主机运行此命令,可以确认我已允许哨兵项目设置中的所有流量,并且还可以确认DSN用于正确的帐户。