Skip to content

Commit

Permalink
Merge branch 'main' into dluna/1666-feat-instrument-mongodb-v6
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna authored Nov 10, 2023
2 parents 928b8fc + 2698bb1 commit 141e826
Show file tree
Hide file tree
Showing 72 changed files with 465 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14
registry-url: 'https://registry.npmjs.org'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-all-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Set MySQL variables
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Set MySQL variables
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Cache Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"gcp-metadata": "^5.0.0"
"gcp-metadata": "^6.0.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.34.2",
"@opentelemetry/sdk-node": "^0.44.0",
"@opentelemetry/sdk-node": "^0.45.1",
"@types/mocha": "8.2.3",
"@types/node": "18.6.5",
"@types/semver": "7.5.3",
Expand Down
8 changes: 4 additions & 4 deletions metapackages/auto-instrumentations-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"typescript": "4.4.4"
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.44.0",
"@opentelemetry/instrumentation": "^0.45.1",
"@opentelemetry/instrumentation-amqplib": "^0.33.2",
"@opentelemetry/instrumentation-aws-lambda": "^0.37.1",
"@opentelemetry/instrumentation-aws-sdk": "^0.36.1",
Expand All @@ -64,9 +64,9 @@
"@opentelemetry/instrumentation-fastify": "^0.32.3",
"@opentelemetry/instrumentation-generic-pool": "^0.32.3",
"@opentelemetry/instrumentation-graphql": "^0.35.2",
"@opentelemetry/instrumentation-grpc": "^0.44.0",
"@opentelemetry/instrumentation-grpc": "^0.45.1",
"@opentelemetry/instrumentation-hapi": "^0.33.1",
"@opentelemetry/instrumentation-http": "^0.44.0",
"@opentelemetry/instrumentation-http": "^0.45.1",
"@opentelemetry/instrumentation-ioredis": "^0.35.2",
"@opentelemetry/instrumentation-knex": "^0.32.2",
"@opentelemetry/instrumentation-koa": "^0.36.1",
Expand All @@ -92,6 +92,6 @@
"@opentelemetry/resource-detector-container": "^0.3.2",
"@opentelemetry/resource-detector-gcp": "^0.29.2",
"@opentelemetry/resources": "^1.12.0",
"@opentelemetry/sdk-node": "^0.44.0"
"@opentelemetry/sdk-node": "^0.45.1"
}
}
6 changes: 5 additions & 1 deletion metapackages/auto-instrumentations-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
* limitations under the License.
*/

export { getNodeAutoInstrumentations, InstrumentationConfigMap } from './utils';
export {
getNodeAutoInstrumentations,
getResourceDetectorsFromEnv,
InstrumentationConfigMap,
} from './utils';
9 changes: 5 additions & 4 deletions metapackages/auto-instrumentations-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues"
},
"peerDependencies": {
"@opentelemetry/api": "^1.3.0"
"@opentelemetry/api": "^1.3.0",
"zone.js": "0.11.4"
},
"devDependencies": {
"@babel/core": "7.22.17",
Expand Down Expand Up @@ -59,10 +60,10 @@
"webpack-merge": "5.8.0"
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.44.0",
"@opentelemetry/instrumentation": "^0.45.1",
"@opentelemetry/instrumentation-document-load": "^0.33.2",
"@opentelemetry/instrumentation-fetch": "^0.44.0",
"@opentelemetry/instrumentation-fetch": "^0.45.1",
"@opentelemetry/instrumentation-user-interaction": "^0.33.2",
"@opentelemetry/instrumentation-xml-http-request": "^0.44.0"
"@opentelemetry/instrumentation-xml-http-request": "^0.45.1"
}
}
5 changes: 5 additions & 0 deletions packages/opentelemetry-host-metrics/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export enum METRIC_NAMES {
PROCESS_MEMORY_USAGE = 'process.memory.usage',
}

export enum METRIC_ATTRIBUTES {
SYSTEM_CPU_LOGICAL_NUMBER = 'system.cpu.logical_number',
SYSTEM_CPU_STATE = 'system.cpu.state',
}

