diff --git a/package-lock.json b/package-lock.json index a14147b85a..97f0a27af3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32709,9 +32709,9 @@ } }, "node_modules/systeminformation": { - "version": "5.22.7", - "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.22.7.tgz", - "integrity": "sha512-AWxlP05KeHbpGdgvZkcudJpsmChc2Y5Eo/GvxG/iUA/Aws5LZKHAMSeAo+V+nD+nxWZaxrwpWcnx4SH3oxNL3A==", + "version": "5.22.9", + "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.22.9.tgz", + "integrity": "sha512-qUWJhQ9JSBhdjzNUQywpvc0icxUAjMY3sZqUoS0GOtaJV9Ijq8s9zEP8Gaqmymn1dOefcICyPXK1L3kgKxlUpg==", "os": [ "darwin", "linux", @@ -36628,7 +36628,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/sdk-metrics": "^1.8.0", - "systeminformation": "^5.22.7" + "systeminformation": "5.22.9" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -46594,7 +46594,7 @@ "nyc": "15.1.0", "rimraf": "5.0.5", "sinon": "15.2.0", - "systeminformation": "^5.22.7", + "systeminformation": "5.22.9", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, @@ -67864,9 +67864,9 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" }, "systeminformation": { - "version": "5.22.7", - "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.22.7.tgz", - "integrity": "sha512-AWxlP05KeHbpGdgvZkcudJpsmChc2Y5Eo/GvxG/iUA/Aws5LZKHAMSeAo+V+nD+nxWZaxrwpWcnx4SH3oxNL3A==" + "version": "5.22.9", + "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.22.9.tgz", + "integrity": "sha512-qUWJhQ9JSBhdjzNUQywpvc0icxUAjMY3sZqUoS0GOtaJV9Ijq8s9zEP8Gaqmymn1dOefcICyPXK1L3kgKxlUpg==" }, "table-layout": { "version": "3.0.2", diff --git a/packages/opentelemetry-host-metrics/global.d.ts b/packages/opentelemetry-host-metrics/global.d.ts new file mode 100644 index 0000000000..19cc54f99a --- /dev/null +++ b/packages/opentelemetry-host-metrics/global.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +declare module 'systeminformation/lib/network' { + export { networkStats } from 'systeminformation'; +} diff --git a/packages/opentelemetry-host-metrics/package.json b/packages/opentelemetry-host-metrics/package.json index 2f9a0b169a..1e5401c557 100644 --- a/packages/opentelemetry-host-metrics/package.json +++ b/packages/opentelemetry-host-metrics/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@opentelemetry/sdk-metrics": "^1.8.0", - "systeminformation": "^5.22.7" + "systeminformation": "5.22.9" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-host-metrics#readme" } \ No newline at end of file diff --git a/packages/opentelemetry-host-metrics/src/stats/common.ts b/packages/opentelemetry-host-metrics/src/stats/common.ts index 7b709f00e3..341d4ee2a7 100644 --- a/packages/opentelemetry-host-metrics/src/stats/common.ts +++ b/packages/opentelemetry-host-metrics/src/stats/common.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { cpus, totalmem, freemem } from 'os'; -import type { CpuInfo } from 'os'; +import { cpus, totalmem, freemem } from 'node:os'; +import type { CpuInfo } from 'node:os'; import type { CpuUsageData, MemoryData, ProcessCpuUsageData } from '../types'; const MILLISECOND = 1 / 1e3; diff --git a/packages/opentelemetry-host-metrics/src/stats/si.ts b/packages/opentelemetry-host-metrics/src/stats/si.ts index 71c6c8c285..3d1aaabef3 100644 --- a/packages/opentelemetry-host-metrics/src/stats/si.ts +++ b/packages/opentelemetry-host-metrics/src/stats/si.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { networkStats } from 'systeminformation'; + +// Import from the network file directly as bundlers trigger the 'osx-temperature-sensor' import in the systeminformation/lib/cpu.js, +// resulting in the following warning: "Can't resolve 'osx-temperature-sensor'" +// See https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2071 +import { networkStats } from 'systeminformation/lib/network'; import type { Systeminformation } from 'systeminformation'; export function getNetworkData() { diff --git a/packages/opentelemetry-host-metrics/test/metric.test.ts b/packages/opentelemetry-host-metrics/test/metric.test.ts index 6ff9a24b4c..3ff5600cac 100644 --- a/packages/opentelemetry-host-metrics/test/metric.test.ts +++ b/packages/opentelemetry-host-metrics/test/metric.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as SI from 'systeminformation'; +import * as Network from 'systeminformation/lib/network'; import type { Systeminformation } from 'systeminformation'; import { Attributes } from '@opentelemetry/api'; import { @@ -26,7 +26,7 @@ import { MetricReader, } from '@opentelemetry/sdk-metrics'; import * as assert from 'assert'; -import * as os from 'os'; +import * as os from 'node:os'; import * as sinon from 'sinon'; import { ATTRIBUTE_NAMES } from '../src/enum'; import { HostMetrics } from '../src'; @@ -140,7 +140,7 @@ describe('Host Metrics', () => { sandbox .stub(process.memoryUsage, 'rss') .callsFake(mockedProcess.memoryUsage.rss); - sandbox.stub(SI, 'networkStats').callsFake(mockedSI.networkStats); + sandbox.stub(Network, 'networkStats').callsFake(mockedSI.networkStats); reader = new TestMetricReader(); diff --git a/packages/opentelemetry-host-metrics/tsconfig.json b/packages/opentelemetry-host-metrics/tsconfig.json index e5f9ff1579..73128b74c5 100644 --- a/packages/opentelemetry-host-metrics/tsconfig.json +++ b/packages/opentelemetry-host-metrics/tsconfig.json @@ -6,6 +6,7 @@ }, "include": [ "src/**/*.ts", - "test/**/*.ts" + "test/**/*.ts", + "global.d.ts" ] } \ No newline at end of file