From d0fc194ace159bbcd56cf9c452348ab148fd09c4 Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Fri, 23 Feb 2024 18:03:09 +0900 Subject: [PATCH 1/3] Fix the usage example (#1949) KnexInstrumentationConfig is just a type --- plugins/node/opentelemetry-instrumentation-knex/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index 189185be87..05537459cc 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -22,7 +22,7 @@ npm install --save @opentelemetry/instrumentation-knex ## Usage ```js -const { KnexInstrumentation, KnexInstrumentationConfig } = require('@opentelemetry/instrumentation-knex'); +const { KnexInstrumentation } = require('@opentelemetry/instrumentation-knex'); const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base'); const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); @@ -34,11 +34,10 @@ provider.register(); registerInstrumentations({ instrumentations: [ - new KnexInstrumentation( - new KnexInstrumentationConfig({ + new KnexInstrumentation({ maxQueryLength: 100, }) - )], + ], tracerProvider: provider, }); ``` From a7861f6d23e07ab6f9e8d02378abd5e17d73bff3 Mon Sep 17 00:00:00 2001 From: Jamie King Date: Fri, 23 Feb 2024 05:46:05 -0700 Subject: [PATCH 2/3] feat(instrumentation-dns): allow ignoreHostnames to be only a single IgnoreMatcher (#1929) Co-authored-by: Marc Pichler --- plugins/node/opentelemetry-instrumentation-dns/README.md | 2 +- .../node/opentelemetry-instrumentation-dns/src/types.ts | 2 +- .../node/opentelemetry-instrumentation-dns/src/utils.ts | 5 ++++- .../test/functionals/utils.test.ts | 7 +++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-dns/README.md b/plugins/node/opentelemetry-instrumentation-dns/README.md index c0aaaa1c98..72f5c9ba7b 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/README.md +++ b/plugins/node/opentelemetry-instrumentation-dns/README.md @@ -44,7 +44,7 @@ Dns instrumentation has currently one option. You can set the following: | Options | Type | Description | | ------- | ---- | ----------- | -| [`ignoreHostnames`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-dns/src/types.ts#L99) | `IgnoreMatcher[]` | Dns instrumentation will not trace all requests that match hostnames | +| [`ignoreHostnames`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-dns/src/types.ts#L99) | `IgnoreMatcher | IgnoreMatcher[]` | Dns instrumentation will not trace all requests that match hostnames | ## Useful links diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/types.ts b/plugins/node/opentelemetry-instrumentation-dns/src/types.ts index 10383813d1..21646bbae7 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/types.ts @@ -17,5 +17,5 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; export type IgnoreMatcher = string | RegExp | ((url: string) => boolean); export interface DnsInstrumentationConfig extends InstrumentationConfig { - ignoreHostnames?: IgnoreMatcher[]; + ignoreHostnames?: IgnoreMatcher | IgnoreMatcher[]; } diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts b/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts index 9fae671bca..1b1d858052 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts @@ -124,13 +124,16 @@ export const satisfiesPattern = ( */ export const isIgnored = ( constant: string, - list?: IgnoreMatcher[], + list?: IgnoreMatcher | IgnoreMatcher[], onException?: (error: Error) => void ): boolean => { if (!list) { // No ignored urls - trace everything return false; } + if (!Array.isArray(list)) { + list = [list]; + } // Try/catch outside the loop for failing fast try { for (const pattern of list) { diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts index c995ca0261..987e680575 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts @@ -88,6 +88,13 @@ describe('Utility', () => { assert.strictEqual(answer1, true); }); + it('should call isSatisfyPattern, match for a single mathcer', () => { + const answer1 = utils.isIgnored('api.montreal.ca', url => + url.endsWith('montreal.ca') + ); + assert.strictEqual(answer1, true); + }); + it('should not re-throw when function throws an exception', () => { satisfiesPatternStub.restore(); const onException = (e: Error) => { From 882fb4b496c4b69424db8f08f8590256b0af5883 Mon Sep 17 00:00:00 2001 From: Daniel Li Date: Fri, 23 Feb 2024 13:10:23 +0000 Subject: [PATCH 3/3] feat(perf_hooks): add node instrumentation perf_hooks (#1902) * feat(perf_hooks): add node instrumentation perf_hooks * chore(perf_hooks): rename to instrumentation-perf-hooks * test(perf_hooks): decrease wait time for tests * fix(perf_hooks): don't export when disabled * chore(perf_hooks): add empty CHANGELOG * refactor(perf_hooks): use import type over import * chore(perf_hooks): add @opentelemetry/instrumentation dependency * fix(perf_hooks): sync package-lock.json * fix(perf_hooks): Markdown lint errors * chore: remove 'performance' from gauge name * fix: update release-please-config * fix(perf_hooks): peer-api-check * chore(perf_hooks): update devDependencies * test(perf_hooks): fix flakey tests --------- Co-authored-by: Marc Pichler --- .github/component_owners.yml | 2 + .release-please-manifest.json | 2 +- package-lock.json | 729 ++++++++++++++++++ .../instrumentation-perf-hooks/.eslintignore | 1 + .../instrumentation-perf-hooks/.eslintrc.js | 7 + .../instrumentation-perf-hooks/CHANGELOG.md | 0 .../node/instrumentation-perf-hooks/LICENSE | 201 +++++ .../node/instrumentation-perf-hooks/README.md | 80 ++ .../instrumentation-perf-hooks/package.json | 58 ++ .../instrumentation-perf-hooks/src/index.ts | 17 + .../src/instrumentation.ts | 89 +++ .../instrumentation-perf-hooks/src/types.ts | 26 + .../test/event_loop_utilization.test.ts | 105 +++ .../instrumentation-perf-hooks/tsconfig.json | 11 + release-please-config.json | 1 + 15 files changed, 1328 insertions(+), 1 deletion(-) create mode 100644 plugins/node/instrumentation-perf-hooks/.eslintignore create mode 100644 plugins/node/instrumentation-perf-hooks/.eslintrc.js create mode 100644 plugins/node/instrumentation-perf-hooks/CHANGELOG.md create mode 100644 plugins/node/instrumentation-perf-hooks/LICENSE create mode 100644 plugins/node/instrumentation-perf-hooks/README.md create mode 100644 plugins/node/instrumentation-perf-hooks/package.json create mode 100644 plugins/node/instrumentation-perf-hooks/src/index.ts create mode 100644 plugins/node/instrumentation-perf-hooks/src/instrumentation.ts create mode 100644 plugins/node/instrumentation-perf-hooks/src/types.ts create mode 100644 plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts create mode 100644 plugins/node/instrumentation-perf-hooks/tsconfig.json diff --git a/.github/component_owners.yml b/.github/component_owners.yml index 4ee43d769d..d681950f7f 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -100,6 +100,8 @@ components: - rauno56 plugins/node/opentelemetry-instrumentation-net: - seemk + plugins/node/opentelemetry-instrumentation-perf-hooks: + - d4nyll plugins/node/opentelemetry-instrumentation-pg: - rauno56 plugins/node/opentelemetry-instrumentation-pino: diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 78f2d84c83..e197b006db 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1 +1 @@ -{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.28.6","detectors/node/opentelemetry-resource-detector-aws":"1.3.6","detectors/node/opentelemetry-resource-detector-azure":"0.2.4","detectors/node/opentelemetry-resource-detector-container":"0.3.6","detectors/node/opentelemetry-resource-detector-gcp":"0.29.6","detectors/node/opentelemetry-resource-detector-github":"0.28.1","detectors/node/opentelemetry-resource-detector-instana":"0.6.0","metapackages/auto-instrumentations-node":"0.41.1","metapackages/auto-instrumentations-web":"0.36.0","packages/opentelemetry-host-metrics":"0.35.0","packages/opentelemetry-id-generator-aws-xray":"1.2.1","packages/opentelemetry-propagation-utils":"0.30.6","packages/opentelemetry-redis-common":"0.36.1","packages/opentelemetry-sampler-aws-xray":"0.34.0","packages/opentelemetry-sql-common":"0.40.0","packages/opentelemetry-test-utils":"0.36.0","plugins/node/instrumentation-amqplib":"0.34.0","plugins/node/instrumentation-cucumber":"0.3.0","plugins/node/instrumentation-dataloader":"0.6.0","plugins/node/instrumentation-fs":"0.9.0","plugins/node/instrumentation-lru-memoizer":"0.34.0","plugins/node/instrumentation-mongoose":"0.35.0","plugins/node/instrumentation-socket.io":"0.36.0","plugins/node/instrumentation-tedious":"0.7.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.38.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.38.1","plugins/node/opentelemetry-instrumentation-bunyan":"0.35.0","plugins/node/opentelemetry-instrumentation-bunyan/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.35.0","plugins/node/opentelemetry-instrumentation-connect":"0.33.0","plugins/node/opentelemetry-instrumentation-dns":"0.33.0","plugins/node/opentelemetry-instrumentation-express":"0.35.0","plugins/node/opentelemetry-instrumentation-express/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-fastify":"0.33.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.33.0","plugins/node/opentelemetry-instrumentation-graphql":"0.37.0","plugins/node/opentelemetry-instrumentation-hapi":"0.34.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.37.0","plugins/node/opentelemetry-instrumentation-knex":"0.33.0","plugins/node/opentelemetry-instrumentation-koa":"0.37.0","plugins/node/opentelemetry-instrumentation-koa/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-memcached":"0.33.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.39.0","plugins/node/opentelemetry-instrumentation-mongodb/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-mysql":"0.35.0","plugins/node/opentelemetry-instrumentation-mysql/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-mysql2":"0.35.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.34.0","plugins/node/opentelemetry-instrumentation-net":"0.33.0","plugins/node/opentelemetry-instrumentation-pg":"0.38.0","plugins/node/opentelemetry-instrumentation-pino":"0.35.0","plugins/node/opentelemetry-instrumentation-redis":"0.36.0","plugins/node/opentelemetry-instrumentation-redis/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-redis-4":"0.36.0","plugins/node/opentelemetry-instrumentation-restify":"0.35.0","plugins/node/opentelemetry-instrumentation-router":"0.34.0","plugins/node/opentelemetry-instrumentation-winston":"0.34.0","plugins/web/opentelemetry-instrumentation-document-load":"0.35.0","plugins/web/opentelemetry-instrumentation-long-task":"0.35.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.35.0","plugins/web/opentelemetry-plugin-react-load":"0.30.0","propagators/opentelemetry-propagator-aws-xray":"1.3.1","propagators/opentelemetry-propagator-grpc-census-binary":"0.27.1","propagators/opentelemetry-propagator-instana":"0.3.1","propagators/opentelemetry-propagator-ot-trace":"0.27.1"} +{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.28.6","detectors/node/opentelemetry-resource-detector-aws":"1.3.6","detectors/node/opentelemetry-resource-detector-azure":"0.2.4","detectors/node/opentelemetry-resource-detector-container":"0.3.6","detectors/node/opentelemetry-resource-detector-gcp":"0.29.6","detectors/node/opentelemetry-resource-detector-github":"0.28.1","detectors/node/opentelemetry-resource-detector-instana":"0.6.0","metapackages/auto-instrumentations-node":"0.41.1","metapackages/auto-instrumentations-web":"0.36.0","packages/opentelemetry-host-metrics":"0.35.0","packages/opentelemetry-id-generator-aws-xray":"1.2.1","packages/opentelemetry-propagation-utils":"0.30.6","packages/opentelemetry-redis-common":"0.36.1","packages/opentelemetry-sampler-aws-xray":"0.34.0","packages/opentelemetry-sql-common":"0.40.0","packages/opentelemetry-test-utils":"0.36.0","plugins/node/instrumentation-amqplib":"0.34.0","plugins/node/instrumentation-cucumber":"0.3.0","plugins/node/instrumentation-dataloader":"0.6.0","plugins/node/instrumentation-fs":"0.9.0","plugins/node/instrumentation-lru-memoizer":"0.34.0","plugins/node/instrumentation-mongoose":"0.35.0","plugins/node/instrumentation-perf-hooks": "0.1.0","plugins/node/instrumentation-socket.io":"0.36.0","plugins/node/instrumentation-tedious":"0.7.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.38.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.38.1","plugins/node/opentelemetry-instrumentation-bunyan":"0.35.0","plugins/node/opentelemetry-instrumentation-bunyan/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.35.0","plugins/node/opentelemetry-instrumentation-connect":"0.33.0","plugins/node/opentelemetry-instrumentation-dns":"0.33.0","plugins/node/opentelemetry-instrumentation-express":"0.35.0","plugins/node/opentelemetry-instrumentation-express/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-fastify":"0.33.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.33.0","plugins/node/opentelemetry-instrumentation-graphql":"0.37.0","plugins/node/opentelemetry-instrumentation-hapi":"0.34.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.37.0","plugins/node/opentelemetry-instrumentation-knex":"0.33.0","plugins/node/opentelemetry-instrumentation-koa":"0.37.0","plugins/node/opentelemetry-instrumentation-koa/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-memcached":"0.33.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.39.0","plugins/node/opentelemetry-instrumentation-mongodb/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-mysql":"0.35.0","plugins/node/opentelemetry-instrumentation-mysql/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-mysql2":"0.35.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.34.0","plugins/node/opentelemetry-instrumentation-net":"0.33.0","plugins/node/opentelemetry-instrumentation-pg":"0.38.0","plugins/node/opentelemetry-instrumentation-pino":"0.35.0","plugins/node/opentelemetry-instrumentation-redis":"0.36.0","plugins/node/opentelemetry-instrumentation-redis/examples":"0.1.0","plugins/node/opentelemetry-instrumentation-redis-4":"0.36.0","plugins/node/opentelemetry-instrumentation-restify":"0.35.0","plugins/node/opentelemetry-instrumentation-router":"0.34.0","plugins/node/opentelemetry-instrumentation-winston":"0.34.0","plugins/web/opentelemetry-instrumentation-document-load":"0.35.0","plugins/web/opentelemetry-instrumentation-long-task":"0.35.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.35.0","plugins/web/opentelemetry-plugin-react-load":"0.30.0","propagators/opentelemetry-propagator-aws-xray":"1.3.1","propagators/opentelemetry-propagator-grpc-census-binary":"0.27.1","propagators/opentelemetry-propagator-instana":"0.3.1","propagators/opentelemetry-propagator-ot-trace":"0.27.1"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2ae8e72eea..bc8de58242 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8056,6 +8056,10 @@ "resolved": "plugins/node/opentelemetry-instrumentation-net", "link": true }, + "node_modules/@opentelemetry/instrumentation-perf-hooks": { + "resolved": "plugins/node/instrumentation-perf-hooks", + "link": true + }, "node_modules/@opentelemetry/instrumentation-pg": { "resolved": "plugins/node/opentelemetry-instrumentation-pg", "link": true @@ -23191,6 +23195,18 @@ "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "devOptional": true }, + "node_modules/nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -32739,6 +32755,12 @@ "errno": "~0.1.7" } }, + "node_modules/workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", + "dev": true + }, "node_modules/wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", @@ -34201,6 +34223,398 @@ "integrity": "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==", "dev": true }, + "plugins/node/instrumentation-perf-hooks": { + "name": "@opentelemetry/instrumentation-perf-hooks", + "version": "0.1.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/instrumentation": "^0.40.0" + }, + "devDependencies": { + "@opentelemetry/api": "^1.0.0", + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "rimraf": "5.0.5", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "engines": { + "node": ">=14.10.0" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@opentelemetry/core": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.20.0.tgz", + "integrity": "sha512-lSRvk5AIdD6CtgYJcJXh0wGibQ3S/8bC2qbqKs9wK8e0K1tsWV6YkGFOqVc+jIRlCbZoIBeZzDe5UI+vb94uvg==", + "dev": true, + "dependencies": { + "@opentelemetry/semantic-conventions": "1.20.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.8.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@opentelemetry/instrumentation": { + "version": "0.40.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.40.0.tgz", + "integrity": "sha512-23TzBKPflUS1uEq5SXymnQKQDSda35KvHjnvxdcDQGE+wg6hwDHgScUCWiBmZW4sxAaPcANfs+Wc9B7yDuyT6Q==", + "dependencies": { + "@types/shimmer": "^1.0.2", + "import-in-the-middle": "1.3.5", + "require-in-the-middle": "^7.1.0", + "semver": "^7.3.2", + "shimmer": "^1.2.1" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.3.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@opentelemetry/resources": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.20.0.tgz", + "integrity": "sha512-nOpV0vGegSq+9ze2cEDvO3BMA5pGBhmhKZiAlj+xQZjiEjPmJtdHIuBLRvptu2ahcbFJw85gIB9BYHZOvZK1JQ==", + "dev": true, + "dependencies": { + "@opentelemetry/core": "1.20.0", + "@opentelemetry/semantic-conventions": "1.20.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.8.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@opentelemetry/sdk-metrics": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.20.0.tgz", + "integrity": "sha512-07bFOQUrpN/Q5biJ/cuBePztKwkc1VGkFblZxAcVkuvCLDAPJfsyr0NNWegWeYe0bpGt1jmXScpUWnVD+t8Q0w==", + "dev": true, + "dependencies": { + "@opentelemetry/core": "1.20.0", + "@opentelemetry/resources": "1.20.0", + "lodash.merge": "^4.6.2" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.8.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@opentelemetry/semantic-conventions": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.20.0.tgz", + "integrity": "sha512-3zLJJCgTKYpbqFX8drl8hOCHtdchELC+kGqlVcV4mHW1DiElTtv1Nt9EKBptTd1IfL56QkuYnWJ3DeHd2Gtu/A==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@types/mocha": { + "version": "10.0.6", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", + "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", + "dev": true + }, + "plugins/node/instrumentation-perf-hooks/node_modules/@types/node": { + "version": "20.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.4.tgz", + "integrity": "sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "plugins/node/instrumentation-perf-hooks/node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/glob": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/import-in-the-middle": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/import-in-the-middle/-/import-in-the-middle-1.3.5.tgz", + "integrity": "sha512-yzHlBqi1EBFrkieAnSt8eTgO5oLSl+YJ7qaOpUH/PMqQOMZoQ/RmDlwnTLQrwYto+gHYjRG+i/IbsB1eDx32NQ==", + "dependencies": { + "module-details-from-path": "^1.0.3" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/mocha": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", + "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", + "dev": true, + "dependencies": { + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha.js" + }, + "engines": { + "node": ">= 14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mochajs" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/mocha/node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "plugins/node/instrumentation-perf-hooks/node_modules/serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "plugins/node/instrumentation-perf-hooks/node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dev": true, + "dependencies": { + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, "plugins/node/instrumentation-socket.io": { "name": "@opentelemetry/instrumentation-socket.io", "version": "0.36.0", @@ -36457,6 +36871,25 @@ "@opentelemetry/api": "^1.3.0" } }, + "plugins/node/opentelemetry-instrumentation-perf-hooks": { + "version": "0.1.0", + "extraneous": true, + "license": "Apache-2.0", + "devDependencies": { + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "ts-mocha": "^10.0.0" + }, + "engines": { + "node": ">=14.10.0" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } + }, "plugins/node/opentelemetry-instrumentation-pg": { "name": "@opentelemetry/instrumentation-pg", "version": "0.38.0", @@ -45081,6 +45514,290 @@ "typescript": "4.4.4" } }, + "@opentelemetry/instrumentation-perf-hooks": { + "version": "file:plugins/node/instrumentation-perf-hooks", + "requires": { + "@opentelemetry/api": "^1.0.0", + "@opentelemetry/instrumentation": "^0.40.0", + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "rimraf": "5.0.5", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "dependencies": { + "@opentelemetry/core": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.20.0.tgz", + "integrity": "sha512-lSRvk5AIdD6CtgYJcJXh0wGibQ3S/8bC2qbqKs9wK8e0K1tsWV6YkGFOqVc+jIRlCbZoIBeZzDe5UI+vb94uvg==", + "dev": true, + "requires": { + "@opentelemetry/semantic-conventions": "1.20.0" + } + }, + "@opentelemetry/instrumentation": { + "version": "0.40.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.40.0.tgz", + "integrity": "sha512-23TzBKPflUS1uEq5SXymnQKQDSda35KvHjnvxdcDQGE+wg6hwDHgScUCWiBmZW4sxAaPcANfs+Wc9B7yDuyT6Q==", + "requires": { + "@types/shimmer": "^1.0.2", + "import-in-the-middle": "1.3.5", + "require-in-the-middle": "^7.1.0", + "semver": "^7.3.2", + "shimmer": "^1.2.1" + } + }, + "@opentelemetry/resources": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.20.0.tgz", + "integrity": "sha512-nOpV0vGegSq+9ze2cEDvO3BMA5pGBhmhKZiAlj+xQZjiEjPmJtdHIuBLRvptu2ahcbFJw85gIB9BYHZOvZK1JQ==", + "dev": true, + "requires": { + "@opentelemetry/core": "1.20.0", + "@opentelemetry/semantic-conventions": "1.20.0" + } + }, + "@opentelemetry/sdk-metrics": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.20.0.tgz", + "integrity": "sha512-07bFOQUrpN/Q5biJ/cuBePztKwkc1VGkFblZxAcVkuvCLDAPJfsyr0NNWegWeYe0bpGt1jmXScpUWnVD+t8Q0w==", + "dev": true, + "requires": { + "@opentelemetry/core": "1.20.0", + "@opentelemetry/resources": "1.20.0", + "lodash.merge": "^4.6.2" + } + }, + "@opentelemetry/semantic-conventions": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.20.0.tgz", + "integrity": "sha512-3zLJJCgTKYpbqFX8drl8hOCHtdchELC+kGqlVcV4mHW1DiElTtv1Nt9EKBptTd1IfL56QkuYnWJ3DeHd2Gtu/A==", + "dev": true + }, + "@types/mocha": { + "version": "10.0.6", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", + "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", + "dev": true + }, + "@types/node": { + "version": "20.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.4.tgz", + "integrity": "sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } + }, + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "dependencies": { + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true + }, + "diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "glob": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "import-in-the-middle": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/import-in-the-middle/-/import-in-the-middle-1.3.5.tgz", + "integrity": "sha512-yzHlBqi1EBFrkieAnSt8eTgO5oLSl+YJ7qaOpUH/PMqQOMZoQ/RmDlwnTLQrwYto+gHYjRG+i/IbsB1eDx32NQ==", + "requires": { + "module-details-from-path": "^1.0.3" + } + }, + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true + }, + "log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "requires": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + } + }, + "mocha": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", + "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", + "dev": true, + "requires": { + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "dependencies": { + "minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + } + } + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } + }, + "yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "requires": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + } + }, + "yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dev": true, + "requires": { + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" + } + } + } + }, "@opentelemetry/instrumentation-pg": { "version": "file:plugins/node/opentelemetry-instrumentation-pg", "requires": { @@ -58873,6 +59590,12 @@ "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "devOptional": true }, + "nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -66473,6 +67196,12 @@ "errno": "~0.1.7" } }, + "workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", + "dev": true + }, "wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", diff --git a/plugins/node/instrumentation-perf-hooks/.eslintignore b/plugins/node/instrumentation-perf-hooks/.eslintignore new file mode 100644 index 0000000000..378eac25d3 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/.eslintignore @@ -0,0 +1 @@ +build diff --git a/plugins/node/instrumentation-perf-hooks/.eslintrc.js b/plugins/node/instrumentation-perf-hooks/.eslintrc.js new file mode 100644 index 0000000000..0c986a856c --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + env: { + mocha: true, + node: true, + }, + ...require('../../../eslint.config.js'), +}; diff --git a/plugins/node/instrumentation-perf-hooks/CHANGELOG.md b/plugins/node/instrumentation-perf-hooks/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/node/instrumentation-perf-hooks/LICENSE b/plugins/node/instrumentation-perf-hooks/LICENSE new file mode 100644 index 0000000000..e50e8c80f9 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [2022] 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 + + http://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. diff --git a/plugins/node/instrumentation-perf-hooks/README.md b/plugins/node/instrumentation-perf-hooks/README.md new file mode 100644 index 0000000000..d09b9716d5 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/README.md @@ -0,0 +1,80 @@ +# OpenTelemetry Node.js Performance Hooks Instrumentation + +[![NPM Published Version][npm-img]][npm-url] +[![Apache License][license-image]][license-image] + +This module provides automatic metric instrumentation that exposes measurements from the [Performance measurement APIs](https://nodejs.org/api/perf_hooks.html) (i.e. `perf_hooks`). + +## Example + +```bash +npm install --save @opentelemetry/sdk-node @opentelemetry/exporter-prometheus +npm install --save @opentelemetry/instrumentation-perf-hooks +``` + +```js +import { NodeSDK } from '@opentelemetry/sdk-node'; +import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; +import { PerfHooksInstrumentation } from '@opentelemetry/instrumentation-perf-hooks'; + +const prometheusExporter = new PrometheusExporter({ + port: 9464, + startServer: true +}); + +const sdk = new NodeSDK({ + metricReader: prometheusExporter, + instrumentations: [new PerfHooksInstrumentation({ + eventLoopUtilizationMeasurementInterval: 5000, + })], +}); + +sdk.start() +``` + +[`NodeSDK`](https://www.npmjs.com/package/@opentelemetry/sdk-node) is the full OpenTelemetry SDK for Node.js that is a layer of abstraction on top of the `@opentelemetry/sdk-metrics` and `@opentelemetry/sdk-trace-*` packages. By specifying `metricReader`, it will initialize the metrics SDK and creates a `MeterProvider`. [`@opentelemetry/exporter-prometheus`](https://www.npmjs.com/package/@opentelemetry/exporter-prometheus) will output metrics collected by registered instrumentation on a `/metrics` endpoint. + +Go to [`localhost:9464/metrics`](http://localhost:9464/metrics), and you should see: + +```txt +# HELP nodejs_performance_event_loop_utilization Event loop utilization +# UNIT nodejs_performance_event_loop_utilization 1 +# TYPE nodejs_performance_event_loop_utilization gauge +nodejs_performance_event_loop_utilization 0.010140079547955264 +``` + +> Metrics will only be exported after it has collected two ELU readings (at least approximately `PerfHooksInstrumentationConfig.eventLoopUtilizationMeasurementInterval` milliseconds after initialization). Otherwise, you may see: +> +> ```txt +> # no registered metrics +> ``` + +### Options + +`PerfHooksInstrumentation`'s constructor accepts the following options: + +| name | type | unit | default | description | +|---|---|---|---|---| +| [`eventLoopUtilizationMeasurementInterval`](./src/types.ts#L25) | `int` | millisecond | `5000` | The approximate number of milliseconds for which to calculate event loop utilization averages. A larger value will result in more accurate averages at the expense of less granular data. Should be set to below the scrape interval of your metrics collector to avoid duplicated data points. | + +## Supported Node.js versions + +v14.10.0+ + + + +## Useful links + +- For more information on OpenTelemetry, visit: +- For more about OpenTelemetry JavaScript: +- For help or feedback on this project, join us in [GitHub Discussions][discussions-url] + +## License + +Apache 2.0 - See [LICENSE][license-url] for more information. + +[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions +[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE +[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat +[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-pg +[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-pg.svg diff --git a/plugins/node/instrumentation-perf-hooks/package.json b/plugins/node/instrumentation-perf-hooks/package.json new file mode 100644 index 0000000000..6e40c2aeb5 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/package.json @@ -0,0 +1,58 @@ +{ + "name": "@opentelemetry/instrumentation-perf-hooks", + "version": "0.1.0", + "description": "OpenTelemetry Node.js Performance measurement API automatic instrumentation package", + "main": "build/src/index.js", + "types": "build/src/index.d.ts", + "repository": "open-telemetry/opentelemetry-js-contrib", + "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-perf-hooks", + "scripts": { + "clean": "rimraf build/*", + "compile": "tsc -p .", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-perf-hooks --include-dependencies", + "prewatch": "npm run precompile", + "prepare": "npm run compile", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "version:update": "node ../../../scripts/version-update.js" + }, + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=14.10.0" + }, + "keywords": [ + "perf_hooks", + "instrumentation", + "nodejs", + "opentelemetry" + ], + "files": [ + "build/src/**/*.js", + "build/src/**/*.js.map", + "build/src/**/*.d.ts", + "LICENSE", + "README.md" + ], + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@opentelemetry/instrumentation": "^0.40.0" + }, + "devDependencies": { + "@opentelemetry/api": "^1.0.0", + "@opentelemetry/sdk-metrics": "^1.20.0", + "@types/mocha": "^10.0.6", + "@types/node": "^20.11.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "rimraf": "5.0.5", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } +} diff --git a/plugins/node/instrumentation-perf-hooks/src/index.ts b/plugins/node/instrumentation-perf-hooks/src/index.ts new file mode 100644 index 0000000000..0cd1fbc2e8 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/src/index.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ +export * from './instrumentation'; +export * from './types'; diff --git a/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts b/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts new file mode 100644 index 0000000000..bc67492a34 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/src/instrumentation.ts @@ -0,0 +1,89 @@ +/* + * 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. + */ +import { EventLoopUtilization, performance } from 'node:perf_hooks'; +import { clearInterval, setInterval } from 'node:timers'; +const { eventLoopUtilization } = performance; + +import { InstrumentationBase } from '@opentelemetry/instrumentation'; + +import { VERSION } from './version'; +import { PerfHooksInstrumentationConfig } from './types'; + +const ELUS_LENGTH = 2; +const DEFAULT_CONFIG: PerfHooksInstrumentationConfig = { + eventLoopUtilizationMeasurementInterval: 5000, +}; + +export class PerfHooksInstrumentation extends InstrumentationBase { + private _ELUs: EventLoopUtilization[] = []; + private _interval: NodeJS.Timeout | undefined; + + constructor(config: PerfHooksInstrumentationConfig = DEFAULT_CONFIG) { + super('@opentelemetry/instrumentation-perf-hooks', VERSION, config); + } + + private _addELU() { + this._ELUs.unshift(eventLoopUtilization()); + if (this._ELUs.length > ELUS_LENGTH) { + this._ELUs.pop(); + } + } + + private _clearELU() { + if (!this._ELUs) { + this._ELUs = []; + } + this._ELUs.length = 0; + } + + // Called when a new `MeterProvider` is set + // the Meter (result of @opentelemetry/api's getMeter) is available as this.meter within this method + override _updateMetricInstruments() { + this.meter + .createObservableGauge('nodejs.event_loop.utilization', { + description: 'Event loop utilization', + unit: '1', + }) + .addCallback(async observableResult => { + if (this._ELUs.length !== ELUS_LENGTH) { + return; + } + const elu = eventLoopUtilization(...this._ELUs); + observableResult.observe(elu.utilization); + }); + } + + init() { + // Not instrumenting or patching a Node.js module + } + + override enable() { + this._clearELU(); + this._addELU(); + clearInterval(this._interval); + this._interval = setInterval( + () => this._addELU(), + (this._config as PerfHooksInstrumentationConfig) + .eventLoopUtilizationMeasurementInterval + ); + } + + override disable() { + this._clearELU(); + clearInterval(this._interval); + this._interval = undefined; + } +} diff --git a/plugins/node/instrumentation-perf-hooks/src/types.ts b/plugins/node/instrumentation-perf-hooks/src/types.ts new file mode 100644 index 0000000000..84f43b0162 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/src/types.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ +import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; + +export interface PerfHooksInstrumentationConfig extends InstrumentationConfig { + /** + * The approximate number of milliseconds for which to calculate event loop utilization averages. + * A larger value will result in more accurate averages at the expense of less granular data. + * Should be set to below the scrape interval of your metrics collector to avoid duplicated data points. + * @default 5000 + */ + eventLoopUtilizationMeasurementInterval?: number; +} diff --git a/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts b/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts new file mode 100644 index 0000000000..89c2420cfb --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/test/event_loop_utilization.test.ts @@ -0,0 +1,105 @@ +/* + * 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. + */ +import { + AggregationTemporality, + InMemoryMetricExporter, + MeterProvider, + DataPointType, + PeriodicExportingMetricReader, +} from '@opentelemetry/sdk-metrics'; + +import { PerfHooksInstrumentation } from '../src'; +import * as assert from 'assert'; + +const MEASUREMENT_INTERVAL = 10; + +const metricExporter = new InMemoryMetricExporter(AggregationTemporality.DELTA); +const metricReader = new PeriodicExportingMetricReader({ + exporter: metricExporter, + exportIntervalMillis: MEASUREMENT_INTERVAL * 2, +}); +const meterProvider = new MeterProvider(); +meterProvider.addMetricReader(metricReader); + +const instrumentation = new PerfHooksInstrumentation({ + eventLoopUtilizationMeasurementInterval: MEASUREMENT_INTERVAL, +}); + +instrumentation.setMeterProvider(meterProvider); + +describe('nodejs.event_loop.utilization', () => { + beforeEach(async () => { + instrumentation.disable(); // Stops future metrics from being collected + metricExporter.reset(); // Remove existing collected metrics + }); + + after(() => { + instrumentation.disable(); + meterProvider.shutdown(); + }); + + it('should stop exporting metrics when disabled', async () => { + // Wait for the ELU data to be collected and exported + // MEASUREMENT_INTERVAL * 2 is the export interval, plus MEASUREMENT_INTERVAL as a buffer + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 3)); + // Retrieve exported metrics + const resourceMetrics = metricExporter.getMetrics(); + const scopeMetrics = + resourceMetrics[resourceMetrics.length - 1].scopeMetrics; + assert.strictEqual(scopeMetrics.length, 0); + }); + + it('should not export immediately after enable', async () => { + instrumentation.enable(); + assert.deepEqual(metricExporter.getMetrics(), []); + }); + + it('can use default eventLoopUtilizationMeasurementInterval', async () => { + // Repeat of 'should not export immediately after enable' but with defaults + const localInstrumentation = new PerfHooksInstrumentation(); + localInstrumentation.setMeterProvider(meterProvider); + localInstrumentation.disable(); + metricExporter.reset(); + localInstrumentation.enable(); + assert.deepEqual(metricExporter.getMetrics(), []); + localInstrumentation.disable(); + }); + + it('should export event loop utilization metrics after eventLoopUtilizationMeasurementInterval', async () => { + instrumentation.enable(); + // Wait for the ELU data to be collected and exported + // MEASUREMENT_INTERVAL * 2 is the export interval, plus MEASUREMENT_INTERVAL as a buffer + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 3)); + const resourceMetrics = metricExporter.getMetrics(); + const scopeMetrics = + resourceMetrics[resourceMetrics.length - 1].scopeMetrics; + const metrics = scopeMetrics[0].metrics; + assert.strictEqual(metrics.length, 1); + assert.strictEqual(metrics[0].dataPointType, DataPointType.GAUGE); + assert.strictEqual(metrics[0].dataPoints.length, 1); + assert.strictEqual(metrics[0].dataPoints[0].value > 0, true); + assert.strictEqual(metrics[0].dataPoints[0].value < 1, true); + assert.strictEqual( + metrics[0].descriptor.name, + 'nodejs.event_loop.utilization' + ); + assert.strictEqual( + metrics[0].descriptor.description, + 'Event loop utilization' + ); + assert.strictEqual(metrics[0].descriptor.unit, '1'); + }); +}); diff --git a/plugins/node/instrumentation-perf-hooks/tsconfig.json b/plugins/node/instrumentation-perf-hooks/tsconfig.json new file mode 100644 index 0000000000..28be80d266 --- /dev/null +++ b/plugins/node/instrumentation-perf-hooks/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ] +} diff --git a/release-please-config.json b/release-please-config.json index 344b719ca6..71fbcf13ad 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -28,6 +28,7 @@ "plugins/node/instrumentation-fs": {}, "plugins/node/instrumentation-lru-memoizer": {}, "plugins/node/instrumentation-mongoose": {}, + "plugins/node/instrumentation-perf-hooks": {}, "plugins/node/instrumentation-socket.io": {}, "plugins/node/instrumentation-tedious": {}, "plugins/node/opentelemetry-instrumentation-aws-lambda": {},