diff --git a/archive/opentelemetry-browser-extension-autoinjection/.eslintrc.js b/archive/opentelemetry-browser-extension-autoinjection/.eslintrc.js deleted file mode 100644 index 0d90aec2bb..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "commonjs": true, - "browser": true, - "jquery": true - }, - "ignorePatterns": [ - ".eslintrc.js", - "build/*", - "ts-build/*" - ], - plugins: [ - "@typescript-eslint", - "json5", - "header" - ], - ...require('../../eslint.config.js') -}; diff --git a/archive/opentelemetry-browser-extension-autoinjection/.gitignore b/archive/opentelemetry-browser-extension-autoinjection/.gitignore deleted file mode 100644 index 41f3dc1005..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ts-build diff --git a/archive/opentelemetry-browser-extension-autoinjection/CHANGELOG.md b/archive/opentelemetry-browser-extension-autoinjection/CHANGELOG.md deleted file mode 100644 index 7d9ef92e37..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/CHANGELOG.md +++ /dev/null @@ -1,101 +0,0 @@ -# Changelog - -## [0.29.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.28.0...browser-extension-autoinjection-v0.29.0) (2022-06-08) - - -### Features - -* update core dependencies stable ^1.3.1 experimental ^0.29.2 ([141b155](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/141b155e344980b51264e26b26c117b2113bcef6)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @opentelemetry/instrumentation-document-load bumped from ^0.28.0 to ^0.29.0 - -## [0.28.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.27.4...browser-extension-autoinjection-v0.28.0) (2022-05-14) - - -### Features - -* add supported node versions for all packages ([#973](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/973)) ([baaacbd](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/baaacbdd35ca4baab0afae64647aa8c0380ee4b7)) -* remove colors dependency ([#943](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/943)) ([b21b96c](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/b21b96c1a3a4f871370f970d6b2825f00e1fe595)), closes [#826](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/826) -* use Otel SDK 1.2/0.28 ([#984](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/984)) ([098c2ed](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/098c2ed6f9c5ab7bd865685018c0777245aab3b7)) - - -### Bug Fixes - -* remove link to browser extension to external repo. ([#979](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/979)) ([c5b9356](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/c5b9356d4eb925df64b66c859d1d8367ae57d437)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @opentelemetry/instrumentation-document-load bumped from 0.27.1 to ^0.28.0 - -### [0.27.4](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.27.3...browser-extension-autoinjection-v0.27.4) (2022-03-02) - - -### Bug Fixes - -* **browser-extension-autoinjection:** update eslint-plugin-json5 version to 0.1.4 ([#896](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/896)) ([e47fcaa](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e47fcaa1a04de35b096f373f44abbf87ff4125f2)) - -### [0.27.3](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.27.2...browser-extension-autoinjection-v0.27.3) (2022-02-06) - - -### Bug Fixes - -* update eslint-plugin-import to resolve conflicts ([#864](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/864)) ([45efaee](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/45efaeec1da51398e44857dc9fe7ab3ef9456983)) - -### [0.27.2](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.27.1...browser-extension-autoinjection-v0.27.2) (2022-01-24) - - -### Bug Fixes - -* fix CI by forcing colors@1.4.0 ([#825](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/825)) ([0ec9f08](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/0ec9f080520fe0f146a915a656300ef53a151ace)) -* rename lerna's --include-filtered-dependencies option ([#817](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/817)) ([cf268e7](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/cf268e7a92b7800ad6dbec9ca77466f9ee03ee1a)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @opentelemetry/instrumentation-document-load bumped from 0.27.0 to ^0.27.1 - -### [0.27.1](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.27.0...browser-extension-autoinjection-v0.27.1) (2021-12-22) - - -### Bug Fixes - -* fastify and browser autoinjection failed to compile ([#793](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/793)) ([c08efa8](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/c08efa82a38d3d5b4d0c51d712a39052317b9f74)) - -## [0.27.0](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.26.0...browser-extension-autoinjection-v0.27.0) (2021-11-30) - - -### Features - -* use latest instrumentation base ([#769](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/769)) ([7aff23e](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/7aff23ebebbe209fa3b78c2e7f513c9cd2231be4)) - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @opentelemetry/instrumentation-document-load bumped from ^0.26.0 to ^0.27.0 - -## [0.26.0](https://www.github.com/open-telemetry/opentelemetry-js-contrib/compare/browser-extension-autoinjection-v0.25.0...browser-extension-autoinjection-v0.26.0) (2021-10-22) - - -### Features - -* support API and SDK 1.0 ([#706](https://www.github.com/open-telemetry/opentelemetry-js-contrib/issues/706)) ([096b694](https://www.github.com/open-telemetry/opentelemetry-js-contrib/commit/096b694bbc3079f0ab4ee0462869b10eb8185202)) - - - -### Dependencies - -* The following workspace dependencies were updated - * dependencies - * @opentelemetry/instrumentation-document-load bumped from ^0.25.0 to ^0.26.0 diff --git a/archive/opentelemetry-browser-extension-autoinjection/LICENSE b/archive/opentelemetry-browser-extension-autoinjection/LICENSE deleted file mode 100644 index f49a4e16e6..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/archive/opentelemetry-browser-extension-autoinjection/README.md b/archive/opentelemetry-browser-extension-autoinjection/README.md index 9e3747a868..be37d351b9 100644 --- a/archive/opentelemetry-browser-extension-autoinjection/README.md +++ b/archive/opentelemetry-browser-extension-autoinjection/README.md @@ -1,8 +1,11 @@ # OpenTelemetry Browser Extension -## :warning: ARCHIVED PROJECT - -> This project has been archived by the maintainers permanently on June 19 2024. +> [!CAUTION] +> +> This project is unmaintained and has been archived by the maintainers +> permanently on June 19 2024. It has not been updated for some time and no +> longer works properly with the latest SDK. +> > We encourage extensions to be developed and maintained outside this repository. > Alternatives can be found in the OpenTelemetry Registry: > @@ -11,58 +14,7 @@ > If you are a developer of such an extension you can > [add it to the registry](https://opentelemetry.io/ecosystem/registry/adding/) > as well. +> +> For reference, the archived code [can be found here][archived-code]. -This browser extension allows you to inject [OpenTelemetry](https://opentelemetry.io/) instrumentation in any web page. It uses the [Web SDK](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-web) and can export data to Zipkin or an OpenTelemetry Collector. - -Compatible with OpenTelemetry JS API and SDK `1.0+`. - -![This animated image shows the process of activating the extension and seeing console output in the developer toolbar](./images/inject-opentelemetry.gif) - -## Supported Environments - -- Google Chrome (with [Manifest Version 3](https://developer.chrome.com/docs/extensions/mv3/intro/) support) -- Chromium (with Manifest Version 2) -- Firefox (*unstable*, with Manifest Version 2) - -## Installation - -### from Source - -Run the following in your shell to download and build the extension from source: - -```shell -git clone https://github.com/open-telemetry/opentelemetry-js-contrib.git -cd opentelemetry-js-contrib/packages/opentelemetry-browser-extension-autoinjection -npm install -npm run build -``` - -This will create a so-called unpacked extension into the `build/` folder you now can load into your browser: - -- Open a new browser window and go to chrome://extensions -- Turn on "Developer Mode" -- Click on "Load unpacked" and select the `build/mv3` (or `build/mv2`) folder, which contains the extension - -If all goes well you should see the extension listed: - -![This image shows the extension being installed in chrome://extensions](./images/extensionCard.png) - -## Usage - -When visiting a website, click on the extension icon, add an url filter that partially matches the current domain, e.g for [https://opentelemetry.io/](https://opentelemetry.io/) you can set "opentel" as value: - -![This image shows an open extension popup with url filter set to "opentel"](./images/popup.png) - -Click on `Save & Reload`, check the developer toolbar to see how spans being are printed to the console and being sent to your collector: - -![This image shows spans being printed into the console of the developer toolbar for opentelemetry.io](./images/console.png) - -## Known Limitations - -1. The extension works with [active tab](https://developer.chrome.com/docs/extensions/mv3/manifest/activeTab/) permission, this means that every time you want to use it, you have to click the extension icon at least once for your tab. - -2. The use of the zone context manager and the used instrumentation libraries are fixed. - -3. Firefox support is unstable, sometimes it works, sometimes not. If you have experience building extensions for firefox, please reach out. - -4. The website you are targeting with this extension might have a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) (CSP) in place and block the extension from injecting javascript or block the exporters from sending spans to a collector. To work around this limitation, you need another browser extension, that allows you to disable CSP for a website. +[archived-code]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/688a92d14aa1bdb67de273205d76c2c6e21f6276/archive/opentelemetry-browser-extension-autoinjection diff --git a/archive/opentelemetry-browser-extension-autoinjection/images/console.png b/archive/opentelemetry-browser-extension-autoinjection/images/console.png deleted file mode 100644 index e19c8cbf4e..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/images/console.png and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/images/extensionCard.png b/archive/opentelemetry-browser-extension-autoinjection/images/extensionCard.png deleted file mode 100644 index c732afd8e2..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/images/extensionCard.png and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/images/inject-opentelemetry.gif b/archive/opentelemetry-browser-extension-autoinjection/images/inject-opentelemetry.gif deleted file mode 100644 index 7ecc11152b..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/images/inject-opentelemetry.gif and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/images/options.png b/archive/opentelemetry-browser-extension-autoinjection/images/options.png deleted file mode 100644 index e9e364c4d4..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/images/options.png and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/images/popup.png b/archive/opentelemetry-browser-extension-autoinjection/images/popup.png deleted file mode 100644 index 52b7323fcf..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/images/popup.png and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/package.json b/archive/opentelemetry-browser-extension-autoinjection/package.json deleted file mode 100644 index f0b7187c34..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/package.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "name": "@opentelemetry/browser-extension-autoinjection", - "version": "0.29.0", - "description": "A browser extension that injects opentelemetry tracers into any website", - "scripts": { - "clean": "rimraf build/*", - "compile": "tsc --build tsconfig.json", - "build": "npx webpack --mode=production", - "build:mv2": "npx webpack --mode=production --env MV=2", - "build:mv3": "npx webpack --mode=production --env MV=3", - "lint": "eslint .", - "lint:fix": "eslint . --fix", - "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/browser-extension-autoinjection --include-dependencies", - "prewatch": "npm run precompile", - "test": "nyc mocha 'test/**/*.test.ts'", - "tdd": "npm run test -- --watch-extensions ts --watch", - "watch": "npx webpack --mode=development --watch", - "watch:mv2": "npx webpack --mode=development --watch --env MV=2", - "watch:mv3": "npx webpack --mode=development --watch --env MV=3" - }, - "private": true, - "keywords": [], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": "^1.3.0" - }, - "devDependencies": { - "@opentelemetry/api": "^1.3.0", - "@types/chrome": "0.0.154", - "@types/jsdom": "16.2.13", - "@types/mocha": "8.2.3", - "@types/react": "17.0.16", - "@types/react-dom": "18.0.2", - "@types/sinon": "10.0.2", - "@types/sinon-chrome": "2.2.11", - "@typescript-eslint/eslint-plugin": "5.8.1", - "@typescript-eslint/parser": "5.8.1", - "eslint": "8.7.0", - "eslint-config-airbnb-base": "15.0.0", - "eslint-plugin-header": "3.1.1", - "eslint-plugin-import": "2.25.4", - "eslint-plugin-json5": "0.1.4", - "html-webpack-plugin": "5.3.2", - "jimp": "0.16.1", - "jsdom": "15.2.1", - "null-loader": "4.0.1", - "nyc": "15.1.0", - "responsive-loader": "2.3.0", - "rimraf": "4.2.0", - "sinon": "15.0.1", - "sinon-chrome": "3.0.1", - "ts-loader": "9.2.5", - "typescript": "4.4.4", - "webpack": "4.46.0", - "webpack-cli": "4.7.2", - "webpack-merge": "5.8.0" - }, - "dependencies": { - "@material-ui/core": "4.12.3", - "@material-ui/icons": "4.11.2", - "@material-ui/lab": "4.0.0-alpha.60", - "@opentelemetry/context-zone": "^1.0.0", - "@opentelemetry/core": "^1.8.0", - "@opentelemetry/exporter-trace-otlp-http": "^0.34.0", - "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.35.1", - "@opentelemetry/instrumentation-document-load": "^0.29.0", - "@opentelemetry/instrumentation-fetch": "^0.35.1", - "@opentelemetry/instrumentation-xml-http-request": "^0.35.1", - "@opentelemetry/resources": "^1.8.0", - "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/sdk-trace-web": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.27.0", - "change-case": "4.1.2", - "json5": "2.2.0", - "react": "17.0.2", - "react-dom": "17.0.2" - }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-browser-extension-autoinjection#readme" -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/background/ProgrammaticContentScriptInjector.ts b/archive/opentelemetry-browser-extension-autoinjection/src/background/ProgrammaticContentScriptInjector.ts deleted file mode 100644 index b85790bedf..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/background/ProgrammaticContentScriptInjector.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { TabStatus, CONTENT_SCRIPT_NAME } from '../types'; - -export class ProgrammaticContentScriptInjector { - scope: typeof chrome; - - constructor(scope: typeof chrome) { - this.scope = scope; - } - - injectContentScript(tabId: number) { - this.scope.tabs.get(tabId, (tab: chrome.tabs.Tab) => { - if (tab.url) { - if (this.scope.scripting) { - this.scope.scripting.executeScript({ - target: { - allFrames: true, - tabId, - }, - files: [CONTENT_SCRIPT_NAME], - }); - } else { - this.scope.tabs.executeScript(tabId, { - file: CONTENT_SCRIPT_NAME, - allFrames: true, - }); - } - } - }); - } - - register() { - this.scope.tabs.onUpdated.addListener( - (tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => { - if (changeInfo.status === TabStatus.LOADING) { - this.injectContentScript(tabId); - } - } - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/background/index.ts b/archive/opentelemetry-browser-extension-autoinjection/src/background/index.ts deleted file mode 100644 index 903e14e134..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/background/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// the following two 'require' are here for webpack. -require('../manifest.json5'); -require('../icons/otel-logo.png'); - -import { ProgrammaticContentScriptInjector } from './ProgrammaticContentScriptInjector'; - -// An error thrown in the background service worker will not be reported in the logs, it's caught here and printed. (MV3 only) -try { - new ProgrammaticContentScriptInjector(chrome).register(); -} catch (e) { - console.error(e); -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/InstrumentationInjector.ts b/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/InstrumentationInjector.ts deleted file mode 100644 index 5c4369f21a..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/InstrumentationInjector.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - DomAttributes, - DomElements, - INSTRUMENTATION_SCRIPT_NAME, - Settings, -} from '../types'; - -export class InstrumentationInjector { - scope: typeof chrome; - doc: Document; - logger: Console; - - constructor(scope: typeof chrome, doc: Document, logger: Console) { - this.scope = scope; - this.doc = doc; - this.logger = logger; - } - - inject(settings: Settings) { - const script = this.scope.runtime.getURL(INSTRUMENTATION_SCRIPT_NAME); - this.logger.log( - `[otel-extension] injecting ${INSTRUMENTATION_SCRIPT_NAME}` - ); - const tag = this.doc.createElement('script'); - tag.setAttribute('src', script); - tag.setAttribute('id', DomElements.CONFIG_TAG); - // Config is based via this data attribute, since CSP might not allow inline script tags, so this is more robust. - tag.setAttribute(`data-${DomAttributes.CONFIG}`, JSON.stringify(settings)); - this.doc.head.appendChild(tag); - this.logger.log(`[otel-extension] ${INSTRUMENTATION_SCRIPT_NAME} injected`); - } - - static checkUrlFilter(urlFilter: string, href: string) { - return urlFilter !== '' && (urlFilter === '*' || href.includes(urlFilter)); - } - - execute() { - this.scope.storage.local.get('settings', ({ settings }) => { - // Define label of badge. - const urlFilter = settings.urlFilter; - if ( - InstrumentationInjector.checkUrlFilter( - urlFilter, - this.doc.location.href - ) - ) { - this.logger.log( - `[otel-extension] ${this.doc.location.href} includes ${urlFilter}` - ); - this.inject(settings); - } else { - this.logger.log( - `[otel-extension] ${this.doc.location.href} does not include ${urlFilter}` - ); - } - }); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/index.ts b/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/index.ts deleted file mode 100644 index 90da8a7760..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/contentScript/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { InstrumentationInjector } from './InstrumentationInjector'; - -new InstrumentationInjector(chrome, document, console).execute(); diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/icons/otel-logo.png b/archive/opentelemetry-browser-extension-autoinjection/src/icons/otel-logo.png deleted file mode 100644 index 1e9deec244..0000000000 Binary files a/archive/opentelemetry-browser-extension-autoinjection/src/icons/otel-logo.png and /dev/null differ diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts b/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts deleted file mode 100644 index d467460e7d..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load'; -import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch'; -import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request'; -import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; -import { ZoneContextManager } from '@opentelemetry/context-zone'; -import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; -import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; -import { - BatchSpanProcessor, - ConsoleSpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/sdk-trace-base'; -import { - Exporters, - ExporterType, - InstrumentationConfiguration, - InstrumentationType, -} from '../types'; - -export class WebInstrumentation { - withZoneContextManager: boolean; - provider: WebTracerProvider; - exporters: Exporters; - instrumentations: { - [InstrumentationType.DOCUMENT_LOAD]: { enabled: boolean }; - [InstrumentationType.FETCH]: { enabled: boolean }; - [InstrumentationType.XML_HTTP_REQUEST]: { enabled: boolean }; - }; - constructor( - config: InstrumentationConfiguration, - provider: WebTracerProvider - ) { - this.exporters = config.exporters; - this.instrumentations = config.instrumentations; - this.provider = provider; - this.withZoneContextManager = config.withZoneContextManager; - } - - addExporters() { - if (this.exporters[ExporterType.CONSOLE].enabled) { - this.provider.addSpanProcessor( - new SimpleSpanProcessor(new ConsoleSpanExporter()) - ); - } - - if (this.exporters[ExporterType.ZIPKIN].enabled) { - this.provider.addSpanProcessor( - new BatchSpanProcessor( - new ZipkinExporter({ - url: this.exporters[ExporterType.ZIPKIN].url, - }) - ) - ); - } - - if (this.exporters[ExporterType.COLLECTOR_TRACE].enabled) { - this.provider.addSpanProcessor( - new BatchSpanProcessor( - new OTLPTraceExporter({ - url: this.exporters[ExporterType.COLLECTOR_TRACE].url, - }) - ) - ); - } - } - - registerInstrumentations() { - const instrumentations = []; - - if (this.instrumentations[InstrumentationType.DOCUMENT_LOAD].enabled) { - instrumentations.push(new DocumentLoadInstrumentation()); - } - - if (this.instrumentations[InstrumentationType.FETCH].enabled) { - instrumentations.push(new FetchInstrumentation()); - } - - if (this.instrumentations[InstrumentationType.XML_HTTP_REQUEST].enabled) { - instrumentations.push(new XMLHttpRequestInstrumentation()); - } - - registerInstrumentations({ - instrumentations, - tracerProvider: this.provider, - }); - } - - register() { - this.addExporters(); - - if (this.withZoneContextManager) { - this.provider.register({ - contextManager: new ZoneContextManager(), - }); - } - - this.registerInstrumentations(); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/index.ts b/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/index.ts deleted file mode 100644 index 2ae22adf05..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/instrumentation/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; -import { - DomAttributes, - DomElements, - InstrumentationType, - Settings, -} from '../types'; -import { WebInstrumentation } from './WebInstrumentation'; -import { Resource } from '@opentelemetry/resources'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; - -const configTag = document.getElementById(DomElements['CONFIG_TAG']); -const { exporters }: Settings = configTag - ? JSON.parse(String(configTag.dataset[DomAttributes['CONFIG']])) - : {}; - -new WebInstrumentation( - { - exporters, - instrumentations: { - [InstrumentationType.DOCUMENT_LOAD]: { - enabled: true, - }, - [InstrumentationType.FETCH]: { - enabled: true, - }, - [InstrumentationType.XML_HTTP_REQUEST]: { - enabled: true, - }, - }, - withZoneContextManager: true, - }, - new WebTracerProvider({ - resource: new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: window.location.hostname, - }), - }) -).register(); diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/manifest.json5 b/archive/opentelemetry-browser-extension-autoinjection/src/manifest.json5 deleted file mode 100644 index 48b89d5249..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/manifest.json5 +++ /dev/null @@ -1,23 +0,0 @@ -{ - "permissions": [ - "activeTab", - "scripting", - "webNavigation", - "storage" - ], - "action": { - "default_popup": "popup.html" - }, - "icons": "icons/otel-logo_{size}.png", - "background": "background.js", - "options_ui": { - "page": "options.html", - "open_in_tab": true, - }, - "web_accessible_resources": [ - "instrumentation.js" - ], - "host_permissions": [ - '' - ] -} \ No newline at end of file diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/template.html b/archive/opentelemetry-browser-extension-autoinjection/src/template.html deleted file mode 100644 index 37e14402dd..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/template.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - OpenTelemetry Browser Extension - - -
-
- - - diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/types.ts b/archive/opentelemetry-browser-extension-autoinjection/src/types.ts deleted file mode 100644 index dcd8f1cb01..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/types.ts +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { styles } from './ui/styles'; -import { WithStyles } from '@material-ui/core'; - -export interface Exporters { - [ExporterType.CONSOLE]: { - enabled: boolean; - }; - [ExporterType.ZIPKIN]: { - enabled: boolean; - url: string; - }; - [ExporterType.COLLECTOR_TRACE]: { - enabled: boolean; - url: string; - }; -} - -export interface InstrumentationConfiguration { - exporters: Exporters; - instrumentations: { - [InstrumentationType.DOCUMENT_LOAD]: { - enabled: boolean; - }; - [InstrumentationType.FETCH]: { - enabled: boolean; - }; - [InstrumentationType.XML_HTTP_REQUEST]: { - enabled: boolean; - }; - }; - withZoneContextManager: boolean; -} - -export interface Settings { - urlFilter: string; - exporters: Exporters; -} - -export class Storage { - settings: Settings; - isPermissionAlertDismissed: boolean; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(storage: { [key: string]: any }) { - this.settings = storage.settings; - this.isPermissionAlertDismissed = storage.isPermissionAlertDismissed; - } -} - -export interface PermissionManagerProps { - permissions: chrome.permissions.Permissions; - onTogglePermissions: (currentValue: boolean) => void; - removingPermissionsFailed: boolean; -} - -export interface PermissionAlertProps { - permissions: chrome.permissions.Permissions; - dismissed: boolean; - onDismiss: () => void; - onGrantPermission: () => void; -} - -export interface ExporterOptionProps { - for: ExporterType; - isEnabled: boolean; - onToggle: (exporter: ExporterType) => void; - onValueChange?: ( - name: ExporterType.ZIPKIN | ExporterType.COLLECTOR_TRACE, - newValue: string - ) => void; - exporterPackageUrl: string; - placeholderValue?: PlaceholderValues; - value?: string; -} - -export interface SaveButtonProps { - label: Labels; - onClick: () => void; -} - -export interface AppProps extends WithStyles { - permissions: chrome.permissions.Permissions; - settings: Settings; - isPermissionAlertDismissed: boolean; - app: AppType; - activeTab: chrome.tabs.Tab | undefined; -} - -export interface AppState { - settings: Settings; - permissions: chrome.permissions.Permissions; - isPermissionAlertDismissed: boolean; - removingPermissionsFailed: boolean; -} - -export enum AppType { - OPTIONS = 'options', - POPUP = 'popup', -} - -export enum ExporterType { - CONSOLE = 'Console', - ZIPKIN = 'Zipkin', - COLLECTOR_TRACE = 'CollectorTrace', -} - -export enum InstrumentationType { - DOCUMENT_LOAD = 'DocumentLoad', - FETCH = 'Fetch', - XML_HTTP_REQUEST = 'XMLHttpRequest', -} - -export enum DomElements { - CONFIG_TAG = 'open-telemetry-instrumentation', -} - -export enum DomAttributes { - CONFIG = 'config', -} - -export enum PlaceholderValues { - ZIPKIN_URL = 'http://localhost:9411/api/v2/spans', - COLLECTOR_TRACE_URL = 'http://localhost:4318/v1/trace', -} - -export enum Labels { - SAVE = 'Save', - SAVE_AND_RELOAD = 'Save & Reload', -} - -export enum TabStatus { - UNLOADED = 'unloaded', - LOADING = 'loading', - COMPLETE = 'complete', -} - -export const CONTENT_SCRIPT_NAME = 'contentScript.js'; -export const INSTRUMENTATION_SCRIPT_NAME = 'instrumentation.js'; diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/App.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/App.tsx deleted file mode 100644 index 7d214fe73f..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/App.tsx +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import * as React from 'react'; -import { - AppType, - ExporterType, - Labels, - AppProps as AppProps, - AppState as AppState, - PlaceholderValues, -} from '../types'; -import { - AppBar, - CssBaseline, - Paper, - Toolbar, - Typography, - Grid, - TextField, -} from '@material-ui/core'; -import { ExporterOption } from './ExporterOption'; -import { capitalCase } from 'change-case'; -import { SaveButton } from './SaveButton'; -import { OpenOptionsPage } from './OpenOptionsPage'; -import { PermissionManager } from './PermissionManager'; -import { PermissionAlert } from './PermissionAlert'; -const packageJson = require('../../package.json'); - -export class App extends React.Component { - permissionsUpdated: () => void; - constructor(props: AppProps) { - super(props); - - this.state = { - settings: props.settings, - permissions: props.permissions, - isPermissionAlertDismissed: props.isPermissionAlertDismissed, - removingPermissionsFailed: false, - }; - - this.handleFilterChange = this.handleFilterChange.bind(this); - this.handleSaveSettings = this.handleSaveSettings.bind(this); - this.handleUrlChange = this.handleUrlChange.bind(this); - this.toggleExporter = this.toggleExporter.bind(this); - this.onTogglePermissions = this.onTogglePermissions.bind(this); - this.dismissPermissionAlert = this.dismissPermissionAlert.bind(this); - - this.permissionsUpdated = () => { - chrome.permissions.getAll(permissions => { - this.setState({ permissions }); - }); - }; - } - - override componentDidMount() { - if (chrome.permissions.onAdded) { - chrome.permissions.onAdded.addListener(this.permissionsUpdated); - chrome.permissions.onRemoved.addListener(this.permissionsUpdated); - } - } - - handleFilterChange(event: React.ChangeEvent) { - this.setState(state => { - state.settings.urlFilter = event.target.value; - return state; - }); - } - - handleUrlChange( - name: ExporterType.ZIPKIN | ExporterType.COLLECTOR_TRACE, - value: string - ) { - this.setState(state => { - state.settings.exporters[name].url = value; - return state; - }); - } - - toggleExporter(name: ExporterType) { - this.setState(state => { - state.settings.exporters[name].enabled = - !state.settings.exporters[name].enabled; - return state; - }); - } - - async handleSaveSettings() { - chrome.storage.local.set( - { - settings: this.state.settings, - }, - async () => { - if (this.props.activeTab) { - const tabId = Number(this.props.activeTab.id); - if (chrome.scripting) { - chrome.scripting.executeScript({ - target: { - tabId, - }, - func: () => { - window.location.reload(); - }, - }); - } else { - chrome.tabs.executeScript(tabId, { - code: 'window.location.reload();', - }); - } - } - } - ); - } - - onTogglePermissions(currentValue: boolean) { - if (currentValue) { - chrome.permissions.remove( - { - origins: ['http://*/*', 'https://*/*'], - }, - () => { - if (chrome.runtime.lastError) { - this.setState({ - removingPermissionsFailed: true, - }); - } - } - ); - } else { - chrome.permissions.request({ - origins: ['http://*/*', 'https://*/*'], - }); - } - } - - dismissPermissionAlert() { - this.setState( - { - isPermissionAlertDismissed: true, - }, - () => { - chrome.storage.local.set({ - isPermissionAlertDismissed: this.state.isPermissionAlertDismissed, - }); - } - ); - } - - override render() { - const { urlFilter, exporters } = this.state.settings; - - const classes = this.props.classes; - - const saveLabel = - this.props.app === AppType.POPUP ? Labels.SAVE_AND_RELOAD : Labels.SAVE; - - return ( - - - - - {this.props.app === AppType.OPTIONS ? ( - - {capitalCase(packageJson.name)} ({packageJson.version}) - - ) : ( - - - - - - )} - - -
- this.onTogglePermissions(false)} - /> - - - Injection Settings - - - - - - - - - - Exporter Settings - - - - - - - - - - Manage Permissions - - - - - - - - - - -
-
- ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/ExporterOption.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/ExporterOption.tsx deleted file mode 100644 index 9b8543c9fb..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/ExporterOption.tsx +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { - FormControlLabel, - FormGroup, - FormHelperText, - Grid, - Link, - Switch, - TextField, -} from '@material-ui/core'; -import * as React from 'react'; -import { ExporterOptionProps, ExporterType } from '../types'; - -export class ExporterOption extends React.Component { - override render() { - return ( - - - - this.props.onToggle(this.props.for)} - > - } - label={this.props.for} - /> - - Toggle to enable{' '} - - {this.props.for}Exporter - - - - - {this.props.value !== undefined ? ( - - - this.props.onValueChange - ? this.props.onValueChange( - this.props.for as - | ExporterType.ZIPKIN - | ExporterType.COLLECTOR_TRACE, - event.target.value - ) - : () => {} - } - /> - - ) : ( - '' - )} - - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/OpenOptionsPage.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/OpenOptionsPage.tsx deleted file mode 100644 index 8ba31e7a0e..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/OpenOptionsPage.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Link } from '@material-ui/core'; -import { Launch } from '@material-ui/icons'; -import * as React from 'react'; - -export class OpenOptionsPage extends React.Component { - constructor(props: {}) { - super(props); - this.openOptionsPage = this.openOptionsPage.bind(this); - } - - openOptionsPage(event: React.MouseEvent) { - event.preventDefault(); - if (chrome.runtime.openOptionsPage) { - chrome.runtime.openOptionsPage(); - } else { - window.open(chrome.runtime.getURL('options.html')); - } - } - - override render() { - return ( - - - - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionAlert.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionAlert.tsx deleted file mode 100644 index 5a9d46b1c4..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionAlert.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as React from 'react'; -import { PermissionAlertProps } from '../types'; -import { Alert } from '@material-ui/lab'; -import { Link } from '@material-ui/core'; - -export class PermissionAlert extends React.Component { - override render() { - const origins = this.props.permissions.origins ?? []; - - const accessToAllUrlsGranted = - origins.includes('') || - (origins.includes('http://*/*') && origins.includes('https://*/*')); - - if (this.props.dismissed || accessToAllUrlsGranted) { - return ''; - } - return ( - - Without the permission to access all websites, you need to click on the - extension icon once every time you open a new tab.{' '} - Click here to grant - access or dismiss this - warning. - - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionManager.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionManager.tsx deleted file mode 100644 index 295c98f7fd..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/PermissionManager.tsx +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - Grid, - FormGroup, - FormControlLabel, - Switch, - FormHelperText, - Link, -} from '@material-ui/core'; -import * as React from 'react'; -import { PermissionManagerProps } from '../types'; -import { Alert } from '@material-ui/lab'; - -export class PermissionManager extends React.Component { - override render() { - const origins = this.props.permissions.origins ?? []; - - const accessToAllUrlsGranted = - origins.includes('') || - (origins.includes('http://*/*') && origins.includes('https://*/*')); - - return ( - - - {this.props.removingPermissionsFailed ? ( - - Permissions can not be revoked. Go to chrome://extensions, open - the details of this extension and revoke them manually. - - ) : ( - '' - )} - - - this.props.onTogglePermissions(accessToAllUrlsGranted) - } - > - } - label="Access all websites" - /> - - Toggle to have injection work immediately on opening a new tab. - Otherwise, you need to click the extension icon once to active it.{' '} - ( - - Learn More - - ) - - - - - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/SaveButton.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/SaveButton.tsx deleted file mode 100644 index 2a3836b9a8..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/SaveButton.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Button } from '@material-ui/core'; -import * as React from 'react'; -import { SaveButtonProps } from '../types'; - -export class SaveButton extends React.Component { - override render() { - return ( - - ); - } -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/index.tsx b/archive/opentelemetry-browser-extension-autoinjection/src/ui/index.tsx deleted file mode 100644 index 2d6ed46554..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/index.tsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import * as React from 'react'; -import * as ReactDOM from 'react-dom'; -import { AppType } from '../types'; -import { styles } from './styles'; -import { withStyles } from '@material-ui/core'; -import { loadFromStorage } from '../utils/storage'; -import { App } from './App'; - -loadFromStorage() - .then(async storage => { - const app = window.location.pathname.startsWith('/options.html') - ? AppType.OPTIONS - : AppType.POPUP; - - let activeTab: chrome.tabs.Tab | undefined; - - if (app === AppType.POPUP) { - const tabs = await new Promise(resolve => { - chrome.tabs.query( - { - active: true, - lastFocusedWindow: true, - }, - result => { - resolve(result); - } - ); - }); - activeTab = tabs[0]; - } - - const permissions = await new Promise( - resolve => { - chrome.permissions.getAll(permissions => resolve(permissions)); - } - ); - - const StyledApp = withStyles(styles)(App); - - ReactDOM.render( - , - document.getElementById('root') - ); - }) - .catch(error => { - // eslint-disable-next-line no-console - console.error(error); - }); diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/ui/styles.ts b/archive/opentelemetry-browser-extension-autoinjection/src/ui/styles.ts deleted file mode 100644 index 9851a9a9e3..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/ui/styles.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { Theme, createStyles } from '@material-ui/core'; - -export const styles = (theme: Theme) => - createStyles({ - appBar: { - position: 'relative', - }, - layout: { - width: 'auto', - marginLeft: theme.spacing(2), - marginRight: theme.spacing(2), - }, - paper: { - marginTop: theme.spacing(3), - marginBottom: theme.spacing(3), - padding: theme.spacing(2), - }, - title: { - flexGrow: 1, - }, - }); diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/utils/manifest-loader.ts b/archive/opentelemetry-browser-extension-autoinjection/src/utils/manifest-loader.ts deleted file mode 100644 index eee7bfb055..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/utils/manifest-loader.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable node/no-extraneous-import */ - -import { capitalCase } from 'change-case'; -import * as json5 from 'json5'; - -// From https://github.com/TypeStrong/ts-loader/blob/main/src/interfaces.ts -interface WebpackLoaderContext { - emitFile(name: string, content: string): void; - getOptions(): { - manifestVersion: number; - }; -} - -interface IconSet { - [key: string]: string; -} - -export default function (this: WebpackLoaderContext, source: string): string { - const p = require('../../package.json'); - const options = this.getOptions(); - - const manifest5 = json5.parse(source); - - const sizes = ['16', '32', '48', '128']; - manifest5.icons = sizes.reduce((result: IconSet, size: string) => { - result[size] = manifest5.icons.replace('{size}', size); - return result; - }, {}); - - manifest5.action['default_icon'] = manifest5.icons; - - const background = - Number(options.manifestVersion) === 3 - ? { - service_worker: manifest5.background, - } - : { - scripts: [manifest5.background], - }; - - const web_accessible_resources = - Number(options.manifestVersion) === 3 - ? [ - { - resources: manifest5.web_accessible_resources, - matches: [''], - }, - ] - : manifest5.web_accessible_resources; - - if (Number(options.manifestVersion) === 2) { - manifest5.permissions = manifest5.permissions.filter( - (permission: string) => permission !== 'scripting' - ); - manifest5.browser_action = Object.assign({}, manifest5.action); - delete manifest5.action; - - manifest5.optional_permissions = Object.values(manifest5.host_permissions); - delete manifest5.host_permissions; - } - - const result = JSON.stringify( - Object.assign(manifest5, { - manifest_version: options.manifestVersion, - version: p.version, - background, - web_accessible_resources, - description: p.description, - name: capitalCase(p.name), - }), - null, - 2 - ); - - this.emitFile('manifest.json', result); - return source; -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/src/utils/storage.ts b/archive/opentelemetry-browser-extension-autoinjection/src/utils/storage.ts deleted file mode 100644 index 20be513eb5..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/src/utils/storage.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ExporterType, Storage } from '../types'; - -export function loadFromStorage(): Promise { - return new Promise(resolve => { - chrome.storage.local.get( - { - isPermissionAlertDismissed: false, - settings: { - urlFilter: '', - exporters: { - [ExporterType.CONSOLE]: { - enabled: true, - }, - [ExporterType.ZIPKIN]: { - enabled: false, - url: '', - }, - [ExporterType.COLLECTOR_TRACE]: { - enabled: false, - url: '', - }, - }, - }, - }, - storage => resolve(new Storage(storage)) - ); - }); -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/test/background.test.ts b/archive/opentelemetry-browser-extension-autoinjection/test/background.test.ts deleted file mode 100644 index 4e5c711ea0..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/test/background.test.ts +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable node/no-unpublished-import */ - -import { ProgrammaticContentScriptInjector } from '../src/background/ProgrammaticContentScriptInjector'; -import * as chromeMock from 'sinon-chrome'; -import * as assert from 'assert'; -import sinon = require('sinon'); - -import { TAB_ID } from './utils'; -import { CONTENT_SCRIPT_NAME, TabStatus } from '../src/types'; - -describe('ProgrammaticContentScriptInjector', () => { - let listener: ProgrammaticContentScriptInjector; - let sandbox: sinon.SinonSandbox; - - before(() => { - sandbox = sinon.createSandbox(); - listener = new ProgrammaticContentScriptInjector( - chromeMock as unknown as typeof chrome - ); - listener.register(); - }); - - afterEach(async () => { - sandbox.restore(); - }); - - it('should subscribe on chrome.tabs.onUpdated', () => { - assert.ok(chromeMock.tabs.onUpdated.addListener.calledOnce); - }); - - it('should only be triggered on tab status "loading"', () => { - const spy = sandbox.spy(listener, 'injectContentScript'); - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.COMPLETE, - }); - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.UNLOADED, - }); - assert.ok(spy.notCalled); - assert.ok(chromeMock.tabs.get.notCalled); - - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.LOADING, - }); - assert.ok(spy.calledOnce, 'injectContentScript not triggered on "loading"'); - assert.ok(chromeMock.tabs.get.calledOnce); - }); - - it('should inject the content script if the url property of a tab is accessible', () => { - chromeMock.tabs.get.reset(); - chromeMock.tabs.get - .onFirstCall() - .callsArgWith(1, { url: undefined } as chrome.tabs.Tab); - chromeMock.tabs.get - .onSecondCall() - .callsArgWith(1, { url: 'http://www.example.com' } as chrome.tabs.Tab); - chromeMock.tabs.get - .onThirdCall() - .callsArgWith(1, { url: 'http://www.example.com' } as chrome.tabs.Tab); - - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.LOADING, - }); - - assert.ok(chromeMock.tabs.executeScript.notCalled); - - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.LOADING, - }); - - assert.ok( - chromeMock.tabs.executeScript.calledOnceWith(TAB_ID, { - file: CONTENT_SCRIPT_NAME, - allFrames: true, - }) - ); - - const chromeMockV3 = chromeMock as typeof chromeMock & { - scripting: { - executeScript: (args: any) => void; - }; - }; - - chromeMockV3.scripting = { - executeScript: args => { - assert.deepStrictEqual(args, { - target: { - allFrames: true, - tabId: TAB_ID, - }, - files: [CONTENT_SCRIPT_NAME], - }); - }, - }; - - chromeMock.tabs.onUpdated.dispatch(TAB_ID, { - status: TabStatus.LOADING, - }); - }); -}); diff --git a/archive/opentelemetry-browser-extension-autoinjection/test/contentScript.test.ts b/archive/opentelemetry-browser-extension-autoinjection/test/contentScript.test.ts deleted file mode 100644 index fd8e842a71..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/test/contentScript.test.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable node/no-unpublished-import */ - -import * as chromeMock from 'sinon-chrome'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; - -import { InstrumentationInjector } from '../src/contentScript/InstrumentationInjector'; -import { JSDOM } from 'jsdom'; -import { - DomAttributes, - DomElements, - INSTRUMENTATION_SCRIPT_NAME, - Settings, -} from '../src/types'; -import { TEST_URL } from './utils'; - -describe('InstrumentationInjector', () => { - let sandbox: sinon.SinonSandbox; - let injector: InstrumentationInjector; - let jsdom: JSDOM; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - jsdom = new JSDOM('', { - url: TEST_URL, - }); - injector = new InstrumentationInjector( - chromeMock as unknown as typeof chrome, - jsdom.window.document, - { - log: () => {}, - } as Console - ); - }); - - afterEach(async () => { - sandbox.restore(); - chromeMock.reset(); - }); - - describe('checkUrlFilter', () => { - it('matches on parts of the URL', () => { - assert.ok( - InstrumentationInjector.checkUrlFilter( - 'example', - 'http://www.example.com' - ) - ); - - assert.ok( - InstrumentationInjector.checkUrlFilter( - 'www.exa', - 'http://www.example.com' - ) - ); - - assert.ok( - !InstrumentationInjector.checkUrlFilter('123', 'http://www.example.com') - ); - }); - - it('accepts "*" as a catch all', () => { - assert.ok( - InstrumentationInjector.checkUrlFilter('*', 'http://www.example.com') - ); - - assert.ok( - InstrumentationInjector.checkUrlFilter( - '*', - 'http://www.opentelemetry.io' - ) - ); - }); - }); - - describe('execute', () => { - it('should load settings from storage', () => { - injector.execute(); - assert.ok(chromeMock.storage.local.get.calledOnceWith('settings')); - }); - - it('should only inject instrumentation if urlFilter matches', () => { - const spy = sandbox.spy(injector, 'inject'); - chromeMock.storage.local.get.onFirstCall().callsArgWith(1, { - settings: { - urlFilter: '123', - }, - }); - chromeMock.storage.local.get.onSecondCall().callsArgWith(1, { - settings: { - urlFilter: 'example', - }, - }); - - injector.execute(); - assert.ok(spy.notCalled); - - injector.execute(); - assert.ok(spy.calledOnce); - }); - }); - - describe('inject', () => { - it('adds a script element to the DOM that loads the instrumentation code', () => { - const scriptName = `chrome-extension://id/${INSTRUMENTATION_SCRIPT_NAME}`; - - chromeMock.runtime.getURL.onFirstCall().returns(scriptName); - - const settings = { exporters: {} }; - injector.inject(settings as Settings); - const configTag = jsdom.window.document.getElementById( - DomElements.CONFIG_TAG - ); - assert.ok(configTag instanceof jsdom.window.HTMLScriptElement); - assert.deepStrictEqual( - settings, - JSON.parse( - String(configTag.getAttribute(`data-${DomAttributes.CONFIG}`)) - ) - ); - assert.ok(configTag.getAttribute('src'), scriptName); - }); - }); -}); diff --git a/archive/opentelemetry-browser-extension-autoinjection/test/instrumentation.test.ts b/archive/opentelemetry-browser-extension-autoinjection/test/instrumentation.test.ts deleted file mode 100644 index 759d3c2589..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/test/instrumentation.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable node/no-unpublished-import */ - -import * as chromeMock from 'sinon-chrome'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import { WebInstrumentation } from '../src/instrumentation/WebInstrumentation'; -import { - ExporterType, - InstrumentationType, - PlaceholderValues, -} from '../src/types'; -import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; -import { JSDOM } from 'jsdom'; -import { TEST_URL } from './utils'; - -describe('WebInstrumentation', () => { - let sandbox: sinon.SinonSandbox; - let provider: WebTracerProvider; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - provider = new WebTracerProvider(); - const { window } = new JSDOM('', { - url: TEST_URL, - }); - - global.window = window as any; - global.XMLHttpRequest = window.XMLHttpRequest; - global.document = window.document; - }); - - afterEach(async () => { - sandbox.restore(); - chromeMock.reset(); - }); - - it('adds exporters to the trace provider', () => { - const addSpanProcessorSpy = sinon.spy(provider, 'addSpanProcessor'); - const instrumentation = new WebInstrumentation( - { - exporters: { - [ExporterType.CONSOLE]: { - enabled: true, - }, - [ExporterType.ZIPKIN]: { - enabled: true, - url: PlaceholderValues.ZIPKIN_URL, - }, - [ExporterType.COLLECTOR_TRACE]: { - enabled: true, - url: PlaceholderValues.COLLECTOR_TRACE_URL, - }, - }, - instrumentations: { - [InstrumentationType.DOCUMENT_LOAD]: { - enabled: true, - }, - [InstrumentationType.FETCH]: { - enabled: false, - }, - [InstrumentationType.XML_HTTP_REQUEST]: { - enabled: true, - }, - }, - withZoneContextManager: true, - }, - provider - ); - instrumentation.register(); - assert.ok(addSpanProcessorSpy.callCount === 3); - }); -}); diff --git a/archive/opentelemetry-browser-extension-autoinjection/test/utils.ts b/archive/opentelemetry-browser-extension-autoinjection/test/utils.ts deleted file mode 100644 index f273cc1b7f..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/test/utils.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const TAB_ID = 13; -export const TEST_URL = 'http://www.example.com'; diff --git a/archive/opentelemetry-browser-extension-autoinjection/tsconfig.json b/archive/opentelemetry-browser-extension-autoinjection/tsconfig.json deleted file mode 100644 index c1e3fae6fe..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "../../tsconfig.base", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "jsx": "react" - }, - "include": [ - "src/**/*.ts", - "src/**/*.tsx", - "test/**/*.ts", - "webpack.config.ts" - ] -} diff --git a/archive/opentelemetry-browser-extension-autoinjection/webpack.config.ts b/archive/opentelemetry-browser-extension-autoinjection/webpack.config.ts deleted file mode 100644 index 53fdc8fa85..0000000000 --- a/archive/opentelemetry-browser-extension-autoinjection/webpack.config.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable node/no-unpublished-import */ - -import * as path from 'path'; -import { mergeWithRules } from 'webpack-merge'; -import * as HtmlWebpackPlugin from 'html-webpack-plugin'; - -// Read the environment variables, and check for the existence of the "MV" variable -// This can be used to only build the one or the other target. -module.exports = (env: { MV?: string; WEBPACK_BUILD: boolean }) => { - // Build the extension for "Manifest Version 2" (Chromium, Firefox & others.) - const baseConfig = { - entry: { - background: './src/background/index.ts', - contentScript: './src/contentScript/index.ts', - instrumentation: './src/instrumentation/index.ts', - ui: './src/ui/index.tsx', - }, - module: { - rules: [ - { - include: [path.resolve(__dirname, 'src/manifest.json5')], - test: /manifest.json5$/, - use: [ - { - loader: 'null-loader', - options: {}, - }, - { - loader: path.resolve('src/utils/manifest-loader.ts'), - options: { - manifestVersion: 2, - }, - }, - ], - }, - { - include: [path.resolve(__dirname, 'src')], - test: /\.tsx?$/, - use: [ - { - loader: 'ts-loader', - options: { - transpileOnly: true, - experimentalWatchApi: true, - }, - }, - ], - }, - { - include: [path.resolve(__dirname, 'src/icons')], - test: /\.(jpe?g|png|webp)$/i, - use: [ - // We are not going to use any of the images for real, throw away all output - { - loader: 'null-loader', - options: {}, - }, - { - loader: 'responsive-loader', - options: { - name: '[name]_[width].[ext]', - outputPath: 'icons/', - sizes: [16, 32, 48, 128], - }, - }, - ], - }, - ], - }, - plugins: [ - new HtmlWebpackPlugin({ - chunks: ['ui'], - inject: 'head', - filename: 'options.html', - template: 'src/template.html', - }), - new HtmlWebpackPlugin({ - chunks: ['ui'], - filename: 'popup.html', - inject: 'head', - template: 'src/template.html', - }), - ], - resolve: { - extensions: ['.tsx', '.ts', '.js'], - }, - }; - - const merge = mergeWithRules({ - module: { - rules: { - test: 'match', - include: 'match', - use: { - loader: 'match', - options: 'replace', - }, - }, - }, - }); - - const targetMV2 = merge(baseConfig, { - output: { - filename: '[name].js', - path: path.resolve(__dirname, 'build/mv2'), - }, - }); - const targetMV3 = merge(baseConfig, { - module: { - rules: [ - { - include: [path.resolve(__dirname, 'src/manifest.json5')], - test: /manifest.json5$/, - use: [ - { - loader: path.resolve('src/utils/manifest-loader.ts'), - options: { - manifestVersion: 3, - }, - }, - ], - }, - ], - }, - output: { - filename: '[name].js', - path: path.resolve(__dirname, 'build/mv3'), - }, - }); - - const exports = []; - - if (env.MV) { - exports.push(Number(env.MV) === 3 ? targetMV3 : targetMV2); - } else { - exports.push(targetMV3); - exports.push(targetMV2); - } - - return exports; -}; diff --git a/examples/connect/tracing.js b/examples/connect/tracing.js index 7639af2925..bbc8994126 100644 --- a/examples/connect/tracing.js +++ b/examples/connect/tracing.js @@ -22,10 +22,14 @@ function log() { } module.exports = (serviceName) => { + const exporter = new CollectorTraceExporter(); const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); const connectInstrumentation = new ConnectInstrumentation(); registerInstrumentations({ @@ -37,10 +41,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new CollectorTraceExporter(); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register({}); return { diff --git a/examples/dns/tracer.js b/examples/dns/tracer.js index a2cee3295c..1dbc49fc73 100644 --- a/examples/dns/tracer.js +++ b/examples/dns/tracer.js @@ -11,8 +11,6 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); - let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ @@ -24,7 +22,11 @@ module.exports = (serviceName) => { }); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/express/src/tracer.ts b/examples/express/src/tracer.ts index b86e92b712..d7122604cc 100644 --- a/examples/express/src/tracer.ts +++ b/examples/express/src/tracer.ts @@ -11,10 +11,14 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; export const setupTracing = (serviceName: string) => { + const exporter = new OTLPTraceExporter({}); const provider = new NodeTracerProvider({ resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], sampler: filterSampler(ignoreHealthCheck, new AlwaysOnSampler()), }); registerInstrumentations({ @@ -26,10 +30,6 @@ export const setupTracing = (serviceName: string) => { ], }); - const exporter = new OTLPTraceExporter({}); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/graphql/tracer.js b/examples/graphql/tracer.js index 82a24edde8..c718f57532 100644 --- a/examples/graphql/tracer.js +++ b/examples/graphql/tracer.js @@ -14,10 +14,12 @@ const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'graphql-service', }), + spanProcessors: [ + new SimpleSpanProcessor(new OTLPTraceExporter()), + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/examples/grpc-census-prop/tracer.js b/examples/grpc-census-prop/tracer.js index b8241dc2b1..7fcb590fdc 100644 --- a/examples/grpc-census-prop/tracer.js +++ b/examples/grpc-census-prop/tracer.js @@ -13,11 +13,13 @@ const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); * requested propagator */ module.exports = (serviceName, binaryPropagator) => { - const provider = new NodeTracerProvider(); - - // It is recommended to use this `BatchSpanProcessor` for better performance - // and optimization, especially in production. - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); + const provider = new NodeTracerProvider({ + spanProcessors: [ + // It is recommended to use `BatchSpanProcessor` for better performance + // and optimization, especially in production. + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], + }); if (binaryPropagator) { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings diff --git a/examples/hapi/tracer.js b/examples/hapi/tracer.js index 9c335d108b..cf0993eda7 100644 --- a/examples/hapi/tracer.js +++ b/examples/hapi/tracer.js @@ -12,15 +12,18 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); - let exporter; if (EXPORTER === 'jaeger') { exporter = new JaegerExporter({ serviceName }); } else { exporter = new ZipkinExporter({ serviceName }); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/ioredis/tracer.js b/examples/ioredis/tracer.js index 6d18533d9a..1b0701cd76 100644 --- a/examples/ioredis/tracer.js +++ b/examples/ioredis/tracer.js @@ -7,11 +7,13 @@ const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); - const exporter = new JaegerExporter({ serviceName: 'ioredis-example' }); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], +}); // Initialize the OpenTelemetry APIs to use the BasicTracer bindings provider.register(); diff --git a/examples/koa/src/tracer.ts b/examples/koa/src/tracer.ts index d0a3321a68..1a06e748c4 100644 --- a/examples/koa/src/tracer.ts +++ b/examples/koa/src/tracer.ts @@ -15,19 +15,21 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' const EXPORTER = process.env.EXPORTER || ''; export const setupTracing = (serviceName: string) => { - const provider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName - }) - }); - let exporter; if (EXPORTER === 'jaeger') { exporter = new JaegerExporter(); } else { exporter = new ZipkinExporter(); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + const provider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName + }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); registerInstrumentations({ instrumentations: [ diff --git a/examples/memcached/tracer.js b/examples/memcached/tracer.js index 285233199a..aecd74956b 100644 --- a/examples/memcached/tracer.js +++ b/examples/memcached/tracer.js @@ -14,10 +14,14 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention const { MemcachedInstrumentation } = require('@opentelemetry/instrumentation-memcached'); module.exports = (serviceName) => { + const exporter = new ConsoleSpanExporter(); const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); registerInstrumentations({ tracerProvider: provider, @@ -26,10 +30,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new ConsoleSpanExporter(); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/meta-node/tracer.js b/examples/meta-node/tracer.js index 4636e30392..50cbb957c6 100644 --- a/examples/meta-node/tracer.js +++ b/examples/meta-node/tracer.js @@ -17,8 +17,11 @@ module.exports = () => { serviceName: 'basic-service', }); - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); provider.register(); registerInstrumentations({ diff --git a/examples/mongodb/src/tracer.ts b/examples/mongodb/src/tracer.ts index a9599dec35..f3d9acdc68 100644 --- a/examples/mongodb/src/tracer.ts +++ b/examples/mongodb/src/tracer.ts @@ -15,6 +15,10 @@ export const setupTracing = (serviceName: string): api.Tracer => { resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(new ZipkinExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings @@ -30,8 +34,5 @@ export const setupTracing = (serviceName: string): api.Tracer => { tracerProvider: provider, }); - provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - return api.trace.getTracer('mongodb-example'); }; diff --git a/examples/mysql/src/tracer.ts b/examples/mysql/src/tracer.ts index 2ded0e2567..34a1746cb7 100644 --- a/examples/mysql/src/tracer.ts +++ b/examples/mysql/src/tracer.ts @@ -2,7 +2,7 @@ import opentelemetry from '@opentelemetry/api'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; -import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; +import { SimpleSpanProcessor, SpanProcessor } from '@opentelemetry/sdk-trace-base'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; @@ -20,25 +20,30 @@ const EXPORTER = process.env.EXPORTER || ''; export const setupTracing = (serviceName: string) => { //metrics: - const meterProvider = new MeterProvider() const metricExporter = new OTLPMetricExporter(); const metricReader = new PeriodicExportingMetricReader({ exporter: metricExporter, exportIntervalMillis: 100, exportTimeoutMillis: 100, }); - meterProvider.addMetricReader(metricReader); + const meterProvider = new MeterProvider({ + readers: [metricReader], + }); //traces: - const tracerProvider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName, - }),}); + const spanProcessors: SpanProcessor[] = []; if (EXPORTER.toLowerCase().startsWith('z')) { - tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter())); + spanProcessors.push(new SimpleSpanProcessor(new ZipkinExporter())); } + const tracerProvider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName, + }), + spanProcessors, + }); + // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings tracerProvider.register(); diff --git a/examples/network/client.js b/examples/network/client.js index 5ce3523971..8aad8eb04e 100644 --- a/examples/network/client.js +++ b/examples/network/client.js @@ -9,13 +9,14 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const provider = new NodeTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({ - serviceName: 'http-client', -}))); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new JaegerExporter({ + serviceName: 'http-client', + })), + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); provider.register(); diff --git a/examples/react-load/preact/src/web-tracer.js b/examples/react-load/preact/src/web-tracer.js index b52d436e0a..f974a91b96 100644 --- a/examples/react-load/preact/src/web-tracer.js +++ b/examples/react-load/preact/src/web-tracer.js @@ -7,13 +7,15 @@ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; export default (serviceName) => { diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); - const provider = new WebTracerProvider(); const exporter = new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces', }); - - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(exporter), + ], + }); provider.register({ contextManager: new ZoneContextManager(), diff --git a/examples/react-load/react/src/web-tracer.js b/examples/react-load/react/src/web-tracer.js index 80796da13e..d026455dff 100644 --- a/examples/react-load/react/src/web-tracer.js +++ b/examples/react-load/react/src/web-tracer.js @@ -8,19 +8,20 @@ import { Resource } from '@opentelemetry/resources'; import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' export default (serviceName) => { + const exporter = new CollectorTraceExporter({ + url: 'http://localhost:55678/v1/trace', + }); + const provider = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: "react-load-example" }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(exporter), + ], }); - const exporter = new CollectorTraceExporter({ - url: 'http://localhost:55678/v1/trace', - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - provider.register({ contextManager: new ZoneContextManager(), }); diff --git a/examples/redis/src/tracer.ts b/examples/redis/src/tracer.ts index de70a60418..91eb03bec2 100644 --- a/examples/redis/src/tracer.ts +++ b/examples/redis/src/tracer.ts @@ -14,11 +14,6 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; const EXPORTER = process.env.EXPORTER || ''; export const setupTracing = (serviceName: string) => { - const provider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName, - }),}); - let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter(); @@ -26,7 +21,14 @@ export const setupTracing = (serviceName: string) => { exporter = new JaegerExporter(); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName, + }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ] + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/restify/tracer.js b/examples/restify/tracer.js index ddeecc3b8d..b2712adf03 100644 --- a/examples/restify/tracer.js +++ b/examples/restify/tracer.js @@ -28,7 +28,16 @@ const Exporter = ((exporterParam) => { })(process.env.EXPORTER); module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const exporter = new Exporter({ + serviceName, + }); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); + registerInstrumentations({ tracerProvider: provider, instrumentations: [ @@ -37,12 +46,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new Exporter({ - serviceName, - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/router/tracer.js b/examples/router/tracer.js index 63aaaaa0a5..73ee585060 100644 --- a/examples/router/tracer.js +++ b/examples/router/tracer.js @@ -28,7 +28,16 @@ const Exporter = ((exporterParam) => { })(process.env.EXPORTER); module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const exporter = new Exporter({ + serviceName, + }); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); + registerInstrumentations({ tracerProvider: provider, instrumentations: [ @@ -37,12 +46,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new Exporter({ - serviceName, - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/web/examples/document-load/index.js b/examples/web/examples/document-load/index.js index 65db02bba3..c09039b587 100644 --- a/examples/web/examples/document-load/index.js +++ b/examples/web/examples/document-load/index.js @@ -15,11 +15,12 @@ const provider = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-dl', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - provider.register({ contextManager: new ZoneContextManager(), propagator: new CompositePropagator({ diff --git a/examples/web/examples/meta/index.js b/examples/web/examples/meta/index.js index 8b9cb5ad41..90e6e4ae73 100644 --- a/examples/web/examples/meta/index.js +++ b/examples/web/examples/meta/index.js @@ -12,11 +12,12 @@ const providerWithZone = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-meta', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - providerWithZone.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/examples/web/examples/user-interaction/index.js b/examples/web/examples/user-interaction/index.js index b75cae65d5..0360f13577 100644 --- a/examples/web/examples/user-interaction/index.js +++ b/examples/web/examples/user-interaction/index.js @@ -13,11 +13,12 @@ const providerWithZone = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-ui', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - providerWithZone.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index b41c31fa3c..60692e339c 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -138,8 +138,10 @@ const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'basic-service', }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); registerInstrumentations({ diff --git a/metapackages/auto-instrumentations-web/README.md b/metapackages/auto-instrumentations-web/README.md index 864e031709..e51b806e84 100644 --- a/metapackages/auto-instrumentations-web/README.md +++ b/metapackages/auto-instrumentations-web/README.md @@ -26,8 +26,11 @@ const exporter = new CollectorTraceExporter({ serviceName: 'auto-instrumentations-web', }); -const provider = new WebTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], +}); provider.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/package-lock.json b/package-lock.json index 1195ed835c..064e56329f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34221,12 +34221,12 @@ } }, "node_modules/undici": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz", - "integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==", + "version": "6.21.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz", + "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==", "dev": true, "engines": { - "node": ">=18.0" + "node": ">=18.17" } }, "node_modules/undici-types": { @@ -37374,7 +37374,7 @@ "semver": "^7.6.0", "test-all-versions": "6.1.0", "typescript": "4.4.4", - "undici": "6.11.1" + "undici": "6.21.1" }, "engines": { "node": ">=14" @@ -49833,7 +49833,7 @@ "semver": "^7.6.0", "test-all-versions": "6.1.0", "typescript": "4.4.4", - "undici": "6.11.1" + "undici": "6.21.1" }, "dependencies": { "@types/mocha": { @@ -69460,9 +69460,9 @@ } }, "undici": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz", - "integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==", + "version": "6.21.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz", + "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==", "dev": true }, "undici-types": { diff --git a/packages/opentelemetry-test-utils/src/instrumentations/otel-default-provider.ts b/packages/opentelemetry-test-utils/src/instrumentations/otel-default-provider.ts index 7882b72c9a..a6c4d1ddd9 100644 --- a/packages/opentelemetry-test-utils/src/instrumentations/otel-default-provider.ts +++ b/packages/opentelemetry-test-utils/src/instrumentations/otel-default-provider.ts @@ -30,19 +30,23 @@ import { export const registerInstrumentationTestingProvider = ( config?: NodeTracerConfig ): NodeTracerProvider => { - const otelTestingProvider = new NodeTracerProvider(config); + const spanProcessors = config?.spanProcessors + ? [...config.spanProcessors] + : []; setTestMemoryExporter(new InMemorySpanExporter()); - otelTestingProvider.addSpanProcessor( - new SimpleSpanProcessor(getTestMemoryExporter()!) - ); + + spanProcessors.push(new SimpleSpanProcessor(getTestMemoryExporter()!)); if (process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST) { - otelTestingProvider.addSpanProcessor( - new SimpleSpanProcessor(new JaegerExporter()) - ); + spanProcessors.push(new SimpleSpanProcessor(new JaegerExporter())); } + const otelTestingProvider = new NodeTracerProvider({ + ...config, + spanProcessors, + }); + otelTestingProvider.register(); return otelTestingProvider; }; diff --git a/plugins/node/instrumentation-cucumber/.tav.yml b/plugins/node/instrumentation-cucumber/.tav.yml index 0a9cf7031d..e00a9aeeb5 100644 --- a/plugins/node/instrumentation-cucumber/.tav.yml +++ b/plugins/node/instrumentation-cucumber/.tav.yml @@ -9,3 +9,8 @@ mode: latest-minors node: '>=18' commands: npm test + - versions: + include: '^11.0.0' + mode: latest-minors + node: '>=18' + commands: npm test diff --git a/plugins/node/instrumentation-cucumber/src/instrumentation.ts b/plugins/node/instrumentation-cucumber/src/instrumentation.ts index 62341ad990..1c8e73de19 100644 --- a/plugins/node/instrumentation-cucumber/src/instrumentation.ts +++ b/plugins/node/instrumentation-cucumber/src/instrumentation.ts @@ -47,7 +47,7 @@ type Cucumber = typeof cucumber; type Hook = (typeof hooks)[number]; type Step = (typeof steps)[number]; -const supportedVersions = ['>=8.0.0 <11']; +const supportedVersions = ['>=8.0.0 <12']; export class CucumberInstrumentation extends InstrumentationBase { private module: Cucumber | undefined; diff --git a/plugins/node/instrumentation-cucumber/test/cucumber.test.ts b/plugins/node/instrumentation-cucumber/test/cucumber.test.ts index deffbef31d..2ffdcae627 100644 --- a/plugins/node/instrumentation-cucumber/test/cucumber.test.ts +++ b/plugins/node/instrumentation-cucumber/test/cucumber.test.ts @@ -53,14 +53,14 @@ import { import { PassThrough } from 'stream'; describe('CucumberInstrumentation', () => { + const memoryExporter = new InMemorySpanExporter(); + const spanProcessor = new SimpleSpanProcessor(memoryExporter); const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'CucumberInstrumentation', }), + spanProcessors: [spanProcessor], }); - const memoryExporter = new InMemorySpanExporter(); - const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); const contextManager = new AsyncHooksContextManager().enable(); before(() => { diff --git a/plugins/node/instrumentation-dataloader/test/dataloader.test.ts b/plugins/node/instrumentation-dataloader/test/dataloader.test.ts index 9686c21d2e..319bde4d03 100644 --- a/plugins/node/instrumentation-dataloader/test/dataloader.test.ts +++ b/plugins/node/instrumentation-dataloader/test/dataloader.test.ts @@ -37,12 +37,13 @@ describe('DataloaderInstrumentation', () => { let contextManager: AsyncHooksContextManager; const memoryExporter = new InMemorySpanExporter(); - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('default'); instrumentation.setTracerProvider(provider); extraInstrumentation.setTracerProvider(provider); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(async () => { instrumentation.enable(); diff --git a/plugins/node/instrumentation-fs/test/fs.test.ts b/plugins/node/instrumentation-fs/test/fs.test.ts index 4e639ceb82..5383c9f1ef 100644 --- a/plugins/node/instrumentation-fs/test/fs.test.ts +++ b/plugins/node/instrumentation-fs/test/fs.test.ts @@ -58,10 +58,11 @@ const pluginConfig = { createHook, endHook, }; -const provider = new BasicTracerProvider(); -const tracer = provider.getTracer('default'); const memoryExporter = new InMemorySpanExporter(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); +const tracer = provider.getTracer('default'); describe('fs instrumentation', () => { let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/instrumentation-fs/test/fsHooks.test.ts b/plugins/node/instrumentation-fs/test/fsHooks.test.ts index bdffab00e8..7fa61ac0af 100644 --- a/plugins/node/instrumentation-fs/test/fsHooks.test.ts +++ b/plugins/node/instrumentation-fs/test/fsHooks.test.ts @@ -37,9 +37,10 @@ const pluginConfig = { endHook, }; -const provider = new BasicTracerProvider(); const memoryExporter = new InMemorySpanExporter(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const assertNotHookError = (err?: Error | null) => { assert.ok( diff --git a/plugins/node/instrumentation-fs/test/fsPromises.test.ts b/plugins/node/instrumentation-fs/test/fsPromises.test.ts index 0400f57ee7..73db46937a 100644 --- a/plugins/node/instrumentation-fs/test/fsPromises.test.ts +++ b/plugins/node/instrumentation-fs/test/fsPromises.test.ts @@ -37,10 +37,11 @@ const endHook = sinon.spy((fnName, { args, span }) => { const pluginConfig = { endHook, }; -const provider = new BasicTracerProvider(); -const tracer = provider.getTracer('default'); const memoryExporter = new InMemorySpanExporter(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); +const tracer = provider.getTracer('default'); describe('fs/promises instrumentation', () => { let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts b/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts index be3db71202..2d90bf8cce 100644 --- a/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts +++ b/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts @@ -37,9 +37,10 @@ const pluginConfig = { endHook, }; -const provider = new BasicTracerProvider(); const memoryExporter = new InMemorySpanExporter(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const assertNotHookError = (err?: Error | null) => { assert.ok( diff --git a/plugins/node/instrumentation-fs/test/parent.test.ts b/plugins/node/instrumentation-fs/test/parent.test.ts index 903e7e48e8..0619b7ed19 100644 --- a/plugins/node/instrumentation-fs/test/parent.test.ts +++ b/plugins/node/instrumentation-fs/test/parent.test.ts @@ -25,9 +25,10 @@ import type { FsInstrumentationConfig } from '../src/types'; import * as api from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -const provider = new BasicTracerProvider(); const memoryExporter = new InMemorySpanExporter(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const tracer = provider.getTracer('default'); diff --git a/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts b/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts index 9571ff23c6..d77bfbdcfe 100644 --- a/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts @@ -27,8 +27,9 @@ describe(`${ConventionalNamePrefix.NodeJs}.eventloop`, function () { beforeEach(() => { metricReader = new TestMetricReader(); - meterProvider = new MeterProvider(); - meterProvider.addMetricReader(metricReader); + meterProvider = new MeterProvider({ + readers: [metricReader], + }); }); for (const metricName in metricNames) { diff --git a/plugins/node/instrumentation-runtime-node/test/event_loop_time.test.ts b/plugins/node/instrumentation-runtime-node/test/event_loop_time.test.ts index ac9a672ab9..7ee96150f3 100644 --- a/plugins/node/instrumentation-runtime-node/test/event_loop_time.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/event_loop_time.test.ts @@ -29,8 +29,9 @@ describe(`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_TIME}`, func beforeEach(() => { metricReader = new TestMetricReader(); - meterProvider = new MeterProvider(); - meterProvider.addMetricReader(metricReader); + meterProvider = new MeterProvider({ + readers: [metricReader], + }); }); it('should not export before being enabled', async function () { diff --git a/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts b/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts index e434557f20..3200dd0392 100644 --- a/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts @@ -29,8 +29,9 @@ describe(`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION} beforeEach(() => { metricReader = new TestMetricReader(); - meterProvider = new MeterProvider(); - meterProvider.addMetricReader(metricReader); + meterProvider = new MeterProvider({ + readers: [metricReader], + }); }); it('should not export before being enabled', async function () { diff --git a/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts b/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts index 177834332f..43aae14344 100644 --- a/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts @@ -31,8 +31,9 @@ describe('nodejs.heap_space', function () { beforeEach(() => { metricReader = new TestMetricReader(); - meterProvider = new MeterProvider(); - meterProvider.addMetricReader(metricReader); + meterProvider = new MeterProvider({ + readers: [metricReader], + }); }); for (const metricName in metricNames) { diff --git a/plugins/node/instrumentation-runtime-node/test/instrumentation.test.ts b/plugins/node/instrumentation-runtime-node/test/instrumentation.test.ts index 34de947e15..f3ccf82a0e 100644 --- a/plugins/node/instrumentation-runtime-node/test/instrumentation.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/instrumentation.test.ts @@ -27,8 +27,9 @@ describe('instrumentation', function () { beforeEach(() => { metricReader = new TestMetricReader(); - meterProvider = new MeterProvider(); - meterProvider.addMetricReader(metricReader); + meterProvider = new MeterProvider({ + readers: [metricReader], + }); }); it('should not export before being enabled', async function () { diff --git a/plugins/node/instrumentation-tedious/test/instrumentation.test.ts b/plugins/node/instrumentation-tedious/test/instrumentation.test.ts index f9419cc4c6..d20d16cad7 100644 --- a/plugins/node/instrumentation-tedious/test/instrumentation.test.ts +++ b/plugins/node/instrumentation-tedious/test/instrumentation.test.ts @@ -89,10 +89,12 @@ describe('tedious', () => { let tedious: any; let contextManager: AsyncHooksContextManager; let connection: Connection; - const provider = new BasicTracerProvider(); + const memoryExporter = new InMemorySpanExporter(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const shouldTest = process.env.RUN_MSSQL_TESTS; // For CI: assumes local db is already available const shouldTestLocally = process.env.RUN_MSSQL_TESTS_LOCAL; // For local: spins up local db via docker - const memoryExporter = new InMemorySpanExporter(); before(function (done) { if (!(shouldTest || shouldTestLocally) || incompatVersions) { @@ -101,7 +103,6 @@ describe('tedious', () => { this.test!.parent!.pending = true; this.skip(); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (shouldTestLocally) { testUtils.startDocker('mssql'); // wait 15 seconds for docker container to start diff --git a/plugins/node/instrumentation-undici/README.md b/plugins/node/instrumentation-undici/README.md index e0d9f8d158..154a915b63 100644 --- a/plugins/node/instrumentation-undici/README.md +++ b/plugins/node/instrumentation-undici/README.md @@ -35,9 +35,12 @@ const { } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/instrumentation-undici/package.json b/plugins/node/instrumentation-undici/package.json index 42b20045ed..9974b898ef 100644 --- a/plugins/node/instrumentation-undici/package.json +++ b/plugins/node/instrumentation-undici/package.json @@ -51,7 +51,7 @@ "semver": "^7.6.0", "test-all-versions": "6.1.0", "typescript": "4.4.4", - "undici": "6.11.1" + "undici": "6.21.1" }, "peerDependencies": { "@opentelemetry/api": "^1.7.0" diff --git a/plugins/node/instrumentation-undici/test/fetch.test.ts b/plugins/node/instrumentation-undici/test/fetch.test.ts index 9ef4e90767..863f74b6c8 100644 --- a/plugins/node/instrumentation-undici/test/fetch.test.ts +++ b/plugins/node/instrumentation-undici/test/fetch.test.ts @@ -42,8 +42,9 @@ describe('UndiciInstrumentation `fetch` tests', function () { const hostname = 'localhost'; const mockServer = new MockServer(); const memoryExporter = new InMemorySpanExporter(); - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); before(function (done) { // Do not test if the `fetch` global API is not available diff --git a/plugins/node/instrumentation-undici/test/metrics.test.ts b/plugins/node/instrumentation-undici/test/metrics.test.ts index a903698385..de7a9ad5c7 100644 --- a/plugins/node/instrumentation-undici/test/metrics.test.ts +++ b/plugins/node/instrumentation-undici/test/metrics.test.ts @@ -37,12 +37,13 @@ describe('UndiciInstrumentation metrics tests', function () { const hostname = 'localhost'; const mockServer = new MockServer(); const provider = new NodeTracerProvider(); - const meterProvider = new MeterProvider(); const metricsMemoryExporter = new InMemoryMetricExporter( AggregationTemporality.DELTA ); const metricReader = new MockMetricsReader(metricsMemoryExporter); - meterProvider.addMetricReader(metricReader); + const meterProvider = new MeterProvider({ + readers: [metricReader], + }); before(function (done) { // Do not test if the `fetch` global API is not available diff --git a/plugins/node/instrumentation-undici/test/undici.test.ts b/plugins/node/instrumentation-undici/test/undici.test.ts index effa2b3a3f..5a0757460c 100644 --- a/plugins/node/instrumentation-undici/test/undici.test.ts +++ b/plugins/node/instrumentation-undici/test/undici.test.ts @@ -68,8 +68,9 @@ describe('UndiciInstrumentation `undici` tests', function () { const hostname = 'localhost'; const mockServer = new MockServer(); const memoryExporter = new InMemorySpanExporter(); - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); before(function (done) { // Load `undici`. It may fail if nodejs version is <18 because the module uses diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts index 0a067dc758..8b68e71fe2 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts @@ -88,8 +88,9 @@ describe('force flush', () => { }); it('should force flush NodeTracerProvider', async () => { - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new BatchSpanProcessor(traceMemoryExporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [new BatchSpanProcessor(traceMemoryExporter)], + }); provider.register(); let forceFlushed = false; const forceFlush = () => @@ -118,10 +119,9 @@ describe('force flush', () => { }); it('should force flush ProxyTracerProvider with NodeTracerProvider', async () => { - const nodeTracerProvider = new NodeTracerProvider(); - nodeTracerProvider.addSpanProcessor( - new BatchSpanProcessor(traceMemoryExporter) - ); + const nodeTracerProvider = new NodeTracerProvider({ + spanProcessors: [new BatchSpanProcessor(traceMemoryExporter)], + }); nodeTracerProvider.register(); const provider = new ProxyTracerProvider(); provider.setDelegate(nodeTracerProvider); @@ -152,10 +152,11 @@ describe('force flush', () => { }); it('should force flush MeterProvider', async () => { - const provider = new MeterProvider(); - provider.addMetricReader( - new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }) - ); + const provider = new MeterProvider({ + readers: [ + new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }), + ], + }); let forceFlushed = false; const forceFlush = () => new Promise(resolve => { @@ -183,10 +184,9 @@ describe('force flush', () => { }); it('should callback once after force flush providers', async () => { - const nodeTracerProvider = new NodeTracerProvider(); - nodeTracerProvider.addSpanProcessor( - new BatchSpanProcessor(traceMemoryExporter) - ); + const nodeTracerProvider = new NodeTracerProvider({ + spanProcessors: [new BatchSpanProcessor(traceMemoryExporter)], + }); nodeTracerProvider.register(); const tracerProvider = new ProxyTracerProvider(); tracerProvider.setDelegate(nodeTracerProvider); @@ -198,10 +198,11 @@ describe('force flush', () => { }); nodeTracerProvider.forceFlush = tracerForceFlush; - const meterProvider = new MeterProvider(); - meterProvider.addMetricReader( - new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }) - ); + const meterProvider = new MeterProvider({ + readers: [ + new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }), + ], + }); let meterForceFlushed = false; const meterForceFlush = () => new Promise(resolve => { diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts index 65c4a76df8..a7aeadfae8 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts @@ -120,8 +120,9 @@ describe('lambda handler', () => { ) => { process.env._HANDLER = handler; - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new BatchSpanProcessor(memoryExporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [new BatchSpanProcessor(memoryExporter)], + }); provider.register(); instrumentation = new AwsLambdaInstrumentation(config); diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/test/bunyan.test.ts b/plugins/node/opentelemetry-instrumentation-bunyan/test/bunyan.test.ts index b26c290b97..aa4196f5d2 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/test/bunyan.test.ts +++ b/plugins/node/opentelemetry-instrumentation-bunyan/test/bunyan.test.ts @@ -40,11 +40,10 @@ import type * as BunyanLogger from 'bunyan'; // import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api'; // diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); -const tracerProvider = new NodeTracerProvider(); +const tracerProvider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(new InMemorySpanExporter())], +}); tracerProvider.register(); -tracerProvider.addSpanProcessor( - new SimpleSpanProcessor(new InMemorySpanExporter()) -); const tracer = tracerProvider.getTracer('default'); const resource = new Resource({ diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts b/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts index 00171c8426..a51dc74a45 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts +++ b/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts @@ -48,8 +48,9 @@ import { import { ResponseHookInfo } from '../src/types'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); context.setGlobalContextManager(new AsyncHooksContextManager()); const testCassandra = process.env.RUN_CASSANDRA_TESTS; diff --git a/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts b/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts index cc2ef79fb5..8d228adc23 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts +++ b/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts @@ -50,14 +50,15 @@ const httpRequest = { const instrumentation = new ConnectInstrumentation(); const contextManager = new AsyncHooksContextManager().enable(); const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); +const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], +}); instrumentation.setTracerProvider(provider); context.setGlobalContextManager(contextManager); const tracer = provider.getTracer('default'); -provider.addSpanProcessor(spanProcessor); instrumentation.enable(); import * as connect from 'connect'; diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/dns-disable.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/dns-disable.test.ts index ddcf174127..79701f213f 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/dns-disable.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/dns-disable.test.ts @@ -26,9 +26,10 @@ import * as Sinon from 'sinon'; import * as dns from 'dns'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const tracer = provider.getTracer('default'); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('DnsInstrumentation', () => { let instrumentation: DnsInstrumentation; diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts index e17d8b06a2..b54e564b50 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts @@ -27,8 +27,9 @@ import { assertSpan } from '../utils/assertSpan'; import { SpanStatusCode } from '@opentelemetry/api'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); describe('dns.lookup()', () => { let instrumentation: DnsInstrumentation; diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts index 7489e25153..b96c74de8d 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts @@ -27,8 +27,9 @@ import { assertSpan } from '../utils/assertSpan'; import { SpanStatusCode } from '@opentelemetry/api'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const supportsPromises = parseInt(process.versions.node.split('.')[0], 10) >= 15; diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts index 1338f43bac..7443d4d81e 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts @@ -27,8 +27,9 @@ import { assertSpan } from '../utils/assertSpan'; import { SpanStatusCode } from '@opentelemetry/api'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); describe('dns.promises.lookup()', () => { let instrumentation: DnsInstrumentation; diff --git a/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts index 50d644086a..abdb7bc26f 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts @@ -39,10 +39,10 @@ import * as express from 'express'; import * as http from 'http'; describe('ExpressInstrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); - const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('default'); const contextManager = new AsyncHooksContextManager().enable(); diff --git a/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts index 5991688ffd..13806b2698 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts @@ -37,10 +37,11 @@ import { RPCMetadata, getRPCMetadata } from '@opentelemetry/core'; import { Server } from 'http'; describe('ExpressInstrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); const contextManager = new AsyncHooksContextManager().enable(); diff --git a/plugins/node/opentelemetry-instrumentation-express/test/hooks.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/hooks.test.ts index 78cfdd3d4a..04af79540c 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/hooks.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/hooks.test.ts @@ -37,10 +37,11 @@ import { httpRequest, serverWithMiddleware } from './utils'; import { RPCMetadata, getRPCMetadata } from '@opentelemetry/core'; describe('ExpressInstrumentation hooks', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); const contextManager = new AsyncHooksContextManager().enable(); diff --git a/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts index 0fdebeabfb..7d462baa13 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts @@ -41,10 +41,11 @@ import * as express from 'express'; import * as http from 'http'; describe('ExpressInstrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); const contextManager = new AsyncHooksContextManager().enable(); diff --git a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts index 80c4195742..1ac82b125f 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts +++ b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts @@ -66,13 +66,14 @@ const httpInstrumentation = new HttpInstrumentation(); const instrumentation = new FastifyInstrumentation(); const contextManager = new AsyncHooksContextManager().enable(); const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); +const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], +}); instrumentation.setTracerProvider(provider); httpInstrumentation.setTracerProvider(provider); context.setGlobalContextManager(contextManager); -provider.addSpanProcessor(spanProcessor); instrumentation.enable(); httpInstrumentation.enable(); diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/README.md b/plugins/node/opentelemetry-instrumentation-generic-pool/README.md index 90404555dc..32b791d12c 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/README.md +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/README.md @@ -27,9 +27,12 @@ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { GenericPoolInstrumentation } = require('@opentelemetry/instrumentation-generic-pool'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-generic-pool/test/index.test.ts index e2e634d4be..3d99207ae5 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/test/index.test.ts @@ -67,10 +67,11 @@ const createPool = { }[isOldVersion ? 'v2' : 'v3']; describe('GenericPool instrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); plugin.setTracerProvider(provider); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts index 661304a212..c538a4d1d2 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts @@ -99,8 +99,9 @@ const queryInvalid = ` `; const exporter = new InMemorySpanExporter(); -const provider = new BasicTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); +const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(exporter)], +}); graphQLInstrumentation.setTracerProvider(provider); describe('graphql', () => { diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts index a9cbe7dd26..684ab99406 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts @@ -29,10 +29,11 @@ import { HapiLayerType } from '../src/internal-types'; import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Hapi.Plugin Tests', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; let server: hapi.Server; diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts index 529df11299..4508bca44a 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts @@ -30,10 +30,11 @@ import { HapiLayerType } from '../src/internal-types'; import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Server.Ext Tests', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; let server: hapi.Server; diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts index 48e2c51912..e6be869a26 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts @@ -35,10 +35,11 @@ import { HapiLayerType } from '../src/internal-types'; import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Core Tests', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; let server: hapi.Server; diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts index 6dad19a9e4..b1a1505e7b 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts @@ -86,7 +86,9 @@ const sanitizeEventForAssertion = (span: ReadableSpan) => { }; describe('ioredis', () => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); let ioredis: typeof ioredisTypes.default; let instrumentation: IORedisInstrumentation; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; @@ -115,7 +117,6 @@ describe('ioredis', () => { testUtils.startDocker('redis'); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); instrumentation = new IORedisInstrumentation(); instrumentation.setTracerProvider(provider); ioredis = require('ioredis'); diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index e467172648..596fdcc619 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -27,9 +27,12 @@ const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts index aa00a3a9f2..61f7be90b2 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts @@ -36,10 +36,11 @@ const plugin = new KnexInstrumentation({ import knex from 'knex'; describe('Knex instrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); plugin.setTracerProvider(provider); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts index c1b894a026..06b914e968 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts @@ -73,10 +73,11 @@ const isrouterCompat = (semver.gte(LIB_VERSION, '13.0.0') && semver.gte(NODE_VERSION, '18.0.0')); describe('Koa Instrumentation', function () { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); plugin.setTracerProvider(provider); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts index ca6e883cac..25be005aeb 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts @@ -75,9 +75,10 @@ const shouldTestLocal = process.env.RUN_MEMCACHED_TESTS_LOCAL; const shouldTest = process.env.RUN_MEMCACHED_TESTS || shouldTestLocal; describe('memcached@2.x', () => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('default'); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); instrumentation.setTracerProvider(provider); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts index 9bb49cb45b..47e925ac14 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts @@ -28,7 +28,6 @@ import { ResourceMetrics, } from '@opentelemetry/sdk-metrics'; -const otelTestingMeterProvider = new MeterProvider(); const inMemoryMetricsExporter = new InMemoryMetricExporter( AggregationTemporality.CUMULATIVE ); @@ -37,6 +36,9 @@ const metricReader = new PeriodicExportingMetricReader({ exportIntervalMillis: 100, exportTimeoutMillis: 100, }); +const otelTestingMeterProvider = new MeterProvider({ + readers: [metricReader], +}); import { registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; const instrumentation = registerInstrumentationTesting( @@ -85,7 +87,6 @@ describe('MongoDBInstrumentation-Metrics', () => { let collection: Collection; before(done => { - otelTestingMeterProvider.addMetricReader(metricReader); instrumentation?.setMeterProvider(otelTestingMeterProvider); shouldTest = true; diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts index b6015d65a8..3661904b5b 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts @@ -67,7 +67,6 @@ describe('mysql@2.x-Metrics', () => { const shouldTest = testMysql || testMysqlLocally; // Skips these tests if false (default) function initMeterProvider() { - otelTestingMeterProvider = new MeterProvider(); inMemoryMetricsExporter = new InMemoryMetricExporter( AggregationTemporality.CUMULATIVE ); @@ -76,8 +75,10 @@ describe('mysql@2.x-Metrics', () => { exportIntervalMillis: 100, exportTimeoutMillis: 100, }); + otelTestingMeterProvider = new MeterProvider({ + readers: [metricReader], + }); - otelTestingMeterProvider.addMetricReader(metricReader); instrumentation.setMeterProvider(otelTestingMeterProvider); } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts index 36b7cd1d5f..7679cb0182 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts @@ -54,11 +54,13 @@ describe('mysql@2.x-Tracing', () => { let connection: mysqlTypes.Connection; let pool: mysqlTypes.Pool; let poolCluster: mysqlTypes.PoolCluster; - const provider = new BasicTracerProvider(); const testMysql = process.env.RUN_MYSQL_TESTS; // For CI: assumes local mysql db is already available const testMysqlLocally = process.env.RUN_MYSQL_TESTS_LOCAL; // For local: spins up local mysql db via docker const shouldTest = testMysql || testMysqlLocally; // Skips these tests if false (default) const memoryExporter = new InMemorySpanExporter(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); before(function (done) { if (!shouldTest) { @@ -67,7 +69,7 @@ describe('mysql@2.x-Tracing', () => { this.test!.parent!.pending = true; this.skip(); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + if (testMysqlLocally) { testUtils.startDocker('mysql'); // wait 15 seconds for docker container to start diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts index 60fe5a9c66..b966900521 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts @@ -90,8 +90,10 @@ describe('mysql2', () => { describe('callback API', () => { let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); const memoryExporter = new InMemorySpanExporter(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); let connection: Connection; let rootConnection: Connection; @@ -123,7 +125,6 @@ describe('mysql2', () => { this.test!.parent!.pending = true; this.skip(); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); rootConnection = createConnection({ port, user: 'root', diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts index 236ade682d..aca1d7b3db 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts @@ -38,8 +38,9 @@ util.inspect.defaultOptions.depth = 3; util.inspect.defaultOptions.breakLength = 200; describe('nestjs-core', () => { - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); instrumentation.setTracerProvider(provider); let contextManager: AsyncHooksContextManager; let app: App; diff --git a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts index 55849289ee..7090311229 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts @@ -28,8 +28,9 @@ import { SocketEvent } from '../src/internal-types'; import { assertIpcSpan, assertTcpSpan, IPC_PATH, HOST, PORT } from './utils'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); function getSpan() { const spans = memoryExporter.getFinishedSpans(); diff --git a/plugins/node/opentelemetry-instrumentation-net/test/instrument.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/instrument.test.ts index 09319a5808..6c8e933a39 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/instrument.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/instrument.test.ts @@ -27,9 +27,10 @@ import * as net from 'net'; import { HOST, PORT } from './utils'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const tracer = provider.getTracer('default'); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('NetInstrumentation', () => { let instrumentation: NetInstrumentation; diff --git a/plugins/node/opentelemetry-instrumentation-net/test/tls.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/tls.test.ts index 0052a4787c..e3232d46fd 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/tls.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/tls.test.ts @@ -34,8 +34,9 @@ import { } from './utils'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); function getTLSSpans() { const spans = memoryExporter.getFinishedSpans(); diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index 0e4f71d42c..d75eea6cb6 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -123,7 +123,9 @@ describe('pg-pool', () => { let pool: pgPool; let contextManager: AsyncHooksContextManager; let instrumentation: PgInstrumentation; - const provider = new BasicTracerProvider(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker @@ -141,7 +143,6 @@ describe('pg-pool', () => { skip(); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testPostgresLocally) { testUtils.startDocker('postgres'); } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index 8dd33aa55f..f842b1316c 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -118,7 +118,9 @@ describe('pg', () => { let client: pg.Client; let instrumentation: PgInstrumentation; let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('external'); const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available @@ -143,7 +145,6 @@ describe('pg', () => { skip(); } - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testPostgresLocally) { testUtils.startDocker('postgres'); } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts index a76bb61988..68f16e1b27 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts @@ -49,16 +49,14 @@ const getLatestSpan = () => { describe('utils.ts', () => { const client = new pg.Client(CONFIG) as PgClientExtended; let contextManager: AsyncHooksContextManager; - const provider = new BasicTracerProvider(); + const provider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('external'); const instrumentationConfig: PgInstrumentationConfig & InstrumentationConfig = {}; - before(() => { - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - }); - beforeEach(() => { contextManager = new AsyncHooksContextManager().enable(); context.setGlobalContextManager(contextManager); diff --git a/plugins/node/opentelemetry-instrumentation-pino/test/pino.test.ts b/plugins/node/opentelemetry-instrumentation-pino/test/pino.test.ts index 6f03e197cd..3c3f805ee6 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/test/pino.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pino/test/pino.test.ts @@ -45,11 +45,10 @@ import { PACKAGE_NAME, PACKAGE_VERSION } from '../src/version'; import type { pino as Pino } from 'pino'; -const tracerProvider = new NodeTracerProvider(); +const tracerProvider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(new InMemorySpanExporter())], +}); tracerProvider.register(); -tracerProvider.addSpanProcessor( - new SimpleSpanProcessor(new InMemorySpanExporter()) -); const tracer = tracerProvider.getTracer('default'); // Setup LoggerProvider for "log sending" tests. diff --git a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts index 13113a2f3d..23f9cd3512 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts @@ -68,7 +68,9 @@ const unsetStatus: SpanStatus = { }; describe('redis@2.x', () => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], + }); const tracer = provider.getTracer('external'); let redis: typeof redisTypes; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; @@ -98,7 +100,6 @@ describe('redis@2.x', () => { } redis = require('redis'); - provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); instrumentation.setTracerProvider(provider); instrumentation.enable(); }); diff --git a/plugins/node/opentelemetry-instrumentation-restify/README.md b/plugins/node/opentelemetry-instrumentation-restify/README.md index 1894864da5..3115cba564 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/README.md +++ b/plugins/node/opentelemetry-instrumentation-restify/README.md @@ -27,9 +27,12 @@ const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ] +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts b/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts index ee7e6c524e..e5af1a6c6a 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/test/restify.test.ts @@ -118,10 +118,11 @@ const createServer = async (setupRoutes?: Function) => { }; describe('Restify Instrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); plugin.setTracerProvider(provider); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-router/README.md b/plugins/node/opentelemetry-instrumentation-router/README.md index 7145d3b8a3..254541ae96 100644 --- a/plugins/node/opentelemetry-instrumentation-router/README.md +++ b/plugins/node/opentelemetry-instrumentation-router/README.md @@ -27,9 +27,12 @@ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { RouterInstrumentation } = require('@opentelemetry/instrumentation-router'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts index 4958ca77f0..c7ca4d9eb9 100644 --- a/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts @@ -152,10 +152,11 @@ const spans = { }; describe('Router instrumentation', () => { - const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); - provider.addSpanProcessor(spanProcessor); + const provider = new NodeTracerProvider({ + spanProcessors: [spanProcessor], + }); plugin.setTracerProvider(provider); const tracer = provider.getTracer('default'); let contextManager: AsyncHooksContextManager; diff --git a/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts b/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts index 2ecb4eab37..7da83449cd 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts +++ b/plugins/node/opentelemetry-instrumentation-winston/test/winston.test.ts @@ -35,9 +35,10 @@ import type { Winston2Logger, Winston3Logger } from '../src/internal-types'; import { WinstonInstrumentation } from '../src'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(memoryExporter)], +}); const tracer = provider.getTracer('default'); -provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); context.setGlobalContextManager(new AsyncHooksContextManager()); const loggerProvider = new LoggerProvider(); diff --git a/plugins/web/opentelemetry-instrumentation-document-load/README.md b/plugins/web/opentelemetry-instrumentation-document-load/README.md index c672add7a5..d127ac0d51 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/README.md +++ b/plugins/web/opentelemetry-instrumentation-document-load/README.md @@ -26,9 +26,11 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { B3Propagator } from '@opentelemetry/propagator-b3'; import { CompositePropagator, W3CTraceContextPropagator } from '@opentelemetry/core'; -const provider = new WebTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); provider.register({ propagator: new CompositePropagator({ diff --git a/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts b/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts index cbe4b0c7b3..017bddc563 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts +++ b/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts @@ -48,10 +48,11 @@ import { EventNames } from '../src/enums/EventNames'; const assert = chai.assert; const exporter = new InMemorySpanExporter(); -const provider = new BasicTracerProvider(); const spanProcessor = new SimpleSpanProcessor(exporter); +const provider = new BasicTracerProvider({ + spanProcessors: [spanProcessor], +}); -provider.addSpanProcessor(spanProcessor); provider.register(); const resources = [ diff --git a/plugins/web/opentelemetry-instrumentation-long-task/README.md b/plugins/web/opentelemetry-instrumentation-long-task/README.md index 5239e006b5..e14aff098b 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/README.md +++ b/plugins/web/opentelemetry-instrumentation-long-task/README.md @@ -23,9 +23,11 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; import { LongTaskInstrumentation } from '@opentelemetry/instrumentation-long-task'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; -const provider = new WebTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); registerInstrumentations({ tracerProvider: provider, diff --git a/plugins/web/opentelemetry-instrumentation-long-task/test/compatibility.test.ts b/plugins/web/opentelemetry-instrumentation-long-task/test/compatibility.test.ts index d3404d19ae..bbc227d640 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/test/compatibility.test.ts +++ b/plugins/web/opentelemetry-instrumentation-long-task/test/compatibility.test.ts @@ -38,11 +38,10 @@ describe("LongTaskInstrumentation doesn't throw in unsupported environments", () let dummySpanExporter: DummySpanExporter; before(() => { - webTracerProvider = new WebTracerProvider(); dummySpanExporter = new DummySpanExporter(); - webTracerProvider.addSpanProcessor( - new tracing.SimpleSpanProcessor(dummySpanExporter) - ); + webTracerProvider = new WebTracerProvider({ + spanProcessors: [new tracing.SimpleSpanProcessor(dummySpanExporter)], + }); webTracerProvider.register(); }); diff --git a/plugins/web/opentelemetry-instrumentation-long-task/test/longTask.test.ts b/plugins/web/opentelemetry-instrumentation-long-task/test/longTask.test.ts index c65ed71e63..4feb913583 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/test/longTask.test.ts +++ b/plugins/web/opentelemetry-instrumentation-long-task/test/longTask.test.ts @@ -60,12 +60,11 @@ describe('LongTaskInstrumentation', () => { beforeEach(() => { sandbox = sinon.createSandbox(); - webTracerProvider = new WebTracerProvider(); dummySpanExporter = new DummySpanExporter(); exportSpy = sandbox.stub(dummySpanExporter, 'export'); - webTracerProvider.addSpanProcessor( - new tracing.SimpleSpanProcessor(dummySpanExporter) - ); + webTracerProvider = new WebTracerProvider({ + spanProcessors: [new tracing.SimpleSpanProcessor(dummySpanExporter)], + }); webTracerProvider.register(); longTaskInstrumentation = new LongTaskInstrumentation({ diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/README.md b/plugins/web/opentelemetry-instrumentation-user-interaction/README.md index 9d4f98bcb7..05f76a002b 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/README.md +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/README.md @@ -32,10 +32,12 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; // import { ZoneContextManager } from '@opentelemetry/context-zone-peer-dep'; const provider = new WebTracerProvider({ - contextManager: new ZoneContextManager() + contextManager: new ZoneContextManager(), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts index 57fa3faba1..f1d4231329 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts @@ -90,13 +90,11 @@ describe('UserInteractionInstrumentation', () => { sandbox.useFakeTimers(); - webTracerProvider = new WebTracerProvider(); - dummySpanExporter = new DummySpanExporter(); exportSpy = sandbox.stub(dummySpanExporter, 'export'); - webTracerProvider.addSpanProcessor( - new tracing.SimpleSpanProcessor(dummySpanExporter) - ); + webTracerProvider = new WebTracerProvider({ + spanProcessors: [new tracing.SimpleSpanProcessor(dummySpanExporter)], + }); webTracerProvider.register(); registerTestInstrumentations(); diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts index 792387e8c5..46b9f52daf 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts @@ -95,13 +95,11 @@ describe('UserInteractionInstrumentation', () => { sandbox.useFakeTimers(); - webTracerProvider = new WebTracerProvider(); dummySpanExporter = new DummySpanExporter(); exportSpy = sandbox.stub(dummySpanExporter, 'export'); - webTracerProvider.addSpanProcessor( - new tracing.SimpleSpanProcessor(dummySpanExporter) - ); - + webTracerProvider = new WebTracerProvider({ + spanProcessors: [new tracing.SimpleSpanProcessor(dummySpanExporter)], + }); webTracerProvider.register({ contextManager, }); diff --git a/plugins/web/opentelemetry-plugin-react-load/test/BaseOpenTelemetryComponent.test.ts b/plugins/web/opentelemetry-plugin-react-load/test/BaseOpenTelemetryComponent.test.ts index 2636e20338..323044bdc7 100644 --- a/plugins/web/opentelemetry-plugin-react-load/test/BaseOpenTelemetryComponent.test.ts +++ b/plugins/web/opentelemetry-plugin-react-load/test/BaseOpenTelemetryComponent.test.ts @@ -68,11 +68,11 @@ describe('ReactLoad Instrumentation', () => { contextManager = new StackContextManager().enable(); context.setGlobalContextManager(contextManager); - provider = new BasicTracerProvider(); - dummyExporter = new DummyExporter(); spanProcessor = new SimpleSpanProcessor(dummyExporter); - provider.addSpanProcessor(spanProcessor); + provider = new BasicTracerProvider({ + spanProcessors: [spanProcessor], + }); sandbox = sinon.createSandbox(); trace.setGlobalTracerProvider(provider);