More Related Content
Similar to Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT (20)
More from Jun-ichi Sakamoto (20)
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
- 6. Azure Application InsightsAzure Application Insights
を採⽤してみたを採⽤してみた
Application Insights とは何か?Application Insights とは何か?
Application Insights は、複数のプラットApplication Insights は、複数のプラット
フォームで使⽤できる Web 開発者向けフォームで使⽤できる Web 開発者向け
の拡張可能なアプリケーション パフォの拡張可能なアプリケーション パフォ
ーマンス管理 (APM) サービスです。ーマンス管理 (APM) サービスです。
- 8. // app.module.ts// app.module.ts
import { ApplicationInsightsModule }import { ApplicationInsightsModule }
from '@markpieszak/ng-application-insightsfrom '@markpieszak/ng-application-insights
@NgModule({@NgModule({
......
imports: [imports: [
ApplicationInsightsModule.forRoot({ApplicationInsightsModule.forRoot({
instrumentationKey: '...' }),instrumentationKey: '...' }),
],],
......
})})
export class AppModule { }export class AppModule { }
- 10. わざと例外を起こしてみるわざと例外を起こしてみる
<!-- FetchDataComponent.html --><!-- FetchDataComponent.html -->
<tr *ngFor="let forecast of forecasts"><tr *ngFor="let forecast of forecasts">
<td>{{ forecast.dateFormatted }}</td><td>{{ forecast.dateFormatted }}</td>
<!-- ↓ 変数名をわざと typo --><!-- ↓ 変数名をわざと typo -->
<td>{{ forecas.summary }}</td><td>{{ forecas.summary }}</td>
</tr></tr>
- 11. 例外が起きるようになった例外が起きるようになった
ERROR TypeError: Cannot readERROR TypeError: Cannot read
property 'summary' of undefinedproperty 'summary' of undefined
at Object.eval [as updateRenderer]at Object.eval [as updateRenderer]
(FetchDataComponent.html:21)(FetchDataComponent.html:21)
- 14. window.onerror は設定済みwindow.onerror は設定済み
> window.onerror.toString()> window.onerror.toString()
"function (message, url, lineNumber, columnN"function (message, url, lineNumber, columnN
var handled = originalOnError && originavar handled = originalOnError && origina
......
しかし Angular のエラーは Angular の⽅法しかし Angular のエラーは Angular の⽅法
で処理される...ということは?で処理される...ということは?
- 16. // my-errorhandler.ts// my-errorhandler.ts
import { ErrorHandler, NgModule } from '@angimport { ErrorHandler, NgModule } from '@ang
import { AppInsights } from 'applicationinsiimport { AppInsights } from 'applicationinsi
export class MyErrorHandlerexport class MyErrorHandler
implements ErrorHandler {implements ErrorHandler {
handleError(error: any) {handleError(error: any) {
let message = ...;let message = ...;
......
let errObj = new Error(message);let errObj = new Error(message);
......
AppInsights.trackException(errObj, undefAppInsights.trackException(errObj, undef
pageUrl: window.location.href });pageUrl: window.location.href });
- 17. // app.module.ts// app.module.ts
import { MyErrorHandler }import { MyErrorHandler }
from './my-errorhandler';from './my-errorhandler';
@NgModule({@NgModule({
......
providers: [providers: [
{ provide: ErrorHandler,{ provide: ErrorHandler,
useClass: MyErrorHandler },useClass: MyErrorHandler },
],],
......
})})
export class AppModule { }export class AppModule { }