From 2a8b082d9ccb4091d66bfddf363813ff3687cbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:08:32 +0100 Subject: [PATCH 1/3] feat: use GA version of metrics Update host-metrics to use the GA version of metrics SDK and no longer use api-metrics. Remove metrics packages from experimental OTel renovate config. --- packages/opentelemetry-host-metrics/package.json | 9 ++++----- packages/opentelemetry-host-metrics/src/BaseMetrics.ts | 5 ++--- packages/opentelemetry-host-metrics/src/metric.ts | 2 +- packages/opentelemetry-host-metrics/test/metric.test.ts | 4 ++-- renovate.json | 9 ++++++++- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/opentelemetry-host-metrics/package.json b/packages/opentelemetry-host-metrics/package.json index 374c7a6beb..4c5612b125 100644 --- a/packages/opentelemetry-host-metrics/package.json +++ b/packages/opentelemetry-host-metrics/package.json @@ -43,10 +43,10 @@ "access": "public" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.3.0" }, "devDependencies": { - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.3.0", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/sinon": "10.0.2", @@ -59,9 +59,8 @@ "typescript": "4.3.5" }, "dependencies": { - "@opentelemetry/api-metrics": "^0.32.0", - "@opentelemetry/core": "^1.0.0", - "@opentelemetry/sdk-metrics": "^0.32.0", + "@opentelemetry/core": "^1.8.0", + "@opentelemetry/sdk-metrics": "^1.8.0", "systeminformation": "^5.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-host-metrics#readme" diff --git a/packages/opentelemetry-host-metrics/src/BaseMetrics.ts b/packages/opentelemetry-host-metrics/src/BaseMetrics.ts index 6bc4774f43..e859a5f7cf 100644 --- a/packages/opentelemetry-host-metrics/src/BaseMetrics.ts +++ b/packages/opentelemetry-host-metrics/src/BaseMetrics.ts @@ -15,7 +15,6 @@ */ import * as api from '@opentelemetry/api'; -import * as apiMetrics from '@opentelemetry/api-metrics'; import * as metrics from '@opentelemetry/sdk-metrics'; import { VERSION } from './version'; @@ -45,7 +44,7 @@ const DEFAULT_NAME = 'opentelemetry-host-metrics'; export abstract class BaseMetrics { protected _logger = api.diag; protected _maxTimeoutUpdateMS: number; - protected _meter: apiMetrics.Meter; + protected _meter: api.Meter; private _name: string; constructor(config: MetricsCollectorConfig) { @@ -53,7 +52,7 @@ export abstract class BaseMetrics { this._maxTimeoutUpdateMS = config.maxTimeoutUpdateMS || DEFAULT_MAX_TIMEOUT_UPDATE_MS; const meterProvider = - config.meterProvider! || apiMetrics.metrics.getMeterProvider(); + config.meterProvider! || api.metrics.getMeterProvider(); if (!config.meterProvider) { this._logger.warn('No meter provider, using default'); } diff --git a/packages/opentelemetry-host-metrics/src/metric.ts b/packages/opentelemetry-host-metrics/src/metric.ts index 11ea1ed910..3dae2efbe4 100644 --- a/packages/opentelemetry-host-metrics/src/metric.ts +++ b/packages/opentelemetry-host-metrics/src/metric.ts @@ -15,7 +15,7 @@ */ import { BaseMetrics } from './BaseMetrics'; -import * as api from '@opentelemetry/api-metrics'; +import * as api from '@opentelemetry/api'; import * as enums from './enum'; import { getCpuUsageData, getMemoryData } from './stats/common'; diff --git a/packages/opentelemetry-host-metrics/test/metric.test.ts b/packages/opentelemetry-host-metrics/test/metric.test.ts index 9c16815aac..85888dc949 100644 --- a/packages/opentelemetry-host-metrics/test/metric.test.ts +++ b/packages/opentelemetry-host-metrics/test/metric.test.ts @@ -15,7 +15,7 @@ */ const SI = require('systeminformation'); -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; import { AggregationTemporality, DataPoint, @@ -33,7 +33,7 @@ const cpuJson = require('./mocks/cpu.json'); const networkJson = require('./mocks/network.json'); class TestMetricReader extends MetricReader { - public selectAggregationTemporality(): AggregationTemporality { + public override selectAggregationTemporality(): AggregationTemporality { return AggregationTemporality.CUMULATIVE; } protected async onForceFlush(): Promise {} diff --git a/renovate.json b/renovate.json index fea5254ddb..d8b54711fc 100644 --- a/renovate.json +++ b/renovate.json @@ -14,7 +14,14 @@ }, { "groupName": "Otel Core experimental", - "matchPackageNames": ["@opentelemetry/sdk-node", "@opentelemetry/instrumentation", "@opentelemetry/instrumentation-grpc", "@opentelemetry/instrumentation-http", "@opentelemetry/instrumentation-fetch", "@opentelemetry/instrumentation-xml-http-request", "@opentelemetry/api-metrics", "@opentelemetry/sdk-metrics" ], + "matchPackageNames": [ + "@opentelemetry/instrumentation", + "@opentelemetry/instrumentation-grpc", + "@opentelemetry/instrumentation-http", + "@opentelemetry/instrumentation-fetch", + "@opentelemetry/instrumentation-xml-http-request", + "@opentelemetry/sdk-node" + ], "rangeStrategy": "bump" } ], From 15ccbe12ec63c33fc22c4929308e122f070443a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Mon, 14 Nov 2022 11:39:18 +0100 Subject: [PATCH 2/3] chore: use MetricsAttributes => Attributes --- packages/opentelemetry-host-metrics/test/metric.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-host-metrics/test/metric.test.ts b/packages/opentelemetry-host-metrics/test/metric.test.ts index 85888dc949..72a1395ca5 100644 --- a/packages/opentelemetry-host-metrics/test/metric.test.ts +++ b/packages/opentelemetry-host-metrics/test/metric.test.ts @@ -15,7 +15,7 @@ */ const SI = require('systeminformation'); -import { MetricAttributes } from '@opentelemetry/api'; +import { Attributes } from '@opentelemetry/api'; import { AggregationTemporality, DataPoint, @@ -231,7 +231,7 @@ async function getRecords( function ensureValue( metric: MetricData, - attributes: MetricAttributes, + attributes: Attributes, value: number ) { const attrHash = hashAttributes(attributes); @@ -247,7 +247,7 @@ function ensureValue( assert.strictEqual(aggValue, value); } -function hashAttributes(attributes: MetricAttributes) { +function hashAttributes(attributes: Attributes) { return Object.entries(attributes) .sort(([a], [b]) => { return a < b ? -1 : 1; From c60100a77a0d153f2786ff4001aaf0cd68e92b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Mon, 14 Nov 2022 11:39:45 +0100 Subject: [PATCH 3/3] chore: remove unused dependency --- packages/opentelemetry-host-metrics/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/opentelemetry-host-metrics/package.json b/packages/opentelemetry-host-metrics/package.json index 4c5612b125..7c924a7f30 100644 --- a/packages/opentelemetry-host-metrics/package.json +++ b/packages/opentelemetry-host-metrics/package.json @@ -59,7 +59,6 @@ "typescript": "4.3.5" }, "dependencies": { - "@opentelemetry/core": "^1.8.0", "@opentelemetry/sdk-metrics": "^1.8.0", "systeminformation": "^5.0.0" },