Skip to content

Commit

Permalink
chore: Improve app load logs (#14596)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Feb 1, 2023
1 parent 3a7e2f1 commit a5ed2ae
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 46 deletions.
11 changes: 3 additions & 8 deletions src/script/audio/AudioRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,9 @@ export class AudioRepository {
return;
}
Object.values(this.audioElements).forEach(element => {
element
.setSinkId(currentOutputDevice)
.then(() => {
this.logger.info(`Updated audio element output to: ${currentOutputDevice}`);
})
.catch(error => {
this.logger.warn(error);
});
element.setSinkId?.(currentOutputDevice).catch(error => {
this.logger.warn(error);
});
});
}

Expand Down
8 changes: 3 additions & 5 deletions src/script/client/ClientRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class ClientRepository {

init(selfUser: User): void {
this.selfUser(selfUser);
this.logger.info(`Initialized repository with user ID '${this.selfUser().id}'`);
}

//##############################################################################
Expand Down Expand Up @@ -155,13 +154,12 @@ export class ClientRepository {
})
.then(clientRecord => {
if (typeof clientRecord === 'string') {
this.logger.info('No local client found in database');
this.logger.warn('No local client found in database');
throw new ClientError(ClientError.TYPE.NO_VALID_CLIENT, ClientError.MESSAGE.NO_VALID_CLIENT);
}

const currentClient = ClientMapper.mapClient(clientRecord, true, clientRecord.domain);
this.clientState.currentClient(currentClient);
this.logger.info(`Loaded local client '${currentClient.id}'`, this.clientState.currentClient());
return this.clientState.currentClient();
});
}
Expand Down Expand Up @@ -485,7 +483,7 @@ export class ClientRepository {
}

