-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup the sample angular application (#170)
- Loading branch information
1 parent
ea12b72
commit 7e272aa
Showing
3 changed files
with
123 additions
and
93 deletions.
There are no files selected for viewing
27 changes: 17 additions & 10 deletions
27
sample/applicationinsights-angularplugin-sample/src/app/app.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 103 additions & 74 deletions
177
sample/applicationinsights-angularplugin-sample/src/app/telemetry.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,112 @@ | ||
import { Injectable, Injector} from '@angular/core'; | ||
import { Injectable, Injector } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { AngularPlugin, ApplicationinsightsAngularpluginErrorService } from '@microsoft/applicationinsights-angularplugin-js'; | ||
import { ApplicationInsights, ICustomProperties, IDependencyTelemetry, IEventTelemetry, IExceptionTelemetry, IMetricTelemetry, IPageViewTelemetry, ITraceTelemetry } from '@microsoft/applicationinsights-web'; | ||
import { | ||
AngularPlugin, | ||
ApplicationinsightsAngularpluginErrorService, | ||
} from '@microsoft/applicationinsights-angularplugin-js'; | ||
import { | ||
ApplicationInsights, | ||
ICustomProperties, | ||
IDependencyTelemetry, | ||
IEventTelemetry, | ||
IExceptionTelemetry, | ||
IMetricTelemetry, | ||
IPageViewTelemetry, | ||
ITraceTelemetry, | ||
} from '@microsoft/applicationinsights-web'; | ||
import { environment } from 'src/environments/environment'; | ||
|
||
@Injectable() | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ApplicationInsightsService { | ||
myinjector = Injector.create({ | ||
providers: [ | ||
{ | ||
provide: ApplicationinsightsAngularpluginErrorService, | ||
useClass: ApplicationinsightsAngularpluginErrorService, | ||
}, | ||
], | ||
}); | ||
|
||
myinjector = Injector.create({ | ||
providers: [ | ||
{ provide: ApplicationinsightsAngularpluginErrorService, useClass: ApplicationinsightsAngularpluginErrorService } | ||
] | ||
}); | ||
|
||
private angularPlugin = new AngularPlugin(this.myinjector); | ||
private appInsights = new ApplicationInsights({ | ||
config: { | ||
connectionString: environment.connectionString, | ||
extensions: [this.angularPlugin], | ||
// auto router tracking, default pageview duration will be set to 0 | ||
extensionConfig: { | ||
[this.angularPlugin.identifier]: { | ||
router: this.router, useInjector: true | ||
}, | ||
}, | ||
private angularPlugin = new AngularPlugin(this.myinjector); | ||
private appInsights = new ApplicationInsights({ | ||
config: { | ||
connectionString: environment.connectionString, | ||
extensions: [this.angularPlugin], | ||
// auto router tracking, default pageview duration will be set to 0 | ||
extensionConfig: { | ||
[this.angularPlugin.identifier]: { | ||
router: this.router, | ||
useInjector: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
constructor(private router: Router) { | ||
this.appInsights.loadAppInsights(); | ||
this.appInsights.setAuthenticatedUserContext('UserContext'); | ||
this.appInsights.addTelemetryInitializer((envelope) => { | ||
envelope.tags = envelope.tags || []; | ||
envelope.tags['ai.cloud.role'] = 'testTag'; | ||
}); | ||
} | ||
|
||
// expose tracking methods | ||
trackEvent(event: IEventTelemetry, customProperties?: ICustomProperties) { | ||
this.appInsights.trackEvent(event, customProperties); | ||
} | ||
|
||
startTrackEvent(name?: string) { | ||
this.appInsights.startTrackEvent(name); | ||
} | ||
|
||
stopTrackEvent( | ||
name: string, | ||
properties?: { [p: string]: string }, | ||
measurements?: { [p: string]: number } | ||
): any { | ||
this.appInsights.stopTrackEvent(name, properties, measurements); | ||
} | ||
|
||
trackPageView(pageView?: IPageViewTelemetry) { | ||
this.appInsights.trackPageView(pageView); | ||
} | ||
|
||
startTrackPage(name?: string) { | ||
this.appInsights.startTrackPage(name); | ||
} | ||
|
||
stopTrackPage( | ||
name?: string, | ||
url?: string, | ||
properties?: { [name: string]: string }, | ||
measurements?: { [name: string]: number } | ||
) { | ||
this.appInsights.stopTrackPage(name, url, properties, measurements); | ||
} | ||
|
||
trackMetric(metric: IMetricTelemetry, properties?: ICustomProperties) { | ||
this.appInsights.trackMetric(metric, properties); | ||
} | ||
|
||
trackException( | ||
exception: IExceptionTelemetry, | ||
properties?: ICustomProperties | ||
) { | ||
this.appInsights.trackException(exception, properties); | ||
} | ||
|
||
trackTrace(message: ITraceTelemetry, properties?: ICustomProperties) { | ||
this.appInsights.trackTrace(message, properties); | ||
} | ||
|
||
constructor(private router: Router) { | ||
this.appInsights.loadAppInsights(); | ||
this.appInsights.setAuthenticatedUserContext("UserContext"); | ||
this.appInsights.addTelemetryInitializer(envelope => { | ||
envelope.tags = envelope.tags || []; | ||
envelope.tags["ai.cloud.role"] = "testTag"; | ||
}); | ||
} | ||
trackDependencyData(dependency: IDependencyTelemetry) { | ||
this.appInsights.trackDependencyData(dependency); | ||
} | ||
|
||
// expose tracking methods | ||
trackEvent(event: IEventTelemetry, customProperties?:ICustomProperties) { | ||
this.appInsights.trackEvent(event, customProperties); | ||
} | ||
|
||
startTrackEvent(name?: string) { | ||
this.appInsights.startTrackEvent(name); | ||
} | ||
|
||
stopTrackEvent(name: string, properties?: { [p: string]: string }, measurements?: { [p: string]: number }): any { | ||
this.appInsights.stopTrackEvent(name, properties, measurements); | ||
} | ||
|
||
trackPageView(pageView?:IPageViewTelemetry) { | ||
this.appInsights.trackPageView(pageView); | ||
} | ||
|
||
startTrackPage(name?: string) { | ||
this.appInsights.startTrackPage(name); | ||
} | ||
|
||
stopTrackPage(name?: string, url?: string, properties?: { [name: string]: string }, measurements?: { [name: string]: number }) { | ||
this.appInsights.stopTrackPage(name, url, properties, measurements); | ||
} | ||
|
||
trackMetric(metric:IMetricTelemetry, properties?: ICustomProperties) { | ||
this.appInsights.trackMetric(metric, properties); | ||
} | ||
|
||
trackException(exception: IExceptionTelemetry, properties?: ICustomProperties) { | ||
this.appInsights.trackException(exception, properties); | ||
} | ||
|
||
trackTrace(message: ITraceTelemetry, properties?: ICustomProperties) { | ||
this.appInsights.trackTrace(message, properties); | ||
} | ||
|
||
trackDependencyData(dependency: IDependencyTelemetry) { | ||
this.appInsights.trackDependencyData(dependency); | ||
} | ||
|
||
flush() { | ||
this.appInsights.flush(); | ||
} | ||
} | ||
flush() { | ||
this.appInsights.flush(); | ||
} | ||
} |