diff --git a/.github/component_owners.yml b/.github/component_owners.yml index acc7575d3a..3974e546ee 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -14,6 +14,8 @@ components: - legendecas packages/opentelemetry-id-generator-aws-xray: - willarmiros + packages/opentelemetry-redis-common: + - haddasbronfman plugins/node/instrumentation-amqplib: - blumamir plugins/node/instrumentation-dataloader: diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e41db53c94..3ef0fb04ab 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,2 +1 @@ -{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.3","detectors/node/opentelemetry-resource-detector-aws":"1.2.1","detectors/node/opentelemetry-resource-detector-container":"0.2.1","detectors/node/opentelemetry-resource-detector-gcp":"0.27.4","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.4.0","metapackages/auto-instrumentations-node":"0.35.0","metapackages/auto-instrumentations-web":"0.31.0","packages/opentelemetry-host-metrics":"0.31.0","packages/opentelemetry-id-generator-aws-xray":"1.1.1","packages/opentelemetry-propagation-utils":"0.29.1","packages/opentelemetry-test-utils":"0.33.0","plugins/node/instrumentation-amqplib":"0.32.0","plugins/node/instrumentation-dataloader":"0.3.0","plugins/node/instrumentation-fs":"0.6.0","plugins/node/instrumentation-lru-memoizer":"0.32.0","plugins/node/instrumentation-mongoose":"0.32.0", "plugins/node/instrumentation-socket.io": "0.32.0","plugins/node/instrumentation-tedious":"0.5.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.34.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.10.0","plugins/node/opentelemetry-instrumentation-bunyan":"0.31.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.32.0","plugins/node/opentelemetry-instrumentation-connect":"0.31.0","plugins/node/opentelemetry-instrumentation-dns":"0.31.0","plugins/node/opentelemetry-instrumentation-express":"0.32.0","plugins/node/opentelemetry-instrumentation-fastify":"0.31.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.31.0","plugins/node/opentelemetry-instrumentation-graphql":"0.33.0","plugins/node/opentelemetry-instrumentation-hapi":"0.31.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.33.0","plugins/node/opentelemetry-instrumentation-knex":"0.31.0","plugins/node/opentelemetry-instrumentation-koa":"0.34.0","plugins/node/opentelemetry-instrumentation-memcached":"0.31.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.33.0","plugins/node/opentelemetry-instrumentation-mysql":"0.32.0","plugins/node/opentelemetry-instrumentation-mysql2":"0.33.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.32.0","plugins/node/opentelemetry-instrumentation-net":"0.31.0","plugins/node/opentelemetry-instrumentation-pg":"0.33.0","plugins/node/opentelemetry-instrumentation-pino":"0.33.0","plugins/node/opentelemetry-instrumentation-redis":"0.34.0","plugins/node/opentelemetry-instrumentation-redis-4":"0.34.0","plugins/node/opentelemetry-instrumentation-restify":"0.31.0","plugins/node/opentelemetry-instrumentation-router":"0.32.0","plugins/node/opentelemetry-instrumentation-winston":"0.31.0","plugins/web/opentelemetry-instrumentation-document-load":"0.31.0","plugins/web/opentelemetry-instrumentation-long-task":"0.32.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.32.0","plugins/web/opentelemetry-plugin-react-load":"0.28.1","propagators/opentelemetry-propagator-aws-xray":"1.1.1","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.1","propagators/opentelemetry-propagator-ot-trace":"0.26.2"} - +{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.3","detectors/node/opentelemetry-resource-detector-aws":"1.2.1","detectors/node/opentelemetry-resource-detector-container":"0.2.1","detectors/node/opentelemetry-resource-detector-gcp":"0.27.4","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.4.0","metapackages/auto-instrumentations-node":"0.36.0","metapackages/auto-instrumentations-web":"0.31.0","packages/opentelemetry-host-metrics":"0.31.0","packages/opentelemetry-id-generator-aws-xray":"1.1.1","packages/opentelemetry-propagation-utils":"0.29.1","packages/opentelemetry-redis-common":"0.34.0","packages/opentelemetry-test-utils":"0.33.0","plugins/node/instrumentation-amqplib":"0.32.0","plugins/node/instrumentation-dataloader":"0.3.0","plugins/node/instrumentation-fs":"0.6.0","plugins/node/instrumentation-lru-memoizer":"0.32.0","plugins/node/instrumentation-mongoose":"0.32.0","plugins/node/instrumentation-socket.io":"0.33.0","plugins/node/instrumentation-tedious":"0.5.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.34.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.10.0","plugins/node/opentelemetry-instrumentation-bunyan":"0.31.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.32.0","plugins/node/opentelemetry-instrumentation-connect":"0.31.0","plugins/node/opentelemetry-instrumentation-dns":"0.31.0","plugins/node/opentelemetry-instrumentation-express":"0.32.0","plugins/node/opentelemetry-instrumentation-fastify":"0.31.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.31.0","plugins/node/opentelemetry-instrumentation-graphql":"0.33.0","plugins/node/opentelemetry-instrumentation-hapi":"0.31.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.33.1","plugins/node/opentelemetry-instrumentation-knex":"0.31.0","plugins/node/opentelemetry-instrumentation-koa":"0.34.0","plugins/node/opentelemetry-instrumentation-memcached":"0.31.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.34.0","plugins/node/opentelemetry-instrumentation-mysql":"0.32.0","plugins/node/opentelemetry-instrumentation-mysql2":"0.33.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.32.0","plugins/node/opentelemetry-instrumentation-net":"0.31.0","plugins/node/opentelemetry-instrumentation-pg":"0.34.0","plugins/node/opentelemetry-instrumentation-pino":"0.33.0","plugins/node/opentelemetry-instrumentation-redis":"0.34.1","plugins/node/opentelemetry-instrumentation-redis-4":"0.34.1","plugins/node/opentelemetry-instrumentation-restify":"0.32.0","plugins/node/opentelemetry-instrumentation-router":"0.32.0","plugins/node/opentelemetry-instrumentation-winston":"0.31.0","plugins/web/opentelemetry-instrumentation-document-load":"0.31.0","plugins/web/opentelemetry-instrumentation-long-task":"0.32.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.32.0","plugins/web/opentelemetry-plugin-react-load":"0.28.1","propagators/opentelemetry-propagator-aws-xray":"1.1.1","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.1","propagators/opentelemetry-propagator-ot-trace":"0.26.2"} diff --git a/examples/ioredis/tracer.js b/examples/ioredis/tracer.js index dec989fec2..6d18533d9a 100644 --- a/examples/ioredis/tracer.js +++ b/examples/ioredis/tracer.js @@ -20,6 +20,7 @@ registerInstrumentations({ instrumentations: [ new IORedisInstrumentation(), ], + tracerProvider: provider, }); module.exports = opentelemetry.trace.getTracer('ioredis-example'); diff --git a/metapackages/auto-instrumentations-node/CHANGELOG.md b/metapackages/auto-instrumentations-node/CHANGELOG.md index 06f7a2d796..017d068361 100644 --- a/metapackages/auto-instrumentations-node/CHANGELOG.md +++ b/metapackages/auto-instrumentations-node/CHANGELOG.md @@ -52,6 +52,26 @@ * dependencies * @opentelemetry/instrumentation-express bumped from ^0.31.1 to ^0.31.2 +## [0.36.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-node-v0.35.0...auto-instrumentations-node-v0.36.0) (2022-12-20) + + +### Features + +* add socket.io instrumentation ([#1284](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1284)) ([f865143](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f865143d9042c41ebed6adbe906097ad7622f2c7)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-ioredis bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-mongodb bumped from ^0.33.0 to ^0.34.0 + * @opentelemetry/instrumentation-pg bumped from ^0.33.0 to ^0.34.0 + * @opentelemetry/instrumentation-redis bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-redis-4 bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-restify bumped from ^0.31.0 to ^0.32.0 + * @opentelemetry/instrumentation-socket.io bumped from ^0.32.0 to ^0.33.0 + ## [0.35.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-node-v0.34.0...auto-instrumentations-node-v0.35.0) (2022-11-16) diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index 5ad4e86a17..314f4e5a04 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/auto-instrumentations-node", - "version": "0.35.0", + "version": "0.36.0", "description": "Metapackage which bundles opentelemetry node core and contrib instrumentations", "author": "OpenTelemetry Authors", "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node#readme", @@ -63,24 +63,24 @@ "@opentelemetry/instrumentation-grpc": "^0.34.0", "@opentelemetry/instrumentation-hapi": "^0.31.0", "@opentelemetry/instrumentation-http": "^0.34.0", - "@opentelemetry/instrumentation-ioredis": "^0.33.0", + "@opentelemetry/instrumentation-ioredis": "^0.33.1", "@opentelemetry/instrumentation-knex": "^0.31.0", "@opentelemetry/instrumentation-koa": "^0.34.0", "@opentelemetry/instrumentation-lru-memoizer": "^0.32.0", "@opentelemetry/instrumentation-memcached": "^0.31.0", - "@opentelemetry/instrumentation-mongodb": "^0.33.0", + "@opentelemetry/instrumentation-mongodb": "^0.34.0", "@opentelemetry/instrumentation-mongoose": "^0.32.0", "@opentelemetry/instrumentation-mysql": "^0.32.0", "@opentelemetry/instrumentation-mysql2": "^0.33.0", "@opentelemetry/instrumentation-nestjs-core": "^0.32.0", "@opentelemetry/instrumentation-net": "^0.31.0", - "@opentelemetry/instrumentation-pg": "^0.33.0", + "@opentelemetry/instrumentation-pg": "^0.34.0", "@opentelemetry/instrumentation-pino": "^0.33.0", - "@opentelemetry/instrumentation-redis": "^0.34.0", - "@opentelemetry/instrumentation-redis-4": "^0.34.0", - "@opentelemetry/instrumentation-restify": "^0.31.0", + "@opentelemetry/instrumentation-redis": "^0.34.1", + "@opentelemetry/instrumentation-redis-4": "^0.34.1", + "@opentelemetry/instrumentation-restify": "^0.32.0", "@opentelemetry/instrumentation-router": "^0.32.0", - "@opentelemetry/instrumentation-socket.io": "^0.32.0", + "@opentelemetry/instrumentation-socket.io": "^0.33.0", "@opentelemetry/instrumentation-tedious": "^0.5.0", "@opentelemetry/instrumentation-winston": "^0.31.0" } diff --git a/packages/opentelemetry-redis-common/.eslintignore b/packages/opentelemetry-redis-common/.eslintignore new file mode 100644 index 0000000000..378eac25d3 --- /dev/null +++ b/packages/opentelemetry-redis-common/.eslintignore @@ -0,0 +1 @@ +build diff --git a/packages/opentelemetry-redis-common/.eslintrc.js b/packages/opentelemetry-redis-common/.eslintrc.js new file mode 100644 index 0000000000..f726f3becb --- /dev/null +++ b/packages/opentelemetry-redis-common/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + "env": { + "mocha": true, + "node": true + }, + ...require('../../eslint.config.js') +} diff --git a/packages/opentelemetry-redis-common/CHANGELOG.md b/packages/opentelemetry-redis-common/CHANGELOG.md new file mode 100644 index 0000000000..a098eecb92 --- /dev/null +++ b/packages/opentelemetry-redis-common/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/redis-common-v0.33.0...redis-common-v0.34.0) (2022-12-20) + + +### Features + +* upstream mocha instrumentation testing plugin from ext-js [#621](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/621) ([#669](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/669)) ([a5170c4](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/a5170c494706a2bec3ba51e59966d0ca8a41d00e)) + + +### Bug Fixes + +* **redis:** serialize non sensitive arguments into db.statement attribute ([#1299](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1299)) ([092a250](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/092a2509bcf884e1b997e0eaec3a6ca02cfd2058)) diff --git a/packages/opentelemetry-redis-common/LICENSE b/packages/opentelemetry-redis-common/LICENSE new file mode 100644 index 0000000000..e50e8c80f9 --- /dev/null +++ b/packages/opentelemetry-redis-common/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [2022] OpenTelemetry Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/opentelemetry-redis-common/README.md b/packages/opentelemetry-redis-common/README.md new file mode 100644 index 0000000000..bb8de2d704 --- /dev/null +++ b/packages/opentelemetry-redis-common/README.md @@ -0,0 +1,7 @@ +# Redis Common Utils for OpenTelemetry redis packages + +This is an internal utils package used for the different redis instrumentations: + +1. ioredis +2. redis +3. redis-4 diff --git a/packages/opentelemetry-redis-common/package.json b/packages/opentelemetry-redis-common/package.json new file mode 100644 index 0000000000..d2add794fe --- /dev/null +++ b/packages/opentelemetry-redis-common/package.json @@ -0,0 +1,50 @@ +{ + "name": "@opentelemetry/redis-common", + "version": "0.34.0", + "description": "Redis utilities for redis instrumentations", + "main": "build/src/index.js", + "types": "build/src/index.d.ts", + "publishConfig": { + "access": "public" + }, + "scripts": { + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "compile": "tsc --build tsconfig.json", + "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/redis-common --include-dependencies", + "prewatch": "npm run precompile", + "prepare": "npm run compile", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "watch": "tsc -w" + }, + "repository": "open-telemetry/opentelemetry-js-contrib", + "keywords": [ + "opentelemetry", + "redis-common" + ], + "files": [ + "build/**/*.js", + "build/**/*.js.map", + "build/**/*.d.ts", + "LICENSE", + "README.md" + ], + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + }, + "bugs": { + "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" + }, + "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/redis-common#readme", + "devDependencies": { + "@types/mocha": "^9.1.1", + "@types/node": "18.11.7", + "gts": "3.1.0", + "mocha": "7.2.0", + "nyc": "15.1.0", + "ts-mocha": "10.0.0", + "typescript": "4.3.5" + } +} diff --git a/packages/opentelemetry-redis-common/src/index.ts b/packages/opentelemetry-redis-common/src/index.ts new file mode 100644 index 0000000000..03f0d2845a --- /dev/null +++ b/packages/opentelemetry-redis-common/src/index.ts @@ -0,0 +1,76 @@ +/* + * 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. + */ + +/** + * List of regexes and the number of arguments that should be serialized for matching commands. + * For example, HSET should serialize which key and field it's operating on, but not its value. + * Setting the subset to -1 will serialize all arguments. + * Commands without a match will have their first argument serialized. + * + * Refer to https://redis.io/commands/ for the full list. + */ +const serializationSubsets = [ + { + regex: /^ECHO/i, + args: 0, + }, + { + regex: /^(LPUSH|MSET|PFA|PUBLISH|RPUSH|SADD|SET|SPUBLISH|XADD|ZADD)/i, + args: 1, + }, + { + regex: /^(HSET|HMSET|LSET|LINSERT)/i, + args: 2, + }, + { + regex: + /^(ACL|BIT|B[LRZ]|CLIENT|CLUSTER|CONFIG|COMMAND|DECR|DEL|EVAL|EX|FUNCTION|GEO|GET|HINCR|HMGET|HSCAN|INCR|L[TRLM]|MEMORY|P[EFISTU]|RPOP|S[CDIMORSU]|XACK|X[CDGILPRT]|Z[CDILMPRS])/i, + args: -1, + }, +]; + +export type DbStatementSerializer = ( + cmdName: string, + cmdArgs: Array +) => string; + +/** + * Given the redis command name and arguments, return a combination of the + * command name + the allowed arguments according to `serializationSubsets`. + * @param cmdName The redis command name + * @param cmdArgs The redis command arguments + * @returns a combination of the command name + args according to `serializationSubsets`. + */ +export const defaultDbStatementSerializer: DbStatementSerializer = ( + cmdName, + cmdArgs +) => { + if (Array.isArray(cmdArgs) && cmdArgs.length) { + const nArgsToSerialize = + serializationSubsets.find(({ regex }) => { + return regex.test(cmdName); + })?.args ?? 0; + const argsToSerialize = + nArgsToSerialize >= 0 ? cmdArgs.slice(0, nArgsToSerialize) : cmdArgs; + if (cmdArgs.length > argsToSerialize.length) { + argsToSerialize.push( + `[${cmdArgs.length - nArgsToSerialize} other arguments]` + ); + } + return `${cmdName} ${argsToSerialize.join(' ')}`; + } + return cmdName; +}; diff --git a/packages/opentelemetry-redis-common/test/redis-common.test.ts b/packages/opentelemetry-redis-common/test/redis-common.test.ts new file mode 100644 index 0000000000..874903fadd --- /dev/null +++ b/packages/opentelemetry-redis-common/test/redis-common.test.ts @@ -0,0 +1,54 @@ +/* + * 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 { defaultDbStatementSerializer } from '../src/index'; +import * as assert from 'assert'; + +describe('#defaultDbStatementSerializer()', () => { + [ + { + cmdName: 'UNKNOWN', + cmdArgs: ['something'], + expected: 'UNKNOWN [1 other arguments]', + }, + { + cmdName: 'ECHO', + cmdArgs: ['echo'], + expected: 'ECHO [1 other arguments]', + }, + { + cmdName: 'LPUSH', + cmdArgs: ['list', 'value'], + expected: 'LPUSH list [1 other arguments]', + }, + { + cmdName: 'HSET', + cmdArgs: ['hash', 'field', 'value'], + expected: 'HSET hash field [1 other arguments]', + }, + { + cmdName: 'INCRBY', + cmdArgs: ['key', 5], + expected: 'INCRBY key 5', + }, + ].forEach(({ cmdName, cmdArgs, expected }) => { + it(`should serialize the correct number of arguments for ${cmdName}`, () => { + assert.strictEqual( + defaultDbStatementSerializer(cmdName, cmdArgs), + expected + ); + }); + }); +}); diff --git a/packages/opentelemetry-redis-common/tsconfig.json b/packages/opentelemetry-redis-common/tsconfig.json new file mode 100644 index 0000000000..4078877ce6 --- /dev/null +++ b/packages/opentelemetry-redis-common/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ] +} diff --git a/plugins/node/instrumentation-socket.io/CHANGELOG.md b/plugins/node/instrumentation-socket.io/CHANGELOG.md new file mode 100644 index 0000000000..b0940745a7 --- /dev/null +++ b/plugins/node/instrumentation-socket.io/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-socket.io-v0.32.0...instrumentation-socket.io-v0.33.0) (2022-12-20) + + +### Features + +* add socket.io instrumentation ([#1284](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1284)) ([f865143](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f865143d9042c41ebed6adbe906097ad7622f2c7)) +* upstream mocha instrumentation testing plugin from ext-js [#621](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/621) ([#669](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/669)) ([a5170c4](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/a5170c494706a2bec3ba51e59966d0ca8a41d00e)) diff --git a/plugins/node/instrumentation-socket.io/package.json b/plugins/node/instrumentation-socket.io/package.json index f6b1191099..8ffc90a3bf 100644 --- a/plugins/node/instrumentation-socket.io/package.json +++ b/plugins/node/instrumentation-socket.io/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-socket.io", - "version": "0.32.0", + "version": "0.33.0", "description": "OpenTelemetry automatic instrumentation package for socket.io", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml b/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml index 4e23df61dc..d905375e40 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml @@ -1,21 +1,21 @@ "aws-sdk": # there are so many version to test, it can take forever. # we will just sample few of them - versions: ">=2.1230.0 || 2.1219.0 || 2.1152.0 || 2.1048.0 || 2.1012.0 || 2.647.0 || 2.308.0" + versions: ">=2.1266.0 || 2.1262.0 || 2.1219.0 || 2.1048.0 || 2.1012.0 || 2.647.0 || 2.308.0" commands: - npm run test # Fix missing `contrib-test-utils` package pretest: npm run --prefix ../../../ lerna:link "@aws-sdk/client-s3": - versions: ">=3.188.0 || 3.154.0 || 3.107.0 || 3.54.0 || 3.6.1" + versions: ">=3.223.0 || 3.218.0 || 3.216.0 || 3.154.0 || 3.107.0 || 3.54.0 || 3.6.1" commands: - npm run test # Fix missing `contrib-test-utils` package pretest: npm run --prefix ../../../ lerna:link "@aws-sdk/client-sqs": - versions: ">=3.188.0 || 3.171.0 || 3.107.0 || 3.58.0 || 3.54.0 || 3.43.0 || 3.24.0" + versions: ">=3.216.0 || 3.171.0 || 3.58.0 || 3.54.0 || 3.43.0 || 3.24.0" commands: - npm run test # Fix missing `contrib-test-utils` package diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md index 804ea5d3cc..d29dea2629 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.33.0...instrumentation-ioredis-v0.33.1) (2022-12-20) + + +### Bug Fixes + +* **redis:** serialize non sensitive arguments into db.statement attribute ([#1299](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1299)) ([092a250](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/092a2509bcf884e1b997e0eaec3a6ca02cfd2058)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.33.0 to ^0.34.0 + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.32.2...instrumentation-ioredis-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/README.md b/plugins/node/opentelemetry-instrumentation-ioredis/README.md index 79159202f4..a9d72ffd3d 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/README.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/README.md @@ -57,7 +57,8 @@ IORedis instrumentation has few options available to choose from. You can set th The instrumentation serializes the command into a Span attribute called `db.statement`. The standard serialization format attempts to be as informative as possible while avoiding the export of potentially sensitive data. The number of serialized arguments depends on the specific command, see the configuration -list in `src/utils.ts`. +list in `@opentelemetry/redis-common`. + 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: diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index 6fd3593ade..d05e59cbaf 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-ioredis", - "version": "0.33.0", + "version": "0.33.1", "description": "OpenTelemetry ioredis automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -71,6 +71,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/redis-common": "^0.34.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/ioredis": "4.26.6" }, diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts index ce5b9d10a8..ac2d32b8d1 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts @@ -27,7 +27,8 @@ import { SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation'; -import { endSpan, defaultDbStatementSerializer } from './utils'; +import { endSpan } from './utils'; +import { defaultDbStatementSerializer } from '@opentelemetry/redis-common'; import { VERSION } from './version'; const DEFAULT_CONFIG: IORedisInstrumentationConfig = { diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts index 55c93fee0f..6250284342 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/utils.ts @@ -15,35 +15,6 @@ */ import { Span, SpanStatusCode } from '@opentelemetry/api'; -import { DbStatementSerializer } from './types'; - -/** - * List of regexes and the number of arguments that should be serialized for matching commands. - * For example, HSET should serialize which key and field it's operating on, but not its value. - * Setting the subset to -1 will serialize all arguments. - * Commands without a match will have their first argument serialized. - * - * Refer to https://redis.io/commands/ for the full list. - */ -const serializationSubsets = [ - { - regex: /^ECHO/i, - args: 0, - }, - { - regex: /^(LPUSH|MSET|PFA|PUBLISH|RPUSH|SADD|SET|SPUBLISH|XADD|ZADD)/i, - args: 1, - }, - { - regex: /^(HSET|HMSET|LSET|LINSERT)/i, - args: 2, - }, - { - regex: - /^(ACL|BIT|B[LRZ]|CLIENT|CLUSTER|CONFIG|COMMAND|DECR|DEL|EVAL|EX|FUNCTION|GEO|GET|HINCR|HMGET|HSCAN|INCR|L[TRLM]|MEMORY|P[EFISTU]|RPOP|S[CDIMORSU]|XACK|X[CDGILPRT]|Z[CDILMPRS])/i, - args: -1, - }, -]; export const endSpan = ( span: Span, @@ -58,24 +29,3 @@ export const endSpan = ( } span.end(); }; - -export const defaultDbStatementSerializer: DbStatementSerializer = ( - cmdName, - cmdArgs -) => { - if (Array.isArray(cmdArgs) && cmdArgs.length) { - const nArgsToSerialize = - serializationSubsets.find(({ regex }) => { - return regex.test(cmdName); - })?.args ?? 0; - const argsToSerialize = - nArgsToSerialize >= 0 ? cmdArgs.slice(0, nArgsToSerialize) : cmdArgs; - if (cmdArgs.length > argsToSerialize.length) { - argsToSerialize.push( - `[${cmdArgs.length - nArgsToSerialize} other arguments]` - ); - } - return `${cmdName} ${argsToSerialize.join(' ')}`; - } - return cmdName; -}; diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts index dae05f48ba..a54ea1b812 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts @@ -43,7 +43,6 @@ import { DbSystemValues, SemanticAttributes, } from '@opentelemetry/semantic-conventions'; -import { defaultDbStatementSerializer } from '../src/utils'; const memoryExporter = new InMemorySpanExporter(); @@ -188,14 +187,14 @@ describe('ioredis', () => { description: string; name: string; args: Array; - serializedArgs: Array; + expectedDbStatement: string; method: (cb: ioredisTypes.CallbackFunction) => unknown; }> = [ { description: 'insert', name: 'hset', args: [hashKeyName, 'testField', 'testValue'], - serializedArgs: [hashKeyName, 'testField', '[1 other arguments]'], + expectedDbStatement: `${hashKeyName} testField [1 other arguments]`, method: (cb: ioredisTypes.CallbackFunction) => client.hset(hashKeyName, 'testField', 'testValue', cb), }, @@ -203,7 +202,7 @@ describe('ioredis', () => { description: 'get', name: 'get', args: [testKeyName], - serializedArgs: [testKeyName], + expectedDbStatement: `${testKeyName}`, method: (cb: ioredisTypes.CallbackFunction) => client.get(testKeyName, cb), }, @@ -245,9 +244,7 @@ describe('ioredis', () => { it(`should create a child span for cb style ${command.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: `${ - command.name - } ${command.serializedArgs.join(' ')}`, + [SemanticAttributes.DB_STATEMENT]: `${command.name} ${command.expectedDbStatement}`, }; const span = provider .getTracer('ioredis-test') @@ -1002,41 +999,4 @@ describe('ioredis', () => { }); }); }); - - describe('#defaultDbStatementSerializer()', () => { - [ - { - cmdName: 'UNKNOWN', - cmdArgs: ['something'], - expected: 'UNKNOWN [1 other arguments]', - }, - { - cmdName: 'ECHO', - cmdArgs: ['echo'], - expected: 'ECHO [1 other arguments]', - }, - { - cmdName: 'LPUSH', - cmdArgs: ['list', 'value'], - expected: 'LPUSH list [1 other arguments]', - }, - { - cmdName: 'HSET', - cmdArgs: ['hash', 'field', 'value'], - expected: 'HSET hash field [1 other arguments]', - }, - { - cmdName: 'INCRBY', - cmdArgs: ['key', 5], - expected: 'INCRBY key 5', - }, - ].forEach(({ cmdName, cmdArgs, expected }) => { - it(`should serialize the correct number of arguments for ${cmdName}`, () => { - assert.strictEqual( - defaultDbStatementSerializer(cmdName, cmdArgs), - expected - ); - }); - }); - }); }); diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md index eb2b6d7c88..0d34a21eb6 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongodb-v0.33.0...instrumentation-mongodb-v0.34.0) (2022-12-20) + + +### Features + +* **mongodb:** add db.operation span attribute ([#1321](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1321)) ([97305e1](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/97305e1880ecbfb3b87d6c38f0c6521570583510)) + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongodb-v0.32.2...instrumentation-mongodb-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/examples/README.md b/plugins/node/opentelemetry-instrumentation-mongodb/examples/README.md index d30fb9ed20..120f97fc84 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/examples/README.md +++ b/plugins/node/opentelemetry-instrumentation-mongodb/examples/README.md @@ -37,11 +37,11 @@ Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/ npm run zipkin:server ``` -- Run the zipkin:client +- Run the client ```sh # from this directory - npm run client + npm run zipkin:client ``` #### Zipkin UI diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index 14a2b29b54..b0232a3287 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-mongodb", - "version": "0.33.0", + "version": "0.34.0", "description": "OpenTelemetry mongodb automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts index f950dd49a8..8361de772c 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts @@ -210,7 +210,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { ns, server, // eslint-disable-next-line @typescript-eslint/no-explicit-any - ops[0] as any + ops[0] as any, + operationName ); const patchedCallback = instrumentation._patchEnd(span, resultHandler); // handle when options is the callback to send the correct number of args @@ -255,7 +256,9 @@ export class MongoDBInstrumentation extends InstrumentationBase { const span = instrumentation.tracer.startSpan(`mongodb.${type}`, { kind: SpanKind.CLIENT, }); - instrumentation._populateV3Attributes(span, ns, server, cmd); + const operation = + commandType === MongodbCommandType.UNKNOWN ? undefined : commandType; + instrumentation._populateV3Attributes(span, ns, server, cmd, operation); const patchedCallback = instrumentation._patchEnd(span, resultHandler); // handle when options is the callback to send the correct number of args if (typeof options === 'function') { @@ -296,7 +299,7 @@ export class MongoDBInstrumentation extends InstrumentationBase { kind: SpanKind.CLIENT, } ); - instrumentation._populateV4Attributes(span, this, ns, cmd); + instrumentation._populateV4Attributes(span, this, ns, cmd, commandType); const patchedCallback = instrumentation._patchEnd(span, resultHandler); return original.call(this, ns, cmd, options, patchedCallback); }; @@ -341,7 +344,7 @@ export class MongoDBInstrumentation extends InstrumentationBase { const span = instrumentation.tracer.startSpan('mongodb.find', { kind: SpanKind.CLIENT, }); - instrumentation._populateV3Attributes(span, ns, server, cmd); + instrumentation._populateV3Attributes(span, ns, server, cmd, 'find'); const patchedCallback = instrumentation._patchEnd(span, resultHandler); // handle when options is the callback to send the correct number of args if (typeof options === 'function') { @@ -413,7 +416,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { span, ns, server, - cursorState.cmd + cursorState.cmd, + 'getMore' ); const patchedCallback = instrumentation._patchEnd(span, resultHandler); // handle when options is the callback to send the correct number of args @@ -472,7 +476,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { span: Span, connectionCtx: any, ns: any, - command?: any + command?: any, + operation?: string ) { let host, port: undefined | string; if (connectionCtx) { @@ -501,7 +506,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { ns.collection, host, port, - commandObj + commandObj, + operation ); } @@ -516,7 +522,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { span: Span, ns: string, topology: MongoInternalTopology, - command?: MongoInternalCommand + command?: MongoInternalCommand, + operation?: string | undefined ) { // add network attributes to determine the remote server let host: undefined | string; @@ -548,7 +555,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { dbCollection, host, port, - commandObj + commandObj, + operation ); } @@ -558,13 +566,15 @@ export class MongoDBInstrumentation extends InstrumentationBase { dbCollection?: string, host?: undefined | string, port?: undefined | string, - commandObj?: any + commandObj?: any, + operation?: string | undefined ) { // add database related attributes span.setAttributes({ [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MONGODB, [SemanticAttributes.DB_NAME]: dbName, [SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection, + [SemanticAttributes.DB_OPERATION]: operation, }); if (host && port) { diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts index 3a663957f6..5a0b39e773 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts @@ -112,7 +112,12 @@ describe('MongoDBInstrumentation', () => { .insertMany(insertData) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.insert', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.insert', + SpanKind.CLIENT, + 'insert' + ); done(); }) .catch(err => { @@ -128,7 +133,12 @@ describe('MongoDBInstrumentation', () => { .updateOne({ a: 2 }, { $set: { b: 1 } }) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.update', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.update', + SpanKind.CLIENT, + 'update' + ); done(); }) .catch(err => { @@ -144,7 +154,12 @@ describe('MongoDBInstrumentation', () => { .deleteOne({ a: 3 }) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.remove', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.remove', + SpanKind.CLIENT, + 'remove' + ); done(); }) .catch(err => { @@ -164,7 +179,12 @@ describe('MongoDBInstrumentation', () => { .toArray() .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.find', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.find', + SpanKind.CLIENT, + 'find' + ); done(); }) .catch(err => { @@ -190,7 +210,8 @@ describe('MongoDBInstrumentation', () => { span => !span.name.includes('mongodb.getMore') ), 'mongodb.find', - SpanKind.CLIENT + SpanKind.CLIENT, + 'find' ); // assert that we correctly got the first as a find assertSpans( @@ -198,7 +219,8 @@ describe('MongoDBInstrumentation', () => { span => !span.name.includes('mongodb.find') ), 'mongodb.getMore', - SpanKind.CLIENT + SpanKind.CLIENT, + 'getMore' ); done(); }) @@ -222,7 +244,8 @@ describe('MongoDBInstrumentation', () => { assertSpans( getTestSpans(), 'mongodb.createIndexes', - SpanKind.CLIENT + SpanKind.CLIENT, + 'createIndexes' ); done(); }) @@ -253,7 +276,14 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const operationName = 'mongodb.insert'; - assertSpans(spans, operationName, SpanKind.CLIENT, false, false); + assertSpans( + spans, + operationName, + SpanKind.CLIENT, + 'insert', + false, + false + ); const mongoSpan = spans.find(s => s.name === operationName); const dbStatement = JSON.parse( mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string @@ -291,7 +321,14 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const operationName = 'mongodb.insert'; - assertSpans(spans, operationName, SpanKind.CLIENT, false, true); + assertSpans( + spans, + operationName, + SpanKind.CLIENT, + 'insert', + false, + true + ); const mongoSpan = spans.find(s => s.name === operationName); const dbStatement = JSON.parse( mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string @@ -324,7 +361,7 @@ describe('MongoDBInstrumentation', () => { .then(() => { span.end(); const spans = getTestSpans(); - assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert'); done(); }) .catch(err => { @@ -421,7 +458,7 @@ describe('MongoDBInstrumentation', () => { .then(() => { span.end(); const spans = getTestSpans(); - assertSpans(spans, 'mongodb.find', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.find', SpanKind.CLIENT, 'find'); done(); }) .catch(err => { @@ -443,7 +480,7 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const mainSpan = spans[spans.length - 1]; - assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert'); resetMemoryExporter(); collection @@ -453,7 +490,7 @@ describe('MongoDBInstrumentation', () => { const spans2 = getTestSpans(); spans2.push(mainSpan); - assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT); + assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT, 'find'); assert.strictEqual( mainSpan.spanContext().spanId, spans2[0].parentSpanId diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts index f42be4b03b..3101a947d2 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts @@ -111,7 +111,12 @@ describe('MongoDBInstrumentation', () => { .insertMany(insertData) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.insert', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.insert', + SpanKind.CLIENT, + 'insert' + ); done(); }) .catch(err => { @@ -127,7 +132,12 @@ describe('MongoDBInstrumentation', () => { .updateOne({ a: 2 }, { $set: { b: 1 } }) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.update', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.update', + SpanKind.CLIENT, + 'update' + ); done(); }) .catch(err => { @@ -143,7 +153,12 @@ describe('MongoDBInstrumentation', () => { .deleteOne({ a: 3 }) .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.delete', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.delete', + SpanKind.CLIENT, + 'delete' + ); done(); }) .catch(err => { @@ -163,7 +178,12 @@ describe('MongoDBInstrumentation', () => { .toArray() .then(() => { span.end(); - assertSpans(getTestSpans(), 'mongodb.find', SpanKind.CLIENT); + assertSpans( + getTestSpans(), + 'mongodb.find', + SpanKind.CLIENT, + 'find' + ); done(); }) .catch(err => { @@ -189,7 +209,8 @@ describe('MongoDBInstrumentation', () => { span => !span.name.includes('mongodb.getMore') ), 'mongodb.find', - SpanKind.CLIENT + SpanKind.CLIENT, + 'find' ); // assert that we correctly got the first as a find assertSpans( @@ -197,7 +218,8 @@ describe('MongoDBInstrumentation', () => { span => !span.name.includes('mongodb.find') ), 'mongodb.getMore', - SpanKind.CLIENT + SpanKind.CLIENT, + 'getMore' ); done(); }) @@ -221,7 +243,8 @@ describe('MongoDBInstrumentation', () => { assertSpans( getTestSpans(), 'mongodb.createIndexes', - SpanKind.CLIENT + SpanKind.CLIENT, + 'createIndexes' ); done(); }) @@ -252,7 +275,14 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const operationName = 'mongodb.insert'; - assertSpans(spans, operationName, SpanKind.CLIENT, false, false); + assertSpans( + spans, + operationName, + SpanKind.CLIENT, + 'insert', + false, + false + ); const mongoSpan = spans.find(s => s.name === operationName); const dbStatement = JSON.parse( mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string @@ -290,7 +320,14 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const operationName = 'mongodb.insert'; - assertSpans(spans, operationName, SpanKind.CLIENT, false, true); + assertSpans( + spans, + operationName, + SpanKind.CLIENT, + 'insert', + false, + true + ); const mongoSpan = spans.find(s => s.name === operationName); const dbStatement = JSON.parse( mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string @@ -323,7 +360,7 @@ describe('MongoDBInstrumentation', () => { .then(() => { span.end(); const spans = getTestSpans(); - assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert'); done(); }) .catch(err => { @@ -417,7 +454,7 @@ describe('MongoDBInstrumentation', () => { .then(() => { span.end(); const spans = getTestSpans(); - assertSpans(spans, 'mongodb.find', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.find', SpanKind.CLIENT, 'find'); done(); }) .catch(err => { @@ -439,7 +476,7 @@ describe('MongoDBInstrumentation', () => { span.end(); const spans = getTestSpans(); const mainSpan = spans[spans.length - 1]; - assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT); + assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert'); resetMemoryExporter(); collection @@ -448,7 +485,7 @@ describe('MongoDBInstrumentation', () => { .then(() => { const spans2 = getTestSpans(); spans2.push(mainSpan); - assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT); + assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT, 'find'); assert.strictEqual( mainSpan.spanContext().spanId, spans2[0].parentSpanId diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts index fde0af56d8..3da0a1833c 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts @@ -65,6 +65,7 @@ export function assertSpans( spans: ReadableSpan[], expectedName: string, expectedKind: SpanKind, + expectedOperation: string, log = false, isEnhancedDatabaseReportingEnabled = false ) { @@ -79,6 +80,10 @@ export function assertSpans( const [mongoSpan] = spans; assert.strictEqual(mongoSpan.name, expectedName); assert.strictEqual(mongoSpan.kind, expectedKind); + assert.strictEqual( + mongoSpan.attributes[SemanticAttributes.DB_OPERATION], + expectedOperation + ); assert.strictEqual( mongoSpan.attributes[SemanticAttributes.DB_SYSTEM], 'mongodb' diff --git a/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md index f317244e5d..6d765bee3e 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.33.0...instrumentation-pg-v0.34.0) (2022-12-20) + + +### Features + +* add sqlcommenter comment with trace context to queries in pg instrumentation ([#1286](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1286)) ([a0003e7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/a0003e76fc46afbbee2558a7d21906be7c9cb1d1)) +* **pg:** support requestHook hook ([#1307](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1307)) ([f0a9368](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f0a93685cfb43543b7ca577dd370d56576b49e3f)) + + +### Bug Fixes + +* pg span names ([#1306](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1306)) ([8a375f5](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/8a375f59f3043a7d3749b1e8af5603b9ed30f08f)) + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.32.0...instrumentation-pg-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-pg/README.md b/plugins/node/opentelemetry-instrumentation-pg/README.md index b14e036343..3703143057 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/README.md +++ b/plugins/node/opentelemetry-instrumentation-pg/README.md @@ -47,7 +47,8 @@ PostgreSQL instrumentation has few options available to choose from. You can set | Options | Type | Description | | ------- | ---- | ----------- | | [`enhancedDatabaseReporting`](./src/types.ts#L30) | `boolean` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations | -| `responseHook` | `PgInstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response | +| `requestHook` | `PgInstrumentationExecutionRequestHook` (function) | Function for adding custom span attributes using information about the query being issued and the db to which it's directed | +| `responseHook` | `PgInstrumentationExecutionResponseHook` (function) | Function for adding custom span attributes from db response | | `requireParentSpan` | `boolean` | If true, requires a parent span to create new spans (default false) | | `addSqlCommenterCommentToQueries` | `boolean` | If true, adds [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) specification compliant comment to queries with tracing context (default false). _NOTE: A comment will not be added to queries that already contain `--` or `/* ... */` in them, even if these are not actually part of comments_ | diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index fdf69fe8be..918375f69a 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-pg", - "version": "0.33.0", + "version": "0.34.0", "description": "OpenTelemetry postgres automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -68,6 +68,7 @@ "pg": "8.7.1", "pg-pool": "3.4.1", "rimraf": "3.0.2", + "safe-stable-stringify": "^2.4.1", "sinon": "14.0.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index f309555951..e41ce010ae 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -17,6 +17,7 @@ import { isWrapped, InstrumentationBase, InstrumentationNodeModuleDefinition, + safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { context, diag, trace, Span, SpanStatusCode } from '@opentelemetry/api'; @@ -26,7 +27,6 @@ import { PgClientConnect, PgClientExtended, PgErrorCallback, - NormalizedQueryConfig, PostgresCallback, PgPoolExtended, PgPoolCallback, @@ -137,12 +137,7 @@ export class PgInstrumentation extends InstrumentationBase { `${PgInstrumentation.COMPONENT}.connect`, { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, - [SemanticAttributes.DB_NAME]: this.database, - [SemanticAttributes.NET_PEER_NAME]: this.host, - [SemanticAttributes.DB_CONNECTION_STRING]: - utils.getConnectionString(this), - [SemanticAttributes.NET_PEER_PORT]: this.port, - [SemanticAttributes.DB_USER]: this.user, + ...utils.getSemanticAttributesFromConnection(this), } ); @@ -173,72 +168,70 @@ export class PgInstrumentation extends InstrumentationBase { `Patching ${PgInstrumentation.COMPONENT}.Client.prototype.query` ); return function query(this: PgClientExtended, ...args: unknown[]) { - let span: Span; + // client.query(text, cb?), client.query(text, values, cb?), and + // client.query(configObj, cb?) are all valid signatures. We construct + // a queryConfig obj from all (valid) signatures to build the span in a + // unified way. We verify that we at least have query text, and code + // defensively when dealing with `queryConfig` after that (to handle all + // the other invalid cases, like a non-array for values being provided). + // The type casts here reflect only what we've actually validated. + const arg0 = args[0]; + const firstArgIsString = typeof arg0 === 'string'; + const firstArgIsQueryObjectWithText = + utils.isObjectWithTextString(arg0); + + // TODO: remove the `as ...` casts below when the TS version is upgraded. + // Newer TS versions will use the result of firstArgIsQueryObjectWithText + // to properly narrow arg0, but TS 4.3.5 does not. + const queryConfig = firstArgIsString + ? { + text: arg0 as string, + values: Array.isArray(args[1]) ? args[1] : undefined, + } + : firstArgIsQueryObjectWithText + ? (arg0 as utils.ObjectWithText) + : undefined; - // Handle different client.query(...) signatures - if (typeof args[0] === 'string') { - const query = args[0]; + const instrumentationConfig = plugin.getConfig(); - if (args.length > 1 && args[1] instanceof Array) { - const params = args[1]; - span = utils.handleParameterizedQuery.call( - this, - plugin.tracer, - plugin.getConfig(), - query, - params - ); - } else { - span = utils.handleTextQuery.call( - this, - plugin.tracer, - plugin.getConfig(), - query - ); - } - - if (plugin.getConfig().addSqlCommenterCommentToQueries) { - // Modify the query with a tracing comment - args[0] = utils.addSqlCommenterComment(span, args[0]); - } - } else if (typeof args[0] === 'object') { - const queryConfig = args[0] as NormalizedQueryConfig; - - span = utils.handleConfigQuery.call( - this, - plugin.tracer, - plugin.getConfig(), - queryConfig - ); + const span = utils.handleConfigQuery.call( + this, + plugin.tracer, + instrumentationConfig, + queryConfig + ); - if (plugin.getConfig().addSqlCommenterCommentToQueries) { - // Copy the query config instead of writing to args[0].text so that we don't modify user's - // original query config reference - args[0] = { - ...queryConfig, - text: utils.addSqlCommenterComment(span, queryConfig.text), - }; - } - } else { - return utils.handleInvalidQuery.call( - this, - plugin.tracer, - plugin.getConfig(), - original, - ...args - ); + // Modify query text w/ a tracing comment before invoking original for + // tracing, but only if args[0] has one of our expected shapes. + // + // TODO: remove the `as ...` casts below when the TS version is upgraded. + // Newer TS versions will use the result of firstArgIsQueryObjectWithText + // to properly narrow arg0, but TS 4.3.5 does not. + if (instrumentationConfig.addSqlCommenterCommentToQueries) { + args[0] = firstArgIsString + ? utils.addSqlCommenterComment(span, arg0 as string) + : firstArgIsQueryObjectWithText + ? { + ...(arg0 as utils.ObjectWithText), + text: utils.addSqlCommenterComment( + span, + (arg0 as utils.ObjectWithText).text + ), + } + : args[0]; } - // Bind callback to parent span + // Bind callback (if any) to parent span (if any) if (args.length > 0) { const parentSpan = trace.getSpan(context.active()); if (typeof args[args.length - 1] === 'function') { // Patch ParameterQuery callback args[args.length - 1] = utils.patchCallback( - plugin.getConfig(), + instrumentationConfig, span, - args[args.length - 1] as PostgresCallback + args[args.length - 1] as PostgresCallback // nb: not type safe. ); + // If a parent span exists, bind the callback if (parentSpan) { args[args.length - 1] = context.bind( @@ -246,28 +239,81 @@ export class PgInstrumentation extends InstrumentationBase { args[args.length - 1] ); } - } else if ( - typeof (args[0] as NormalizedQueryConfig).callback === 'function' - ) { + } else if (typeof queryConfig?.callback === 'function') { // Patch ConfigQuery callback let callback = utils.patchCallback( plugin.getConfig(), span, - (args[0] as NormalizedQueryConfig).callback! + queryConfig.callback as PostgresCallback // nb: not type safe. ); + // If a parent span existed, bind the callback if (parentSpan) { callback = context.bind(context.active(), callback); } - // Copy the callback instead of writing to args.callback so that we don't modify user's - // original callback reference + // 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 any); + if ( + typeof instrumentationConfig.requestHook === 'function' && + queryConfig + ) { + safeExecuteInTheMiddle( + () => { + // pick keys to expose explicitly, so we're not leaking pg package + // internals that are subject to change + const { database, host, port, user } = this.connectionParameters; + const connection = { database, host, port, user }; + + instrumentationConfig.requestHook!(span, { + connection, + query: { + text: queryConfig.text, + // nb: if `client.query` is called with illegal arguments + // (e.g., if `queryConfig.values` is passed explicitly, but a + // non-array is given), then the type casts will be wrong. But + // we leave it up to the queryHook to handle that, and we + // catch and swallow any errors it throws. The other options + // are all worse. E.g., we could leave `queryConfig.values` + // and `queryConfig.name` as `unknown`, but then the hook body + // would be forced to validate (or cast) them before using + // them, which seems incredibly cumbersome given that these + // casts will be correct 99.9% of the time -- and pg.query + // will immediately throw during development in the other .1% + // of cases. Alternatively, we could simply skip calling the + // hook when `values` or `name` don't have the expected type, + // but that would add unnecessary validation overhead to every + // hook invocation and possibly be even more confusing/unexpected. + values: queryConfig.values as unknown[], + name: queryConfig.name as string | undefined, + }, + }); + }, + err => { + if (err) { + plugin._diag.error('Error running query hook', err); + } + }, + true + ); + } + + let result: unknown; + try { + result = original.apply(this, args as never); + } catch (e: unknown) { + // span.recordException(e); + span.setStatus({ + code: SpanStatusCode.ERROR, + message: utils.getErrorMessage(e), + }); + span.end(); + throw e; + } // Bind promise to parent span and end the span if (result instanceof Promise) { @@ -302,7 +348,6 @@ export class PgInstrumentation extends InstrumentationBase { const plugin = this; return (originalConnect: typeof pgPoolTypes.prototype.connect) => { return function connect(this: PgPoolExtended, callback?: PgPoolCallback) { - const connString = utils.getConnectionString(this.options); // setup span const span = startSpan( plugin.tracer, @@ -310,11 +355,7 @@ export class PgInstrumentation extends InstrumentationBase { `${PG_POOL_COMPONENT}.connect`, { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, - [SemanticAttributes.DB_NAME]: this.options.database, // required - [SemanticAttributes.NET_PEER_NAME]: this.options.host, // required - [SemanticAttributes.DB_CONNECTION_STRING]: connString, // required - [SemanticAttributes.NET_PEER_PORT]: this.options.port, - [SemanticAttributes.DB_USER]: this.options.user, + ...utils.getSemanticAttributesFromConnection(this.options), [AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options.idleTimeoutMillis, [AttributeNames.MAX_CLIENT]: this.options.maxClient, @@ -359,10 +400,10 @@ function handleConnectResult(span: Span, connectResult: unknown) { span.end(); return result; }) - .catch((error: Error) => { + .catch((error: unknown) => { span.setStatus({ code: SpanStatusCode.ERROR, - message: error.message, + message: utils.getErrorMessage(error), }); span.end(); return Promise.reject(error); diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts index dc4e54fe7a..546d84b9ee 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts @@ -19,9 +19,17 @@ import type * as pgPoolTypes from 'pg-pool'; 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 { +// NB: this type describes the shape of a parsed, normalized form of the +// connection information that's stored inside each pg.Client instance. It's +// _not_ the same as the ConnectionConfig type exported from `@types/pg`. That +// type defines how data must be _passed in_ when creating a new `pg.Client`, +// which doesn't necessarily match the normalized internal form. E.g., a user +// can call `new Client({ connectionString: '...' }), but `connectionString` +// will never show up in the type below, because only the extracted host, port, +// etc. are recorded in this normalized config. The keys listed below are also +// incomplete, which is fine because the type is internal and these keys are the +// only ones our code is reading. See https://github.com/brianc/node-postgres/blob/fde5ec586e49258dfc4a2fcd861fcdecb4794fc3/lib/client.js#L25 +export interface PgParsedConnectionParams { database?: string; host?: string; port?: number; @@ -29,13 +37,7 @@ export interface PgClientConnectionParams { } 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; + connectionParameters: PgParsedConnectionParams; } export type PgPoolCallback = ( diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/types.ts b/plugins/node/opentelemetry-instrumentation-pg/src/types.ts index 3e0d280cad..1c9a7da2c6 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/types.ts @@ -26,12 +26,39 @@ export interface PgInstrumentationExecutionResponseHook { (span: api.Span, responseInfo: PgResponseHookInformation): void; } +export interface PgRequestHookInformation { + query: { + text: string; + name?: string; + values?: unknown[]; + }; + connection: { + database?: string; + host?: string; + port?: number; + user?: string; + }; +} + +export interface PgInstrumentationExecutionRequestHook { + (span: api.Span, queryInfo: PgRequestHookInformation): void; +} + export interface PgInstrumentationConfig extends InstrumentationConfig { /** - * If true, additional information about query parameters will be attached (as `attributes`) to spans representing + * If true, an attribute containing the query's parameters will be attached + * the spans generated to represent the query. */ enhancedDatabaseReporting?: boolean; + /** + * Hook that allows adding custom span attributes or updating the + * span's name based on the data about the query to execute. + * + * @default undefined + */ + requestHook?: PgInstrumentationExecutionRequestHook; + /** * Hook that allows adding custom span attributes based on the data * returned from "query" Pg actions. diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index 048c0d7ad0..3cc25d45eb 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -35,12 +35,11 @@ import { } from '@opentelemetry/semantic-conventions'; import { PgClientExtended, - NormalizedQueryConfig, PostgresCallback, - PgClientConnectionParams, PgErrorCallback, PgPoolCallback, PgPoolExtended, + PgParsedConnectionParams, } from './internal-types'; import { PgInstrumentationConfig } from './types'; import type * as pgTypes from 'pg'; @@ -51,20 +50,72 @@ 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'; +/** + * Helper function to get a low cardinality span name from whatever info we have + * about the query. + * + * This is tricky, because we don't have most of the information (table name, + * operation name, etc) the spec recommends using to build a low-cardinality + * value w/o parsing. So, we use db.name and assume that, if the query's a named + * prepared statement, those `name` values will be low cardinality. If we don't + * have a named prepared statement, we try to parse an operation (despite the + * spec's warnings). + * + * @params dbName The name of the db against which this query is being issued, + * which could be missing if no db name was given at the time that the + * connection was established. + * @params queryConfig Information we have about the query being issued, typed + * to reflect only the validation we've actually done on the args to + * `client.query()`. This will be undefined if `client.query()` was called + * with invalid arguments. + */ +export function getQuerySpanName( + dbName: string | undefined, + queryConfig?: { text: string; name?: unknown } +) { + // NB: when the query config is invalid, we omit the dbName too, so that + // someone (or some tool) reading the span name doesn't misinterpret the + // dbName as being a prepared statement or sql commit name. + if (!queryConfig) return PgInstrumentation.BASE_SPAN_NAME; + + // Either the name of a prepared statement; or an attempted parse + // of the SQL command, normalized to uppercase; or unknown. + const command = + typeof queryConfig.name === 'string' && queryConfig.name + ? queryConfig.name + : parseNormalizedOperationName(queryConfig.text); + + return `${PgInstrumentation.BASE_SPAN_NAME}:${command}${ + dbName ? ` ${dbName}` : '' + }`; +} + +function parseNormalizedOperationName(queryText: string) { + const sqlCommand = queryText.split(' ')[0].toUpperCase(); + + // Handle query text being "COMMIT;", which has an extra semicolon before the space. + return sqlCommand.endsWith(';') ? sqlCommand.slice(0, -1) : sqlCommand; } -export function getConnectionString(params: PgClientConnectionParams) { +export function getConnectionString(params: PgParsedConnectionParams) { const host = params.host || 'localhost'; const port = params.port || 5432; const database = params.database || ''; return `postgresql://${host}:${port}/${database}`; } +export function getSemanticAttributesFromConnection( + params: PgParsedConnectionParams +) { + return { + [SemanticAttributes.DB_NAME]: params.database, // required + [SemanticAttributes.DB_CONNECTION_STRING]: getConnectionString(params), // required + [SemanticAttributes.NET_PEER_NAME]: params.host, // required + [SemanticAttributes.NET_PEER_PORT]: params.port, + [SemanticAttributes.DB_USER]: params.user, + }; +} + export function startSpan( tracer: Tracer, instrumentationConfig: PgInstrumentationConfig, @@ -85,127 +136,51 @@ export function startSpan( }); } -// Private helper function to start a span after a connection has been established -function startQuerySpan( - client: PgClientExtended, +// Create a span from our normalized queryConfig object, +// or return a basic span if no queryConfig was given/could be created. +export function handleConfigQuery( + this: PgClientExtended, tracer: Tracer, instrumentationConfig: PgInstrumentationConfig, - name: string + queryConfig?: { text: string; values?: unknown; name?: unknown } ) { - const jdbcString = getConnectionString(client.connectionParameters); - return startSpan(tracer, instrumentationConfig, name, { - [SemanticAttributes.DB_NAME]: client.connectionParameters.database, // required + // Create child span. + const { connectionParameters } = this; + const dbName = connectionParameters.database; + + const spanName = getQuerySpanName(dbName, queryConfig); + const span = startSpan(tracer, instrumentationConfig, spanName, { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, // required - [SemanticAttributes.DB_CONNECTION_STRING]: jdbcString, // required - [SemanticAttributes.NET_PEER_NAME]: client.connectionParameters.host, // required - [SemanticAttributes.NET_PEER_PORT]: client.connectionParameters.port, - [SemanticAttributes.DB_USER]: client.connectionParameters.user, + ...getSemanticAttributesFromConnection(connectionParameters), }); -} -// Queries where args[0] is a QueryConfig -export function handleConfigQuery( - this: PgClientExtended, - tracer: Tracer, - instrumentationConfig: PgInstrumentationConfig, - queryConfig: NormalizedQueryConfig -) { - // Set child span name - const queryCommand = getCommandFromText(queryConfig.name || queryConfig.text); - const name = PgInstrumentation.BASE_SPAN_NAME + ':' + queryCommand; - const span = startQuerySpan(this, tracer, instrumentationConfig, name); + if (!queryConfig) { + return span; + } // Set attributes if (queryConfig.text) { span.setAttribute(SemanticAttributes.DB_STATEMENT, queryConfig.text); } + if ( instrumentationConfig.enhancedDatabaseReporting && - queryConfig.values instanceof Array + Array.isArray(queryConfig.values) ) { span.setAttribute( AttributeNames.PG_VALUES, arrayStringifyHelper(queryConfig.values) ); } + // Set plan name attribute, if present - if (queryConfig.name) { + if (typeof queryConfig.name === 'string') { span.setAttribute(AttributeNames.PG_PLAN, queryConfig.name); } return span; } -// Queries where args[1] is a 'values' array -export function handleParameterizedQuery( - this: PgClientExtended, - tracer: Tracer, - instrumentationConfig: PgInstrumentationConfig, - query: string, - values: unknown[] -) { - // Set child span name - const queryCommand = getCommandFromText(query); - const name = PgInstrumentation.BASE_SPAN_NAME + ':' + queryCommand; - const span = startQuerySpan(this, tracer, instrumentationConfig, name); - - // Set attributes - span.setAttribute(SemanticAttributes.DB_STATEMENT, query); - if (instrumentationConfig.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, - instrumentationConfig: PgInstrumentationConfig, - query: string -) { - // Set child span name - const queryCommand = getCommandFromText(query); - const name = PgInstrumentation.BASE_SPAN_NAME + ':' + queryCommand; - const span = startQuerySpan(this, tracer, instrumentationConfig, name); - - // Set attributes - span.setAttribute(SemanticAttributes.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, - instrumentationConfig: PgInstrumentationConfig, - originalQuery: typeof pgTypes.Client.prototype.query, - ...args: unknown[] -) { - let result; - const span = startQuerySpan( - this, - tracer, - instrumentationConfig, - PgInstrumentation.BASE_SPAN_NAME - ); - try { - result = originalQuery.apply(this, args as never); - } catch (e) { - // span.recordException(e); - span.setStatus({ code: SpanStatusCode.ERROR, message: e.message }); - throw e; - } finally { - span.end(); - } - return result; -} - export function handleExecutionResult( config: PgInstrumentationConfig, span: Span, @@ -358,3 +333,26 @@ export function addSqlCommenterComment(span: Span, query: string): string { return `${query} /*${commentString}*/`; } + +/** + * Attempt to get a message string from a thrown value, while being quite + * defensive, to recognize the fact that, in JS, any kind of value (even + * primitives) can be thrown. + */ +export function getErrorMessage(e: unknown) { + return typeof e === 'object' && e !== null && 'message' in e + ? String((e as { message?: unknown }).message) + : undefined; +} + +export function isObjectWithTextString(it: unknown): it is ObjectWithText { + return ( + typeof it === 'object' && + typeof (it as null | { text?: unknown })?.text === 'string' + ); +} + +export type ObjectWithText = { + text: string; + [k: string]: unknown; +}; diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index e91b0034fb..393da4ca0e 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -33,6 +33,7 @@ import { import * as assert from 'assert'; import type * as pg from 'pg'; import * as sinon from 'sinon'; +import stringify from 'safe-stable-stringify'; import { PgInstrumentation, PgInstrumentationConfig, @@ -203,6 +204,26 @@ describe('pg', () => { runCallbackTest(null, DEFAULT_ATTRIBUTES, [], errorStatus); memoryExporter.reset(); + assert.throws( + () => { + (client as any).query(null); + }, + assertPgError, + 'pg should throw when null provided as only arg' + ); + runCallbackTest(null, DEFAULT_ATTRIBUTES, [], errorStatus); + memoryExporter.reset(); + + assert.throws( + () => { + (client as any).query(undefined); + }, + assertPgError, + 'pg should throw when undefined provided as only arg' + ); + runCallbackTest(null, DEFAULT_ATTRIBUTES, [], errorStatus); + memoryExporter.reset(); + assert.doesNotThrow( () => (client as any).query({ foo: 'bar' }, undefined, () => { @@ -493,6 +514,100 @@ describe('pg', () => { }); }); + describe('when specifying a requestHook configuration', () => { + const dataAttributeName = 'pg_data'; + const query = 'SELECT 0::text'; + const events: TimedEvent[] = []; + + // these are the attributes that we'd expect would end up on the final + // span if there is no requestHook. + const attributes = { + ...DEFAULT_ATTRIBUTES, + [SemanticAttributes.DB_STATEMENT]: query, + }; + + // These are the attributes we expect on the span after the requestHook + // has run. We set up the hook to just add to the span a stringified + // version of the args it receives (which is an easy way to assert both + // that the proper args were passed and that the hook was called). + const attributesAfterHook = { + ...attributes, + [dataAttributeName]: stringify({ + connection: { + database: CONFIG.database, + port: CONFIG.port, + host: CONFIG.host, + user: CONFIG.user, + }, + query: { text: query }, + }), + }; + + describe('AND valid requestHook', () => { + beforeEach(async () => { + create({ + enhancedDatabaseReporting: true, + requestHook: (span, requestInfo) => { + span.setAttribute(dataAttributeName, stringify(requestInfo)); + }, + }); + }); + + it('should attach request hook data to resulting spans for query with callback ', done => { + const span = tracer.startSpan('test span'); + context.with(trace.setSpan(context.active(), span), () => { + const res = client.query(query, (err, res) => { + assert.strictEqual(err, null); + assert.ok(res); + runCallbackTest(span, attributesAfterHook, events); + done(); + }); + assert.strictEqual(res, undefined, 'No promise is returned'); + }); + }); + + it('should attach request hook data to resulting spans for query returning a Promise', async () => { + const span = tracer.startSpan('test span'); + await context.with( + trace.setSpan(context.active(), span), + async () => { + const resPromise = await client.query({ text: query }); + try { + assert.ok(resPromise); + runCallbackTest(span, attributesAfterHook, events); + } catch (e) { + assert.ok(false, e.message); + } + } + ); + }); + }); + + describe('AND invalid requestHook', () => { + beforeEach(async () => { + create({ + enhancedDatabaseReporting: true, + requestHook: (_span, _requestInfo) => { + throw 'some kind of failure!'; + }, + }); + }); + + it('should not do any harm when throwing an exception', done => { + const span = tracer.startSpan('test span'); + context.with(trace.setSpan(context.active(), span), () => { + const res = client.query(query, (err, res) => { + assert.strictEqual(err, null); + assert.ok(res); + runCallbackTest(span, attributes, events); + done(); + }); + assert.strictEqual(res, undefined, 'No promise is returned'); + }); + }); + }); + }); + describe('when specifying a responseHook configuration', () => { const dataAttributeName = 'pg_data'; const query = 'SELECT 0::text'; diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts index 4b43e4da95..099ffa3bf4 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts @@ -33,7 +33,7 @@ import * as assert from 'assert'; import * as pg from 'pg'; import { PgInstrumentationConfig } from '../src'; import { AttributeNames } from '../src/enums/AttributeNames'; -import { PgClientExtended, NormalizedQueryConfig } from '../src/internal-types'; +import { PgClientExtended } from '../src/internal-types'; import * as utils from '../src/utils'; const memoryExporter = new InMemorySpanExporter(); @@ -75,6 +75,59 @@ describe('utils.ts', () => { context.disable(); }); + describe('.getQuerySpanName()', () => { + const dummyQuery = { + text: 'SELECT $1', + values: ['hello'], + name: 'select-placeholder-val', + }; + + it('uses prepared statement name when given, over query text', () => { + assert.strictEqual( + utils.getQuerySpanName('dbName', dummyQuery), + 'pg.query:select-placeholder-val dbName' + ); + }); + + it('falls back to parsing query text when no (valid) name is available', () => { + assert.strictEqual( + utils.getQuerySpanName('dbName', { ...dummyQuery, name: undefined }), + 'pg.query:SELECT dbName' + ); + }); + + it('normalizes operation names parsed from query text', () => { + const queryUpperCase = { text: dummyQuery.text.toUpperCase() }; + const queryLowerCase = { text: dummyQuery.text.toLowerCase() }; + + assert.strictEqual( + utils.getQuerySpanName('dbName', queryUpperCase), + utils.getQuerySpanName('dbName', queryLowerCase) + ); + }); + + it('ignores trailing semicolons when parsing operation names', () => { + assert.strictEqual( + utils.getQuerySpanName('dbName', { text: 'COMMIT;' }), + 'pg.query:COMMIT dbName' + ); + }); + + it('omits db name if missing', () => { + assert.strictEqual( + utils.getQuerySpanName(undefined, dummyQuery), + 'pg.query:select-placeholder-val' + ); + }); + + it('should omit all info if the queryConfig is invalid', () => { + assert.strictEqual( + utils.getQuerySpanName('db-name-ignored', undefined), + 'pg.query' + ); + }); + }); + describe('.startSpan()', () => { it('starts real span when requireParentSpan=false', async () => { const span = utils.startSpan(tracer, instrumentationConfig, 'spanName', { @@ -131,7 +184,7 @@ describe('utils.ts', () => { }); describe('.handleConfigQuery()', () => { - const queryConfig: NormalizedQueryConfig = { + const queryConfig = { text: 'SELECT $1::text', values: ['0'], }; @@ -171,47 +224,6 @@ describe('utils.ts', () => { }); }); - 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, - instrumentationConfig, - 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: PgInstrumentationConfig & InstrumentationConfig = { - ...instrumentationConfig, - 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]'); - }); - }); - describe('addSqlCommenterComment', () => { it('adds comment to a simple query', () => { const spanContext: SpanContext = { diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md index f9386e6b6f..49f7ca6e89 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-4-v0.34.0...instrumentation-redis-4-v0.34.1) (2022-12-20) + + +### Bug Fixes + +* **redis-4:** add support to new version of redis ([#1324](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1324)) ([378f130](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/378f130befb2bd8be42d367b9db5ae9329d57b5e)) +* **redis:** serialize non sensitive arguments into db.statement attribute ([#1299](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1299)) ([092a250](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/092a2509bcf884e1b997e0eaec3a6ca02cfd2058)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.33.0 to ^0.34.0 + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-4-v0.33.1...instrumentation-redis-4-v0.34.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/README.md b/plugins/node/opentelemetry-instrumentation-redis-4/README.md index 7d4870a511..dec67f105d 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/README.md +++ b/plugins/node/opentelemetry-instrumentation-redis-4/README.md @@ -53,14 +53,14 @@ Redis instrumentation has a few options available to choose from. You can set th #### Custom `db.statement` Serializer -The instrumentation serializes the command into a Span attribute called -`db.statement`. The default serialization sets the attribute to the command -name, without the command arguments. +The instrumentation serializes the command into a Span attribute called `db.statement`. The standard serialization format attempts to be as informative as possible while avoiding the export of potentially sensitive data. The number of serialized arguments depends on the specific command, see the configuration +list in `@opentelemetry/redis-common`. 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 and arguments: +Here is a simple example to serialize the command name and all command arguments. +Notice that it might capture sensitive data and big payloads: ```javascript const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis'); diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/package.json b/plugins/node/opentelemetry-instrumentation-redis-4/package.json index 08b95f8103..f2eb5ec0a7 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis-4/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-redis-4", - "version": "0.34.0", + "version": "0.34.1", "description": "Automatic OpenTelemetry instrumentation for redis package version 4", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -71,6 +71,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/redis-common": "^0.34.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis-4#readme" diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts index b73d86c5f4..4bf503e6c4 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts @@ -28,7 +28,8 @@ import { InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile, } from '@opentelemetry/instrumentation'; -import { defaultDbStatementSerializer, getClientAttributes } from './utils'; +import { getClientAttributes } from './utils'; +import { defaultDbStatementSerializer } from '@opentelemetry/redis-common'; import { RedisInstrumentationConfig } from './types'; import { VERSION } from './version'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; @@ -174,6 +175,15 @@ export class RedisInstrumentation extends InstrumentationBase { this._getPatchRedisClientMulti() ); + if (isWrapped(redisClientPrototype?.MULTI)) { + this._unwrap(redisClientPrototype, 'MULTI'); + } + this._wrap( + redisClientPrototype, + 'MULTI', + this._getPatchRedisClientMulti() + ); + if (isWrapped(redisClientPrototype?.sendCommand)) { this._unwrap(redisClientPrototype, 'sendCommand'); } @@ -197,6 +207,9 @@ export class RedisInstrumentation extends InstrumentationBase { if (isWrapped(redisClientPrototype?.multi)) { this._unwrap(redisClientPrototype, 'multi'); } + if (isWrapped(redisClientPrototype?.MULTI)) { + this._unwrap(redisClientPrototype, 'MULTI'); + } if (isWrapped(redisClientPrototype?.sendCommand)) { this._unwrap(redisClientPrototype, 'sendCommand'); } diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts index 168bb2f36c..f102606474 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts @@ -13,15 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { DbStatementSerializer } from './types'; import { DbSystemValues, SemanticAttributes, } from '@opentelemetry/semantic-conventions'; -export const defaultDbStatementSerializer: DbStatementSerializer = cmdName => - cmdName; - export function getClientAttributes(options: any) { return { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.REDIS, diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts b/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts index ffbec97a85..615572cf5a 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts @@ -99,7 +99,7 @@ describe('redis@^4.0.0', () => { ); assert.strictEqual( setSpan?.attributes[SemanticAttributes.DB_STATEMENT], - 'SET' + 'SET key [1 other arguments]' ); assert.strictEqual( setSpan?.attributes[SemanticAttributes.NET_PEER_NAME], @@ -124,7 +124,7 @@ describe('redis@^4.0.0', () => { ); assert.strictEqual( getSpan?.attributes[SemanticAttributes.DB_STATEMENT], - 'GET' + 'GET key' ); assert.strictEqual( getSpan?.attributes[SemanticAttributes.NET_PEER_NAME], @@ -149,7 +149,7 @@ describe('redis@^4.0.0', () => { assert.ok(setSpan); assert.strictEqual( setSpan?.attributes[SemanticAttributes.DB_STATEMENT], - 'SET' + 'SET key [1 other arguments]' ); assert.strictEqual( setSpan?.attributes[SemanticAttributes.NET_PEER_NAME], @@ -253,7 +253,7 @@ describe('redis@^4.0.0', () => { assert.strictEqual(multiSetSpan.name, 'redis-SET'); assert.strictEqual( multiSetSpan.attributes[SemanticAttributes.DB_STATEMENT], - 'SET' + 'SET key [1 other arguments]' ); assert.strictEqual( multiSetSpan?.attributes[SemanticAttributes.NET_PEER_NAME], @@ -272,7 +272,7 @@ describe('redis@^4.0.0', () => { assert.strictEqual(multiGetSpan.name, 'redis-GET'); assert.strictEqual( multiGetSpan.attributes[SemanticAttributes.DB_STATEMENT], - 'GET' + 'GET another-key' ); assert.strictEqual( multiGetSpan?.attributes[SemanticAttributes.NET_PEER_NAME], @@ -299,7 +299,7 @@ describe('redis@^4.0.0', () => { assert.ok(multiSetSpan); assert.strictEqual( multiSetSpan.attributes[SemanticAttributes.DB_STATEMENT], - 'SET' + 'SET key [1 other arguments]' ); assert.strictEqual( multiSetSpan?.attributes[SemanticAttributes.NET_PEER_NAME], diff --git a/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md index 481940fac9..6a4304734b 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.34.0...instrumentation-redis-v0.34.1) (2022-12-20) + + +### Bug Fixes + +* **redis:** serialize non sensitive arguments into db.statement attribute ([#1299](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1299)) ([092a250](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/092a2509bcf884e1b997e0eaec3a6ca02cfd2058)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.33.0 to ^0.34.0 + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.33.1...instrumentation-redis-v0.34.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-redis/README.md b/plugins/node/opentelemetry-instrumentation-redis/README.md index 4386a95da7..cf8aae670f 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/README.md +++ b/plugins/node/opentelemetry-instrumentation-redis/README.md @@ -55,14 +55,14 @@ Redis instrumentation has a few options available to choose from. You can set th #### Custom `db.statement` Serializer -The instrumentation serializes the command into a Span attribute called -`db.statement`. The default serialization sets the attribute to the command -name, without the command arguments. +The instrumentation serializes the command into a Span attribute called `db.statement`. The standard serialization format attempts to be as informative as possible while avoiding the export of potentially sensitive data. The number of serialized arguments depends on the specific command, see the configuration +list in `@opentelemetry/redis-common`. 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 and arguments: +Here is a simple example to serialize the command name and all command arguments. +Notice that it might capture sensitive data and big payloads: ```javascript const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis'); diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index 0d34a57604..339bce4872 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-redis", - "version": "0.34.0", + "version": "0.34.1", "description": "Automatic OpenTelemetry instrumentation for redis package version 2 and 3", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -71,6 +71,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/redis-common": "^0.34.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/redis": "2.8.31" }, diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts index 29b2e34f95..988c5c1a0f 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts @@ -24,11 +24,7 @@ import { trace, diag, } from '@opentelemetry/api'; -import { - DbStatementSerializer, - RedisCommand, - RedisInstrumentationConfig, -} from './types'; +import { RedisCommand, RedisInstrumentationConfig } from './types'; import { EventEmitter } from 'events'; import { RedisInstrumentation } from './'; import { @@ -37,6 +33,7 @@ import { } from '@opentelemetry/semantic-conventions'; import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation'; import { RedisPluginClientTypes } from './internal-types'; +import { defaultDbStatementSerializer } from '@opentelemetry/redis-common'; const endSpan = (span: Span, err?: Error | null) => { if (err) { @@ -75,8 +72,6 @@ export const getTracedCreateStreamTrace = ( }; }; -const defaultDbStatementSerializer: DbStatementSerializer = cmdName => cmdName; - export const getTracedInternalSendCommand = ( tracer: Tracer, original: Function, diff --git a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts index 09842809fc..01d449a57e 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts @@ -133,12 +133,14 @@ describe('redis@2.x', () => { description: string; command: string; args: string[]; + expectedDbStatement: string; method: (cb: redisTypes.Callback) => unknown; }> = [ { description: 'insert', command: 'hset', args: ['hash', 'random', 'random'], + expectedDbStatement: 'hash random [1 other arguments]', method: (cb: redisTypes.Callback) => client.hset('hash', 'random', 'random', cb), }, @@ -146,6 +148,7 @@ describe('redis@2.x', () => { description: 'get', command: 'get', args: ['test'], + expectedDbStatement: 'test', method: (cb: redisTypes.Callback) => client.get('test', cb), }, @@ -153,6 +156,7 @@ describe('redis@2.x', () => { description: 'delete', command: 'del', args: ['test'], + expectedDbStatement: 'test', method: (cb: redisTypes.Callback) => client.del('test', cb), }, ]; @@ -188,7 +192,7 @@ describe('redis@2.x', () => { it(`should create a child span for ${operation.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [SemanticAttributes.DB_STATEMENT]: operation.command, + [SemanticAttributes.DB_STATEMENT]: `${operation.command} ${operation.expectedDbStatement}`, }; const span = tracer.startSpan('test span'); context.with(trace.setSpan(context.active(), span), () => { diff --git a/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md index 0f61989954..5bc2799d58 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-restify-v0.31.0...instrumentation-restify-v0.32.0) (2022-12-20) + + +### Features + +* **restify:** add requestHook support ([#1312](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1312)) ([4098e6a](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/4098e6a3d4257e5da9b8cece430bde7d70319cf3)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-restify-v0.30.1...instrumentation-restify-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-restify/README.md b/plugins/node/opentelemetry-instrumentation-restify/README.md index 9ef35ea4da..719a042ab7 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/README.md +++ b/plugins/node/opentelemetry-instrumentation-restify/README.md @@ -41,6 +41,27 @@ registerInstrumentations({ See [examples/restify](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/restify) for a short example. +## Restify Instrumentation Options + +| Options | Type | Example | Description | +| `requestHook` | `RestifyCustomAttributeFunction` | `(span, requestInfo) => {}` | Function for adding custom attributes to restify requests. Receives params: `Span, RestifyRequestInfo`. | + +### Using `requestHook` + +Instrumentation configuration accepts a custom "hook" function which will be called for every instrumented restify request. Custom attributes can be set on the span or run any custom logic per request. + +```javascript +import { RestifyInstrumentation } from "@opentelemetry/instrumentation-restify" +const restifyInstrumentation = new RestifyInstrumentation({ + requestHook: function (span: Span, info: RestifyRequestInfo) { + span.setAttribute( + 'http.method', + info.request.method, + ) + } +}); +``` + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/opentelemetry-instrumentation-restify/package.json b/plugins/node/opentelemetry-instrumentation-restify/package.json index 6dc057e31d..4b5f05904b 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/package.json +++ b/plugins/node/opentelemetry-instrumentation-restify/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-restify", - "version": "0.31.0", + "version": "0.32.0", "description": "OpenTelemetry restify automatic instrumentation package", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/index.ts b/plugins/node/opentelemetry-instrumentation-restify/src/index.ts index dae24360d1..331bf99930 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/index.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/index.ts @@ -20,3 +20,4 @@ export * from './instrumentation'; export default RestifyInstrumentation; export * from './enums/AttributeNames'; +export * from './types'; diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts index 76fb7b95f9..a856359d96 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts @@ -19,31 +19,44 @@ import type * as restify from 'restify'; import * as api from '@opentelemetry/api'; import type { Server } from 'restify'; -import { LayerType } from './internal-types'; +import { LayerType } from './types'; import * as AttributeNames from './enums/AttributeNames'; import { VERSION } from './version'; import * as constants from './constants'; import { InstrumentationBase, - InstrumentationConfig, InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile, isWrapped, + safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { isPromise, isAsyncFunction } from './utils'; import { getRPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core'; +import type { RestifyInstrumentationConfig } from './types'; const { diag } = api; export class RestifyInstrumentation extends InstrumentationBase { - constructor(config: InstrumentationConfig = {}) { - super(`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, VERSION); + constructor(config: RestifyInstrumentationConfig = {}) { + super( + `@opentelemetry/instrumentation-${constants.MODULE_NAME}`, + VERSION, + Object.assign({}, config) + ); } private _moduleVersion?: string; private _isDisabled = false; + override setConfig(config: RestifyInstrumentationConfig = {}) { + this._config = Object.assign({}, config); + } + + override getConfig(): RestifyInstrumentationConfig { + return this._config as RestifyInstrumentationConfig; + } + init() { const module = new InstrumentationNodeModuleDefinition( constants.MODULE_NAME, @@ -185,6 +198,26 @@ export class RestifyInstrumentation extends InstrumentationBase { }, api.context.active() ); + + const instrumentation = this; + const requestHook = instrumentation.getConfig().requestHook; + if (requestHook) { + safeExecuteInTheMiddle( + () => { + return requestHook!(span, { + request: req, + layerType: metadata.type, + }); + }, + e => { + if (e) { + instrumentation._diag.error('request hook failed', e); + } + }, + true + ); + } + const patchedNext = (err?: any) => { span.end(); next(err); diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-restify/src/internal-types.ts index d6280a6bda..deb0ea3e98 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/internal-types.ts @@ -15,11 +15,7 @@ */ import { Span } from '@opentelemetry/api'; import type * as restify from 'restify'; - -export enum LayerType { - MIDDLEWARE = 'middleware', - REQUEST_HANDLER = 'request_handler', -} +import { LayerType } from './types'; declare interface RequestWithRoute extends restify.Request { route: { path: string }; diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/types.ts b/plugins/node/opentelemetry-instrumentation-restify/src/types.ts new file mode 100644 index 0000000000..238f247a81 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-restify/src/types.ts @@ -0,0 +1,45 @@ +/* + * 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 { InstrumentationConfig } from '@opentelemetry/instrumentation'; + +export enum LayerType { + MIDDLEWARE = 'middleware', + REQUEST_HANDLER = 'request_handler', +} + +export interface RestifyRequestInfo { + request: any; // Request type from @types/restify package + layerType: LayerType; +} + +/** + * Function that can be used to add custom attributes to the current span + * @param span - The restify handler span. + * @param info - The restify request info object. + */ +export interface RestifyCustomAttributeFunction { + (span: Span, info: RestifyRequestInfo): void; +} + +/** + * Options available for the restify Instrumentation + */ +export interface RestifyInstrumentationConfig extends InstrumentationConfig { + /** Function for adding custom attributes to each handler span */ + requestHook?: RestifyCustomAttributeFunction; +} diff --git a/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts b/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts index 33ce317188..0e381bf969 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { context, trace } from '@opentelemetry/api'; +import { context, trace, Span } from '@opentelemetry/api'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { RPCType, setRPCMetadata } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; @@ -25,6 +26,7 @@ import { import RestifyInstrumentation from '../src'; import * as types from '../src/internal-types'; +import { RestifyRequestInfo } from '../src/types'; const plugin = new RestifyInstrumentation(); import * as semver from 'semver'; @@ -487,6 +489,85 @@ describe('Restify Instrumentation', () => { assert.strictEqual(memoryExporter.getFinishedSpans().length, 3); assert.strictEqual(res, '{"route":"bar"}'); }); + + describe('using requestHook in config', () => { + it('calls requestHook provided function when set in config', async () => { + const requestHook = (span: Span, info: RestifyRequestInfo) => { + span.setAttribute( + SemanticAttributes.HTTP_METHOD, + info.request.method + ); + span.setAttribute('restify.layer', info.layerType); + }; + + plugin.setConfig({ + ...plugin.getConfig(), + requestHook, + }); + + const rootSpan = tracer.startSpan('clientSpan'); + + await context.with( + trace.setSpan(context.active(), rootSpan), + async () => { + await httpRequest.get(`http://localhost:${port}/route/foo`); + rootSpan.end(); + assert.strictEqual(memoryExporter.getFinishedSpans().length, 4); + + { + // span from get + const span = memoryExporter.getFinishedSpans()[2]; + assert.notStrictEqual(span, undefined); + assert.strictEqual( + span.attributes[SemanticAttributes.HTTP_METHOD], + 'GET' + ); + assert.strictEqual( + span.attributes['restify.layer'], + 'request_handler' + ); + } + } + ); + }); + + it('does not propagate an error from a requestHook that throws exception', async () => { + const requestHook = (span: Span, info: RestifyRequestInfo) => { + span.setAttribute( + SemanticAttributes.HTTP_METHOD, + info.request.method + ); + + throw Error('error thrown in requestHook'); + }; + + plugin.setConfig({ + ...plugin.getConfig(), + requestHook, + }); + + const rootSpan = tracer.startSpan('clientSpan'); + + await context.with( + trace.setSpan(context.active(), rootSpan), + async () => { + await httpRequest.get(`http://localhost:${port}/route/foo`); + rootSpan.end(); + assert.strictEqual(memoryExporter.getFinishedSpans().length, 4); + + { + // span from get + const span = memoryExporter.getFinishedSpans()[2]; + assert.notStrictEqual(span, undefined); + assert.strictEqual( + span.attributes[SemanticAttributes.HTTP_METHOD], + 'GET' + ); + } + } + ); + }); + }); }); describe('Disabling restify instrumentation', () => { diff --git a/release-please-config.json b/release-please-config.json index 6894b5d84d..424fe6824a 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -17,6 +17,7 @@ "packages/opentelemetry-host-metrics": {}, "packages/opentelemetry-id-generator-aws-xray": {}, "packages/opentelemetry-propagation-utils": {}, + "packages/opentelemetry-redis-common": {}, "packages/opentelemetry-test-utils": {}, "plugins/node/instrumentation-amqplib": {}, "plugins/node/instrumentation-dataloader": {},