monitoring notifications

This commit is contained in:
Peter Maquiran
2024-06-20 15:40:08 +01:00
parent 2d6d5a9492
commit 9ea120bfcd
17 changed files with 279 additions and 347 deletions
@@ -50,7 +50,7 @@ export class AgendaDataRepositoryService {
try {
const result = await this.agendaDataService.getEvent(id).pipe(
map((response) => {
APINODReturn(EventOutputDTOSchema, response, 'get/Events/${id}', tracing)
APINODReturn(EventOutputDTOSchema, response, `get/Events/${id}`, tracing)
return EventMapper.toDomain(response)
})
).toPromise()
@@ -78,7 +78,7 @@ export class AgendaDataRepositoryService {
try {
const result = await this.agendaDataService.getEvent(id).pipe(
map((response) => {
APINODReturn(EventOutputDTOSchema, response, 'get/Events/${id}', tracing)
APINODReturn(EventOutputDTOSchema, response, `get/Events/${id}`, tracing)
console.log('response',response)
console.log('ToDomain',EventToApproveDetailsMapper.toDomain(response))
return EventToApproveDetailsMapper.toDomain(response)
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { NotificationRepositoryService } from './notification-repository.service';
describe('NotificationRepositoryService', () => {
let service: NotificationRepositoryService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(NotificationRepositoryService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class NotificationRepositoryService {
constructor() { }
}
@@ -3,6 +3,7 @@ import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { Tracer, Span } from '@opentelemetry/sdk-trace-base';
import { OpentelemetryAgendaProvider, OpentelemetryInterceptorProvider, OpentelemetryNotificationProvider } from './opentelemetry';
import { Device, DeviceInfo } from '@capacitor/device';
import { SessionStore } from 'src/app/store/session.service';
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
@@ -58,9 +59,7 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
span.setAttribute(key, value);
},
finish: () => {
if(!window.location.origin.includes('https')) {
span.end();
}
span.end();
if(bugPrint && hasBug) {
console.error(name, data)
@@ -87,6 +86,7 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
tracing.setAttribute('User', SessionStore?.user?.FullName);
tracing.setAttribute('current.page', window.location.pathname);
tracing.setAttribute('device.name', device?.name || device?.model)
@@ -95,11 +95,17 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true
try {
const result = await originalMethod.apply(this, args);
tracing.finish()
if(autoFinish) {
tracing.finish()
}
return result
} catch (e) {
tracing.setAttribute('catch', 'true')
tracing.finish()
if(autoFinish) {
tracing.finish()
}
console.error(e);
return false
}
@@ -119,6 +125,7 @@ export function XTracer({ name, bugPrint, module, autoFinish = true }) {
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
tracing.setAttribute('User', SessionStore?.user?.FullName);
tracing.setAttribute('current.page', window.location.pathname);
tracing.setAttribute('device.name', device?.name || device?.model)
@@ -127,12 +134,18 @@ export function XTracer({ name, bugPrint, module, autoFinish = true }) {
try {
const result = originalMethod.apply(this, args);
tracing.finish()
if(autoFinish) {
tracing.finish()
}
return result
} catch (e) {
tracing.setAttribute('catch', 'true')
tracing.finish()
if(autoFinish) {
tracing.finish()
}
console.error(e);
return false
}
+93 -52
View File
@@ -18,7 +18,22 @@ import { ChatService } from 'src/app/services/chat.service';
import { FCM } from '@capacitor-community/fcm';
import { ChatSystemService } from './chat/chat-system.service';
import {ChatController} from 'src/app/controller/chat'
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { TracingType, XTracer, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { z } from 'zod';
const notificationDataSchema = z.object({
Service: z.string(),
IdObject: z.string().optional(),
Object: z.string().optional(),
FolderId: z.string().optional(),
});
const notificationSchema = z.object({
notification: z.object({
data: notificationDataSchema,
}),
});
@Injectable({
providedIn: 'root'
})
@@ -105,6 +120,8 @@ export class NotificationsService {
if (this.platform.is('mobile')) {
if (!this.isPushNotificationsAvailable) {
tracing.setAttribute('notification.available', 'false')
tracing.setAttribute('outcome', 'failed')
return false
}
if (this.platform.is('ios')) {
@@ -143,11 +160,13 @@ export class NotificationsService {
this.token = token
tracing.setAttribute('notification.token', 'true')
tracing.setAttribute('outcome', 'success')
tracing.finish()
},
(error) => {
console.error('Permission denied:', error);
tracing.setAttribute('notification.token', 'false')
tracing.setAttribute('outcome', 'failed')
tracing.finish()
}
);
}
@@ -343,69 +362,91 @@ export class NotificationsService {
}
notificatinsRoutes = (notification) => {
@XTracer({name:'Notification/notificatinsRoutes', bugPrint: true, module:'notification'})
notificatinsRoutes (notification, tracing?: TracingType) {
console.log('BACK BACK', notification)
try {
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
console.log('BACK BACK', notification)
this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
}
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diploma-revisao") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
} else if (notification.notification.data.Service === "chat") {
let navigationExtras: NavigationExtras = { queryParams: { "roomId": notification.notification.data.IdObject, } };
if (window.location.search.includes("roomId")) {
this.zone.run(() => this.router.navigate(['/home/chat']));
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
}
setTimeout(() => {
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
}, 200);
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diploma-revisao") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
} else if (notification.notification.data.Service === "chat") {
let navigationExtras: NavigationExtras = { queryParams: { "roomId": notification.notification.data.IdObject, } };
if (window.location.search.includes("roomId")) {
this.zone.run(() => this.router.navigate(['/home/chat']));
}
setTimeout(() => {
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
}, 200);
} else {
tracing.setAttribute('notification.route', 'false')
tracing.setAttribute('outcome', 'failed')
tracing.setAttribute('parameters', JSON.stringify(notification))
}
} catch (error) {
const validationError = notificationSchema.safeParse(notification)
if(!validationError.success) {
const errors: z.ZodError<any> = (validationError as any).error;
console.log("Validation errors:", errors.issues);
tracing.setAttribute('parameters', JSON.stringify(notification))
tracing.setAttribute('validation.errors', JSON.stringify(errors.issues))
}
tracing.setAttribute('outcome', 'failed')
tracing.setAttribute('parameters', JSON.stringify(notification))
tracing.setAttribute('error', JSON.stringify(error))
}