send direct message

This commit is contained in:
Peter Maquiran
2024-08-20 16:34:47 +01:00
parent 4fb24f7875
commit 59fc19879f
41 changed files with 912 additions and 308 deletions
+103
View File
@@ -1,5 +1,11 @@
// import { DateUtils } from './date';
import { environment } from "src/environments/environment";
import { openTelemetryLogging } from "../../monitoring/opentelemetry/logging";
import { SessionStore } from "src/app/store/session.service";
import { DeviceInfo } from "@capacitor/device";
import { Device } from '@capacitor/device';
export type MessageType = {
message: string;
context?: string;
@@ -15,6 +21,12 @@ function getCurrentTime() {
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
}
let device: DeviceInfo;
Device.getInfo().then(e => {
device = e
});
export class Logger {
constructor() {}
@@ -25,6 +37,25 @@ export class Logger {
'color: #00897B', // CSS Style
Object.assign(obj, { createdAt: getCurrentTime(), message })
);
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
openTelemetryLogging.send({
type: 'graylog',
spanContext: null,
payload: {
message: message,
object: {
...obj,
spanId: null,
name,
user: SessionStore?.user?.FullName,
device_name: device?.name || device?.model,
commit_date: environment.version.lastCommitTime,
}
}
})
}
}
static debug(message: string, obj = {}): void {
@@ -33,6 +64,24 @@ export class Logger {
'color: #039BE5', // CSS Style
Object.assign(obj, {createdAt: getCurrentTime(), message })
);
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
openTelemetryLogging.send({
type: 'graylog',
spanContext: null,
payload: {
message: message,
object: {
...obj,
spanId: null,
name,
user: SessionStore?.user?.FullName,
device_name: device?.name || device?.model,
commit_date: environment.version.lastCommitTime,
}
}
})
}
}
static info(message: string, obj = {}): void {
@@ -44,6 +93,24 @@ export class Logger {
obj,
'\n',
);
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
openTelemetryLogging.send({
type: 'graylog',
spanContext: null,
payload: {
message: message,
object: {
...obj,
spanId: null,
name,
user: SessionStore?.user?.FullName,
device_name: device?.name || device?.model,
commit_date: environment.version.lastCommitTime,
}
}
})
}
}
static warn(message: string, obj = {}): void {
@@ -55,6 +122,24 @@ export class Logger {
obj,
'\n',
);
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
openTelemetryLogging.send({
type: 'graylog',
spanContext: null,
payload: {
message: message,
object: {
...obj,
spanId: null,
name,
user: SessionStore?.user?.FullName,
device_name: device?.name || device?.model,
commit_date: environment.version.lastCommitTime,
}
}
})
}
}
static error(message?: string, obj = {}): void {
@@ -67,6 +152,24 @@ export class Logger {
obj,
'\n',
);
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
openTelemetryLogging.send({
type: 'graylog',
spanContext: null,
payload: {
message: message,
object: {
...obj,
spanId: null,
name,
user: SessionStore?.user?.FullName,
device_name: device?.name || device?.model,
commit_date: environment.version.lastCommitTime,
}
}
})
}
}
fatal(error?: any, message?: string, context?: string): void {}
@@ -1,7 +1,7 @@
import { v4 as uuidv4 } from 'uuid';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { Tracer, Span } from '@opentelemetry/sdk-trace-base';
import { OpentelemetryAgendaProvider, OpentelemetryInterceptorProvider, OpentelemetryLogging, OpentelemetryNotificationProvider } from './opentelemetry';
import { OpentelemetryAgendaProvider, OpentelemetryChatProvider, OpentelemetryInterceptorProvider, OpentelemetryLogging, OpentelemetryNotificationProvider } from './opentelemetry';
import { Device, DeviceInfo } from '@capacitor/device';
import { SessionStore } from 'src/app/store/session.service';
import { environment } from 'src/environments/environment';
@@ -12,7 +12,7 @@ import {
} from '@opentelemetry/api';
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
const tracerNotificationInstance = OpentelemetryNotificationProvider.getTracer('example-tracer-hole', '111', {})
const tracerChat = OpentelemetryChatProvider.getTracer('OpentelemetryChatProvider','some' ,{})
let device: DeviceInfo;
Device.getInfo().then(e => {
@@ -45,6 +45,8 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
if(module == 'notification') {
_tracerInstance = tracerNotificationInstance
} else if (module == 'chat') {
_tracerInstance = tracerChat
} else {
_tracerInstance = tracerInstance
}
@@ -184,6 +186,9 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true,
return result
} catch (e) {
tracing.setAttribute('catch', 'true')
tracing.log("cath", {
error: e
})
if(autoFinish) {
setTimeout(tracing.finish , daley)
@@ -226,6 +231,9 @@ export function XTracer({ name, bugPrint, module, autoFinish = true, daley =0 })
} catch (e) {
tracing.setAttribute('catch', 'true')
tracing.log("cath", {
error: e
})
if(autoFinish) {
setTimeout(tracing.finish , daley)