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

Remove App Insights agent from client bundle #3243

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ ignore/
!.yarn/versions

/infrastructure/.terraform/
/.angular/cache/
2 changes: 1 addition & 1 deletion charts/xui-webapp/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ nodejs:
SERVICES_CASE_JUDICIAL_API: http://rd-judicial-api-aat.service.core-compute-aat.internal
SERVICES_LOCATION_REF_API_URL: http://rd-location-ref-api-aat.service.core-compute-aat.internal
FEATURE_ACCESS_MANAGEMENT_ENABLED: true
PREVIEW_DEPLOYMENT_ID: exui-preview-deployment-3230
PREVIEW_DEPLOYMENT_ID: exui-preview-deployment-3243
keyVaults:
rpx:
secrets:
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"@nicky-lenaers/ngx-scroll-to": "^1.1.1",
"accessibility-checker": "^3.0.6",
"applicationinsights": "1.7.2",
"applicationinsights-js": "^1.0.20",
"axios": "^0.21.1",
"axios-mock-adapter": "^1.18.2",
"class-transformer": "^0.3.2",
Expand Down Expand Up @@ -175,7 +174,6 @@
"@stryker-mutator/karma-runner": "^3.0.1",
"@stryker-mutator/mocha-runner": "^3.0.1",
"@stryker-mutator/typescript": "^3.0.1",
"@types/applicationinsights-js": "^1.0.9",
"@types/config": "^0.0.36",
"@types/cookie-parser": "^1.4.2",
"@types/crypto-js": "^3.1.43",
Expand Down
9 changes: 1 addition & 8 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ import { AcceptTermsService } from './services/acceptTerms/acceptTerms.service';
import { CaseShareService } from './services/case/share-case.service';
import { DefaultErrorHandler } from './services/errorHandler/defaultErrorHandler';
import { JurisdictionService } from './services/jurisdiction/jurisdiction.service';
import { AbstractAppInsights, AppInsightsWrapper } from './services/logger/appInsightsWrapper';
import { CryptoWrapper } from './services/logger/cryptoWrapper';
import { LoggerService } from './services/logger/logger.service';
import { MonitoringService } from './services/logger/monitoring.service';
import { SharedModule } from './shared/shared.module';
import { effects } from './store/effects';
// ngrx modules - END
Expand Down Expand Up @@ -125,12 +123,7 @@ export function launchDarklyClientIdFactory(
multi: true
},
CryptoWrapper,
MonitoringService,
LoggerService,
{
provide: AbstractAppInsights,
useClass: AppInsightsWrapper
},
{
provide: ErrorHandler,
useClass: DefaultErrorHandler
Expand All @@ -150,4 +143,4 @@ export function launchDarklyClientIdFactory(
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}
export class AppModule { }
100 changes: 0 additions & 100 deletions src/app/services/logger/appInsightsWrapper.ts

This file was deleted.

30 changes: 10 additions & 20 deletions src/app/services/logger/logger.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LoggerService } from './logger.service';

describe('Logger service', () => {
const mockedMonitoringService = jasmine.createSpyObj('mockedMonitoringService', ['logEvent', 'logException', 'enableCookies']);
const mockedNgxLogger = jasmine.createSpyObj('mockedNgxLogger', ['trace', 'debug', 'info',
'log', 'warn', 'error', 'fatal']);
const mockedSessionStorageService = jasmine.createSpyObj('mockedCookieService', ['getItem']);
Expand All @@ -12,83 +11,74 @@ describe('Logger service', () => {
mockEnvironmentService.config$ = mockConfig;

it('should be Truthy', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
expect(service).toBeTruthy();
});

it('should be able to call info', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.info('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.info).toHaveBeenCalled();
});

it('should be able to call log', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.log('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.log).toHaveBeenCalled();
});

it('should be able to call warn', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.warn('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.warn).toHaveBeenCalled();
});

it('should be able to call error', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.error('message');
expect(mockedMonitoringService.logException).toHaveBeenCalled();
expect(mockedNgxLogger.error).toHaveBeenCalled();
});

it('should be able to call fatal', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.fatal('message');
expect(mockedMonitoringService.logException).toHaveBeenCalled();
expect(mockedNgxLogger.fatal).toHaveBeenCalled();
});

it('should be able to call debug', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.debug('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
});

it('should be able to call trace', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.trace('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(mockedNgxLogger.trace).toHaveBeenCalled();
});

it('should be able to get a message', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
// slice off the last two characters of string to ensure no accidental discrepancies
const expectedMessage = `Message - message, Timestamp - ${Date.now()}`.slice(0, -2);
const returnedMessage = service.getMessage('message');
expect(mockedMonitoringService.logEvent).toHaveBeenCalled();
expect(returnedMessage).not.toBeNull();
expect(returnedMessage.slice(0, -2)).toBe(expectedMessage);
});

