Angular 哨兵不为我工作

Sentry isn't working for me on Angular

我按照 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,用我的 public 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 仪表板中看不到任何记录:

我在我的本地主机上 运行 这个。 但是我找不到任何文档说这会阻止日志出现,而且我也我允许任何域发送日志:

我做错了什么或没做什么?

哨兵有一个新的SDK for angular apps

您可以通过在 sentry.io 导航栏搜索输入中搜索 "Client Keys DSN" 来找到您的应用 dsn link。