Add telemetry initialization for each service

This commit is contained in:
Simon Larsen 2024-02-23 13:50:47 +00:00
parent dfbf9a827f
commit f8810d0711
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
8 changed files with 107 additions and 67 deletions

View File

@ -3,6 +3,12 @@ import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import Telemetry from 'CommonUI/src/Utils/Telemetry';
Telemetry.init({
serviceName: 'Accounts',
});
const root: any = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);

View File

@ -2,7 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
// import 'the-new-css-reset/css/reset.css';
import Telemetry from 'CommonUI/src/Utils/Telemetry';
Telemetry.init({
serviceName: 'AdminDashboard',
});
const root: any = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement

View File

@ -8,13 +8,8 @@ export default class Text {
return textInBase64;
}
const raw: string = Buffer.from(textInBase64, 'base64').toString();
let result: string = '';
for (let i: number = 0; i < raw.length; i++) {
const hex: string = raw.charCodeAt(i).toString(16);
result += hex.length === 2 ? hex : '0' + hex;
}
return result;
const hex: string = Buffer.from(textInBase64, 'base64').toString('hex');
return hex;
}
public static isBase64(text: string): boolean {

View File

@ -20,7 +20,7 @@ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
import { Logger, logs } from '@opentelemetry/api-logs';
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
export default class OneUptimeTelemetry {
export default class Telemetry {
public static sdk: opentelemetry.NodeSDK | null = null;
public static logger: Logger | null = null;
@ -187,6 +187,6 @@ export default class OneUptimeTelemetry {
}
}
OneUptimeTelemetry.init({
Telemetry.init({
serviceName: process.env['SERVICE_NAME'] || 'oneuptime',
});

View File

@ -15,37 +15,43 @@ import {
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
const providerConfig: TracerConfig = {
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'my-react-app',
}),
};
export default class Telemetry {
public static init(data: {
serviceName: string;
}): void {
const provider: WebTracerProvider = new WebTracerProvider(providerConfig);
if (OpenTelemetryExporterOtlpEndpoint) {
// we will use ConsoleSpanExporter to check the generated spans in dev console
// provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
const providerConfig: TracerConfig = {
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: data.serviceName,
}),
};
if (OpenTelemetryExporterOtlpEndpoint) {
provider.addSpanProcessor(
new BatchSpanProcessor(
new OTLPTraceExporter({
url:
OpenTelemetryExporterOtlpEndpoint?.toString() +
'/v1/traces',
headers: OpenTelemetryExporterOtlpHeaders,
})
)
);
const provider: WebTracerProvider = new WebTracerProvider(providerConfig);
provider.addSpanProcessor(
new BatchSpanProcessor(
new OTLPTraceExporter({
url:
OpenTelemetryExporterOtlpEndpoint?.toString() +
'/v1/traces',
headers: OpenTelemetryExporterOtlpHeaders,
})
)
);
provider.register({
contextManager: new ZoneContextManager(),
});
registerInstrumentations({
instrumentations: [
new FetchInstrumentation(),
new XMLHttpRequestInstrumentation(),
],
});
}
}
}
provider.register({
contextManager: new ZoneContextManager(),
});
registerInstrumentations({
instrumentations: [
new FetchInstrumentation(),
new XMLHttpRequestInstrumentation(),
],
});

View File

@ -2,7 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import 'CommonUI/src/Utils/Telemetry';
import Telemetry from 'CommonUI/src/Utils/Telemetry';
Telemetry.init({
serviceName: 'Dashboard',
});
const root: any = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement

View File

@ -8,7 +8,7 @@ import ObjectID from 'Common/Types/ObjectID';
import Navigation from 'CommonUI/src/Utils/Navigation';
import ListResult from 'CommonUI/src/Utils/BaseDatabase/ListResult';
import Span from 'Model/AnalyticsModels/Span';
import ModelAPI from 'CommonUI/src/Utils/AnalyticsModelAPI/AnalyticsModelAPI';
import AnalyticsModelAPI from 'CommonUI/src/Utils/AnalyticsModelAPI/AnalyticsModelAPI';
import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax';
import SortOrder from 'Common/Types/BaseDatabase/SortOrder';
import API from 'CommonUI/src/Utils/API/API';
@ -18,10 +18,17 @@ import SpanUtil from '../../../../../../Utils/SpanUtil';
import OneUptimeDate from 'Common/Types/Date';
import Color from 'Common/Types/Color';
import DashboardLogsViewer from '../../../../../../Components/LogsViewer/LogsViewer';
import Select from 'CommonUI/src/Utils/BaseDatabase/Select';
import TelemetryService from 'Model/Models/TelemetryService';
import ModelAPI from 'CommonUI/src/Utils/ModelAPI/ModelAPI';
import DashboardNavigation from '../../../../../../Utils/Navigation';
const TraceView: FunctionComponent<PageComponentProps> = (
_props: PageComponentProps
): ReactElement => {
const [telemetryServices, setTelemetryServices] = React.useState<TelemetryService[]>([]);
const [selectedSpans, setSelectedSpans] = React.useState<string[]>([]);
const oneuptimeSpanId: ObjectID = Navigation.getLastParamAsObjectID(0);
@ -45,20 +52,42 @@ const TraceView: FunctionComponent<PageComponentProps> = (
// get trace with this id and then get all the parentSpanId with this traceid.
const parentSpan: Span | null = await ModelAPI.getItem<Span>({
const telemetryServices = await ModelAPI.getList<TelemetryService>({
query: {
projectId: DashboardNavigation.getProjectId()!
},
limit: LIMIT_PER_PROJECT,
skip: 0,
modelType: TelemetryService,
sort: {
name: SortOrder.Ascending
},
select: {
name: true,
_id: true
}
});
setTelemetryServices(telemetryServices.data);
const select: Select<Span> = {
startTime: true,
endTime: true,
startTimeUnixNano: true,
endTimeUnixNano: true,
name: true,
traceId: true,
parentSpanId: true,
spanId: true,
kind: true,
serviceId: true,
};
const parentSpan: Span | null = await AnalyticsModelAPI.getItem<Span>({
id: oneuptimeSpanId,
modelType: Span,
select: {
startTime: true,
endTime: true,
startTimeUnixNano: true,
endTimeUnixNano: true,
name: true,
traceId: true,
parentSpanId: true,
spanId: true,
kind: true,
},
select: select,
});
if (parentSpan === null) {
@ -73,19 +102,9 @@ const TraceView: FunctionComponent<PageComponentProps> = (
setTraceId(traceId);
const childSpans: ListResult<Span> = await ModelAPI.getList<Span>({
const childSpans: ListResult<Span> = await AnalyticsModelAPI.getList<Span>({
modelType: Span,
select: {
startTime: true,
endTime: true,
startTimeUnixNano: true,
endTimeUnixNano: true,
name: true,
traceId: true,
parentSpanId: true,
spanId: true,
kind: true,
},
select: select,
query: {
traceId: traceId,
},
@ -254,7 +273,7 @@ const TraceView: FunctionComponent<PageComponentProps> = (
return {
id: span.spanId!,
title: span.name!,
description: span.spanId!,
description: telemetryServices.find((service) => service._id && service._id.toString() === span.serviceId?.toString())?.name || '',
};
}),
onBarSelectChange(barIds: Array<string>) {

View File

@ -3,6 +3,12 @@ import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import Telemetry from 'CommonUI/src/Utils/Telemetry';
Telemetry.init({
serviceName: 'StatusPage',
});
const root: any = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);