Skip to content

Commit c5d7f82

Browse files
authored
runfix: Improve datadog logs (#15031)
1 parent 4868f07 commit c5d7f82

File tree

11 files changed

+58
-45
lines changed

11 files changed

+58
-45
lines changed

src/script/audio/AudioRepository.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ export class AudioRepository {
106106
Object.values(AudioType).forEach(audioId => {
107107
this.audioElements[audioId] = this.createAudioElement(`./audio/${audioId}.mp3`, preload);
108108
});
109-
110-
this.logger.info(`Sounds initialized (preload: '${preload}')`);
111109
}
112110

113111
private stopAll(): void {
@@ -168,7 +166,7 @@ export class AudioRepository {
168166
case AUDIO_PLAY_PERMISSION.ALLOWED:
169167
try {
170168
await this.playAudio(audioElement, playInLoop);
171-
this.logger.info(`Playing sound '${audioId}' (loop: '${playInLoop}')`);
169+
this.logger.log(`Playing sound '${audioId}' (loop: '${playInLoop}')`);
172170
} catch (error) {
173171
this.logger.error(`Failed to play sound '${audioId}': ${error.message}`);
174172
throw error;
@@ -201,7 +199,6 @@ export class AudioRepository {
201199
readonly stop = (audioId: AudioType): void => {
202200
const audioElement = this.getSoundById(audioId);
203201
if (!audioElement?.paused) {
204-
this.logger.info(`Stopping sound '${audioId}'`);
205202
audioElement.pause();
206203
audioElement.load();
207204
}

src/script/auth/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const config = Config.getConfig();
7878
async function runApp() {
7979
const [min, max] = config.SUPPORTED_API_RANGE;
8080
const {domain} = await core.useAPIVersion(min, max, config.ENABLE_DEV_BACKEND_API);
81-
await initializeDataDog(config, domain);
81+
await initializeDataDog(config, {domain: domain});
8282

8383
render(Root);
8484
if (module.hot) {

src/script/client/ClientRepository.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class ClientRepository {
133133
const status = error.response?.status;
134134
const clientNotFoundBackend = status === HTTP_STATUS.NOT_FOUND;
135135
if (clientNotFoundBackend) {
136-
this.logger.warn(`Local client '${clientId}' no longer exists on the backend`, error);
136+
this.logger.warn(`Local client no longer exists on the backend`, error);
137137
throw new ClientError(ClientError.TYPE.NO_VALID_CLIENT, ClientError.MESSAGE.NO_VALID_CLIENT);
138138
}
139139

@@ -246,8 +246,7 @@ export class ClientRepository {
246246
async getValidLocalClient(): Promise<ko.Observable<ClientEntity>> {
247247
try {
248248
const clientEntity = await this.getCurrentClientFromDb();
249-
const clientPayload = await this.getClientByIdFromBackend(clientEntity.id);
250-
this.logger.info(`Client with ID '${clientPayload.id}' (${clientPayload.type}) validated on backend`);
249+
await this.getClientByIdFromBackend(clientEntity.id);
251250
const currentClient = this.clientState.currentClient;
252251

253252
await this.clientService.putClientCapabilities(currentClient().id, {
@@ -374,7 +373,6 @@ export class ClientRepository {
374373
* @returns Resolves with all locally known clients except the current one
375374
*/
376375
async getClientsForSelf(): Promise<ClientEntity[]> {
377-
this.logger.info('Retrieving all clients of the self user from database');
378376
const {domain, id} = this.selfUser();
379377
const clientRecords = await this.getClientByUserIdFromDb({domain, id});
380378
const clientEntities = ClientMapper.mapClients(clientRecords, true, domain);
@@ -444,15 +442,15 @@ export class ClientRepository {
444442
delete clientsFromBackend[clientId];
445443

446444
if (this.clientState.currentClient() && this.isCurrentClient(userId, clientId)) {
447-
this.logger.warn(`Removing duplicate self client '${clientId}' locally`);
445+
this.logger.warn(`Removing duplicate local self client`);
448446
await this.removeClient(userId, clientId);
449447
}
450448

451449
// Locally known client changed on backend
452450
if (wasUpdated) {
453451
// Clear the previous client in DB (in case the domain changes the primary key will also change, thus invalidating the previous client)
454452
await this.clientService.deleteClientFromDb(client.meta.primary_key);
455-
this.logger.info(`Updating client '${clientId}' of user '${userId.id}' locally`);
453+
this.logger.info(`Updating local client`);
456454
promises.push(this.saveClientInDb(userId, client));
457455
continue;
458456
}
@@ -463,7 +461,7 @@ export class ClientRepository {
463461
}
464462

465463
// Locally known client deleted on backend
466-
this.logger.warn(`Removing client '${clientId}' of user '${userId.id}' locally`);
464+
this.logger.warn(`Removing local client`);
467465
await this.removeClient(userId, clientId);
468466
}
469467

@@ -475,7 +473,7 @@ export class ClientRepository {
475473
}
476474

477475
// Locally unknown client new on backend
478-
this.logger.debug(`New client '${clientId}' of user '${userId.id}' will be stored locally`);
476+
this.logger.debug(`New client will be stored locally`);
479477
if (matchQualifiedIds(this.selfUser(), userId)) {
480478
this.onClientAdd({client: clientPayload as RegisteredClient});
481479
}
@@ -541,7 +539,7 @@ export class ClientRepository {
541539
* @param eventJson JSON data of 'user.client-add' event
542540
*/
543541
private onClientAdd(eventJson: Pick<UserClientAddEvent, 'client'>): void {
544-
this.logger.debug('Client of self user added', eventJson);
542+
this.logger.debug('Client of self user added');
545543
amplify.publish(WebAppEvents.CLIENT.ADD, this.selfUser().qualifiedId, eventJson.client, true);
546544
}
547545

src/script/client/ClientService.ts

-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ import type {
2626
import type {QualifiedId} from '@wireapp/api-client/lib/user';
2727
import {container} from 'tsyringe';
2828

29-
import {Logger, getLogger} from 'Util/Logger';
30-
3129
import {APIClient} from '../service/APIClientSingleton';
3230
import type {ClientRecord} from '../storage';
3331
import {StorageService} from '../storage';
3432
import {StorageSchemata} from '../storage/StorageSchemata';
3533

3634
export class ClientService {
37-
private readonly logger: Logger;
3835
private readonly CLIENT_STORE_NAME: string;
3936

4037
static get URL_CLIENTS(): string {
@@ -49,8 +46,6 @@ export class ClientService {
4946
private readonly storageService = container.resolve(StorageService),
5047
private readonly apiClient = container.resolve(APIClient),
5148
) {
52-
this.logger = getLogger('ClientService');
53-
5449
this.CLIENT_STORE_NAME = StorageSchemata.OBJECT_STORE.CLIENTS;
5550
}
5651

@@ -159,11 +154,9 @@ export class ClientService {
159154
}
160155

161156
if (clientRecord === undefined) {
162-
this.logger.info(`Client with primary key '${primaryKey}' not found in database`);
163157
return primaryKey;
164158
}
165159

166-
this.logger.info(`Loaded client record from database '${primaryKey}'`);
167160
return clientRecord;
168161
}
169162

@@ -182,7 +175,6 @@ export class ClientService {
182175
clientPayload.meta.primary_key = primaryKey;
183176

184177
return this.storageService.save(this.CLIENT_STORE_NAME, primaryKey, clientPayload).then(() => {
185-
this.logger.info(`Client '${clientPayload.id}' stored with primary key '${primaryKey}'`);
186178
return clientPayload;
187179
});
188180
}

src/script/conversation/ConversationRepository.ts

+26-7
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ export class ConversationRepository {
489489
const response = await this.conversationService.getConversationById(qualifiedId);
490490
const [conversationEntity] = this.mapConversations([response]);
491491

492-
this.logger.info(`Fetched conversation '${conversationId}' from backend`);
493492
this.saveConversation(conversationEntity);
494493

495494
fetching_conversations[conversationId].forEach(({resolveFn}) => resolveFn(conversationEntity));
@@ -1943,6 +1942,31 @@ export class ConversationRepository {
19431942
// Event callbacks
19441943
//##############################################################################
19451944

1945+
private logConversationEvent(event: IncomingEvent, source: EventSource) {
1946+
if (event.type === CONVERSATION_EVENT.TYPING) {
1947+
// Prevent logging typing events
1948+
return;
1949+
}
1950+
const {time, from, qualified_conversation} = event;
1951+
const extra: Record<string, unknown> = {};
1952+
extra.messageId = 'id' in event && event.id;
1953+
const logMessage = `Conversation Event: '${event.type}' (Source: ${source})`;
1954+
switch (event.type) {
1955+
case ClientEvent.CONVERSATION.ASSET_ADD:
1956+
extra.contentType = event.data.content_type;
1957+
extra.size = event.data.content_length;
1958+
extra.status = event.data.status;
1959+
1960+
case ClientEvent.CONVERSATION.MESSAGE_ADD:
1961+
extra.sender = event.from_client_id;
1962+
break;
1963+
1964+
case ClientEvent.CONVERSATION.MESSAGE_DELETE:
1965+
extra.deletedMessage = event.data.message_id;
1966+
}
1967+
this.logger.info(logMessage, {time, from, qualified_conversation, ...extra});
1968+
}
1969+
19461970
/**
19471971
* Listener for incoming events.
19481972
*
@@ -1951,9 +1975,7 @@ export class ConversationRepository {
19511975
* @returns Resolves when event was handled
19521976
*/
19531977
private readonly onConversationEvent = (event: IncomingEvent, source = EventRepository.SOURCE.STREAM) => {
1954-
const logObject = {eventJson: JSON.stringify(event), eventObject: event};
1955-
const logMessage = `Conversation Event: '${event.type}' (Source: ${source})`;
1956-
this.logger.info(logMessage, logObject);
1978+
this.logConversationEvent(event, source);
19571979
return this.handleConversationEvent(event, source);
19581980
};
19591981

@@ -1975,9 +1997,6 @@ export class ConversationRepository {
19751997
const conversationId: QualifiedId = eventData?.conversationId
19761998
? {domain: '', id: eventData.conversationId}
19771999
: qualified_conversation || {domain: '', id: conversation};
1978-
this.logger.info(
1979-
`Handling event '${type}' in conversation '${conversationId.id}/${conversationId.domain}' (Source: ${eventSource})`,
1980-
);
19812000

19822001
const inSelfConversation = this.conversationState.isSelfConversation(conversationId);
19832002
if (inSelfConversation) {

src/script/conversation/EventBuilder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface BaseEvent {
4242
data?: unknown;
4343
from: string;
4444
id: string;
45+
from_client_id?: string;
4546
qualified_conversation?: QualifiedId;
4647
qualified_from?: QualifiedId;
4748
server_time?: string;

src/script/event/EventRepository.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,9 @@ export class EventRepository {
303303
source = EventRepository.SOURCE.INJECTED;
304304
}
305305

306-
const id = 'id' in event ? event.id : 'ID not specified';
307306
const conversationId = 'conversation' in event && event.conversation;
308307
const inSelfConversation = conversationId === this.userState.self().id;
309308
if (!inSelfConversation) {
310-
this.logger.info(`Injected event ID '${id}' of type '${event.type}' with source '${source}'`);
311309
return this.processEvent(event, source);
312310
}
313311
return undefined;
@@ -362,7 +360,7 @@ export class EventRepository {
362360
return event;
363361
}
364362
case EventValidation.OUTDATED_TIMESTAMP: {
365-
this.logger.info(`Ignored outdated event type: '${event.type}'`);
363+
this.logger.warn(`Ignored outdated event type: '${event.type}'`);
366364
return event;
367365
}
368366
case EventValidation.VALID:

src/script/main/app.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ export class App {
335335
async initApp(clientType: ClientType, onProgress: (progress: number, message?: string) => void) {
336336
// add body information
337337
const [apiVersionMin, apiVersionMax] = this.config.SUPPORTED_API_RANGE;
338-
const {domain} = await this.core.useAPIVersion(apiVersionMin, apiVersionMax, this.config.ENABLE_DEV_BACKEND_API);
339-
await initializeDataDog(this.config, domain);
338+
await this.core.useAPIVersion(apiVersionMin, apiVersionMax, this.config.ENABLE_DEV_BACKEND_API);
340339

341340
const osCssClass = Runtime.isMacOS() ? 'os-mac' : 'os-pc';
342341
const platformCssClass = Runtime.isDesktopApp() ? 'platform-electron' : 'platform-web';
@@ -380,6 +379,7 @@ export class App {
380379
});
381380

382381
const selfUser = await this.initiateSelfUser();
382+
await initializeDataDog(this.config, selfUser.qualifiedId);
383383

384384
onProgress(5, t('initReceivedSelfUser', selfUser.name()));
385385
telemetry.timeStep(AppInitTimingsStep.RECEIVED_SELF_USER);
@@ -462,7 +462,7 @@ export class App {
462462
telemetry.timeStep(AppInitTimingsStep.APP_LOADED);
463463

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

467467
return selfUser;
468468
} catch (error) {

src/script/time/serverTimeHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const serverTimeHandler = {
2525
computeTimeOffset(serverTimeString: string): void {
2626
const timeOffset = Date.now() - new Date(serverTimeString).valueOf();
2727
this.timeOffset(timeOffset);
28-
this.logger.info(`Current backend time is '${serverTimeString}'. Time offset updated to '${this.timeOffset()}' ms`);
28+
this.logger.log(`Current backend time is '${serverTimeString}'. Time offset updated to '${this.timeOffset()}' ms`);
2929
},
3030

3131
getTimeOffset(): number {

src/script/util/DataDog.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const uuidRegex = /([a-z\d]{8})-([a-z\d]{4})-([a-z\d]{4})-([a-z\d]{4})-([a-z\d]{
2323

2424
let isDataDogInitialized = false;
2525

26-
export async function initializeDataDog(config: Configuration, domain?: string) {
26+
export async function initializeDataDog(config: Configuration, user: {id?: string; domain: string}) {
2727
if (isDataDogInitialized) {
2828
return;
2929
}
@@ -37,10 +37,15 @@ export async function initializeDataDog(config: Configuration, domain?: string)
3737
return;
3838
}
3939

40+
const {domain, id: userId} = user ?? {};
41+
4042
const replacer = (_match: string, p1: string) => `${p1}***`;
4143
const truncateDomain = (value: string) => `${value.substring(0, 3)}***`;
4244
const replaceAllStrings = (string: string) => string.replaceAll(uuidRegex, replacer);
4345
const replaceDomains = (string: string) => (domain ? string.replaceAll(domain, truncateDomain(domain)) : string);
46+
const removeColors = (string: string) =>
47+
string.replaceAll(/%c/g, '').replaceAll(/color:[^;]+; font-weight:[^;]+; /g, '');
48+
const removeTimestamp = (string: string) => string.replaceAll(/\[\d+-\d+-\d+ \d+:\d+:\d+\] /g, '');
4449

4550
const {datadogRum} = await import('@datadog/browser-rum');
4651

@@ -72,8 +77,18 @@ export async function initializeDataDog(config: Configuration, domain?: string)
7277
forwardConsoleLogs: ['info', 'warn', 'error'], // For now those logs should be fine, we need to investigate if we need another logs in the future
7378
sessionSampleRate: 100,
7479
beforeSend: log => {
80+
if (log.message.match(/@wireapp\/webapp\/avs/)) {
81+
return false;
82+
}
7583
log.view.url = '/';
76-
log.message = replaceDomains(replaceAllStrings(log.message));
84+
log.message = replaceDomains(replaceAllStrings(removeTimestamp(removeColors(log.message))));
85+
return undefined;
7786
},
7887
});
88+
89+
if (userId) {
90+
const id = userId.substring(0, 8);
91+
datadogRum.setUser({id});
92+
datadogLogs.setUser({id});
93+
}
7994
}

src/script/view_model/WarningsContainer/WarningsState.ts

-7
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ import {WebAppEvents} from '@wireapp/webapp-events';
2424

2525
import {PrimaryModal} from 'Components/Modals/PrimaryModal';
2626
import {t} from 'Util/LocalizerUtil';
27-
import {getLogger} from 'Util/Logger';
2827
import {safeWindowOpen} from 'Util/SanitizationUtil';
2928

3029
import {TYPE} from './WarningsTypes';
3130

3231
import {Config} from '../../Config';
3332
import {PermissionState} from '../../notification/PermissionState';
3433

35-
const logger = getLogger('WarningsViewModel');
36-
3734
type WarningsState = {
3835
name: string;
3936
warnings: TYPE[];
@@ -60,7 +57,6 @@ const hideWarning = (type = getVisibleWarning()) => {
6057
const {warnings, removeWarning} = useWarningsState.getState();
6158
if (warnings.includes(type)) {
6259
removeWarning(type);
63-
logger.info(`Dismissed warning of type '${type}'`);
6460
}
6561
};
6662

@@ -74,8 +70,6 @@ const showWarning = (type: TYPE, info?: {name: string}) => {
7470
hideWarning(visibleWarning);
7571
}
7672

77-
logger.warn(`Showing warning of type '${type}'`);
78-
7973
if (info) {
8074
setName(info.name);
8175
}
@@ -95,7 +89,6 @@ const closeWarning = (): void => {
9589

9690
if (warnings.includes(warningToClose)) {
9791
removeWarning(warningToClose);
98-
logger.info(`Dismissed warning of type '${warningToClose}'`);
9992
}
10093

10194
switch (warningToClose) {

0 commit comments

Comments
 (0)