mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
improve profile reactiveness and action page performance
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { HttpClient, HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
||||
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ok, err, Result } from 'neverthrow';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { TracingType } from './monitoring/opentelemetry/tracer';
|
||||
|
||||
|
||||
export type HTTPOptions = {
|
||||
headers?: HttpHeaders
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -10,10 +16,10 @@ export class HttpService {
|
||||
|
||||
constructor(private http:HttpClient) { }
|
||||
|
||||
async post<T>(url: string, body: any, tracing?: TracingType): Promise<Result<T, HttpErrorResponse>> {
|
||||
async post<T>(url: string, body: any, options:HTTPOptions ={}, tracing?: TracingType): Promise<Result<T, HttpErrorResponse>> {
|
||||
|
||||
try {
|
||||
const result = await this.http.post(url, body).toPromise()
|
||||
const result = await this.http.post(url, body, options).toPromise()
|
||||
return ok (result as T)
|
||||
} catch (e) {
|
||||
return err(e as HttpErrorResponse)
|
||||
@@ -42,11 +48,9 @@ export class HttpService {
|
||||
if(isHttpError(e)) {
|
||||
tracing?.setAttribute('status.code', e.status.toString())
|
||||
if (e.status == 400) {
|
||||
tracing?.bugFlag()
|
||||
tracing?.setAttribute('outcome', 'failed')
|
||||
}
|
||||
} else {
|
||||
tracing?.bugFlag()
|
||||
tracing.setAttribute('outcome', 'failed')
|
||||
tracing?.setAttribute('map.error', 'true')
|
||||
tracing?.setAttribute('map.error.context', JSON.stringify(e))
|
||||
|
||||
@@ -84,4 +84,4 @@ function childSpanExample(parentContext) {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
parentSpanExample()
|
||||
// parentSpanExample()
|
||||
|
||||
@@ -8,7 +8,9 @@ import { environment } from 'src/environments/environment';
|
||||
import { UseCaseCounter } from './matrix';
|
||||
import { openTelemetryLogging } from './logging';
|
||||
// import { context, propagation } from '@opentelemetry/api';
|
||||
|
||||
import {
|
||||
SpanStatus, SpanStatusCode
|
||||
} from '@opentelemetry/api';
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
|
||||
const tracerNotificationInstance = OpentelemetryNotificationProvider.getTracer('example-tracer-hole', '111', {})
|
||||
// const logger: ILoggerAdapter = new ColoredLoggerService()
|
||||
@@ -53,15 +55,16 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
|
||||
const data = {
|
||||
event: {},
|
||||
tags: {}
|
||||
tags: {},
|
||||
status: {} as any,
|
||||
}
|
||||
|
||||
return {
|
||||
const returnObject = {
|
||||
span: span as any,
|
||||
tracer: tracerInstance,
|
||||
tracerId: requestId,
|
||||
attributes: SemanticAttributes,
|
||||
setStatus: (status: any) => {
|
||||
setStatus: (status: SpanStatus) => {
|
||||
span.setStatus(status);
|
||||
},
|
||||
addEvent: (context: string, message?: any, obj?: any) => {
|
||||
@@ -79,7 +82,7 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
span.setAttribute(key, value);
|
||||
|
||||
if(key =='outcome' && value == 'failed') {
|
||||
span.setAttribute('error', 'true')
|
||||
returnObject.hasError('error')
|
||||
}
|
||||
},
|
||||
log(message: string, data: Object) {
|
||||
@@ -110,18 +113,25 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
finish: () => {
|
||||
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
|
||||
span.end();
|
||||
UseCaseCounter.add(1, {user: SessionStore?.user?.FullName, outcome:data.tags['outcome'], usecase: name})
|
||||
UseCaseCounter.add(1, {user: SessionStore?.user?.FullName, outcome:data.tags['outcome'] || data.status?.code , usecase: name})
|
||||
}
|
||||
|
||||
if(bugPrint && data.tags['outcome'] == 'failed') {
|
||||
if(bugPrint && (data.tags['outcome'] == 'failed' || data.status?.code == SpanStatusCode.ERROR)) {
|
||||
console.error(name, data)
|
||||
}
|
||||
},
|
||||
bugFlag:() => {},
|
||||
hasError:(message: string) => {
|
||||
if(data.status?.code != SpanStatusCode.ERROR) {
|
||||
data.status = {code: SpanStatusCode.ERROR, message}
|
||||
span.setStatus({code: SpanStatusCode.ERROR, message})
|
||||
span.setAttribute('outcome','failed')
|
||||
}
|
||||
},
|
||||
createSpan: (name, parent?: any) => {
|
||||
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
|
||||
}
|
||||
}
|
||||
return returnObject
|
||||
}
|
||||
|
||||
export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true, daley =0 }) {
|
||||
@@ -221,7 +231,7 @@ export type TracingType = {
|
||||
getAttribute: (key: string) => string;
|
||||
LocalLogEvent: (name: string, attributesOrStartTime: any, obj?:any) => void;
|
||||
finish: () => void;
|
||||
bugFlag:() => void;
|
||||
hasError:(message: string) => void;
|
||||
createSpan:(name, parent?: any) => Span;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user