diff --git a/CommonServer/API/StatusAPI.ts b/CommonServer/API/StatusAPI.ts index 845dde8f77..51efee7441 100644 --- a/CommonServer/API/StatusAPI.ts +++ b/CommonServer/API/StatusAPI.ts @@ -19,35 +19,30 @@ export default class StatusAPI { public static statusCheckSuccessCounter = Telemetry.getCounter({ name: 'status.check.success', description: 'Status check counter', - labels: {}, }); // ready counter public static stausReadySuccess = Telemetry.getCounter({ name: 'status.ready.success', description: 'Ready check counter', - labels: {}, }); // live counter public static stausLiveSuccess = Telemetry.getCounter({ name: 'status.live.success', description: 'Live check counter', - labels: {}, }); // ready failed counter public static stausReadyFailed = Telemetry.getCounter({ name: 'status.ready.failed', description: 'Ready check counter', - labels: {}, }); // live failed counter public static stausLiveFailed = Telemetry.getCounter({ name: 'status.live.failed', description: 'Live check counter', - labels: {}, }); public static init(options: StatusAPIOptions): ExpressRouter { diff --git a/CommonServer/Utils/Telemetry.ts b/CommonServer/Utils/Telemetry.ts index 28ce1bd4ff..c877bc4c5f 100644 --- a/CommonServer/Utils/Telemetry.ts +++ b/CommonServer/Utils/Telemetry.ts @@ -5,19 +5,21 @@ import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; import { AWSXRayIdGenerator } from '@opentelemetry/id-generator-aws-xray'; -import { Meter, MeterProvider } from '@opentelemetry/metrics'; import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base'; import { Resource } from '@opentelemetry/resources'; import { BatchLogRecordProcessor, LoggerProvider, } from '@opentelemetry/sdk-logs'; -import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; +import { PeriodicExportingMetricReader, MeterProvider } from '@opentelemetry/sdk-metrics'; import * as opentelemetry from '@opentelemetry/sdk-node'; import { SpanExporter } from '@opentelemetry/sdk-trace-node'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import URL from 'Common/Types/API/URL'; import Dictionary from 'Common/Types/Dictionary'; +import OpenTelemetryAPI, { Meter } from '@opentelemetry/api'; + + // Enable this line to see debug logs // diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); @@ -27,8 +29,8 @@ const serviceName: string = process.env['SERVICE_NAME'] || 'oneuptime'; export default class Telemetry { public static sdk: opentelemetry.NodeSDK | null = null; public static logger: Logger | null = null; - public static meter: Meter | null = null; + public static meterProvider: MeterProvider | null = null; public static getHeaders(): Dictionary { if (!process.env['OPENTELEMETRY_EXPORTER_OTLP_HEADERS']) { @@ -189,9 +191,18 @@ export default class Telemetry { return this.logger!; } + public static getMeterProvider(): MeterProvider { + if (!this.meterProvider) { + this.meterProvider = new MeterProvider(); + OpenTelemetryAPI.metrics.setGlobalMeterProvider(this.meterProvider); + } + + return this.meterProvider; + } + public static getMeter(): Meter { if (!this.meter) { - this.meter = new MeterProvider().getMeter(serviceName); + this.meter = OpenTelemetryAPI.metrics.getMeter('default'); } return this.meter; @@ -200,16 +211,12 @@ export default class Telemetry { public static getCounter(data: { name: string; description: string; - labels: Dictionary; }): Counter { - const { name, description, labels } = data; - - const counter = this.getMeter().createCounter(name, { description }); - - if (labels && Object.keys(labels).length > 0) { - counter.bind(labels); - } + const { name, description } = data; + const counter = this.getMeter().createCounter(name, { + description: description, + }); return counter; } } diff --git a/Ingestor/API/OTelIngest.ts b/Ingestor/API/OTelIngest.ts index 8ebbf4efbf..9f95cafd64 100644 --- a/Ingestor/API/OTelIngest.ts +++ b/Ingestor/API/OTelIngest.ts @@ -316,7 +316,7 @@ router.post( const metricDescription: string = metric[ 'description' ] as string; - + if ( metric['sum'] && (metric['sum'] as JSONObject)['dataPoints'] &&