Browse Source

fix: add logs about sending websocket events to clients

Karol Sójko 1 year ago
parent
commit
9465f2ecd8

+ 4 - 0
packages/auth/src/Infra/WebSockets/WebSocketsClientService.ts

@@ -5,12 +5,14 @@ import { DomainEventFactoryInterface } from '../../Domain/Event/DomainEventFacto
 import { User } from '../../Domain/User/User'
 import { ClientServiceInterface } from '../../Domain/Client/ClientServiceInterface'
 import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
+import { Logger } from 'winston'
 
 @injectable()
 export class WebSocketsClientService implements ClientServiceInterface {
   constructor(
     @inject(TYPES.Auth_DomainEventFactory) private domainEventFactory: DomainEventFactoryInterface,
     @inject(TYPES.Auth_DomainEventPublisher) private domainEventPublisher: DomainEventPublisherInterface,
+    @inject(TYPES.Auth_Logger) private logger: Logger,
   ) {}
 
   async sendUserRolesChangedEvent(user: User): Promise<void> {
@@ -20,6 +22,8 @@ export class WebSocketsClientService implements ClientServiceInterface {
       (await user.roles).map((role) => role.name),
     )
 
+    this.logger.info(`[WebSockets] Requesting message ${event.type} to user ${user.uuid}`)
+
     await this.domainEventPublisher.publish(
       this.domainEventFactory.createWebSocketMessageRequestedEvent({
         userUuid: user.uuid,

+ 1 - 0
packages/syncing-server/src/Bootstrap/Container.ts

@@ -554,6 +554,7 @@ export class ContainerConfigLoader {
         new SendEventToClient(
           container.get<DomainEventFactoryInterface>(TYPES.Sync_DomainEventFactory),
           container.get<DomainEventPublisherInterface>(TYPES.Sync_DomainEventPublisher),
+          container.get<Logger>(TYPES.Sync_Logger),
         ),
       )
     container

+ 6 - 1
packages/syncing-server/src/Domain/UseCase/Syncing/SendEventToClient/SendEventToClient.spec.ts

@@ -5,14 +5,19 @@ import {
 } from '@standardnotes/domain-events'
 import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
 import { SendEventToClient } from './SendEventToClient'
+import { Logger } from 'winston'
 
 describe('SendEventToClient', () => {
   let domainEventFactory: DomainEventFactoryInterface
   let domainEventPublisher: DomainEventPublisherInterface
+  let logger: Logger
 
-  const createUseCase = () => new SendEventToClient(domainEventFactory, domainEventPublisher)
+  const createUseCase = () => new SendEventToClient(domainEventFactory, domainEventPublisher, logger)
 
   beforeEach(() => {
+    logger = {} as jest.Mocked<Logger>
+    logger.info = jest.fn()
+
     domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
     domainEventFactory.createWebSocketMessageRequestedEvent = jest
       .fn()

+ 4 - 0
packages/syncing-server/src/Domain/UseCase/Syncing/SendEventToClient/SendEventToClient.ts

@@ -3,11 +3,13 @@ import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
 
 import { SendEventToClientDTO } from './SendEventToClientDTO'
 import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
+import { Logger } from 'winston'
 
 export class SendEventToClient implements UseCaseInterface<void> {
   constructor(
     private domainEventFactory: DomainEventFactoryInterface,
     private domainEventPublisher: DomainEventPublisherInterface,
+    private logger: Logger,
   ) {}
 
   async execute(dto: SendEventToClientDTO): Promise<Result<void>> {
@@ -17,6 +19,8 @@ export class SendEventToClient implements UseCaseInterface<void> {
     }
     const userUuid = userUuidOrError.getValue()
 
+    this.logger.info(`[WebSockets] Requesting message ${dto.event.type} to user ${dto.userUuid}`)
+
     const event = this.domainEventFactory.createWebSocketMessageRequestedEvent({
       userUuid: userUuid.value,
       message: JSON.stringify(dto.event),