From 2e1d377dab061b88000701b21dd287d4cafe77b8 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 7 Apr 2021 18:46:46 +0200 Subject: [PATCH 1/2] chore: remove plugins and update docs references --- README.md | 71 +- .../plugins-node-core-and-contrib/README.md | 51 -- .../package.json | 28 - .../README.md | 6 - .../README.md | 8 +- .../README.md | 6 - .../opentelemetry-plugin-dns/.eslintignore | 1 - .../opentelemetry-plugin-dns/.eslintrc.js | 7 - .../node/opentelemetry-plugin-dns/.npmignore | 4 - plugins/node/opentelemetry-plugin-dns/LICENSE | 201 ----- .../node/opentelemetry-plugin-dns/README.md | 96 --- .../opentelemetry-plugin-dns/package.json | 69 -- .../node/opentelemetry-plugin-dns/src/dns.ts | 209 ------ .../src/enums/AddressFamily.ts | 21 - .../src/enums/AttributeNames.ts | 25 - .../opentelemetry-plugin-dns/src/index.ts | 18 - .../opentelemetry-plugin-dns/src/types.ts | 100 --- .../opentelemetry-plugin-dns/src/utils.ts | 155 ---- .../opentelemetry-plugin-dns/src/version.ts | 18 - .../test/functionals/dns-disable.test.ts | 66 -- .../test/functionals/dns-enable.test.ts | 42 -- .../test/functionals/utils.test.ts | 169 ----- .../test/integrations/dns-lookup.test.ts | 215 ------ .../integrations/dnspromise-lookup.test.ts | 222 ------ .../test/utils/assertSpan.ts | 69 -- .../test/utils/utils.ts | 27 - .../opentelemetry-plugin-dns/tsconfig.json | 11 - .../.eslintignore | 1 - .../opentelemetry-plugin-express/.eslintrc.js | 7 - .../opentelemetry-plugin-express/.npmignore | 4 - .../node/opentelemetry-plugin-express/LICENSE | 201 ----- .../opentelemetry-plugin-express/README.md | 99 --- .../opentelemetry-plugin-express/package.json | 69 -- .../src/express.ts | 263 ------- .../opentelemetry-plugin-express/src/index.ts | 17 - .../opentelemetry-plugin-express/src/types.ts | 102 --- .../opentelemetry-plugin-express/src/utils.ts | 135 ---- .../src/version.ts | 18 - .../test/express.test.ts | 472 ------------ .../test/utils.test.ts | 147 ---- .../tsconfig.json | 11 - .../.eslintignore | 1 - .../opentelemetry-plugin-ioredis/.eslintrc.js | 7 - .../opentelemetry-plugin-ioredis/.npmignore | 4 - .../node/opentelemetry-plugin-ioredis/LICENSE | 201 ----- .../opentelemetry-plugin-ioredis/README.md | 111 --- .../opentelemetry-plugin-ioredis/package.json | 74 -- .../opentelemetry-plugin-ioredis/src/index.ts | 17 - .../src/ioredis.ts | 77 -- .../opentelemetry-plugin-ioredis/src/types.ts | 47 -- .../opentelemetry-plugin-ioredis/src/utils.ts | 140 ---- .../src/version.ts | 18 - .../test/ioredis.test.ts | 708 ------------------ .../tsconfig.json | 11 - .../.eslintignore | 1 - .../opentelemetry-plugin-mongodb/.eslintrc.js | 7 - .../opentelemetry-plugin-mongodb/.npmignore | 4 - .../node/opentelemetry-plugin-mongodb/LICENSE | 201 ----- .../opentelemetry-plugin-mongodb/README.md | 89 --- .../opentelemetry-plugin-mongodb/package.json | 69 -- .../opentelemetry-plugin-mongodb/src/index.ts | 17 - .../src/mongodb.ts | 267 ------- .../opentelemetry-plugin-mongodb/src/types.ts | 49 -- .../src/version.ts | 18 - .../test/mongodb.test.ts | 255 ------- .../test/multiple_versions.test.ts | 113 --- .../test/utils.ts | 99 --- .../tsconfig.json | 11 - .../opentelemetry-plugin-mysql/.eslintignore | 1 - .../opentelemetry-plugin-mysql/.eslintrc.js | 7 - .../opentelemetry-plugin-mysql/.npmignore | 4 - .../node/opentelemetry-plugin-mysql/LICENSE | 201 ----- .../node/opentelemetry-plugin-mysql/README.md | 82 -- .../opentelemetry-plugin-mysql/package.json | 70 -- .../opentelemetry-plugin-mysql/src/index.ts | 16 - .../opentelemetry-plugin-mysql/src/mysql.ts | 274 ------- .../opentelemetry-plugin-mysql/src/utils.ts | 109 --- .../opentelemetry-plugin-mysql/src/version.ts | 18 - .../test/mysql.test.ts | 629 ---------------- .../opentelemetry-plugin-mysql/tsconfig.json | 11 - .../.eslintignore | 1 - .../opentelemetry-plugin-pg-pool/.eslintrc.js | 7 - .../opentelemetry-plugin-pg-pool/.npmignore | 4 - .../node/opentelemetry-plugin-pg-pool/LICENSE | 201 ----- .../opentelemetry-plugin-pg-pool/README.md | 75 -- .../opentelemetry-plugin-pg-pool/package.json | 78 -- .../opentelemetry-plugin-pg-pool/src/enums.ts | 36 - .../opentelemetry-plugin-pg-pool/src/index.ts | 17 - .../src/pg-pool.ts | 131 ---- .../opentelemetry-plugin-pg-pool/src/types.ts | 37 - .../opentelemetry-plugin-pg-pool/src/utils.ts | 43 -- .../src/version.ts | 18 - .../test/pg-pool.test.ts | 282 ------- .../tsconfig.json | 11 - .../opentelemetry-plugin-pg/.eslintignore | 1 - .../node/opentelemetry-plugin-pg/.eslintrc.js | 7 - .../node/opentelemetry-plugin-pg/.npmignore | 4 - plugins/node/opentelemetry-plugin-pg/LICENSE | 201 ----- .../node/opentelemetry-plugin-pg/README.md | 99 --- .../node/opentelemetry-plugin-pg/package.json | 75 -- .../node/opentelemetry-plugin-pg/src/enums.ts | 36 - .../node/opentelemetry-plugin-pg/src/index.ts | 17 - .../node/opentelemetry-plugin-pg/src/pg.ts | 178 ----- .../node/opentelemetry-plugin-pg/src/types.ts | 57 -- .../node/opentelemetry-plugin-pg/src/utils.ts | 177 ----- .../opentelemetry-plugin-pg/src/version.ts | 18 - .../opentelemetry-plugin-pg/test/pg.test.ts | 536 ------------- .../test/utils.test.ts | 150 ---- .../opentelemetry-plugin-pg/tsconfig.json | 11 - .../opentelemetry-plugin-redis/.eslintignore | 1 - .../opentelemetry-plugin-redis/.eslintrc.js | 7 - .../opentelemetry-plugin-redis/.npmignore | 4 - .../node/opentelemetry-plugin-redis/LICENSE | 201 ----- .../node/opentelemetry-plugin-redis/README.md | 81 -- .../opentelemetry-plugin-redis/package.json | 73 -- .../opentelemetry-plugin-redis/src/index.ts | 17 - .../opentelemetry-plugin-redis/src/redis.ts | 101 --- .../opentelemetry-plugin-redis/src/types.ts | 36 - .../opentelemetry-plugin-redis/src/utils.ts | 126 ---- .../opentelemetry-plugin-redis/src/version.ts | 18 - .../test/redis.test.ts | 236 ------ .../opentelemetry-plugin-redis/tsconfig.json | 11 - .../README.md | 10 +- 123 files changed, 39 insertions(+), 10890 deletions(-) delete mode 100644 metapackages/plugins-node-core-and-contrib/README.md delete mode 100644 metapackages/plugins-node-core-and-contrib/package.json delete mode 100644 plugins/node/opentelemetry-plugin-dns/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-dns/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-dns/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-dns/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-dns/README.md delete mode 100644 plugins/node/opentelemetry-plugin-dns/package.json delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/dns.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/enums/AddressFamily.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/enums/AttributeNames.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/functionals/utils.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/utils/assertSpan.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/test/utils/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-dns/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-express/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-express/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-express/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-express/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-express/README.md delete mode 100644 plugins/node/opentelemetry-plugin-express/package.json delete mode 100644 plugins/node/opentelemetry-plugin-express/src/express.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/test/express.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/test/utils.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-express/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/README.md delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/package.json delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-ioredis/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/README.md delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/package.json delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/src/mongodb.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/test/mongodb.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/test/multiple_versions.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/test/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-mongodb/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-mysql/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-mysql/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-mysql/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-mysql/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-mysql/README.md delete mode 100644 plugins/node/opentelemetry-plugin-mysql/package.json delete mode 100644 plugins/node/opentelemetry-plugin-mysql/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-mysql/src/mysql.ts delete mode 100644 plugins/node/opentelemetry-plugin-mysql/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-mysql/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-mysql/test/mysql.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-mysql/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/README.md delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/package.json delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/enums.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/pg-pool.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg-pool/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-pg/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-pg/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-pg/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-pg/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-pg/README.md delete mode 100644 plugins/node/opentelemetry-plugin-pg/package.json delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/enums.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/pg.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/test/pg.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/test/utils.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-pg/tsconfig.json delete mode 100644 plugins/node/opentelemetry-plugin-redis/.eslintignore delete mode 100644 plugins/node/opentelemetry-plugin-redis/.eslintrc.js delete mode 100644 plugins/node/opentelemetry-plugin-redis/.npmignore delete mode 100644 plugins/node/opentelemetry-plugin-redis/LICENSE delete mode 100644 plugins/node/opentelemetry-plugin-redis/README.md delete mode 100644 plugins/node/opentelemetry-plugin-redis/package.json delete mode 100644 plugins/node/opentelemetry-plugin-redis/src/index.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/src/redis.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/src/types.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/src/utils.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/src/version.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/test/redis.test.ts delete mode 100644 plugins/node/opentelemetry-plugin-redis/tsconfig.json diff --git a/README.md b/README.md index f4c0a635e3..ac933641e7 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Contributing   •   - Plugins + Instrumentations   •   Propagators   •   @@ -46,37 +46,36 @@ core distribution of the API and SDK. ## Plugins -OpenTelemetry can collect tracing data automatically using plugins. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for: +OpenTelemetry can collect tracing data automatically using instrumentations. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for: ### Node Plugins -- [@opentelemetry/plugin-grpc][otel-plugin-grpc] -- [@opentelemetry/plugin-http][otel-plugin-http] -- [@opentelemetry/plugin-https][otel-plugin-https] -- [@opentelemetry/plugin-mongodb][otel-plugin-mongodb] -- [@opentelemetry/plugin-mysql][otel-plugin-mysql] -- [@opentelemetry/plugin-pg][otel-plugin-pg] -- [@opentelemetry/plugin-pg-pool][otel-plugin-pg-pool] -- [@opentelemetry/plugin-redis][otel-plugin-redis] -- [@opentelemetry/plugin-ioredis][otel-plugin-ioredis] -- [@opentelemetry/plugin-express][otel-plugin-express] -- [@opentelemetry/plugin-dns][otel-plugin-dns] -- [@opentelemetry/hapi-instrumentation][otel-contrib-hapi-instrumentation] +- [@opentelemetry/instrumentation-grpc][otel-instrumentation-grpc] +- [@opentelemetry/instrumentation-http][otel-instrumentation-http] +- [@opentelemetry/instrumentation-mongodb][otel-contrib-instrumentation-mongodb] +- [@opentelemetry/instrumentation-mysql][otel-contrib-instrumentation-mysql] +- [@opentelemetry/instrumentation-pg][otel-contrib-instrumentation-pg] +- [@opentelemetry/instrumentation-redis][otel-contrib-instrumentation-redis] +- [@opentelemetry/instrumentation-ioredis][otel-contrib-instrumentation-ioredis] +- [@opentelemetry/instrumentation-express][otel-contrib-instrumentation-express] +- [@opentelemetry/instrumentation-dns][otel-contrib-instrumentation-dns] +- [@opentelemetry/instrumentation-hapi][otel-contrib-instrumentation-hapi] - [@opentelemetry/instrumentation-koa][otel-contrib-instrumentation-koa] - [@opentelemetry/instrumentation-graphql][otel-contrib-instrumentation-graphql] ### Web Plugins -- [@opentelemetry/instrumentation-document-load][otel-instrumentation-document-load] - [@opentelemetry/instrumentation-xml-http-request][otel-instrumentation-xml-http-request] -- [@opentelemetry/instrumentation-user-interaction][otel-instrumentation-user-interaction] -- [@opentelemetry/plugin-react-load][otel-plugin-react-load] +- [@opentelemetry/instrumentation-document-load][otel-contrib-instrumentation-document-load] +- [@opentelemetry/instrumentation-user-interaction][otel-contrib-instrumentation-user-interaction] +- [@opentelemetry/plugin-react-load][otel-contrib-plugin-react-load] ### Metapackages Multiple plugins may be leveraged via metapackages. -- [@opentelemetry/plugins-node-core-and-contrib][otel-plugins-node-core-and-contrib] - all officially supported core and contrib plugins. +- [@opentelemetry/auto-instrumentations-node][otel-contrib-auto-instr-node] - Metapackage which bundles opentelemetry node core and contrib instrumentations +- [@opentelemetry/auto-instrumentations-web][otel-contrib-auto-instr-web] - Metapackage which bundles opentelemetry web core and contrib instrumentations ## Supported Runtimes @@ -116,22 +115,24 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE [up-for-grabs-issues]: https://github.com/open-telemetry/opentelemetry-js-contrib/issues?q=is%3Aissue+is%3Aopen+label%3Aup-for-grabs [good-first-issues]: https://github.com/open-telemetry/openTelemetry-js-contrib/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 -[otel-plugin-grpc]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-plugin-grpc -[otel-plugin-http]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-plugin-http -[otel-plugin-https]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-plugin-https -[otel-plugin-dns]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-dns -[otel-instrumentation-document-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load -[otel-plugin-react-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-plugin-react-load -[otel-plugin-ioredis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-ioredis -[otel-plugin-mongodb]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-mongodb -[otel-plugin-mysql]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-mysql -[otel-plugin-pg-pool]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-pg-pool -[otel-plugin-pg]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-pg -[otel-plugin-redis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-redis -[otel-instrumentation-user-interaction]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction + +[otel-instrumentation-grpc]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-grpc +[otel-instrumentation-http]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http [otel-instrumentation-xml-http-request]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-xml-http-request -[otel-plugin-express]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-express -[otel-plugins-node-core-and-contrib]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/plugins-node-core-and-contrib -[otel-contrib-hapi-instrumentation]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-hapi-instrumentation -[otel-contrib-instrumentation-koa]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa + +[otel-contrib-instrumentation-dns]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns +[otel-contrib-instrumentation-document-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load +[otel-contrib-instrumentation-express]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express [otel-contrib-instrumentation-graphql]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql +[otel-contrib-instrumentation-hapi]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi +[otel-contrib-instrumentation-ioredis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis +[otel-contrib-instrumentation-koa]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa +[otel-contrib-instrumentation-mongodb]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb +[otel-contrib-instrumentation-mysql]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql +[otel-contrib-instrumentation-pg]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg +[otel-contrib-instrumentation-redis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis +[otel-contrib-instrumentation-user-interaction]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction +[otel-contrib-plugin-react-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-plugin-react-load + +[otel-contrib-auto-instr-node]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node +[otel-contrib-auto-instr-web]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-web \ No newline at end of file diff --git a/metapackages/plugins-node-core-and-contrib/README.md b/metapackages/plugins-node-core-and-contrib/README.md deleted file mode 100644 index ccb1d574da..0000000000 --- a/metapackages/plugins-node-core-and-contrib/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# OpenTelemetry Plugins Node Core and Contrib - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![Apache License][license-image]][license-image] - -This package depends on all node plugins maintained by OpenTelemetry authors. -Installing it will also install all plugins. - -## Plugins - -In addition to all [node core plugins][otel-plugins-node-core], the following plugins will be installed by this package: - -- [@opentelemetry/plugin-express][otel-plugin-express] -- [@opentelemetry/plugin-ioredis][otel-plugin-ioredis] -- [@opentelemetry/plugin-mongodb][otel-plugin-mongodb] -- [@opentelemetry/plugin-mysql][otel-plugin-mysql] -- [@opentelemetry/plugin-pg-pool][otel-plugin-pg-pool] -- [@opentelemetry/plugin-pg][otel-plugin-pg] -- [@opentelemetry/plugin-redis][otel-plugin-redis] - -Note: [@opentelemetry/plugin-dns][otel-plugin-dns] is excluded by default because it requires some manual configuration to prevent infinite loops with exporters. - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=metapackages/plugins-node-core -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetryplugins-node-core -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugins-node-core-and-contrib -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugins-node-core-and-contrib.svg - -[otel-plugins-node-core]: https://www.npmjs.com/package/@opentelemetry/plugins-node-core - -[otel-plugin-dns]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-dns -[otel-plugin-express]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-express -[otel-plugin-ioredis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-ioredis -[otel-plugin-mongodb]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-mongodb -[otel-plugin-mysql]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-mysql -[otel-plugin-pg-pool]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-pg-pool -[otel-plugin-pg]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-pg -[otel-plugin-redis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-plugin-redis diff --git a/metapackages/plugins-node-core-and-contrib/package.json b/metapackages/plugins-node-core-and-contrib/package.json deleted file mode 100644 index ddc7c94d43..0000000000 --- a/metapackages/plugins-node-core-and-contrib/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@opentelemetry/plugins-node-core-and-contrib", - "version": "0.15.0", - "description": "Metapackage which bundles opentelemetry node core and contrib plugins", - "author": "OpenTelemetry Authors", - "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", - "license": "Apache-2.0", - "publishConfig": { - "access": "public" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/open-telemetry/opentelemetry-js.git" - }, - "bugs": { - "url": "https://github.com/open-telemetry/opentelemetry-js/issues" - }, - "dependencies": { - "@opentelemetry/plugin-express": "^0.15.0", - "@opentelemetry/plugin-ioredis": "^0.15.0", - "@opentelemetry/plugin-mongodb": "^0.15.0", - "@opentelemetry/plugin-mysql": "^0.15.0", - "@opentelemetry/plugin-pg": "^0.15.0", - "@opentelemetry/plugin-pg-pool": "^0.15.0", - "@opentelemetry/plugin-redis": "^0.15.0", - "@opentelemetry/plugins-node-core": "0.18.2" - } -} diff --git a/plugins/node/opentelemetry-instrumentation-dns/README.md b/plugins/node/opentelemetry-instrumentation-dns/README.md index 7aea2dfac9..9096546698 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/README.md +++ b/plugins/node/opentelemetry-instrumentation-dns/README.md @@ -31,12 +31,6 @@ registerInstrumentations({ new DnsInstrumentation({ // see under for available configuration }), - { - // be sure to disable old plugin but only if it was installed - plugins: { - dns: { enabled: false, path: '@opentelemetry/plugin-dns' } - }, - } ], tracerProvider: provider, }); diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/README.md b/plugins/node/opentelemetry-instrumentation-ioredis/README.md index 78eb4ba748..f3797173de 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/README.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/README.md @@ -37,13 +37,7 @@ registerInstrumentations({ instrumentations: [ new IORedisInstrumentation({ // see under for available configuration - }), - { - // be sure to disable old plugin but only if it was installed - plugins: { - ioredis: { enabled: false, path: '@opentelemetry/plugin-ioredis' } - }, - } + }) ], tracerProvider: provider, }) diff --git a/plugins/node/opentelemetry-instrumentation-mysql/README.md b/plugins/node/opentelemetry-instrumentation-mysql/README.md index cf136008c1..757c322155 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql/README.md @@ -36,12 +36,6 @@ provider.register(); registerInstrumentations({ instrumentations: [ new MySQLInstrumentation(), - { - // be sure to disable old plugin but only if it was installed - plugins: { - mysql: { enabled: false, path: '@opentelemetry/plugin-mysql' } - }, - } ], tracerProvider: provider, }) diff --git a/plugins/node/opentelemetry-plugin-dns/.eslintignore b/plugins/node/opentelemetry-plugin-dns/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-dns/.eslintrc.js b/plugins/node/opentelemetry-plugin-dns/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-dns/.npmignore b/plugins/node/opentelemetry-plugin-dns/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-dns/LICENSE b/plugins/node/opentelemetry-plugin-dns/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-dns/README.md b/plugins/node/opentelemetry-plugin-dns/README.md deleted file mode 100644 index 6faf40d934..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/README.md +++ /dev/null @@ -1,96 +0,0 @@ -# OpenTelemetry DNS Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`dns`](http://nodejs.org/dist/latest/docs/api/dns.html). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-dns -``` - -## Usage - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - dns: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-dns', - // dns plugin options - } - } - }, - ], - tracerProvider: provider, -}); - -``` - -### Zipkin - -If you use Zipkin, you must use `ignoreHostnames` in order to not trace those calls. If the server is local. You can set : - -```js -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - instrumentations: [ - { - plugins: { - dns: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-dns', - ignoreHostnames: ['localhost'] - } - } - }, - ], - tracerProvider: provider, -}); - -``` - -### Dns Plugin Options - -Dns plugin has currently one option. You can set the following: - -| Options | Type | Description | -| ------- | ---- | ----------- | -| [`ignoreHostnames`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-plugin-dns/src/types.ts#L98) | `IgnoreMatcher[]` | Dns plugin will not trace all requests that match hostnames | - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-dns -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-dns -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-dns&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-dns&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-dns -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-dns.svg diff --git a/plugins/node/opentelemetry-plugin-dns/package.json b/plugins/node/opentelemetry-plugin-dns/package.json deleted file mode 100644 index 758d0f373f..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@opentelemetry/plugin-dns", - "version": "0.15.0", - "description": "OpenTelemetry dns automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "precompile": "tsc --version", - "prepare": "npm run compile", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p ." - }, - "keywords": [ - "opentelemetry", - "dns", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/node": "0.18.2", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/semver": "7.3.1", - "@types/shimmer": "1.0.1", - "@types/sinon": "9.0.4", - "codecov": "3.7.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "10.0.0", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "semver": "^7.3.2", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-dns/src/dns.ts b/plugins/node/opentelemetry-plugin-dns/src/dns.ts deleted file mode 100644 index 752e989bb6..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/dns.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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 { BasePlugin } from '@opentelemetry/core'; -import { diag, Span, SpanKind, SpanOptions } from '@opentelemetry/api'; -import { LookupAddress } from 'dns'; -import * as semver from 'semver'; -import * as shimmer from 'shimmer'; -import { AddressFamily } from './enums/AddressFamily'; -import { AttributeNames } from './enums/AttributeNames'; -import { - Dns, - DnsPluginConfig, - LookupCallbackSignature, - LookupFunction, - LookupFunctionSignature, - LookupPromiseSignature, -} from './types'; -import * as utils from './utils'; -import { VERSION } from './version'; - -/** - * Dns instrumentation plugin for Opentelemetry - */ -export class DnsPlugin extends BasePlugin { - readonly component: string; - protected _config!: DnsPluginConfig; - - constructor(readonly moduleName: string, readonly version: string) { - super('@opentelemetry/plugin-dns', VERSION); - // For now component is equal to moduleName but it can change in the future. - this.component = this.moduleName; - this._config = {}; - } - - /** Patches DNS functions. */ - protected patch() { - diag.debug('applying patch to %s@%s', this.moduleName, this.version); - - shimmer.wrap<{ lookup: LookupFunction }, 'lookup'>( - this._moduleExports, - 'lookup', - // tslint:disable-next-line:no-any - this._getLookup() as any - ); - - // new promise methods in node >= 10.6.0 - // https://nodejs.org/docs/latest/api/dns.html#dns_dnspromises_lookup_hostname_options - if (semver.gte(this.version, '10.6.0')) { - shimmer.wrap( - this._moduleExports.promises, - 'lookup', - // tslint:disable-next-line:no-any - this._getLookup() as any - ); - } - - return this._moduleExports; - } - - /** Unpatches all DNS patched function. */ - protected unpatch(): void { - shimmer.unwrap(this._moduleExports, 'lookup'); - if (semver.gte(this.version, '10.6.0')) { - shimmer.unwrap(this._moduleExports.promises, 'lookup'); - } - } - - /** - * Get the patched lookup function - */ - private _getLookup() { - return (original: (hostname: string, ...args: unknown[]) => void) => { - return this._getPatchLookupFunction(original); - }; - } - - /** - * Creates spans for lookup operations, restoring spans' context if applied. - */ - private _getPatchLookupFunction( - original: (hostname: string, ...args: unknown[]) => void - ) { - diag.debug('patch lookup function'); - const plugin = this; - return function patchedLookup( - this: {}, - hostname: string, - ...args: unknown[] - ) { - if ( - utils.isIgnored(hostname, plugin._config.ignoreHostnames, (e: Error) => - diag.error('caught ignoreHostname error: ', e) - ) - ) { - return original.apply(this, [hostname, ...args]); - } - - const argsCount = args.length; - diag.debug('wrap lookup callback function and starts span'); - const name = utils.getOperationName('lookup'); - const span = plugin._startDnsSpan(name, { - attributes: { - [AttributeNames.PEER_HOSTNAME]: hostname, - }, - }); - - const originalCallback = args[argsCount - 1]; - if (typeof originalCallback === 'function') { - args[argsCount - 1] = plugin._wrapLookupCallback( - originalCallback, - args[argsCount - 2], - span - ); - return plugin._safeExecute(span, () => - // tslint:disable-next-line:no-any - (original as LookupFunctionSignature).apply(this, [ - hostname, - ...args, - ] as any) - ); - } else { - const promise = plugin._safeExecute(span, () => - (original as LookupPromiseSignature).apply(this, [hostname, ...args]) - ); - promise.then( - result => { - utils.setLookupAttributes(span, result as LookupAddress); - span.end(); - }, - (e: NodeJS.ErrnoException) => { - utils.setError(e, span, plugin.version); - span.end(); - } - ); - - return promise; - } - }; - } - - /** - * Start a new span with default attributes and kind - */ - private _startDnsSpan(name: string, options: Omit) { - return this._tracer - .startSpan(name, { ...options, kind: SpanKind.CLIENT }) - .setAttribute(AttributeNames.COMPONENT, this.component); - } - - /** - * Wrap lookup callback function - */ - private _wrapLookupCallback( - original: Function, - options: unknown, - span: Span - ): LookupCallbackSignature { - const plugin = this; - return function wrappedLookupCallback( - this: {}, - err: NodeJS.ErrnoException | null, - address: string | LookupAddress[], - family?: AddressFamily - ): void { - diag.debug('executing wrapped lookup callback function'); - - if (err !== null) { - utils.setError(err, span, plugin.version); - } else { - utils.setLookupAttributes(span, address, family); - } - - span.end(); - diag.debug('executing original lookup callback function'); - return original.apply(this, arguments); - }; - } - - /** - * Safely handle "execute" callback - */ - private _safeExecute ReturnType>( - span: Span, - execute: T - ): ReturnType { - try { - return execute(); - } catch (error) { - utils.setError(error, span, this.version); - span.end(); - throw error; - } - } -} -export const plugin = new DnsPlugin('dns', process.versions.node); diff --git a/plugins/node/opentelemetry-plugin-dns/src/enums/AddressFamily.ts b/plugins/node/opentelemetry-plugin-dns/src/enums/AddressFamily.ts deleted file mode 100644 index 57522ecc1d..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/enums/AddressFamily.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 enum AddressFamily { - IPV4 = 4, - IPV6 = 6, - UNKNOWN = 0, -} diff --git a/plugins/node/opentelemetry-plugin-dns/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-plugin-dns/src/enums/AttributeNames.ts deleted file mode 100644 index 384ea7dcb1..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/enums/AttributeNames.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 enum AttributeNames { - COMPONENT = 'component', - PEER_HOSTNAME = 'peer.hostname', - PEER_PORT = 'peer.port', - PEER_SERVICE = 'peer.service', - // NOT ON OFFICIAL SPEC - DNS_ERROR_CODE = 'dns.error_code', - DNS_ERROR_NAME = 'dns.error_name', - DNS_ERROR_MESSAGE = 'dns.error_message', -} diff --git a/plugins/node/opentelemetry-plugin-dns/src/index.ts b/plugins/node/opentelemetry-plugin-dns/src/index.ts deleted file mode 100644 index 9dd853e11a..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 './dns'; -export * from './types'; diff --git a/plugins/node/opentelemetry-plugin-dns/src/types.ts b/plugins/node/opentelemetry-plugin-dns/src/types.ts deleted file mode 100644 index 33c19642f1..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/types.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 * as dns from 'dns'; -import { PluginConfig } from '@opentelemetry/core'; - -export type Dns = typeof dns; - -export type IgnoreMatcher = string | RegExp | ((url: string) => boolean); - -export type LookupFunction = (( - hostname: string, - family: number, - callback: LookupSimpleCallback -) => void) & - (( - hostname: string, - options: dns.LookupOneOptions, - callback: LookupSimpleCallback - ) => void) & - (( - hostname: string, - options: dns.LookupAllOptions, - callback: ( - err: NodeJS.ErrnoException | null, - addresses: dns.LookupAddress[] - ) => void - ) => void) & - (( - hostname: string, - options: dns.LookupOptions, - callback: ( - err: NodeJS.ErrnoException | null, - address: string | dns.LookupAddress[], - family: number - ) => void - ) => void) & - ((hostname: string, callback: LookupSimpleCallback) => void); - -export type LookupSimpleArgs = [number, LookupSimpleCallback]; -export type LookupOneArgs = [dns.LookupOneOptions, LookupSimpleCallback]; -export type LookupAllArgs = [ - dns.LookupAllOptions, - (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void -]; -export type LookupArgs = [ - dns.LookupOptions, - ( - err: NodeJS.ErrnoException | null, - address: string | dns.LookupAddress[], - family: number - ) => void -]; -export type LookupArgSignature = LookupSimpleArgs & - LookupSimpleCallback & - LookupOneArgs & - LookupAllArgs & - LookupArgs; - -export type LookupFunctionSignature = ( - hostname: string, - args: Array -) => void; -export type LookupPromiseSignature = ( - hostname: string, - ...args: unknown[] -) => Promise; -export type LookupSimpleCallback = ( - err: NodeJS.ErrnoException | null, - address: string, - family: number -) => void; - -export type LookupCallbackSignature = LookupSimpleCallback & - (( - err: NodeJS.ErrnoException | null, - addresses: dns.LookupAddress[] - ) => void) & - (( - err: NodeJS.ErrnoException | null, - address: string | dns.LookupAddress[], - family: number - ) => void); - -export interface DnsPluginConfig extends PluginConfig { - ignoreHostnames?: IgnoreMatcher[]; -} diff --git a/plugins/node/opentelemetry-plugin-dns/src/utils.ts b/plugins/node/opentelemetry-plugin-dns/src/utils.ts deleted file mode 100644 index dac8751e3c..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/utils.ts +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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 { Span, SpanStatusCode, SpanAttributes } from '@opentelemetry/api'; -import { AttributeNames } from './enums/AttributeNames'; -import { AddressFamily } from './enums/AddressFamily'; -import * as dns from 'dns'; -import { IgnoreMatcher } from './types'; - -/** - * Set error attributes on the span passed in params - * @param err the error that we use for filling the attributes - * @param span the span to be set - * @param nodeVersion the node version - */ -export const setError = ( - err: NodeJS.ErrnoException, - span: Span, - nodeVersion: string -) => { - const { code, message, name } = err; - const attributes = { - [AttributeNames.DNS_ERROR_MESSAGE]: message, - [AttributeNames.DNS_ERROR_NAME]: name, - } as SpanAttributes; - - if (nodeVersion.startsWith('12')) { - attributes[AttributeNames.DNS_ERROR_CODE] = code!; - } - - span.setAttributes(attributes); - - span.setStatus({ - code: SpanStatusCode.ERROR, - message, - }); -}; - -/** - * Returns the family attribute name to be set on the span - * @param family `4` (ipv4) or `6` (ipv6). `0` means bug. - * @param [index] `4` (ipv4) or `6` (ipv6). `0` means bug. - */ -export const getFamilyAttribute = ( - family: AddressFamily, - index?: number -): string => { - return index ? `peer[${index}].ipv${family}` : `peer.ipv${family}`; -}; - -/** - * Returns the span name - * @param funcName function name that is wrapped (e.g `lookup`) - * @param [service] e.g `http` - */ -export const getOperationName = ( - funcName: string, - service?: string -): string => { - return service ? `dns.${service}/${funcName}` : `dns.${funcName}`; -}; - -export const setLookupAttributes = ( - span: Span, - address: string | dns.LookupAddress[] | dns.LookupAddress, - family?: number -) => { - const attributes = {} as SpanAttributes; - const isObject = typeof address === 'object'; - let addresses = address; - - if (!isObject) { - addresses = [{ address, family } as dns.LookupAddress]; - } else if (!(addresses instanceof Array)) { - addresses = [ - { - address: (address as dns.LookupAddress).address, - family: (address as dns.LookupAddress).family, - } as dns.LookupAddress, - ]; - } - - addresses.forEach((_, i) => { - const peerAttrFormat = getFamilyAttribute(_.family, i); - attributes[peerAttrFormat] = _.address; - }); - - span.setAttributes(attributes); -}; - -/** - * Check whether the given obj match pattern - * @param constant e.g URL of request - * @param pattern Match pattern - */ -export const satisfiesPattern = ( - constant: string, - pattern: IgnoreMatcher -): boolean => { - if (typeof pattern === 'string') { - return pattern === constant; - } else if (pattern instanceof RegExp) { - return pattern.test(constant); - } else if (typeof pattern === 'function') { - return pattern(constant); - } else { - throw new TypeError('Pattern is in unsupported datatype'); - } -}; - -/** - * Check whether the given dns request is ignored by configuration - * It will not re-throw exceptions from `list` provided by the client - * @param constant e.g URL of request - * @param [list] List of ignore patterns - * @param [onException] callback for doing something when an exception has - * occurred - */ -export const isIgnored = ( - constant: string, - list?: IgnoreMatcher[], - onException?: (error: Error) => void -): boolean => { - if (!list) { - // No ignored urls - trace everything - return false; - } - // Try/catch outside the loop for failing fast - try { - for (const pattern of list) { - if (satisfiesPattern(constant, pattern)) { - return true; - } - } - } catch (e) { - if (onException) { - onException(e); - } - } - - return false; -}; diff --git a/plugins/node/opentelemetry-plugin-dns/src/version.ts b/plugins/node/opentelemetry-plugin-dns/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts b/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts deleted file mode 100644 index a156db0d2c..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import { context } from '@opentelemetry/api'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { plugin } from '../../src/dns'; -import * as sinon from 'sinon'; -import * as dns from 'dns'; - -const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -const tracer = provider.getTracer('default'); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - -describe('DnsPlugin', () => { - before(() => { - plugin.enable(dns, provider); - assert.strictEqual(dns.lookup.__wrapped, true); - }); - - beforeEach(() => { - sinon.spy(tracer, 'startSpan'); - sinon.spy(context, 'with'); - }); - - afterEach(() => { - sinon.restore(); - }); - - describe('unpatch()', () => { - it('should not call tracer methods for creating span', done => { - plugin.disable(); - const hostname = 'localhost'; - - dns.lookup(hostname, (err, address, family) => { - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 0); - - assert.strictEqual(dns.lookup.__wrapped, undefined); - assert.strictEqual((context.with as sinon.SinonSpy).called, false); - done(); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts b/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts deleted file mode 100644 index 6659b4a6f8..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { plugin, DnsPlugin } from '../../src/dns'; -import * as dns from 'dns'; - -const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - -describe('DnsPlugin', () => { - before(() => { - plugin.enable(dns, provider); - }); - - after(() => { - plugin.disable(); - }); - - it('should return a plugin', () => { - assert.ok(plugin instanceof DnsPlugin); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-dns/test/functionals/utils.test.ts b/plugins/node/opentelemetry-plugin-dns/test/functionals/utils.test.ts deleted file mode 100644 index e4ef5645aa..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/functionals/utils.test.ts +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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 { BasicTracerProvider, Span } from '@opentelemetry/tracing'; -import { diag, ROOT_CONTEXT, SpanKind, TraceFlags } from '@opentelemetry/api'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import { AttributeNames } from '../../src/enums/AttributeNames'; -import { IgnoreMatcher } from '../../src/types'; -import * as utils from '../../src/utils'; - -describe('Utility', () => { - describe('satisfiesPattern()', () => { - it('string pattern', () => { - const answer1 = utils.satisfiesPattern('localhost', 'localhost'); - assert.strictEqual(answer1, true); - const answer2 = utils.satisfiesPattern('hostname', 'localhost'); - assert.strictEqual(answer2, false); - }); - - it('regex pattern', () => { - const answer1 = utils.satisfiesPattern('LocalHost', /localhost/i); - assert.strictEqual(answer1, true); - const answer2 = utils.satisfiesPattern('Montreal.ca', /montreal.ca/); - assert.strictEqual(answer2, false); - }); - - it('should throw if type is unknown', () => { - try { - utils.satisfiesPattern( - 'google.com', - (true as unknown) as IgnoreMatcher - ); - assert.fail(); - } catch (error) { - assert.strictEqual(error instanceof TypeError, true); - } - }); - - it('function pattern', () => { - const answer1 = utils.satisfiesPattern( - 'montreal.ca', - (url: string) => url === 'montreal.ca' - ); - assert.strictEqual(answer1, true); - const answer2 = utils.satisfiesPattern( - 'montreal.ca', - (url: string) => url !== 'montreal.ca' - ); - assert.strictEqual(answer2, false); - }); - }); - - describe('isIgnored()', () => { - let satisfiesPatternStub: sinon.SinonSpy<[string, IgnoreMatcher], boolean>; - beforeEach(() => { - satisfiesPatternStub = sinon.spy(utils, 'satisfiesPattern'); - }); - - afterEach(() => { - satisfiesPatternStub.restore(); - }); - - it('should call isSatisfyPattern, n match', () => { - const answer1 = utils.isIgnored('localhost', ['test']); - assert.strictEqual(answer1, false); - assert.strictEqual( - (utils.satisfiesPattern as sinon.SinonSpy).callCount, - 1 - ); - }); - - it('should call isSatisfyPattern, match for function', () => { - satisfiesPatternStub.restore(); - 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) => { - diag.error('error', e); - }; - for (const callback of [undefined, onException]) { - assert.doesNotThrow(() => - utils.isIgnored( - 'test', - [ - url => { - throw new Error('test'); - }, - ], - callback - ) - ); - } - }); - - it('should call onException when function throws an exception', () => { - satisfiesPatternStub.restore(); - const onException = sinon.spy(); - assert.doesNotThrow(() => - utils.isIgnored( - 'test', - [ - url => { - throw new Error('test'); - }, - ], - onException - ) - ); - assert.strictEqual((onException as sinon.SinonSpy).callCount, 1); - }); - - it('should not call isSatisfyPattern', () => { - utils.isIgnored('test', []); - assert.strictEqual( - (utils.satisfiesPattern as sinon.SinonSpy).callCount, - 0 - ); - }); - - it('should return false on empty list', () => { - const answer1 = utils.isIgnored('test', []); - assert.strictEqual(answer1, false); - }); - - it('should not throw and return false when list is undefined', () => { - const answer2 = utils.isIgnored('test', undefined); - assert.strictEqual(answer2, false); - }); - }); - - describe('setError()', () => { - it('should have error attributes', () => { - const errorMessage = 'test error'; - const span = new Span( - new BasicTracerProvider().getTracer('default'), - ROOT_CONTEXT, - 'test', - { spanId: '', traceId: '', traceFlags: TraceFlags.NONE }, - SpanKind.INTERNAL - ); - utils.setError(new Error(errorMessage), span, process.versions.node); - const attributes = span.attributes; - assert.strictEqual( - attributes[AttributeNames.DNS_ERROR_MESSAGE], - errorMessage - ); - assert.ok(attributes[AttributeNames.DNS_ERROR_NAME]); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts b/plugins/node/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts deleted file mode 100644 index 1233cc4874..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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 { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { plugin } from '../../src/dns'; -import * as dns from 'dns'; -import * as utils from '../utils/utils'; -import { assertSpan } from '../utils/assertSpan'; -import { SpanStatusCode } from '@opentelemetry/api'; - -const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - -describe('dns.lookup()', () => { - before(function (done) { - // mandatory - if (process.env.CI) { - plugin.enable(dns, provider); - done(); - return; - } - - utils.checkInternet(isConnected => { - if (!isConnected) { - this.skip(); - // don't disturbe people - } - done(); - }); - plugin.enable(dns, provider); - }); - - afterEach(() => { - memoryExporter.reset(); - }); - - after(() => { - plugin.disable(); - }); - - describe('with family param', () => { - [4, 6].forEach(ipversion => { - it(`should export a valid span with "family" arg to ${ipversion}`, done => { - const hostname = 'google.com'; - dns.lookup(hostname, ipversion, (err, address, family) => { - assert.strictEqual(err, null); - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses: [{ address, family }], hostname }); - done(); - }); - }); - }); - }); - - describe('with no options param', () => { - it('should export a valid span', done => { - const hostname = 'google.com'; - dns.lookup(hostname, (err, address, family) => { - assert.strictEqual(err, null); - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses: [{ address, family }], hostname }); - done(); - }); - }); - - it('should export a valid span with error NOT_FOUND', done => { - const hostname = 'áš•'; - dns.lookup(hostname, (err, address, family) => { - assert.ok(err); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [{ address, family }], - hostname, - forceStatus: { - code: SpanStatusCode.ERROR, - message: err!.message, - }, - }); - done(); - }); - }); - - it('should export a valid span with error INVALID_ARGUMENT when "family" param is equal to -1', () => { - const hostname = 'google.com'; - try { - dns.lookup(hostname, -1, () => {}); - assert.fail(); - } catch (error) { - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [], - hostname, - forceStatus: { - code: SpanStatusCode.ERROR, - message: error!.message, - }, - }); - } - }); - - it('should export a valid span with error INVALID_ARGUMENT when "hostname" param is a number', () => { - const hostname = 1234; - try { - // tslint:disable-next-line:no-any - dns.lookup(hostname as any, 4, () => {}); - assert.fail(); - } catch (error) { - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [], - // tslint:disable-next-line:no-any - hostname: hostname as any, - forceStatus: { - code: SpanStatusCode.ERROR, - message: error!.message, - }, - }); - } - }); - }); - describe('with options param', () => { - [4, 6].forEach(family => { - it(`should export a valid span with "family" to ${family}`, done => { - const hostname = 'google.com'; - dns.lookup(hostname, { family }, (err, address, family) => { - assert.strictEqual(err, null); - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - - assertSpan(span, { addresses: [{ address, family }], hostname }); - done(); - }); - }); - - it(`should export a valid span when setting "verbatim" property to true and "family" to ${family}`, done => { - const hostname = 'google.com'; - dns.lookup( - hostname, - { family, verbatim: true }, - (err, address, family) => { - assert.strictEqual(err, null); - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - - assertSpan(span, { addresses: [{ address, family }], hostname }); - done(); - } - ); - }); - }); - - it('should export a valid span when setting "all" property to true', done => { - const hostname = 'montreal.ca'; - dns.lookup( - hostname, - { all: true }, - (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => { - assert.strictEqual(err, null); - assert.ok(addresses instanceof Array); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses, hostname }); - done(); - } - ); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts b/plugins/node/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts deleted file mode 100644 index 1bc997571e..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts +++ /dev/null @@ -1,222 +0,0 @@ -/* - * 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 { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { plugin } from '../../src/dns'; -import * as dns from 'dns'; -import * as utils from '../utils/utils'; -import { assertSpan } from '../utils/assertSpan'; -import { SpanStatusCode } from '@opentelemetry/api'; - -const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - -async function lookupPromise( - hostname: string, - options: dns.LookupOptions = {} -): Promise { - return new Promise((resolve, reject) => { - dns.lookup(hostname, options, (err, address, family) => { - if (err) reject(err); - if (options.all) { - resolve(address); - } else { - resolve({ address, family }); - } - }); - }); -} - -describe('dns.promises.lookup()', () => { - before(function (done) { - // if node version is supported, it's mandatory for CI - if (process.env.CI) { - plugin.enable(dns, provider); - done(); - return; - } - - utils.checkInternet(isConnected => { - if (!isConnected) { - this.skip(); - // don't disturb people - } - done(); - }); - plugin.enable(dns, provider); - }); - - afterEach(() => { - memoryExporter.reset(); - }); - - after(() => { - plugin.disable(); - }); - - describe('with family param', () => { - [4, 6].forEach(ipversion => { - it(`should export a valid span with "family" arg to ${ipversion}`, async () => { - const hostname = 'google.com'; - const { address, family } = await lookupPromise(hostname, { - family: ipversion, - }); - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses: [{ address, family }], hostname }); - }); - }); - }); - - describe('with no options param', () => { - it('should export a valid span', async () => { - const hostname = 'google.com'; - const { address, family } = await lookupPromise(hostname); - - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses: [{ address, family }], hostname }); - }); - - it('should export a valid span with error NOT_FOUND', async () => { - const hostname = 'áš•'; - try { - await lookupPromise(hostname); - assert.fail(); - } catch (error) { - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [], - hostname, - forceStatus: { - code: SpanStatusCode.ERROR, - message: error!.message, - }, - }); - } - }); - - it('should export a valid span with error INVALID_ARGUMENT when "family" param is equal to -1', async () => { - const hostname = 'google.com'; - try { - await lookupPromise(hostname, { family: -1 }); - assert.fail(); - } catch (error) { - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [], - // tslint:disable-next-line:no-any - hostname: hostname as any, - forceStatus: { - code: SpanStatusCode.ERROR, - message: error!.message, - }, - }); - } - }); - - it('should export a valid span with error INVALID_ARGUMENT when "hostname" param is a number', async () => { - const hostname = 1234; - try { - // tslint:disable-next-line:no-any - await lookupPromise(hostname as any, { family: 4 }); - assert.fail(); - } catch (error) { - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - - assert.strictEqual(spans.length, 1); - assertSpan(span, { - addresses: [], - // tslint:disable-next-line:no-any - hostname: hostname as any, - forceStatus: { - code: SpanStatusCode.ERROR, - message: error!.message, - }, - }); - } - }); - }); - describe('with options param', () => { - [4, 6].forEach(ipversion => { - it(`should export a valid span with "family" to ${ipversion}`, async () => { - const hostname = 'google.com'; - const { address, family } = await lookupPromise(hostname, { - family: ipversion, - }); - - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - - assertSpan(span, { addresses: [{ address, family }], hostname }); - }); - - it(`should export a valid span when setting "verbatim" property to true and "family" to ${ipversion}`, async () => { - const hostname = 'google.com'; - const { address, family } = await lookupPromise(hostname, { - family: ipversion, - verbatim: true, - }); - - assert.ok(address); - assert.ok(family); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - - assertSpan(span, { addresses: [{ address, family }], hostname }); - }); - }); - - it('should export a valid span when setting "all" property to true', async () => { - const hostname = 'montreal.ca'; - const addresses = await lookupPromise(hostname, { all: true }); - - assert.ok(addresses instanceof Array); - - const spans = memoryExporter.getFinishedSpans(); - const [span] = spans; - assert.strictEqual(spans.length, 1); - assertSpan(span, { addresses, hostname }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-dns/test/utils/assertSpan.ts b/plugins/node/opentelemetry-plugin-dns/test/utils/assertSpan.ts deleted file mode 100644 index c52101d1ed..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/utils/assertSpan.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 { SpanKind, SpanStatus, SpanStatusCode } from '@opentelemetry/api'; -import { hrTimeToNanoseconds } from '@opentelemetry/core'; -import * as assert from 'assert'; -import { AttributeNames } from '../../src/enums/AttributeNames'; -import { ReadableSpan } from '@opentelemetry/tracing'; -import * as utils from '../../src/utils'; -import { LookupAddress } from 'dns'; - -export const assertSpan = ( - span: ReadableSpan, - validations: { - addresses: LookupAddress[]; - hostname: string; - forceStatus?: SpanStatus; - } -) => { - if (span.spanContext.traceId) { - assert.strictEqual(span.spanContext.traceId.length, 32); - } - if (span.spanContext.spanId) { - assert.strictEqual(span.spanContext.spanId.length, 16); - } - - assert.strictEqual(span.kind, SpanKind.CLIENT); - - assert.strictEqual(span.attributes[AttributeNames.COMPONENT], 'dns'); - assert.strictEqual( - span.attributes[AttributeNames.DNS_ERROR_MESSAGE], - span.status.message - ); - assert.strictEqual( - span.attributes[AttributeNames.PEER_HOSTNAME], - validations.hostname - ); - - validations.addresses.forEach((_, i) => { - assert.strictEqual( - span.attributes[utils.getFamilyAttribute(_.family, i)], - _.address - ); - }); - - assert.ok(span.endTime); - assert.strictEqual(span.links.length, 0); - assert.strictEqual(span.events.length, 0); - - assert.deepStrictEqual( - span.status, - validations.forceStatus || { code: SpanStatusCode.UNSET } - ); - - assert.ok(hrTimeToNanoseconds(span.duration), 'must have positive duration'); -}; diff --git a/plugins/node/opentelemetry-plugin-dns/test/utils/utils.ts b/plugins/node/opentelemetry-plugin-dns/test/utils/utils.ts deleted file mode 100644 index a4e37eabea..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/test/utils/utils.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 * as dns from 'dns'; - -export const checkInternet = (cb: (isConnected: boolean) => void) => { - dns.lookup('google.com', err => { - if (err && err.code === 'ENOTFOUND') { - cb(false); - } else { - cb(true); - } - }); -}; diff --git a/plugins/node/opentelemetry-plugin-dns/tsconfig.json b/plugins/node/opentelemetry-plugin-dns/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-dns/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-express/.eslintignore b/plugins/node/opentelemetry-plugin-express/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-express/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-express/.eslintrc.js b/plugins/node/opentelemetry-plugin-express/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-express/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-express/.npmignore b/plugins/node/opentelemetry-plugin-express/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-express/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-express/LICENSE b/plugins/node/opentelemetry-plugin-express/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-express/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-express/README.md b/plugins/node/opentelemetry-plugin-express/README.md deleted file mode 100644 index 41bebac483..0000000000 --- a/plugins/node/opentelemetry-plugin-express/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# OpenTelemetry Express Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`express`](https://github.com/expressjs/express). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-express -``` -### Supported Versions - - `^4.0.0` - -## Usage - -OpenTelemetry Express Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. - -To load a specific plugin (express in this case), specify it in the registerInstrumentations's configuration. -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - express: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-express', - } - } - }, - ], - tracerProvider: provider, -}); - -``` - -To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -See [examples/express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/express) for a short example. - -### Caveats - -Because of the way express works, it's hard to correctly compute the time taken by asynchronous middlewares and request handlers. For this reason, the time you'll see reported for asynchronous middlewares and request handlers will only represent the synchronous execution time, and **not** any asynchronous work. - -### Express Plugin Options - -Express plugin has few options available to choose from. You can set the following: - -| Options | Type | Description | -| ------- | ---- | ----------- | -| `ignoreLayers` | `IgnoreMatcher[]` | Express plugin will not trace all layers that match. | -| `ignoreLayersType`| `ExpressLayerType[]` | Express plugin will ignore the layers that match based on their type. | - -For reference, here are the three different layer type: - - `router` is the name of `express.Router()` - - `middleware` - - `request_handler` is the name for anything thats not a router or a middleware. - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-express -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-express -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-express&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-express&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-express -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-express.svg diff --git a/plugins/node/opentelemetry-plugin-express/package.json b/plugins/node/opentelemetry-plugin-express/package.json deleted file mode 100644 index 3ae9d9ca9e..0000000000 --- a/plugins/node/opentelemetry-plugin-express/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@opentelemetry/plugin-express", - "version": "0.15.0", - "description": "OpenTelemetry express automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts'", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "tdd": "yarn test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "prepare": "npm run compile", - "watch": "tsc -w" - }, - "keywords": [ - "opentelemetry", - "express", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/tracing": "0.18.2", - "@types/express": "4.17.7", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "express": "4.17.1", - "gts": "3.1.0", - "mocha": "7.2.0", - "nyc": "15.1.0", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-express/src/express.ts b/plugins/node/opentelemetry-plugin-express/src/express.ts deleted file mode 100644 index b4a19e14a1..0000000000 --- a/plugins/node/opentelemetry-plugin-express/src/express.ts +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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 { BasePlugin, hrTime } from '@opentelemetry/core'; -import { diag, SpanAttributes, getSpan, context } from '@opentelemetry/api'; -import * as express from 'express'; -import * as core from 'express-serve-static-core'; -import * as shimmer from 'shimmer'; -import { - ExpressLayer, - ExpressRouter, - AttributeNames, - PatchedRequest, - Parameters, - PathParams, - _LAYERS_STORE_PROPERTY, - ExpressPluginConfig, - ExpressLayerType, - ExpressPluginSpan, -} from './types'; -import { getLayerMetadata, storeLayerPath, isLayerIgnored } from './utils'; -import { VERSION } from './version'; - -/** - * This symbol is used to mark express layer as being already instrumented - * since its possible to use a given layer multiple times (ex: middlewares) - */ -export const kLayerPatched: unique symbol = Symbol('express-layer-patched'); - -/** Express instrumentation plugin for OpenTelemetry */ -export class ExpressPlugin extends BasePlugin { - static readonly component = 'express'; - readonly supportedVersions = ['^4.0.0']; - protected _config!: ExpressPluginConfig; - protected _logger = diag; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-express', VERSION); - } - - /** - * Patches Express operations. - */ - protected patch() { - diag.debug('Patching Express'); - - if (this._moduleExports === undefined || this._moduleExports === null) { - return this._moduleExports; - } - const routerProto = (this._moduleExports - .Router as unknown) as express.Router; - - this._logger.debug('patching express.Router.prototype.route'); - shimmer.wrap(routerProto, 'route', this._getRoutePatch.bind(this)); - - this._logger.debug('patching express.Router.prototype.use'); - shimmer.wrap(routerProto, 'use', this._getRouterUsePatch.bind(this)); - - this._logger.debug('patching express.Application.use'); - shimmer.wrap( - this._moduleExports.application, - 'use', - this._getAppUsePatch.bind(this) - ); - - return this._moduleExports; - } - - /** Unpatches all Express patched functions. */ - unpatch(): void { - const routerProto = (this._moduleExports - .Router as unknown) as express.Router; - shimmer.unwrap(routerProto, 'use'); - shimmer.unwrap(routerProto, 'route'); - shimmer.unwrap(this._moduleExports.application, 'use'); - } - - /** - * Get the patch for Router.route function - * @param original - */ - private _getRoutePatch(original: (path: PathParams) => express.IRoute) { - const plugin = this; - return function route_trace( - this: ExpressRouter, - ...args: Parameters - ) { - const route = original.apply(this, args); - const layer = this.stack[this.stack.length - 1] as ExpressLayer; - plugin._applyPatch( - layer, - typeof args[0] === 'string' ? args[0] : undefined - ); - return route; - }; - } - - /** - * Get the patch for Router.use function - * @param original - */ - private _getRouterUsePatch( - original: express.IRouterHandler & - express.IRouterMatcher - ) { - const plugin = this; - return function use( - this: express.Application, - ...args: Parameters - ) { - const route = original.apply(this, args); - const layer = this.stack[this.stack.length - 1] as ExpressLayer; - plugin._applyPatch( - layer, - typeof args[0] === 'string' ? args[0] : undefined - ); - return route; - // tslint:disable-next-line:no-any - } as any; - } - - /** - * Get the patch for Application.use function - * @param original - */ - private _getAppUsePatch( - original: core.ApplicationRequestHandler - ) { - const plugin = this; - return function use( - this: { _router: ExpressRouter }, - ...args: Parameters - ) { - const route = original.apply(this, args); - const layer = this._router.stack[this._router.stack.length - 1]; - plugin._applyPatch( - layer, - typeof args[0] === 'string' ? args[0] : undefined - ); - return route; - // tslint:disable-next-line:no-any - } as any; - } - - /** Patch each express layer to create span and propagate context */ - private _applyPatch(layer: ExpressLayer, layerPath?: string) { - const plugin = this; - if (layer[kLayerPatched] === true) return; - layer[kLayerPatched] = true; - this._logger.debug('patching express.Router.Layer.handle'); - shimmer.wrap(layer, 'handle', (original: Function) => { - if (original.length === 4) return original; - - return function ( - this: ExpressLayer, - req: PatchedRequest, - res: express.Response, - next: express.NextFunction - ) { - storeLayerPath(req, layerPath); - const route = (req[_LAYERS_STORE_PROPERTY] as string[]) - .filter(path => path !== '/' && path !== '/*') - .join(''); - const attributes: SpanAttributes = { - [AttributeNames.COMPONENT]: ExpressPlugin.component, - [AttributeNames.HTTP_ROUTE]: route.length > 0 ? route : undefined, - }; - const metadata = getLayerMetadata(layer, layerPath); - const type = metadata.attributes[ - AttributeNames.EXPRESS_TYPE - ] as ExpressLayerType; - - // Rename the root http span in case we haven't done it already - // once we reach the request handler - if ( - metadata.attributes[AttributeNames.EXPRESS_TYPE] === - ExpressLayerType.REQUEST_HANDLER - ) { - const parent = getSpan(context.active()) as ExpressPluginSpan; - if (parent?.name) { - const parentRoute = parent.name.split(' ')[1]; - if (!route.includes(parentRoute)) { - parent.updateName(`${req.method} ${route}`); - } - } - } - - // verify against the config if the layer should be ignored - if (isLayerIgnored(metadata.name, type, plugin._config)) { - return original.apply(this, arguments); - } - if (getSpan(context.active()) === undefined) { - return original.apply(this, arguments); - } - - const span = plugin._tracer.startSpan(metadata.name, { - attributes: Object.assign(attributes, metadata.attributes), - }); - const startTime = hrTime(); - let spanHasEnded = false; - // If we found anything that isnt a middleware, there no point of measuring - // their time since they dont have callback. - if ( - metadata.attributes[AttributeNames.EXPRESS_TYPE] !== - ExpressLayerType.MIDDLEWARE - ) { - span.end(startTime); - spanHasEnded = true; - } - // listener for response.on('finish') - const onResponseFinish = () => { - if (spanHasEnded === false) { - spanHasEnded = true; - span.end(startTime); - } - }; - // verify we have a callback - const args = Array.from(arguments); - const callbackIdx = args.findIndex(arg => typeof arg === 'function'); - if (callbackIdx >= 0) { - arguments[callbackIdx] = function () { - if (spanHasEnded === false) { - spanHasEnded = true; - req.res?.removeListener('finish', onResponseFinish); - span.end(); - } - if (!(req.route && arguments[0] instanceof Error)) { - (req[_LAYERS_STORE_PROPERTY] as string[]).pop(); - } - const callback = args[callbackIdx] as Function; - return context.bind(callback).apply(this, arguments); - }; - } - const result = original.apply(this, arguments); - /** - * At this point if the callback wasn't called, that means either the - * layer is asynchronous (so it will call the callback later on) or that - * the layer directly end the http response, so we'll hook into the "finish" - * event to handle the later case. - */ - if (!spanHasEnded) { - req.res?.once('finish', onResponseFinish); - } - return result; - }; - }); - } -} - -export const plugin = new ExpressPlugin(ExpressPlugin.component); diff --git a/plugins/node/opentelemetry-plugin-express/src/index.ts b/plugins/node/opentelemetry-plugin-express/src/index.ts deleted file mode 100644 index da51d32e0b..0000000000 --- a/plugins/node/opentelemetry-plugin-express/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './express'; diff --git a/plugins/node/opentelemetry-plugin-express/src/types.ts b/plugins/node/opentelemetry-plugin-express/src/types.ts deleted file mode 100644 index d22f62aa7d..0000000000 --- a/plugins/node/opentelemetry-plugin-express/src/types.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 { kLayerPatched } from './express'; -import { Request } from 'express'; -import { SpanAttributes, Span } from '@opentelemetry/api'; -import { PluginConfig } from '@opentelemetry/core'; - -/** - * This const define where on the `request` object the plugin will mount the - * current stack of express layer. - * - * It is necessary because express doesnt store the different layers - * (ie: middleware, router etc) that it called to get to the current layer. - * Given that, the only way to know the route of a given layer is to - * store the path of where each previous layer has been mounted. - * - * ex: bodyParser > auth middleware > /users router > get /:id - * in this case the stack would be: ["/users", "/:id"] - * - * ex2: bodyParser > /api router > /v1 router > /users router > get /:id - * stack: ["/api", "/v1", "/users", ":id"] - * - */ -export const _LAYERS_STORE_PROPERTY = '__ot_middlewares'; - -export type Parameters = T extends (...args: infer T) => any ? T : unknown[]; -export type PatchedRequest = { - [_LAYERS_STORE_PROPERTY]?: string[]; -} & Request; -export type PathParams = string | RegExp | Array; - -// https://github.com/expressjs/express/blob/main/lib/router/index.js#L53 -export type ExpressRouter = { - params: { [key: string]: string }; - _params: string[]; - caseSensitive: boolean; - mergeParams: boolean; - strict: boolean; - stack: ExpressLayer[]; -}; - -// https://github.com/expressjs/express/blob/main/lib/router/layer.js#L33 -export type ExpressLayer = { - handle: Function; - [kLayerPatched]?: boolean; - name: string; - params: { [key: string]: string }; - path: string; - regexp: RegExp; -}; - -export type LayerMetadata = { - attributes: SpanAttributes; - name: string; -}; - -// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-semantic-conventions.md#databases-client-calls -export enum AttributeNames { - COMPONENT = 'component', - HTTP_ROUTE = 'http.route', - EXPRESS_TYPE = 'express.type', - EXPRESS_NAME = 'express.name', -} - -export enum ExpressLayerType { - ROUTER = 'router', - MIDDLEWARE = 'middleware', - REQUEST_HANDLER = 'request_handler', -} - -export type IgnoreMatcher = string | RegExp | ((name: string) => boolean); - -/** - * Options available for the Express Plugin (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-plugin-express#express-plugin-options)) - */ -export interface ExpressPluginConfig extends PluginConfig { - /** Ignore specific based on their name */ - ignoreLayers?: IgnoreMatcher[]; - /** Ignore specific layers based on their type */ - ignoreLayersType?: ExpressLayerType[]; -} - -/** - * extends opentelemetry/api Span object to instrument the root span name of http plugin - */ -export interface ExpressPluginSpan extends Span { - name?: string; -} diff --git a/plugins/node/opentelemetry-plugin-express/src/utils.ts b/plugins/node/opentelemetry-plugin-express/src/utils.ts deleted file mode 100644 index ccd559b5d4..0000000000 --- a/plugins/node/opentelemetry-plugin-express/src/utils.ts +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 { SpanAttributes } from '@opentelemetry/api'; -import { - ExpressLayer, - AttributeNames, - PatchedRequest, - _LAYERS_STORE_PROPERTY, - ExpressLayerType, - IgnoreMatcher, - ExpressPluginConfig, -} from './types'; - -/** - * Store layers path in the request to be able to construct route later - * @param request The request where - * @param [value] the value to push into the array - */ -export const storeLayerPath = (request: PatchedRequest, value?: string) => { - if (Array.isArray(request[_LAYERS_STORE_PROPERTY]) === false) { - Object.defineProperty(request, _LAYERS_STORE_PROPERTY, { - enumerable: false, - value: [], - }); - } - if (value === undefined) return; - (request[_LAYERS_STORE_PROPERTY] as string[]).push(value); -}; - -/** - * Parse express layer context to retrieve a name and attributes. - * @param layer Express layer - * @param [layerPath] if present, the path on which the layer has been mounted - */ -export const getLayerMetadata = ( - layer: ExpressLayer, - layerPath?: string -): { - attributes: SpanAttributes; - name: string; -} => { - if (layer.name === 'router') { - return { - attributes: { - [AttributeNames.EXPRESS_NAME]: layerPath, - [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER, - }, - name: `router - ${layerPath}`, - }; - } else if (layer.name === 'bound dispatch') { - return { - attributes: { - [AttributeNames.EXPRESS_NAME]: layerPath ?? 'request handler', - [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER, - }, - name: `request handler${layer.path ? ` - ${layerPath}` : ''}`, - }; - } else { - return { - attributes: { - [AttributeNames.EXPRESS_NAME]: layer.name, - [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE, - }, - name: `middleware - ${layer.name}`, - }; - } -}; - -/** - * Check whether the given obj match pattern - * @param constant e.g URL of request - * @param obj obj to inspect - * @param pattern Match pattern - */ -const satisfiesPattern = ( - constant: string, - pattern: IgnoreMatcher -): boolean => { - if (typeof pattern === 'string') { - return pattern === constant; - } else if (pattern instanceof RegExp) { - return pattern.test(constant); - } else if (typeof pattern === 'function') { - return pattern(constant); - } else { - throw new TypeError('Pattern is in unsupported datatype'); - } -}; - -/** - * Check whether the given request is ignored by configuration - * It will not re-throw exceptions from `list` provided by the client - * @param constant e.g URL of request - * @param [list] List of ignore patterns - * @param [onException] callback for doing something when an exception has - * occurred - */ -export const isLayerIgnored = ( - name: string, - type: ExpressLayerType, - config?: ExpressPluginConfig -): boolean => { - if ( - Array.isArray(config?.ignoreLayersType) && - config?.ignoreLayersType?.includes(type) - ) { - return true; - } - if (Array.isArray(config?.ignoreLayers) === false) return false; - try { - for (const pattern of config!.ignoreLayers!) { - if (satisfiesPattern(name, pattern)) { - return true; - } - } - } catch (e) { - /* catch block*/ - } - - return false; -}; diff --git a/plugins/node/opentelemetry-plugin-express/src/version.ts b/plugins/node/opentelemetry-plugin-express/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-express/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-express/test/express.test.ts b/plugins/node/opentelemetry-plugin-express/test/express.test.ts deleted file mode 100644 index b869cd2bc7..0000000000 --- a/plugins/node/opentelemetry-plugin-express/test/express.test.ts +++ /dev/null @@ -1,472 +0,0 @@ -/* - * 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 { context, setSpan, Span, Tracer } from '@opentelemetry/api'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as express from 'express'; -import * as http from 'http'; -import { AddressInfo } from 'net'; -import { plugin } from '../src'; -import { - AttributeNames, - ExpressLayerType, - ExpressPluginConfig, - ExpressPluginSpan, -} from '../src/types'; - -const httpRequest = { - get: (options: http.ClientRequestArgs | string) => { - return new Promise((resolve, reject) => { - return http.get(options, resp => { - let data = ''; - resp.on('data', chunk => { - data += chunk; - }); - resp.on('end', () => { - resolve(data); - }); - resp.on('error', err => { - reject(err); - }); - }); - }); - }, -}; - -const serverWithMiddleware = async ( - tracer: Tracer, - rootSpan: Span, - addMiddlewares: (app: express.Express) => void -): Promise => { - const app = express(); - if (tracer) { - app.use((req, res, next) => - context.with(setSpan(context.active(), rootSpan), next) - ); - } - - app.use(express.json()); - - addMiddlewares(app); - - const router = express.Router(); - app.use('/toto', router); - router.get('/:id', (req, res) => { - setImmediate(() => { - res.status(200).end(req.params.id); - }); - }); - const server = http.createServer(app); - await new Promise(resolve => - server.listen(0, () => { - resolve(); - }) - ); - - return server; -}; - -describe('Express Plugin', () => { - const provider = new NodeTracerProvider(); - const memoryExporter = new InMemorySpanExporter(); - const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); - const tracer = provider.getTracer('default'); - let contextManager: AsyncHooksContextManager; - - before(() => { - plugin.enable(express, provider); - }); - - beforeEach(() => { - contextManager = new AsyncHooksContextManager(); - context.setGlobalContextManager(contextManager.enable()); - }); - - afterEach(() => { - memoryExporter.reset(); - context.disable(); - }); - - describe('Instrumenting normal get operations', () => { - it('should create a child span for middlewares', async () => { - const rootSpan = tracer.startSpan('rootSpan') as ExpressPluginSpan; - const app = express(); - app.use((req, res, next) => - context.with(setSpan(context.active(), rootSpan), next) - ); - app.use(express.json()); - const customMiddleware: express.RequestHandler = (req, res, next) => { - for (let i = 0; i < 1000000; i++) { - continue; - } - return next(); - }; - app.use(customMiddleware); - const router = express.Router(); - app.use('/toto', router); - let finishListenerCount: number | undefined; - const server = await serverWithMiddleware(tracer, rootSpan, app => { - app.use((req, res, next) => { - res.on('finish', () => { - finishListenerCount = res.listenerCount('finish'); - }); - next(); - }); - for (let index = 0; index < 15; index++) { - app.use(customMiddleware); - } - }); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - const response = await httpRequest.get( - `http://localhost:${port}/toto/tata` - ); - assert.strictEqual(response, 'tata'); - rootSpan.end(); - assert.strictEqual(rootSpan.name, 'GET /toto/:id'); - assert.strictEqual(finishListenerCount, 2); - assert.notStrictEqual( - memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('customMiddleware')), - undefined - ); - assert.notStrictEqual( - memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('jsonParser')), - undefined - ); - const requestHandlerSpan = memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('request handler')); - assert.notStrictEqual(requestHandlerSpan, undefined); - assert.strictEqual( - requestHandlerSpan?.attributes[AttributeNames.COMPONENT], - 'express' - ); - assert.strictEqual( - requestHandlerSpan?.attributes[AttributeNames.HTTP_ROUTE], - '/toto/:id' - ); - assert.strictEqual( - requestHandlerSpan?.attributes[AttributeNames.EXPRESS_TYPE], - 'request_handler' - ); - const exportedRootSpan = memoryExporter - .getFinishedSpans() - .find(span => span.name === 'GET /toto/:id'); - assert.notStrictEqual(exportedRootSpan, undefined); - }); - server.close(); - }); - - it('supports sync middlewares directly responding', async () => { - const rootSpan = tracer.startSpan('rootSpan'); - let finishListenerCount: number | undefined; - const server = await serverWithMiddleware(tracer, rootSpan, app => { - app.use((req, res, next) => { - res.on('finish', () => { - finishListenerCount = res.listenerCount('finish'); - }); - next(); - }); - const syncMiddleware: express.RequestHandler = (req, res, next) => { - for (let i = 0; i < 1000000; i++) { - continue; - } - res.status(200).end('middleware'); - }; - for (let index = 0; index < 15; index++) { - app.use(syncMiddleware); - } - }); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - const response = await httpRequest.get( - `http://localhost:${port}/toto/tata` - ); - assert.strictEqual(response, 'middleware'); - rootSpan.end(); - assert.strictEqual(finishListenerCount, 3); - assert.notStrictEqual( - memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('syncMiddleware')), - undefined, - 'no syncMiddleware span' - ); - }); - server.close(); - }); - - it('supports async middlewares', async () => { - const rootSpan = tracer.startSpan('rootSpan'); - let finishListenerCount: number | undefined; - const server = await serverWithMiddleware(tracer, rootSpan, app => { - app.use((req, res, next) => { - res.on('finish', () => { - finishListenerCount = res.listenerCount('finish'); - }); - next(); - }); - const asyncMiddleware: express.RequestHandler = (req, res, next) => { - setTimeout(() => { - next(); - }, 50); - }; - for (let index = 0; index < 15; index++) { - app.use(asyncMiddleware); - } - }); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - const response = await httpRequest.get( - `http://localhost:${port}/toto/tata` - ); - assert.strictEqual(response, 'tata'); - rootSpan.end(); - assert.strictEqual(finishListenerCount, 2); - assert.notStrictEqual( - memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('asyncMiddleware')), - undefined, - 'no asyncMiddleware span' - ); - }); - server.close(); - }); - - it('supports async middlewares directly responding', async () => { - const rootSpan = tracer.startSpan('rootSpan'); - let finishListenerCount: number | undefined; - const server = await serverWithMiddleware(tracer, rootSpan, app => { - app.use((req, res, next) => { - res.on('finish', () => { - finishListenerCount = res.listenerCount('finish'); - }); - next(); - }); - const asyncMiddleware: express.RequestHandler = (req, res, next) => { - setTimeout(() => { - res.status(200).end('middleware'); - }, 50); - }; - for (let index = 0; index < 15; index++) { - app.use(asyncMiddleware); - } - }); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - const response = await httpRequest.get( - `http://localhost:${port}/toto/tata` - ); - assert.strictEqual(response, 'middleware'); - rootSpan.end(); - assert.strictEqual(finishListenerCount, 3); - assert.notStrictEqual( - memoryExporter - .getFinishedSpans() - .find(span => span.name.includes('asyncMiddleware')), - undefined, - 'no asyncMiddleware span' - ); - }); - server.close(); - }); - - it('should not create span because there are no parent', async () => { - const app = express(); - app.use(express.json()); - app.use((req, res, next) => { - for (let i = 0; i < 1000000; i++) {} - return next(); - }); - const router = express.Router(); - app.use('/toto', router); - router.get('/:id', (req, res, next) => { - return res.status(200).end('test'); - }); - const server = http.createServer(app); - await new Promise(resolve => server.listen(0, resolve)); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - const res = await httpRequest.get(`http://localhost:${port}/toto/tata`); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - assert.strictEqual(res, 'test'); - server.close(); - }); - }); - - describe('Instrumenting with specific config', () => { - it('should ignore specific middlewares based on config', async () => { - plugin.disable(); - const config: ExpressPluginConfig = { - ignoreLayersType: [ExpressLayerType.MIDDLEWARE], - }; - plugin.enable(express, provider, config); - const rootSpan = tracer.startSpan('rootSpan'); - const app = express(); - app.use(express.json()); - app.use((req, res, next) => { - for (let i = 0; i < 1000; i++) { - continue; - } - return next(); - }); - const server = http.createServer(app); - await new Promise(resolve => server.listen(0, resolve)); - - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - await httpRequest.get(`http://localhost:${port}/toto/tata`); - rootSpan.end(); - assert.deepEqual( - memoryExporter - .getFinishedSpans() - .filter( - span => - span.attributes[AttributeNames.EXPRESS_TYPE] === - ExpressLayerType.MIDDLEWARE - ).length, - 0 - ); - const exportedRootSpan = memoryExporter - .getFinishedSpans() - .find(span => span.name === 'rootSpan'); - assert.notStrictEqual(exportedRootSpan, undefined); - }); - server.close(); - }); - }); - - describe('when route exists', () => { - let server: http.Server; - let rootSpan: ExpressPluginSpan; - const config: ExpressPluginConfig = { - ignoreLayersType: [ - ExpressLayerType.MIDDLEWARE, - ExpressLayerType.ROUTER, - ExpressLayerType.REQUEST_HANDLER, - ], - }; - - beforeEach(async () => { - plugin.disable(); - plugin.enable(express, provider, config); - rootSpan = tracer.startSpan('rootSpan') as ExpressPluginSpan; - const app = express(); - app.use((req, res, next) => - context.with(setSpan(context.active(), rootSpan), next) - ); - app.use(express.json()); - app.use((req, res, next) => { - for (let i = 0; i < 1000; i++) {} - return next(); - }); - const router = express.Router(); - app.use('/toto', router); - router.get('/:id', (req, res) => { - setImmediate(() => { - res.status(200).end(); - }); - }); - - server = http.createServer(app); - await new Promise(resolve => server.listen(0, resolve)); - }); - - afterEach(() => { - server.close(); - }); - - it('should ignore all ExpressLayerType based on config', async () => { - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - await httpRequest.get(`http://localhost:${port}/toto/tata`); - rootSpan.end(); - assert.deepStrictEqual( - memoryExporter - .getFinishedSpans() - .filter( - span => - span.attributes[AttributeNames.EXPRESS_TYPE] === - ExpressLayerType.MIDDLEWARE || - span.attributes[AttributeNames.EXPRESS_TYPE] === - ExpressLayerType.ROUTER || - span.attributes[AttributeNames.EXPRESS_TYPE] === - ExpressLayerType.REQUEST_HANDLER - ).length, - 0 - ); - }); - }); - - it('root span name should be modified to GET /todo/:id', async () => { - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - await httpRequest.get(`http://localhost:${port}/toto/tata`); - rootSpan.end(); - assert.strictEqual(rootSpan.name, 'GET /toto/:id'); - const exportedRootSpan = memoryExporter - .getFinishedSpans() - .find(span => span.name === 'GET /toto/:id'); - assert.notStrictEqual(exportedRootSpan, undefined); - }); - }); - }); - - describe('Disabling plugin', () => { - it('should not create new spans', async () => { - plugin.disable(); - const rootSpan = tracer.startSpan('rootSpan'); - const app = express(); - app.use(express.json()); - app.use((req, res, next) => { - for (let i = 0; i < 1000; i++) { - continue; - } - return next(); - }); - const server = http.createServer(app); - await new Promise(resolve => server.listen(0, resolve)); - const port = (server.address() as AddressInfo).port; - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - await context.with(setSpan(context.active(), rootSpan), async () => { - await httpRequest.get(`http://localhost:${port}/toto/tata`); - rootSpan.end(); - assert.deepEqual(memoryExporter.getFinishedSpans().length, 1); - assert.notStrictEqual(memoryExporter.getFinishedSpans()[0], undefined); - }); - server.close(); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-express/test/utils.test.ts b/plugins/node/opentelemetry-plugin-express/test/utils.test.ts deleted file mode 100644 index 38a7176211..0000000000 --- a/plugins/node/opentelemetry-plugin-express/test/utils.test.ts +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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 * as utils from '../src/utils'; -import * as assert from 'assert'; -import { - ExpressLayerType, - ExpressPluginConfig, - ExpressLayer, - AttributeNames, -} from '../src/types'; - -describe('Utils', () => { - describe('isLayerIgnored()', () => { - it('should not fail with invalid config', () => { - assert.doesNotThrow(() => - utils.isLayerIgnored('', ExpressLayerType.MIDDLEWARE) - ); - assert.doesNotThrow(() => - utils.isLayerIgnored( - '', - ExpressLayerType.MIDDLEWARE, - {} as ExpressPluginConfig - ) - ); - assert.doesNotThrow(() => - utils.isLayerIgnored('', ExpressLayerType.MIDDLEWARE, { - ignoreLayersType: {}, - } as ExpressPluginConfig) - ); - assert.doesNotThrow(() => - utils.isLayerIgnored('', ExpressLayerType.MIDDLEWARE, { - ignoreLayersType: {}, - ignoreLayers: {}, - } as ExpressPluginConfig) - ); - }); - - it('should ignore based on type', () => { - assert.deepEqual( - utils.isLayerIgnored('', ExpressLayerType.MIDDLEWARE, { - ignoreLayersType: [ExpressLayerType.MIDDLEWARE], - }), - true - ); - assert.deepEqual( - utils.isLayerIgnored('', ExpressLayerType.ROUTER, { - ignoreLayersType: [ExpressLayerType.MIDDLEWARE], - }), - false - ); - }); - - it('should ignore based on the name', () => { - assert.deepEqual( - utils.isLayerIgnored('bodyParser', ExpressLayerType.MIDDLEWARE, { - ignoreLayers: ['bodyParser'], - }), - true - ); - assert.deepEqual( - utils.isLayerIgnored('bodyParser', ExpressLayerType.MIDDLEWARE, { - ignoreLayers: [(name: string) => name === 'bodyParser'], - }), - true - ); - assert.deepEqual( - utils.isLayerIgnored('bodyParser', ExpressLayerType.MIDDLEWARE, { - ignoreLayers: [/bodyParser/], - }), - true - ); - assert.deepEqual( - utils.isLayerIgnored('test', ExpressLayerType.ROUTER, { - ignoreLayers: ['bodyParser'], - }), - false - ); - }); - }); - - describe('getLayerMetadata()', () => { - it('should return router metadata', () => { - assert.deepEqual( - utils.getLayerMetadata( - { - name: 'router', - } as ExpressLayer, - '/test' - ), - { - attributes: { - [AttributeNames.EXPRESS_NAME]: '/test', - [AttributeNames.EXPRESS_TYPE]: 'router', - }, - name: 'router - /test', - } - ); - }); - - it('should return request handler metadata', () => { - assert.deepEqual( - utils.getLayerMetadata( - { - name: 'bound dispatch', - } as ExpressLayer, - '/:id' - ), - { - attributes: { - [AttributeNames.EXPRESS_NAME]: '/:id', - [AttributeNames.EXPRESS_TYPE]: 'request_handler', - }, - name: 'request handler', - } - ); - }); - - it('should return middleware metadata', () => { - assert.deepEqual( - utils.getLayerMetadata({ - name: 'bodyParser', - } as ExpressLayer), - { - attributes: { - [AttributeNames.EXPRESS_NAME]: 'bodyParser', - [AttributeNames.EXPRESS_TYPE]: 'middleware', - }, - name: 'middleware - bodyParser', - } - ); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-express/tsconfig.json b/plugins/node/opentelemetry-plugin-express/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-express/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-ioredis/.eslintignore b/plugins/node/opentelemetry-plugin-ioredis/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-ioredis/.eslintrc.js b/plugins/node/opentelemetry-plugin-ioredis/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-ioredis/.npmignore b/plugins/node/opentelemetry-plugin-ioredis/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-ioredis/LICENSE b/plugins/node/opentelemetry-plugin-ioredis/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-ioredis/README.md b/plugins/node/opentelemetry-plugin-ioredis/README.md deleted file mode 100644 index 347ee6df00..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# OpenTelemetry ioredis Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`ioredis`](https://github.com/luin/ioredis). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -``` -npm install --save @opentelemetry/plugin-ioredis -``` - -### Supported Versions - - `>=2.0.0` - -## Usage - -To load a specific plugin (**ioredis** in this case), specify it in the registerInstrumentations's configuration -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - ioredis: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-ioredis', - } - } - }, - ], - tracerProvider: provider, -}); - -``` - -To load all of the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. -```javascript -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - tracerProvider: provider, -}); - -``` - -### IORedis Plugin Options - -IORedis plugin has few options available to choose from. You can set the following: - -| Options | Type | Description | -| ------- | ---- | ----------- | -| `dbStatementSerializer` | `DbStatementSerializer` | IORedis plugin will serialize db.statement using the specified function. | - -#### Custom db.statement Serializer -The plugin serializes the whole command into a Span attribute called `db.statement`. The standard serialization format is `{cmdName} {cmdArgs.join(',')}`. -It is also possible to define a custom serialization function. The function will receive the command name and arguments and must return a string. - -Here is a simple example to serialize the command name skipping arguments: - -```javascript -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider({ - plugins: { - ioredis: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-ioredis', - dbStatementSerializer: function (cmdName, cmdArgs) { - return cmdName; - } - } - } -}); - -``` - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-ioredis -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-ioredis -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-ioredis&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-ioredis&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-ioredis -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-ioredis.svg diff --git a/plugins/node/opentelemetry-plugin-ioredis/package.json b/plugins/node/opentelemetry-plugin-ioredis/package.json deleted file mode 100644 index d7add7729f..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@opentelemetry/plugin-ioredis", - "version": "0.15.0", - "description": "OpenTelemetry ioredis automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", - "test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "prepare": "npm run compile" - }, - "keywords": [ - "opentelemetry", - "ioredis", - "redis", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/test-utils": "^0.15.0", - "@opentelemetry/tracing": "0.18.2", - "@types/ioredis": "4.17.3", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "cross-env": "7.0.2", - "gts": "3.1.0", - "ioredis": "4.17.3", - "mocha": "7.2.0", - "nyc": "15.1.0", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/index.ts b/plugins/node/opentelemetry-plugin-ioredis/src/index.ts deleted file mode 100644 index 98bfff0f0d..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './ioredis'; diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts b/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts deleted file mode 100644 index 37d9010d6d..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 { diag } from '@opentelemetry/api'; -import { BasePlugin } from '@opentelemetry/core'; -import type * as ioredisTypes from 'ioredis'; -import * as shimmer from 'shimmer'; -import { IoredisPluginConfig } from './types'; -import { traceConnection, traceSendCommand } from './utils'; -import { VERSION } from './version'; - -export class IORedisPlugin extends BasePlugin { - static readonly DB_SYSTEM = 'redis'; - readonly supportedVersions = ['>1 <5']; - protected _config!: IoredisPluginConfig; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-ioredis', VERSION); - } - - protected patch(): typeof ioredisTypes { - diag.debug('Patching ioredis.prototype.sendCommand'); - shimmer.wrap( - this._moduleExports.prototype, - 'sendCommand', - this._patchSendCommand() - ); - - diag.debug('patching ioredis.prototype.connect'); - shimmer.wrap( - this._moduleExports.prototype, - 'connect', - this._patchConnection() - ); - - return this._moduleExports; - } - - protected unpatch(): void { - if (this._moduleExports) { - shimmer.unwrap(this._moduleExports.prototype, 'sendCommand'); - shimmer.unwrap(this._moduleExports.prototype, 'connect'); - } - } - - /** - * Patch send command internal to trace requests - */ - private _patchSendCommand() { - const tracer = this._tracer; - return (original: Function) => { - return traceSendCommand(tracer, original, plugin._config); - }; - } - - private _patchConnection() { - const tracer = this._tracer; - return (original: Function) => { - return traceConnection(tracer, original); - }; - } -} - -export const plugin = new IORedisPlugin('ioredis'); diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/types.ts b/plugins/node/opentelemetry-plugin-ioredis/src/types.ts deleted file mode 100644 index 09246ace00..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/types.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 * as ioredisTypes from 'ioredis'; -import { PluginConfig } from '@opentelemetry/core'; - -export interface IoredisCommand { - reject: (err: Error) => void; - resolve: (result: {}) => void; - promise: Promise<{}>; - args: Array; - callback: ioredisTypes.CallbackFunction; - name: string; -} - -/** - * Function that can be used to serialize db.statement tag - * @param cmdName - The name of the command (eg. set, get, mset) - * @param cmdArgs - Array of arguments passed to the command - * - * @returns serialized string that will be used as the db.statement attribute. - */ -export type DbStatementSerializer = ( - cmdName: IoredisCommand['name'], - cmdArgs: IoredisCommand['args'] -) => string; - -/** - * Options available for the IORedis Plugin (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-plugin-ioredis#ioredis-plugin-options)) - */ -export interface IoredisPluginConfig extends PluginConfig { - /** Custom serializer function for the db.statement tag */ - dbStatementSerializer?: DbStatementSerializer; -} diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts b/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts deleted file mode 100644 index 08b86ae9c0..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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 * as ioredisTypes from 'ioredis'; -import { - Tracer, - SpanKind, - Span, - SpanStatusCode, - getSpan, - context, -} from '@opentelemetry/api'; -import { - IoredisCommand, - IoredisPluginConfig, - DbStatementSerializer, -} from './types'; -import { IORedisPlugin } from './ioredis'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -const endSpan = (span: Span, err: NodeJS.ErrnoException | null | undefined) => { - if (err) { - span.recordException(err); - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }); - } - span.end(); -}; - -export const traceConnection = (tracer: Tracer, original: Function) => { - return function (this: ioredisTypes.Redis) { - const span = tracer.startSpan('connect', { - kind: SpanKind.CLIENT, - attributes: { - [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, - [DatabaseAttribute.DB_STATEMENT]: 'connect', - }, - }); - const { host, port } = this.options; - - span.setAttributes({ - [GeneralAttribute.NET_PEER_NAME]: host, - [GeneralAttribute.NET_PEER_PORT]: port, - [GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`, - }); - try { - const client = original.apply(this, arguments); - endSpan(span, null); - return client; - } catch (error) { - endSpan(span, error); - throw error; - } - }; -}; - -const defaultDbStatementSerializer: DbStatementSerializer = ( - cmdName, - cmdArgs -) => - Array.isArray(cmdArgs) && cmdArgs.length - ? `${cmdName} ${cmdArgs.join(' ')}` - : cmdName; - -export const traceSendCommand = ( - tracer: Tracer, - original: Function, - config?: IoredisPluginConfig -) => { - const dbStatementSerializer = - config?.dbStatementSerializer || defaultDbStatementSerializer; - return function (this: ioredisTypes.Redis, cmd?: IoredisCommand) { - if (arguments.length < 1 || typeof cmd !== 'object') { - return original.apply(this, arguments); - } - // Do not trace if there is not parent span - if (getSpan(context.active()) === undefined) { - return original.apply(this, arguments); - } - - const span = tracer.startSpan(cmd.name, { - kind: SpanKind.CLIENT, - attributes: { - [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, - [DatabaseAttribute.DB_STATEMENT]: dbStatementSerializer( - cmd.name, - cmd.args - ), - }, - }); - - const { host, port } = this.options; - - span.setAttributes({ - [GeneralAttribute.NET_PEER_NAME]: host, - [GeneralAttribute.NET_PEER_PORT]: port, - [GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`, - }); - - try { - const result = original.apply(this, arguments); - - const origResolve = cmd.resolve; - /* eslint-disable @typescript-eslint/no-explicit-any */ - cmd.resolve = function (result: any) { - endSpan(span, null); - origResolve(result); - }; - - const origReject = cmd.reject; - cmd.reject = function (err: Error) { - endSpan(span, err); - origReject(err); - }; - - return result; - } catch (error) { - endSpan(span, error); - throw error; - } - }; -}; diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/version.ts b/plugins/node/opentelemetry-plugin-ioredis/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts deleted file mode 100644 index 2f2607ead3..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts +++ /dev/null @@ -1,708 +0,0 @@ -/* - * 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 { - SpanStatusCode, - context, - SpanKind, - SpanStatus, - getSpan, - setSpan, -} from '@opentelemetry/api'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import * as testUtils from '@opentelemetry/test-utils'; -import { - InMemorySpanExporter, - ReadableSpan, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as ioredisTypes from 'ioredis'; -import { IORedisPlugin, plugin } from '../src'; -import { IoredisPluginConfig, DbStatementSerializer } from '../src/types'; -import { - DatabaseAttribute, - ExceptionAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -const memoryExporter = new InMemorySpanExporter(); - -const CONFIG = { - host: process.env.OPENTELEMETRY_REDIS_HOST || 'localhost', - port: parseInt(process.env.OPENTELEMETRY_REDIS_PORT || '63790', 10), -}; - -const URL = `redis://${CONFIG.host}:${CONFIG.port}`; - -const DEFAULT_ATTRIBUTES = { - [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, - [GeneralAttribute.NET_PEER_NAME]: CONFIG.host, - [GeneralAttribute.NET_PEER_PORT]: CONFIG.port, - [GeneralAttribute.NET_PEER_ADDRESS]: URL, -}; - -const unsetStatus: SpanStatus = { - code: SpanStatusCode.UNSET, -}; - -const predictableStackTrace = - '-- Stack trace replaced by test to predictable value -- '; -const sanitizeEventForAssertion = (span: ReadableSpan) => { - span.events.forEach(e => { - // stack trace includes data such as /user/{userName}/repos/{projectName} - if (e.attributes?.[ExceptionAttribute.STACKTRACE]) { - e.attributes[ExceptionAttribute.STACKTRACE] = predictableStackTrace; - } - - // since time will change on each test invocation, it is being replaced to predicable value - e.time = [0, 0]; - }); -}; - -describe('ioredis', () => { - const provider = new NodeTracerProvider(); - let ioredis: typeof ioredisTypes; - const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; - const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; - - let contextManager: AsyncHooksContextManager; - beforeEach(() => { - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(() => { - context.disable(); - }); - - before(function () { - // needs to be "function" to have MochaContext "this" context - if (!shouldTest) { - // this.skip() workaround - // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 - this.test!.parent!.pending = true; - this.skip(); - } - - if (shouldTestLocal) { - testUtils.startDocker('redis'); - } - - ioredis = require('ioredis'); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - plugin.enable(ioredis, provider); - }); - - after(() => { - if (shouldTestLocal) { - testUtils.cleanUpDocker('redis'); - } - }); - - it('should have correct module name', () => { - assert.strictEqual(plugin.moduleName, 'ioredis'); - }); - - describe('#createClient()', () => { - it('should propagate the current span to event handlers', done => { - const span = provider.getTracer('ioredis-test').startSpan('test span'); - let client: ioredisTypes.Redis; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: 'connect', - }; - const readyHandler = () => { - const endedSpans = memoryExporter.getFinishedSpans(); - - assert.strictEqual(getSpan(context.active()), span); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, 'connect'); - assert.strictEqual(endedSpans[1].name, 'info'); - testUtils.assertPropagation(endedSpans[0], span); - - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - span.end(); - assert.strictEqual(endedSpans.length, 3); - assert.strictEqual(endedSpans[2].name, 'test span'); - - client.quit(() => { - assert.strictEqual(endedSpans.length, 4); - assert.strictEqual(endedSpans[3].name, 'quit'); - done(); - }); - }; - const errorHandler = (err: Error) => { - assert.ifError(err); - client.quit(done); - }; - - context.with(setSpan(context.active(), span), () => { - client = new ioredis(URL); - client.on('ready', readyHandler); - client.on('error', errorHandler); - }); - }); - }); - - describe('#send_internal_message()', () => { - // use a random part in key names because redis instance is used for parallel running tests - const randomId = ((Math.random() * 2 ** 32) >>> 0).toString(16); - const testKeyName = `test-${randomId}`; - const hashKeyName = `hash-${randomId}`; - - let client: ioredisTypes.Redis; - - const IOREDIS_CALLBACK_OPERATIONS: Array<{ - description: string; - name: string; - args: Array; - method: (cb: ioredisTypes.CallbackFunction) => unknown; - }> = [ - { - description: 'insert', - name: 'hset', - args: [hashKeyName, 'testField', 'testValue'], - method: (cb: ioredisTypes.CallbackFunction) => - client.hset(hashKeyName, 'testField', 'testValue', cb), - }, - { - description: 'get', - name: 'get', - args: [testKeyName], - method: (cb: ioredisTypes.CallbackFunction) => - client.get(testKeyName, cb), - }, - ]; - - before(done => { - client = new ioredis(URL); - client.on('error', err => { - done(err); - }); - client.on('ready', done); - }); - - beforeEach(async () => { - await client.set(testKeyName, 'data'); - memoryExporter.reset(); - }); - - after(done => { - client.quit(done); - }); - - afterEach(async () => { - await client.del(hashKeyName); - await client.del(testKeyName); - memoryExporter.reset(); - }); - - describe('Instrumenting query operations', () => { - IOREDIS_CALLBACK_OPERATIONS.forEach(command => { - it(`should create a child span for cb style ${command.description}`, done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: `${ - command.name - } ${command.args.join(' ')}`, - }; - const span = provider - .getTracer('ioredis-test') - .startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - command.method((err, _result) => { - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, command.name); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }); - }); - }); - }); - - it('should create a child span for hset promise', async () => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: `hset ${hashKeyName} random random`, - }; - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - await client.hset(hashKeyName, 'random', 'random'); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, 'hset'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - } catch (error) { - assert.ifError(error); - } - }); - }); - - it('should set span with error when redis return reject', async () => { - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - await client.set('non-int-key', 'non-int-value'); - try { - // should throw 'ReplyError: ERR value is not an integer or out of range' - // because the value im the key is not numeric and we try to increment it - await client.incr('non-int-key'); - } catch (ex) { - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - const ioredisSpan = endedSpans[1]; - // redis 'incr' operation failed with exception, so span should indicate it - assert.strictEqual(ioredisSpan.status.code, SpanStatusCode.ERROR); - const exceptionEvent = ioredisSpan.events[0]; - assert.strictEqual(exceptionEvent.name, 'exception'); - assert.strictEqual( - exceptionEvent.attributes?.[ExceptionAttribute.MESSAGE], - ex.message - ); - assert.strictEqual( - exceptionEvent.attributes?.[ExceptionAttribute.STACKTRACE], - ex.stack - ); - assert.strictEqual( - exceptionEvent.attributes?.[ExceptionAttribute.TYPE], - ex.name - ); - } - }); - }); - - it('should create a child span for streamify scanning', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: 'scan 0', - }; - const span = provider.getTracer('ioredis-test').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const stream = client.scanStream(); - stream - .on('data', resultKeys => { - // `resultKeys` is an array of strings representing key names. - // Note that resultKeys may contain 0 keys, and that it will sometimes - // contain duplicates due to SCAN's implementation in Redis. - for (let i = 0; i < resultKeys.length; i++) { - console.log(resultKeys[i]); - } - }) - .on('end', () => { - console.log('all keys have been visited'); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, 'scan'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }) - .on('error', err => { - done(err); - }); - }); - }); - - it('should create a child span for pubsub', async () => { - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - // use lazyConnect so we can call the `connect` function and await it. - // this ensures that all operations are sequential and predictable. - const pub = new ioredis(URL, { lazyConnect: true }); - await pub.connect(); - const sub = new ioredis(URL, { lazyConnect: true }); - await sub.connect(); - await sub.subscribe('news', 'music'); - await pub.publish('news', 'Hello world!'); - await pub.publish('music', 'Hello again!'); - await sub.unsubscribe('news', 'music'); - await sub.quit(); - await pub.quit(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 10); - span.end(); - assert.strictEqual(endedSpans.length, 11); - const spanNames = [ - 'connect', - 'info', - 'connect', - 'info', - 'subscribe', - 'publish', - 'publish', - 'unsubscribe', - 'quit', - 'quit', - 'test span', - ]; - let i = 0; - while (i < 11) { - assert.strictEqual(endedSpans[i].name, spanNames[i]); - i++; - } - - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: 'subscribe news music', - }; - testUtils.assertSpan( - endedSpans[4], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - } catch (error) { - assert.ifError(error); - } - }); - }); - - it('should create a child span for lua', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`, - }; - - const span = provider.getTracer('ioredis-test').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - // This will define a command echo: - client.defineCommand('echo', { - numberOfKeys: 1, - lua: 'return {KEYS[1],ARGV[1]}', - }); - // Now `echo` can be used just like any other ordinary command, - // and ioredis will try to use `EVALSHA` internally when possible for better performance. - client.echo(testKeyName, (err, result) => { - assert.ifError(err); - - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - const evalshaSpan = endedSpans[0]; - // the script may be already cached on server therefore we get either 2 or 3 spans - if (endedSpans.length === 3) { - assert.strictEqual(endedSpans[2].name, 'test span'); - assert.strictEqual(endedSpans[1].name, 'eval'); - assert.strictEqual(endedSpans[0].name, 'evalsha'); - // in this case, server returns NOSCRIPT error for evalsha, - // telling the client to use EVAL instead - sanitizeEventForAssertion(evalshaSpan); - testUtils.assertSpan( - evalshaSpan, - SpanKind.CLIENT, - attributes, - [ - { - attributes: { - [ExceptionAttribute.MESSAGE]: - 'NOSCRIPT No matching script. Please use EVAL.', - [ExceptionAttribute.STACKTRACE]: predictableStackTrace, - [ExceptionAttribute.TYPE]: 'ReplyError', - }, - name: 'exception', - time: [0, 0], - }, - ], - { - code: SpanStatusCode.ERROR, - } - ); - } else { - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[1].name, 'test span'); - assert.strictEqual(endedSpans[0].name, 'evalsha'); - testUtils.assertSpan( - evalshaSpan, - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - } - testUtils.assertPropagation(evalshaSpan, span); - done(); - }); - }); - }); - - it('should create a child span for multi/transaction', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: 'multi', - }; - - const span = provider.getTracer('ioredis-test').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - client - .multi() - .set('foo', 'bar') - .get('foo') - .exec((err, _results) => { - assert.ifError(err); - - assert.strictEqual(memoryExporter.getFinishedSpans().length, 4); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 5); - assert.strictEqual(endedSpans[0].name, 'multi'); - assert.strictEqual(endedSpans[1].name, 'set'); - assert.strictEqual(endedSpans[2].name, 'get'); - assert.strictEqual(endedSpans[3].name, 'exec'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }); - }); - }); - - it('should create a child span for pipeline', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: 'set foo bar', - }; - - const span = provider.getTracer('ioredis-test').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const pipeline = client.pipeline(); - pipeline.set('foo', 'bar'); - pipeline.del('cc'); - pipeline.exec((err, results) => { - assert.ifError(err); - - assert.strictEqual(memoryExporter.getFinishedSpans().length, 2); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 3); - assert.strictEqual(endedSpans[0].name, 'set'); - assert.strictEqual(endedSpans[1].name, 'del'); - assert.strictEqual(endedSpans[2].name, 'test span'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }); - }); - }); - - it('should create a child span for get promise', async () => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: `get ${testKeyName}`, - }; - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - const value = await client.get(testKeyName); - assert.strictEqual(value, 'data'); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, 'get'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - } catch (error) { - assert.ifError(error); - } - }); - }); - - it('should create a child span for del', async () => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: `del ${testKeyName}`, - }; - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - const result = await client.del(testKeyName); - assert.strictEqual(result, 1); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, 'del'); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - } catch (error) { - assert.ifError(error); - } - }); - }); - }); - - describe('Instrumenting without parent span', () => { - before(() => { - plugin.disable(); - plugin.enable(ioredis, provider); - }); - it('should not create child span', async () => { - await client.set(testKeyName, 'data'); - const result = await client.del(testKeyName); - assert.strictEqual(result, 1); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - }); - }); - - describe('Instrumenting with a custom db.statement serializer', () => { - const dbStatementSerializer: DbStatementSerializer = (cmdName, cmdArgs) => - `FOOBAR_${cmdName}: ${cmdArgs[0]}`; - before(() => { - plugin.disable(); - const config: IoredisPluginConfig = { - dbStatementSerializer, - }; - plugin.enable(ioredis, provider, config); - }); - - IOREDIS_CALLBACK_OPERATIONS.forEach(command => { - it(`should tag the span with a custom db.statement for cb style ${command.description}`, done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: dbStatementSerializer( - command.name, - command.args - ), - }; - const span = provider - .getTracer('ioredis-test') - .startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - command.method((err, _result) => { - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual(endedSpans[0].name, command.name); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }); - }); - }); - }); - }); - - describe('Removing instrumentation', () => { - before(() => { - plugin.disable(); - }); - - IOREDIS_CALLBACK_OPERATIONS.forEach(operation => { - it(`should not create a child span for cb style ${operation.description}`, done => { - const span = provider - .getTracer('ioredis-test') - .startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - operation.method((err, _) => { - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 1); - assert.strictEqual(endedSpans[0], span); - done(); - }); - }); - }); - }); - - it('should not create a child span for hset promise upon error', async () => { - const span = provider.getTracer('ioredis-test').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - await client.hset(hashKeyName, 'random', 'random'); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 1); - assert.strictEqual(endedSpans[0].name, 'test span'); - } catch (error) { - assert.ifError(error); - } - }); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-ioredis/tsconfig.json b/plugins/node/opentelemetry-plugin-ioredis/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-mongodb/.eslintignore b/plugins/node/opentelemetry-plugin-mongodb/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-mongodb/.eslintrc.js b/plugins/node/opentelemetry-plugin-mongodb/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-mongodb/.npmignore b/plugins/node/opentelemetry-plugin-mongodb/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-mongodb/LICENSE b/plugins/node/opentelemetry-plugin-mongodb/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-mongodb/README.md b/plugins/node/opentelemetry-plugin-mongodb/README.md deleted file mode 100644 index 49b735b743..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# OpenTelemetry mongodb Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`mongodb`](https://github.com/mongodb/node-mongodb-native). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-mongodb -``` -### Supported Versions - - `'>=2.0.0 <4` - -## Usage - -OpenTelemetry Mongodb Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. - -To load a specific plugin (mongodb in this case), specify it in the registerInstrumentations's configuration. -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - mongodb: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-mongodb', - } - }, - }, - ], - tracerProvider: provider, -}); - -``` - -To load all of the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -See [examples/mongodb](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/mongodb) for a short example. - -### Mongo Plugin Options - -Mongodb plugin has few options available to choose from. You can set the following: - -| Options | Type | Description | -| ------- | ---- | ----------- | -| [`enhancedDatabaseReporting`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-api/src/trace/instrumentation/Plugin.ts#L91) | `string` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations | - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-mongodb -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-mongodb -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-mongodb&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-mongodb&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-mongodb -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-mongodb.svg diff --git a/plugins/node/opentelemetry-plugin-mongodb/package.json b/plugins/node/opentelemetry-plugin-mongodb/package.json deleted file mode 100644 index 59e7e89330..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@opentelemetry/plugin-mongodb", - "version": "0.15.0", - "description": "OpenTelemetry mongodb automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "prepare": "npm run compile" - }, - "keywords": [ - "opentelemetry", - "mongodb", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/mongodb": "3.5.25", - "@types/node": "14.0.27", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "mongodb": "3.5.9", - "nyc": "15.1.0", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-mongodb/src/index.ts b/plugins/node/opentelemetry-plugin-mongodb/src/index.ts deleted file mode 100644 index 7312679b34..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './mongodb'; diff --git a/plugins/node/opentelemetry-plugin-mongodb/src/mongodb.ts b/plugins/node/opentelemetry-plugin-mongodb/src/mongodb.ts deleted file mode 100644 index 98a7f8fff5..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/src/mongodb.ts +++ /dev/null @@ -1,267 +0,0 @@ -/* - * 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 { BasePlugin } from '@opentelemetry/core'; -import { - diag, - getSpan, - SpanStatusCode, - Span, - SpanKind, - context, -} from '@opentelemetry/api'; -import type * as mongodb from 'mongodb'; -import * as shimmer from 'shimmer'; -import { - Func, - MongodbCommandType, - MongoInternalCommand, - MongoInternalTopology, -} from './types'; -import { VERSION } from './version'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -/** MongoDBCore instrumentation plugin for OpenTelemetry */ -export class MongoDBPlugin extends BasePlugin { - private readonly _SERVER_METHODS = ['insert', 'update', 'remove', 'command']; - private readonly _CURSOR_METHODS = ['_next', 'next']; - private _hasPatched: boolean = false; - - readonly supportedVersions = ['>=2 <4']; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-mongodb-core', VERSION); - } - - /** - * Patches MongoDB operations. - */ - protected patch() { - diag.debug('Patching MongoDB'); - if (this._hasPatched === true) { - diag.debug('Patch is already applied, ignoring.'); - return this._moduleExports; - } - - if (this._moduleExports.Server) { - for (const fn of this._SERVER_METHODS) { - diag.debug(`patching mongodb.Server.prototype.${fn}`); - shimmer.wrap( - this._moduleExports.Server.prototype, - // Forced to cast due to incomplete typings - fn as any, - this._getPatchCommand(fn) - ); - } - } - - if (this._moduleExports.Cursor) { - diag.debug( - 'patching mongodb.Cursor.prototype functions:', - this._CURSOR_METHODS - ); - shimmer.massWrap( - [this._moduleExports.Cursor.prototype], - this._CURSOR_METHODS as never[], - // tslint:disable-next-line:no-any - this._getPatchCursor() as any - ); - } - - this._hasPatched = true; - return this._moduleExports; - } - - /** Unpatches all MongoDB patched functions. */ - unpatch(): void { - shimmer.massUnwrap( - [this._moduleExports.Server.prototype], - this._SERVER_METHODS as never[] - ); - shimmer.massUnwrap( - [this._moduleExports.Cursor.prototype], - this._CURSOR_METHODS as never[] - ); - } - - /** Creates spans for Command operations */ - private _getPatchCommand(operationName: string) { - const plugin = this; - return (original: Func) => { - return function patchedServerCommand( - this: mongodb.Server, - ns: string, - commands: MongoInternalCommand[] | MongoInternalCommand, - options: {} | Function, - callback: Function - ): mongodb.Server { - const currentSpan = getSpan(context.active()); - const resultHandler = - typeof options === 'function' ? options : callback; - if ( - !currentSpan || - typeof resultHandler !== 'function' || - typeof commands !== 'object' - ) { - return original.apply(this, (arguments as unknown) as unknown[]); - } - const command = commands instanceof Array ? commands[0] : commands; - const commandType = plugin._getCommandType(command); - const type = - commandType === MongodbCommandType.UNKNOWN - ? operationName - : commandType; - const span = plugin._tracer.startSpan(`mongodb.${type}`, { - kind: SpanKind.CLIENT, - }); - plugin._populateAttributes( - span, - ns, - command, - this as MongoInternalTopology - ); - return original.call( - this, - ns, - commands, - plugin._patchEnd(span, resultHandler) - ); - }; - }; - } - - /** - * Get the mongodb command type from the object. - * @param command Internal mongodb command object - */ - private _getCommandType(command: MongoInternalCommand): MongodbCommandType { - if (command.createIndexes !== undefined) { - return MongodbCommandType.CREATE_INDEXES; - } else if (command.findandmodify !== undefined) { - return MongodbCommandType.FIND_AND_MODIFY; - } else if (command.ismaster !== undefined) { - return MongodbCommandType.IS_MASTER; - } else if (command.count !== undefined) { - return MongodbCommandType.COUNT; - } else { - return MongodbCommandType.UNKNOWN; - } - } - - /** - * Populate span's attributes by fetching related metadata from the context - * @param span span to add attributes to - * @param ns mongodb namespace - * @param command mongodb internal representation of a command - * @param topology mongodb internal representation of the network topology - */ - private _populateAttributes( - span: Span, - ns: string, - command: MongoInternalCommand, - topology: MongoInternalTopology - ) { - // add network attributes to determine the remote server - if (topology && topology.s) { - span.setAttributes({ - [GeneralAttribute.NET_HOST_NAME]: `${ - topology.s.options?.host ?? topology.s.host - }`, - [GeneralAttribute.NET_HOST_PORT]: `${ - topology.s.options?.port ?? topology.s.port - }`, - }); - } - - // The namespace is a combination of the database name and the name of the - // collection or index, like so: [database-name].[collection-or-index-name]. - // It could be a string or an instance of MongoDBNamespace, as such we - // always coerce to a string to extract db and collection. - const [dbName, dbCollection] = ns.toString().split('.'); - - // add database related attributes - span.setAttributes({ - [DatabaseAttribute.DB_SYSTEM]: 'mongodb', - [DatabaseAttribute.DB_NAME]: dbName, - [DatabaseAttribute.DB_MONGODB_COLLECTION]: dbCollection, - }); - - if (command === undefined) return; - - // capture parameters within the query as well if enhancedDatabaseReporting is enabled. - const commandObj = command.query ?? command.q ?? command; - const query = - this._config?.enhancedDatabaseReporting === true - ? commandObj - : Object.keys(commandObj).reduce((obj, key) => { - obj[key] = '?'; - return obj; - }, {} as { [key: string]: unknown }); - - span.setAttribute('db.statement', JSON.stringify(query)); - } - - /** Creates spans for Cursor operations */ - private _getPatchCursor() { - const plugin = this; - return (original: Func) => { - return function patchedCursorCommand( - this: { - ns: string; - cmd: MongoInternalCommand; - topology: MongoInternalTopology; - }, - ...args: unknown[] - ): mongodb.Cursor { - const currentSpan = getSpan(context.active()); - const resultHandler = args[0]; - if (!currentSpan || typeof resultHandler !== 'function') { - return original.apply(this, args); - } - const span = plugin._tracer.startSpan('mongodb.query', { - kind: SpanKind.CLIENT, - }); - plugin._populateAttributes(span, this.ns, this.cmd, this.topology); - - return original.call(this, plugin._patchEnd(span, resultHandler)); - }; - }; - } - - /** - * Ends a created span. - * @param span The created span to end. - * @param resultHandler A callback function. - */ - private _patchEnd(span: Span, resultHandler: Function): Function { - return function patchedEnd(this: {}, ...args: unknown[]) { - const error = args[0]; - if (error instanceof Error) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: error.message, - }); - } - span.end(); - return resultHandler.apply(this, args); - }; - } -} - -export const plugin = new MongoDBPlugin('mongodb'); diff --git a/plugins/node/opentelemetry-plugin-mongodb/src/types.ts b/plugins/node/opentelemetry-plugin-mongodb/src/types.ts deleted file mode 100644 index 84393b4c43..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/src/types.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 type Func = (...args: unknown[]) => T; -export type MongoInternalCommand = { - findandmodify: boolean; - createIndexes: boolean; - count: boolean; - ismaster: boolean; - indexes?: unknown[]; - query?: { [key: string]: unknown }; - q?: { [key: string]: unknown }; -}; - -// https://github.com/mongodb/node-mongodb-native/blob/main/lib/topologies/server.js#L179 -export type MongoInternalTopology = { - s?: { - // those are for mongodb@3 - options?: { - host?: string; - port?: number; - servername?: string; - }; - // those are for mongodb@2 - host?: string; - port?: number; - }; -}; - -export enum MongodbCommandType { - CREATE_INDEXES = 'createIndexes', - FIND_AND_MODIFY = 'findAndModify', - IS_MASTER = 'isMaster', - COUNT = 'count', - UNKNOWN = 'unknown', -} diff --git a/plugins/node/opentelemetry-plugin-mongodb/src/version.ts b/plugins/node/opentelemetry-plugin-mongodb/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-mongodb/test/mongodb.test.ts b/plugins/node/opentelemetry-plugin-mongodb/test/mongodb.test.ts deleted file mode 100644 index 545febdfd1..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/test/mongodb.test.ts +++ /dev/null @@ -1,255 +0,0 @@ -/* - * 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. - */ - -// for testing locally use this command to run docker -// docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=localhost -p 27017:27017 --name otmongo mongo - -import { context, setSpan, SpanKind } from '@opentelemetry/api'; -import { PluginConfig } from '@opentelemetry/core'; -import { BasicTracerProvider } from '@opentelemetry/tracing'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as mongodb from 'mongodb'; -import { plugin } from '../src'; -import { assertSpans, accessCollection } from './utils'; - -describe('MongoDBPlugin', () => { - // For these tests, mongo must be running. Add RUN_MONGODB_TESTS to run - // these tests. - const RUN_MONGODB_TESTS = process.env.RUN_MONGODB_TESTS as string; - let shouldTest = true; - if (!RUN_MONGODB_TESTS) { - console.log('Skipping test-mongodb. Run MongoDB to test'); - shouldTest = false; - } - // shouldTest = true - - const URL = `mongodb://${process.env.MONGODB_HOST || 'localhost'}:${ - process.env.MONGODB_PORT || '27017' - }`; - const DB_NAME = process.env.MONGODB_DB || 'opentelemetry-tests'; - const COLLECTION_NAME = 'test'; - - let contextManager: AsyncHooksContextManager; - let client: mongodb.MongoClient; - let collection: mongodb.Collection; - const enhancedDbConfig: PluginConfig = { enhancedDatabaseReporting: true }; - const provider = new BasicTracerProvider(); - const memoryExporter = new InMemorySpanExporter(); - const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); - - before(done => { - plugin.enable(mongodb, provider); - accessCollection(URL, DB_NAME, COLLECTION_NAME) - .then(result => { - client = result.client; - collection = result.collection; - done(); - }) - .catch((err: Error) => { - console.log( - 'Skipping test-mongodb. Could not connect. Run MongoDB to test' - ); - shouldTest = false; - done(); - }); - }); - - beforeEach(function mongoBeforeEach(done) { - // Skipping all tests in beforeEach() is a workaround. Mocha does not work - // properly when skipping tests in before() on nested describe() calls. - // https://github.com/mochajs/mocha/issues/2819 - if (!shouldTest) { - this.skip(); - } - memoryExporter.reset(); - // Non traced insertion of basic data to perform tests - const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - collection.insertMany(insertData, (err, result) => { - done(); - }); - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(done => { - collection.deleteOne({}, done); - context.disable(); - }); - - after(() => { - if (client) { - client.close(); - } - }); - - /** Should intercept query */ - describe('Instrumenting query operations', () => { - it('should create a child span for insert', done => { - const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = provider.getTracer('default').startSpan('insertRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.insertMany(insertData, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.insert', - SpanKind.CLIENT - ); - done(); - }); - }); - }); - - it('should create a child span for update', done => { - const span = provider.getTracer('default').startSpan('updateRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.updateOne({ a: 2 }, { $set: { b: 1 } }, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.update', - SpanKind.CLIENT - ); - done(); - }); - }); - }); - - it('should create a child span for remove', done => { - const span = provider.getTracer('default').startSpan('removeRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.deleteOne({ a: 3 }, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.remove', - SpanKind.CLIENT - ); - done(); - }); - }); - }); - - it('should create a child span for insert and include database query params in span', done => { - const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = provider.getTracer('default').startSpan('insertRootSpan'); - - plugin.enable(mongodb, provider, enhancedDbConfig); - - context.with(setSpan(context.active(), span), () => { - collection.insertMany(insertData, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.insert', - SpanKind.CLIENT, - false, - true - ); - done(); - }); - }); - }); - }); - - /** Should intercept cursor */ - describe('Instrumenting cursor operations', () => { - it('should create a child span for find', done => { - const span = provider.getTracer('default').startSpan('findRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.find({}).toArray((err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.query', - SpanKind.CLIENT - ); - done(); - }); - }); - }); - }); - - /** Should intercept command */ - describe('Instrumenting command operations', () => { - it('should create a child span for create index', done => { - const span = provider.getTracer('default').startSpan('indexRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.createIndex({ a: 1 }, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.createIndexes', - SpanKind.CLIENT - ); - done(); - }); - }); - }); - }); - - /** Should intercept command */ - describe('Removing Instrumentation', () => { - it('should unpatch plugin', () => { - assert.doesNotThrow(() => { - plugin.unpatch(); - }); - }); - - it('should not create a child span for query', done => { - const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = provider.getTracer('default').startSpan('insertRootSpan'); - collection.insertMany(insertData, (err, result) => { - span.end(); - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - done(); - }); - }); - - it('should not create a child span for cursor', done => { - const span = provider.getTracer('default').startSpan('findRootSpan'); - collection.find({}).toArray((err, result) => { - span.end(); - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - done(); - }); - }); - - it('should not create a child span for command', done => { - const span = provider.getTracer('default').startSpan('indexRootSpan'); - collection.createIndex({ a: 1 }, (err, result) => { - span.end(); - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - done(); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-mongodb/test/multiple_versions.test.ts b/plugins/node/opentelemetry-plugin-mongodb/test/multiple_versions.test.ts deleted file mode 100644 index 3e4df91ee5..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/test/multiple_versions.test.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 { context, setSpan, SpanKind } from '@opentelemetry/api'; -import { BasicTracerProvider } from '@opentelemetry/tracing'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as mongodb from 'mongodb'; -import { MongoDBPlugin } from '../src/mongodb'; -import { assertSpans, accessCollection } from './utils'; - -describe('Multiple enable on the plugin', () => { - // For these tests, mongo must be running. Add RUN_MONGODB_TESTS to run - // these tests. - const RUN_MONGODB_TESTS = process.env.RUN_MONGODB_TESTS as string; - let shouldTest = true; - if (!RUN_MONGODB_TESTS) { - console.log('Skipping test-mongodb. Run MongoDB to test'); - shouldTest = false; - } - - const URL = `mongodb://${process.env.MONGODB_HOST || 'localhost'}:${ - process.env.MONGODB_PORT || '27017' - }`; - const DB_NAME = process.env.MONGODB_DB || 'opentelemetry-tests'; - const COLLECTION_NAME = 'test'; - - let contextManager: AsyncHooksContextManager; - let client: mongodb.MongoClient; - let collection: mongodb.Collection; - const provider = new BasicTracerProvider(); - const memoryExporter = new InMemorySpanExporter(); - const spanProcessor = new SimpleSpanProcessor(memoryExporter); - const plugin = new MongoDBPlugin('mongodb'); - provider.addSpanProcessor(spanProcessor); - - before(done => { - // enable twice to simulate loading to different versions - plugin.enable(mongodb, provider); - plugin.enable(mongodb, provider); - accessCollection(URL, DB_NAME, COLLECTION_NAME) - .then(result => { - client = result.client; - collection = result.collection; - done(); - }) - .catch((err: Error) => { - console.log( - 'Skipping test-mongodb. Could not connect. Run MongoDB to test' - ); - shouldTest = false; - done(); - }); - }); - - beforeEach(function mongoBeforeEach() { - // Skipping all tests in beforeEach() is a workaround. Mocha does not work - // properly when skipping tests in before() on nested describe() calls. - // https://github.com/mochajs/mocha/issues/2819 - if (!shouldTest) { - this.skip(); - } - memoryExporter.reset(); - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(done => { - collection.deleteOne({}, done); - context.disable(); - }); - - after(() => { - if (client) { - client.close(); - } - }); - - it('should create a child span for insert', done => { - const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - - const span = provider.getTracer('default').startSpan('insertRootSpan'); - context.with(setSpan(context.active(), span), () => { - collection.insertMany(insertData, (err, result) => { - span.end(); - assert.ifError(err); - assertSpans( - memoryExporter.getFinishedSpans(), - 'mongodb.insert', - SpanKind.CLIENT - ); - done(); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-mongodb/test/utils.ts b/plugins/node/opentelemetry-plugin-mongodb/test/utils.ts deleted file mode 100644 index 36e161aa65..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/test/utils.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 { SpanStatusCode, SpanKind } from '@opentelemetry/api'; -import { ReadableSpan } from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as mongodb from 'mongodb'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -export interface MongoDBAccess { - client: mongodb.MongoClient; - collection: mongodb.Collection; -} - -/** - * Access the mongodb collection. - * @param url The mongodb URL to access. - * @param dbName The mongodb database name. - * @param collectionName The mongodb collection name. - */ -export function accessCollection( - url: string, - dbName: string, - collectionName: string -): Promise { - return new Promise((resolve, reject) => { - mongodb.MongoClient.connect(url, (err, client) => { - if (err) { - reject(err); - return; - } - const db = client.db(dbName); - const collection = db.collection(collectionName); - resolve({ client, collection }); - }); - }); -} - -/** - * Asserts root spans attributes. - * @param spans Readable spans that we need to assert. - * @param expectedName The expected name of the first root span. - * @param expectedKind The expected kind of the first root span. - * @param log - * @param isEnhancedDatabaseReportingEnabled Is enhanced database reporting enabled: boolean - */ -export function assertSpans( - spans: ReadableSpan[], - expectedName: string, - expectedKind: SpanKind, - log = false, - isEnhancedDatabaseReportingEnabled = false -) { - if (log) { - console.log(spans); - } - assert.strictEqual(spans.length, 2); - spans.forEach(span => { - assert(span.endTime instanceof Array); - assert(span.endTime.length === 2); - }); - const [mongoSpan] = spans; - assert.strictEqual(mongoSpan.name, expectedName); - assert.strictEqual(mongoSpan.kind, expectedKind); - assert.strictEqual( - mongoSpan.attributes[DatabaseAttribute.DB_SYSTEM], - 'mongodb' - ); - assert.strictEqual( - mongoSpan.attributes[GeneralAttribute.NET_HOST_NAME], - process.env.MONGODB_HOST || 'localhost' - ); - assert.strictEqual(mongoSpan.status.code, SpanStatusCode.UNSET); - - if (isEnhancedDatabaseReportingEnabled) { - const dbStatement = mongoSpan.attributes[ - DatabaseAttribute.DB_STATEMENT - ] as any; - for (const key in dbStatement) { - assert.notStrictEqual(dbStatement[key], '?'); - } - } -} diff --git a/plugins/node/opentelemetry-plugin-mongodb/tsconfig.json b/plugins/node/opentelemetry-plugin-mongodb/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-mongodb/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-mysql/.eslintignore b/plugins/node/opentelemetry-plugin-mysql/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-mysql/.eslintrc.js b/plugins/node/opentelemetry-plugin-mysql/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-mysql/.npmignore b/plugins/node/opentelemetry-plugin-mysql/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-mysql/LICENSE b/plugins/node/opentelemetry-plugin-mysql/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-mysql/README.md b/plugins/node/opentelemetry-plugin-mysql/README.md deleted file mode 100644 index 7653fed9d4..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# OpenTelemetry mysql Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`mysql`](https://www.npmjs.com/package/mysql). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-mysql -``` - -## Supported Versions -- `~2.0.0` - -## Usage - -OpenTelemetry MySQL Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with [mysql](https://www.npmjs.com/package/mysql). - -To load a specific plugin (**MySQL** in this case), specify it in the registerInstrumentations's configuration -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - mysql: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-mysql', - } - }, - }, - ], - tracerProvider: provider, -}); - -``` - -To load all of the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/mysql) for a short example. - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-mysql -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-mysql -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-mysql&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-mysql&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-mysql -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-mysql.svg diff --git a/plugins/node/opentelemetry-plugin-mysql/package.json b/plugins/node/opentelemetry-plugin-mysql/package.json deleted file mode 100644 index 9800cab2f9..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@opentelemetry/plugin-mysql", - "version": "0.15.0", - "description": "OpenTelemetry mysql automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "prepare": "npm run compile" - }, - "keywords": [ - "opentelemetry", - "mysql", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/semantic-conventions": "0.18.2", - "@opentelemetry/test-utils": "^0.15.0", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/mysql": "2.15.15", - "@types/node": "14.0.27", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "mysql": "2.18.1", - "nyc": "15.1.0", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-mysql/src/index.ts b/plugins/node/opentelemetry-plugin-mysql/src/index.ts deleted file mode 100644 index bcfc25371d..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/src/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 './mysql'; diff --git a/plugins/node/opentelemetry-plugin-mysql/src/mysql.ts b/plugins/node/opentelemetry-plugin-mysql/src/mysql.ts deleted file mode 100644 index 7c68751039..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/src/mysql.ts +++ /dev/null @@ -1,274 +0,0 @@ -/* - * 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 { BasePlugin, isWrapped } from '@opentelemetry/core'; -import { diag, SpanStatusCode, Span, SpanKind } from '@opentelemetry/api'; -import type * as mysqlTypes from 'mysql'; -import * as shimmer from 'shimmer'; -import { getConnectionAttributes, getDbStatement, getSpanName } from './utils'; -import { VERSION } from './version'; -import { DatabaseAttribute } from '@opentelemetry/semantic-conventions'; - -export class MysqlPlugin extends BasePlugin { - readonly supportedVersions = ['2.*']; - - static readonly COMPONENT = 'mysql'; - - static readonly COMMON_ATTRIBUTES = { - [DatabaseAttribute.DB_SYSTEM]: MysqlPlugin.COMPONENT, - }; - - private _enabled = false; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-mysql', VERSION); - } - - protected patch(): typeof mysqlTypes { - this._enabled = true; - shimmer.wrap( - this._moduleExports, - 'createConnection', - this._patchCreateConnection() as any - ); - - shimmer.wrap( - this._moduleExports, - 'createPool', - this._patchCreatePool() as any - ); - - shimmer.wrap( - this._moduleExports, - 'createPoolCluster', - this._patchCreatePoolCluster() as any - ); - - return this._moduleExports; - } - - protected unpatch(): void { - this._enabled = false; - shimmer.unwrap(this._moduleExports, 'createConnection'); - shimmer.unwrap(this._moduleExports, 'createPool'); - shimmer.unwrap(this._moduleExports, 'createPoolCluster'); - } - - // global export function - private _patchCreateConnection() { - return (originalCreateConnection: Function) => { - const thisPlugin = this; - diag.debug('MysqlPlugin#patch: patched mysql createConnection'); - - return function createConnection( - _connectionUri: string | mysqlTypes.ConnectionConfig - ) { - const originalResult = originalCreateConnection(...arguments); - - // This is unwrapped on next call after unpatch - shimmer.wrap( - originalResult, - 'query', - thisPlugin._patchQuery(originalResult) as any - ); - - return originalResult; - }; - }; - } - - // global export function - private _patchCreatePool() { - return (originalCreatePool: Function) => { - const thisPlugin = this; - diag.debug('MysqlPlugin#patch: patched mysql createPool'); - return function createPool(_config: string | mysqlTypes.PoolConfig) { - const pool = originalCreatePool(...arguments); - - shimmer.wrap(pool, 'query', thisPlugin._patchQuery(pool)); - shimmer.wrap( - pool, - 'getConnection', - thisPlugin._patchGetConnection(pool) - ); - - return pool; - }; - }; - } - - // global export function - private _patchCreatePoolCluster() { - return (originalCreatePoolCluster: Function) => { - const thisPlugin = this; - diag.debug('MysqlPlugin#patch: patched mysql createPoolCluster'); - return function createPool(_config: string | mysqlTypes.PoolConfig) { - const cluster = originalCreatePoolCluster(...arguments); - - // This is unwrapped on next call after unpatch - shimmer.wrap( - cluster, - 'getConnection', - thisPlugin._patchGetConnection(cluster) - ); - - return cluster; - }; - }; - } - - // method on cluster or pool - private _patchGetConnection(pool: mysqlTypes.Pool | mysqlTypes.PoolCluster) { - return (originalGetConnection: Function) => { - const thisPlugin = this; - diag.debug('MysqlPlugin#patch: patched mysql pool getConnection'); - return function getConnection( - arg1?: unknown, - arg2?: unknown, - arg3?: unknown - ) { - // Unwrap if unpatch has been called - if (!thisPlugin._enabled) { - shimmer.unwrap(pool, 'getConnection'); - return originalGetConnection.apply(pool, arguments); - } - - if (arguments.length === 1 && typeof arg1 === 'function') { - const patchFn = thisPlugin._getConnectionCallbackPatchFn(arg1); - return originalGetConnection.call(pool, patchFn); - } - if (arguments.length === 2 && typeof arg2 === 'function') { - const patchFn = thisPlugin._getConnectionCallbackPatchFn(arg2); - return originalGetConnection.call(pool, arg1, patchFn); - } - if (arguments.length === 3 && typeof arg3 === 'function') { - const patchFn = thisPlugin._getConnectionCallbackPatchFn(arg3); - return originalGetConnection.call(pool, arg1, arg2, patchFn); - } - - return originalGetConnection.apply(pool, arguments); - }; - }; - } - - private _getConnectionCallbackPatchFn(cb: Function) { - const thisPlugin = this; - return function () { - if (arguments[1]) { - // this is the callback passed into a query - // no need to unwrap - if (!isWrapped(arguments[1].query)) { - shimmer.wrap( - arguments[1], - 'query', - thisPlugin._patchQuery(arguments[1]) - ); - } - } - if (typeof cb === 'function') { - cb(...arguments); - } - }; - } - - private _patchQuery(connection: mysqlTypes.Connection | mysqlTypes.Pool) { - return (originalQuery: Function): mysqlTypes.QueryFunction => { - const thisPlugin = this; - diag.debug('MysqlPlugin: patched mysql query'); - - const format = this._moduleExports.format; - - return function query( - query: string | mysqlTypes.Query | mysqlTypes.QueryOptions, - _valuesOrCallback?: unknown[] | mysqlTypes.queryCallback, - _callback?: mysqlTypes.queryCallback - ) { - if (!thisPlugin._enabled) { - shimmer.unwrap(connection, 'query'); - return originalQuery.apply(connection, arguments); - } - - const span = thisPlugin._tracer.startSpan(getSpanName(query), { - kind: SpanKind.CLIENT, - attributes: { - ...MysqlPlugin.COMMON_ATTRIBUTES, - ...getConnectionAttributes(connection.config), - }, - }); - - let values; - - if (Array.isArray(_valuesOrCallback)) { - values = _valuesOrCallback; - } else if (arguments[2]) { - values = [_valuesOrCallback]; - } - - span.setAttribute( - DatabaseAttribute.DB_STATEMENT, - getDbStatement(query, format, values) - ); - - if (arguments.length === 1) { - const streamableQuery: mysqlTypes.Query = originalQuery.apply( - connection, - arguments - ); - - return streamableQuery - .on('error', err => - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }) - ) - .on('end', () => { - span.end(); - }); - } - - if (typeof arguments[1] === 'function') { - shimmer.wrap(arguments, 1, thisPlugin._patchCallbackQuery(span)); - } else if (typeof arguments[2] === 'function') { - shimmer.wrap(arguments, 2, thisPlugin._patchCallbackQuery(span)); - } - - return originalQuery.apply(connection, arguments); - }; - }; - } - - private _patchCallbackQuery(span: Span) { - return (originalCallback: Function) => { - return function ( - err: mysqlTypes.MysqlError | null, - results?: any, - fields?: mysqlTypes.FieldInfo[] - ) { - if (err) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }); - } - span.end(); - return originalCallback(...arguments); - }; - }; - } -} - -export const plugin = new MysqlPlugin(MysqlPlugin.COMPONENT); diff --git a/plugins/node/opentelemetry-plugin-mysql/src/utils.ts b/plugins/node/opentelemetry-plugin-mysql/src/utils.ts deleted file mode 100644 index 2ffe83a92c..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/src/utils.ts +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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 { SpanAttributes } from '@opentelemetry/api'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; -import type { - ConnectionConfig, - PoolActualConfig, - Query, - QueryOptions, -} from 'mysql'; - -/** - * Get an SpanAttributes map from a mysql connection config object - * - * @param config ConnectionConfig - */ -export function getConnectionAttributes( - config: ConnectionConfig | PoolActualConfig -): SpanAttributes { - const { host, port, database, user } = getConfig(config); - - return { - [GeneralAttribute.NET_PEER_HOSTNAME]: host, - [GeneralAttribute.NET_PEER_PORT]: port, - [GeneralAttribute.NET_PEER_ADDRESS]: getJDBCString(host, port, database), - [DatabaseAttribute.DB_NAME]: database, - [DatabaseAttribute.DB_USER]: user, - }; -} - -function getConfig(config: any) { - const { host, port, database, user } = - (config && config.connectionConfig) || config || {}; - return { host, port, database, user }; -} - -function getJDBCString( - host: string | undefined, - port: number | undefined, - database: string | undefined -) { - let jdbcString = `jdbc:mysql://${host || 'localhost'}`; - - if (typeof port === 'number') { - jdbcString += `:${port}`; - } - - if (typeof database === 'string') { - jdbcString += `/${database}`; - } - - return jdbcString; -} - -/** - * Conjures up the value for the db.statement attribute by formatting a SQL query. - * - * @returns the database statement being executed. - */ -export function getDbStatement( - query: string | Query | QueryOptions, - format: ( - sql: string, - values: any[], - stringifyObjects?: boolean, - timeZone?: string - ) => string, - values?: any[] -): string { - if (typeof query === 'string') { - return values ? format(query, values) : query; - } else { - // According to https://github.com/mysqljs/mysql#performing-queries - // The values argument will override the values in the option object. - return values || query.values - ? format(query.sql, values || query.values) - : query.sql; - } -} - -/** - * The span name SHOULD be set to a low cardinality value - * representing the statement executed on the database. - * - * @returns SQL statement without variable arguments or SQL verb - */ -export function getSpanName(query: string | Query | QueryOptions): string { - if (typeof query === 'object') { - return query.sql; - } - return query.split(' ')[0]; -} diff --git a/plugins/node/opentelemetry-plugin-mysql/src/version.ts b/plugins/node/opentelemetry-plugin-mysql/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-mysql/test/mysql.test.ts b/plugins/node/opentelemetry-plugin-mysql/test/mysql.test.ts deleted file mode 100644 index be41ec3e07..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/test/mysql.test.ts +++ /dev/null @@ -1,629 +0,0 @@ -/* - * 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 { SpanStatusCode, context, setSpan } from '@opentelemetry/api'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import * as testUtils from '@opentelemetry/test-utils'; -import { - InMemorySpanExporter, - ReadableSpan, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as mysql from 'mysql'; -import { MysqlPlugin, plugin } from '../src'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -const port = Number(process.env.MYSQL_PORT) || 33306; -const database = process.env.MYSQL_DATABASE || 'test_db'; -const host = process.env.MYSQL_HOST || '127.0.0.1'; -const user = process.env.MYSQL_USER || 'otel'; -const password = process.env.MYSQL_PASSWORD || 'secret'; - -describe('mysql@2.x', () => { - let contextManager: AsyncHooksContextManager; - let connection: mysql.Connection; - let pool: mysql.Pool; - let poolCluster: mysql.PoolCluster; - const provider = new NodeTracerProvider(); - const testMysql = process.env.RUN_MYSQL_TESTS; // For CI: assumes local mysql db is already available - const testMysqlLocally = process.env.RUN_MYSQL_TESTS_LOCAL; // For local: spins up local mysql db via docker - const shouldTest = testMysql || testMysqlLocally; // Skips these tests if false (default) - const memoryExporter = new InMemorySpanExporter(); - - before(function (done) { - if (!shouldTest) { - // this.skip() workaround - // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 - this.test!.parent!.pending = true; - this.skip(); - } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - if (testMysqlLocally) { - testUtils.startDocker('mysql'); - // wait 15 seconds for docker container to start - this.timeout(20000); - setTimeout(done, 15000); - } else { - done(); - } - }); - - after(function () { - if (testMysqlLocally) { - this.timeout(5000); - testUtils.cleanUpDocker('mysql'); - } - }); - - beforeEach(() => { - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - plugin.enable(mysql, provider); - connection = mysql.createConnection({ - port, - user, - host, - password, - database, - }); - pool = mysql.createPool({ - port, - user, - host, - password, - database, - }); - poolCluster = mysql.createPoolCluster(); - poolCluster.add('name', { - port, - user, - host, - password, - database, - }); - }); - - afterEach(done => { - context.disable(); - memoryExporter.reset(); - plugin.disable(); - connection.end(() => { - pool.end(() => { - poolCluster.end(() => { - done(); - }); - }); - }); - }); - - it('should export a plugin', () => { - assert(plugin instanceof MysqlPlugin); - }); - - it('should have correct moduleName', () => { - assert.strictEqual(plugin.moduleName, 'mysql'); - }); - - describe('when the query is a string', () => { - it('should name the span accordingly ', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - const query = connection.query(sql); - - query.on('end', () => { - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans[0].name, 'SELECT'); - done(); - }); - }); - }); - }); - - describe('when the query is an object', () => { - it('should name the span accordingly ', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - const query = connection.query({ sql, values: [1] }); - - query.on('end', () => { - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans[0].name, sql); - done(); - }); - }); - }); - }); - - describe('#Connection', () => { - it('should intercept connection.query(text: string)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - const query = connection.query(sql); - let rows = 0; - - query.on('result', row => { - assert.strictEqual(row.solution, 2); - rows += 1; - }); - - query.on('end', () => { - assert.strictEqual(rows, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - - it('should intercept connection.query(text: string, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - connection.query(sql, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - - it('should intercept connection.query(text: options, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - connection.query({ sql, values: [1] }, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept connection.query(text: options, values: [], callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - connection.query({ sql }, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept connection.query(text: string, values: [], callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - connection.query(sql, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept connection.query(text: string, value: any, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - connection.query(sql, 1, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should attach error messages to spans', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - connection.query(sql, (err, res) => { - assert.ok(err); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, undefined, err!.message); - done(); - }); - }); - }); - }); - - describe('#Pool', () => { - it('should intercept pool.query(text: string)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - const query = pool.query(sql); - let rows = 0; - - query.on('result', row => { - assert.strictEqual(row.solution, 2); - rows += 1; - }); - - query.on('end', () => { - assert.strictEqual(rows, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - - it('should intercept pool.getConnection().query(text: string)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - pool.getConnection((err, conn) => { - const query = conn.query(sql); - let rows = 0; - - query.on('result', row => { - assert.strictEqual(row.solution, 2); - rows += 1; - }); - - query.on('end', () => { - assert.strictEqual(rows, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - }); - - it('should intercept pool.query(text: string, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - pool.query(sql, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - - it('should intercept pool.getConnection().query(text: string, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - pool.getConnection((err, conn) => { - conn.query(sql, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - }); - - it('should intercept pool.query(text: options, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - pool.query({ sql, values: [1] }, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept pool.query(text: options, values: [], callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - pool.query({ sql }, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept pool.query(text: string, values: [], callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - pool.query(sql, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should intercept pool.query(text: string, value: any, callback)', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - pool.query(sql, 1, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - - it('should attach error messages to spans', done => { - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - pool.query(sql, (err, res) => { - assert.ok(err); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, undefined, err!.message); - done(); - }); - }); - }); - }); - - describe('#PoolCluster', () => { - it('should intercept poolClusterConnection.query(text: string)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - const query = poolClusterConnection.query(sql); - let rows = 0; - - query.on('result', row => { - assert.strictEqual(row.solution, 2); - rows += 1; - }); - - query.on('end', () => { - assert.strictEqual(rows, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - }); - - it('should intercept poolClusterConnection.query(text: string, callback)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+1 as solution'; - poolClusterConnection.query(sql, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - }); - - it('should intercept poolClusterConnection.query(text: options, callback)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - poolClusterConnection.query({ sql, values: [1] }, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - }); - - it('should intercept poolClusterConnection.query(text: options, values: [], callback)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1+? as solution'; - poolClusterConnection.query({ sql }, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 2); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - }); - - it('should intercept poolClusterConnection.query(text: string, values: [], callback)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - poolClusterConnection.query(sql, [1], (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - }); - - it('should intercept poolClusterConnection.query(text: string, value: any, callback)', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - poolClusterConnection.query(sql, 1, (err, res) => { - assert.ifError(err); - assert.ok(res); - assert.strictEqual(res[0].solution, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, [1]); - done(); - }); - }); - }); - }); - - it('should attach error messages to spans', done => { - poolCluster.getConnection((err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT ? as solution'; - poolClusterConnection.query(sql, (err, res) => { - assert.ok(err); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql, undefined, err!.message); - done(); - }); - }); - }); - }); - - it('should get connection by name', done => { - poolCluster.getConnection('name', (err, poolClusterConnection) => { - assert.ifError(err); - const span = provider.getTracer('default').startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const sql = 'SELECT 1 as solution'; - poolClusterConnection.query(sql, (err, res) => { - assert.ifError(err); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - }); - }); - }); - - it('should get connection by name and selector', done => { - poolCluster.getConnection( - 'name', - 'ORDER', - (err, poolClusterConnection) => { - assert.ifError(err); - const sql = 'SELECT 1 as solution'; - poolClusterConnection.query(sql, (err, res) => { - assert.ifError(err); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); - done(); - }); - } - ); - }); - }); -}); - -function assertSpan( - span: ReadableSpan, - sql: string, - values?: any, - errorMessage?: string -) { - assert.strictEqual(span.attributes[DatabaseAttribute.DB_SYSTEM], 'mysql'); - assert.strictEqual(span.attributes[DatabaseAttribute.DB_NAME], database); - assert.strictEqual(span.attributes[GeneralAttribute.NET_PEER_PORT], port); - assert.strictEqual(span.attributes[GeneralAttribute.NET_PEER_HOSTNAME], host); - assert.strictEqual(span.attributes[DatabaseAttribute.DB_USER], user); - assert.strictEqual( - span.attributes[DatabaseAttribute.DB_STATEMENT], - mysql.format(sql, values) - ); - if (errorMessage) { - assert.strictEqual(span.status.message, errorMessage); - assert.strictEqual(span.status.code, SpanStatusCode.ERROR); - } -} diff --git a/plugins/node/opentelemetry-plugin-mysql/tsconfig.json b/plugins/node/opentelemetry-plugin-mysql/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-mysql/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/.eslintignore b/plugins/node/opentelemetry-plugin-pg-pool/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-pg-pool/.eslintrc.js b/plugins/node/opentelemetry-plugin-pg-pool/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/.npmignore b/plugins/node/opentelemetry-plugin-pg-pool/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-pg-pool/LICENSE b/plugins/node/opentelemetry-plugin-pg-pool/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-pg-pool/README.md b/plugins/node/opentelemetry-plugin-pg-pool/README.md deleted file mode 100644 index 498fc44d82..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# OpenTelemetry Postgres Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`pg`](https://github.com/brianc/node-postgres). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-pg -npm install --save @opentelemetry/plugin-pg-pool -``` - -## Usage - -To load all of the [default supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use the below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider(); // All default plugins will be used -``` - -If instead you would just want to load a specific plugin (**pg** and **pg-pool** in this case), specify it in the `NodeTracer` configuration. You'll need to install both plugins for full functionality. - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider({ - plugins: { - pg: { - enabled: true, - // You may use a package name or absolute path to the module - path: '@opentelemetry/plugin-pg', - }, - 'pg-pool': { - enabled: true, - // You may use a package name or absolute path to the module - path: '@opentelemetry/plugin-pg-pool', - } - } -}); -``` - -See [examples/postgres](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/postgres) for a short example. - -## Supported Versions - -- [pg](https://npmjs.com/package/pg): `7.x` -- [pg-pool](https://npmjs.com/package/pg-pool): `2.x` - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-pg-pool -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-pg-pool -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-pg-pool&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-pg-pool&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-pg-pool -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-pg-pool.svg diff --git a/plugins/node/opentelemetry-plugin-pg-pool/package.json b/plugins/node/opentelemetry-plugin-pg-pool/package.json deleted file mode 100644 index 10c53ef63b..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/package.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "@opentelemetry/plugin-pg-pool", - "version": "0.15.0", - "description": "OpenTelemetry postgres pool automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:debug": "ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", - "test:local": "cross-env RUN_POSTGRES_TESTS_LOCAL=true npm run test", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "prepare": "npm run compile", - "watch": "tsc -w" - }, - "keywords": [ - "opentelemetry", - "postgres", - "pg", - "pg-pool", - "postgresql", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/plugin-pg": "^0.15.0", - "@opentelemetry/test-utils": "^0.15.0", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/pg": "7.14.4", - "@types/pg-pool": "2.0.2", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "cross-env": "7.0.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "nyc": "15.1.0", - "pg": "8.3.0", - "pg-pool": "3.2.1", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/enums.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/enums.ts deleted file mode 100644 index f2d96a9cd2..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/enums.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 enum AttributeNames { - // required by https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-database.md - COMPONENT = 'component', - DB_TYPE = 'db.type', - DB_INSTANCE = 'db.instance', - DB_STATEMENT = 'db.statement', - PEER_ADDRESS = 'peer.address', - PEER_HOSTNAME = 'peer.host', - - // optional - DB_USER = 'db.user', - PEER_PORT = 'peer.port', - PEER_IPV4 = 'peer.ipv4', - PEER_IPV6 = 'peer.ipv6', - PEER_SERVICE = 'peer.service', - - // PG-POOL specific -- not specified by spec - IDLE_TIMEOUT_MILLIS = 'idle.timeout.millis', - MAX_CLIENT = 'max', -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/index.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/index.ts deleted file mode 100644 index a5b72734a9..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './pg-pool'; diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/pg-pool.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/pg-pool.ts deleted file mode 100644 index 8af374b0ac..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/pg-pool.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 { BasePlugin } from '@opentelemetry/core'; -import { - context, - diag, - SpanStatusCode, - SpanKind, - getSpan, -} from '@opentelemetry/api'; -import { AttributeNames } from './enums'; -import * as shimmer from 'shimmer'; -import * as pgPoolTypes from 'pg-pool'; -import { PgPoolCallback, PgPoolExtended } from './types'; -import * as utils from './utils'; -import { VERSION } from './version'; - -export class PostgresPoolPlugin extends BasePlugin { - protected _config: {}; - - static readonly COMPONENT = 'pg-pool'; - static readonly DB_TYPE = 'sql'; - - readonly supportedVersions = ['2.*', '3.*']; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-pg-pool', VERSION); - this._config = {}; - } - - protected patch(): typeof pgPoolTypes { - shimmer.wrap( - this._moduleExports.prototype, - 'connect', - this._getPoolConnectPatch() as never - ); - - return this._moduleExports; - } - - protected unpatch(): void { - shimmer.unwrap(this._moduleExports.prototype, 'connect'); - } - - private _getPoolConnectPatch() { - const plugin = this; - return (originalConnect: typeof pgPoolTypes.prototype.connect) => { - diag.debug(`Patching ${PostgresPoolPlugin.COMPONENT}.prototype.connect`); - return function connect(this: PgPoolExtended, callback?: PgPoolCallback) { - const jdbcString = utils.getJDBCString(this.options); - // setup span - const span = plugin._tracer.startSpan( - `${PostgresPoolPlugin.COMPONENT}.connect`, - { - kind: SpanKind.CLIENT, - attributes: { - [AttributeNames.COMPONENT]: PostgresPoolPlugin.COMPONENT, // required - [AttributeNames.DB_TYPE]: PostgresPoolPlugin.DB_TYPE, // required - [AttributeNames.DB_INSTANCE]: this.options.database, // required - [AttributeNames.PEER_HOSTNAME]: this.options.host, // required - [AttributeNames.PEER_ADDRESS]: jdbcString, // required - [AttributeNames.PEER_PORT]: this.options.port, - [AttributeNames.DB_USER]: this.options.user, - [AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options - .idleTimeoutMillis, - [AttributeNames.MAX_CLIENT]: this.options.maxClient, - }, - } - ); - - if (callback) { - const parentSpan = getSpan(context.active()); - callback = utils.patchCallback(span, callback) as PgPoolCallback; - // If a parent span exists, bind the callback - if (parentSpan) { - callback = context.bind(callback); - } - } - - const connectResult: unknown = originalConnect.call( - this, - callback as never - ); - - // No callback was provided, return a promise instead - if (connectResult instanceof Promise) { - const connectResultPromise = connectResult as Promise; - return context.bind( - connectResultPromise - .then(result => { - // Return a pass-along promise which ends the span and then goes to user's orig resolvers - return new Promise(resolve => { - span.end(); - resolve(result); - }); - }) - .catch((error: Error) => { - return new Promise((_, reject) => { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: error.message, - }); - span.end(); - reject(error); - }); - }) - ); - } - - // Else a callback was provided, so just return the result - return connectResult; - }; - }; - } -} - -export const plugin = new PostgresPoolPlugin(PostgresPoolPlugin.COMPONENT); diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/types.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/types.ts deleted file mode 100644 index f630b57cee..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/types.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 * as pgTypes from 'pg'; -import * as pgPoolTypes from 'pg-pool'; - -export type PgPoolCallback = ( - err: Error, - client: any, - done: (release?: any) => void -) => void; - -export interface PgPoolOptionsParams { - database: string; - host: string; - port: number; - user: string; - idleTimeoutMillis: number; // the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due to idle time - maxClient: number; // maximum size of the pool -} - -export interface PgPoolExtended extends pgPoolTypes { - options: PgPoolOptionsParams; -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/utils.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/utils.ts deleted file mode 100644 index 2f1d27e7bf..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/utils.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 { Span, SpanStatusCode } from '@opentelemetry/api'; -import { PgPoolOptionsParams, PgPoolCallback, PgPoolExtended } from './types'; - -export function getJDBCString(params: PgPoolOptionsParams) { - const host = params.host || 'localhost'; // postgres defaults to localhost - const port = params.port || 5432; // postgres defaults to port 5432 - const database = params.database || ''; - return `jdbc:postgresql://${host}:${port}/${database}`; -} - -export function patchCallback(span: Span, cb: PgPoolCallback): PgPoolCallback { - return function patchedCallback( - this: PgPoolExtended, - err: Error, - res: object, - done: any - ) { - if (err) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }); - } - span.end(); - cb.call(this, err, res, done); - }; -} diff --git a/plugins/node/opentelemetry-plugin-pg-pool/src/version.ts b/plugins/node/opentelemetry-plugin-pg-pool/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts b/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts deleted file mode 100644 index 7ce6298828..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts +++ /dev/null @@ -1,282 +0,0 @@ -/* - * 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 { - SpanAttributes, - SpanStatusCode, - context, - Span, - SpanKind, - SpanStatus, - TimedEvent, - setSpan, -} from '@opentelemetry/api'; -import { BasicTracerProvider } from '@opentelemetry/tracing'; -import { plugin as pgPlugin, PostgresPlugin } from '@opentelemetry/plugin-pg'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import * as testUtils from '@opentelemetry/test-utils'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as pg from 'pg'; -import * as pgPool from 'pg-pool'; -import { plugin, PostgresPoolPlugin } from '../src'; -import { AttributeNames } from '../src/enums'; - -const memoryExporter = new InMemorySpanExporter(); - -const CONFIG = { - user: process.env.POSTGRES_USER || 'postgres', - database: process.env.POSTGRES_DB || 'postgres', - host: process.env.POSTGRES_HOST || 'localhost', - port: process.env.POSTGRES_PORT - ? parseInt(process.env.POSTGRES_PORT, 10) - : 54320, - maxClient: 1, - idleTimeoutMillis: 10000, -}; - -const DEFAULT_PGPOOL_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PostgresPoolPlugin.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PostgresPoolPlugin.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, - [AttributeNames.MAX_CLIENT]: CONFIG.maxClient, - [AttributeNames.IDLE_TIMEOUT_MILLIS]: CONFIG.idleTimeoutMillis, -}; - -const DEFAULT_PG_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PostgresPlugin.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PostgresPlugin.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, -}; - -const unsetStatus: SpanStatus = { - code: SpanStatusCode.UNSET, -}; - -const runCallbackTest = ( - parentSpan: Span, - attributes: SpanAttributes, - events: TimedEvent[], - status: SpanStatus = unsetStatus, - spansLength = 1, - spansIndex = 0 -) => { - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, spansLength); - const pgSpan = spans[spansIndex]; - testUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events, status); - testUtils.assertPropagation(pgSpan, parentSpan); -}; - -describe('pg-pool@2.x', () => { - let pool: pgPool; - let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); - const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: - // assumes local postgres db is already available - const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker - const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) - - before(function () { - if (!shouldTest) { - // this.skip() workaround - // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 - this.test!.parent!.pending = true; - this.skip(); - } - pool = new pgPool(CONFIG); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - if (testPostgresLocally) { - testUtils.startDocker('postgres'); - } - }); - - after(done => { - if (testPostgresLocally) { - testUtils.cleanUpDocker('postgres'); - } - pool.end(() => { - done(); - }); - }); - - beforeEach(() => { - plugin.enable(pgPool, provider); - pgPlugin.enable(pg, provider); - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(() => { - memoryExporter.reset(); - plugin.disable(); - pgPlugin.disable(); - context.disable(); - }); - - it('should return a plugin', () => { - assert.ok(plugin instanceof PostgresPoolPlugin); - }); - - it('should have correct moduleName', () => { - assert.strictEqual(plugin.moduleName, 'pg-pool'); - }); - - describe('#pool.connect()', () => { - // promise - checkout a client - it('should intercept pool.connect()', async () => { - const pgPoolattributes = { - ...DEFAULT_PGPOOL_ATTRIBUTES, - }; - const pgAttributes = { - ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', - }; - const events: TimedEvent[] = []; - const span = provider.getTracer('test-pg-pool').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - const client = await pool.connect(); - runCallbackTest(span, pgPoolattributes, events, unsetStatus, 1, 0); - assert.ok(client, 'pool.connect() returns a promise'); - try { - await client.query('SELECT NOW()'); - runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1); - } finally { - client.release(); - } - }); - }); - - // callback - checkout a client - it('should not return a promise if callback is provided', done => { - const pgPoolattributes = { - ...DEFAULT_PGPOOL_ATTRIBUTES, - }; - const pgAttributes = { - ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', - }; - const events: TimedEvent[] = []; - const parentSpan = provider - .getTracer('test-pg-pool') - .startSpan('test span'); - context.with(setSpan(context.active(), parentSpan), () => { - const resNoPromise = pool.connect((err, client, release) => { - if (err) { - return done(err); - } - if (!release) { - throw new Error('Did not receive release function'); - } - if (!client) { - throw new Error('No client received'); - } - assert.ok(client); - runCallbackTest( - parentSpan, - pgPoolattributes, - events, - unsetStatus, - 1, - 0 - ); - client.query('SELECT NOW()', (err, ret) => { - release(); - if (err) { - return done(err); - } - assert.ok(ret); - runCallbackTest( - parentSpan, - pgAttributes, - events, - unsetStatus, - 2, - 1 - ); - done(); - }); - }); - assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); - }); - }); - }); - - describe('#pool.query()', () => { - // promise - it('should call patched client.query()', async () => { - const pgPoolattributes = { - ...DEFAULT_PGPOOL_ATTRIBUTES, - }; - const pgAttributes = { - ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', - }; - const events: TimedEvent[] = []; - const span = provider.getTracer('test-pg-pool').startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - const result = await pool.query('SELECT NOW()'); - runCallbackTest(span, pgPoolattributes, events, unsetStatus, 2, 0); - runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1); - assert.ok(result, 'pool.query() returns a promise'); - }); - }); - - // callback - it('should not return a promise if callback is provided', done => { - const pgPoolattributes = { - ...DEFAULT_PGPOOL_ATTRIBUTES, - }; - const pgAttributes = { - ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', - }; - const events: TimedEvent[] = []; - const parentSpan = provider - .getTracer('test-pg-pool') - .startSpan('test span'); - context.with(setSpan(context.active(), parentSpan), () => { - const resNoPromise = pool.query('SELECT NOW()', (err, result) => { - if (err) { - return done(err); - } - runCallbackTest( - parentSpan, - pgPoolattributes, - events, - unsetStatus, - 2, - 0 - ); - runCallbackTest(parentSpan, pgAttributes, events, unsetStatus, 2, 1); - done(); - }); - assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-pg-pool/tsconfig.json b/plugins/node/opentelemetry-plugin-pg-pool/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-pg-pool/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-pg/.eslintignore b/plugins/node/opentelemetry-plugin-pg/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-pg/.eslintrc.js b/plugins/node/opentelemetry-plugin-pg/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-pg/.npmignore b/plugins/node/opentelemetry-plugin-pg/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-pg/LICENSE b/plugins/node/opentelemetry-plugin-pg/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-pg/README.md b/plugins/node/opentelemetry-plugin-pg/README.md deleted file mode 100644 index 69d1ede2eb..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# OpenTelemetry Postgres Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`pg`](https://github.com/brianc/node-postgres). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -```bash -npm install --save @opentelemetry/plugin-pg -npm install --save @opentelemetry/plugin-pg-pool -``` - -## Usage - -To load all of the [default supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use the below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider(); // All default plugins will be used -``` - -If instead you would just want to load a specific plugin (**pg** in this case), specify it in the `NodeTracer` configuration. - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider({ - plugins: { - pg: { - enabled: true, - // You may use a package name or absolute path to the module - path: '@opentelemetry/plugin-pg', - } - } -}); -``` - -If you are using any of the [`pg.Pool`](https://node-postgres.com/api/pool) APIs, you will also need to include the [`pg-pool` plugin](../opentelemetry-plugin-pg-pool). - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); - -const provider = new NodeTracerProvider({ - plugins: { - pg: { - enabled: true, - // You may use a package name or absolute path to the module - path: '@opentelemetry/plugin-pg', - }, - 'pg-pool': { - enabled: true, - // You may use a package name or absolute path to the module - path: '@opentelemetry/plugin-pg-pool', - }, - } -}); -``` - -See [examples/postgres](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/postgres) for a short example. - -### PostgreSQL Plugin Options - -PostgreSQL plugin has few options available to choose from. You can set the following: - -| Options | Type | Description | -| ------- | ---- | ----------- | -| [`enhancedDatabaseReporting`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-api/src/trace/instrumentation/Plugin.ts#L90) | `boolean` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations | - -## Supported Versions - -- [pg](https://npmjs.com/package/pg): `7.x` -- [pg-pool](https://npmjs.com/package/pg-pool): `2.x` (Installed by `pg`) - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-pg -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-pg -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-pg&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-pg&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-pg -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-pg.svg diff --git a/plugins/node/opentelemetry-plugin-pg/package.json b/plugins/node/opentelemetry-plugin-pg/package.json deleted file mode 100644 index 5a034e86d6..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "@opentelemetry/plugin-pg", - "version": "0.15.0", - "description": "OpenTelemetry postgres automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:debug": "ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", - "test:local": "cross-env RUN_POSTGRES_TESTS_LOCAL=true npm run test", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "prepare": "npm run compile", - "watch": "tsc -w" - }, - "keywords": [ - "opentelemetry", - "postgres", - "pg", - "postgresql", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/test-utils": "^0.15.0", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/pg": "7.14.4", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "cross-env": "7.0.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "nyc": "15.1.0", - "pg": "8.3.0", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-pg/src/enums.ts b/plugins/node/opentelemetry-plugin-pg/src/enums.ts deleted file mode 100644 index ee9f5d3682..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/enums.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 enum AttributeNames { - // required by https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-database.md - COMPONENT = 'component', - DB_TYPE = 'db.type', - DB_INSTANCE = 'db.instance', - DB_STATEMENT = 'db.statement', - PEER_ADDRESS = 'peer.address', - PEER_HOSTNAME = 'peer.host', - - // optional - DB_USER = 'db.user', - PEER_PORT = 'peer.port', - PEER_IPV4 = 'peer.ipv4', - PEER_IPV6 = 'peer.ipv6', - PEER_SERVICE = 'peer.service', - - // PG specific -- not specified by spec - PG_VALUES = 'pg.values', - PG_PLAN = 'pg.plan', -} diff --git a/plugins/node/opentelemetry-plugin-pg/src/index.ts b/plugins/node/opentelemetry-plugin-pg/src/index.ts deleted file mode 100644 index f9b5606213..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './pg'; diff --git a/plugins/node/opentelemetry-plugin-pg/src/pg.ts b/plugins/node/opentelemetry-plugin-pg/src/pg.ts deleted file mode 100644 index f74e5d739b..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/pg.ts +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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 { BasePlugin, isWrapped } from '@opentelemetry/core'; -import { - context, - diag, - SpanStatusCode, - Span, - getSpan, -} from '@opentelemetry/api'; -import * as pgTypes from 'pg'; -import * as shimmer from 'shimmer'; -import { - PgClientExtended, - NormalizedQueryConfig, - PostgresCallback, - PostgresPluginConfig, -} from './types'; -import * as utils from './utils'; -import { VERSION } from './version'; - -export class PostgresPlugin extends BasePlugin { - static readonly COMPONENT = 'pg'; - static readonly DB_TYPE = 'sql'; - - protected _config!: PostgresPluginConfig; - - static readonly BASE_SPAN_NAME = PostgresPlugin.COMPONENT + '.query'; - - readonly supportedVersions = ['7.*', '8.*']; - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-pg', VERSION); - this._config = {}; - } - - protected patch(): typeof pgTypes { - if (!isWrapped(this._moduleExports.Client.prototype.query)) { - shimmer.wrap( - this._moduleExports.Client.prototype, - 'query', - this._getClientQueryPatch() as never - ); - } - return this._moduleExports; - } - - protected unpatch(): void { - shimmer.unwrap(this._moduleExports.Client.prototype, 'query'); - } - - private _getClientQueryPatch() { - const plugin = this; - return (original: typeof pgTypes.Client.prototype.query) => { - diag.debug(`Patching ${PostgresPlugin.COMPONENT}.Client.prototype.query`); - return function query(this: PgClientExtended, ...args: unknown[]) { - let span: Span; - - // Handle different client.query(...) signatures - if (typeof args[0] === 'string') { - const query = args[0]; - if (args.length > 1 && args[1] instanceof Array) { - const params = args[1]; - span = utils.handleParameterizedQuery.call( - this, - plugin._tracer, - plugin._config, - query, - params - ); - if (plugin._config.postQueryHook) { - plugin._config.postQueryHook({ span, query, params }); - } - } else { - span = utils.handleTextQuery.call(this, plugin._tracer, query); - if (plugin._config.postQueryHook) { - plugin._config.postQueryHook({ span, query }); - } - } - } else if (typeof args[0] === 'object') { - const queryConfig = args[0] as NormalizedQueryConfig; - span = utils.handleConfigQuery.call( - this, - plugin._tracer, - plugin._config, - queryConfig - ); - if (plugin._config.postQueryHook) { - plugin._config.postQueryHook({ span, config: queryConfig }); - } - } else { - return utils.handleInvalidQuery.call( - this, - plugin._tracer, - original, - ...args - ); - } - - // Bind callback to parent span - if (args.length > 0) { - const parentSpan = getSpan(context.active()); - if (typeof args[args.length - 1] === 'function') { - // Patch ParameterQuery callback - args[args.length - 1] = utils.patchCallback( - span, - args[args.length - 1] as PostgresCallback - ); - // If a parent span exists, bind the callback - if (parentSpan) { - args[args.length - 1] = context.bind(args[args.length - 1]); - } - } else if ( - typeof (args[0] as NormalizedQueryConfig).callback === 'function' - ) { - // Patch ConfigQuery callback - let callback = utils.patchCallback( - span, - (args[0] as NormalizedQueryConfig).callback! - ); - // If a parent span existed, bind the callback - if (parentSpan) { - callback = context.bind(callback); - } - - // Copy the callback instead of writing to args.callback so that we don't modify user's - // original callback reference - args[0] = { ...(args[0] as object), callback }; - } - } - - // Perform the original query - const result: unknown = original.apply(this, args as never); - - // Bind promise to parent span and end the span - if (result instanceof Promise) { - return result - .then((result: unknown) => { - // Return a pass-along promise which ends the span and then goes to user's orig resolvers - return new Promise(resolve => { - span.end(); - resolve(result); - }); - }) - .catch((error: Error) => { - return new Promise((_, reject) => { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: error.message, - }); - span.end(); - reject(error); - }); - }); - } - - // else returns void - return result; // void - }; - }; - } -} - -export const plugin = new PostgresPlugin(PostgresPlugin.COMPONENT); diff --git a/plugins/node/opentelemetry-plugin-pg/src/types.ts b/plugins/node/opentelemetry-plugin-pg/src/types.ts deleted file mode 100644 index 30cab5839b..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/types.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 { Span } from '@opentelemetry/api'; -import { PluginConfig } from '@opentelemetry/core'; - -import * as pgTypes from 'pg'; - -export type PostgresCallback = (err: Error, res: object) => unknown; - -// These are not included in @types/pg, so manually define them. -// https://github.com/brianc/node-postgres/blob/fde5ec586e49258dfc4a2fcd861fcdecb4794fc3/lib/client.js#L25 -export interface PgClientConnectionParams { - database: string; - host: string; - port: number; - user: string; -} - -export interface PgClientExtended extends pgTypes.Client { - connectionParameters: PgClientConnectionParams; -} - -// Interface name based on original driver implementation -// https://github.com/brianc/node-postgres/blob/2ef55503738eb2cbb6326744381a92c0bc0439ab/packages/pg/lib/utils.js#L157 -export interface NormalizedQueryConfig extends pgTypes.QueryConfig { - callback?: PostgresCallback; -} - -export interface PostgresPostQueryHookFunction { - (ctx: QueryContext): void; -} - -export interface QueryContext { - span: Span; - query?: string; - config?: NormalizedQueryConfig; - params?: unknown[]; -} - -// Options available for the Postgres Plugin -export interface PostgresPluginConfig extends PluginConfig { - postQueryHook?: PostgresPostQueryHookFunction; -} diff --git a/plugins/node/opentelemetry-plugin-pg/src/utils.ts b/plugins/node/opentelemetry-plugin-pg/src/utils.ts deleted file mode 100644 index dd73d8ba10..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/utils.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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 { Span, SpanStatusCode, Tracer, SpanKind } from '@opentelemetry/api'; -import { PluginConfig } from '@opentelemetry/core'; -import { AttributeNames } from './enums'; -import { - PgClientExtended, - NormalizedQueryConfig, - PostgresCallback, - PgClientConnectionParams, -} from './types'; -import * as pgTypes from 'pg'; -import { PostgresPlugin } from './pg'; - -function arrayStringifyHelper(arr: Array): string { - return '[' + arr.toString() + ']'; -} - -// Helper function to get a low cardinality command name from the full text query -function getCommandFromText(text?: string): string { - if (!text) return 'unknown'; - const words = text.split(' '); - return words[0].length > 0 ? words[0] : 'unknown'; -} - -function getJDBCString(params: PgClientConnectionParams) { - const host = params.host || 'localhost'; // postgres defaults to localhost - const port = params.port || 5432; // postgres defaults to port 5432 - const database = params.database || ''; - return `jdbc:postgresql://${host}:${port}/${database}`; -} - -// Private helper function to start a span -function pgStartSpan(tracer: Tracer, client: PgClientExtended, name: string) { - const jdbcString = getJDBCString(client.connectionParameters); - return tracer.startSpan(name, { - kind: SpanKind.CLIENT, - attributes: { - [AttributeNames.COMPONENT]: PostgresPlugin.COMPONENT, // required - [AttributeNames.DB_INSTANCE]: client.connectionParameters.database, // required - [AttributeNames.DB_TYPE]: PostgresPlugin.DB_TYPE, // required - [AttributeNames.PEER_ADDRESS]: jdbcString, // required - [AttributeNames.PEER_HOSTNAME]: client.connectionParameters.host, // required - [AttributeNames.PEER_PORT]: client.connectionParameters.port, - [AttributeNames.DB_USER]: client.connectionParameters.user, - }, - }); -} - -// Queries where args[0] is a QueryConfig -export function handleConfigQuery( - this: PgClientExtended, - tracer: Tracer, - pluginConfig: PluginConfig, - queryConfig: NormalizedQueryConfig -) { - // Set child span name - const queryCommand = getCommandFromText(queryConfig.name || queryConfig.text); - const name = PostgresPlugin.BASE_SPAN_NAME + ':' + queryCommand; - const span = pgStartSpan(tracer, this, name); - - // Set attributes - if (queryConfig.text) { - span.setAttribute(AttributeNames.DB_STATEMENT, queryConfig.text); - } - if ( - pluginConfig.enhancedDatabaseReporting && - queryConfig.values instanceof Array - ) { - span.setAttribute( - AttributeNames.PG_VALUES, - arrayStringifyHelper(queryConfig.values) - ); - } - // Set plan name attribute, if present - if (queryConfig.name) { - span.setAttribute(AttributeNames.PG_PLAN, queryConfig.name); - } - - return span; -} - -// Queries where args[1] is a 'values' array -export function handleParameterizedQuery( - this: PgClientExtended, - tracer: Tracer, - pluginConfig: PluginConfig, - query: string, - values: unknown[] -) { - // Set child span name - const queryCommand = getCommandFromText(query); - const name = PostgresPlugin.BASE_SPAN_NAME + ':' + queryCommand; - const span = pgStartSpan(tracer, this, name); - - // Set attributes - span.setAttribute(AttributeNames.DB_STATEMENT, query); - if (pluginConfig.enhancedDatabaseReporting) { - span.setAttribute(AttributeNames.PG_VALUES, arrayStringifyHelper(values)); - } - - return span; -} - -// Queries where args[0] is a text query and 'values' was not specified -export function handleTextQuery( - this: PgClientExtended, - tracer: Tracer, - query: string -) { - // Set child span name - const queryCommand = getCommandFromText(query); - const name = PostgresPlugin.BASE_SPAN_NAME + ':' + queryCommand; - const span = pgStartSpan(tracer, this, name); - - // Set attributes - span.setAttribute(AttributeNames.DB_STATEMENT, query); - - return span; -} - -/** - * Invalid query handler. We should never enter this function unless invalid args were passed to the driver. - * Create and immediately end a new span - */ -export function handleInvalidQuery( - this: PgClientExtended, - tracer: Tracer, - originalQuery: typeof pgTypes.Client.prototype.query, - ...args: unknown[] -) { - let result; - const span = pgStartSpan(tracer, this, PostgresPlugin.BASE_SPAN_NAME); - try { - result = originalQuery.apply(this, args as never); - } catch (e) { - span.setStatus({ code: SpanStatusCode.ERROR, message: e.message }); - throw e; - } finally { - span.end(); - } - return result; -} - -export function patchCallback( - span: Span, - cb: PostgresCallback -): PostgresCallback { - return function patchedCallback( - this: PgClientExtended, - err: Error, - res: object - ) { - if (err) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }); - } - span.end(); - cb.call(this, err, res); - }; -} diff --git a/plugins/node/opentelemetry-plugin-pg/src/version.ts b/plugins/node/opentelemetry-plugin-pg/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-pg/test/pg.test.ts b/plugins/node/opentelemetry-plugin-pg/test/pg.test.ts deleted file mode 100644 index 0e0a1a6bfa..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/test/pg.test.ts +++ /dev/null @@ -1,536 +0,0 @@ -/* - * 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 { - SpanAttributes, - SpanStatusCode, - context, - Span, - SpanKind, - SpanStatus, - TimedEvent, - setSpan, - getSpan, -} from '@opentelemetry/api'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import * as testUtils from '@opentelemetry/test-utils'; -import { - BasicTracerProvider, - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as pg from 'pg'; -import { plugin, PostgresPlugin } from '../src'; -import { AttributeNames } from '../src/enums'; -import { PostgresPluginConfig } from '../src/types'; - -const memoryExporter = new InMemorySpanExporter(); - -const CONFIG = { - user: process.env.POSTGRES_USER || 'postgres', - database: process.env.POSTGRES_DB || 'postgres', - host: process.env.POSTGRES_HOST || 'localhost', - port: process.env.POSTGRES_PORT - ? parseInt(process.env.POSTGRES_PORT, 10) - : 54320, -}; - -const DEFAULT_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PostgresPlugin.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PostgresPlugin.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, -}; - -const unsetStatus: SpanStatus = { - code: SpanStatusCode.UNSET, -}; -const errorStatus: SpanStatus = { - code: SpanStatusCode.ERROR, -}; - -const runCallbackTest = ( - span: Span | null, - attributes: SpanAttributes, - events: TimedEvent[], - status: SpanStatus = unsetStatus, - spansLength = 1, - spansIndex = 0 -) => { - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, spansLength); - const pgSpan = spans[spansIndex]; - testUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events, status); - if (span) { - testUtils.assertPropagation(pgSpan, span); - } -}; - -describe('pg@7.x', () => { - let client: pg.Client; - let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); - const tracer = provider.getTracer('external'); - const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available - const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker - const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) - - before(async function () { - if (!shouldTest) { - // this.skip() workaround - // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 - this.test!.parent!.pending = true; - this.skip(); - } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - if (testPostgresLocally) { - testUtils.startDocker('postgres'); - } - - client = new pg.Client(CONFIG); - await client.connect(); - }); - - after(async () => { - if (testPostgresLocally) { - testUtils.cleanUpDocker('postgres'); - } - await client.end(); - }); - - beforeEach(() => { - plugin.enable(pg, provider); - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(() => { - memoryExporter.reset(); - plugin.disable(); - context.disable(); - }); - - it('should return a plugin', () => { - assert.ok(plugin instanceof PostgresPlugin); - }); - - it('should have correct moduleName', () => { - assert.strictEqual(plugin.moduleName, 'pg'); - }); - - it('should maintain pg module error throwing behavior with bad arguments', () => { - const assertPgError = (e: Error) => { - const src = e.stack!.split('\n').map(line => line.trim())[1]; - return /node_modules[/\\]pg/.test(src); - }; - - assert.throws( - () => { - (client as any).query(); - }, - assertPgError, - 'pg should throw when no args provided' - ); - runCallbackTest(null, DEFAULT_ATTRIBUTES, [], errorStatus); - memoryExporter.reset(); - - assert.doesNotThrow( - () => - (client as any).query({ foo: 'bar' }, undefined, () => { - runCallbackTest( - null, - { - ...DEFAULT_ATTRIBUTES, - }, - [], - errorStatus - ); - }), - 'pg should not throw when invalid config args are provided' - ); - }); - - describe('#client.query(...)', () => { - it('should not return a promise if callback is provided', done => { - const res = client.query('SELECT NOW()', (err, res) => { - assert.strictEqual(err, null); - done(); - }); - assert.strictEqual(res, undefined, 'No promise is returned'); - }); - - it('should return a promise if callback is provided', done => { - const resPromise = client.query('SELECT NOW()'); - resPromise - .then(res => { - assert.ok(res); - done(); - }) - .catch((err: Error) => { - assert.ok(false, err.message); - }); - }); - - it('should intercept client.query(text, callback)', done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const res = client.query('SELECT NOW()', (err, res) => { - assert.strictEqual(err, null); - assert.ok(res); - runCallbackTest(span, attributes, events); - done(); - }); - assert.strictEqual(res, undefined, 'No promise is returned'); - }); - }); - - it('should intercept client.query(text, values, callback)', done => { - const query = 'SELECT $1::text'; - const values = ['0']; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const resNoPromise = client.query(query, values, (err, res) => { - assert.strictEqual(err, null); - assert.ok(res); - runCallbackTest(span, attributes, events); - done(); - }); - assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); - }); - }); - - it('should intercept client.query({text, callback})', done => { - const query = 'SELECT NOW()'; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const resNoPromise = client.query({ - text: query, - callback: (err: Error, res: pg.QueryResult) => { - assert.strictEqual(err, null); - assert.ok(res); - runCallbackTest(span, attributes, events); - done(); - }, - } as pg.QueryConfig); - assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); - }); - }); - - it('should intercept client.query({text}, callback)', done => { - const query = 'SELECT NOW()'; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - const resNoPromise = client.query({ text: query }, (err, res) => { - assert.strictEqual(err, null); - assert.ok(res); - runCallbackTest(span, attributes, events); - done(); - }); - assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); - }); - }); - - it('should intercept client.query(text, values)', async () => { - const query = 'SELECT $1::text'; - const values = ['0']; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - const resPromise = await client.query(query, values); - try { - assert.ok(resPromise); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - }); - - it('should intercept client.query({text, values})', async () => { - const query = 'SELECT $1::text'; - const values = ['0']; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - const resPromise = await client.query({ - text: query, - values: values, - }); - try { - assert.ok(resPromise); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - }); - - it('should intercept client.query(plan)', async () => { - const name = 'fetch-text'; - const query = 'SELECT $1::text'; - const values = ['0']; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.PG_PLAN]: name, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - - await context.with(setSpan(context.active(), span), async () => { - try { - const resPromise = await client.query({ - name: name, - text: query, - values: values, - }); - assert.strictEqual(resPromise.command, 'SELECT'); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - }); - - it('should intercept client.query(text)', async () => { - const query = 'SELECT NOW()'; - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - const resPromise = await client.query(query); - assert.ok(resPromise); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - }); - - it('should handle the same callback being given to multiple client.query()s', done => { - let events = 0; - const parent = tracer.startSpan('parent'); - - const queryHandler = (err?: Error, res?: pg.QueryResult) => { - const span = getSpan(context.active()); - assert.deepStrictEqual(span!.context(), parent.context()); - if (err) { - throw err; - } - events += 1; - if (events === 7) { - done(); - } - }; - - const config = { - text: 'SELECT NOW()', - callback: queryHandler, - }; - - context.with(setSpan(context.active(), parent), () => { - client.query(config.text, config.callback); // 1 - client.query(config); // 2 - client.query(config.text, queryHandler); // 3 - client.query(config.text, queryHandler); // 4 - client - .query(config.text) - .then(result => queryHandler(undefined, result)) - .catch(err => queryHandler(err)); // 5 - client.query(config); // 6 - client.query(config); // 7 - }); - }); - - it('should preserve correct context even when using the same callback in client.query()', done => { - const spans = [tracer.startSpan('span 1'), tracer.startSpan('span 2')]; - const currentSpans: (Span | undefined)[] = []; - const queryHandler = () => { - currentSpans.push(getSpan(context.active())); - if (currentSpans.length === 2) { - assert.deepStrictEqual(currentSpans, spans); - done(); - } - }; - - context.with(setSpan(context.active(), spans[0]), () => { - client.query('SELECT NOW()', queryHandler); - }); - context.with(setSpan(context.active(), spans[1]), () => { - client.query('SELECT NOW()', queryHandler); - }); - }); - - it('should preserve correct context even when using the same promise resolver in client.query()', done => { - const spans = [tracer.startSpan('span 1'), tracer.startSpan('span 2')]; - const currentSpans: (Span | undefined)[] = []; - const queryHandler = () => { - currentSpans.push(getSpan(context.active())); - if (currentSpans.length === 2) { - assert.deepStrictEqual(currentSpans, spans); - done(); - } - }; - - context.with(setSpan(context.active(), spans[0]), () => { - client.query('SELECT NOW()').then(queryHandler); - }); - context.with(setSpan(context.active(), spans[1]), () => { - client.query('SELECT NOW()').then(queryHandler); - }); - }); - - it('should call postQueryHook with query text if set', async () => { - plugin.disable(); - let called = false; - const query = 'SELECT NOW()'; - const config: PostgresPluginConfig = { - postQueryHook: ctx => { - called = true; - assert.strictEqual(ctx.query, query); - assert.strictEqual(ctx.params, undefined); - }, - }; - plugin.enable(pg, provider, config); - - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - try { - const resPromise = await client.query(query); - assert.ok(resPromise); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - assert.strictEqual(called, true); - }); - it('should call postQueryHook with query text and params if set', async () => { - plugin.disable(); - let called = false; - const values = ['0']; - const query = 'SELECT $1::text'; - const config: PostgresPluginConfig = { - postQueryHook: ctx => { - called = true; - assert.strictEqual(ctx.query, query); - assert.strictEqual(ctx.params, values); - }, - }; - plugin.enable(pg, provider, config); - - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await context.with(setSpan(context.active(), span), async () => { - const resPromise = await client.query(query, values); - try { - assert.ok(resPromise); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - assert.strictEqual(called, true); - }); - - it('should call postQueryHook with query config if set', async () => { - plugin.disable(); - const name = 'fetch-text'; - const query = 'SELECT $1::text'; - const values = ['0']; - let called = false; - const config: PostgresPluginConfig = { - postQueryHook: ctx => { - called = true; - if (!ctx.config) { - assert.ok(false, 'ctx.config was undefined'); - } - assert.strictEqual(ctx.config.text, query); - assert.strictEqual(ctx.config.values, values); - }, - }; - plugin.enable(pg, provider, config); - - const attributes = { - ...DEFAULT_ATTRIBUTES, - [AttributeNames.PG_PLAN]: name, - [AttributeNames.DB_STATEMENT]: query, - }; - const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - - await context.with(setSpan(context.active(), span), async () => { - try { - const resPromise = await client.query({ - name: name, - text: query, - values: values, - }); - assert.strictEqual(resPromise.command, 'SELECT'); - runCallbackTest(span, attributes, events); - } catch (e) { - assert.ok(false, e.message); - } - }); - assert.strictEqual(called, true); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-pg/test/utils.test.ts b/plugins/node/opentelemetry-plugin-pg/test/utils.test.ts deleted file mode 100644 index 50b3829b2f..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/test/utils.test.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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 { context } from '@opentelemetry/api'; -import { PluginConfig } from '@opentelemetry/core'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import { - BasicTracerProvider, - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as pg from 'pg'; -import { AttributeNames } from '../src/enums'; -import { PgClientExtended, NormalizedQueryConfig } from '../src/types'; -import * as utils from '../src/utils'; - -const memoryExporter = new InMemorySpanExporter(); - -const CONFIG = { - user: process.env.POSTGRES_USER || 'postgres', - database: process.env.POSTGRES_DB || 'postgres', - host: process.env.POSTGRES_HOST || 'localhost', - port: process.env.POSTGRES_PORT - ? parseInt(process.env.POSTGRES_PORT, 10) - : 54320, -}; - -const getLatestSpan = () => { - const spans = memoryExporter.getFinishedSpans(); - return spans[spans.length - 1]; -}; - -describe('utils.ts', () => { - const client = new pg.Client(CONFIG) as PgClientExtended; - let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); - const tracer = provider.getTracer('external'); - - const pluginConfig: PluginConfig = {}; - - before(() => { - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - }); - - beforeEach(() => { - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(() => { - memoryExporter.reset(); - context.disable(); - }); - - describe('.handleConfigQuery()', () => { - const queryConfig: NormalizedQueryConfig = { - text: 'SELECT $1::text', - values: ['0'], - }; - - it('does not track pg.values by default', async () => { - const querySpan = utils.handleConfigQuery.call( - client, - tracer, - pluginConfig, - queryConfig - ); - querySpan.end(); - - const readableSpan = getLatestSpan(); - - const pgValues = readableSpan.attributes[AttributeNames.PG_VALUES]; - assert.strictEqual(pgValues, undefined); - }); - - it('tracks pg.values if enabled explicitly', async () => { - const extPluginConfig: PluginConfig = { - ...pluginConfig, - enhancedDatabaseReporting: true, - }; - const querySpan = utils.handleConfigQuery.call( - client, - tracer, - extPluginConfig, - queryConfig - ); - querySpan.end(); - - const readableSpan = getLatestSpan(); - - const pgValues = readableSpan.attributes[AttributeNames.PG_VALUES]; - assert.strictEqual(pgValues, '[0]'); - }); - }); - - describe('.handleParameterizedQuery()', () => { - const query = 'SELECT $1::text'; - const values = ['0']; - - it('does not track pg.values by default', async () => { - const querySpan = utils.handleParameterizedQuery.call( - client, - tracer, - pluginConfig, - query, - values - ); - querySpan.end(); - - const readableSpan = getLatestSpan(); - - const pgValues = readableSpan.attributes[AttributeNames.PG_VALUES]; - assert.strictEqual(pgValues, undefined); - }); - - it('tracks pg.values if enabled explicitly', async () => { - const extPluginConfig: PluginConfig = { - ...pluginConfig, - enhancedDatabaseReporting: true, - }; - const querySpan = utils.handleParameterizedQuery.call( - client, - tracer, - extPluginConfig, - query, - values - ); - querySpan.end(); - - const readableSpan = getLatestSpan(); - - const pgValues = readableSpan.attributes[AttributeNames.PG_VALUES]; - assert.strictEqual(pgValues, '[0]'); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-pg/tsconfig.json b/plugins/node/opentelemetry-plugin-pg/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-pg/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/plugins/node/opentelemetry-plugin-redis/.eslintignore b/plugins/node/opentelemetry-plugin-redis/.eslintignore deleted file mode 100644 index 378eac25d3..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/plugins/node/opentelemetry-plugin-redis/.eslintrc.js b/plugins/node/opentelemetry-plugin-redis/.eslintrc.js deleted file mode 100644 index f756f4488b..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "node": true - }, - ...require('../../../eslint.config.js') -} diff --git a/plugins/node/opentelemetry-plugin-redis/.npmignore b/plugins/node/opentelemetry-plugin-redis/.npmignore deleted file mode 100644 index 9505ba9450..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin -/coverage -/doc -/test diff --git a/plugins/node/opentelemetry-plugin-redis/LICENSE b/plugins/node/opentelemetry-plugin-redis/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 [yyyy] [name of copyright owner] - - 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/opentelemetry-plugin-redis/README.md b/plugins/node/opentelemetry-plugin-redis/README.md deleted file mode 100644 index 8bc250f39c..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# OpenTelemetry redis Instrumentation for Node.js - -[![NPM Published Version][npm-img]][npm-url] -[![dependencies][dependencies-image]][dependencies-url] -[![devDependencies][devDependencies-image]][devDependencies-url] -[![Apache License][license-image]][license-image] - -This module provides automatic instrumentation for [`redis@^2.6.0`](https://github.com/NodeRedis/node_redis). - -For automatic instrumentation see the -[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. - -## Installation - -``` -npm install --save @opentelemetry/plugin-redis -``` - -### Supported Versions - - `>=2.6.0` - -## Usage - -OpenTelemetry Redis Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with [redis](https://www.npmjs.com/package/redis). - -To load a specific plugin (**redis** in this case), specify it in the registerInstrumentations's configuration -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - instrumentations: [ - { - plugins: { - redis: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-redis', - } - }, - }, - ], - tracerProvider: provider, -}); -``` - -To load all of the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. -```javascript -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); - -const provider = new NodeTracerProvider(); -provider.register(); -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -See [examples/redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/redis) for a short example. - -## 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/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-redis -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-redis -[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-contrib.svg?path=plugins%2Fnode%2Fopentelemetry-plugin-redis&type=dev -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=plugins%2Fnode%2Fopentelemetry-plugin-redis&type=dev -[npm-url]: https://www.npmjs.com/package/@opentelemetry/plugin-redis -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fplugin-redis.svg diff --git a/plugins/node/opentelemetry-plugin-redis/package.json b/plugins/node/opentelemetry-plugin-redis/package.json deleted file mode 100644 index d9418dd3a9..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@opentelemetry/plugin-redis", - "version": "0.15.0", - "description": "OpenTelemetry redis automatic instrumentation package.", - "main": "build/src/index.js", - "types": "build/src/index.d.ts", - "repository": "open-telemetry/opentelemetry-js-contrib", - "scripts": { - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'", - "test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test", - "tdd": "npm run test -- --watch-extensions ts --watch", - "clean": "rimraf build/*", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "precompile": "tsc --version", - "version:update": "node ../../../scripts/version-update.js", - "compile": "npm run version:update && tsc -p .", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "prepare": "npm run compile" - }, - "keywords": [ - "opentelemetry", - "redis", - "nodejs", - "tracing", - "profiling", - "plugin" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - }, - "files": [ - "build/src/**/*.js", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@opentelemetry/context-async-hooks": "0.18.2", - "@opentelemetry/node": "0.18.2", - "@opentelemetry/semantic-conventions": "0.18.2", - "@opentelemetry/test-utils": "^0.15.0", - "@opentelemetry/tracing": "0.18.2", - "@types/mocha": "7.0.2", - "@types/node": "14.0.27", - "@types/redis": "2.8.25", - "@types/shimmer": "1.0.1", - "codecov": "3.7.2", - "cross-env": "7.0.2", - "gts": "3.1.0", - "mocha": "7.2.0", - "nyc": "15.1.0", - "redis": "3.0.2", - "rimraf": "3.0.2", - "ts-mocha": "8.0.0", - "ts-node": "9.0.0", - "tslint-consistent-codestyle": "1.16.0", - "tslint-microsoft-contrib": "6.2.0", - "typescript": "4.1.3" - }, - "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "shimmer": "^1.2.1" - } -} diff --git a/plugins/node/opentelemetry-plugin-redis/src/index.ts b/plugins/node/opentelemetry-plugin-redis/src/index.ts deleted file mode 100644 index 36ffbfcc71..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 './redis'; diff --git a/plugins/node/opentelemetry-plugin-redis/src/redis.ts b/plugins/node/opentelemetry-plugin-redis/src/redis.ts deleted file mode 100644 index 1dce593375..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/redis.ts +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 { diag } from '@opentelemetry/api'; -import { BasePlugin } from '@opentelemetry/core'; -import type * as redisTypes from 'redis'; -import * as shimmer from 'shimmer'; -import { - getTracedCreateClient, - getTracedCreateStreamTrace, - getTracedInternalSendCommand, -} from './utils'; -import { VERSION } from './version'; - -export class RedisPlugin extends BasePlugin { - static readonly COMPONENT = 'redis'; - readonly supportedVersions = ['^2.6.0', '^3.0.0']; // equivalent to >= 2.6.0 - - constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-redis', VERSION); - } - - protected patch() { - if (this._moduleExports.RedisClient) { - diag.debug('Patching redis.RedisClient.prototype.internal_send_command'); - shimmer.wrap( - this._moduleExports.RedisClient.prototype, - 'internal_send_command', - this._getPatchInternalSendCommand() - ); - - diag.debug('patching redis.create_stream'); - shimmer.wrap( - this._moduleExports.RedisClient.prototype, - 'create_stream', - this._getPatchCreateStream() - ); - - diag.debug('patching redis.createClient'); - shimmer.wrap( - this._moduleExports, - 'createClient', - this._getPatchCreateClient() - ); - } - return this._moduleExports; - } - - protected unpatch(): void { - if (this._moduleExports) { - shimmer.unwrap( - this._moduleExports.RedisClient.prototype, - 'internal_send_command' - ); - shimmer.unwrap( - this._moduleExports.RedisClient.prototype, - 'create_stream' - ); - shimmer.unwrap(this._moduleExports, 'createClient'); - } - } - - /** - * Patch internal_send_command(...) to trace requests - */ - private _getPatchInternalSendCommand() { - const tracer = this._tracer; - return function internal_send_command(original: Function) { - return getTracedInternalSendCommand(tracer, original); - }; - } - - private _getPatchCreateClient() { - const tracer = this._tracer; - return function createClient(original: Function) { - return getTracedCreateClient(tracer, original); - }; - } - - private _getPatchCreateStream() { - const tracer = this._tracer; - return function createReadStream(original: Function) { - return getTracedCreateStreamTrace(tracer, original); - }; - } -} - -export const plugin = new RedisPlugin(RedisPlugin.COMPONENT); diff --git a/plugins/node/opentelemetry-plugin-redis/src/types.ts b/plugins/node/opentelemetry-plugin-redis/src/types.ts deleted file mode 100644 index 2c3be48ba4..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/types.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 * as redisTypes from 'redis'; - -// exported from -// https://github.com/NodeRedis/node_redis/blob/master/lib/command.js -export interface RedisCommand { - command: string; - args: string[]; - buffer_args: boolean; - callback: redisTypes.Callback; - call_on_write: boolean; -} - -export interface RedisPluginClientTypes { - options?: { - host: string; - port: string; - }; - - address?: string; -} diff --git a/plugins/node/opentelemetry-plugin-redis/src/utils.ts b/plugins/node/opentelemetry-plugin-redis/src/utils.ts deleted file mode 100644 index 71287e33d7..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/utils.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 * as redisTypes from 'redis'; -import { - context, - Tracer, - SpanKind, - Span, - SpanStatusCode, -} from '@opentelemetry/api'; -import { RedisCommand, RedisPluginClientTypes } from './types'; -import { EventEmitter } from 'events'; -import { RedisPlugin } from './redis'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -const endSpan = (span: Span, err?: Error | null) => { - if (err) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: err.message, - }); - } - span.end(); -}; - -export const getTracedCreateClient = (tracer: Tracer, original: Function) => { - return function createClientTrace(this: redisTypes.RedisClient) { - const client: redisTypes.RedisClient = original.apply(this, arguments); - return context.bind(client); - }; -}; - -export const getTracedCreateStreamTrace = ( - tracer: Tracer, - original: Function -) => { - return function create_stream_trace(this: redisTypes.RedisClient) { - if (!this.stream) { - Object.defineProperty(this, 'stream', { - get() { - return this._patched_redis_stream; - }, - set(val: EventEmitter) { - context.bind(val); - this._patched_redis_stream = val; - }, - }); - } - return original.apply(this, arguments); - }; -}; - -export const getTracedInternalSendCommand = ( - tracer: Tracer, - original: Function -) => { - return function internal_send_command_trace( - this: RedisPluginClientTypes, - cmd?: RedisCommand - ) { - // New versions of redis (2.4+) use a single options object - // instead of named arguments - if (arguments.length === 1 && typeof cmd === 'object') { - const span = tracer.startSpan(`${RedisPlugin.COMPONENT}-${cmd.command}`, { - kind: SpanKind.CLIENT, - attributes: { - [DatabaseAttribute.DB_SYSTEM]: RedisPlugin.COMPONENT, - [DatabaseAttribute.DB_STATEMENT]: cmd.command, - }, - }); - - // Set attributes for not explicitly typed RedisPluginClientTypes - if (this.options) { - span.setAttributes({ - [GeneralAttribute.NET_PEER_HOSTNAME]: this.options.host, - [GeneralAttribute.NET_PEER_PORT]: this.options.port, - }); - } - if (this.address) { - span.setAttribute( - GeneralAttribute.NET_PEER_ADDRESS, - `redis://${this.address}` - ); - } - - const originalCallback = arguments[0].callback; - if (originalCallback) { - (arguments[0] as RedisCommand).callback = function callback( - this: unknown, - err: Error | null, - _reply: T - ) { - endSpan(span, err); - return originalCallback.apply(this, arguments); - }; - } - try { - // Span will be ended in callback - return original.apply(this, arguments); - } catch (rethrow) { - endSpan(span, rethrow); - throw rethrow; // rethrow after ending span - } - } - - // We don't know how to trace this call, so don't start/stop a span - return original.apply(this, arguments); - }; -}; diff --git a/plugins/node/opentelemetry-plugin-redis/src/version.ts b/plugins/node/opentelemetry-plugin-redis/src/version.ts deleted file mode 100644 index 1e4172026f..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.15.0'; diff --git a/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts b/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts deleted file mode 100644 index 9978297ae8..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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 { - SpanStatusCode, - context, - SpanKind, - SpanStatus, - getSpan, - setSpan, -} from '@opentelemetry/api'; -import { NodeTracerProvider } from '@opentelemetry/node'; -import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -import * as testUtils from '@opentelemetry/test-utils'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import * as assert from 'assert'; -import * as redisTypes from 'redis'; -import { plugin, RedisPlugin } from '../src'; -import { - DatabaseAttribute, - GeneralAttribute, -} from '@opentelemetry/semantic-conventions'; - -const memoryExporter = new InMemorySpanExporter(); - -const CONFIG = { - host: process.env.OPENTELEMETRY_REDIS_HOST || 'localhost', - port: process.env.OPENTELEMETRY_REDIS_PORT || '63790', -}; - -const URL = `redis://${CONFIG.host}:${CONFIG.port}`; - -const DEFAULT_ATTRIBUTES = { - [DatabaseAttribute.DB_SYSTEM]: RedisPlugin.COMPONENT, - [GeneralAttribute.NET_PEER_HOSTNAME]: CONFIG.host, - [GeneralAttribute.NET_PEER_PORT]: CONFIG.port, - [GeneralAttribute.NET_PEER_ADDRESS]: URL, -}; - -const unsetStatus: SpanStatus = { - code: SpanStatusCode.UNSET, -}; - -describe('redis@2.x', () => { - const provider = new NodeTracerProvider(); - const tracer = provider.getTracer('external'); - let redis: typeof redisTypes; - const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; - const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; - - let contextManager: AsyncHooksContextManager; - beforeEach(() => { - contextManager = new AsyncHooksContextManager().enable(); - context.setGlobalContextManager(contextManager); - }); - - afterEach(() => { - context.disable(); - }); - - before(function () { - // needs to be "function" to have MochaContext "this" context - if (!shouldTest) { - // this.skip() workaround - // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 - this.test!.parent!.pending = true; - this.skip(); - } - - if (shouldTestLocal) { - testUtils.startDocker('redis'); - } - - redis = require('redis'); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - plugin.enable(redis, provider); - }); - - after(() => { - if (shouldTestLocal) { - testUtils.cleanUpDocker('redis'); - } - }); - - it('should have correct module name', () => { - assert.strictEqual(plugin.moduleName, RedisPlugin.COMPONENT); - }); - - describe('#createClient()', () => { - it('should propagate the current span to event handlers', done => { - const span = tracer.startSpan('test span'); - let client: redisTypes.RedisClient; - const readyHandler = () => { - assert.strictEqual(getSpan(context.active()), span); - client.quit(done); - }; - const errorHandler = (err: Error) => { - assert.ifError(err); - client.quit(done); - }; - - context.with(setSpan(context.active(), span), () => { - client = redis.createClient(URL); - client.on('ready', readyHandler); - client.on('error', errorHandler); - }); - }); - }); - - describe('#send_internal_message()', () => { - let client: redisTypes.RedisClient; - - const REDIS_OPERATIONS: Array<{ - description: string; - command: string; - method: (cb: redisTypes.Callback) => unknown; - }> = [ - { - description: 'insert', - command: 'hset', - method: (cb: redisTypes.Callback) => - client.hset('hash', 'random', 'random', cb), - }, - { - description: 'get', - command: 'get', - method: (cb: redisTypes.Callback) => - client.get('test', cb), - }, - { - description: 'delete', - command: 'del', - method: (cb: redisTypes.Callback) => client.del('test', cb), - }, - ]; - - before(done => { - client = redis.createClient(URL); - client.on('error', err => { - done(err); - }); - client.on('ready', done); - }); - - beforeEach(done => { - client.set('test', 'data', () => { - memoryExporter.reset(); - done(); - }); - }); - - after(done => { - client.quit(done); - }); - - afterEach(done => { - client.del('hash', () => { - memoryExporter.reset(); - done(); - }); - }); - - describe('Instrumenting query operations', () => { - REDIS_OPERATIONS.forEach(operation => { - it(`should create a child span for ${operation.description}`, done => { - const attributes = { - ...DEFAULT_ATTRIBUTES, - [DatabaseAttribute.DB_STATEMENT]: operation.command, - }; - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - operation.method((err, _result) => { - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 2); - assert.strictEqual( - endedSpans[0].name, - `redis-${operation.command}` - ); - testUtils.assertSpan( - endedSpans[0], - SpanKind.CLIENT, - attributes, - [], - unsetStatus - ); - testUtils.assertPropagation(endedSpans[0], span); - done(); - }); - }); - }); - }); - }); - - describe('Removing instrumentation', () => { - before(() => { - plugin.disable(); - }); - - REDIS_OPERATIONS.forEach(operation => { - it(`should not create a child span for ${operation.description}`, done => { - const span = tracer.startSpan('test span'); - context.with(setSpan(context.active(), span), () => { - operation.method((err, _) => { - assert.ifError(err); - assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - span.end(); - const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(endedSpans.length, 1); - assert.strictEqual(endedSpans[0], span); - done(); - }); - }); - }); - }); - }); - }); -}); diff --git a/plugins/node/opentelemetry-plugin-redis/tsconfig.json b/plugins/node/opentelemetry-plugin-redis/tsconfig.json deleted file mode 100644 index 28be80d266..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ] -} diff --git a/propagators/opentelemetry-propagator-grpc-census-binary/README.md b/propagators/opentelemetry-propagator-grpc-census-binary/README.md index 757b1f1f70..2c00845b7e 100644 --- a/propagators/opentelemetry-propagator-grpc-census-binary/README.md +++ b/propagators/opentelemetry-propagator-grpc-census-binary/README.md @@ -17,6 +17,7 @@ Example of usage: const { NodeTracerProvider } = require('@opentelemetry/node'); const { GrpcCensusPropagator } = require("@opentelemetry/propagator-grpc-census-binary"); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { GrpcInstrumentation } = require('opentelemetry/instrumentation-grpc'); const provider = new NodeTracerProvider(); @@ -28,14 +29,7 @@ provider.register({ registerInstrumentations({ instrumentations: [ - { - plugins: { - grpc: { - enabled: true, - path: '@opentelemetry/plugin-grpc', - } - }, - }, + new GrpcInstrumentation(), ], tracerProvider: provider, }); From 2b14dab4d911a6fe67f6f37fd94670774fa2696b Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 15 Apr 2021 21:28:21 +0200 Subject: [PATCH 2/2] chore: updating readme, versions, examples, fixing karma - have to downgrade --- README.md | 10 ++--- .../package.json | 2 +- examples/dns/package.json | 16 +++---- examples/express/package.json | 14 +++--- examples/graphql/package.json | 19 ++++---- examples/graphql/tracer.js | 11 ++--- examples/grpc-census-prop/package.json | 16 +++---- examples/grpc-census-prop/tracer.js | 18 ++++---- examples/grpc_dynamic_codegen/package.json | 44 +++++++++++++++++++ examples/grpc_dynamic_codegen/tracer.js | 19 ++++---- examples/hapi/package.json | 18 ++++---- examples/host-metrics/package.json | 16 +++---- examples/ioredis/package.json | 14 +++--- examples/koa/package.json | 18 ++++---- examples/meta-node/package.json | 14 +++--- examples/meta-node/tracer.js | 20 --------- examples/mongodb/package.json | 16 +++---- examples/mongodb/tracer.js | 5 --- examples/mysql/package.json | 18 ++++---- examples/mysql/server.js | 3 +- examples/mysql/tracer.js | 24 +++++----- examples/postgres/package.json | 18 ++++---- examples/postgres/tracer.js | 14 +++--- examples/react-load/preact/package.json | 12 ++--- examples/react-load/preact/src/web-tracer.js | 2 +- examples/react-load/react/package.json | 14 +++--- examples/redis/package.json | 18 ++++---- examples/redis/tracer.js | 11 +++++ examples/web/package.json | 26 +++++------ karma.base.js | 2 +- karma.webpack.js | 2 +- .../auto-instrumentations-node/package.json | 8 ++-- .../auto-instrumentations-web/package.json | 10 ++--- .../opentelemetry-host-metrics/package.json | 8 ++-- .../package.json | 10 ++--- .../package.json | 6 +-- .../README.md | 9 ++-- .../package.json | 8 ++-- .../README.md | 10 ----- .../package.json | 4 +- .../README.md | 4 +- .../package.json | 6 +-- .../README.md | 1 - .../package.json | 6 +-- .../README.md | 26 ----------- .../package.json | 8 ++-- .../README.md | 14 ++++-- .../package.json | 6 +-- .../README.md | 1 - .../package.json | 6 +-- .../package.json | 6 +-- .../test/connect.test.ts | 1 + .../README.md | 27 ------------ .../package.json | 4 +- .../README.md | 7 --- .../package.json | 6 +-- .../karma.conf.js | 2 +- .../package.json | 14 +++--- .../karma.conf.js | 2 +- .../package.json | 10 ++--- .../karma.conf.js | 2 +- .../package.json | 14 +++--- .../package.json | 4 +- .../package.json | 4 +- scripts/version-update.js | 2 +- 65 files changed, 338 insertions(+), 372 deletions(-) create mode 100644 examples/grpc_dynamic_codegen/package.json diff --git a/README.md b/README.md index ac933641e7..5a00d7946a 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,11 @@ This is a repository for OpenTelemetry JavaScript contributions that are not par [core repository](https://github.com/open-telemetry/opentelemetry-js) and core distribution of the API and SDK. -## Plugins +## Instrumentations OpenTelemetry can collect tracing data automatically using instrumentations. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for: -### Node Plugins +### Node Instrumentations - [@opentelemetry/instrumentation-grpc][otel-instrumentation-grpc] - [@opentelemetry/instrumentation-http][otel-instrumentation-http] @@ -63,7 +63,7 @@ OpenTelemetry can collect tracing data automatically using instrumentations. Ven - [@opentelemetry/instrumentation-koa][otel-contrib-instrumentation-koa] - [@opentelemetry/instrumentation-graphql][otel-contrib-instrumentation-graphql] -### Web Plugins +### Web Instrumentations - [@opentelemetry/instrumentation-xml-http-request][otel-instrumentation-xml-http-request] - [@opentelemetry/instrumentation-document-load][otel-contrib-instrumentation-document-load] @@ -72,7 +72,7 @@ OpenTelemetry can collect tracing data automatically using instrumentations. Ven ### Metapackages -Multiple plugins may be leveraged via metapackages. +Multiple instrumentations may be leveraged via metapackages. - [@opentelemetry/auto-instrumentations-node][otel-contrib-auto-instr-node] - Metapackage which bundles opentelemetry node core and contrib instrumentations - [@opentelemetry/auto-instrumentations-web][otel-contrib-auto-instr-web] - Metapackage which bundles opentelemetry web core and contrib instrumentations @@ -135,4 +135,4 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [otel-contrib-plugin-react-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-plugin-react-load [otel-contrib-auto-instr-node]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node -[otel-contrib-auto-instr-web]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-web \ No newline at end of file +[otel-contrib-auto-instr-web]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-web diff --git a/detectors/node/opentelemetry-resource-detector-github/package.json b/detectors/node/opentelemetry-resource-detector-github/package.json index 0c27b03264..74433cf731 100644 --- a/detectors/node/opentelemetry-resource-detector-github/package.json +++ b/detectors/node/opentelemetry-resource-detector-github/package.json @@ -58,6 +58,6 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/resources": "^0.18.0" + "@opentelemetry/resources": "^0.18.2" } } diff --git a/examples/dns/package.json b/examples/dns/package.json index ee0339dee4..02c9617601 100644 --- a/examples/dns/package.json +++ b/examples/dns/package.json @@ -1,7 +1,7 @@ { "name": "dns-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of DNS integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -26,13 +26,13 @@ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-dns": "^0.14.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-dns": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme", "devDependencies": { diff --git a/examples/express/package.json b/examples/express/package.json index e6ab114ccd..1940b1bbd1 100644 --- a/examples/express/package.json +++ b/examples/express/package.json @@ -1,7 +1,7 @@ { "name": "express-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of Express integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,14 +28,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", "@opentelemetry/instrumentation-express": "^0.15.0", "@opentelemetry/instrumentation-http": "^0.18.2", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "axios": "^0.19.0", "cross-env": "^7.0.3", "express": "^4.17.1" diff --git a/examples/graphql/package.json b/examples/graphql/package.json index 2ad8900c1b..9da18aa89b 100644 --- a/examples/graphql/package.json +++ b/examples/graphql/package.json @@ -1,7 +1,7 @@ { "name": "opentelemetry-plugin-graphql-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of using @opentelemetry/plugin-graphql with OpenTelemetry", "main": "index.js", "scripts": { @@ -31,15 +31,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-graphql": "^0.14.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/plugin-express": "^0.14.0", - "@opentelemetry/plugin-http": "^0.18.0", - "@opentelemetry/plugin-https": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-graphql": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/instrumentation-express": "^0.15.0", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "apollo-server": "^2.18.1", "express": "^4.17.1", "express-graphql": "^0.11.0", diff --git a/examples/graphql/tracer.js b/examples/graphql/tracer.js index 6e3a782f25..7ae4d855bc 100644 --- a/examples/graphql/tracer.js +++ b/examples/graphql/tracer.js @@ -5,6 +5,8 @@ const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graph const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { NodeTracerProvider } = require('@opentelemetry/node'); const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); +const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); +const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express'); const exporter = new CollectorTraceExporter({ serviceName: 'basic-service', @@ -23,12 +25,7 @@ registerInstrumentations({ // depth: 2, // mergeItems: true, }), - { - plugins: { - http: { enabled: false, path: '@opentelemetry/plugin-http' }, - https: { enabled: false, path: '@opentelemetry/plugin-https' }, - express: { enabled: false, path: '@opentelemetry/plugin-express' }, - }, - }, + new HttpInstrumentation(), + new ExpressInstrumentation(), ], }); diff --git a/examples/grpc-census-prop/package.json b/examples/grpc-census-prop/package.json index 37a667913a..76fc84f3b1 100644 --- a/examples/grpc-census-prop/package.json +++ b/examples/grpc-census-prop/package.json @@ -1,6 +1,6 @@ { "name": "grpc-census-prop-example", - "version": "0.14.0", + "version": "0.15.0", "description": "Example of using propagator-grpc-census-binary", "main": "index.js", "scripts": { @@ -34,13 +34,13 @@ "@opencensus/instrumentation-grpc": "0.0.21", "@opencensus/nodejs": "0.0.21", "@opencensus/propagation-binaryformat": "0.0.21", - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/plugin-grpc": "^0.18.0", - "@opentelemetry/propagator-grpc-census-binary": "^0.14.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-grpc": "^0.18.2", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/propagator-grpc-census-binary": "^0.15.0", + "@opentelemetry/tracing": "^0.18.2", "grpc": "^1.24.2", "node-pre-gyp": "0.12.0" }, diff --git a/examples/grpc-census-prop/tracer.js b/examples/grpc-census-prop/tracer.js index 143ef819cf..42b92519f4 100644 --- a/examples/grpc-census-prop/tracer.js +++ b/examples/grpc-census-prop/tracer.js @@ -5,21 +5,15 @@ const { NodeTracerProvider } = require('@opentelemetry/node'); const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/tracing'); const { HttpTraceContext } = require('@opentelemetry/core'); const { GrpcCensusPropagator } = require('@opentelemetry/propagator-grpc-census-binary'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); /** * Return an OpenTelemetry tracer configured to use the gRPC plugin and with the * requested propagator */ module.exports = (serviceName, binaryPropagator) => { - const provider = new NodeTracerProvider({ - plugins: { - grpc: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-grpc', - }, - }, - }); + const provider = new NodeTracerProvider(); // It is recommended to use this `BatchSpanProcessor` for better performance // and optimization, especially in production. @@ -36,5 +30,11 @@ module.exports = (serviceName, binaryPropagator) => { }); } + registerInstrumentations({ + instrumentations: [ + new GrpcInstrumentation(), + ], + }); + return opentelemetry.trace.getTracer(serviceName); }; diff --git a/examples/grpc_dynamic_codegen/package.json b/examples/grpc_dynamic_codegen/package.json new file mode 100644 index 0000000000..5183f709a2 --- /dev/null +++ b/examples/grpc_dynamic_codegen/package.json @@ -0,0 +1,44 @@ +{ + "name": "grpc-dynamic-codegen-example", + "version": "0.15.0", + "description": "Example of gRPC integration with OpenTelemetry", + "main": "index.js", + "scripts": { + "zipkin:server": "cross-env EXPORTER=zipkin node ./capitalize_server.js", + "zipkin:client": "cross-env EXPORTER=zipkin node ./capitalize_client.js", + "jaeger:server": "cross-env EXPORTER=jaeger node ./capitalize_server.js", + "jaeger:client": "cross-env EXPORTER=jaeger node ./capitalize_client.js" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git" + }, + "keywords": [ + "opentelemetry", + "grpc", + "tracing" + ], + "engines": { + "node": ">=8" + }, + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/open-telemetry/opentelemetry-js/issues" + }, + "dependencies": { + "@grpc/proto-loader": "^0.4.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/instrumentation-grpc": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", + "grpc": "^1.24.6", + "node-pre-gyp": "^0.17.0" + }, + "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", + "devDependencies": { + "cross-env": "^7.0.3" + } +} diff --git a/examples/grpc_dynamic_codegen/tracer.js b/examples/grpc_dynamic_codegen/tracer.js index f027899d1e..e4c843b236 100644 --- a/examples/grpc_dynamic_codegen/tracer.js +++ b/examples/grpc_dynamic_codegen/tracer.js @@ -5,19 +5,14 @@ const { NodeTracerProvider } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); + const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider({ - plugins: { - grpc: { - enabled: true, - // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-grpc', - }, - }, - }); + const provider = new NodeTracerProvider(); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { @@ -37,5 +32,11 @@ module.exports = (serviceName) => { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); + registerInstrumentations({ + instrumentations: [ + new GrpcInstrumentation(), + ], + }); + return opentelemetry.trace.getTracer('grpc-dynamic-codegen-example'); }; diff --git a/examples/hapi/package.json b/examples/hapi/package.json index 28051c36b5..242ce42c55 100644 --- a/examples/hapi/package.json +++ b/examples/hapi/package.json @@ -1,7 +1,7 @@ { "name": "hapi-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of Hapi auto-instrumentation with OpenTelemetry", "main": "index.js", "scripts": { @@ -32,14 +32,14 @@ }, "dependencies": { "@hapi/hapi": "^19.2.0", - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-hapi": "^0.14.0", - "@opentelemetry/instrumentation-http": "^0.18.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-hapi": "^0.15.0", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "axios": "^0.19.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme", diff --git a/examples/host-metrics/package.json b/examples/host-metrics/package.json index 050df920ca..9c5046d46e 100644 --- a/examples/host-metrics/package.json +++ b/examples/host-metrics/package.json @@ -1,7 +1,7 @@ { "name": "host-metrics-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of using @opentelemetry/host-metrics", "main": "index.js", "scripts": { @@ -26,13 +26,13 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/exporter-prometheus": "^0.18.0", - "@opentelemetry/host-metrics": "^0.14.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/metrics": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/exporter-prometheus": "^0.18.2", + "@opentelemetry/host-metrics": "^0.15.0", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/metrics": "^0.18.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme" } diff --git a/examples/ioredis/package.json b/examples/ioredis/package.json index ffbd772772..605e959734 100644 --- a/examples/ioredis/package.json +++ b/examples/ioredis/package.json @@ -1,7 +1,7 @@ { "name": "ioredis-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of HTTP integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,12 +28,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-ioredis": "^0.14.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-ioredis": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "ioredis": "^4.22.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme" diff --git a/examples/koa/package.json b/examples/koa/package.json index f0a24ff0af..51988bc15f 100644 --- a/examples/koa/package.json +++ b/examples/koa/package.json @@ -1,7 +1,7 @@ { "name": "koa-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of Koa and @koa/router integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -32,14 +32,14 @@ }, "dependencies": { "@koa/router": "^9.3.1", - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-http": "^0.18.0", - "@opentelemetry/instrumentation-koa": "^0.14.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/instrumentation-koa": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "axios": "^0.19.0", "koa": "^2.13.0" }, diff --git a/examples/meta-node/package.json b/examples/meta-node/package.json index 9d164e5d06..2491108717 100644 --- a/examples/meta-node/package.json +++ b/examples/meta-node/package.json @@ -1,7 +1,7 @@ { "name": "instrumentations-node-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of using meta package for default auto instrumentations in node", "main": "index.js", "scripts": { @@ -35,12 +35,12 @@ "eslint": "^7.4.0" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/auto-instrumentations-node": "^0.14.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/auto-instrumentations-node": "^0.15.0", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "axios": "^0.21.1", "express": "^4.17.1" } diff --git a/examples/meta-node/tracer.js b/examples/meta-node/tracer.js index 5bd19ee98c..311a9a4a37 100644 --- a/examples/meta-node/tracer.js +++ b/examples/meta-node/tracer.js @@ -30,26 +30,6 @@ module.exports = () => { }, }, }), - // disable old plugins - this can be removed once plugins are deprecated - // and removed from registerInstrumentations - { - plugins: { - mongodb: { enabled: false, path: '@opentelemetry/plugin-mongodb' }, - grpc: { enabled: false, path: '@opentelemetry/plugin-grpc' }, - '@grpc/grpc-js': { enabled: false, path: '@opentelemetry/plugin-grpc-js' }, - http: { enabled: false, path: '@opentelemetry/plugin-http' }, - https: { enabled: false, path: '@opentelemetry/plugin-httsps' }, - mysql: { enabled: false, path: '@opentelemetry/plugin-mysql' }, - pg: { enabled: false, path: '@opentelemetry/plugin-pg' }, - redis: { enabled: false, path: '@opentelemetry/plugin-redis' }, - ioredis: { enabled: false, path: '@opentelemetry/plugin-ioredis' }, - 'pg-pool': { enabled: false, path: '@opentelemetry/plugin-pg-pool' }, - express: { enabled: false, path: '@opentelemetry/plugin-express' }, - '@hapi/hapi': { enabled: false, path: '@opentelemetry/hapi-instrumentation' }, - koa: { enabled: false, path: '@opentelemetry/koa-instrumentation' }, - dns: { enabled: false, path: '@opentelemetry/plugin-dns' }, - }, - }, ], tracerProvider: provider, }); diff --git a/examples/mongodb/package.json b/examples/mongodb/package.json index 91d5204fa4..71746f9196 100644 --- a/examples/mongodb/package.json +++ b/examples/mongodb/package.json @@ -1,7 +1,7 @@ { "name": "mongodb-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of mongodb integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,14 +28,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-http": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", "@opentelemetry/instrumentation-mongodb": "^0.15.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "mongodb": "^3.5.7" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme", diff --git a/examples/mongodb/tracer.js b/examples/mongodb/tracer.js index 4aa932a4d1..d6be62694b 100644 --- a/examples/mongodb/tracer.js +++ b/examples/mongodb/tracer.js @@ -28,11 +28,6 @@ module.exports = (serviceName) => { new MongoDBInstrumentation({ enhancedDatabaseReporting: true, }), - { - plugins: { - mongodb: { enabled: false }, - }, - }, ], tracerProvider: provider, }); diff --git a/examples/mysql/package.json b/examples/mysql/package.json index b724eafc7f..0694e60f34 100644 --- a/examples/mysql/package.json +++ b/examples/mysql/package.json @@ -1,7 +1,7 @@ { "name": "mysql-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of mysql integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,14 +28,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/plugin-http": "^0.18.0", - "@opentelemetry/plugin-mysql": "^0.14.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/instrumentation-mysql": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "mysql": "*" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", diff --git a/examples/mysql/server.js b/examples/mysql/server.js index 748ef339d1..5d06c9ec25 100644 --- a/examples/mysql/server.js +++ b/examples/mysql/server.js @@ -2,6 +2,7 @@ // eslint-disable-next-line import/order const tracer = require('./tracer')('example-mysql-http-server'); +const api = require('@opentelemetry/api'); const mysql = require('mysql'); const http = require('http'); @@ -102,7 +103,7 @@ function handleClusterQuery(response) { const query = 'SELECT 1 + 1 as cluster_solution'; cluster.getConnection((connErr, conn) => { conn.query(query, (err, results, _fields) => { - tracer.getCurrentSpan().addEvent('results'); + api.getSpan(api.context.active()).addEvent('results'); if (err) { console.log('Error code:', err.code); response.end(err.message); diff --git a/examples/mysql/tracer.js b/examples/mysql/tracer.js index 097cd0a8fb..df04d2b03c 100644 --- a/examples/mysql/tracer.js +++ b/examples/mysql/tracer.js @@ -5,20 +5,12 @@ const { NodeTracerProvider } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); +const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql'); module.exports = (serviceName) => { - const provider = new NodeTracerProvider({ - plugins: { - mysql: { - enabled: true, - path: '@opentelemetry/plugin-mysql', - }, - http: { - enabled: true, - path: '@opentelemetry/plugin-http', - }, - }, - }); + const provider = new NodeTracerProvider(); provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({ serviceName, @@ -30,5 +22,13 @@ module.exports = (serviceName) => { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); + registerInstrumentations({ + instrumentations: [ + new HttpInstrumentation(), + new MySQLInstrumentation(), + ], + tracerProvider: provider, + }); + return opentelemetry.trace.getTracer('mysql-example'); }; diff --git a/examples/postgres/package.json b/examples/postgres/package.json index 555519ffa0..66f0e2e918 100644 --- a/examples/postgres/package.json +++ b/examples/postgres/package.json @@ -1,7 +1,7 @@ { "name": "postgres-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of Postgres integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -30,14 +30,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-http": "^0.18.0", - "@opentelemetry/instrumentation-pg": "^0.14.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/instrumentation-pg": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "express": "^4.17.1", "pg": "^7.12.1" }, diff --git a/examples/postgres/tracer.js b/examples/postgres/tracer.js index e9fc4e7c96..7850455662 100644 --- a/examples/postgres/tracer.js +++ b/examples/postgres/tracer.js @@ -14,13 +14,6 @@ const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { const provider = new NodeTracerProvider(); - registerInstrumentations({ - instrumentations: [ - new PgInstrumentation(), - new HttpInstrumentation(), - ], - }); - let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ @@ -39,5 +32,12 @@ module.exports = (serviceName) => { // Initialize the OpenTelemetry APIs to use the BasicTracer bindings provider.register(); + registerInstrumentations({ + instrumentations: [ + new PgInstrumentation(), + new HttpInstrumentation(), + ], + }); + return opentelemetry.trace.getTracer('example-postgres'); }; diff --git a/examples/react-load/preact/package.json b/examples/react-load/preact/package.json index ae7083fbe8..3c746b4c67 100644 --- a/examples/react-load/preact/package.json +++ b/examples/react-load/preact/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "react-load-preact-example", - "version": "0.9.0", + "version": "0.15.0", "description": "Example of using @opentelemetry/plugin-react-load in browser with Preact", "main": "index.js", "scripts": { @@ -37,11 +37,11 @@ "sirv-cli": "1.0.3" }, "dependencies": { - "@opentelemetry/context-zone": "^0.18.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/plugin-react-load": "^0.11.0", - "@opentelemetry/tracing": "^0.18.0", - "@opentelemetry/web": "^0.18.0", + "@opentelemetry/context-zone": "^0.18.2", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/plugin-react-load": "^0.15.0", + "@opentelemetry/tracing": "^0.18.2", + "@opentelemetry/web": "^0.18.2", "preact": "^10.3.2", "preact-render-to-string": "^5.1.4", "preact-router": "^3.2.1" diff --git a/examples/react-load/preact/src/web-tracer.js b/examples/react-load/preact/src/web-tracer.js index db3821964f..5be32f4915 100644 --- a/examples/react-load/preact/src/web-tracer.js +++ b/examples/react-load/preact/src/web-tracer.js @@ -15,7 +15,7 @@ export default (serviceName) => { provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register({ - contextManager: new ZoneContextManager(), + contextManager: new ZoneContextManager(), }); const tracer = provider.getTracer(serviceName); diff --git a/examples/react-load/react/package.json b/examples/react-load/react/package.json index c26a2bf8b6..0004a25838 100644 --- a/examples/react-load/react/package.json +++ b/examples/react-load/react/package.json @@ -1,7 +1,7 @@ { "name": "react-load-example", "private": true, - "version": "0.9.0", + "version": "0.15.0", "description": "Example of using @opentelemetry/plugin-react-load in browser with React", "main": "index.jsx", "scripts": { @@ -36,12 +36,12 @@ "ts-loader": "^6.0.4" }, "dependencies": { - "@opentelemetry/context-zone": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/plugin-react-load": "^0.11.0", - "@opentelemetry/tracing": "^0.18.0", - "@opentelemetry/web": "^0.18.0", + "@opentelemetry/context-zone": "^0.18.2", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/plugin-react-load": "^0.15.0", + "@opentelemetry/tracing": "^0.18.2", + "@opentelemetry/web": "^0.18.2", "react": "^16.13.1", "react-dom": "^16.13.1", "react-router-dom": "^5.2.0", diff --git a/examples/redis/package.json b/examples/redis/package.json index 5bdf6e7e0f..593acb4700 100644 --- a/examples/redis/package.json +++ b/examples/redis/package.json @@ -1,7 +1,7 @@ { "name": "redis-example", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of HTTP integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -30,14 +30,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/exporter-jaeger": "^0.18.0", - "@opentelemetry/exporter-zipkin": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/node": "^0.18.0", - "@opentelemetry/plugin-http": "^0.18.0", - "@opentelemetry/plugin-redis": "^0.14.0", - "@opentelemetry/tracing": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/exporter-jaeger": "^0.18.2", + "@opentelemetry/exporter-zipkin": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", + "@opentelemetry/instrumentation-redis": "^0.15.0", + "@opentelemetry/node": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", "axios": "^0.19.0", "express": "^4.17.1", "redis": "^2.8.0" diff --git a/examples/redis/tracer.js b/examples/redis/tracer.js index dc2b07e251..665da92a4e 100644 --- a/examples/redis/tracer.js +++ b/examples/redis/tracer.js @@ -5,6 +5,9 @@ const { NodeTracerProvider } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); +const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis'); const EXPORTER = process.env.EXPORTER || ''; @@ -27,5 +30,13 @@ module.exports = (serviceName) => { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); + registerInstrumentations({ + instrumentations: [ + new HttpInstrumentation(), + new RedisInstrumentation(), + ], + tracerProvider: provider, + }); + return opentelemetry.trace.getTracer('redis-example'); }; diff --git a/examples/web/package.json b/examples/web/package.json index 8299371bc7..d6c776991d 100644 --- a/examples/web/package.json +++ b/examples/web/package.json @@ -1,7 +1,7 @@ { "name": "web-examples", "private": true, - "version": "0.14.0", + "version": "0.15.0", "description": "Example of using web plugins in browser", "main": "index.js", "scripts": { @@ -34,18 +34,18 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/auto-instrumentations-web": "^0.14.0", - "@opentelemetry/context-zone": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/exporter-collector": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/instrumentation-document-load": "^0.14.0", - "@opentelemetry/instrumentation-user-interaction": "^0.14.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.18.0", - "@opentelemetry/propagator-b3": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", - "@opentelemetry/web": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/auto-instrumentations-web": "^0.15.0", + "@opentelemetry/context-zone": "^0.18.2", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/exporter-collector": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/instrumentation-document-load": "^0.15.0", + "@opentelemetry/instrumentation-user-interaction": "^0.15.0", + "@opentelemetry/instrumentation-xml-http-request": "^0.18.2", + "@opentelemetry/propagator-b3": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", + "@opentelemetry/web": "^0.18.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme" } diff --git a/karma.base.js b/karma.base.js index 088ac3f987..70435dda11 100644 --- a/karma.base.js +++ b/karma.base.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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. diff --git a/karma.webpack.js b/karma.webpack.js index 36c6884dd2..5863df2f3f 100644 --- a/karma.webpack.js +++ b/karma.webpack.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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. diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index fea57a80e3..ab4c428552 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -43,13 +43,13 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", "@opentelemetry/instrumentation-dns": "^0.15.0", "@opentelemetry/instrumentation-express": "^0.15.0", "@opentelemetry/instrumentation-graphql": "^0.15.0", - "@opentelemetry/instrumentation-grpc": "^0.18.0", - "@opentelemetry/instrumentation-http": "^0.18.0", + "@opentelemetry/instrumentation-grpc": "^0.18.2", + "@opentelemetry/instrumentation-http": "^0.18.2", "@opentelemetry/instrumentation-ioredis": "^0.15.0", "@opentelemetry/instrumentation-koa": "^0.15.0", "@opentelemetry/instrumentation-mongodb": "^0.15.0", diff --git a/metapackages/auto-instrumentations-web/package.json b/metapackages/auto-instrumentations-web/package.json index bfee9f1ff3..bae046d1d3 100644 --- a/metapackages/auto-instrumentations-web/package.json +++ b/metapackages/auto-instrumentations-web/package.json @@ -41,7 +41,7 @@ "karma-coverage-istanbul-reporter": "3.0.3", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", - "karma-webpack": "5.0.0", + "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", @@ -55,11 +55,11 @@ "webpack-merge": "5.7.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", "@opentelemetry/instrumentation-document-load": "^0.15.0", - "@opentelemetry/instrumentation-fetch": "^0.18.0", + "@opentelemetry/instrumentation-fetch": "^0.18.2", "@opentelemetry/instrumentation-user-interaction": "^0.15.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.18.0" + "@opentelemetry/instrumentation-xml-http-request": "^0.18.2" } } diff --git a/packages/opentelemetry-host-metrics/package.json b/packages/opentelemetry-host-metrics/package.json index 46b79fa6e0..e281f80a70 100644 --- a/packages/opentelemetry-host-metrics/package.json +++ b/packages/opentelemetry-host-metrics/package.json @@ -61,10 +61,10 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/api-metrics": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/metrics": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/api-metrics": "^0.18.2", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/metrics": "^0.18.2", "systeminformation": "^4.31.0" } } diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json index 10b0cab5b2..5943fd3a7a 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json @@ -63,10 +63,10 @@ "typescript": "3.9.7" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/resources": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/resources": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-dns/package.json b/plugins/node/opentelemetry-instrumentation-dns/package.json index b29a96223b..0fae06fdfd 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/package.json +++ b/plugins/node/opentelemetry-instrumentation-dns/package.json @@ -62,9 +62,9 @@ "typescript": "3.9.7" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2", "semver": "^7.3.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-express/README.md b/plugins/node/opentelemetry-instrumentation-express/README.md index a645ce4af2..6c065ddcd3 100644 --- a/plugins/node/opentelemetry-instrumentation-express/README.md +++ b/plugins/node/opentelemetry-instrumentation-express/README.md @@ -34,15 +34,16 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express'); const provider = new NodeTracerProvider(); +provider.register(); + registerInstrumentations({ - tracerProvider: provider, instrumentations: [ // Express instrumentation expects HTTP layer to be instrumented - HttpInstrumentation, - ExpressInstrumentation, + new HttpInstrumentation(), + new ExpressInstrumentation(), ], + tracerProvider: provider, }); -provider.register(); ``` See [examples/express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/express) for a short example. diff --git a/plugins/node/opentelemetry-instrumentation-express/package.json b/plugins/node/opentelemetry-instrumentation-express/package.json index 26b6a799fc..899606bf5a 100644 --- a/plugins/node/opentelemetry-instrumentation-express/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/package.json @@ -61,9 +61,9 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-graphql/README.md b/plugins/node/opentelemetry-instrumentation-graphql/README.md index 67414b3201..172fcd21df 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/README.md +++ b/plugins/node/opentelemetry-instrumentation-graphql/README.md @@ -19,20 +19,10 @@ npm install @opentelemetry/instrumentation-graphql 'use strict'; const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graphql'); - -const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { NodeTracerProvider } = require('@opentelemetry/node'); -const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const exporter = new CollectorTraceExporter({ - serviceName: 'basic-service', -}); - const provider = new NodeTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-graphql/package.json b/plugins/node/opentelemetry-instrumentation-graphql/package.json index 4f31518edf..c35c5e1291 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/package.json +++ b/plugins/node/opentelemetry-instrumentation-graphql/package.json @@ -61,7 +61,7 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-hapi/README.md b/plugins/node/opentelemetry-instrumentation-hapi/README.md index b3715ed531..98af413685 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/README.md +++ b/plugins/node/opentelemetry-instrumentation-hapi/README.md @@ -26,10 +26,11 @@ To load a specific instrumentation (Hapi in this case), specify it in the regist ```js const { NodeTracerProvider } = require('@opentelemetry/node'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); + const provider = new NodeTracerProvider(); provider.register(); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); registerInstrumentations({ tracerProvider: provider, }); @@ -53,6 +54,7 @@ You can combine loading default plugins and HapiInstrumentation at the same time const { NodeTracerProvider } = require('@opentelemetry/node'); const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); + const provider = new NodeTracerProvider(); provider.register(); diff --git a/plugins/node/opentelemetry-instrumentation-hapi/package.json b/plugins/node/opentelemetry-instrumentation-hapi/package.json index cf0bb27aba..fbc719b477 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/package.json +++ b/plugins/node/opentelemetry-instrumentation-hapi/package.json @@ -62,8 +62,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/README.md b/plugins/node/opentelemetry-instrumentation-ioredis/README.md index f3797173de..01e9f6dfb1 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/README.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/README.md @@ -30,7 +30,6 @@ const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-iored const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index 9ae33ec367..cc80567c60 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -66,8 +66,8 @@ "typescript": "3.9.7" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-koa/README.md b/plugins/node/opentelemetry-instrumentation-koa/README.md index 810947aaa7..6aade4369a 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/README.md +++ b/plugins/node/opentelemetry-instrumentation-koa/README.md @@ -22,37 +22,11 @@ npm install --save @opentelemetry/instrumentation-koa OpenTelemetry Koa Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. -To load all of the [default supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use the below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. - ```js const { NodeTracerProvider } = require('@opentelemetry/node'); -const provider = new NodeTracerProvider(); -provider.register(); - const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -If instead you would just want to load a specific instrumentation only (**koa** in this case); - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); const { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa'); -const provider = new NodeTracerProvider(); -provider.register(); - -const koaInstrumentation = new KoaInstrumentation(); -koaInstrumentation.setTracerProvider(provider); -``` -You can combine loading default plugins and KoaInstrumentation at the same time: - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); provider.register(); diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index 57ca7107d5..40f3be9e83 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -64,9 +64,9 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/README.md b/plugins/node/opentelemetry-instrumentation-mongodb/README.md index c106390496..4595786281 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/README.md +++ b/plugins/node/opentelemetry-instrumentation-mongodb/README.md @@ -25,16 +25,22 @@ OpenTelemetry Mongodb Instrumentation allows the user to automatically collect t To load a specific instrumentation (**mongodb** in this case), specify it in the Node Tracer's configuration. ```javascript -const { NodeTracerProvider } = require('@opentelemetry/node'); const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb'); +const { NodeTracerProvider } = require('@opentelemetry/node'); +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); -const mongodbInstrumentation = new MongoDBInstrumentation({ - // see under for available configuration +registerInstrumentations({ + instrumentations: [ + new MongoDBInstrumentation({ + // see under for available configuration + }), + ], + tracerProvider: provider, }); + ``` ### Mongo instrumentation Options diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index fb63702103..06243a63ca 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -62,8 +62,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/README.md b/plugins/node/opentelemetry-instrumentation-mysql/README.md index 757c322155..fe870aa6f5 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql/README.md @@ -30,7 +30,6 @@ const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql') const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index 88db3d26a2..dd62e04be0 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -60,8 +60,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-net/package.json b/plugins/node/opentelemetry-instrumentation-net/package.json index 48f3e26015..a5a14661a2 100644 --- a/plugins/node/opentelemetry-instrumentation-net/package.json +++ b/plugins/node/opentelemetry-instrumentation-net/package.json @@ -61,8 +61,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts index b97672c191..ce82738111 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts @@ -218,6 +218,7 @@ describe('NetInstrumentation', () => { it('should finish previous span when connecting twice', done => { socket.connect(PORT, () => { + socket.destroy(); socket.connect(PORT, () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 2); diff --git a/plugins/node/opentelemetry-instrumentation-pg/README.md b/plugins/node/opentelemetry-instrumentation-pg/README.md index 491b59d8e3..af0356f79e 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/README.md +++ b/plugins/node/opentelemetry-instrumentation-pg/README.md @@ -20,36 +20,9 @@ It will install Instrumentation for PG and PG-POOL ## Usage -To load all of the [default supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use the below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. - -```js -const { NodeTracerProvider } = require('@opentelemetry/node'); -const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); -provider.register(); - -registerInstrumentations({ - tracerProvider: provider, -}); -``` - -If instead you would just want to load a specific instrumentation only (**pg** in this case); - ```js -const { NodeTracerProvider } = require('@opentelemetry/node'); const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg'); - -const provider = new NodeTracerProvider(); -provider.register(); -const pgInstrumentation = new PgInstrumentation(); -pgInstrumentation.setTracerProvider(provider); -``` - -You can combine loading default plugins and PgInstrumentation at the same: - -```js const { NodeTracerProvider } = require('@opentelemetry/node'); -const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 0e8380e0a6..610e8e2ae2 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -70,7 +70,7 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-redis/README.md b/plugins/node/opentelemetry-instrumentation-redis/README.md index 06a6002665..5615173885 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/README.md +++ b/plugins/node/opentelemetry-instrumentation-redis/README.md @@ -30,18 +30,11 @@ const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis') const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ instrumentations: [ new RedisInstrumentation(), - { - // be sure to disable old plugin but only if it was installed - plugins: { - redis: { enabled: false, path: '@opentelemetry/plugin-redis' } - }, - } ], tracerProvider: provider, }) diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index dff209a82c..79df2e326a 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -64,8 +64,8 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2" } } diff --git a/plugins/web/opentelemetry-instrumentation-document-load/karma.conf.js b/plugins/web/opentelemetry-instrumentation-document-load/karma.conf.js index d4b27cc2b3..6174839d65 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/karma.conf.js +++ b/plugins/web/opentelemetry-instrumentation-document-load/karma.conf.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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. diff --git a/plugins/web/opentelemetry-instrumentation-document-load/package.json b/plugins/web/opentelemetry-instrumentation-document-load/package.json index ca5bcef7db..6d788b009d 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/package.json +++ b/plugins/web/opentelemetry-instrumentation-document-load/package.json @@ -56,7 +56,7 @@ "karma-coverage-istanbul-reporter": "3.0.3", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", - "karma-webpack": "5.0.0", + "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", @@ -72,11 +72,11 @@ "webpack-merge": "5.0.9" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", - "@opentelemetry/web": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", + "@opentelemetry/web": "^0.18.2" } } diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/karma.conf.js b/plugins/web/opentelemetry-instrumentation-user-interaction/karma.conf.js index e44536269b..4a4bd49791 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/karma.conf.js +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/karma.conf.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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. diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json index 79f2cf8f0c..946a69e035 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json @@ -62,7 +62,7 @@ "karma-jquery": "0.2.4", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", - "karma-webpack": "5.0.0", + "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", @@ -79,10 +79,10 @@ "zone.js": "0.10.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/instrumentation": "^0.18.0", - "@opentelemetry/web": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/instrumentation": "^0.18.2", + "@opentelemetry/web": "^0.18.2" }, "peerDependencies": { "zone.js": "0.10.3" diff --git a/plugins/web/opentelemetry-plugin-react-load/karma.conf.js b/plugins/web/opentelemetry-plugin-react-load/karma.conf.js index d4b27cc2b3..6174839d65 100644 --- a/plugins/web/opentelemetry-plugin-react-load/karma.conf.js +++ b/plugins/web/opentelemetry-plugin-react-load/karma.conf.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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. diff --git a/plugins/web/opentelemetry-plugin-react-load/package.json b/plugins/web/opentelemetry-plugin-react-load/package.json index ee421b9cb9..ae809b41cf 100644 --- a/plugins/web/opentelemetry-plugin-react-load/package.json +++ b/plugins/web/opentelemetry-plugin-react-load/package.json @@ -61,7 +61,7 @@ "karma-coverage-istanbul-reporter": "3.0.3", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", - "karma-webpack": "5.0.0", + "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", "react": "17.0.1", @@ -82,12 +82,12 @@ "react": "^16.13.1 || ^17.0.0" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/context-zone": "^0.18.0", - "@opentelemetry/core": "^0.18.0", - "@opentelemetry/semantic-conventions": "^0.18.0", - "@opentelemetry/tracing": "^0.18.0", - "@opentelemetry/web": "^0.18.0", + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/context-zone": "^0.18.2", + "@opentelemetry/core": "^0.18.2", + "@opentelemetry/semantic-conventions": "^0.18.2", + "@opentelemetry/tracing": "^0.18.2", + "@opentelemetry/web": "^0.18.2", "shimmer": "^1.2.1" } } diff --git a/propagators/opentelemetry-propagator-grpc-census-binary/package.json b/propagators/opentelemetry-propagator-grpc-census-binary/package.json index d615f40085..1a0d7a074c 100644 --- a/propagators/opentelemetry-propagator-grpc-census-binary/package.json +++ b/propagators/opentelemetry-propagator-grpc-census-binary/package.json @@ -58,7 +58,7 @@ "typescript": "4.1.3" }, "dependencies": { - "@opentelemetry/api": "^0.18.0", - "@opentelemetry/core": "^0.18.0" + "@opentelemetry/api": "^0.18.1", + "@opentelemetry/core": "^0.18.2" } } diff --git a/propagators/opentelemetry-propagator-ot-trace/package.json b/propagators/opentelemetry-propagator-ot-trace/package.json index 278c60351b..6e88caa3d1 100644 --- a/propagators/opentelemetry-propagator-ot-trace/package.json +++ b/propagators/opentelemetry-propagator-ot-trace/package.json @@ -43,7 +43,7 @@ "access": "public" }, "dependencies": { - "@opentelemetry/api": "^0.18.0" + "@opentelemetry/api": "^0.18.1" }, "devDependencies": { "@types/mocha": "8.2.0", @@ -57,7 +57,7 @@ "karma-coverage-istanbul-reporter": "3.0.3", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", - "karma-webpack": "5.0.0", + "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", diff --git a/scripts/version-update.js b/scripts/version-update.js index 381af0b75f..992f8f4ba1 100644 --- a/scripts/version-update.js +++ b/scripts/version-update.js @@ -1,5 +1,5 @@ /*! - * Copyright 2019, OpenTelemetry Authors + * 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.