describe('enableCookies()', () => {
it('should make a call to monitoringService', () => {
const service = new LoggerService(mockedMonitoringService, mockedNgxLogger, mockedSessionStorageService,
const service = new LoggerService(mockedNgxLogger, mockedSessionStorageService,
mockedCryptoWrapper, mockEnvironmentService);
service.enableCookies();
expect(mockedMonitoringService.enableCookies).toHaveBeenCalled();
});
});

Expand Down
25 changes: 6 additions & 19 deletions src/app/services/logger/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { environment as config } from '../../../environments/environment';
import { UserInfo } from '../../models/user-details.model';
import { SessionStorageService } from '../session-storage/session-storage.service';
import { CryptoWrapper } from './cryptoWrapper';
import { MonitoringService } from './monitoring.service';
import { EnvironmentService } from '../../shared/services/environment.service';

export interface ILoggerService {
Expand All @@ -26,11 +25,10 @@ export class LoggerService implements ILoggerService {
// Do nothing.
};

constructor(private readonly monitoringService: MonitoringService,
private readonly ngxLogger: NGXLogger,
private readonly sessionStorageService: SessionStorageService,
private readonly cryptoWrapper: CryptoWrapper,
private readonly environmentService: EnvironmentService) {
constructor(private readonly ngxLogger: NGXLogger,
private readonly sessionStorageService: SessionStorageService,
private readonly cryptoWrapper: CryptoWrapper,
private readonly environmentService: EnvironmentService) {
this.COOKIE_KEYS = {
TOKEN: config.cookies.token,
USER: config.cookies.userId
Expand All @@ -46,54 +44,43 @@ export class LoggerService implements ILoggerService {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public trace(message: any, ... additional: any[]): void {
public trace(message: any, ...additional: any[]): void {
const formattedMessage = this.getMessage(message);
this.ngxLogger.trace(formattedMessage);
this.monitoringService.logEvent(message);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public debug(message: any, ...additional: any[]): void {
const formattedMessage = this.getMessage(message);
this.ngxLogger.debug(formattedMessage);
this.monitoringService.logEvent(message);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public info(message: any, ...additional: any[]): void {
const formattedMessage = this.getMessage(message);
this.ngxLogger.info(formattedMessage);
this.monitoringService.logEvent(message);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public log(message: any, ...additional: any[]): void {
const formattedMessage = this.getMessage(message);
this.ngxLogger.log(formattedMessage, ...additional);
this.monitoringService.logEvent(message);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public warn(message: any, ...additional: any[]): void {
const formattedMessage = this.getMessage(message);
this.ngxLogger.warn(formattedMessage);
this.monitoringService.logEvent(message);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public error(message: any, ...additional: any[]): void {
this.ngxLogger.error(message);
const formattedMessage = this.getMessage(message);
const error = new Error(formattedMessage);
this.monitoringService.logException(error);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public fatal(message: any, ...additional: any[]): void {
this.ngxLogger.fatal(message);
const formattedMessage = this.getMessage(message);
const error = new Error(formattedMessage);
this.monitoringService.logException(error);
}

public getMessage(message: any): string {
Expand All @@ -109,7 +96,7 @@ export class LoggerService implements ILoggerService {
}

public enableCookies(): void {
this.monitoringService.enableCookies();
// do nothing.
}

public static switchConsoleLogs(consoleConfig: any): void {
Expand Down
Loading