// Locally unknown client new on backend
this.logger.info(`New client '${clientId}' of user '${userId}' will be stored locally`);
this.logger.debug(`New client '${clientId}' of user '${userId}' will be stored locally`);
if (matchQualifiedIds(this.selfUser(), userId)) {
this.onClientAdd({client: clientPayload as RegisteredClient});
}
Expand Down Expand Up @@ -551,7 +549,7 @@ export class ClientRepository {
* @param eventJson JSON data of 'user.client-add' event
*/
private onClientAdd(eventJson: Pick<UserClientAddEvent, 'client'>): void {
this.logger.info('Client of self user added', eventJson);
this.logger.debug('Client of self user added', eventJson);
amplify.publish(WebAppEvents.CLIENT.ADD, this.selfUser().qualifiedId, eventJson.client, true);
}

Expand Down
19 changes: 9 additions & 10 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,10 @@ export class App {
telemetry.timeStep(AppInitTimingsStep.APP_PRE_LOADED);

userRepository['userState'].self().devices(clientEntities);
this.logger.info('App pre-loading completed');
this._handleUrlParams();
await conversationRepository.updateConversationsOnAppInit();
await conversationRepository.conversationLabelRepository.loadLabels();

telemetry.timeStep(AppInitTimingsStep.APP_LOADED);

telemetry.report();
amplify.publish(WebAppEvents.LIFECYCLE.LOADED);

telemetry.timeStep(AppInitTimingsStep.UPDATED_CONVERSATIONS);
Expand All @@ -457,12 +453,15 @@ export class App {
audioRepository.init(true);
conversationRepository.cleanupConversations();
callingRepository.setReady();
this.logger.info('App fully loaded');
telemetry.timeStep(AppInitTimingsStep.APP_LOADED);

const loadTime = telemetry.report();
this.logger.info(`App loaded within ${loadTime}s for user "${selfUser.id}" and client "${clientEntity().id}"`);

return selfUser;
} catch (error) {
if (error instanceof BaseError) {
this._appInitFailure(error);
await this._appInitFailure(error);
return undefined;
}
throw error;
Expand All @@ -472,11 +471,11 @@ export class App {
/**
* Initialize ServiceWorker if supported.
*/
private initServiceWorker(): void {
private async initServiceWorker() {
if (navigator.serviceWorker) {
navigator.serviceWorker
await navigator.serviceWorker
.register(`/sw.js?${Environment.version(false)}`)
.then(({scope}) => this.logger.info(`ServiceWorker registration successful with scope: ${scope}`));
.then(({scope}) => this.logger.debug(`ServiceWorker registration successful with scope: ${scope}`));
}
}

Expand Down Expand Up @@ -673,7 +672,7 @@ export class App {

const keepConversationInput = signOutReason === SIGN_OUT_REASON.SESSION_EXPIRED;
const deletedKeys = CacheRepository.clearLocalStorage(keepConversationInput, keysToKeep);
this.logger.info(`Deleted "${deletedKeys.length}" keys from localStorage.`, deletedKeys);
this.logger.debug(`Deleted "${deletedKeys.length}" keys from localStorage.`, deletedKeys);
}

if (clearData) {
Expand Down
4 changes: 2 additions & 2 deletions src/script/permission/PermissionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export class PermissionRepository {
return navigator.permissions
.query({name: permissionType as any})
.then(permissionStatus => {
this.logger.log(`Permission state for '${permissionType}' is '${permissionStatus.state}'`);
this.logger.debug(`Permission state for '${permissionType}' is '${permissionStatus.state}'`);
setPermissionState(permissionStatus.state as PermissionStatusState);

permissionStatus.onchange = () => {
this.logger.log(`Permission state for '${permissionType}' changed to '${permissionStatus.state}'`);
this.logger.debug(`Permission state for '${permissionType}' changed to '${permissionStatus.state}'`);
setPermissionState(permissionStatus.state as PermissionStatusState);
};

Expand Down
12 changes: 0 additions & 12 deletions src/script/team/TeamMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ import type {MemberData, TeamData} from '@wireapp/api-client/lib/team/';
import type {TeamUpdateData} from '@wireapp/api-client/lib/team/data/';
import type {PermissionsData} from '@wireapp/api-client/lib/team/member/PermissionsData';

import {Logger, getLogger} from 'Util/Logger';

import {TeamEntity} from './TeamEntity';
import {TeamMemberEntity} from './TeamMemberEntity';

import type {User} from '../entity/User';
import {roleFromTeamPermissions} from '../user/UserPermission';

export class TeamMapper {
private readonly logger: Logger;

constructor() {
this.logger = getLogger('TeamMapper');
}

mapTeamFromObject(data: TeamData, teamEntity?: TeamEntity): TeamEntity {
return this.updateTeamFromObject(data, teamEntity);
}
Expand Down Expand Up @@ -81,10 +73,6 @@ export class TeamMapper {
mapRole(userEntity: User, permissions?: PermissionsData): void {
if (permissions) {
const teamRole = roleFromTeamPermissions(permissions);
this.logger.info(
`Identified user '${userEntity.id}' of team '${userEntity.teamId}' as '${teamRole}'`,
permissions,
);
userEntity.teamRole(teamRole);
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/script/telemetry/app_init/AppInitTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
*
*/

import {Logger, getLogger} from 'Util/Logger';

import {AppInitStatistics, AppStatistics} from './AppInitStatistics';
import type {AppInitStatisticsValue} from './AppInitStatisticsValue';
import {AppInitTimings} from './AppInitTimings';
import type {AppInitTimingsStep} from './AppInitTimingsStep';

export class AppInitTelemetry {
private readonly logger: Logger;
private readonly timings: AppInitTimings;
private readonly statistics: AppInitStatistics;

constructor() {
this.logger = getLogger('AppInitTelemetry');
this.timings = new AppInitTimings();
this.statistics = new AppInitStatistics();
}
Expand All @@ -51,12 +47,11 @@ export class AppInitTelemetry {
this.timings.log();
}

report(): void {
const segmentations = this.getStatistics();
segmentations.loading_time = this.timings.getAppLoad();
this.logger.info(`App version '${segmentations.app_version}' initialized within ${segmentations.loading_time}s`);
report(): number {
this.logStatistics();
this.logTimings();

return this.timings.getAppLoad();
}

timeStep(step: AppInitTimingsStep): void {
Expand Down
2 changes: 1 addition & 1 deletion src/script/telemetry/app_init/AppInitTimings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class AppInitTimings {
const appLoaded = this.timings[AppInitTimingsStep.APP_LOADED];
const appLoadedInSeconds = appLoaded / TIME_IN_MILLIS.SECOND;

return (Math.floor(appLoadedInSeconds / AppInitTimings.CONFIG.BUCKET_SIZE) + 1) * AppInitTimings.CONFIG.BUCKET_SIZE;
return Math.floor(appLoadedInSeconds);
}

log() {
Expand Down

0 comments on commit a5ed2ae

Please sign in to comment.