Skip to content

Commit

Permalink
chore: initialize datadog as soon as possible (#17656)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Jun 26, 2024
1 parent c3fc92c commit 40b01af
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ export class App {
onProgress(2.5);
telemetry.timeStep(AppInitTimingsStep.RECEIVED_ACCESS_TOKEN);

const selfUser = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]);

await initializeDataDog(this.config, selfUser.qualifiedId);
onProgress(5, t('initReceivedSelfUser', selfUser.name()));

try {
await this.core.init(clientType);
} catch (error) {
Expand All @@ -384,7 +389,7 @@ export class App {
userRepository.addClientToUser(userId, newClient, true);
});

const selfUser = await this.initiateSelfUser();
await this.initiateSelfUser(selfUser);

const localClient = await this.core.getLocalClient();
if (!localClient) {
Expand All @@ -403,8 +408,6 @@ export class App {
},
});

await initializeDataDog(this.config, selfUser.qualifiedId);

// Setup all event middleware
const eventStorageMiddleware = new EventStorageMiddleware(this.service.event, selfUser);
const serviceMiddleware = new ServiceMiddleware(conversationRepository, userRepository, selfUser);
Expand All @@ -423,7 +426,6 @@ export class App {
const federationEventProcessor = new FederationEventProcessor(eventRepository, serverTimeHandler, selfUser);
eventRepository.setEventProcessors([federationEventProcessor]);

onProgress(5, t('initReceivedSelfUser', selfUser.name()));
telemetry.timeStep(AppInitTimingsStep.RECEIVED_SELF_USER);
const clientEntity = await this._initiateSelfUserClients(selfUser, clientRepository);
callingRepository.initAvs(selfUser, clientEntity.id);
Expand Down Expand Up @@ -612,20 +614,18 @@ export class App {
* Initiate the self user by getting it from the backend.
* @returns Resolves with the self user entity
*/
private async initiateSelfUser() {
const userEntity = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]);

if (!userEntity.hasActivatedIdentity()) {
if (!userEntity.isTemporaryGuest()) {
private async initiateSelfUser(selfUser: User) {
if (!selfUser.hasActivatedIdentity()) {
if (!selfUser.isTemporaryGuest()) {
throw new Error('User does not have an activated identity');
}
}

container.resolve(StorageService).init(this.core.storage);
this.repository.client.init(userEntity);
await this.repository.properties.init(userEntity);
this.repository.client.init(selfUser);
await this.repository.properties.init(selfUser);

return userEntity;
return selfUser;
}

/**
Expand Down

0 comments on commit 40b01af

Please sign in to comment.