diff --git a/metapackages/esbuild-plugin-node/.eslintignore b/metapackages/esbuild-plugin-node/.eslintignore new file mode 100644 index 0000000000..03db8f9b34 --- /dev/null +++ b/metapackages/esbuild-plugin-node/.eslintignore @@ -0,0 +1,2 @@ +build +.eslintrc.js diff --git a/metapackages/esbuild-plugin-node/.eslintrc.js b/metapackages/esbuild-plugin-node/.eslintrc.js new file mode 100644 index 0000000000..fe91e21049 --- /dev/null +++ b/metapackages/esbuild-plugin-node/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + "env": { + "commonjs": true, + "node": true, + "mocha": true, + }, + ...require('../../eslint.config.js') +} diff --git a/metapackages/esbuild-plugin-node/.gitignore b/metapackages/esbuild-plugin-node/.gitignore new file mode 100644 index 0000000000..d5677e91f5 --- /dev/null +++ b/metapackages/esbuild-plugin-node/.gitignore @@ -0,0 +1 @@ +test-dist/ diff --git a/metapackages/esbuild-plugin-node/LICENSE b/metapackages/esbuild-plugin-node/LICENSE new file mode 100644 index 0000000000..e50e8c80f9 --- /dev/null +++ b/metapackages/esbuild-plugin-node/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/metapackages/esbuild-plugin-node/README.md b/metapackages/esbuild-plugin-node/README.md new file mode 100644 index 0000000000..73ce67daea --- /dev/null +++ b/metapackages/esbuild-plugin-node/README.md @@ -0,0 +1,204 @@ +# OpenTelemetry Esbuild for Node + +[![NPM Published Version][npm-img]][npm-url] +[![Apache License][license-image]][license-url] + +## About + +This module provides a way to auto instrument any Node application to capture telemetry from a number of popular libraries and frameworks, via an [esbuild](https://esbuild.github.io/) plugin. +You can export the telemetry data in a variety of formats. Exporters, samplers, and more can be configured via [environment variables][env-var-url]. +The net result is the ability to gather telemetry data from a Node application without any code changes. + +This module also provides a simple way to manually initialize multiple Node instrumentations for use with the OpenTelemetry SDK. + +Compatible with OpenTelemetry JS API and SDK `1.0+`. + +## Installation + +```bash +npm install --save @opentelemetry/esbuild-plugin-node +``` + +## Usage: Esbuild plugin + +This module includes auto instrumentation for all supported instrumentations and [all available data exporters][exporter-url]. +It provides a completely automatic, out-of-the-box experience. +Please see the [Supported Instrumentations](#supported-instrumentations) section for more information. + +Enable auto instrumentation by configuring it in your esbuild script: + +```javascript +const { openTelemetryPlugin } = require('@opentelemetry/esbuild-plugin-node'); +const { build } = require('esbuild'); + +build({ + entryPoints: ['src/server.ts'], + bundle: true, + outfile: 'dist/server.js', + target: 'node20', + platform: 'node', + sourcemap: true, + plugins: [openTelemetryPlugin()], +}).catch(err => { + throw err; +}); +``` + +## Usage: Instrumentation Initialization + +OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages. + +Enable auto instrumentation by configuring it in your esbuild script: + +```javascript +const { openTelemetryPlugin } = require('@opentelemetry/esbuild-plugin-node'); +const { build } = require('esbuild'); + +build({ + entryPoints: ['src/server.ts'], + bundle: true, + outfile: 'dist/server.js', + target: 'node20', + platform: 'node', + sourcemap: true, + plugins: [openTelemetryPlugin()], +}).catch(err => { + throw err; +}); +``` + +Custom configuration for each of the instrumentations can be passed to the plugin, by providing an object with the name of the instrumentation as a key, and its configuration as the value. + +```javascript +const { openTelemetryPlugin } = require('@opentelemetry/esbuild-plugin-node'); +const { build } = require('esbuild'); + +build({ + entryPoints: ['src/server.ts'], + bundle: true, + outfile: 'dist/server.js', + target: 'node20', + platform: 'node', + sourcemap: true, + plugins: [ + openTelemetryPlugin({ + '@opentelemetry/instrumentation-pino': { + logHook: (span, record) => { + // Reformat the injected log fields to use camelCase, eg. trace_id -> traceId + const context = span.spanContext(); + record.traceId = context.traceId; + record.spanId = context.spanId; + record.strTraceFlags = context.traceFlags; + + if (record.trace_id === context.traceId) delete record.trace_id; + if (record.span_id === context.spanId) delete record.span_id; + if (Number(record.trace_flags) === context.traceFlags) + delete record.trace_flags; + }, + }, + }), + ], +}).catch(err => { + throw err; +}); +``` + +This esbuild script will instrument non-builtin packages but will not configure the rest of the OpenTelemetry SDK to export traces +from your application. To do that you must also configure the SDK. + +The esbuild script currently only patches non-builtin modules (more specifically, modules in [opentelemetry-js-contrib](https://github.com/open-telemetry/opentelemetry-js-contrib)), so this is also the place to configure the instrumentation +for builtins or add any additional instrumentations. + +### Gotchas + +There are limitations to the configuration options for each package. Most notably, any functions (like `ignoreIncomingRequestHook` in the example) must not depend on any scope outside the function itself, including but not limited to module level variables and imports. + +The reason for this is that the current mechanism of instrumenting packages involves stringifying the instrumentation configs, which does not account for any external scoped dependencies. + +```javascript +const { + getNodeAutoInstrumentations, +} = require('@opentelemetry/auto-instrumentations-node'); +const { + AsyncHooksContextManager, +} = require('@opentelemetry/context-async-hooks'); +const { + OTLPTraceExporter, +} = require('@opentelemetry/exporter-trace-otlp-http'); +const { NodeSDK } = require('@opentelemetry/sdk-node'); + +const instrumentations = getNodeAutoInstrumentations({ + '@opentelemetry/instrumentation-http': { + ignoreIncomingRequestHook: request => { + // GET /metrics is for fetching prometheus metrics, + // which generates a ton of noise and is not very interesting + return request.method === 'GET' && request.url === '/metrics'; + }, + }, +}); + +const sdk = new NodeSDK({ + traceExporter: new OTLPTraceExporter(), + contextManager: new AsyncHooksContextManager().enable(), + instrumentations, +}); + +sdk.start(); + +process.on('SIGTERM', () => { + sdk.shutdown().finally(() => process.exit(0)); +}); +``` + +## Supported instrumentations + +- [@opentelemetry/instrumentation-amqplib](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-amqplib) +- [@opentelemetry/instrumentation-aws-lambda](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-aws-lambda) +- [@opentelemetry/instrumentation-aws-sdk](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-aws-sdk) +- [@opentelemetry/instrumentation-bunyan](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-bunyan) +- [@opentelemetry/instrumentation-cassandra-driver](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-cassandra) +- [@opentelemetry/instrumentation-connect](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-connect) +- [@opentelemetry/instrumentation-cucumber](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-cucumber) +- [@opentelemetry/instrumentation-dataloader](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-dataloader) +- [@opentelemetry/instrumentation-dns](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns) +- [@opentelemetry/instrumentation-express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express) +- [@opentelemetry/instrumentation-fastify](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify) +- [@opentelemetry/instrumentation-generic-pool](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-generic-pool) +- [@opentelemetry/instrumentation-graphql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql) +- [@opentelemetry/instrumentation-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-grpc) +- [@opentelemetry/instrumentation-hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi) +- [@opentelemetry/instrumentation-http](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http) +- [@opentelemetry/instrumentation-ioredis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis) +- [@opentelemetry/instrumentation-knex](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex) +- [@opentelemetry/instrumentation-koa](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa) +- [@opentelemetry/instrumentation-lru-memoizer](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer) +- [@opentelemetry/instrumentation-memcached](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-memcached) +- [@opentelemetry/instrumentation-mongodb](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb) +- [@opentelemetry/instrumentation-mongoose](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose) +- [@opentelemetry/instrumentation-mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql) +- [@opentelemetry/instrumentation-mysql2](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2) +- [@opentelemetry/instrumentation-nestjs-core](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core) +- [@opentelemetry/instrumentation-net](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-net) +- [@opentelemetry/instrumentation-pg](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg) +- [@opentelemetry/instrumentation-pino](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pino) +- [@opentelemetry/instrumentation-redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis) +- [@opentelemetry/instrumentation-restify](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-restify) +- [@opentelemetry/instrumentation-socket.io](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-socket.io) +- [@opentelemetry/instrumentation-winston](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston) + +## Useful links + +- For more information on OpenTelemetry, visit: +- For more about OpenTelemetry JavaScript: + +## License + +APACHE 2.0 - See [LICENSE][license-url] for more information. + +[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE +[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat +[npm-url]: https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node +[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fauto-instrumentations-node.svg +[env-var-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration +[exporter-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#otlp-exporter +[require-url]: https://nodejs.org/api/cli.html#-r---require-module diff --git a/metapackages/esbuild-plugin-node/package.json b/metapackages/esbuild-plugin-node/package.json new file mode 100644 index 0000000000..a56337efc7 --- /dev/null +++ b/metapackages/esbuild-plugin-node/package.json @@ -0,0 +1,105 @@ +{ + "name": "@opentelemetry/esbuild-plugin-node", + "version": "0.1.0", + "description": "Metapackage which bundles opentelemetry node core and contrib instrumentations via an esbuild plugin", + "author": "OpenTelemetry Authors", + "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/esbuild-plugin-node#readme", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + }, + "publishConfig": { + "access": "public" + }, + "main": "build/src/index.js", + "types": "build/src/index.d.ts", + "exports": { + ".": "./build/src/index.js", + "./register": "./build/src/register.js" + }, + "repository": "open-telemetry/opentelemetry-js-contrib", + "scripts": { + "clean": "rimraf build/*", + "compile": "tsc -p .", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/esbuild-plugin-node --include-dependencies", + "prewatch": "npm run precompile", + "prepublishOnly": "npm run compile", + "tdd": "yarn test -- --watch-extensions ts --watch", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts'", + "watch": "tsc -w" + }, + "bugs": { + "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.4.1", + "esbuild": "0.19.x" + }, + "devDependencies": { + "@opentelemetry/api": "^1.4.1", + "@types/mocha": "7.0.2", + "@types/node": "18.6.5", + "@types/sinon": "10.0.18", + "mocha": "7.2.0", + "nyc": "15.1.0", + "rimraf": "5.0.5", + "sinon": "15.2.0", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "dependencies": { + "@opentelemetry/auto-instrumentations-node": "^0.40.1", + "@opentelemetry/instrumentation": "^0.45.1", + "@opentelemetry/instrumentation-amqplib": "^0.33.4", + "@opentelemetry/instrumentation-aws-lambda": "^0.37.2", + "@opentelemetry/instrumentation-aws-sdk": "^0.37.0", + "@opentelemetry/instrumentation-bunyan": "^0.33.0", + "@opentelemetry/instrumentation-cassandra-driver": "^0.34.1", + "@opentelemetry/instrumentation-connect": "^0.32.3", + "@opentelemetry/instrumentation-cucumber": "^0.1.2", + "@opentelemetry/instrumentation-dataloader": "^0.5.3", + "@opentelemetry/instrumentation-dns": "^0.32.4", + "@opentelemetry/instrumentation-express": "^0.33.3", + "@opentelemetry/instrumentation-fs": "^0.8.3", + "@opentelemetry/instrumentation-fastify": "^0.32.4", + "@opentelemetry/instrumentation-generic-pool": "^0.32.4", + "@opentelemetry/instrumentation-graphql": "^0.36.0", + "@opentelemetry/instrumentation-grpc": "^0.45.1", + "@opentelemetry/instrumentation-hapi": "^0.33.2", + "@opentelemetry/instrumentation-http": "^0.45.1", + "@opentelemetry/instrumentation-ioredis": "^0.36.0", + "@opentelemetry/instrumentation-knex": "^0.32.3", + "@opentelemetry/instrumentation-koa": "^0.36.2", + "@opentelemetry/instrumentation-lru-memoizer": "^0.33.4", + "@opentelemetry/instrumentation-memcached": "^0.32.4", + "@opentelemetry/instrumentation-mongodb": "^0.37.3", + "@opentelemetry/instrumentation-mongoose": "^0.33.4", + "@opentelemetry/instrumentation-mysql": "^0.34.4", + "@opentelemetry/instrumentation-mysql2": "^0.34.4", + "@opentelemetry/instrumentation-nestjs-core": "^0.33.3", + "@opentelemetry/instrumentation-net": "^0.32.3", + "@opentelemetry/instrumentation-pg": "^0.37.1", + "@opentelemetry/instrumentation-pino": "^0.34.3", + "@opentelemetry/instrumentation-redis": "^0.35.4", + "@opentelemetry/instrumentation-redis-4": "^0.35.5", + "@opentelemetry/instrumentation-restify": "^0.34.2", + "@opentelemetry/instrumentation-router": "^0.33.3", + "@opentelemetry/instrumentation-socket.io": "^0.34.4", + "@opentelemetry/instrumentation-tedious": "^0.6.4", + "@opentelemetry/instrumentation-winston": "^0.33.0", + "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.4", + "@opentelemetry/resource-detector-aws": "^1.3.4", + "@opentelemetry/resource-detector-container": "^0.3.4", + "@opentelemetry/resource-detector-gcp": "^0.29.4", + "@opentelemetry/resources": "^1.12.0", + "@opentelemetry/sdk-node": "^0.45.1", + "esbuild": "^0.19.7" + }, + "files": [ + "build/src/**/*.js", + "build/src/**/*.js.map", + "build/src/**/*.d.ts" + ] +} diff --git a/metapackages/esbuild-plugin-node/src/common.ts b/metapackages/esbuild-plugin-node/src/common.ts new file mode 100644 index 0000000000..fe20844581 --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/common.ts @@ -0,0 +1,62 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { ModuleParams } from './types'; + +export function wrapModule( + originalSource: string, + { + oTelInstrumentationPackage, + oTelInstrumentationClass, + instrumentationName, + oTelInstrumentationConstructorArgs = '', + }: ModuleParams +) { + return ` +(function() { + ${originalSource} +})(...arguments); +{ + let mod = module.exports; + + const { ${oTelInstrumentationClass} } = require('${oTelInstrumentationPackage}'); + const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).init(); + if (instrumentations.length > 1 && !'${instrumentationName}') { + throw new Error('instrumentationName must be specified because ${oTelInstrumentationClass} has multiple instrumentations'); + } + const instrumentation = ${ + instrumentationName + ? `instrumentations.find(i => i.name === '${instrumentationName}')` + : 'instrumentations[0]' + }; + + if (instrumentation.patch && instrumentation.files?.length) { + throw new Error('Not sure how to handle patch and files on instrumentation for ${oTelInstrumentationClass} ${instrumentationName}'); + } + + if (!instrumentation.patch) { + if (!instrumentation.files?.length) { + throw new Error('No patch nor files exist on instrumentation for ${oTelInstrumentationClass} ${instrumentationName}'); + } else if (instrumentation.files.length > 1) { + throw new Error('Not sure how to handle multiple files for nstrumentations for ${instrumentationName}'); + } + } + + mod = instrumentation.patch?.(mod) ?? instrumentation.files[0].patch({ ...mod }); + module.exports = mod; +} +`; +} diff --git a/metapackages/esbuild-plugin-node/src/config/aws-sdk.ts b/metapackages/esbuild-plugin-node/src/config/aws-sdk.ts new file mode 100644 index 0000000000..4218649b02 --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/aws-sdk.ts @@ -0,0 +1,59 @@ +/* + * 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 { + AwsInstrumentation, + AwsSdkInstrumentationConfig, +} from '@opentelemetry/instrumentation-aws-sdk'; + +import { InstrumentationConfig } from './types'; +import { InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; + +function getAwsInstrumentationArgs(config?: AwsSdkInstrumentationConfig) { + if (!config) return; + + return `{ + enabled: ${config.enabled ?? true}, + sqsExtractContextPropagationFromPayload: ${ + config.sqsExtractContextPropagationFromPayload + }, + suppressInternalInstrumentation: ${config.suppressInternalInstrumentation}, + // TODO: Figure out a way to pass in functions correctly. Stringifying them like this means they can't depend + // on any out of scope dependencies like imports + preRequestHook: ${config.preRequestHook?.toString() ?? undefined}, + responseHook: ${config.responseHook?.toString() ?? undefined}, + sqsProcessHook: ${config.sqsProcessHook?.toString() ?? undefined}, + }`; +} + +export const awsSdkInstrumentations: InstrumentationNodeModuleDefinition[] = + new AwsInstrumentation().init(); + +export const awsSdkInstrumentationConfig: Record< + '@smithy/smithy-client' | '@smithy/middleware-stack', + InstrumentationConfig<'@opentelemetry/instrumentation-aws-sdk'> +> = { + '@smithy/smithy-client': { + oTelInstrumentationPackage: '@opentelemetry/instrumentation-aws-sdk', + oTelInstrumentationClass: 'AwsInstrumentation', + configGenerator: getAwsInstrumentationArgs, + }, + '@smithy/middleware-stack': { + oTelInstrumentationPackage: '@opentelemetry/instrumentation-aws-sdk', + oTelInstrumentationClass: 'AwsInstrumentation', + configGenerator: getAwsInstrumentationArgs, + }, +}; diff --git a/metapackages/esbuild-plugin-node/src/config/fastify.ts b/metapackages/esbuild-plugin-node/src/config/fastify.ts new file mode 100644 index 0000000000..06ae1142ac --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/fastify.ts @@ -0,0 +1,46 @@ +/* + * 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 { + FastifyInstrumentation, + FastifyInstrumentationConfig, +} from '@opentelemetry/instrumentation-fastify'; + +import { InstrumentationConfig } from './types'; + +function getFastifyInstrumentationArgs(config?: FastifyInstrumentationConfig) { + if (!config) return; + + return `{ + enabled: ${config.enabled ?? true}, + // TODO: Figure out a way to pass in functions correctly. Stringifying them like this means they can't depend + // on any out of scope dependencies like imports + requestHook: ${config.requestHook?.toString() ?? undefined}, + }`; +} + +export const fastifyInstrumentations = new FastifyInstrumentation().init(); + +export const fastifyInstrumentationConfig: Record< + 'fastify', + InstrumentationConfig<'@opentelemetry/instrumentation-fastify'> +> = { + fastify: { + oTelInstrumentationPackage: '@opentelemetry/instrumentation-fastify', + oTelInstrumentationClass: 'FastifyInstrumentation', + configGenerator: getFastifyInstrumentationArgs, + }, +}; diff --git a/metapackages/esbuild-plugin-node/src/config/index.ts b/metapackages/esbuild-plugin-node/src/config/index.ts new file mode 100644 index 0000000000..a5f1b5e954 --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { instrumentations, otelPackageToInstrumentationConfig } from './main'; diff --git a/metapackages/esbuild-plugin-node/src/config/main.ts b/metapackages/esbuild-plugin-node/src/config/main.ts new file mode 100644 index 0000000000..d1c075a6f5 --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/main.ts @@ -0,0 +1,37 @@ +/* + * 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 { awsSdkInstrumentationConfig, awsSdkInstrumentations } from './aws-sdk'; +import { + fastifyInstrumentationConfig, + fastifyInstrumentations, +} from './fastify'; +import { pinoInstrumentationConfig, pinoInstrumentations } from './pino'; + +import { InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; + +export const instrumentations: InstrumentationNodeModuleDefinition[] = + [ + ...fastifyInstrumentations, + ...pinoInstrumentations, + ...awsSdkInstrumentations, + ]; + +export const otelPackageToInstrumentationConfig = { + ...pinoInstrumentationConfig, + ...fastifyInstrumentationConfig, + ...awsSdkInstrumentationConfig, +}; diff --git a/metapackages/esbuild-plugin-node/src/config/pino.ts b/metapackages/esbuild-plugin-node/src/config/pino.ts new file mode 100644 index 0000000000..5875cc80ab --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/pino.ts @@ -0,0 +1,48 @@ +/* + * 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 { + PinoInstrumentation, + PinoInstrumentationConfig, +} from '@opentelemetry/instrumentation-pino'; + +import { InstrumentationConfig } from './types'; +import { InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; + +function getPinoInstrumentationArgs(config?: PinoInstrumentationConfig) { + if (!config) return; + + return `{ + enabled: ${config.enabled ?? true}, + // TODO: Figure out a way to pass in functions correctly. Stringifying them like this means they can't depend + // on any out of scope dependencies like imports + logHook: ${config.logHook?.toString() ?? undefined}, + }`; +} + +export const pinoInstrumentations: InstrumentationNodeModuleDefinition[] = + new PinoInstrumentation().init(); + +export const pinoInstrumentationConfig: Record< + 'pino', + InstrumentationConfig<'@opentelemetry/instrumentation-pino'> +> = { + pino: { + oTelInstrumentationPackage: '@opentelemetry/instrumentation-pino', + oTelInstrumentationClass: 'PinoInstrumentation', + configGenerator: getPinoInstrumentationArgs, + }, +}; diff --git a/metapackages/esbuild-plugin-node/src/config/types.ts b/metapackages/esbuild-plugin-node/src/config/types.ts new file mode 100644 index 0000000000..80023b325c --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/config/types.ts @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node'; + +export interface InstrumentationConfig< + T extends keyof InstrumentationConfigMap +> { + oTelInstrumentationPackage: T; + oTelInstrumentationClass: string; + configGenerator: (config?: InstrumentationConfigMap[T]) => string | undefined; +} diff --git a/metapackages/esbuild-plugin-node/src/index.ts b/metapackages/esbuild-plugin-node/src/index.ts new file mode 100644 index 0000000000..edd48fc192 --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { openTelemetryPlugin } from './plugin'; diff --git a/metapackages/esbuild-plugin-node/src/plugin.ts b/metapackages/esbuild-plugin-node/src/plugin.ts new file mode 100644 index 0000000000..358d98331f --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/plugin.ts @@ -0,0 +1,221 @@ +/* + * 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 { instrumentations, otelPackageToInstrumentationConfig } from './config'; + +import type { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node'; +import { OnLoadArgs } from './types'; +import { Plugin } from 'esbuild'; +import { builtinModules } from 'module'; +import { dirname } from 'path'; +import { readFile } from 'fs/promises'; +import { satisfies } from 'semver'; +import { wrapModule } from './common'; + +const NODE_MODULES = 'node_modules/'; + +const BUILT_INS = new Set(builtinModules.flatMap(b => [b, `node:${b}`])); + +export interface OpenTelemetryPluginParams { + instrumentationConfig?: InstrumentationConfigMap; + + /** Modules to consider external and ignore from the plugin */ + externalModules?: string[]; + + /** + * Path prefixes to ignore. + * + * ie if you configure compilteOptions.paths in your tsconfig.json to use something like `~/` for the + * root of your project then you could set that here to ignore modules + */ + pathPrefixesToIgnore?: string[]; +} + +interface ExtractedModule { + package: string | null; + path: string | null; +} + +export function openTelemetryPlugin( + pluginConfig?: OpenTelemetryPluginParams +): Plugin { + return { + name: 'open-telemetry', + setup(build) { + build.onResolve({ filter: /.*/ }, async args => { + if ( + shouldIgnoreModule({ + namespace: args.namespace, + path: args.path, + importer: args.importer, + externalModules: pluginConfig?.externalModules, + pathPrefixesToIgnore: pluginConfig?.pathPrefixesToIgnore, + }) + ) { + return; + } + + const path = dotFriendlyResolve(args.path, args.resolveDir); + const extractedModule = extractPackageAndModulePath(path); + + if (isBuiltIn(args.path, extractedModule)) return; + + const matchingInstrumentation = instrumentations.find( + instrumentation => { + const moduleWithPackage = `${extractedModule.package}/${extractedModule.path}`; + const nameMatches = + instrumentation.name === args.path || + instrumentation.name === moduleWithPackage; + + if (!nameMatches) { + const fileMatch = instrumentation.files.find( + file => + file.name === args.path || file.name === moduleWithPackage + ); + if (!fileMatch) return; + } + + const packageJsonPath = require.resolve( + `${extractedModule.package}/package.json`, + { paths: [args.resolveDir] } + ); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { version } = require(packageJsonPath); + + return instrumentation.supportedVersions.some(supportedVersion => + satisfies(version, supportedVersion) + ); + } + ); + if (!matchingInstrumentation) return; + + return { + path, + pluginData: { + shouldPatchPackage: true, + instrumentation: { name: matchingInstrumentation.name }, + }, + }; + }); + + build.onLoad( + { filter: /.*/ }, + async ({ path, pluginData }: OnLoadArgs) => { + if (!pluginData?.shouldPatchPackage) return; + + const contents = await readFile(path); + + const config = + otelPackageToInstrumentationConfig[pluginData.instrumentation.name]; + + const packageConfig = + pluginConfig?.instrumentationConfig?.[ + config.oTelInstrumentationPackage + ]; + + return { + contents: wrapModule(contents.toString(), { + instrumentationName: pluginData.instrumentation.name, + oTelInstrumentationClass: config.oTelInstrumentationClass, + oTelInstrumentationPackage: config.oTelInstrumentationPackage, + oTelInstrumentationConstructorArgs: + config.configGenerator(packageConfig), + }), + resolveDir: dirname(path), + }; + } + ); + }, + }; +} + +// @see https://github.com/nodejs/node/issues/47000 +function dotFriendlyResolve(path: string, directory: string): string { + if (path === '.') { + path = './'; + } else if (path === '..') { + path = '../'; + } + return require.resolve(path, { paths: [directory] }); +} + +/** + * For a given full path to a module, + * return the package name it belongs to and the local path to the module + * input: '/foo/node_modules/@co/stuff/foo/bar/baz.js' + * output: { pkg: '@co/stuff', path: 'foo/bar/baz.js' } + */ +function extractPackageAndModulePath(fullPath: string): ExtractedModule { + const nm = fullPath.lastIndexOf(NODE_MODULES); + if (nm < 0) { + return { package: null, path: null }; + } + + const subPath = fullPath.substring(nm + NODE_MODULES.length); + const firstSlash = subPath.indexOf('/'); + + if (subPath.startsWith('@')) { + const secondSlash = subPath.substring(firstSlash + 1).indexOf('/'); + + return { + package: subPath.substring(0, firstSlash + 1 + secondSlash), + path: subPath.substring(firstSlash + 1 + secondSlash + 1), + }; + } + + return { + package: subPath.substring(0, firstSlash), + path: subPath.substring(firstSlash + 1), + }; +} + +function shouldIgnoreModule({ + namespace, + path, + importer, + externalModules, + pathPrefixesToIgnore, +}: { + namespace: string; + path: string; + importer: string; + externalModules?: string[]; + pathPrefixesToIgnore?: string[]; +}): boolean { + if (namespace !== 'file') return true; + + if ( + !importer.includes(NODE_MODULES) && + (path.startsWith('.') || path.startsWith('@')) + ) { + return true; + } + + if (pathPrefixesToIgnore?.some(prefix => path.startsWith(prefix))) { + return true; + } + + if (externalModules?.includes(path)) return true; + + return false; +} + +function isBuiltIn(path: string, extractedModule: ExtractedModule): boolean { + return ( + BUILT_INS.has(path) || + BUILT_INS.has(`${extractedModule.package}/${extractedModule.path}`) + ); +} diff --git a/metapackages/esbuild-plugin-node/src/types.ts b/metapackages/esbuild-plugin-node/src/types.ts new file mode 100644 index 0000000000..a62e02454f --- /dev/null +++ b/metapackages/esbuild-plugin-node/src/types.ts @@ -0,0 +1,40 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { OnLoadArgs as EsbuildOnLoadArgs } from 'esbuild'; + +export type InstrumentedPackage = + | 'fastify' + | 'pino' + | '@smithy/smithy-client' + | '@smithy/middleware-stack'; + +export type OnLoadArgs = Omit & { + pluginData?: { + shouldPatchPackage: boolean; + package: InstrumentedPackage; + instrumentation: { + name: InstrumentedPackage; + }; + }; +}; + +export interface ModuleParams { + oTelInstrumentationPackage: string; + oTelInstrumentationClass: string; + oTelInstrumentationConstructorArgs?: string; + instrumentationName?: string; +} diff --git a/metapackages/esbuild-plugin-node/test/plugin.test.ts b/metapackages/esbuild-plugin-node/test/plugin.test.ts new file mode 100644 index 0000000000..359ed365a1 --- /dev/null +++ b/metapackages/esbuild-plugin-node/test/plugin.test.ts @@ -0,0 +1,103 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as assert from 'assert'; + +import { exec as execCb, spawnSync } from 'child_process'; + +import { promisify } from 'util'; + +const exec = promisify(execCb); + +function startTestApp() { + return spawnSync( + process.execPath, + ['--require', './test-app/register.js', '../test-dist/app.js'], + { + cwd: __dirname, + timeout: 5000, + killSignal: 'SIGKILL', // SIGTERM is not sufficient to terminate some hangs + env: { + ...process.env, + OTEL_NODE_RESOURCE_DETECTORS: 'none', + OTEL_TRACES_EXPORTER: 'console', + // nx (used by lerna run) defaults `FORCE_COLOR=true`, which in + // node v18.17.0, v20.3.0 and later results in ANSI color escapes + // in the ConsoleSpanExporter output that is checked below. + FORCE_COLOR: '0', + }, + } + ); +} + +function getTraceId( + stdOutLines: string[], + spanName: string +): string | undefined { + const traceLogNameLineIndex = stdOutLines.findIndex(logLine => + logLine.includes(`name: '${spanName}'`) + ); + if (traceLogNameLineIndex === -1) return; + + const logsBeforeName = stdOutLines.slice(0, traceLogNameLineIndex); + const logsIncludingAndAfterName = stdOutLines.slice(traceLogNameLineIndex); + const openingBracketLineIndex = logsBeforeName.lastIndexOf('{'); + const closingBracketLineIndex = + traceLogNameLineIndex + logsIncludingAndAfterName.indexOf('}') + 1; + + const traceId = /traceId: '([0-9a-f]+)'/.exec( + stdOutLines.slice(openingBracketLineIndex, closingBracketLineIndex).join('') + )?.[1]; + + return traceId; +} + +describe('Esbuild can instrument packages via a plugin', function () { + this.beforeAll(async () => { + await exec(`ts-node ${__dirname}/test-app/build.ts`); + }); + + it('fastify and pino', async () => { + const proc = startTestApp(); + + assert.ifError(proc.error); + assert.equal(proc.status, 0, `proc.status (${proc.status})`); + assert.equal(proc.signal, null, `proc.signal (${proc.signal})`); + + const stdOut = proc.stdout.toString(); + const stdOutLines = stdOut.split('\n'); + + assert.ok( + stdOutLines.find( + logLine => + logLine === + 'OpenTelemetry automatic instrumentation started successfully' + ) + ); + + const traceId = getTraceId(stdOutLines, 'request handler - fastify'); + + assert.ok(traceId, 'console span output in stdout contains a traceId'); + + const requestHandlerLogMessage = stdOutLines.find(line => + line.includes('Log message from handler') + ); + + assert.ok(requestHandlerLogMessage, 'Log message handler is triggered'); + const { trace_id } = JSON.parse(requestHandlerLogMessage); + assert.equal(traceId, trace_id, 'Pino logs include trace ID'); + }); +}); diff --git a/metapackages/esbuild-plugin-node/test/test-app/app.ts b/metapackages/esbuild-plugin-node/test/test-app/app.ts new file mode 100644 index 0000000000..996351d467 --- /dev/null +++ b/metapackages/esbuild-plugin-node/test/test-app/app.ts @@ -0,0 +1,44 @@ +/* + * 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 fastify from 'fastify'; +import pino from 'pino'; + +export const server = fastify({ + logger: pino({}, pino.destination(1)), + disableRequestLogging: true, +}); + +server.get('/test', req => { + req.log.info({ hi: 'there' }, 'Log message from handler'); + return { hi: 'there' }; +}); + +server + .listen({ port: 8080 }) + .then(() => { + server + .inject() + .get('/test') + .end() + .catch(err => { + throw err; + }) + .finally(() => server.close()); + }) + .catch(err => { + throw err; + }); diff --git a/metapackages/esbuild-plugin-node/test/test-app/build.ts b/metapackages/esbuild-plugin-node/test/test-app/build.ts new file mode 100644 index 0000000000..22b168b247 --- /dev/null +++ b/metapackages/esbuild-plugin-node/test/test-app/build.ts @@ -0,0 +1,30 @@ +/* + * 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 { build } from 'esbuild'; +import { openTelemetryPlugin } from '../../src/plugin'; + +build({ + entryPoints: [`${__dirname}/app.ts`], + bundle: true, + outfile: 'test-dist/app.js', + target: 'node20', + platform: 'node', + sourcemap: true, + plugins: [openTelemetryPlugin()], +}).catch(err => { + throw err; +}); diff --git a/metapackages/esbuild-plugin-node/test/test-app/register.js b/metapackages/esbuild-plugin-node/test/test-app/register.js new file mode 100644 index 0000000000..f738d9e27f --- /dev/null +++ b/metapackages/esbuild-plugin-node/test/test-app/register.js @@ -0,0 +1,46 @@ +/* + * 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. + */ + +const opentelemetry = require('@opentelemetry/sdk-node'); +const { DiagConsoleLogger, diag } = require('@opentelemetry/api'); +const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); + +diag.setLogger( + new DiagConsoleLogger(), + opentelemetry.core.getEnv().OTEL_LOG_LEVEL +); + +const sdk = new opentelemetry.NodeSDK({ + // Notably instrumentation fastify and pino are not in here + instrumentations: [], +}); + +try { + sdk.start(); + diag.info('OpenTelemetry automatic instrumentation started successfully'); +} catch (error) { + diag.error( + 'Error initializing OpenTelemetry SDK. Your application is not instrumented and will not produce telemetry', + error + ); +} + +process.on('SIGTERM', () => { + sdk + .shutdown() + .then(() => diag.debug('OpenTelemetry SDK terminated')) + .catch(error => diag.error('Error terminating OpenTelemetry SDK', error)); +}); diff --git a/metapackages/esbuild-plugin-node/tsconfig.json b/metapackages/esbuild-plugin-node/tsconfig.json new file mode 100644 index 0000000000..4078877ce6 --- /dev/null +++ b/metapackages/esbuild-plugin-node/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ] +} diff --git a/package-lock.json b/package-lock.json index 0bcce7b048..bdbba86d5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -356,6 +356,84 @@ "zone.js": "0.11.4" } }, + "metapackages/esbuild-plugin-node": { + "name": "@opentelemetry/esbuild-plugin-node", + "version": "0.1.0", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/auto-instrumentations-node": "^0.40.1", + "@opentelemetry/instrumentation": "^0.45.1", + "@opentelemetry/instrumentation-amqplib": "^0.33.4", + "@opentelemetry/instrumentation-aws-lambda": "^0.37.2", + "@opentelemetry/instrumentation-aws-sdk": "^0.37.0", + "@opentelemetry/instrumentation-bunyan": "^0.33.0", + "@opentelemetry/instrumentation-cassandra-driver": "^0.34.1", + "@opentelemetry/instrumentation-connect": "^0.32.3", + "@opentelemetry/instrumentation-cucumber": "^0.1.2", + "@opentelemetry/instrumentation-dataloader": "^0.5.3", + "@opentelemetry/instrumentation-dns": "^0.32.4", + "@opentelemetry/instrumentation-express": "^0.33.3", + "@opentelemetry/instrumentation-fastify": "^0.32.4", + "@opentelemetry/instrumentation-fs": "^0.8.3", + "@opentelemetry/instrumentation-generic-pool": "^0.32.4", + "@opentelemetry/instrumentation-graphql": "^0.36.0", + "@opentelemetry/instrumentation-grpc": "^0.45.1", + "@opentelemetry/instrumentation-hapi": "^0.33.2", + "@opentelemetry/instrumentation-http": "^0.45.1", + "@opentelemetry/instrumentation-ioredis": "^0.36.0", + "@opentelemetry/instrumentation-knex": "^0.32.3", + "@opentelemetry/instrumentation-koa": "^0.36.2", + "@opentelemetry/instrumentation-lru-memoizer": "^0.33.4", + "@opentelemetry/instrumentation-memcached": "^0.32.4", + "@opentelemetry/instrumentation-mongodb": "^0.37.3", + "@opentelemetry/instrumentation-mongoose": "^0.33.4", + "@opentelemetry/instrumentation-mysql": "^0.34.4", + "@opentelemetry/instrumentation-mysql2": "^0.34.4", + "@opentelemetry/instrumentation-nestjs-core": "^0.33.3", + "@opentelemetry/instrumentation-net": "^0.32.3", + "@opentelemetry/instrumentation-pg": "^0.37.1", + "@opentelemetry/instrumentation-pino": "^0.34.3", + "@opentelemetry/instrumentation-redis": "^0.35.4", + "@opentelemetry/instrumentation-redis-4": "^0.35.5", + "@opentelemetry/instrumentation-restify": "^0.34.2", + "@opentelemetry/instrumentation-router": "^0.33.3", + "@opentelemetry/instrumentation-socket.io": "^0.34.4", + "@opentelemetry/instrumentation-tedious": "^0.6.4", + "@opentelemetry/instrumentation-winston": "^0.33.0", + "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.4", + "@opentelemetry/resource-detector-aws": "^1.3.4", + "@opentelemetry/resource-detector-container": "^0.3.4", + "@opentelemetry/resource-detector-gcp": "^0.29.4", + "@opentelemetry/resources": "^1.12.0", + "@opentelemetry/sdk-node": "^0.45.1", + "esbuild": "^0.19.7" + }, + "devDependencies": { + "@opentelemetry/api": "^1.4.1", + "@types/mocha": "7.0.2", + "@types/node": "18.6.5", + "@types/sinon": "10.0.18", + "mocha": "7.2.0", + "nyc": "15.1.0", + "rimraf": "5.0.5", + "sinon": "15.2.0", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.4.1", + "esbuild": "0.19.x" + } + }, + "metapackages/esbuild-plugin-node/node_modules/@types/mocha": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", + "integrity": "sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==", + "dev": true + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -4842,6 +4920,336 @@ "node": ">=10.0.0" } }, + "node_modules/@esbuild/android-arm": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.7.tgz", + "integrity": "sha512-YGSPnndkcLo4PmVl2tKatEn+0mlVMr3yEpOOT0BeMria87PhvoJb5dg5f5Ft9fbCVgtAz4pWMzZVgSEGpDAlww==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.7.tgz", + "integrity": "sha512-YEDcw5IT7hW3sFKZBkCAQaOCJQLONVcD4bOyTXMZz5fr66pTHnAet46XAtbXAkJRfIn2YVhdC6R9g4xa27jQ1w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.7.tgz", + "integrity": "sha512-jhINx8DEjz68cChFvM72YzrqfwJuFbfvSxZAk4bebpngGfNNRm+zRl4rtT9oAX6N9b6gBcFaJHFew5Blf6CvUw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.7.tgz", + "integrity": "sha512-dr81gbmWN//3ZnBIm6YNCl4p3pjnabg1/ZVOgz2fJoUO1a3mq9WQ/1iuEluMs7mCL+Zwv7AY5e3g1hjXqQZ9Iw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.7.tgz", + "integrity": "sha512-Lc0q5HouGlzQEwLkgEKnWcSazqr9l9OdV2HhVasWJzLKeOt0PLhHaUHuzb8s/UIya38DJDoUm74GToZ6Wc7NGQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.7.tgz", + "integrity": "sha512-+y2YsUr0CxDFF7GWiegWjGtTUF6gac2zFasfFkRJPkMAuMy9O7+2EH550VlqVdpEEchWMynkdhC9ZjtnMiHImQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.7.tgz", + "integrity": "sha512-CdXOxIbIzPJmJhrpmJTLx+o35NoiKBIgOvmvT+jeSadYiWJn0vFKsl+0bSG/5lwjNHoIDEyMYc/GAPR9jxusTA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.7.tgz", + "integrity": "sha512-Y+SCmWxsJOdQtjcBxoacn/pGW9HDZpwsoof0ttL+2vGcHokFlfqV666JpfLCSP2xLxFpF1lj7T3Ox3sr95YXww==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.7.tgz", + "integrity": "sha512-inHqdOVCkUhHNvuQPT1oCB7cWz9qQ/Cz46xmVe0b7UXcuIJU3166aqSunsqkgSGMtUCWOZw3+KMwI6otINuC9g==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.7.tgz", + "integrity": "sha512-2BbiL7nLS5ZO96bxTQkdO0euGZIUQEUXMTrqLxKUmk/Y5pmrWU84f+CMJpM8+EHaBPfFSPnomEaQiG/+Gmh61g==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.7.tgz", + "integrity": "sha512-BVFQla72KXv3yyTFCQXF7MORvpTo4uTA8FVFgmwVrqbB/4DsBFWilUm1i2Oq6zN36DOZKSVUTb16jbjedhfSHw==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.7.tgz", + "integrity": "sha512-DzAYckIaK+pS31Q/rGpvUKu7M+5/t+jI+cdleDgUwbU7KdG2eC3SUbZHlo6Q4P1CfVKZ1lUERRFP8+q0ob9i2w==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.7.tgz", + "integrity": "sha512-JQ1p0SmUteNdUaaiRtyS59GkkfTW0Edo+e0O2sihnY4FoZLz5glpWUQEKMSzMhA430ctkylkS7+vn8ziuhUugQ==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.7.tgz", + "integrity": "sha512-xGwVJ7eGhkprY/nB7L7MXysHduqjpzUl40+XoYDGC4UPLbnG+gsyS1wQPJ9lFPcxYAaDXbdRXd1ACs9AE9lxuw==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.7.tgz", + "integrity": "sha512-U8Rhki5PVU0L0nvk+E8FjkV8r4Lh4hVEb9duR6Zl21eIEYEwXz8RScj4LZWA2i3V70V4UHVgiqMpszXvG0Yqhg==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.7.tgz", + "integrity": "sha512-ZYZopyLhm4mcoZXjFt25itRlocKlcazDVkB4AhioiL9hOWhDldU9n38g62fhOI4Pth6vp+Mrd5rFKxD0/S+7aQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.7.tgz", + "integrity": "sha512-/yfjlsYmT1O3cum3J6cmGG16Fd5tqKMcg5D+sBYLaOQExheAJhqr8xOAEIuLo8JYkevmjM5zFD9rVs3VBcsjtQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.7.tgz", + "integrity": "sha512-MYDFyV0EW1cTP46IgUJ38OnEY5TaXxjoDmwiTXPjezahQgZd+j3T55Ht8/Q9YXBM0+T9HJygrSRGV5QNF/YVDQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.7.tgz", + "integrity": "sha512-JcPvgzf2NN/y6X3UUSqP6jSS06V0DZAV/8q0PjsZyGSXsIGcG110XsdmuWiHM+pno7/mJF6fjH5/vhUz/vA9fw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.7.tgz", + "integrity": "sha512-ZA0KSYti5w5toax5FpmfcAgu3ZNJxYSRm0AW/Dao5up0YV1hDVof1NvwLomjEN+3/GMtaWDI+CIyJOMTRSTdMw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.7.tgz", + "integrity": "sha512-CTOnijBKc5Jpk6/W9hQMMvJnsSYRYgveN6O75DTACCY18RA2nqka8dTZR+x/JqXCRiKk84+5+bRKXUSbbwsS0A==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.7.tgz", + "integrity": "sha512-gRaP2sk6hc98N734luX4VpF318l3w+ofrtTu9j5L8EQXF+FzQKV6alCOHMVoJJHvVK/mGbwBXfOL1HETQu9IGQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@eslint/eslintrc": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.1.tgz", @@ -8309,6 +8717,10 @@ "@opentelemetry/api": ">=1.0.0 <1.8.0" } }, + "node_modules/@opentelemetry/esbuild-plugin-node": { + "resolved": "metapackages/esbuild-plugin-node", + "link": true + }, "node_modules/@opentelemetry/exporter-jaeger": { "version": "1.18.1", "resolved": "https://registry.npmjs.org/@opentelemetry/exporter-jaeger/-/exporter-jaeger-1.18.1.tgz", @@ -15004,6 +15416,42 @@ "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==", "dev": true }, + "node_modules/esbuild": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.7.tgz", + "integrity": "sha512-6brbTZVqxhqgbpqBR5MzErImcpA0SQdoKOkcWK/U30HtQxnokIpG3TX2r0IJqbFUzqLjhU/zC1S5ndgakObVCQ==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.19.7", + "@esbuild/android-arm64": "0.19.7", + "@esbuild/android-x64": "0.19.7", + "@esbuild/darwin-arm64": "0.19.7", + "@esbuild/darwin-x64": "0.19.7", + "@esbuild/freebsd-arm64": "0.19.7", + "@esbuild/freebsd-x64": "0.19.7", + "@esbuild/linux-arm": "0.19.7", + "@esbuild/linux-arm64": "0.19.7", + "@esbuild/linux-ia32": "0.19.7", + "@esbuild/linux-loong64": "0.19.7", + "@esbuild/linux-mips64el": "0.19.7", + "@esbuild/linux-ppc64": "0.19.7", + "@esbuild/linux-riscv64": "0.19.7", + "@esbuild/linux-s390x": "0.19.7", + "@esbuild/linux-x64": "0.19.7", + "@esbuild/netbsd-x64": "0.19.7", + "@esbuild/openbsd-x64": "0.19.7", + "@esbuild/sunos-x64": "0.19.7", + "@esbuild/win32-arm64": "0.19.7", + "@esbuild/win32-ia32": "0.19.7", + "@esbuild/win32-x64": "0.19.7" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -41160,6 +41608,138 @@ "integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==", "dev": true }, + "@esbuild/android-arm": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.7.tgz", + "integrity": "sha512-YGSPnndkcLo4PmVl2tKatEn+0mlVMr3yEpOOT0BeMria87PhvoJb5dg5f5Ft9fbCVgtAz4pWMzZVgSEGpDAlww==", + "optional": true + }, + "@esbuild/android-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.7.tgz", + "integrity": "sha512-YEDcw5IT7hW3sFKZBkCAQaOCJQLONVcD4bOyTXMZz5fr66pTHnAet46XAtbXAkJRfIn2YVhdC6R9g4xa27jQ1w==", + "optional": true + }, + "@esbuild/android-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.7.tgz", + "integrity": "sha512-jhINx8DEjz68cChFvM72YzrqfwJuFbfvSxZAk4bebpngGfNNRm+zRl4rtT9oAX6N9b6gBcFaJHFew5Blf6CvUw==", + "optional": true + }, + "@esbuild/darwin-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.7.tgz", + "integrity": "sha512-dr81gbmWN//3ZnBIm6YNCl4p3pjnabg1/ZVOgz2fJoUO1a3mq9WQ/1iuEluMs7mCL+Zwv7AY5e3g1hjXqQZ9Iw==", + "optional": true + }, + "@esbuild/darwin-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.7.tgz", + "integrity": "sha512-Lc0q5HouGlzQEwLkgEKnWcSazqr9l9OdV2HhVasWJzLKeOt0PLhHaUHuzb8s/UIya38DJDoUm74GToZ6Wc7NGQ==", + "optional": true + }, + "@esbuild/freebsd-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.7.tgz", + "integrity": "sha512-+y2YsUr0CxDFF7GWiegWjGtTUF6gac2zFasfFkRJPkMAuMy9O7+2EH550VlqVdpEEchWMynkdhC9ZjtnMiHImQ==", + "optional": true + }, + "@esbuild/freebsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.7.tgz", + "integrity": "sha512-CdXOxIbIzPJmJhrpmJTLx+o35NoiKBIgOvmvT+jeSadYiWJn0vFKsl+0bSG/5lwjNHoIDEyMYc/GAPR9jxusTA==", + "optional": true + }, + "@esbuild/linux-arm": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.7.tgz", + "integrity": "sha512-Y+SCmWxsJOdQtjcBxoacn/pGW9HDZpwsoof0ttL+2vGcHokFlfqV666JpfLCSP2xLxFpF1lj7T3Ox3sr95YXww==", + "optional": true + }, + "@esbuild/linux-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.7.tgz", + "integrity": "sha512-inHqdOVCkUhHNvuQPT1oCB7cWz9qQ/Cz46xmVe0b7UXcuIJU3166aqSunsqkgSGMtUCWOZw3+KMwI6otINuC9g==", + "optional": true + }, + "@esbuild/linux-ia32": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.7.tgz", + "integrity": "sha512-2BbiL7nLS5ZO96bxTQkdO0euGZIUQEUXMTrqLxKUmk/Y5pmrWU84f+CMJpM8+EHaBPfFSPnomEaQiG/+Gmh61g==", + "optional": true + }, + "@esbuild/linux-loong64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.7.tgz", + "integrity": "sha512-BVFQla72KXv3yyTFCQXF7MORvpTo4uTA8FVFgmwVrqbB/4DsBFWilUm1i2Oq6zN36DOZKSVUTb16jbjedhfSHw==", + "optional": true + }, + "@esbuild/linux-mips64el": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.7.tgz", + "integrity": "sha512-DzAYckIaK+pS31Q/rGpvUKu7M+5/t+jI+cdleDgUwbU7KdG2eC3SUbZHlo6Q4P1CfVKZ1lUERRFP8+q0ob9i2w==", + "optional": true + }, + "@esbuild/linux-ppc64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.7.tgz", + "integrity": "sha512-JQ1p0SmUteNdUaaiRtyS59GkkfTW0Edo+e0O2sihnY4FoZLz5glpWUQEKMSzMhA430ctkylkS7+vn8ziuhUugQ==", + "optional": true + }, + "@esbuild/linux-riscv64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.7.tgz", + "integrity": "sha512-xGwVJ7eGhkprY/nB7L7MXysHduqjpzUl40+XoYDGC4UPLbnG+gsyS1wQPJ9lFPcxYAaDXbdRXd1ACs9AE9lxuw==", + "optional": true + }, + "@esbuild/linux-s390x": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.7.tgz", + "integrity": "sha512-U8Rhki5PVU0L0nvk+E8FjkV8r4Lh4hVEb9duR6Zl21eIEYEwXz8RScj4LZWA2i3V70V4UHVgiqMpszXvG0Yqhg==", + "optional": true + }, + "@esbuild/linux-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.7.tgz", + "integrity": "sha512-ZYZopyLhm4mcoZXjFt25itRlocKlcazDVkB4AhioiL9hOWhDldU9n38g62fhOI4Pth6vp+Mrd5rFKxD0/S+7aQ==", + "optional": true + }, + "@esbuild/netbsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.7.tgz", + "integrity": "sha512-/yfjlsYmT1O3cum3J6cmGG16Fd5tqKMcg5D+sBYLaOQExheAJhqr8xOAEIuLo8JYkevmjM5zFD9rVs3VBcsjtQ==", + "optional": true + }, + "@esbuild/openbsd-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.7.tgz", + "integrity": "sha512-MYDFyV0EW1cTP46IgUJ38OnEY5TaXxjoDmwiTXPjezahQgZd+j3T55Ht8/Q9YXBM0+T9HJygrSRGV5QNF/YVDQ==", + "optional": true + }, + "@esbuild/sunos-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.7.tgz", + "integrity": "sha512-JcPvgzf2NN/y6X3UUSqP6jSS06V0DZAV/8q0PjsZyGSXsIGcG110XsdmuWiHM+pno7/mJF6fjH5/vhUz/vA9fw==", + "optional": true + }, + "@esbuild/win32-arm64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.7.tgz", + "integrity": "sha512-ZA0KSYti5w5toax5FpmfcAgu3ZNJxYSRm0AW/Dao5up0YV1hDVof1NvwLomjEN+3/GMtaWDI+CIyJOMTRSTdMw==", + "optional": true + }, + "@esbuild/win32-ia32": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.7.tgz", + "integrity": "sha512-CTOnijBKc5Jpk6/W9hQMMvJnsSYRYgveN6O75DTACCY18RA2nqka8dTZR+x/JqXCRiKk84+5+bRKXUSbbwsS0A==", + "optional": true + }, + "@esbuild/win32-x64": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.7.tgz", + "integrity": "sha512-gRaP2sk6hc98N734luX4VpF318l3w+ofrtTu9j5L8EQXF+FzQKV6alCOHMVoJJHvVK/mGbwBXfOL1HETQu9IGQ==", + "optional": true + }, "@eslint/eslintrc": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.1.tgz", @@ -43898,6 +44478,75 @@ "@opentelemetry/semantic-conventions": "1.18.1" } }, + "@opentelemetry/esbuild-plugin-node": { + "version": "file:metapackages/esbuild-plugin-node", + "requires": { + "@opentelemetry/api": "^1.4.1", + "@opentelemetry/auto-instrumentations-node": "^0.40.1", + "@opentelemetry/instrumentation": "^0.45.1", + "@opentelemetry/instrumentation-amqplib": "^0.33.4", + "@opentelemetry/instrumentation-aws-lambda": "^0.37.2", + "@opentelemetry/instrumentation-aws-sdk": "^0.37.0", + "@opentelemetry/instrumentation-bunyan": "^0.33.0", + "@opentelemetry/instrumentation-cassandra-driver": "^0.34.1", + "@opentelemetry/instrumentation-connect": "^0.32.3", + "@opentelemetry/instrumentation-cucumber": "^0.1.2", + "@opentelemetry/instrumentation-dataloader": "^0.5.3", + "@opentelemetry/instrumentation-dns": "^0.32.4", + "@opentelemetry/instrumentation-express": "^0.33.3", + "@opentelemetry/instrumentation-fastify": "^0.32.4", + "@opentelemetry/instrumentation-fs": "^0.8.3", + "@opentelemetry/instrumentation-generic-pool": "^0.32.4", + "@opentelemetry/instrumentation-graphql": "^0.36.0", + "@opentelemetry/instrumentation-grpc": "^0.45.1", + "@opentelemetry/instrumentation-hapi": "^0.33.2", + "@opentelemetry/instrumentation-http": "^0.45.1", + "@opentelemetry/instrumentation-ioredis": "^0.36.0", + "@opentelemetry/instrumentation-knex": "^0.32.3", + "@opentelemetry/instrumentation-koa": "^0.36.2", + "@opentelemetry/instrumentation-lru-memoizer": "^0.33.4", + "@opentelemetry/instrumentation-memcached": "^0.32.4", + "@opentelemetry/instrumentation-mongodb": "^0.37.3", + "@opentelemetry/instrumentation-mongoose": "^0.33.4", + "@opentelemetry/instrumentation-mysql": "^0.34.4", + "@opentelemetry/instrumentation-mysql2": "^0.34.4", + "@opentelemetry/instrumentation-nestjs-core": "^0.33.3", + "@opentelemetry/instrumentation-net": "^0.32.3", + "@opentelemetry/instrumentation-pg": "^0.37.1", + "@opentelemetry/instrumentation-pino": "^0.34.3", + "@opentelemetry/instrumentation-redis": "^0.35.4", + "@opentelemetry/instrumentation-redis-4": "^0.35.5", + "@opentelemetry/instrumentation-restify": "^0.34.2", + "@opentelemetry/instrumentation-router": "^0.33.3", + "@opentelemetry/instrumentation-socket.io": "^0.34.4", + "@opentelemetry/instrumentation-tedious": "^0.6.4", + "@opentelemetry/instrumentation-winston": "^0.33.0", + "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.4", + "@opentelemetry/resource-detector-aws": "^1.3.4", + "@opentelemetry/resource-detector-container": "^0.3.4", + "@opentelemetry/resource-detector-gcp": "^0.29.4", + "@opentelemetry/resources": "^1.12.0", + "@opentelemetry/sdk-node": "^0.45.1", + "@types/mocha": "7.0.2", + "@types/node": "18.6.5", + "@types/sinon": "10.0.18", + "esbuild": "^0.19.7", + "mocha": "7.2.0", + "nyc": "15.1.0", + "rimraf": "5.0.5", + "sinon": "15.2.0", + "ts-mocha": "10.0.0", + "typescript": "4.4.4" + }, + "dependencies": { + "@types/mocha": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", + "integrity": "sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==", + "dev": true + } + } + }, "@opentelemetry/exporter-jaeger": { "version": "1.18.1", "resolved": "https://registry.npmjs.org/@opentelemetry/exporter-jaeger/-/exporter-jaeger-1.18.1.tgz", @@ -51490,6 +52139,35 @@ "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==", "dev": true }, + "esbuild": { + "version": "0.19.7", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.7.tgz", + "integrity": "sha512-6brbTZVqxhqgbpqBR5MzErImcpA0SQdoKOkcWK/U30HtQxnokIpG3TX2r0IJqbFUzqLjhU/zC1S5ndgakObVCQ==", + "requires": { + "@esbuild/android-arm": "0.19.7", + "@esbuild/android-arm64": "0.19.7", + "@esbuild/android-x64": "0.19.7", + "@esbuild/darwin-arm64": "0.19.7", + "@esbuild/darwin-x64": "0.19.7", + "@esbuild/freebsd-arm64": "0.19.7", + "@esbuild/freebsd-x64": "0.19.7", + "@esbuild/linux-arm": "0.19.7", + "@esbuild/linux-arm64": "0.19.7", + "@esbuild/linux-ia32": "0.19.7", + "@esbuild/linux-loong64": "0.19.7", + "@esbuild/linux-mips64el": "0.19.7", + "@esbuild/linux-ppc64": "0.19.7", + "@esbuild/linux-riscv64": "0.19.7", + "@esbuild/linux-s390x": "0.19.7", + "@esbuild/linux-x64": "0.19.7", + "@esbuild/netbsd-x64": "0.19.7", + "@esbuild/openbsd-x64": "0.19.7", + "@esbuild/sunos-x64": "0.19.7", + "@esbuild/win32-arm64": "0.19.7", + "@esbuild/win32-ia32": "0.19.7", + "@esbuild/win32-x64": "0.19.7" + } + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", diff --git a/plugins/node/instrumentation-amqplib/src/amqplib.ts b/plugins/node/instrumentation-amqplib/src/amqplib.ts index 17fd6e20b6..acfb6b831a 100644 --- a/plugins/node/instrumentation-amqplib/src/amqplib.ts +++ b/plugins/node/instrumentation-amqplib/src/amqplib.ts @@ -84,7 +84,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { this._config = Object.assign({}, DEFAULT_CONFIG, config); } - protected init() { + init() { const channelModelModuleFile = new InstrumentationNodeModuleFile( 'amqplib/lib/channel_model.js', ['>=0.5.5'], diff --git a/plugins/node/instrumentation-dataloader/src/instrumentation.ts b/plugins/node/instrumentation-dataloader/src/instrumentation.ts index 7264d031ae..f1a735c645 100644 --- a/plugins/node/instrumentation-dataloader/src/instrumentation.ts +++ b/plugins/node/instrumentation-dataloader/src/instrumentation.ts @@ -49,7 +49,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-dataloader', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( MODULE_NAME, diff --git a/plugins/node/instrumentation-mongoose/src/mongoose.ts b/plugins/node/instrumentation-mongoose/src/mongoose.ts index bfd73574b4..7b8f5d1014 100644 --- a/plugins/node/instrumentation-mongoose/src/mongoose.ts +++ b/plugins/node/instrumentation-mongoose/src/mongoose.ts @@ -74,7 +74,7 @@ export class MongooseInstrumentation extends InstrumentationBase { this._config = Object.assign({}, config); } - protected init(): InstrumentationModuleDefinition { + init(): InstrumentationModuleDefinition { const module = new InstrumentationNodeModuleDefinition( 'mongoose', ['>=5.9.7 <7'], diff --git a/plugins/node/instrumentation-socket.io/src/socket.io.ts b/plugins/node/instrumentation-socket.io/src/socket.io.ts index db37e5c375..ee08d25a36 100644 --- a/plugins/node/instrumentation-socket.io/src/socket.io.ts +++ b/plugins/node/instrumentation-socket.io/src/socket.io.ts @@ -61,7 +61,7 @@ export class SocketIoInstrumentation extends InstrumentationBase { ); } - protected init() { + init() { const socketInstrumentation = new InstrumentationNodeModuleFile( 'socket.io/dist/socket.js', ['>=3 <5'], diff --git a/plugins/node/instrumentation-tedious/src/instrumentation.ts b/plugins/node/instrumentation-tedious/src/instrumentation.ts index 7484dd49fb..1589d610df 100644 --- a/plugins/node/instrumentation-tedious/src/instrumentation.ts +++ b/plugins/node/instrumentation-tedious/src/instrumentation.ts @@ -15,19 +15,21 @@ */ import * as api from '@opentelemetry/api'; -import { EventEmitter } from 'events'; +import type * as tedious from 'tedious'; + +import { + DbSystemValues, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped, } from '@opentelemetry/instrumentation'; -import { - DbSystemValues, - SemanticAttributes, -} from '@opentelemetry/semantic-conventions'; -import type * as tedious from 'tedious'; -import { TediousInstrumentationConfig } from './types'; import { getSpanName, once } from './utils'; + +import { EventEmitter } from 'events'; +import { TediousInstrumentationConfig } from './types'; import { VERSION } from './version'; const CURRENT_DATABASE = Symbol( @@ -70,7 +72,7 @@ export class TediousInstrumentation extends InstrumentationBase< super('@opentelemetry/instrumentation-tedious', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( TediousInstrumentation.COMPONENT, diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts index b82192ce82..c2cdb5f20e 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts @@ -88,7 +88,7 @@ export class AwsInstrumentation extends InstrumentationBase { this._config = Object.assign({}, config); } - protected init(): InstrumentationModuleDefinition[] { + init(): InstrumentationModuleDefinition[] { const v3MiddlewareStackFileOldVersions = new InstrumentationNodeModuleFile( '@aws-sdk/middleware-stack/dist/cjs/MiddlewareStack.js', ['>=3.1.0 <3.35.0'], diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts index 0a3a8102a7..ae474ee37e 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts @@ -32,7 +32,7 @@ export class BunyanInstrumentation extends InstrumentationBase< super('@opentelemetry/instrumentation-bunyan', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( 'bunyan', diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts index fe2f9718e5..3e09445247 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts @@ -47,7 +47,7 @@ export class CassandraDriverInstrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-cassandra-driver', VERSION, config); } - protected init() { + init() { return new InstrumentationNodeModuleDefinition( 'cassandra-driver', supportedVersions, diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts index 217744e3da..8548525108 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts @@ -82,7 +82,7 @@ export class GraphQLInstrumentation extends InstrumentationBase { this._config = Object.assign({}, DEFAULT_CONFIG, config); } - protected init() { + init() { const module = new InstrumentationNodeModuleDefinition( 'graphql', supportedVersions diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts index 9644497626..f9e44bf955 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts @@ -14,46 +14,47 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; -import { getRPCMetadata, RPCType } from '@opentelemetry/core'; -import { - InstrumentationBase, - InstrumentationConfig, - InstrumentationNodeModuleDefinition, - isWrapped, -} from '@opentelemetry/instrumentation'; - // types for @hapi/hapi are published under @types/hapi__hapi import type * as Hapi from 'hapi__hapi'; -import { VERSION } from './version'; +import * as api from '@opentelemetry/api'; + import { HapiComponentName, + HapiPluginInput, HapiServerRouteInput, - handlerPatched, - PatchableServerRoute, HapiServerRouteInputMethod, - HapiPluginInput, - RegisterFunction, PatchableExtMethod, + PatchableServerRoute, + RegisterFunction, ServerExtDirectInput, + handlerPatched, } from './internal-types'; import { - getRouteMetadata, - getPluginName, - isLifecycleExtType, - isLifecycleExtEventObj, + InstrumentationBase, + InstrumentationConfig, + InstrumentationNodeModuleDefinition, + isWrapped, +} from '@opentelemetry/instrumentation'; +import { RPCType, getRPCMetadata } from '@opentelemetry/core'; +import { getExtMetadata, + getPluginName, + getRouteMetadata, isDirectExtInput, + isLifecycleExtEventObj, + isLifecycleExtType, isPatchableExtMethod, } from './utils'; +import { VERSION } from './version'; + /** Hapi instrumentation for OpenTelemetry */ export class HapiInstrumentation extends InstrumentationBase { constructor(config?: InstrumentationConfig) { super('@opentelemetry/instrumentation-hapi', VERSION, config); } - protected init() { + init() { return new InstrumentationNodeModuleDefinition( HapiComponentName, ['>=17 <21'], diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts index 843639241e..a973f5da00 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts @@ -51,7 +51,7 @@ export class KoaInstrumentation extends InstrumentationBase { return this._config as KoaInstrumentationConfig; } - protected init() { + init() { return new InstrumentationNodeModuleDefinition( 'koa', ['^2.0.0'], diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 8ef20b9e2b..49f7abd71b 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -79,7 +79,7 @@ export class MySQLInstrumentation extends InstrumentationBase< ); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( 'mysql', diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts index ea792f8025..ab9552b0fc 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts @@ -15,26 +15,28 @@ */ import * as api from '@opentelemetry/api'; +import type * as mysqlTypes from 'mysql2'; + +import { + DbSystemValues, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; -import { - DbSystemValues, - SemanticAttributes, -} from '@opentelemetry/semantic-conventions'; -import { addSqlCommenterComment } from '@opentelemetry/sql-common'; -import type * as mysqlTypes from 'mysql2'; -import { MySQL2InstrumentationConfig } from './types'; import { getConnectionAttributes, getDbStatement, getSpanName, once, } from './utils'; + +import { MySQL2InstrumentationConfig } from './types'; import { VERSION } from './version'; +import { addSqlCommenterComment } from '@opentelemetry/sql-common'; type formatType = typeof mysqlTypes.format; @@ -47,7 +49,7 @@ export class MySQL2Instrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-mysql2', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( 'mysql2', diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index 1fa8f58d3d..e344f23691 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -61,7 +61,7 @@ export class PgInstrumentation extends InstrumentationBase { ); } - protected init() { + init() { const modulePG = new InstrumentationNodeModuleDefinition( 'pg', ['8.*'], diff --git a/plugins/node/opentelemetry-instrumentation-pino/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pino/src/instrumentation.ts index c930c2fa99..5c090cc60e 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pino/src/instrumentation.ts @@ -36,7 +36,7 @@ export class PinoInstrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-pino', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( 'pino', diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts index 3ac531847f..3e6e70a5f3 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts @@ -62,7 +62,7 @@ export class RedisInstrumentation extends InstrumentationBase { this._config = Object.assign({}, DEFAULT_CONFIG, config); } - protected init() { + init() { // @node-redis/client is a new package introduced and consumed by 'redis 4.0.x' // on redis@4.1.0 it was changed to @redis/client. // we will instrument both packages diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts index 819daa3398..3a960f4840 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts @@ -43,7 +43,7 @@ export class RedisInstrumentation extends InstrumentationBase { this._config = Object.assign({}, DEFAULT_CONFIG, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition( 'redis', diff --git a/plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts index 6b4c8dbaa8..3a3882b596 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts @@ -45,7 +45,7 @@ export class WinstonInstrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-winston', VERSION, config); } - protected init() { + init() { return [ new InstrumentationNodeModuleDefinition<{}>( 'winston',