diff --git a/Common/Types/Date.ts b/Common/Types/Date.ts index e4eabe4971..917498068a 100644 --- a/Common/Types/Date.ts +++ b/Common/Types/Date.ts @@ -8,6 +8,20 @@ import moment from 'moment-timezone'; export const Moment: typeof moment = moment; export default class OneUptimeDate { + + + public getNanoSecondsFromSeconds(seconds: number): number { + return seconds * 1000 * 1000 * 1000; + } + + public getMicroSecondsFromSeconds(seconds: number): number { + return seconds * 1000 * 1000; + } + + public getMilliSecondsFromSeconds(seconds: number): number { + return seconds * 1000; + } + public static getCurrentDateAsUnixNano(): number { return this.toUnixNano(this.getCurrentDate()); } diff --git a/Common/Types/Text.ts b/Common/Types/Text.ts index 33de515591..1dbec2bc87 100644 --- a/Common/Types/Text.ts +++ b/Common/Types/Text.ts @@ -1,4 +1,21 @@ export default class Text { + + + public static convertBase64ToHex(base64: string): string { + + if(!base64) { + return base64; + } + + const raw = Buffer.from(base64, 'base64').toString(); + let result = ''; + 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.toUpperCase(); + } + public static generateRandomText(length?: number): string { if (!length) { length = 10; diff --git a/CommonServer/Utils/OpenTelemetry.ts b/CommonServer/Utils/OpenTelemetry.ts index b8122f91b6..7ab5ab37da 100644 --- a/CommonServer/Utils/OpenTelemetry.ts +++ b/CommonServer/Utils/OpenTelemetry.ts @@ -28,8 +28,6 @@ if ( const otlpEndpoint: string = process.env['OTEL_EXPORTER_OTLP_ENDPOINT']; - logger.info(otlpEndpoint); - sdk = new opentelemetry.NodeSDK({ traceExporter: new OTLPTraceExporter({ url: otlpEndpoint + '/v1/traces', diff --git a/Dashboard/src/Pages/Telemetry/Services/View/Traces/View/Index.tsx b/Dashboard/src/Pages/Telemetry/Services/View/Traces/View/Index.tsx index 3af7c33ee3..249f4ed100 100644 --- a/Dashboard/src/Pages/Telemetry/Services/View/Traces/View/Index.tsx +++ b/Dashboard/src/Pages/Telemetry/Services/View/Traces/View/Index.tsx @@ -161,6 +161,35 @@ const TraceView: FunctionComponent = ( }); }, []); + + const getDivisibilityFactor: Function = (totalTimelineTimeInUnixNano: number): { + divisibilityFactor: number; + intervalUnit: string; + } => { + + let intervalUnit: string = 'ms'; + let divisibilityFactor: number = 1000; // default is in milliseconds + + if(totalTimelineTimeInUnixNano < 1000){ + intervalUnit = 'ns'; + divisibilityFactor = 1; // this is in nanoseconds + } else if(totalTimelineTimeInUnixNano < 1000000){ + intervalUnit = 'μs'; + divisibilityFactor = 1000; // this is in microseconds + } else if(totalTimelineTimeInUnixNano < 1000000000){ + intervalUnit = 'ms'; + divisibilityFactor = 1000000; // this is in microseconds + } else if (totalTimelineTimeInUnixNano < 1000000000000){ + intervalUnit = 's'; + divisibilityFactor = 1000000000; // this is in seconds + } + + return { + divisibilityFactor: divisibilityFactor, + intervalUnit: intervalUnit + }; + } + React.useEffect(() => { // convert spans to gantt chart @@ -185,8 +214,12 @@ const TraceView: FunctionComponent = ( const startTimeline: number = 0; - const divisibilityFactor: number = 1000; // 1000 to convert from nanoseconds to ms - const intervalUnit: string = 'ms'; + const divisibilityFactorAndIntervalUnit: { + divisibilityFactor: number; + intervalUnit: string; + } = getDivisibilityFactor((timelineEndTimeUnixNano - timelineStartTimeUnixNano)); + + const divisibilityFactor: number = divisibilityFactorAndIntervalUnit.divisibilityFactor; const endTimeline: number = (timelineEndTimeUnixNano - timelineStartTimeUnixNano) / @@ -233,7 +266,7 @@ const TraceView: FunctionComponent = ( start: startTimeline, end: Math.ceil(endTimeline / interval) * interval, interval: interval, - intervalUnit: intervalUnit, + intervalUnit: divisibilityFactorAndIntervalUnit.intervalUnit, }, };