我按照their tutorial在我的Angular应用程序上安装了Sentry,因为它的部分已经过时,所以我一直在我的代码中修复它们,最后得到了这个:
// My module.ts
// modules
import { NgModule, Injector, ErrorHandler } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
// import Raven from 'raven-js/src/raven';
import * as Raven from 'raven-js';
Raven.config('https://mypublicDSN@sentry.io/omitted').install();
class RavenExceptionHandler {
call(err:any) {
Raven.captureException(err.originalException);
}
}
// components
import { MyComponent } from './components/my.component';
// services
import { ApiService } from './services/api';
// configuration
import { environment } from 'environments/environment';
// instance
@NgModule({
providers: [
ApiService,
{
provide: ErrorHandler,
useClass: RavenExceptionHandler
}
],
declarations: [
MyComponent,
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
HttpClientModule,
// material design components:
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatFormFieldModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatListModule,
MatNativeDateModule,
MatProgressBarModule,
MatRadioModule,
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule,
MatStepperModule,
MatTableModule,
MatToolbarModule,
MatTooltipModule,
],
exports: [
MyComponent,
],
})
export class MyModule {
constructor(private injector: Injector) { }
}
我导入了Raven,使用我的公共DSN对其进行了配置,对RavenExceptionHandler
进行了初始化,导入ErrorHandler
并添加了使用这两种处理程序的提供程序。
现在我的设置已经转到我的组件并且在构造函数中引发了错误:
// my.component.ts
import { Component, Input, ElementRef, ViewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DataService } from './data.service';
@Component({
selector: 'my-selector',
templateUrl: './my-selector.template.html',
styleUrls: ['./my-selector.styles.css']
})
export class DataPrepComponent {
@Input() public projectId: string;
@Input() public documentId: string;
constructor(public dataService: DataService) {
console.log("Throwing error");
throw new Error('Throwing error for Sentry');
}
}
我可以看到日志中出现的错误,但我无法在Sentry信息中心看到任何内容:
我在我的本地主机上运行它。但是我找不到任何可以防止日志出现的文档,我也允许任何域发送日志:
我做错了什么或不做什么?