Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ng-application-insights.service.ts #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Injectable } from '@angular/core';
import {
ApplicationInsights,
IConfig,
IConfiguration,
IEventTelemetry,
IExceptionTelemetry,
ITelemetryItem,

} from '@microsoft/applicationinsights-web';
import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
import { Router } from '@angular/router';

interface ICustomProperties {
[key: string]: any;
Expand All @@ -16,15 +19,18 @@ export class NgApplicationInsightsConfig {
enabled = true;
instrumentationKey = '';
properties?: ICustomProperties = {};
}
extraConfig?: IConfiguration & IConfig = {};
disabledUrls?: string[] = [];
};

@Injectable({
providedIn: 'root',
})
export class NgApplicationInsightsService {
appInsights: ApplicationInsights;
public appInsights!: ApplicationInsights;
private customProperties: ICustomProperties = {};


constructor(
private config: NgApplicationInsightsConfig,
private router: Router
Expand All @@ -34,9 +40,19 @@ export class NgApplicationInsightsService {
config: {
instrumentationKey: this.config.instrumentationKey,
enableAutoRouteTracking: true,
...this.config.extraConfig,
},
});

this.appInsights.addTelemetryInitializer((envelope: ITelemetryItem) => {
const dataBase = JSON.stringify(envelope.baseData);
const disabled = this.config.disabledUrls || [];
if ( disabled.some((item) => dataBase.includes(item))) {
return false;
}
return true;
});

this.appInsights.loadAppInsights();
this.createRouterSubscription();
}
Expand Down
Loading