export enum CPU_LABELS {
USER = 'user',
SYSTEM = 'system',
Expand Down
43 changes: 23 additions & 20 deletions packages/opentelemetry-host-metrics/src/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,51 @@ export class HostMetrics extends BaseMetrics {
observableResult: api.BatchObservableResult,
cpuUsages: CpuUsageData[]
): void {
const stateAttr = enums.METRIC_ATTRIBUTES.SYSTEM_CPU_STATE;
const cpuAttr = enums.METRIC_ATTRIBUTES.SYSTEM_CPU_LOGICAL_NUMBER;

for (let i = 0, j = cpuUsages.length; i < j; i++) {
const cpuUsage = cpuUsages[i];
observableResult.observe(this._cpuTime, cpuUsage.user, {
state: enums.CPU_LABELS.USER,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.USER,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuTime, cpuUsage.system, {
state: enums.CPU_LABELS.SYSTEM,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.SYSTEM,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuTime, cpuUsage.idle, {
state: enums.CPU_LABELS.IDLE,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.IDLE,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuTime, cpuUsage.interrupt, {
state: enums.CPU_LABELS.INTERRUPT,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.INTERRUPT,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuTime, cpuUsage.nice, {
state: enums.CPU_LABELS.NICE,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.NICE,
[cpuAttr]: cpuUsage.cpuNumber,
});

observableResult.observe(this._cpuUtilization, cpuUsage.userP, {
state: enums.CPU_LABELS.USER,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.USER,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuUtilization, cpuUsage.systemP, {
state: enums.CPU_LABELS.SYSTEM,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.SYSTEM,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuUtilization, cpuUsage.idleP, {
state: enums.CPU_LABELS.IDLE,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.IDLE,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuUtilization, cpuUsage.interruptP, {
state: enums.CPU_LABELS.INTERRUPT,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.INTERRUPT,
[cpuAttr]: cpuUsage.cpuNumber,
});
observableResult.observe(this._cpuUtilization, cpuUsage.niceP, {
state: enums.CPU_LABELS.NICE,
cpu: cpuUsage.cpuNumber,
[stateAttr]: enums.CPU_LABELS.NICE,
[cpuAttr]: cpuUsage.cpuNumber,
});
}
}
Expand Down
49 changes: 32 additions & 17 deletions packages/opentelemetry-host-metrics/src/stats/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,39 @@ const MILLISECOND = 1 / 1e3;
let cpuUsageTime: number | undefined = undefined;

/**
* It returns cpu load delta from last time - to be used with SumObservers.
* When called first time it will return 0 and then delta will be calculated
* We get data as soon as we load the module so the 1st collect
* of the metric already has valuable data to be sent.
*/
let prevOsData: { time: number; cpus: os.CpuInfo[] } = {
time: Date.now(),
cpus: os.cpus(),
};

/**
* For each CPU returned by `os.cpus()` it returns
* - the CPU times in each state (user, sys, ...) in seconds
* - the % of time the CPU was in each state since last measurement
*/
export function getCpuUsageData(): CpuUsageData[] {
if (typeof cpuUsageTime !== 'number') {
cpuUsageTime = new Date().getTime() - process.uptime() * 1000;
}
const currentTime = Date.now();
const timeElapsed = currentTime - prevOsData.time;
const currentOsData = { time: currentTime, cpus: os.cpus() };

const timeElapsed = (new Date().getTime() - cpuUsageTime) / 1000;
const usageData = currentOsData.cpus.map((cpu, cpuNumber) => {
const prevTimes = prevOsData.cpus[cpuNumber].times;
const currTimes = cpu.times;

return os.cpus().map((cpu, cpuNumber) => {
const idle = cpu.times.idle * MILLISECOND;
const user = cpu.times.user * MILLISECOND;
const system = cpu.times.sys * MILLISECOND;
const interrupt = cpu.times.irq * MILLISECOND;
const nice = cpu.times.nice * MILLISECOND;
const idle = currTimes.idle * MILLISECOND;
const user = currTimes.user * MILLISECOND;
const system = currTimes.sys * MILLISECOND;
const interrupt = currTimes.irq * MILLISECOND;
const nice = currTimes.nice * MILLISECOND;

const idleP = idle / timeElapsed;
const userP = user / timeElapsed;
const systemP = system / timeElapsed;
const interruptP = interrupt / timeElapsed;
const niceP = nice / timeElapsed;
const idleP = (currTimes.idle - prevTimes.idle) / timeElapsed;
const userP = (currTimes.user - prevTimes.user) / timeElapsed;
const systemP = (currTimes.sys - prevTimes.sys) / timeElapsed;
const interruptP = (currTimes.irq - prevTimes.irq) / timeElapsed;
const niceP = (currTimes.nice - prevTimes.nice) / timeElapsed;

return {
cpuNumber: String(cpuNumber),
Expand All @@ -59,6 +70,10 @@ export function getCpuUsageData(): CpuUsageData[] {
niceP,
};
});

prevOsData = currentOsData;

return usageData;
}

/**
Expand Down
Loading

0 comments on commit 141e826

Please sign in to comment.