Skip to content

Commit 4fea486

Browse files
committed
test for instrumentationKey
1 parent 445175d commit 4fea486

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule, ModuleWithProviders, Optional, SkipSelf } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

4-
import {AppInsightsConfig, AppInsightsService} from './src/app-insight.service';
4+
import { AppInsightsConfig, AppInsightsService } from './src/app-insight.service';
55

66
export * from './src/app-insight.service';
77

src/app-insight.service.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,25 @@ export class AppInsightsService implements IAppInsights {
195195
}
196196

197197
public init(): void {
198+
if (!this.config.instrumentationKey) {
199+
throw new Error(
200+
'An instrumentationKey value is required in initialize AppInsightsService ');
201+
}
202+
198203
try {
199-
console.warn('in AppInsights.init');
200-
AppInsights.downloadAndSetup(this.config);
201-
console.warn('in AppInsights.init: calling downloadAndSetup');
202-
203-
this.router.events.filter(event => event instanceof NavigationStart)
204-
.subscribe((event: NavigationStart) => {
205-
this.startTrackPage(event.url);
206-
});
207-
208-
this.router.events.filter(event => event instanceof NavigationEnd)
209-
.subscribe((event: NavigationEnd) => {
210-
this.stopTrackPage(event.url);
211-
});
204+
console.warn('in AppInsights.init');
205+
AppInsights.downloadAndSetup(this.config);
206+
console.warn('in AppInsights.init: calling downloadAndSetup');
207+
208+
this.router.events.filter(event => event instanceof NavigationStart)
209+
.subscribe((event: NavigationStart) => {
210+
this.startTrackPage(event.url);
211+
});
212+
213+
this.router.events.filter(event => event instanceof NavigationEnd)
214+
.subscribe((event: NavigationEnd) => {
215+
this.stopTrackPage(event.url);
216+
});
212217
} catch (ex) {
213218
console.warn('Angular application insights Error [downloadAndSetup]: ', ex);
214219
}

0 commit comments

Comments
 (0)