mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
monit notification
This commit is contained in:
@@ -30,4 +30,5 @@ function createProvider(serviceName) {
|
||||
// Example usage:
|
||||
export const OpentelemetryChatProvider = createProvider('FO-chat-service');
|
||||
export const OpentelemetryAgendaProvider = createProvider('FO-agenda-service');
|
||||
export const OpentelemetryNotificationProvider = createProvider('FO-notification');
|
||||
export const OpentelemetryPublicationProvider = createProvider('FO-publication-service');
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
||||
import { Tracer, Span } from '@opentelemetry/sdk-trace-base';
|
||||
import { OpentelemetryAgendaProvider } from './opentelemetry';
|
||||
import { OpentelemetryAgendaProvider, OpentelemetryNotificationProvider } from './opentelemetry';
|
||||
import { Device, DeviceInfo } from '@capacitor/device';
|
||||
|
||||
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
|
||||
const tracerNotificationInstance = OpentelemetryNotificationProvider.getTracer('example-tracer-hole', '111', {})
|
||||
|
||||
})
|
||||
// const logger: ILoggerAdapter = new ColoredLoggerService()
|
||||
|
||||
let device: DeviceInfo;
|
||||
@@ -16,7 +16,64 @@ Device.getInfo().then(e => {
|
||||
device = e
|
||||
});
|
||||
|
||||
export function XTracerAsync({ name, log, bugPrint }: any, p0?: any) {
|
||||
|
||||
const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingType => {
|
||||
const requestId = uuidv4()
|
||||
|
||||
let _tracerInstance:Tracer
|
||||
|
||||
if(module == 'notification') {
|
||||
_tracerInstance = tracerNotificationInstance
|
||||
} else {
|
||||
_tracerInstance = tracerInstance
|
||||
}
|
||||
|
||||
const span = _tracerInstance.startSpan(name);
|
||||
let hasBug:Boolean
|
||||
|
||||
const data = {
|
||||
event: {},
|
||||
tags: {}
|
||||
}
|
||||
|
||||
return {
|
||||
span: span as any,
|
||||
tracer: tracerInstance,
|
||||
tracerId: requestId,
|
||||
attributes: SemanticAttributes,
|
||||
setStatus: (status: any) => {
|
||||
span.setStatus(status);
|
||||
},
|
||||
addEvent: (context: string, message?: any, obj?: any) => {
|
||||
|
||||
data.event[context] = message;
|
||||
|
||||
const value = [JSON.stringify(message)] as any
|
||||
span.addEvent(context, value);
|
||||
},
|
||||
LocalLogEvent:(context: string, message: any, obj: any) => {
|
||||
data.tags[context] = message;
|
||||
},
|
||||
setAttribute: (key: string, value: string) => {
|
||||
data.tags[key] = value;
|
||||
span.setAttribute(key, value);
|
||||
},
|
||||
finish: () => {
|
||||
span.end();
|
||||
if(bugPrint && hasBug) {
|
||||
console.error(name, data)
|
||||
}
|
||||
},
|
||||
bugFlag:() => {
|
||||
hasBug = true
|
||||
},
|
||||
createSpan: (name, parent?: any) => {
|
||||
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function XTracerAsync({ name, log, bugPrint, module = null, autoFinish = true }) {
|
||||
return (
|
||||
target: unknown,
|
||||
propertyKey: string,
|
||||
@@ -25,55 +82,9 @@ export function XTracerAsync({ name, log, bugPrint }: any, p0?: any) {
|
||||
const originalMethod = descriptor.value;
|
||||
descriptor.value = async function (...args: unknown[]) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
const span = tracerInstance.startSpan(name);
|
||||
let hasBug:Boolean
|
||||
|
||||
const data = {
|
||||
event: {},
|
||||
tags: {}
|
||||
}
|
||||
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
|
||||
|
||||
const createTracingInstance = (): TracingType => {
|
||||
|
||||
return {
|
||||
span: span as any,
|
||||
tracer: tracerInstance,
|
||||
tracerId: requestId,
|
||||
attributes: SemanticAttributes,
|
||||
setStatus: (status: any) => {
|
||||
span.setStatus(status);
|
||||
},
|
||||
addEvent: (context: string, message?: any, obj?: any) => {
|
||||
|
||||
data.event[context] = message;
|
||||
|
||||
const value = [JSON.stringify(message)] as any
|
||||
span.addEvent(context, value);
|
||||
},
|
||||
LocalLogEvent:(context: string, message: any, obj: any) => {
|
||||
data.tags[context] = message;
|
||||
},
|
||||
setAttribute: (key: string, value: string) => {
|
||||
data.tags[key] = value;
|
||||
span.setAttribute(key, value);
|
||||
},
|
||||
finish: () => {
|
||||
span.end();
|
||||
if(bugPrint && hasBug) {
|
||||
console.error(name, data)
|
||||
}
|
||||
},
|
||||
bugFlag:() => {
|
||||
hasBug = true
|
||||
},
|
||||
createSpan: (name, parent?: any) => {
|
||||
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tracing = createTracingInstance()
|
||||
tracing.setAttribute('current.page', window.location.pathname);
|
||||
tracing.setAttribute('device.name', device?.name || device?.model)
|
||||
|
||||
@@ -83,16 +94,17 @@ export function XTracerAsync({ name, log, bugPrint }: any, p0?: any) {
|
||||
const result = await originalMethod.apply(this, args);
|
||||
|
||||
if(!window.location.origin.includes('https')) {
|
||||
tracing.finish()
|
||||
if(autoFinish) {
|
||||
tracing.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
} catch (e) {
|
||||
|
||||
|
||||
if(!window.location.origin.includes('https')) {
|
||||
tracing.finish()
|
||||
if(autoFinish) {
|
||||
tracing.finish()
|
||||
}
|
||||
}
|
||||
console.error(e);
|
||||
return false
|
||||
@@ -102,7 +114,7 @@ export function XTracerAsync({ name, log, bugPrint }: any, p0?: any) {
|
||||
}
|
||||
|
||||
|
||||
export function XTracer({name, log, bugPrint}: any) {
|
||||
export function XTracer({ name, log, bugPrint, module, autoFinish = true }: any) {
|
||||
return (
|
||||
target: unknown,
|
||||
propertyKey: string,
|
||||
@@ -111,56 +123,8 @@ export function XTracer({name, log, bugPrint}: any) {
|
||||
const originalMethod = descriptor.value;
|
||||
descriptor.value = function (...args: unknown[]) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
const span = tracerInstance.startSpan(name);
|
||||
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
|
||||
|
||||
let hasBug:Boolean
|
||||
|
||||
const data = {
|
||||
event: {},
|
||||
tags: {}
|
||||
}
|
||||
|
||||
const createTracingInstance = (): TracingType => {
|
||||
|
||||
return {
|
||||
span: span as any,
|
||||
tracer: tracerInstance,
|
||||
tracerId: requestId,
|
||||
attributes: SemanticAttributes,
|
||||
setStatus: (status: any) => {
|
||||
span.setStatus(status);
|
||||
},
|
||||
addEvent: (context: string, message?: any, obj?: any) => {
|
||||
|
||||
data.event[context] = message;
|
||||
|
||||
const value = [JSON.stringify(message)] as any
|
||||
span.addEvent(context, value);
|
||||
},
|
||||
LocalLogEvent:(context: string, message: any, obj: any) => {
|
||||
data.tags[context] = message;
|
||||
},
|
||||
setAttribute: (key: string, value: string) => {
|
||||
data.tags[key] = value;
|
||||
span.setAttribute(key, value);
|
||||
},
|
||||
finish: () => {
|
||||
span.end();
|
||||
if(bugPrint && hasBug) {
|
||||
console.error(name, data)
|
||||
}
|
||||
},
|
||||
bugFlag:() => {
|
||||
hasBug = true
|
||||
},
|
||||
createSpan: (name, parent?: any) => {
|
||||
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tracing = createTracingInstance()
|
||||
tracing.setAttribute('current.page', window.location.pathname);
|
||||
tracing.setAttribute('device.name', device?.name || device?.model)
|
||||
|
||||
@@ -169,15 +133,12 @@ export function XTracer({name, log, bugPrint}: any) {
|
||||
try {
|
||||
const result = originalMethod.apply(this, args);
|
||||
|
||||
|
||||
if(!window.location.origin.includes('https')) {
|
||||
tracing.finish()
|
||||
}
|
||||
|
||||
return result
|
||||
} catch (e) {
|
||||
|
||||
|
||||
if(!window.location.origin.includes('https')) {
|
||||
tracing.finish()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user