add telemetry

This commit is contained in:
Peter Maquiran
2024-10-29 16:00:19 +01:00
parent 0c6fa3118e
commit eedb66a1cf
11 changed files with 110 additions and 34 deletions
@@ -1,10 +1,8 @@
import { Injectable } from '@angular/core';
import { object, z } from 'zod';
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
import { MessageRemoteDataSourceService } from '../../../../module/chat/data/repository/message/message-remote-data-source.service';
import { MessageSocketRepositoryService } from '../../../../module/chat/data/repository/message/message-live-signalr-data-source.service';
import { z } from 'zod';
import { IMessageSocketRepository } from '../../repository/message/message-socket-repository';
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { zodSafeValidation } from 'src/app/utils/zodValidation';
const MessageReactionInputDTOSchema = z.object({
memberId: z.number(),
@@ -25,8 +23,23 @@ export class MessageReactionUseCaseService {
public repository: IMessageSocketRepository
) { }
@ValidateSchema(MessageReactionInputDTOSchema)
execute(input: MessageReactionInput) {
return this.repository.reactToMessageSocket(input)
@XTracerAsync({name:'MessageReactionUseCaseService', module:'chat', bugPrint: true, waitNThrow: 5000})
async execute(input: MessageReactionInput, tracing?: TracingType) {
const validation = zodSafeValidation<MessageReactionInput>(MessageReactionInputDTOSchema, input)
if(validation.isOk()) {
const result = await this.repository.reactToMessageSocket(input)
// console.log('result', result)
return result
} else {
tracing.hasError('invalid input', {
error: validation.error
})
}
}
}
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { FirebasePushNotificationService } from 'src/app/module/notification/data/datasource/firebase-push-notification.service';
import { NotificationLive } from 'src/app/module/notification/data/dto/NotificationLiveOutputDTO';
import { NotificationMapper } from 'src/app/module/notification/domain/mapper/notificationMapper';
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import {
SpanStatus, SpanStatusCode
} from '@opentelemetry/api';
@Injectable({
providedIn: 'root'
})
export class NotificationReceiveService {
constructor(
private FirebasePushNotificationService: FirebasePushNotificationService,
) { }
@XTracerAsync({name:'NotificationReceiveService', module:'notification', bugPrint: true})
async execute(func:Function,tracing?: TracingType) {
const notificationSubject: Subject<NotificationLive> = new Subject<NotificationLive>();
this.FirebasePushNotificationService.onReceiveForeground(async (data)=> {
try {
func(NotificationMapper(data));
} catch (error) {
const NewTracing = tracing.newTracer({name:'NotificationReceiveService-item-error'})
NewTracing.setAttribute('notification-item-error', 'true')
NewTracing.hasError('NotificationMapper', {
notificationData: data
})
NewTracing.log('invalid notification', data);
NewTracing.finish()
}
})
return notificationSubject
}
}
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subject, timer } from 'rxjs';
import { Platform } from '@ionic/angular';
import { SignalRConnection, SocketMessage } from './signalR';
import { SignalRConnection } from './signalR';
import { Plugins } from '@capacitor/core';
import { switchMap } from 'rxjs/operators';
import { err, Result } from 'neverthrow';
@@ -11,7 +11,7 @@ import { MessageCreateOutPutDataDTO, MessageInputDTO } from '../../../../../core
import { MessageMarkAsReadInput } from '../../../../../core/chat/usecase/message/message-mark-as-read-use-case.service';
import { MessageOutPutDataDTO } from 'src/app/core/chat/repository/dto/messageOutputDTO';
import { MessageDeleteInputDTO } from '../../../../../core/chat/usecase/message/message-delete-by-id-live-use-case.service';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
interface sendDeliverAt {
memberId: number,
@@ -140,13 +140,17 @@ export class MessageSocketRepositoryService implements IMessageSocketRepository
reactToMessageSocket(data: MessageReactionInput) {
this.socket.sendData({
data['requestId'] = InstanceId +'@'+ uuidv4();
return this.socket.sendData({
method: 'ReactMessage',
data
})
}
updateMessage(input: MessageUpdateInput) {
input['requestId'] = InstanceId +'@'+ uuidv4();
this.socket.sendData({
method: 'EditMessage',
data: input,
@@ -2,12 +2,12 @@ import { Injectable } from '@angular/core';
import { liveQuery } from 'Dexie';
import { MessageEntity } from '../../../../../core/chat/entity/message';
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
import { Observable as DexieObservable, PromiseExtended } from 'Dexie';
import { PromiseExtended } from 'Dexie';
import { DexieMessageTable, MessageTable, MessageTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/message';
import { chatDatabase } from 'src/app/infra/database/dexie/instance/chat/service';
import { IDirectMessages, IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
import { BehaviorSubject, combineLatest, from, Observable, Subject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { combineLatest, from, Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { v4 as uuidv4 } from 'uuid'
import { err, ok } from 'neverthrow';
@@ -8,9 +8,8 @@ import { NotificationListMapper } from '../domain/mapper/notificationListMapper'
import { NotificationTable } from './infra/db/notification.db';
import { Observable, Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { NotificationMapper } from '../domain/mapper/notificationMapper';
import { NotificationLive } from './dto/NotificationLiveOutputDTO';
import { NotificationReceiveService } from 'src/app/core/notification/use-case/notification-receive.service'
@Injectable({
providedIn: 'root'
})
@@ -21,16 +20,15 @@ export class NotificationRepositoryService {
constructor(
private RemoteNotificationService: RemoteNotificationService,
private FirebasePushNotificationService: FirebasePushNotificationService,
private LocalNotificationService: LocalNotificationService
private LocalNotificationService: LocalNotificationService,
private NotificationReceiveService: NotificationReceiveService
) {
this.FirebasePushNotificationService.onReceiveForeground(async (data)=> {
this.notificationSubject.next(NotificationMapper(data));
this.NotificationReceiveService.execute((data) => {
console.log('FirebasePushNotificationService', data)
this.init()
this.init();
})
if(SessionStore.user.UserId) {
this.init()
}
@@ -165,6 +165,9 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish, waitNThrow =
},
createSpan: (name, parent?: any) => {
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
},
newTracer({bugPrint = false, name, autoFinish =false, waitNThrow = 0}) {
return createTracingInstance({bugPrint, name, module, autoFinish, waitNThrow})
}
}
@@ -285,6 +288,7 @@ export type TracingType = {
finish: () => void;
hasError:(message: string, obj?: Object) => void;
createSpan:(name, parent?: any) => Span;
newTracer:({name, bugPrint, autoFinish, daley, waitNThrow}: {name:string, bugPrint?:any, autoFinish?:any, daley?:any, waitNThrow?:any}) => TracingType;
};
export interface UserInteraction {
@@ -61,35 +61,46 @@ export class TaskDetailsPage implements OnInit {
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 10)
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 100)
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 500)
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 1000)
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 2000)
@@ -97,7 +108,9 @@ export class TaskDetailsPage implements OnInit {
setTimeout(() => {
console.log('change', this.task.Note);
// this.task.Note = this.sanitizeHtml(this.task.Note) as any
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
if(this.text.nativeElement) {
(this.text.nativeElement as HTMLDivElement).innerHTML = this.decode(this.task.Note)
}
}, 4000)
+1 -1
View File
@@ -89,7 +89,7 @@
<span *ngIf="room.lastMessageAudio" class="item-files-title font-13-em"> audio </span>
<fa-icon *ngIf="room?.messages?.[0]?.attachments[0]?.mimeType == 'application/meeting'" icon="calendar-alt" class="file-icon" [class.set-active-item-font-to-white]="room.$id == selectedRoomId"></fa-icon>
<fa-icon *ngIf="room.lastMessageImage" icon="image"></fa-icon>
<span class="pl-2 font-13-em add-ellipsis" *ngIf="!room.lastMessageAudio">{{ room.messages[0].attachments[0].description }}</span>
<span class="pl-2 font-13-em add-ellipsis" *ngIf="!room.lastMessageAudio && !room.lastMessageImage">{{ room.messages[0].attachments[0].description }}</span>
</div>
<!-- <div class="item-files" *ngIf="room.attachments">