From 1536a7cbb2078812e9953aff8b1ed0ee53dfff7e Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Fri, 4 Nov 2022 02:53:54 +0800 Subject: [PATCH] feat(api): merge api-metrics into api (#3374) Co-authored-by: Marc Pichler --- .github/workflows/unit-test.yml | 12 +- CHANGELOG.md | 2 + api-metrics/.eslintrc.js | 8 - api-metrics/LICENSE | 201 ------------------ api-metrics/README.md | 98 --------- api-metrics/karma.conf.js | 24 --- api-metrics/package.json | 87 -------- api-metrics/src/index.ts | 54 ----- api-metrics/src/internal/global-utils.ts | 96 --------- api-metrics/src/internal/semver.ts | 140 ------------ .../src/platform/browser/globalThis.ts | 35 --- api-metrics/test/api/api.test.ts | 49 ----- api-metrics/test/index-webpack.ts | 20 -- api-metrics/test/internal/global.test.ts | 118 ---------- api-metrics/test/internal/semver.test.ts | 148 ------------- api-metrics/test/types/Metric.test.ts | 109 ---------- api-metrics/tsconfig.all.json | 9 - api-metrics/tsconfig.docs.json | 15 -- api-metrics/tsconfig.esm.json | 11 - api-metrics/tsconfig.esnext.json | 11 - api-metrics/tsconfig.json | 16 -- {api-metrics => api}/.eslintignore | 0 api/TODO.md | 11 - api/package.json | 8 +- {api-metrics => api}/src/api/metrics.ts | 15 +- .../index.ts => api/src/context-api.ts | 6 +- api/src/diag-api.ts | 26 +++ api/src/diag/index.ts | 18 -- api/src/index.ts | 163 +++++++++----- api/src/internal/global-utils.ts | 4 +- .../index.ts => api/src/metrics-api.ts | 6 +- .../src/types => api/src/metrics}/Meter.ts | 0 .../src/metrics}/MeterProvider.ts | 0 .../src/types => api/src/metrics}/Metric.ts | 7 +- .../src => api/src/metrics}/NoopMeter.ts | 4 +- .../src/metrics}/NoopMeterProvider.ts | 4 +- .../src/metrics}/ObservableResult.ts | 0 api/src/platform/browser/globalThis.ts | 3 +- .../index.ts => api/src/propagation-api.ts | 6 +- .../globalThis.ts => api/src/trace-api.ts | 8 +- api/test/{ => common}/api/api.test.ts | 41 +++- api/test/{ => common}/baggage/Baggage.test.ts | 2 +- .../context/NoopContextManager.test.ts | 4 +- .../{ => common}/diag/ComponentLogger.test.ts | 2 +- .../{ => common}/diag/consoleLogger.test.ts | 2 +- api/test/{ => common}/diag/logLevel.test.ts | 8 +- api/test/{ => common}/diag/logger.test.ts | 6 +- api/test/{ => common}/internal/global.test.ts | 12 +- api/test/{ => common}/internal/semver.test.ts | 4 +- .../test/common}/internal/version.test.ts | 4 +- api/test/common/metrics/Metric.test.ts | 109 ++++++++++ .../noop-implementations/noop-meter.test.ts | 4 +- .../noop-implementations/noop-span.test.ts | 4 +- .../noop-tracer-provider.test.ts | 4 +- .../noop-implementations/noop-tracer.test.ts | 6 +- .../proxy-tracer.test.ts | 6 +- .../trace/spancontext-utils.test.ts | 4 +- .../trace/tracestate-validators.test.ts | 2 +- .../{ => common}/trace/tracestate.test.ts | 4 +- api/test/index-webpack.ts | 7 +- api/test/index-webpack.worker.ts | 2 +- api/test/internal/version.test.ts | 30 --- api/test/tree-shaking/tree-shaking.test.ts | 119 +++++++++++ .../examples/metrics/index.js | 3 +- examples/opentelemetry-web/package.json | 3 +- examples/otlp-exporter-node/package.json | 3 +- experimental/examples/prometheus/package.json | 2 +- experimental/packages/api-logs/README.md | 4 +- .../package.json | 5 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../browser/CollectorMetricExporter.test.ts | 3 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../src/PrometheusSerializer.ts | 10 +- .../test/PrometheusExporter.test.ts | 4 +- .../test/PrometheusSerializer.test.ts | 2 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../src/instrumentation.ts | 3 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../src/http.ts | 5 +- .../src/utils.ts | 2 +- .../tsconfig.json | 3 - .../package.json | 5 +- .../src/autoLoader.ts | 3 +- .../src/autoLoaderUtils.ts | 3 +- .../src/instrumentation.ts | 4 +- .../src/types.ts | 3 +- .../src/types_internal.ts | 3 +- .../test/common/autoLoader.test.ts | 11 +- .../tsconfig.esnext.json | 5 - .../tsconfig.json | 3 - .../opentelemetry-sdk-metrics/README.md | 4 +- .../opentelemetry-sdk-metrics/package.json | 5 +- .../src/InstrumentDescriptor.ts | 2 +- .../src/Instruments.ts | 58 +++-- .../opentelemetry-sdk-metrics/src/Meter.ts | 55 +++-- .../src/MeterProvider.ts | 23 +- .../src/ObservableResult.ts | 30 +-- .../src/aggregator/types.ts | 3 +- ...AlignedHistogramBucketExemplarReservoir.ts | 3 +- .../exemplar/AlwaysSampleExemplarFilter.ts | 3 +- .../src/exemplar/Exemplar.ts | 3 +- .../src/exemplar/ExemplarFilter.ts | 3 +- .../src/exemplar/ExemplarReservoir.ts | 3 +- .../src/exemplar/NeverSampleExemplarFilter.ts | 3 +- .../SimpleFixedSizeExemplarReservoir.ts | 3 +- .../src/exemplar/WithTraceExemplarFilter.ts | 3 +- .../src/export/MetricData.ts | 3 +- .../src/state/DeltaMetricProcessor.ts | 3 +- .../src/state/HashMap.ts | 2 +- .../src/state/MultiWritableMetricStorage.ts | 3 +- .../src/state/ObservableRegistry.ts | 6 +- .../src/state/SyncMetricStorage.ts | 3 +- .../src/state/WritableMetricStorage.ts | 3 +- .../opentelemetry-sdk-metrics/src/utils.ts | 2 +- .../src/view/AttributesProcessor.ts | 3 +- .../test/Instruments.test.ts | 2 +- .../test/Meter.test.ts | 2 +- .../test/ObservableResult.test.ts | 2 +- .../test/aggregator/Histogram.test.ts | 3 +- .../test/export/ConsoleMetricExporter.test.ts | 2 +- .../export/InMemoryMetricExporter.test.ts | 2 +- .../test/state/HashMap.test.ts | 2 +- .../test/state/MetricStorageRegistry.test.ts | 5 +- .../state/MultiWritableMetricStorage.test.ts | 2 +- .../opentelemetry-sdk-metrics/test/util.ts | 6 +- .../test/utils.test.ts | 2 +- .../tsconfig.esm.json | 5 - .../tsconfig.esnext.json | 5 - .../opentelemetry-sdk-metrics/tsconfig.json | 3 - .../opentelemetry-sdk-node/package.json | 5 +- .../opentelemetry-sdk-node/src/sdk.ts | 3 +- .../opentelemetry-sdk-node/test/sdk.test.ts | 2 +- .../opentelemetry-sdk-node/tsconfig.json | 3 - .../packages/otlp-transformer/package.json | 5 +- .../otlp-transformer/src/metrics/internal.ts | 2 +- .../otlp-transformer/test/metrics.test.ts | 2 +- .../packages/otlp-transformer/tsconfig.json | 3 - lerna.json | 1 - .../src/platform/browser/globalThis.ts | 3 +- tsconfig.base.json | 1 + tsconfig.json | 4 - 150 files changed, 698 insertions(+), 1687 deletions(-) delete mode 100644 api-metrics/.eslintrc.js delete mode 100644 api-metrics/LICENSE delete mode 100644 api-metrics/README.md delete mode 100644 api-metrics/karma.conf.js delete mode 100644 api-metrics/package.json delete mode 100644 api-metrics/src/index.ts delete mode 100644 api-metrics/src/internal/global-utils.ts delete mode 100644 api-metrics/src/internal/semver.ts delete mode 100644 api-metrics/src/platform/browser/globalThis.ts delete mode 100644 api-metrics/test/api/api.test.ts delete mode 100644 api-metrics/test/index-webpack.ts delete mode 100644 api-metrics/test/internal/global.test.ts delete mode 100644 api-metrics/test/internal/semver.test.ts delete mode 100644 api-metrics/test/types/Metric.test.ts delete mode 100644 api-metrics/tsconfig.all.json delete mode 100644 api-metrics/tsconfig.docs.json delete mode 100644 api-metrics/tsconfig.esm.json delete mode 100644 api-metrics/tsconfig.esnext.json delete mode 100644 api-metrics/tsconfig.json rename {api-metrics => api}/.eslintignore (100%) delete mode 100644 api/TODO.md rename {api-metrics => api}/src/api/metrics.ts (81%) rename api-metrics/src/platform/index.ts => api/src/context-api.ts (72%) create mode 100644 api/src/diag-api.ts delete mode 100644 api/src/diag/index.ts rename api-metrics/src/platform/browser/index.ts => api/src/metrics-api.ts (72%) rename {api-metrics/src/types => api/src/metrics}/Meter.ts (100%) rename {api-metrics/src/types => api/src/metrics}/MeterProvider.ts (100%) rename {api-metrics/src/types => api/src/metrics}/Metric.ts (95%) rename {api-metrics/src => api/src/metrics}/NoopMeter.ts (98%) rename {api-metrics/src => api/src/metrics}/NoopMeterProvider.ts (90%) rename {api-metrics/src/types => api/src/metrics}/ObservableResult.ts (100%) rename api-metrics/src/platform/node/index.ts => api/src/propagation-api.ts (70%) rename api-metrics/src/platform/node/globalThis.ts => api/src/trace-api.ts (72%) rename api/test/{ => common}/api/api.test.ts (85%) rename api/test/{ => common}/baggage/Baggage.test.ts (99%) rename api/test/{ => common}/context/NoopContextManager.test.ts (95%) rename api/test/{ => common}/diag/ComponentLogger.test.ts (96%) rename api/test/{ => common}/diag/consoleLogger.test.ts (99%) rename api/test/{ => common}/diag/logLevel.test.ts (96%) rename api/test/{ => common}/diag/logger.test.ts (94%) rename api/test/{ => common}/internal/global.test.ts (93%) rename api/test/{ => common}/internal/semver.test.ts (97%) rename {api-metrics/test => api/test/common}/internal/version.test.ts (90%) create mode 100644 api/test/common/metrics/Metric.test.ts rename {api-metrics/test => api/test/common}/noop-implementations/noop-meter.test.ts (97%) rename api/test/{ => common}/noop-implementations/noop-span.test.ts (94%) rename api/test/{ => common}/noop-implementations/noop-tracer-provider.test.ts (88%) rename api/test/{ => common}/noop-implementations/noop-tracer.test.ts (93%) rename api/test/{ => common}/proxy-implementations/proxy-tracer.test.ts (97%) rename api/test/{ => common}/trace/spancontext-utils.test.ts (96%) rename api/test/{ => common}/trace/tracestate-validators.test.ts (96%) rename api/test/{ => common}/trace/tracestate.test.ts (97%) delete mode 100644 api/test/internal/version.test.ts create mode 100644 api/test/tree-shaking/tree-shaking.test.ts diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 734bd6b29d..618e168e1e 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -47,10 +47,15 @@ jobs: - name: Build 🔧 run: | - npm run compile + npx lerna run compile - name: Unit tests - run: npm run test + run: | + # TODO(legendecas): webpack https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported + if [ "${{ matrix.node_version }}" = "18" ]; then + export NODE_OPTIONS=--openssl-legacy-provider + fi + npm run test - name: Report Coverage run: npm run codecov if: ${{ matrix.node_version == '14' }} @@ -88,7 +93,8 @@ jobs: - name: Build 🔧 run: | - npm run compile + npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" + npx lerna run compile - name: Unit tests run: npm run test diff --git a/CHANGELOG.md b/CHANGELOG.md index 79881b78dd..ce8e916111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. ### :boom: Breaking Change +* feat(api): merge api-metrics into api [#3374](https://github.com/open-telemetry/opentelemetry-js/pull/3374) @legendecas + ### :rocket: (Enhancement) * feat(sdk-trace): re-export sdk-trace-base in sdk-trace-node and web [#3319](https://github.com/open-telemetry/opentelemetry-js/pull/3319) @legendecas diff --git a/api-metrics/.eslintrc.js b/api-metrics/.eslintrc.js deleted file mode 100644 index 7d5c10c7f9..0000000000 --- a/api-metrics/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - "env": { - "mocha": true, - "commonjs": true, - "shared-node-browser": true - }, - ...require('../eslint.config.js') -} diff --git a/api-metrics/LICENSE b/api-metrics/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/api-metrics/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/api-metrics/README.md b/api-metrics/README.md deleted file mode 100644 index d9e8745ec7..0000000000 --- a/api-metrics/README.md +++ /dev/null @@ -1,98 +0,0 @@ -# OpenTelemetry API for JavaScript - -[![NPM Published Version][npm-img]][npm-url] -[![Apache License][license-image]][license-image] - -**Note: This is an experimental package under active development. New releases may include breaking changes.** - -This package provides everything needed to interact with the unstable OpenTelemetry Metrics API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser. - -## Beta Software - Use at your own risk - -The metrics API is considered alpha software and there is no guarantee of stability or long-term support. When the API is stabilized, it will be made available and supported long-term in the `@opentelemetry/api` package and this package will be deprecated. - -## Quick Start - -To get started you need to install the SDK and instrumentations, create a MeterProvider, and register it with the API. - -### Install Dependencies - -```sh -$ # Install metrics dependencies -$ npm install \ - @opentelemetry/api-metrics \ - @opentelemetry/sdk-metrics \ - @opentelemetry/exporter-prometheus # add exporters as needed -``` - -> Note: this example is for node.js. See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a browser example. - -### Initialize the SDK - -Before any other module in your application is loaded, you must initialize the global tracer and meter providers. If you fail to initialize a provider, no-op implementations will be provided to any library which acquires them from the API. - -To collect traces and metrics, you will have to tell the SDK where to export telemetry data to. This example uses Jaeger and Prometheus, but exporters exist for [other tracing backends][other-tracing-backends]. If you're not sure if there is an exporter for your tracing backend, contact your tracing provider. - -#### Metrics - -```javascript -const api = require("@opentelemetry/api-metrics"); -const { MeterProvider } = require("@opentelemetry/sdk-metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); - -// The Prometheus exporter runs an HTTP server which the Prometheus backend -// scrapes to collect metrics. -const exporter = new PrometheusExporter({ startServer: true }); -// Creates MeterProvider and installs the exporter as a MetricReader -const meterProvider = new MeterProvider(); -meterProvider.addMetricReader(exporter); - -/** - * Registering the provider with the API allows it to be discovered - * and used by instrumentation libraries. - */ -api.metrics.setGlobalMeterProvider(meterProvider); -``` - -## Version Compatibility - -Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same `node_modules` structure, the OpenTelemetry API takes advantage of a variable on the `global` object to store the global API. When an API method in the API package is called, it checks if this `global` API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API. - -## Advanced Use - -### API Methods - -If you are writing an instrumentation library, or prefer to call the API methods directly rather than using the `register` method on the Tracer/Meter Provider, OpenTelemetry provides direct access to the underlying API methods through the `@opentelemetry/api-metrics` package. API entry points are defined as global singleton objects `trace`, `metrics`, `propagation`, and `context` which contain methods used to initialize SDK implementations and acquire resources from the API. - -- [Metrics API Documentation][metrics-api-docs] - -```javascript -const api = require("@opentelemetry/api-metrics"); - -/* Initialize MeterProvider */ -api.metrics.setGlobalMeterProvider(meterProvider); -/* returns meterProvider (no-op if a working provider has not been initialized) */ -api.metrics.getMeterProvider(); -/* returns a meter from the registered global meter provider (no-op if a working provider has not been initialized) */ -api.metrics.getMeter(name, version); -``` - -## Useful links - -- For more information on OpenTelemetry, visit: -- For more about OpenTelemetry JavaScript: -- For help or feedback on this project, join us in [GitHub Discussions][discussions-url] - -## License - -Apache 2.0 - See [LICENSE][license-url] for more information. - -[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions -[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE -[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[npm-url]: https://www.npmjs.com/package/@opentelemetry/api-metrics -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fapi-metrics.svg - -[metrics-api-docs]: https://open-telemetry.github.io/opentelemetry-js/modules/_opentelemetry_api_metrics.html - -[other-tracing-backends]: https://github.com/open-telemetry/opentelemetry-js#trace-exporters diff --git a/api-metrics/karma.conf.js b/api-metrics/karma.conf.js deleted file mode 100644 index 29b7b9bc5a..0000000000 --- a/api-metrics/karma.conf.js +++ /dev/null @@ -1,24 +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 - * - * 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. - */ - -const karmaWebpackConfig = require('../karma.webpack'); -const karmaBaseConfig = require('../karma.base'); - -module.exports = (config) => { - config.set(Object.assign({}, karmaBaseConfig, { - webpack: karmaWebpackConfig - })) -}; diff --git a/api-metrics/package.json b/api-metrics/package.json deleted file mode 100644 index fc920cbb19..0000000000 --- a/api-metrics/package.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "name": "@opentelemetry/api-metrics", - "version": "1.0.0", - "description": "Public metrics API for OpenTelemetry", - "main": "build/src/index.js", - "module": "build/esm/index.js", - "esnext": "build/esnext/index.js", - "types": "build/src/index.d.ts", - "browser": { - "./src/platform/index.ts": "./src/platform/browser/index.ts", - "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", - "./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js", - "./build/src/platform/index.js": "./build/src/platform/browser/index.js" - }, - "repository": "open-telemetry/opentelemetry-js", - "scripts": { - "prepublishOnly": "npm run compile", - "compile": "tsc --build tsconfig.all.json", - "clean": "tsc --build --clean tsconfig.all.json", - "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", - "test:browser": "nyc karma start --single-run", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../", - "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../", - "build": "npm run compile", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", - "version": "node ../scripts/version-update.js", - "watch": "tsc --build --watch tsconfig.all.json", - "precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies", - "prewatch": "node ../scripts/version-update.js" - }, - "keywords": [ - "opentelemetry", - "nodejs", - "browser", - "profiling", - "metrics", - "stats", - "monitoring" - ], - "author": "OpenTelemetry Authors", - "license": "Apache-2.0", - "engines": { - "node": ">=14" - }, - "files": [ - "build/esm/**/*.js", - "build/esm/**/*.js.map", - "build/esm/**/*.d.ts", - "build/esnext/**/*.js", - "build/esnext/**/*.js.map", - "build/esnext/**/*.d.ts", - "build/src/**/*.js", - "build/src/**/*.js.map", - "build/src/**/*.d.ts", - "doc", - "LICENSE", - "README.md" - ], - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@opentelemetry/api": "^1.0.0" - }, - "devDependencies": { - "@types/mocha": "10.0.0", - "@types/node": "18.6.5", - "@types/webpack-env": "1.16.3", - "codecov": "3.8.3", - "istanbul-instrumenter-loader": "3.0.1", - "karma": "6.3.16", - "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", - "karma-mocha": "2.0.1", - "karma-spec-reporter": "0.0.32", - "karma-webpack": "4.0.2", - "mocha": "10.0.0", - "nyc": "15.1.0", - "ts-loader": "8.4.0", - "ts-mocha": "10.0.0", - "typescript": "4.4.4", - "webpack": "4.46.0" - }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-api-metrics", - "sideEffects": false -} diff --git a/api-metrics/src/index.ts b/api-metrics/src/index.ts deleted file mode 100644 index 5a59fe2d96..0000000000 --- a/api-metrics/src/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. - */ - -export { - createNoopMeter, -} from './NoopMeter'; - -export { - MeterOptions, - Meter, -} from './types/Meter'; - -export { - MeterProvider, -} from './types/MeterProvider'; - -export { - ValueType, - Counter, - Histogram, - MetricOptions, - Observable, - ObservableCounter, - ObservableGauge, - ObservableUpDownCounter, - UpDownCounter, - BatchObservableCallback, - MetricAttributes, - MetricAttributeValue, - ObservableCallback, -} from './types/Metric'; - -export { - BatchObservableResult, - ObservableResult, -} from './types/ObservableResult'; - -import { MetricsAPI } from './api/metrics'; - -/** Entrypoint for metrics API */ -export const metrics = MetricsAPI.getInstance(); diff --git a/api-metrics/src/internal/global-utils.ts b/api-metrics/src/internal/global-utils.ts deleted file mode 100644 index f83c203398..0000000000 --- a/api-metrics/src/internal/global-utils.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { diag } from '@opentelemetry/api'; -import { _globalThis } from '../platform'; -import { MeterProvider } from '../types/MeterProvider'; -import { VERSION } from '../version'; -import { isCompatible } from './semver'; - -const major = VERSION.split('.')[0]; -const GLOBAL_OPENTELEMETRY_METRICS_API_KEY = Symbol.for( - `opentelemetry.js.api.metrics.${major}` -); - -const _global = _globalThis as OTelGlobal; - -export function registerGlobal( - type: Type, - instance: OTelGlobalAPI[Type], - allowOverride = false -): boolean { - const api = (_global[GLOBAL_OPENTELEMETRY_METRICS_API_KEY] = _global[ - GLOBAL_OPENTELEMETRY_METRICS_API_KEY - ] ?? { - version: VERSION, - }); - - if (!allowOverride && api[type]) { - // already registered an API of this type - const err = new Error( - `@opentelemetry/api: Attempted duplicate registration of API: ${type}` - ); - diag.error(err.stack || err.message); - return false; - } - - if (api.version !== VERSION) { - // All registered APIs must be of the same version exactly - const err = new Error( - '@opentelemetry/api: All API registration versions must match' - ); - diag.error(err.stack || err.message); - return false; - } - - api[type] = instance; - diag.debug( - `@opentelemetry/api: Registered a global for ${type} v${VERSION}.` - ); - - return true; -} - -export function getGlobal( - type: Type -): OTelGlobalAPI[Type] | undefined { - const globalVersion = _global[GLOBAL_OPENTELEMETRY_METRICS_API_KEY]?.version; - if (!globalVersion || !isCompatible(globalVersion)) { - return; - } - return _global[GLOBAL_OPENTELEMETRY_METRICS_API_KEY]?.[type]; -} - -export function unregisterGlobal(type: keyof OTelGlobalAPI) { - diag.debug( - `@opentelemetry/api-metrics: Unregistering a global for ${type} v${VERSION}.` - ); - const api = _global[GLOBAL_OPENTELEMETRY_METRICS_API_KEY]; - - if (api) { - delete api[type]; - } -} - -type OTelGlobal = { - [GLOBAL_OPENTELEMETRY_METRICS_API_KEY]?: OTelGlobalAPI; -}; - -type OTelGlobalAPI = { - version: string; - - metrics?: MeterProvider; -}; diff --git a/api-metrics/src/internal/semver.ts b/api-metrics/src/internal/semver.ts deleted file mode 100644 index 076f9b9b51..0000000000 --- a/api-metrics/src/internal/semver.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { VERSION } from '../version'; - -const re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/; - -/** - * Create a function to test an API version to see if it is compatible with the provided ownVersion. - * - * The returned function has the following semantics: - * - Exact match is always compatible - * - Major versions must match exactly - * - 1.x package cannot use global 2.x package - * - 2.x package cannot use global 1.x package - * - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API - * - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects - * - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3 - * - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor - * - Patch and build tag differences are not considered at this time - * - * @param ownVersion version which should be checked against - */ -export function _makeCompatibilityCheck( - ownVersion: string -): (globalVersion: string) => boolean { - const acceptedVersions = new Set([ownVersion]); - const rejectedVersions = new Set(); - - const myVersionMatch = ownVersion.match(re); - if (!myVersionMatch) { - // we cannot guarantee compatibility so we always return noop - return () => false; - } - - const ownVersionParsed = { - major: +myVersionMatch[1], - minor: +myVersionMatch[2], - patch: +myVersionMatch[3], - prerelease: myVersionMatch[4], - }; - - // if ownVersion has a prerelease tag, versions must match exactly - if (ownVersionParsed.prerelease != null) { - return function isExactmatch(globalVersion: string): boolean { - return globalVersion === ownVersion; - }; - } - - function _reject(v: string) { - rejectedVersions.add(v); - return false; - } - - function _accept(v: string) { - acceptedVersions.add(v); - return true; - } - - return function isCompatible(globalVersion: string): boolean { - if (acceptedVersions.has(globalVersion)) { - return true; - } - - if (rejectedVersions.has(globalVersion)) { - return false; - } - - const globalVersionMatch = globalVersion.match(re); - if (!globalVersionMatch) { - // cannot parse other version - // we cannot guarantee compatibility so we always noop - return _reject(globalVersion); - } - - const globalVersionParsed = { - major: +globalVersionMatch[1], - minor: +globalVersionMatch[2], - patch: +globalVersionMatch[3], - prerelease: globalVersionMatch[4], - }; - - // if globalVersion has a prerelease tag, versions must match exactly - if (globalVersionParsed.prerelease != null) { - return _reject(globalVersion); - } - - // major versions must match - if (ownVersionParsed.major !== globalVersionParsed.major) { - return _reject(globalVersion); - } - - if (ownVersionParsed.major === 0) { - if ( - ownVersionParsed.minor === globalVersionParsed.minor && - ownVersionParsed.patch <= globalVersionParsed.patch - ) { - return _accept(globalVersion); - } - - return _reject(globalVersion); - } - - if (ownVersionParsed.minor <= globalVersionParsed.minor) { - return _accept(globalVersion); - } - - return _reject(globalVersion); - }; -} - -/** - * Test an API version to see if it is compatible with this API. - * - * - Exact match is always compatible - * - Major versions must match exactly - * - 1.x package cannot use global 2.x package - * - 2.x package cannot use global 1.x package - * - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API - * - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects - * - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3 - * - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor - * - Patch and build tag differences are not considered at this time - * - * @param version version of the API requesting an instance of the global API - */ -export const isCompatible = _makeCompatibilityCheck(VERSION); diff --git a/api-metrics/src/platform/browser/globalThis.ts b/api-metrics/src/platform/browser/globalThis.ts deleted file mode 100644 index 1dece570f3..0000000000 --- a/api-metrics/src/platform/browser/globalThis.ts +++ /dev/null @@ -1,35 +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. - */ - -// Updates to this file should also be replicated to @opentelemetry/api and -// @opentelemetry/core too. - -/** - * - globalThis (New standard) - * - self (Will return the current window instance for supported browsers) - * - window (fallback for older browser implementations) - * - global (NodeJS implementation) - * - (When all else fails) - */ - -/** only globals that common to node and browsers are allowed */ -// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef -export const _globalThis: typeof globalThis = - typeof globalThis === 'object' ? globalThis : - typeof self === 'object' ? self : - typeof window === 'object' ? window : - typeof global === 'object' ? global : - {} as typeof globalThis; diff --git a/api-metrics/test/api/api.test.ts b/api-metrics/test/api/api.test.ts deleted file mode 100644 index 66278d6bc7..0000000000 --- a/api-metrics/test/api/api.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as assert from 'assert'; -import { metrics } from '../../src'; -import { NoopMeter } from '../../src/NoopMeter'; -import { NoopMeterProvider } from '../../src/NoopMeterProvider'; - - -describe('API', () => { - it('should expose a meter provider via getMeterProvider', () => { - const meter = metrics.getMeterProvider(); - assert.ok(meter); - assert.strictEqual(typeof meter, 'object'); - }); - - describe('GlobalMeterProvider', () => { - const dummyMeter = new NoopMeter(); - - beforeEach(() => { - metrics.disable(); - }); - - it('should use the global meter provider', () => { - metrics.setGlobalMeterProvider(new TestMeterProvider()); - const meter = metrics.getMeterProvider().getMeter('name'); - assert.deepStrictEqual(meter, dummyMeter); - }); - - class TestMeterProvider extends NoopMeterProvider { - override getMeter() { - return dummyMeter; - } - } - }); -}); diff --git a/api-metrics/test/index-webpack.ts b/api-metrics/test/index-webpack.ts deleted file mode 100644 index 061a48ccfa..0000000000 --- a/api-metrics/test/index-webpack.ts +++ /dev/null @@ -1,20 +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. - */ -const testsContext = require.context('.', true, /test$/); -testsContext.keys().forEach(testsContext); - -const srcContext = require.context('.', true, /src$/); -srcContext.keys().forEach(srcContext); diff --git a/api-metrics/test/internal/global.test.ts b/api-metrics/test/internal/global.test.ts deleted file mode 100644 index e239728706..0000000000 --- a/api-metrics/test/internal/global.test.ts +++ /dev/null @@ -1,118 +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 assert from 'assert'; -import { getGlobal } from '../../src/internal/global-utils'; -import { _globalThis } from '../../src/platform'; -import { NoopMeterProvider } from '../../src/NoopMeterProvider'; -import sinon = require('sinon'); -import { diag } from '@opentelemetry/api'; - -const api1 = require('../../src') as typeof import('../../src'); - -// clear cache and load a second instance of the api -for (const key of Object.keys(require.cache)) { - delete require.cache[key]; -} -const api2 = require('../../src') as typeof import('../../src'); - -// This will need to be changed manually on major version changes. -// It is intentionally not autogenerated to ensure the author of the change is aware of what they are doing. -const GLOBAL_METRICS_API_SYMBOL_KEY = 'opentelemetry.js.api.metrics.1'; - -const getMockLogger = () => ({ - verbose: sinon.spy(), - debug: sinon.spy(), - info: sinon.spy(), - warn: sinon.spy(), - error: sinon.spy(), -}); - -describe('Global Utils', () => { - // prove they are separate instances - assert.notEqual(api1, api2); - // that return separate noop instances to start - assert.notStrictEqual( - api1.metrics.getMeterProvider(), - api2.metrics.getMeterProvider(), - ); - - beforeEach(() => { - api1.metrics.disable(); - // @ts-expect-error we are modifying internals for testing purposes here - delete _globalThis[Symbol.for(GLOBAL_METRICS_API_SYMBOL_KEY)]; - }); - - it('should change the global meter provider', () => { - const original = api1.metrics.getMeterProvider(); - const newMeterProvider = new NoopMeterProvider(); - api1.metrics.setGlobalMeterProvider(newMeterProvider); - assert.notStrictEqual(api1.metrics.getMeterProvider(), original); - assert.strictEqual(api1.metrics.getMeterProvider(), newMeterProvider); - }); - - it('should load an instance from one which was set in the other', () => { - api1.metrics.setGlobalMeterProvider(new NoopMeterProvider()); - assert.strictEqual( - api1.metrics.getMeterProvider(), - api2.metrics.getMeterProvider() - ); - }); - - it('should disable both if one is disabled', () => { - const manager = new NoopMeterProvider(); - api1.metrics.setGlobalMeterProvider(manager); - - assert.strictEqual(manager, api1.metrics.getMeterProvider()); - api2.metrics.disable(); - assert.notStrictEqual(manager, api1.metrics.getMeterProvider()); - }); - - it('should return the module NoOp implementation if the version is a mismatch', () => { - const newMeterProvider = new NoopMeterProvider(); - api1.metrics.setGlobalMeterProvider(newMeterProvider); - - // ensure new meter provider is returned - assert.strictEqual(api1.metrics.getMeterProvider(), newMeterProvider); - - const globalInstance = getGlobal('metrics'); - assert.ok(globalInstance); - // @ts-expect-error we are modifying internals for testing purposes here - _globalThis[Symbol.for(GLOBAL_METRICS_API_SYMBOL_KEY)].version = '0.0.1'; - - // ensure new meter provider is not returned because version above is incompatible - assert.notStrictEqual( - api1.metrics.getMeterProvider(), - newMeterProvider - ); - }); - - it('should log an error if there is a duplicate registration', () => { - const logger = getMockLogger(); - diag.setLogger(logger); - - api1.metrics.setGlobalMeterProvider(new NoopMeterProvider()); - api1.metrics.setGlobalMeterProvider(new NoopMeterProvider()); - - sinon.assert.calledOnce(logger.error); - assert.strictEqual(logger.error.firstCall.args.length, 1); - assert.ok( - logger.error.firstCall.args[0].startsWith( - 'Error: @opentelemetry/api: Attempted duplicate registration of API: metrics' - ) - ); - }); -}); diff --git a/api-metrics/test/internal/semver.test.ts b/api-metrics/test/internal/semver.test.ts deleted file mode 100644 index e9ac3ec727..0000000000 --- a/api-metrics/test/internal/semver.test.ts +++ /dev/null @@ -1,148 +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 assert from 'assert'; -import { - isCompatible, - _makeCompatibilityCheck, -} from '../../src/internal/semver'; -import { VERSION } from '../../src/version'; - -describe('semver', () => { - it('should be compatible if versions are equal', () => { - assert.ok(isCompatible(VERSION)); - }); - - it('returns false if own version cannot be parsed', () => { - const check = _makeCompatibilityCheck('this is not semver'); - assert.ok(!check('1.0.0')); - }); - - it('incompatible if other version cannot be parsed', () => { - const check = _makeCompatibilityCheck('0.1.2'); - assert.ok(!check('this is not semver')); - }); - - describe('>= 1.0.0', () => { - const globalVersion = '5.5.5'; - const vers: [string, boolean][] = [ - // same major/minor run should be compatible - ['5.5.5', true], - ['5.5.6', true], - ['5.5.4', true], - - // prerelease version should not be compatible - ['5.5.5-rc.0', false], - - // if our version has a minor version increase, we may try to call methods which don't exist on the global - ['5.6.5', false], - ['5.6.6', false], - ['5.6.4', false], - - // if the global version is ahead of us by a minor revision, it has at least the methods we know about - ['5.4.5', true], - ['5.4.6', true], - ['5.4.4', true], - - // major version mismatch is always incompatible - ['6.5.5', false], - ['6.5.6', false], - ['6.5.4', false], - ['6.6.5', false], - ['6.6.6', false], - ['6.6.4', false], - ['6.4.5', false], - ['6.4.6', false], - ['6.4.4', false], - ['4.5.5', false], - ['4.5.6', false], - ['4.5.4', false], - ['4.6.5', false], - ['4.6.6', false], - ['4.6.4', false], - ['4.4.5', false], - ['4.4.6', false], - ['4.4.4', false], - ]; - - test(globalVersion, vers); - }); - - describe('< 1.0.0', () => { - const globalVersion = '0.5.5'; - const vers: [string, boolean][] = [ - // same minor/patch should be compatible - ['0.5.5', true], - - // prerelease version should not be compatible - ['0.5.5-rc.0', false], - - // if our version has a patch version increase, we may try to call methods which don't exist on the global - ['0.5.6', false], - - // if the global version is ahead of us by a patch revision, it has at least the methods we know about - ['0.5.4', true], - - // minor version mismatch is always incompatible - ['0.6.5', false], - ['0.6.6', false], - ['0.6.4', false], - ['0.4.5', false], - ['0.4.6', false], - ['0.4.4', false], - - // major version mismatch is always incompatible - ['1.5.5', false], - ['1.5.6', false], - ['1.5.4', false], - ['1.6.5', false], - ['1.6.6', false], - ['1.6.4', false], - ['1.4.5', false], - ['1.4.6', false], - ['1.4.4', false], - ]; - - test(globalVersion, vers); - }); - - describe('global version is prerelease', () => { - const globalVersion = '1.0.0-rc.3'; - const vers: [string, boolean][] = [ - // must match exactly - ['1.0.0', false], - ['1.0.0-rc.2', false], - ['1.0.0-rc.4', false], - - ['1.0.0-rc.3', true], - ]; - - test(globalVersion, vers); - }); -}); - -function test(globalVersion: string, vers: [string, boolean][]) { - describe(`global version is ${globalVersion}`, () => { - for (const [version, compatible] of vers) { - it(`API version ${version} ${ - compatible ? 'should' : 'should not' - } be able to access global`, () => { - const check = _makeCompatibilityCheck(version); - assert.strictEqual(check(globalVersion), compatible); - }); - } - }); -} diff --git a/api-metrics/test/types/Metric.test.ts b/api-metrics/test/types/Metric.test.ts deleted file mode 100644 index a499db168f..0000000000 --- a/api-metrics/test/types/Metric.test.ts +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Counter, UpDownCounter, Histogram } from '../../src'; - -describe('Metric', () => { - describe('Counter', () =>{ - it('enable not to define any type', () => { - const counter: Counter = { - add(_value: number, _attribute: unknown) {} - }; - counter.add(1, { 'some-attribute': 'value' }); - }); - - it('enable to use with type', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: Counter = { - add(_value: number, _attribute: Attributes) {} - }; - counter.add(1, { 'some-attribute': 'value' }); - }); - - it('disable wrong attributes by typing', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: Counter = { - add(_value: number, _attribute: Attributes) {} - }; - // @ts-expect-error Expacting the type of Attributes - counter.add(1, { 'another-attribute': 'value' }); - }); - }); - - describe('UpDownCounter', () =>{ - it('enable not to define any type', () => { - const counter: UpDownCounter = { - add(_value: number, _attribute: unknown) {} - }; - counter.add(1, { 'some-attribute': 'value' }); - }); - - it('enable to use with type', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: UpDownCounter = { - add(_value: number, _attribute: Attributes) {} - }; - counter.add(1, { 'some-attribute': 'value' }); - }); - - it('disable wrong attributes by typing', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: UpDownCounter = { - add(_value: number, _attribute: Attributes) {} - }; - // @ts-expect-error Expacting the type of Attributes - counter.add(1, { 'another-attribute': 'value' }); - }); - }); - - describe('Histogram', () =>{ - it('enable not to define any type', () => { - const counter: Histogram = { - record(_value: number, _attribute: unknown) {} - }; - counter.record(1, { 'some-attribute': 'value' }); - }); - - it('enable to use with type', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: Histogram = { - record(_value: number, _attribute: Attributes) {} - }; - counter.record(1, { 'some-attribute': 'value' }); - }); - - it('disable wrong attributes by typing', () => { - type Attributes = { - 'some-attribute': string - }; - const counter: Histogram = { - record(_value: number, _attribute: Attributes) {} - }; - // @ts-expect-error Expacting the type of Attributes - counter.record(1, { 'another-attribute': 'value' }); - }); - }); -}); diff --git a/api-metrics/tsconfig.all.json b/api-metrics/tsconfig.all.json deleted file mode 100644 index 4aa747e89f..0000000000 --- a/api-metrics/tsconfig.all.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.base.json", - "files": [], - "references": [ - { "path": "./tsconfig.json" }, - { "path": "./tsconfig.esm.json" }, - { "path": "./tsconfig.esnext.json" } - ] -} diff --git a/api-metrics/tsconfig.docs.json b/api-metrics/tsconfig.docs.json deleted file mode 100644 index 627fa3ff3e..0000000000 --- a/api-metrics/tsconfig.docs.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts" - ], - "typedocOptions": { - "name": "OpenTelemetry API for JavaScript", - "out": "docs/out", - "mode": "file", - "hideGenerator": true - } -} diff --git a/api-metrics/tsconfig.esm.json b/api-metrics/tsconfig.esm.json deleted file mode 100644 index 50611a86af..0000000000 --- a/api-metrics/tsconfig.esm.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../tsconfig.base.esm.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "build/esm", - "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" - }, - "include": [ - "src/**/*.ts" - ] -} diff --git a/api-metrics/tsconfig.esnext.json b/api-metrics/tsconfig.esnext.json deleted file mode 100644 index 0e3427cbc1..0000000000 --- a/api-metrics/tsconfig.esnext.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../tsconfig.base.esnext.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "build/esnext", - "tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo" - }, - "include": [ - "src/**/*.ts" - ] -} diff --git a/api-metrics/tsconfig.json b/api-metrics/tsconfig.json deleted file mode 100644 index e8b7e27e71..0000000000 --- a/api-metrics/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../tsconfig.base.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ], - "references": [ - { - "path": "../api" - } - ] -} diff --git a/api-metrics/.eslintignore b/api/.eslintignore similarity index 100% rename from api-metrics/.eslintignore rename to api/.eslintignore diff --git a/api/TODO.md b/api/TODO.md deleted file mode 100644 index 30f67e54ec..0000000000 --- a/api/TODO.md +++ /dev/null @@ -1,11 +0,0 @@ -# TODO - -These tasks must be completed before the API package can be released from this repository. - -- [x] remove files specific to the API git repo -- [x] add to lerna monorepo - - [x] add tsconfig files - - [x] add web testing - - [x] build esm versions -- [ ] test node versions 8, 10, and 12 -- [x] add to auto published docs diff --git a/api/package.json b/api/package.json index 4fb085886d..799ea8ab95 100644 --- a/api/package.json +++ b/api/package.json @@ -24,7 +24,7 @@ "lint:fix": "eslint . --ext .ts --fix", "lint": "eslint . --ext .ts", "test:browser": "nyc karma start --single-run", - "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "test:webworker": "nyc karma start karma.worker.js --single-run", "cycle-check": "dpdm --exit-code circular:1 src/index.ts", "version": "node ../scripts/version-update.js", @@ -63,6 +63,7 @@ "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/sinon": "10.0.13", + "@types/webpack": "4.41.26", "@types/webpack-env": "1.16.3", "codecov": "3.8.3", "dpdm": "3.10.0", @@ -74,13 +75,16 @@ "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.32", "karma-webpack": "4.0.2", + "memfs": "3.4.9", "mocha": "10.0.0", "nyc": "15.1.0", "sinon": "14.0.0", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", "typescript": "4.4.4", + "unionfs": "4.4.0", "webpack": "4.46.0" }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api" + "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api", + "sideEffects": false } diff --git a/api-metrics/src/api/metrics.ts b/api/src/api/metrics.ts similarity index 81% rename from api-metrics/src/api/metrics.ts rename to api/src/api/metrics.ts index b3f9bac6b6..5353d84b91 100644 --- a/api-metrics/src/api/metrics.ts +++ b/api/src/api/metrics.ts @@ -14,10 +14,13 @@ * limitations under the License. */ -import { Meter, MeterOptions } from '../types/Meter'; -import { MeterProvider } from '../types/MeterProvider'; -import { NOOP_METER_PROVIDER } from '../NoopMeterProvider'; +import { Meter, MeterOptions } from '../metrics/Meter'; +import { MeterProvider } from '../metrics/MeterProvider'; +import { NOOP_METER_PROVIDER } from '../metrics/NoopMeterProvider'; import { getGlobal, registerGlobal, unregisterGlobal } from '../internal/global-utils'; +import { DiagAPI } from './diag'; + +const API_NAME = 'metrics'; /** * Singleton object which represents the entry point to the OpenTelemetry Metrics API @@ -42,14 +45,14 @@ export class MetricsAPI { * Returns true if the meter provider was successfully registered, else false. */ public setGlobalMeterProvider(provider: MeterProvider): boolean { - return registerGlobal('metrics', provider); + return registerGlobal(API_NAME, provider, DiagAPI.instance()); } /** * Returns the global meter provider. */ public getMeterProvider(): MeterProvider { - return getGlobal('metrics') || NOOP_METER_PROVIDER; + return getGlobal(API_NAME) || NOOP_METER_PROVIDER; } /** @@ -61,6 +64,6 @@ export class MetricsAPI { /** Remove the global meter provider */ public disable(): void { - unregisterGlobal('metrics'); + unregisterGlobal(API_NAME, DiagAPI.instance()); } } diff --git a/api-metrics/src/platform/index.ts b/api/src/context-api.ts similarity index 72% rename from api-metrics/src/platform/index.ts rename to api/src/context-api.ts index cdaf8858ce..db474def26 100644 --- a/api-metrics/src/platform/index.ts +++ b/api/src/context-api.ts @@ -14,4 +14,8 @@ * limitations under the License. */ -export * from './node'; +// Split module-level variable definition into separate files to allow +// tree-shaking on each api instance. +import { ContextAPI } from './api/context'; +/** Entrypoint for context API */ +export const context = ContextAPI.getInstance(); diff --git a/api/src/diag-api.ts b/api/src/diag-api.ts new file mode 100644 index 0000000000..ecad84caf4 --- /dev/null +++ b/api/src/diag-api.ts @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Split module-level variable definition into separate files to allow +// tree-shaking on each api instance. +import { DiagAPI } from './api/diag'; +/** + * Entrypoint for Diag API. + * Defines Diagnostic handler used for internal diagnostic logging operations. + * The default provides a Noop DiagLogger implementation which may be changed via the + * diag.setLogger(logger: DiagLogger) function. + */ +export const diag = DiagAPI.instance(); diff --git a/api/src/diag/index.ts b/api/src/diag/index.ts deleted file mode 100644 index 751b5eeda2..0000000000 --- a/api/src/diag/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export * from './consoleLogger'; -export * from './types'; diff --git a/api/src/index.ts b/api/src/index.ts index 72825b0806..63325fa97e 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -14,75 +14,132 @@ * limitations under the License. */ -export * from './baggage/types'; +export { + BaggageEntry, + BaggageEntryMetadata, + Baggage, +} from './baggage/types'; export { baggageEntryMetadataFromString } from './baggage/utils'; -export * from './common/Exception'; -export * from './common/Time'; -export * from './common/Attributes'; -export * from './diag'; -export * from './propagation/TextMapPropagator'; -export * from './trace/attributes'; -export * from './trace/link'; -export * from './trace/ProxyTracer'; -export * from './trace/ProxyTracerProvider'; -export * from './trace/Sampler'; -export * from './trace/SamplingResult'; -export * from './trace/span_context'; -export * from './trace/span_kind'; -export * from './trace/span'; -export * from './trace/SpanOptions'; -export * from './trace/status'; -export * from './trace/trace_flags'; -export * from './trace/trace_state'; -export { createTraceState } from './trace/internal/utils'; -export * from './trace/tracer_provider'; -export * from './trace/tracer'; -export * from './trace/tracer_options'; +export { Exception } from './common/Exception'; +export { HrTime, TimeInput } from './common/Time'; +export { Attributes, AttributeValue } from './common/Attributes'; + +// Context APIs +export { + createContextKey, + ROOT_CONTEXT, +} from './context/context'; +export { + Context, + ContextManager, +} from './context/types'; +export type { ContextAPI } from './api/context'; + +// Diag APIs +export { DiagConsoleLogger } from './diag/consoleLogger'; +export { + DiagLogFunction, + DiagLogger, + DiagLogLevel, + ComponentLoggerOptions, +} from './diag/types'; +export type { DiagAPI } from './api/diag'; + +// Metrics APIs +export { + createNoopMeter, +} from './metrics/NoopMeter'; +export { + MeterOptions, + Meter, +} from './metrics/Meter'; +export { + MeterProvider, +} from './metrics/MeterProvider'; +export { + ValueType, + Counter, + Histogram, + MetricOptions, + Observable, + ObservableCounter, + ObservableGauge, + ObservableUpDownCounter, + UpDownCounter, + BatchObservableCallback, + MetricAttributes, + MetricAttributeValue, + ObservableCallback, +} from './metrics/Metric'; +export { + BatchObservableResult, + ObservableResult, +} from './metrics/ObservableResult'; +// Propagation APIs +export { + TextMapPropagator, + TextMapSetter, + TextMapGetter, + defaultTextMapGetter, + defaultTextMapSetter, +} from './propagation/TextMapPropagator'; +export type { PropagationAPI } from './api/propagation'; + +// Trace APIs +export { + SpanAttributes, + SpanAttributeValue, +} from './trace/attributes'; +export { Link } from './trace/link'; +export { ProxyTracer, TracerDelegator } from './trace/ProxyTracer'; +export { ProxyTracerProvider } from './trace/ProxyTracerProvider'; +export { Sampler } from './trace/Sampler'; +export { SamplingDecision, SamplingResult } from './trace/SamplingResult'; +export { SpanContext } from './trace/span_context'; +export { SpanKind } from './trace/span_kind'; +export { Span } from './trace/span'; +export { SpanOptions } from './trace/SpanOptions'; +export { SpanStatus, SpanStatusCode } from './trace/status'; +export { TraceFlags } from './trace/trace_flags'; +export { TraceState } from './trace/trace_state'; +export { createTraceState } from './trace/internal/utils'; +export { TracerProvider } from './trace/tracer_provider'; +export { Tracer } from './trace/tracer'; +export { TracerOptions } from './trace/tracer_options'; export { isSpanContextValid, isValidTraceId, isValidSpanId, } from './trace/spancontext-utils'; - export { INVALID_SPANID, INVALID_TRACEID, INVALID_SPAN_CONTEXT, } from './trace/invalid-span-constants'; - -export * from './context/context'; -export * from './context/types'; - -import { ContextAPI } from './api/context'; -export type { ContextAPI } from './api/context'; -/** Entrypoint for context API */ -export const context = ContextAPI.getInstance(); - -import { TraceAPI } from './api/trace'; export type { TraceAPI } from './api/trace'; -/** Entrypoint for trace API */ -export const trace = TraceAPI.getInstance(); -import { PropagationAPI } from './api/propagation'; -export type { PropagationAPI } from './api/propagation'; -/** Entrypoint for propagation API */ -export const propagation = PropagationAPI.getInstance(); - -import { DiagAPI } from './api/diag'; -export type { DiagAPI } from './api/diag'; - -/** - * Entrypoint for Diag API. - * Defines Diagnostic handler used for internal diagnostic logging operations. - * The default provides a Noop DiagLogger implementation which may be changed via the - * diag.setLogger(logger: DiagLogger) function. - */ -export const diag = DiagAPI.instance(); +// Split module-level variable definition into separate files to allow +// tree-shaking on each api instance. +import { context } from './context-api'; +import { diag } from './diag-api'; +import { metrics } from './metrics-api'; +import { propagation } from './propagation-api'; +import { trace } from './trace-api'; -export default { - trace, +// Named export. +export { context, + diag, + metrics, propagation, + trace, +}; +// Default export. +export default { + context, diag, + metrics, + propagation, + trace, }; diff --git a/api/src/internal/global-utils.ts b/api/src/internal/global-utils.ts index 5306aa503b..0753bc2775 100644 --- a/api/src/internal/global-utils.ts +++ b/api/src/internal/global-utils.ts @@ -14,8 +14,9 @@ * limitations under the License. */ +import { MeterProvider } from '../metrics/MeterProvider'; import { ContextManager } from '../context/types'; -import { DiagLogger } from '../diag'; +import { DiagLogger } from '../diag/types'; import { _globalThis } from '../platform'; import { TextMapPropagator } from '../propagation/TextMapPropagator'; import type { TracerProvider } from '../trace/tracer_provider'; @@ -98,5 +99,6 @@ type OTelGlobalAPI = { diag?: DiagLogger; trace?: TracerProvider; context?: ContextManager; + metrics?: MeterProvider; propagation?: TextMapPropagator; }; diff --git a/api-metrics/src/platform/browser/index.ts b/api/src/metrics-api.ts similarity index 72% rename from api-metrics/src/platform/browser/index.ts rename to api/src/metrics-api.ts index e9d6ebed71..16f399a22e 100644 --- a/api-metrics/src/platform/browser/index.ts +++ b/api/src/metrics-api.ts @@ -14,4 +14,8 @@ * limitations under the License. */ -export * from './globalThis'; +// Split module-level variable definition into separate files to allow +// tree-shaking on each api instance. +import { MetricsAPI } from './api/metrics'; +/** Entrypoint for metrics API */ +export const metrics = MetricsAPI.getInstance(); diff --git a/api-metrics/src/types/Meter.ts b/api/src/metrics/Meter.ts similarity index 100% rename from api-metrics/src/types/Meter.ts rename to api/src/metrics/Meter.ts diff --git a/api-metrics/src/types/MeterProvider.ts b/api/src/metrics/MeterProvider.ts similarity index 100% rename from api-metrics/src/types/MeterProvider.ts rename to api/src/metrics/MeterProvider.ts diff --git a/api-metrics/src/types/Metric.ts b/api/src/metrics/Metric.ts similarity index 95% rename from api-metrics/src/types/Metric.ts rename to api/src/metrics/Metric.ts index 6ca013766f..b20cfa4662 100644 --- a/api-metrics/src/types/Metric.ts +++ b/api/src/metrics/Metric.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { Context, SpanAttributes, SpanAttributeValue } from '@opentelemetry/api'; +import { Attributes, AttributeValue } from '../common/Attributes'; +import { Context } from '../context/types'; import { BatchObservableResult, ObservableResult } from './ObservableResult'; /** @@ -88,7 +89,7 @@ export interface Histogram { }); }); }); + + describe('Global metrics', () => { + it('should expose a meter provider via getMeterProvider', () => { + const meter = metrics.getMeterProvider(); + assert.ok(meter); + assert.strictEqual(typeof meter, 'object'); + }); + + describe('GlobalMeterProvider', () => { + const dummyMeter = new NoopMeter(); + + beforeEach(() => { + metrics.disable(); + }); + + it('should use the global meter provider', () => { + metrics.setGlobalMeterProvider(new TestMeterProvider()); + const meter = metrics.getMeterProvider().getMeter('name'); + assert.deepStrictEqual(meter, dummyMeter); + }); + + class TestMeterProvider extends NoopMeterProvider { + override getMeter() { + return dummyMeter; + } + } + }); + }); }); diff --git a/api/test/baggage/Baggage.test.ts b/api/test/common/baggage/Baggage.test.ts similarity index 99% rename from api/test/baggage/Baggage.test.ts rename to api/test/common/baggage/Baggage.test.ts index 080b6a4193..81895306c0 100644 --- a/api/test/baggage/Baggage.test.ts +++ b/api/test/common/baggage/Baggage.test.ts @@ -19,7 +19,7 @@ import { ROOT_CONTEXT, propagation, baggageEntryMetadataFromString, -} from '../../src'; +} from '../../../src'; describe('Baggage', () => { describe('create', () => { diff --git a/api/test/context/NoopContextManager.test.ts b/api/test/common/context/NoopContextManager.test.ts similarity index 95% rename from api/test/context/NoopContextManager.test.ts rename to api/test/common/context/NoopContextManager.test.ts index 8a8a732bf7..8d257971b0 100644 --- a/api/test/context/NoopContextManager.test.ts +++ b/api/test/common/context/NoopContextManager.test.ts @@ -15,8 +15,8 @@ */ import * as assert from 'assert'; -import { createContextKey, ROOT_CONTEXT } from '../../src/context/context'; -import { NoopContextManager } from '../../src/context/NoopContextManager'; +import { createContextKey, ROOT_CONTEXT } from '../../../src/context/context'; +import { NoopContextManager } from '../../../src/context/NoopContextManager'; describe('NoopContextManager', () => { let contextManager: NoopContextManager; diff --git a/api/test/diag/ComponentLogger.test.ts b/api/test/common/diag/ComponentLogger.test.ts similarity index 96% rename from api/test/diag/ComponentLogger.test.ts rename to api/test/common/diag/ComponentLogger.test.ts index b9648c218a..2a01cf2e98 100644 --- a/api/test/diag/ComponentLogger.test.ts +++ b/api/test/common/diag/ComponentLogger.test.ts @@ -16,7 +16,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; -import { diag, DiagLogger, DiagLogLevel } from '../../src'; +import { diag, DiagLogger, DiagLogLevel } from '../../../src'; class SpyLogger implements DiagLogger { debug() {} diff --git a/api/test/diag/consoleLogger.test.ts b/api/test/common/diag/consoleLogger.test.ts similarity index 99% rename from api/test/diag/consoleLogger.test.ts rename to api/test/common/diag/consoleLogger.test.ts index fd57f11836..781acd93b0 100644 --- a/api/test/diag/consoleLogger.test.ts +++ b/api/test/common/diag/consoleLogger.test.ts @@ -17,7 +17,7 @@ /* eslint-disable no-console */ import * as assert from 'assert'; -import { DiagConsoleLogger } from '../../src/diag/consoleLogger'; +import { DiagConsoleLogger } from '../../../src/diag/consoleLogger'; export const diagLoggerFunctions = [ 'verbose', diff --git a/api/test/diag/logLevel.test.ts b/api/test/common/diag/logLevel.test.ts similarity index 96% rename from api/test/diag/logLevel.test.ts rename to api/test/common/diag/logLevel.test.ts index 1825db31a9..065e46d683 100644 --- a/api/test/diag/logLevel.test.ts +++ b/api/test/common/diag/logLevel.test.ts @@ -15,10 +15,10 @@ */ import * as assert from 'assert'; -import { diag } from '../../src'; -import { createLogLevelDiagLogger } from '../../src/diag/internal/logLevelLogger'; -import { createNoopDiagLogger } from '../../src/diag/internal/noopLogger'; -import { DiagLogger, DiagLogLevel } from '../../src/diag/types'; +import { diag } from '../../../src'; +import { createLogLevelDiagLogger } from '../../../src/diag/internal/logLevelLogger'; +import { createNoopDiagLogger } from '../../../src/diag/internal/noopLogger'; +import { DiagLogger, DiagLogLevel } from '../../../src/diag/types'; // Matches the previous Logger definition const incompleteLoggerFuncs = ['debug', 'info', 'warn', 'error'] as const; diff --git a/api/test/diag/logger.test.ts b/api/test/common/diag/logger.test.ts similarity index 94% rename from api/test/diag/logger.test.ts rename to api/test/common/diag/logger.test.ts index c0efdcb6f2..1b6f0d57ba 100644 --- a/api/test/diag/logger.test.ts +++ b/api/test/common/diag/logger.test.ts @@ -16,9 +16,9 @@ import * as assert from 'assert'; import sinon = require('sinon'); -import { diag, DiagLogLevel } from '../../src'; -import { createNoopDiagLogger } from '../../src/diag/internal/noopLogger'; -import { DiagLogger } from '../../src/diag/types'; +import { diag, DiagLogLevel } from '../../../src'; +import { createNoopDiagLogger } from '../../../src/diag/internal/noopLogger'; +import { DiagLogger } from '../../../src/diag/types'; export const diagLoggerFunctions = [ 'verbose', diff --git a/api/test/internal/global.test.ts b/api/test/common/internal/global.test.ts similarity index 93% rename from api/test/internal/global.test.ts rename to api/test/common/internal/global.test.ts index ba6218c7ed..291f707233 100644 --- a/api/test/internal/global.test.ts +++ b/api/test/common/internal/global.test.ts @@ -15,19 +15,19 @@ */ import * as assert from 'assert'; -import { getGlobal } from '../../src/internal/global-utils'; -import { _globalThis } from '../../src/platform'; -import { NoopContextManager } from '../../src/context/NoopContextManager'; -import { DiagLogLevel } from '../../src/diag/types'; +import { getGlobal } from '../../../src/internal/global-utils'; +import { _globalThis } from '../../../src/platform'; +import { NoopContextManager } from '../../../src/context/NoopContextManager'; +import { DiagLogLevel } from '../../../src/diag/types'; import sinon = require('sinon'); -const api1 = require('../../src') as typeof import('../../src'); +const api1 = require('../../../src') as typeof import('../../../src'); // clear cache and load a second instance of the api for (const key of Object.keys(require.cache)) { delete require.cache[key]; } -const api2 = require('../../src') as typeof import('../../src'); +const api2 = require('../../../src') as typeof import('../../../src'); // This will need to be changed manually on major version changes. // It is intentionally not autogenerated to ensure the author of the change is aware of what they are doing. diff --git a/api/test/internal/semver.test.ts b/api/test/common/internal/semver.test.ts similarity index 97% rename from api/test/internal/semver.test.ts rename to api/test/common/internal/semver.test.ts index e9ac3ec727..acd164b542 100644 --- a/api/test/internal/semver.test.ts +++ b/api/test/common/internal/semver.test.ts @@ -18,8 +18,8 @@ import * as assert from 'assert'; import { isCompatible, _makeCompatibilityCheck, -} from '../../src/internal/semver'; -import { VERSION } from '../../src/version'; +} from '../../../src/internal/semver'; +import { VERSION } from '../../../src/version'; describe('semver', () => { it('should be compatible if versions are equal', () => { diff --git a/api-metrics/test/internal/version.test.ts b/api/test/common/internal/version.test.ts similarity index 90% rename from api-metrics/test/internal/version.test.ts rename to api/test/common/internal/version.test.ts index 4d0e5f2542..cfffeb20fa 100644 --- a/api-metrics/test/internal/version.test.ts +++ b/api/test/common/internal/version.test.ts @@ -15,11 +15,11 @@ */ import * as assert from 'assert'; -import { VERSION } from '../../src/version'; +import { VERSION } from '../../../src/version'; describe('version', () => { it('should have generated VERSION.ts', () => { - const pjson = require('../../package.json'); + const pjson = require('../../../package.json'); assert.strictEqual(pjson.version, VERSION); }); diff --git a/api/test/common/metrics/Metric.test.ts b/api/test/common/metrics/Metric.test.ts new file mode 100644 index 0000000000..d7111d01f7 --- /dev/null +++ b/api/test/common/metrics/Metric.test.ts @@ -0,0 +1,109 @@ +/* + * 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 { Counter, UpDownCounter, Histogram } from '../../../src'; + +describe('Metric', () => { + describe('Counter', () =>{ + it('enable not to define any type', () => { + const counter: Counter = { + add(_value: number, _attribute: unknown) {} + }; + counter.add(1, { 'some-attribute': 'value' }); + }); + + it('enable to use with type', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: Counter = { + add(_value: number, _attribute: Attributes) {} + }; + counter.add(1, { 'some-attribute': 'value' }); + }); + + it('disable wrong attributes by typing', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: Counter = { + add(_value: number, _attribute: Attributes) {} + }; + // @ts-expect-error Expacting the type of Attributes + counter.add(1, { 'another-attribute': 'value' }); + }); + }); + + describe('UpDownCounter', () =>{ + it('enable not to define any type', () => { + const counter: UpDownCounter = { + add(_value: number, _attribute: unknown) {} + }; + counter.add(1, { 'some-attribute': 'value' }); + }); + + it('enable to use with type', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: UpDownCounter = { + add(_value: number, _attribute: Attributes) {} + }; + counter.add(1, { 'some-attribute': 'value' }); + }); + + it('disable wrong attributes by typing', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: UpDownCounter = { + add(_value: number, _attribute: Attributes) {} + }; + // @ts-expect-error Expacting the type of Attributes + counter.add(1, { 'another-attribute': 'value' }); + }); + }); + + describe('Histogram', () =>{ + it('enable not to define any type', () => { + const counter: Histogram = { + record(_value: number, _attribute: unknown) {} + }; + counter.record(1, { 'some-attribute': 'value' }); + }); + + it('enable to use with type', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: Histogram = { + record(_value: number, _attribute: Attributes) {} + }; + counter.record(1, { 'some-attribute': 'value' }); + }); + + it('disable wrong attributes by typing', () => { + type Attributes = { + 'some-attribute': string + }; + const counter: Histogram = { + record(_value: number, _attribute: Attributes) {} + }; + // @ts-expect-error Expacting the type of Attributes + counter.record(1, { 'another-attribute': 'value' }); + }); + }); +}); diff --git a/api-metrics/test/noop-implementations/noop-meter.test.ts b/api/test/common/noop-implementations/noop-meter.test.ts similarity index 97% rename from api-metrics/test/noop-implementations/noop-meter.test.ts rename to api/test/common/noop-implementations/noop-meter.test.ts index 07395a925b..951bdb80e7 100644 --- a/api-metrics/test/noop-implementations/noop-meter.test.ts +++ b/api/test/common/noop-implementations/noop-meter.test.ts @@ -24,8 +24,8 @@ import { NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC, NOOP_UP_DOWN_COUNTER_METRIC, createNoopMeter, -} from '../../src/NoopMeter'; -import { NoopMeterProvider } from '../../src/NoopMeterProvider'; +} from '../../../src/metrics/NoopMeter'; +import { NoopMeterProvider } from '../../../src/metrics/NoopMeterProvider'; const attributes = {}; const options = { diff --git a/api/test/noop-implementations/noop-span.test.ts b/api/test/common/noop-implementations/noop-span.test.ts similarity index 94% rename from api/test/noop-implementations/noop-span.test.ts rename to api/test/common/noop-implementations/noop-span.test.ts index de0007aeeb..5bc341f31a 100644 --- a/api/test/noop-implementations/noop-span.test.ts +++ b/api/test/common/noop-implementations/noop-span.test.ts @@ -20,8 +20,8 @@ import { INVALID_SPANID, INVALID_TRACEID, TraceFlags, -} from '../../src'; -import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan'; +} from '../../../src'; +import { NonRecordingSpan } from '../../../src/trace/NonRecordingSpan'; describe('NonRecordingSpan', () => { it('do not crash', () => { diff --git a/api/test/noop-implementations/noop-tracer-provider.test.ts b/api/test/common/noop-implementations/noop-tracer-provider.test.ts similarity index 88% rename from api/test/noop-implementations/noop-tracer-provider.test.ts rename to api/test/common/noop-implementations/noop-tracer-provider.test.ts index 5b7e5ff7b1..d9eda44ee9 100644 --- a/api/test/noop-implementations/noop-tracer-provider.test.ts +++ b/api/test/common/noop-implementations/noop-tracer-provider.test.ts @@ -15,8 +15,8 @@ */ import * as assert from 'assert'; -import { NoopTracer } from '../../src/trace/NoopTracer'; -import { NoopTracerProvider } from '../../src/trace/NoopTracerProvider'; +import { NoopTracer } from '../../../src/trace/NoopTracer'; +import { NoopTracerProvider } from '../../../src/trace/NoopTracerProvider'; describe('NoopTracerProvider', () => { it('should not crash', () => { diff --git a/api/test/noop-implementations/noop-tracer.test.ts b/api/test/common/noop-implementations/noop-tracer.test.ts similarity index 93% rename from api/test/noop-implementations/noop-tracer.test.ts rename to api/test/common/noop-implementations/noop-tracer.test.ts index 037017208e..429f6d481d 100644 --- a/api/test/noop-implementations/noop-tracer.test.ts +++ b/api/test/common/noop-implementations/noop-tracer.test.ts @@ -22,9 +22,9 @@ import { SpanKind, trace, TraceFlags, -} from '../../src'; -import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan'; -import { NoopTracer } from '../../src/trace/NoopTracer'; +} from '../../../src'; +import { NonRecordingSpan } from '../../../src/trace/NonRecordingSpan'; +import { NoopTracer } from '../../../src/trace/NoopTracer'; describe('NoopTracer', () => { it('should not crash', () => { diff --git a/api/test/proxy-implementations/proxy-tracer.test.ts b/api/test/common/proxy-implementations/proxy-tracer.test.ts similarity index 97% rename from api/test/proxy-implementations/proxy-tracer.test.ts rename to api/test/common/proxy-implementations/proxy-tracer.test.ts index bb9c55bfe1..9bf7e94409 100644 --- a/api/test/proxy-implementations/proxy-tracer.test.ts +++ b/api/test/common/proxy-implementations/proxy-tracer.test.ts @@ -26,9 +26,9 @@ import { SpanOptions, Tracer, TracerProvider, -} from '../../src'; -import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan'; -import { NoopTracer } from '../../src/trace/NoopTracer'; +} from '../../../src'; +import { NonRecordingSpan } from '../../../src/trace/NonRecordingSpan'; +import { NoopTracer } from '../../../src/trace/NoopTracer'; describe('ProxyTracer', () => { let provider: ProxyTracerProvider; diff --git a/api/test/trace/spancontext-utils.test.ts b/api/test/common/trace/spancontext-utils.test.ts similarity index 96% rename from api/test/trace/spancontext-utils.test.ts rename to api/test/common/trace/spancontext-utils.test.ts index 09f5712b27..e2d87f807d 100644 --- a/api/test/trace/spancontext-utils.test.ts +++ b/api/test/common/trace/spancontext-utils.test.ts @@ -15,8 +15,8 @@ */ import * as assert from 'assert'; -import * as context from '../../src/trace/spancontext-utils'; -import { INVALID_SPANID, INVALID_TRACEID, TraceFlags } from '../../src'; +import * as context from '../../../src/trace/spancontext-utils'; +import { INVALID_SPANID, INVALID_TRACEID, TraceFlags } from '../../../src'; describe('spancontext-utils', () => { it('should return true for valid spancontext', () => { diff --git a/api/test/trace/tracestate-validators.test.ts b/api/test/common/trace/tracestate-validators.test.ts similarity index 96% rename from api/test/trace/tracestate-validators.test.ts rename to api/test/common/trace/tracestate-validators.test.ts index 0f355f1c12..15f49434eb 100644 --- a/api/test/trace/tracestate-validators.test.ts +++ b/api/test/common/trace/tracestate-validators.test.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import { validateKey, validateValue } from '../../src/trace/internal/tracestate-validators'; +import { validateKey, validateValue } from '../../../src/trace/internal/tracestate-validators'; describe('validators', () => { describe('validateKey', () => { diff --git a/api/test/trace/tracestate.test.ts b/api/test/common/trace/tracestate.test.ts similarity index 97% rename from api/test/trace/tracestate.test.ts rename to api/test/common/trace/tracestate.test.ts index 699c6cd9cb..6d20195b43 100644 --- a/api/test/trace/tracestate.test.ts +++ b/api/test/common/trace/tracestate.test.ts @@ -15,8 +15,8 @@ */ import * as assert from 'assert'; -import { createTraceState } from '../../src/trace/internal/utils'; -import { TraceStateImpl } from '../../src/trace/internal/tracestate-impl'; +import { createTraceState } from '../../../src/trace/internal/utils'; +import { TraceStateImpl } from '../../../src/trace/internal/tracestate-impl'; describe('TraceState', () => { describe('.serialize()', () => { diff --git a/api/test/index-webpack.ts b/api/test/index-webpack.ts index 856be100b2..2d2ef32478 100644 --- a/api/test/index-webpack.ts +++ b/api/test/index-webpack.ts @@ -14,11 +14,6 @@ * limitations under the License. */ { - const testsContext = require.context('.', true, /test$/); + const testsContext = require.context('./common', true); testsContext.keys().forEach(testsContext); } - -{ - const srcContext = require.context('.', true, /src$/); - srcContext.keys().forEach(srcContext); -} diff --git a/api/test/index-webpack.worker.ts b/api/test/index-webpack.worker.ts index d568d570b1..2d2ef32478 100644 --- a/api/test/index-webpack.worker.ts +++ b/api/test/index-webpack.worker.ts @@ -14,6 +14,6 @@ * limitations under the License. */ { - const testsContext = require.context('./', true, /test$/); + const testsContext = require.context('./common', true); testsContext.keys().forEach(testsContext); } diff --git a/api/test/internal/version.test.ts b/api/test/internal/version.test.ts deleted file mode 100644 index 4d0e5f2542..0000000000 --- a/api/test/internal/version.test.ts +++ /dev/null @@ -1,30 +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 assert from 'assert'; -import { VERSION } from '../../src/version'; - -describe('version', () => { - it('should have generated VERSION.ts', () => { - const pjson = require('../../package.json'); - assert.strictEqual(pjson.version, VERSION); - }); - - it('prerelease tag versions are banned', () => { - // see https://github.com/open-telemetry/opentelemetry-js-api/issues/74 - assert.ok(VERSION.match(/^\d+\.\d+\.\d+$/)); - }); -}); diff --git a/api/test/tree-shaking/tree-shaking.test.ts b/api/test/tree-shaking/tree-shaking.test.ts new file mode 100644 index 0000000000..37ab5def3a --- /dev/null +++ b/api/test/tree-shaking/tree-shaking.test.ts @@ -0,0 +1,119 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as assert from 'assert'; +import * as webpack from 'webpack'; +import * as path from 'path'; +import { Union } from 'unionfs'; +import { fs as mfs } from 'memfs'; +import * as realFs from 'fs'; + +/** + * Verify that tree-shaking can be properly applied on the @opentelemetry/api package. + * Unused optional apis should be able to be removed from the final bundle. + */ +describe('tree-shaking', () => { + const allowedAPIs = ['ContextAPI', 'DiagAPI']; + const testAPIs = [ + { + name: 'MetricsAPI', + export: 'metrics', + }, + { + name: 'PropagationAPI', + export: 'propagation', + }, + { + name: 'TraceAPI', + export: 'trace' + }, + ]; + const APIMatcher = /(?:class|function) (\w+API)/g; + + const sourceCodePath = path.join(__dirname, 'test.js'); + const outputPath = path.join(__dirname, 'output'); + const outputFilename = path.join(outputPath, 'bundle.js'); + + afterEach(() => { + try { + mfs.unlinkSync(outputFilename); + } catch { + /** ignore */ + } + }); + + for (const testAPI of testAPIs) { + it(`verify ${testAPI.name}`, async () => { + const sourceCode = ` + import { ${testAPI.export} } from '../../'; + console.log(${testAPI.export}); + `; + mfs.mkdirpSync(path.dirname(sourceCodePath)); + mfs.writeFileSync(sourceCodePath, sourceCode, { encoding: 'utf8' }); + + const compiler = webpack({ + entry: sourceCodePath, + output: { + filename: 'bundle.js', + path: outputPath, + }, + mode: 'production', + optimization: { + // disable minimization so that we can inspect the output easily. + minimize: false, + } + }); + + const fs = new Union(); + fs.use(mfs as any) + .use(realFs); + + //direct webpack to use unionfs for file input + compiler.inputFileSystem = fs; + //direct webpack to output to memoryfs rather than to disk + compiler.outputFileSystem = { + ...mfs, + join: path.join, + } as any; + + const stats = await new Promise((resolve, reject) => { + compiler.run((err, stats) => { + if (err) { + return reject(err); + } + resolve(stats); + }); + }); + assert.deepStrictEqual(stats.compilation.errors, []); + assert.deepStrictEqual(stats.compilation.warnings, []); + + const outputFile = mfs.readFileSync(outputFilename, 'utf8') as string; + const matches = new Set(); + let match; + do { + match = APIMatcher.exec(outputFile); + if (match) { + matches.add(match[1]); + } + } while (match); + + // Remove allowed apis from checking list. + allowedAPIs.forEach(it => matches.delete(it)); + + assert.deepStrictEqual(Array.from(matches), [testAPI.name]); + }); + } +}); diff --git a/examples/opentelemetry-web/examples/metrics/index.js b/examples/opentelemetry-web/examples/metrics/index.js index e036f1e8d2..c3f86cfbe5 100644 --- a/examples/opentelemetry-web/examples/metrics/index.js +++ b/examples/opentelemetry-web/examples/metrics/index.js @@ -1,5 +1,4 @@ -const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api'); -const { metrics } = require('@opentelemetry/api-metrics'); +const { DiagConsoleLogger, DiagLogLevel, diag, metrics } = require('@opentelemetry/api'); const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http'); const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics'); diff --git a/examples/opentelemetry-web/package.json b/examples/opentelemetry-web/package.json index f99b49e3f7..966968275d 100644 --- a/examples/opentelemetry-web/package.json +++ b/examples/opentelemetry-web/package.json @@ -42,8 +42,7 @@ "webpack-merge": "^5.8.0" }, "dependencies": { - "@opentelemetry/api": "^1.0.2", - "@opentelemetry/api-metrics": "0.33.0", + "@opentelemetry/api": "^1.2.0", "@opentelemetry/context-zone": "1.7.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/exporter-metrics-otlp-http": "0.33.0", diff --git a/examples/otlp-exporter-node/package.json b/examples/otlp-exporter-node/package.json index 085d15917d..d122327991 100644 --- a/examples/otlp-exporter-node/package.json +++ b/examples/otlp-exporter-node/package.json @@ -28,8 +28,7 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "^1.1.0", - "@opentelemetry/api-metrics": "0.33.0", + "@opentelemetry/api": "^1.2.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/exporter-metrics-otlp-grpc": "0.33.0", "@opentelemetry/exporter-metrics-otlp-http": "0.33.0", diff --git a/experimental/examples/prometheus/package.json b/experimental/examples/prometheus/package.json index 837fcf9b61..96a9f5572d 100644 --- a/experimental/examples/prometheus/package.json +++ b/experimental/examples/prometheus/package.json @@ -9,7 +9,7 @@ "author": "OpenTelemetry Authors", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/api": "^1.0.2", + "@opentelemetry/api": "^1.2.0", "@opentelemetry/exporter-prometheus": "0.33.0", "@opentelemetry/sdk-metrics": "0.33.0" } diff --git a/experimental/packages/api-logs/README.md b/experimental/packages/api-logs/README.md index b0704800de..57d40a3211 100644 --- a/experimental/packages/api-logs/README.md +++ b/experimental/packages/api-logs/README.md @@ -58,6 +58,6 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions [license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[npm-url]: https://www.npmjs.com/package/@opentelemetry/api-metrics -[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fapi-metrics.svg +[npm-url]: https://www.npmjs.com/package/@opentelemetry/api-logs +[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fapi-logs.svg [logs-api-docs]: https://open-telemetry.github.io/opentelemetry-js/modules/_opentelemetry_api_logs.html diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json index d7dc5a21a8..e44641b004 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json @@ -49,8 +49,7 @@ "devDependencies": { "@babel/core": "7.16.0", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "^1.0.0", - "@opentelemetry/api-metrics": "0.33.0", + "@opentelemetry/api": "^1.2.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/sinon": "10.0.13", @@ -65,7 +64,7 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { "@grpc/grpc-js": "^1.7.1", diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts index 58922addc3..e7f2baa351 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Counter, Histogram, ObservableGauge, ObservableResult, ValueType } from '@opentelemetry/api-metrics'; +import { Counter, Histogram, ObservableGauge, ObservableResult, ValueType } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json index c2a6041ceb..d866e532c2 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index 0740d5913e..4b21d78f8f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -64,7 +64,7 @@ }, "devDependencies": { "@babel/core": "7.16.0", - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.2.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/sinon": "10.0.13", @@ -91,10 +91,9 @@ "webpack-merge": "5.8.0" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/otlp-exporter-base": "0.33.0", "@opentelemetry/otlp-transformer": "0.33.0", diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 166dbc4a81..c0cb9dc2ab 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { diag, DiagLogger, DiagLogLevel } from '@opentelemetry/api'; -import { Counter, Histogram, } from '@opentelemetry/api-metrics'; +import { diag, DiagLogger, DiagLogLevel, Counter, Histogram } from '@opentelemetry/api'; import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'; import { AggregationTemporality, ResourceMetrics, } from '@opentelemetry/sdk-metrics'; import * as assert from 'assert'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts index 0b15459815..5989d870f6 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts @@ -22,7 +22,7 @@ import { ObservableCounter, ObservableGauge, ObservableUpDownCounter, -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import * as assert from 'assert'; import { InstrumentationScope, VERSION } from '@opentelemetry/core'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json index 7a2d809dff..af647ba8e3 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json index bad7943e6e..bd21a3c040 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json @@ -48,8 +48,7 @@ }, "devDependencies": { "@babel/core": "7.16.0", - "@opentelemetry/api": "^1.0.0", - "@opentelemetry/api-metrics": "0.33.0", + "@opentelemetry/api": "^1.2.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/sinon": "10.0.13", @@ -64,7 +63,7 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { "@opentelemetry/core": "1.7.0", diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts index 2f62a8ba2c..ce3a70ff24 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts @@ -20,7 +20,7 @@ import { Histogram, ValueType, ObservableGauge, -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import * as assert from 'assert'; import { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json index 133b1e8bb8..521fc31cfe 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/opentelemetry-exporter-prometheus/package.json b/experimental/packages/opentelemetry-exporter-prometheus/package.json index bb841bacd4..9461ac2bca 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/package.json +++ b/experimental/packages/opentelemetry-exporter-prometheus/package.json @@ -43,7 +43,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.2.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/sinon": "10.0.13", @@ -56,10 +56,9 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/sdk-metrics": "0.33.0", "@opentelemetry/resources": "1.7.0" diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index 410cbfbf34..0879f16e87 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { diag } from '@opentelemetry/api'; +import { + diag, + MetricAttributes, + MetricAttributeValue, +} from '@opentelemetry/api'; import { ResourceMetrics, InstrumentType, @@ -24,10 +28,6 @@ import { DataPoint, Histogram, } from '@opentelemetry/sdk-metrics'; -import type { - MetricAttributes, - MetricAttributeValue -} from '@opentelemetry/api-metrics'; import { hrTimeToMilliseconds } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts index 6b60952670..3104348300 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts @@ -15,9 +15,10 @@ */ import { + Counter, Meter, ObservableResult -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; import { MeterProvider } from '@opentelemetry/sdk-metrics'; import * as assert from 'assert'; import * as sinon from 'sinon'; @@ -28,7 +29,6 @@ import { mockHrTime } from './util'; import { SinonStubbedInstance } from 'sinon'; -import { Counter } from '@opentelemetry/api-metrics'; const serializedEmptyResourceLines = [ '# HELP target_info Target metadata', diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 852946f355..2694c96f83 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -18,7 +18,7 @@ import * as assert from 'assert'; import { MetricAttributes, UpDownCounter -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; import { Aggregation, AggregationTemporality, diff --git a/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json b/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json index 9ac6b6fd90..719097c712 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/package.json b/experimental/packages/opentelemetry-instrumentation-grpc/package.json index 8d9f69ef1c..09f8ab2aff 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/package.json +++ b/experimental/packages/opentelemetry-instrumentation-grpc/package.json @@ -47,7 +47,7 @@ "devDependencies": { "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.2.0", "@opentelemetry/context-async-hooks": "1.7.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/sdk-trace-base": "1.7.0", @@ -68,10 +68,9 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/instrumentation": "0.33.0", "@opentelemetry/semantic-conventions": "1.7.0" }, diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts index 5ac237038a..d6f782684b 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts @@ -19,7 +19,6 @@ import { VERSION } from './version'; import { GrpcNativeInstrumentation } from './grpc'; import { GrpcJsInstrumentation } from './grpc-js'; import * as api from '@opentelemetry/api'; -import { MeterProvider } from '@opentelemetry/api-metrics'; /** The metadata key under which span context is stored as a binary value. */ export const GRPC_TRACE_KEY = 'grpc-trace-bin'; @@ -81,7 +80,7 @@ export class GrpcInstrumentation { * Sets MeterProvider to this plugin * @param meterProvider */ - public setMeterProvider(meterProvider: MeterProvider) { + public setMeterProvider(meterProvider: api.MeterProvider) { this._grpcJsInstrumentation.setMeterProvider(meterProvider); this._grpcNativeInstrumentation.setMeterProvider(meterProvider); } diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/tsconfig.json b/experimental/packages/opentelemetry-instrumentation-grpc/tsconfig.json index 25a8b5fb03..0170a84c3c 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation-grpc/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-context-async-hooks" }, diff --git a/experimental/packages/opentelemetry-instrumentation-http/package.json b/experimental/packages/opentelemetry-instrumentation-http/package.json index ef2a792705..67983b76d6 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/package.json +++ b/experimental/packages/opentelemetry-instrumentation-http/package.json @@ -45,7 +45,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.2.0", "@opentelemetry/context-async-hooks": "1.7.0", "@opentelemetry/sdk-trace-base": "1.7.0", "@opentelemetry/sdk-trace-node": "1.7.0", @@ -69,10 +69,9 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/instrumentation": "0.33.0", "@opentelemetry/sdk-metrics": "0.33.0", diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts index a0e07a1e9f..4129759589 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts @@ -25,8 +25,11 @@ import { SpanStatus, SpanStatusCode, trace, + Histogram, + MeterProvider, + MetricAttributes, + ValueType, } from '@opentelemetry/api'; -import { Histogram, MeterProvider, MetricAttributes, ValueType } from '@opentelemetry/api-metrics'; import { hrTime, hrTimeDuration, hrTimeToMilliseconds, suppressTracing } from '@opentelemetry/core'; import type * as http from 'http'; import type * as https from 'https'; diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts index e9e9b45468..4094586493 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { + MetricAttributes, SpanAttributes, SpanStatusCode, Span, @@ -35,7 +36,6 @@ import { getRPCMetadata, RPCType } from '@opentelemetry/core'; import * as url from 'url'; import { AttributeNames } from './enums/AttributeNames'; import { Err, IgnoreMatcher, ParsedRequestOptions } from './types'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; /** * Get an absolute url diff --git a/experimental/packages/opentelemetry-instrumentation-http/tsconfig.json b/experimental/packages/opentelemetry-instrumentation-http/tsconfig.json index c6158c12c1..00267e9c1a 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation-http/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-context-async-hooks" }, diff --git a/experimental/packages/opentelemetry-instrumentation/package.json b/experimental/packages/opentelemetry-instrumentation/package.json index abc09deb23..96437b278b 100644 --- a/experimental/packages/opentelemetry-instrumentation/package.json +++ b/experimental/packages/opentelemetry-instrumentation/package.json @@ -68,17 +68,16 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "require-in-the-middle": "^5.0.3", "semver": "^7.3.2", "shimmer": "^1.2.1" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.2.0" }, "devDependencies": { "@babel/core": "7.16.0", - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.2.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", "@types/semver": "7.3.9", diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts index 862ba111e0..c6a052c6c9 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { trace } from '@opentelemetry/api'; -import { metrics } from '@opentelemetry/api-metrics'; +import { trace, metrics } from '@opentelemetry/api'; import { disableInstrumentations, enableInstrumentations, diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts index 962c6de128..a6d63de472 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { TracerProvider } from '@opentelemetry/api'; -import { MeterProvider } from '@opentelemetry/api-metrics'; +import { TracerProvider, MeterProvider } from '@opentelemetry/api'; import { Instrumentation } from './types'; import { AutoLoaderResult, InstrumentationOption } from './types_internal'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index fb9f53fc70..5024b5d536 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -17,11 +17,13 @@ import { diag, DiagLogger, + metrics, + Meter, + MeterProvider, trace, Tracer, TracerProvider, } from '@opentelemetry/api'; -import { Meter, MeterProvider, metrics } from '@opentelemetry/api-metrics'; import * as shimmer from 'shimmer'; import { InstrumentationModuleDefinition } from './platform/node'; import * as types from './types'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 9edd6368ec..837f096792 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { TracerProvider } from '@opentelemetry/api'; -import { MeterProvider } from '@opentelemetry/api-metrics'; +import { TracerProvider, MeterProvider } from '@opentelemetry/api'; /** Interface Instrumentation to apply patch. */ export interface Instrumentation { diff --git a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts index 6383b6cd17..016be0ad36 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { TracerProvider } from '@opentelemetry/api'; -import { MeterProvider } from '@opentelemetry/api-metrics'; +import { TracerProvider, MeterProvider } from '@opentelemetry/api'; import { InstrumentationBase } from './platform'; import { Instrumentation } from './types'; diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts index c7bf2f6967..c7bebf204c 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts @@ -14,15 +14,16 @@ * limitations under the License. */ -import { Tracer, TracerProvider } from '@opentelemetry/api'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import { InstrumentationBase, registerInstrumentations } from '../../src'; import { + Tracer, + TracerProvider, Meter, MeterOptions, MeterProvider, -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import { InstrumentationBase, registerInstrumentations } from '../../src'; class DummyTracerProvider implements TracerProvider { getTracer(name: string, version?: string): Tracer { diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json index dc405c942c..cb78dd6ff3 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json @@ -7,10 +7,5 @@ }, "include": [ "src/**/*.ts" - ], - "references": [ - { - "path": "../../../api-metrics/tsconfig.esnext.json" - } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.json index ce90824272..e22548584a 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.json @@ -11,9 +11,6 @@ "references": [ { "path": "../../../api" - }, - { - "path": "../../../api-metrics" } ] } diff --git a/experimental/packages/opentelemetry-sdk-metrics/README.md b/experimental/packages/opentelemetry-sdk-metrics/README.md index 044c385913..ab5f2dd0a0 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/README.md +++ b/experimental/packages/opentelemetry-sdk-metrics/README.md @@ -14,7 +14,7 @@ It does **not** provide automated instrumentation of known libraries or host env ## Installation ```bash -npm install --save @opentelemetry/api-metrics +npm install --save @opentelemetry/api npm install --save @opentelemetry/sdk-metrics ``` @@ -23,7 +23,7 @@ npm install --save @opentelemetry/sdk-metrics The basic setup of the SDK can be seen as followings: ```js -const opentelemetry = require('@opentelemetry/api-metrics'); +const opentelemetry = require('@opentelemetry/api'); const { MeterProvider } = require('@opentelemetry/sdk-metrics'); // To create an instrument, you first need to initialize the Meter provider. diff --git a/experimental/packages/opentelemetry-sdk-metrics/package.json b/experimental/packages/opentelemetry-sdk-metrics/package.json index f53dc3cacf..dcd526d57f 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/package.json +++ b/experimental/packages/opentelemetry-sdk-metrics/package.json @@ -54,7 +54,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": ">=1.2.0 <1.3.0", "@types/lodash.merge": "4.6.6", "@types/mocha": "10.0.0", "@types/node": "18.6.5", @@ -74,10 +74,9 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": ">=1.2.0 <1.3.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/resources": "1.7.0", "lodash.merge": "4.6.2" diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/InstrumentDescriptor.ts b/experimental/packages/opentelemetry-sdk-metrics/src/InstrumentDescriptor.ts index e511cd8dd3..4008bc3de2 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/InstrumentDescriptor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/InstrumentDescriptor.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { MetricOptions, ValueType } from '@opentelemetry/api-metrics'; +import { MetricOptions, ValueType } from '@opentelemetry/api'; import { View } from './view/View'; /** diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/Instruments.ts b/experimental/packages/opentelemetry-sdk-metrics/src/Instruments.ts index 5706059691..8b70c06f70 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/Instruments.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/Instruments.ts @@ -14,9 +14,21 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; -import * as metrics from '@opentelemetry/api-metrics'; -import { ObservableCallback } from '@opentelemetry/api-metrics'; +import { + context as contextApi, + diag, + Context, + MetricAttributes, + ValueType, + UpDownCounter, + Counter, + Histogram, + Observable, + ObservableCallback, + ObservableCounter, + ObservableGauge, + ObservableUpDownCounter, +} from '@opentelemetry/api'; import { hrTime } from '@opentelemetry/core'; import { InstrumentDescriptor } from './InstrumentDescriptor'; import { ObservableRegistry } from './state/ObservableRegistry'; @@ -25,9 +37,9 @@ import { AsyncWritableMetricStorage, WritableMetricStorage } from './state/Writa export class SyncInstrument { constructor(private _writableMetricStorage: WritableMetricStorage, protected _descriptor: InstrumentDescriptor) {} - protected _record(value: number, attributes: metrics.MetricAttributes = {}, context: api.Context = api.context.active()) { - if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) { - api.diag.warn( + protected _record(value: number, attributes: MetricAttributes = {}, context: Context = contextApi.active()) { + if (this._descriptor.valueType === ValueType.INT && !Number.isInteger(value)) { + diag.warn( `INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); @@ -37,27 +49,27 @@ export class SyncInstrument { } /** - * The class implements {@link metrics.UpDownCounter} interface. + * The class implements {@link UpDownCounter} interface. */ -export class UpDownCounterInstrument extends SyncInstrument implements metrics.UpDownCounter { +export class UpDownCounterInstrument extends SyncInstrument implements UpDownCounter { /** * Increment value of counter by the input. Inputs may be negative. */ - add(value: number, attributes?: metrics.MetricAttributes, ctx?: api.Context): void { + add(value: number, attributes?: MetricAttributes, ctx?: Context): void { this._record(value, attributes, ctx); } } /** - * The class implements {@link metrics.Counter} interface. + * The class implements {@link Counter} interface. */ -export class CounterInstrument extends SyncInstrument implements metrics.Counter { +export class CounterInstrument extends SyncInstrument implements Counter { /** * Increment value of counter by the input. Inputs may not be negative. */ - add(value: number, attributes?: metrics.MetricAttributes, ctx?: api.Context): void { + add(value: number, attributes?: MetricAttributes, ctx?: Context): void { if (value < 0) { - api.diag.warn(`negative value provided to counter ${this._descriptor.name}: ${value}`); + diag.warn(`negative value provided to counter ${this._descriptor.name}: ${value}`); return; } @@ -66,22 +78,22 @@ export class CounterInstrument extends SyncInstrument implements metrics.Counter } /** - * The class implements {@link metrics.Histogram} interface. + * The class implements {@link Histogram} interface. */ -export class HistogramInstrument extends SyncInstrument implements metrics.Histogram { +export class HistogramInstrument extends SyncInstrument implements Histogram { /** * Records a measurement. Value of the measurement must not be negative. */ - record(value: number, attributes?: metrics.MetricAttributes, ctx?: api.Context): void { + record(value: number, attributes?: MetricAttributes, ctx?: Context): void { if (value < 0) { - api.diag.warn(`negative value provided to histogram ${this._descriptor.name}: ${value}`); + diag.warn(`negative value provided to histogram ${this._descriptor.name}: ${value}`); return; } this._record(value, attributes, ctx); } } -export class ObservableInstrument implements metrics.Observable { +export class ObservableInstrument implements Observable { /** @internal */ _metricStorages: AsyncWritableMetricStorage[]; /** @internal */ @@ -93,23 +105,23 @@ export class ObservableInstrument implements metrics.Observable { } /** - * @see {metrics.Observable.addCallback} + * @see {Observable.addCallback} */ addCallback(callback: ObservableCallback) { this._observableRegistry.addCallback(callback, this); } /** - * @see {metrics.Observable.removeCallback} + * @see {Observable.removeCallback} */ removeCallback(callback: ObservableCallback) { this._observableRegistry.removeCallback(callback, this); } } -export class ObservableCounterInstrument extends ObservableInstrument implements metrics.ObservableCounter {} -export class ObservableGaugeInstrument extends ObservableInstrument implements metrics.ObservableGauge {} -export class ObservableUpDownCounterInstrument extends ObservableInstrument implements metrics.ObservableUpDownCounter {} +export class ObservableCounterInstrument extends ObservableInstrument implements ObservableCounter {} +export class ObservableGaugeInstrument extends ObservableInstrument implements ObservableGauge {} +export class ObservableUpDownCounterInstrument extends ObservableInstrument implements ObservableUpDownCounter {} export function isObservableInstrument(it: unknown): it is ObservableInstrument { return it instanceof ObservableInstrument; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/Meter.ts b/experimental/packages/opentelemetry-sdk-metrics/src/Meter.ts index d8a7f00a21..bd58dcbac1 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/Meter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/Meter.ts @@ -14,7 +14,18 @@ * limitations under the License. */ -import * as metrics from '@opentelemetry/api-metrics'; +import { + Meter as IMeter, + MetricOptions, + Histogram, + Counter, + UpDownCounter, + ObservableGauge, + ObservableCounter, + ObservableUpDownCounter, + BatchObservableCallback, + Observable, +} from '@opentelemetry/api'; import { createInstrumentDescriptor, InstrumentType } from './InstrumentDescriptor'; import { CounterInstrument, @@ -27,85 +38,85 @@ import { import { MeterSharedState } from './state/MeterSharedState'; /** - * This class implements the {@link metrics.Meter} interface. + * This class implements the {@link IMeter} interface. */ -export class Meter implements metrics.Meter { +export class Meter implements IMeter { constructor(private _meterSharedState: MeterSharedState) {} /** - * Create a {@link metrics.Histogram} instrument. + * Create a {@link Histogram} instrument. */ - createHistogram(name: string, options?: metrics.MetricOptions): metrics.Histogram { + createHistogram(name: string, options?: MetricOptions): Histogram { const descriptor = createInstrumentDescriptor(name, InstrumentType.HISTOGRAM, options); const storage = this._meterSharedState.registerMetricStorage(descriptor); return new HistogramInstrument(storage, descriptor); } /** - * Create a {@link metrics.Counter} instrument. + * Create a {@link Counter} instrument. */ - createCounter(name: string, options?: metrics.MetricOptions): metrics.Counter { + createCounter(name: string, options?: MetricOptions): Counter { const descriptor = createInstrumentDescriptor(name, InstrumentType.COUNTER, options); const storage = this._meterSharedState.registerMetricStorage(descriptor); return new CounterInstrument(storage, descriptor); } /** - * Create a {@link metrics.UpDownCounter} instrument. + * Create a {@link UpDownCounter} instrument. */ - createUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.UpDownCounter { + createUpDownCounter(name: string, options?: MetricOptions): UpDownCounter { const descriptor = createInstrumentDescriptor(name, InstrumentType.UP_DOWN_COUNTER, options); const storage = this._meterSharedState.registerMetricStorage(descriptor); return new UpDownCounterInstrument(storage, descriptor); } /** - * Create a {@link metrics.ObservableGauge} instrument. + * Create a {@link ObservableGauge} instrument. */ createObservableGauge( name: string, - options?: metrics.MetricOptions, - ): metrics.ObservableGauge { + options?: MetricOptions, + ): ObservableGauge { const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_GAUGE, options); const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor); return new ObservableGaugeInstrument(descriptor, storages, this._meterSharedState.observableRegistry); } /** - * Create a {@link metrics.ObservableCounter} instrument. + * Create a {@link ObservableCounter} instrument. */ createObservableCounter( name: string, - options?: metrics.MetricOptions, - ): metrics.ObservableCounter { + options?: MetricOptions, + ): ObservableCounter { const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_COUNTER, options); const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor); return new ObservableCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry); } /** - * Create a {@link metrics.ObservableUpDownCounter} instrument. + * Create a {@link ObservableUpDownCounter} instrument. */ createObservableUpDownCounter( name: string, - options?: metrics.MetricOptions, - ): metrics.ObservableUpDownCounter { + options?: MetricOptions, + ): ObservableUpDownCounter { const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_UP_DOWN_COUNTER, options); const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor); return new ObservableUpDownCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry); } /** - * @see {@link metrics.Meter.addBatchObservableCallback} + * @see {@link Meter.addBatchObservableCallback} */ - addBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]) { + addBatchObservableCallback(callback: BatchObservableCallback, observables: Observable[]) { this._meterSharedState.observableRegistry.addBatchCallback(callback, observables); } /** - * @see {@link metrics.Meter.removeBatchObservableCallback} + * @see {@link Meter.removeBatchObservableCallback} */ - removeBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]) { + removeBatchObservableCallback(callback: BatchObservableCallback, observables: Observable[]) { this._meterSharedState.observableRegistry.removeBatchCallback(callback, observables); } } diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/MeterProvider.ts b/experimental/packages/opentelemetry-sdk-metrics/src/MeterProvider.ts index f8008d1c4b..01c3f54a1b 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/MeterProvider.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/MeterProvider.ts @@ -14,8 +14,13 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; -import * as metrics from '@opentelemetry/api-metrics'; +import { + diag, + MeterProvider as IMeterProvider, + Meter as IMeter, + MeterOptions, + createNoopMeter, +} from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import { MetricReader } from './export/MetricReader'; import { MeterProviderSharedState } from './state/MeterProviderSharedState'; @@ -33,9 +38,9 @@ export interface MeterProviderOptions { } /** - * This class implements the {@link metrics.MeterProvider} interface. + * This class implements the {@link MeterProvider} interface. */ -export class MeterProvider implements metrics.MeterProvider { +export class MeterProvider implements IMeterProvider { private _sharedState: MeterProviderSharedState; private _shutdown = false; @@ -51,11 +56,11 @@ export class MeterProvider implements metrics.MeterProvider { /** * Get a meter with the configuration of the MeterProvider. */ - getMeter(name: string, version = '', options: metrics.MeterOptions = {}): metrics.Meter { + getMeter(name: string, version = '', options: MeterOptions = {}): IMeter { // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#meter-creation if (this._shutdown) { - api.diag.warn('A shutdown MeterProvider cannot provide a Meter'); - return metrics.createNoopMeter(); + diag.warn('A shutdown MeterProvider cannot provide a Meter'); + return createNoopMeter(); } return this._sharedState @@ -83,7 +88,7 @@ export class MeterProvider implements metrics.MeterProvider { */ async shutdown(options?: ShutdownOptions): Promise { if (this._shutdown) { - api.diag.warn('shutdown may only be called once per MeterProvider'); + diag.warn('shutdown may only be called once per MeterProvider'); return; } @@ -102,7 +107,7 @@ export class MeterProvider implements metrics.MeterProvider { async forceFlush(options?: ForceFlushOptions): Promise { // do not flush after shutdown if (this._shutdown) { - api.diag.warn('invalid attempt to force flush after MeterProvider shutdown'); + diag.warn('invalid attempt to force flush after MeterProvider shutdown'); return; } diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/ObservableResult.ts b/experimental/packages/opentelemetry-sdk-metrics/src/ObservableResult.ts index 19ba32846c..e3a46f1c4d 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/ObservableResult.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/ObservableResult.ts @@ -14,16 +14,22 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; -import * as metrics from '@opentelemetry/api-metrics'; +import { + diag, + ObservableResult, + MetricAttributes, + ValueType, + BatchObservableResult, + Observable, +} from '@opentelemetry/api'; import { AttributeHashMap } from './state/HashMap'; import { isObservableInstrument, ObservableInstrument } from './Instruments'; import { InstrumentDescriptor } from '.'; /** - * The class implements {@link metrics.ObservableResult} interface. + * The class implements {@link ObservableResult} interface. */ -export class ObservableResultImpl implements metrics.ObservableResult { +export class ObservableResultImpl implements ObservableResult { /** * @internal */ @@ -34,9 +40,9 @@ export class ObservableResultImpl implements metrics.ObservableResult { /** * Observe a measurement of the value associated with the given attributes. */ - observe(value: number, attributes: metrics.MetricAttributes = {}): void { - if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) { - api.diag.warn( + observe(value: number, attributes: MetricAttributes = {}): void { + if (this._descriptor.valueType === ValueType.INT && !Number.isInteger(value)) { + diag.warn( `INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); @@ -46,9 +52,9 @@ export class ObservableResultImpl implements metrics.ObservableResult { } /** - * The class implements {@link metrics.BatchObservableCallback} interface. + * The class implements {@link BatchObservableCallback} interface. */ -export class BatchObservableResultImpl implements metrics.BatchObservableResult { +export class BatchObservableResultImpl implements BatchObservableResult { /** * @internal */ @@ -57,7 +63,7 @@ export class BatchObservableResultImpl implements metrics.BatchObservableResult /** * Observe a measurement of the value associated with the given attributes. */ - observe(metric: metrics.Observable, value: number, attributes: metrics.MetricAttributes = {}): void { + observe(metric: Observable, value: number, attributes: MetricAttributes = {}): void { if (!isObservableInstrument(metric)) { return; } @@ -66,8 +72,8 @@ export class BatchObservableResultImpl implements metrics.BatchObservableResult map = new AttributeHashMap(); this._buffer.set(metric, map); } - if (metric._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) { - api.diag.warn( + if (metric._descriptor.valueType === ValueType.INT && !Number.isInteger(value)) { + diag.warn( `INT value type cannot accept a floating-point value for ${metric._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/aggregator/types.ts b/experimental/packages/opentelemetry-sdk-metrics/src/aggregator/types.ts index 20c8f7ec4d..cc6a2a4976 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/aggregator/types.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/aggregator/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { HrTime, MetricAttributes } from '@opentelemetry/api'; import { AggregationTemporality } from '../export/AggregationTemporality'; import { MetricData } from '../export/MetricData'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlignedHistogramBucketExemplarReservoir.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlignedHistogramBucketExemplarReservoir.ts index 96060d16ae..0148ead72b 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlignedHistogramBucketExemplarReservoir.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlignedHistogramBucketExemplarReservoir.ts @@ -15,8 +15,7 @@ */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlwaysSampleExemplarFilter.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlwaysSampleExemplarFilter.ts index d2c52cdc0e..01c4a5dbfb 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlwaysSampleExemplarFilter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/AlwaysSampleExemplarFilter.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; -import { Context, HrTime } from '@opentelemetry/api'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { ExemplarFilter } from './ExemplarFilter'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/Exemplar.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/Exemplar.ts index 28628ff04f..d98246dc49 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/Exemplar.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/Exemplar.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { HrTime, MetricAttributes } from '@opentelemetry/api'; /** * A representation of an exemplar, which is a sample input measurement. diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarFilter.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarFilter.ts index ae005b4988..78b8ca0f39 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarFilter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarFilter.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; -import { Context, HrTime } from '@opentelemetry/api'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; /** * This interface represents a ExemplarFilter. Exemplar filters are diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarReservoir.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarReservoir.ts index 190976502e..fb2e0b8adb 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarReservoir.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/ExemplarReservoir.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; -import { Context, HrTime, isSpanContextValid, trace } from '@opentelemetry/api'; +import { Context, HrTime, isSpanContextValid, trace, MetricAttributes } from '@opentelemetry/api'; import { Exemplar } from './Exemplar'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/NeverSampleExemplarFilter.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/NeverSampleExemplarFilter.ts index 374f35e52f..c51adda410 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/NeverSampleExemplarFilter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/NeverSampleExemplarFilter.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; -import { Context, HrTime } from '@opentelemetry/api'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { ExemplarFilter } from './ExemplarFilter'; export class NeverSampleExemplarFilter implements ExemplarFilter { diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/SimpleFixedSizeExemplarReservoir.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/SimpleFixedSizeExemplarReservoir.ts index 31b0369d87..892f0605dc 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/SimpleFixedSizeExemplarReservoir.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/SimpleFixedSizeExemplarReservoir.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir'; /** diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts index 1ca0439c0d..6251a36a05 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; -import { Context, HrTime, isSpanContextValid, trace, TraceFlags } from '@opentelemetry/api'; +import { Context, HrTime, isSpanContextValid, trace, TraceFlags, MetricAttributes } from '@opentelemetry/api'; import { ExemplarFilter } from './ExemplarFilter'; export class WithTraceExemplarFilter implements ExemplarFilter { diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/export/MetricData.ts b/experimental/packages/opentelemetry-sdk-metrics/src/export/MetricData.ts index f31c748e0b..b15da1d9b9 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/export/MetricData.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/export/MetricData.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { HrTime, MetricAttributes } from '@opentelemetry/api'; import { InstrumentationScope } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/DeltaMetricProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/DeltaMetricProcessor.ts index 22c25edab0..999db3c282 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/DeltaMetricProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/DeltaMetricProcessor.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { Maybe } from '../utils'; import { Accumulation, Aggregator } from '../aggregator/types'; import { AttributeHashMap } from './HashMap'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/HashMap.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/HashMap.ts index 0f8efd3794..681d4dedee 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/HashMap.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/HashMap.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; import { hashAttributes } from '../utils'; export interface Hash { diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/MultiWritableMetricStorage.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/MultiWritableMetricStorage.ts index 323ef83947..64694793ed 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/MultiWritableMetricStorage.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/MultiWritableMetricStorage.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { WritableMetricStorage } from './WritableMetricStorage'; /** diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/ObservableRegistry.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/ObservableRegistry.ts index c74b9f9ab9..bd3e3fc6a7 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/ObservableRegistry.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/ObservableRegistry.ts @@ -14,9 +14,7 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; -import { HrTime } from '@opentelemetry/api'; -import { BatchObservableCallback, Observable, ObservableCallback } from '@opentelemetry/api-metrics'; +import { diag, HrTime, BatchObservableCallback, Observable, ObservableCallback } from '@opentelemetry/api'; import { isObservableInstrument, ObservableInstrument } from '../Instruments'; import { BatchObservableResultImpl, ObservableResultImpl } from '../ObservableResult'; import { callWithTimeout, PromiseAllSettled, isPromiseAllSettledRejectionResult, setEquals } from '../utils'; @@ -67,7 +65,7 @@ export class ObservableRegistry { // Create a set of unique instruments. const observableInstruments = new Set(instruments.filter(isObservableInstrument)); if (observableInstruments.size === 0) { - api.diag.error('BatchObservableCallback is not associated with valid instruments', instruments); + diag.error('BatchObservableCallback is not associated with valid instruments', instruments); return; } const idx = this._findBatchCallback(callback, observableInstruments); diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/SyncMetricStorage.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/SyncMetricStorage.ts index 26d5fec1ab..7bfd5967b2 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/SyncMetricStorage.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/SyncMetricStorage.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { WritableMetricStorage } from './WritableMetricStorage'; import { Accumulation, Aggregator } from '../aggregator/types'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/state/WritableMetricStorage.ts b/experimental/packages/opentelemetry-sdk-metrics/src/state/WritableMetricStorage.ts index 8bfdbcfde1..72945cd01d 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/state/WritableMetricStorage.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/state/WritableMetricStorage.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context, HrTime } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, HrTime, MetricAttributes } from '@opentelemetry/api'; import { AttributeHashMap } from './HashMap'; /** diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/utils.ts b/experimental/packages/opentelemetry-sdk-metrics/src/utils.ts index 33e198b3ba..532e05d227 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/utils.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; import { InstrumentationScope } from '@opentelemetry/core'; export type Maybe = T | undefined; diff --git a/experimental/packages/opentelemetry-sdk-metrics/src/view/AttributesProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics/src/view/AttributesProcessor.ts index 9900daf82f..96858c6428 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/src/view/AttributesProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/src/view/AttributesProcessor.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Context } from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { Context, MetricAttributes } from '@opentelemetry/api'; /** * The {@link AttributesProcessor} is responsible for customizing which diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/Instruments.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/Instruments.test.ts index 772e268fa4..1faa5b64a1 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/Instruments.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/Instruments.test.ts @@ -36,7 +36,7 @@ import { defaultResource, defaultInstrumentationScope } from './util'; -import { ObservableResult, ValueType } from '@opentelemetry/api-metrics'; +import { ObservableResult, ValueType } from '@opentelemetry/api'; describe('Instruments', () => { describe('Counter', () => { diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/Meter.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/Meter.test.ts index ada1234d58..c51c0baa52 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/Meter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/Meter.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Observable } from '@opentelemetry/api-metrics'; +import { Observable } from '@opentelemetry/api'; import * as assert from 'assert'; import { CounterInstrument, diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/ObservableResult.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/ObservableResult.test.ts index aaa97768b8..c425eafec7 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/ObservableResult.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/ObservableResult.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ValueType } from '@opentelemetry/api-metrics'; +import { ValueType } from '@opentelemetry/api'; import * as assert from 'assert'; import { InstrumentType } from '../src'; import { ObservableInstrument } from '../src/Instruments'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/aggregator/Histogram.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/aggregator/Histogram.test.ts index f5d5ea7e33..3dadaf8b1c 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/aggregator/Histogram.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/aggregator/Histogram.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { HrTime } from '@opentelemetry/api'; +import { HrTime, ValueType } from '@opentelemetry/api'; import * as assert from 'assert'; import { AggregationTemporality, @@ -30,7 +30,6 @@ import { commonValues, defaultInstrumentDescriptor } from '../util'; -import { ValueType } from '@opentelemetry/api-metrics'; describe('HistogramAggregator', () => { describe('createAccumulation', () => { diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/export/ConsoleMetricExporter.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/export/ConsoleMetricExporter.test.ts index 39edda36f1..6097aeb555 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/export/ConsoleMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/export/ConsoleMetricExporter.test.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as metrics from '@opentelemetry/api-metrics'; +import * as metrics from '@opentelemetry/api'; import { ExportResult } from '@opentelemetry/core'; import { ConsoleMetricExporter } from '../../src/export/ConsoleMetricExporter'; import { PeriodicExportingMetricReader } from '../../src/export/PeriodicExportingMetricReader'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/export/InMemoryMetricExporter.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/export/InMemoryMetricExporter.test.ts index 7afb3299a4..cab538fd2d 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/export/InMemoryMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/export/InMemoryMetricExporter.test.ts @@ -15,7 +15,7 @@ */ import { ExportResultCode } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import * as metrics from '@opentelemetry/api-metrics'; +import * as metrics from '@opentelemetry/api'; import assert = require('assert'); import { AggregationTemporality } from '../../src/export/AggregationTemporality'; import { InMemoryMetricExporter } from '../../src/export/InMemoryMetricExporter'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/state/HashMap.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/state/HashMap.test.ts index d41c24e9f4..8ae772989b 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/state/HashMap.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/state/HashMap.test.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; import { HashMap } from '../../src/state/HashMap'; import { hashAttributes } from '../../src/utils'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/state/MetricStorageRegistry.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/state/MetricStorageRegistry.test.ts index fa8424b992..53ffa5a75a 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/state/MetricStorageRegistry.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/state/MetricStorageRegistry.test.ts @@ -15,13 +15,12 @@ */ import { MetricStorageRegistry } from '../../src/state/MetricStorageRegistry'; -import { ValueType } from '@opentelemetry/api-metrics'; +import { diag, ValueType } from '@opentelemetry/api'; import { MetricStorage } from '../../src/state/MetricStorage'; import { HrTime } from '@opentelemetry/api'; import { MetricCollectorHandle } from '../../src/state/MetricCollector'; import { MetricData, InstrumentDescriptor, InstrumentType } from '../../src'; import { Maybe } from '../../src/utils'; -import * as api from '@opentelemetry/api'; import * as assert from 'assert'; import * as sinon from 'sinon'; import { @@ -44,7 +43,7 @@ describe('MetricStorageRegistry', () => { let spyLoggerWarn: sinon.SinonStub<[message: string, ...args: unknown[]], void>; beforeEach(() => { - spyLoggerWarn = sinon.stub(api.diag, 'warn'); + spyLoggerWarn = sinon.stub(diag, 'warn'); }); afterEach(() => { diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/state/MultiWritableMetricStorage.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/state/MultiWritableMetricStorage.test.ts index e91c952e69..1ccae07723 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/state/MultiWritableMetricStorage.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/state/MultiWritableMetricStorage.test.ts @@ -15,7 +15,7 @@ */ import * as api from '@opentelemetry/api'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; import { hrTime } from '@opentelemetry/core'; import * as assert from 'assert'; import { MultiMetricStorage } from '../../src/state/MultiWritableMetricStorage'; diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/util.ts b/experimental/packages/opentelemetry-sdk-metrics/test/util.ts index 87c6184e37..80f9ab1c49 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/util.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/util.ts @@ -14,13 +14,13 @@ * limitations under the License. */ -import * as api from '@opentelemetry/api'; import { + Context, BatchObservableCallback, MetricAttributes, ObservableCallback, ValueType, -} from '@opentelemetry/api-metrics'; +} from '@opentelemetry/api'; import { InstrumentationScope } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import * as assert from 'assert'; @@ -40,7 +40,7 @@ export type Measurement = { value: number; // TODO: use common attributes attributes: MetricAttributes - context?: api.Context; + context?: Context; }; export const defaultResource = new Resource({ diff --git a/experimental/packages/opentelemetry-sdk-metrics/test/utils.test.ts b/experimental/packages/opentelemetry-sdk-metrics/test/utils.test.ts index 07731a5376..2bf818088a 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/test/utils.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics/test/utils.test.ts @@ -18,7 +18,7 @@ import * as sinon from 'sinon'; import * as assert from 'assert'; import { callWithTimeout, hashAttributes, TimeoutError } from '../src/utils'; import { assertRejects } from './test-utils'; -import { MetricAttributes } from '@opentelemetry/api-metrics'; +import { MetricAttributes } from '@opentelemetry/api'; describe('utils', () => { afterEach(() => { diff --git a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esm.json b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esm.json index fb267e4d26..379f547a46 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esm.json @@ -7,10 +7,5 @@ }, "include": [ "src/**/*.ts" - ], - "references": [ - { - "path": "../../../api-metrics/tsconfig.esnext.json" - } ] } diff --git a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esnext.json b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esnext.json index dc405c942c..cb78dd6ff3 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esnext.json +++ b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.esnext.json @@ -7,10 +7,5 @@ }, "include": [ "src/**/*.ts" - ], - "references": [ - { - "path": "../../../api-metrics/tsconfig.esnext.json" - } ] } diff --git a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.json b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.json index bcce5660d3..f93e34131f 100644 --- a/experimental/packages/opentelemetry-sdk-metrics/tsconfig.json +++ b/experimental/packages/opentelemetry-sdk-metrics/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/opentelemetry-sdk-node/package.json b/experimental/packages/opentelemetry-sdk-node/package.json index 8a60ba30b7..30d559fc65 100644 --- a/experimental/packages/opentelemetry-sdk-node/package.json +++ b/experimental/packages/opentelemetry-sdk-node/package.json @@ -49,7 +49,6 @@ "@opentelemetry/exporter-trace-otlp-http": "0.33.0", "@opentelemetry/exporter-trace-otlp-proto": "0.33.0", "@opentelemetry/exporter-zipkin": "1.7.0", - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/instrumentation": "0.33.0", "@opentelemetry/resources": "1.7.0", @@ -59,10 +58,10 @@ "@opentelemetry/semantic-conventions": "1.7.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.3.0" + "@opentelemetry/api": ">=1.2.0 <1.3.0" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.3.0", + "@opentelemetry/api": ">=1.2.0 <1.3.0", "@opentelemetry/context-async-hooks": "1.7.0", "@types/mocha": "10.0.0", "@types/node": "18.6.5", diff --git a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts index bb20ed9440..38f85b87f2 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { ContextManager, TextMapPropagator } from '@opentelemetry/api'; -import { metrics } from '@opentelemetry/api-metrics'; +import { ContextManager, TextMapPropagator, metrics } from '@opentelemetry/api'; import { InstrumentationOption, registerInstrumentations diff --git a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts index bb78a3f7d3..6d853e4902 100644 --- a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts +++ b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts @@ -21,8 +21,8 @@ import { trace, diag, DiagLogLevel, + metrics, } from '@opentelemetry/api'; -import { metrics } from '@opentelemetry/api-metrics'; import { AsyncHooksContextManager, AsyncLocalStorageContextManager, diff --git a/experimental/packages/opentelemetry-sdk-node/tsconfig.json b/experimental/packages/opentelemetry-sdk-node/tsconfig.json index 1ecf7ce067..20eb8eace7 100644 --- a/experimental/packages/opentelemetry-sdk-node/tsconfig.json +++ b/experimental/packages/opentelemetry-sdk-node/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-context-async-hooks" }, diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer/package.json index 471c94cda9..8a5adedb64 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer/package.json @@ -52,10 +52,10 @@ "README.md" ], "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.3.0" + "@opentelemetry/api": ">=1.2.0 <1.3.0" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.3.0", + "@opentelemetry/api": ">=1.2.0 <1.3.0", "@types/mocha": "10.0.0", "@types/webpack-env": "1.16.3", "codecov": "3.8.3", @@ -76,7 +76,6 @@ "webpack": "4.46.0" }, "dependencies": { - "@opentelemetry/api-metrics": "0.33.0", "@opentelemetry/core": "1.7.0", "@opentelemetry/resources": "1.7.0", "@opentelemetry/sdk-metrics": "0.33.0", diff --git a/experimental/packages/otlp-transformer/src/metrics/internal.ts b/experimental/packages/otlp-transformer/src/metrics/internal.ts index bc17b84976..7aa9c82acd 100644 --- a/experimental/packages/otlp-transformer/src/metrics/internal.ts +++ b/experimental/packages/otlp-transformer/src/metrics/internal.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ValueType } from '@opentelemetry/api-metrics'; +import { ValueType } from '@opentelemetry/api'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; import { AggregationTemporality, diff --git a/experimental/packages/otlp-transformer/test/metrics.test.ts b/experimental/packages/otlp-transformer/test/metrics.test.ts index afb65d264a..df88389c5e 100644 --- a/experimental/packages/otlp-transformer/test/metrics.test.ts +++ b/experimental/packages/otlp-transformer/test/metrics.test.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ValueType } from '@opentelemetry/api-metrics'; +import { ValueType } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import { AggregationTemporality, diff --git a/experimental/packages/otlp-transformer/tsconfig.json b/experimental/packages/otlp-transformer/tsconfig.json index 64be5006a0..11ace43aeb 100644 --- a/experimental/packages/otlp-transformer/tsconfig.json +++ b/experimental/packages/otlp-transformer/tsconfig.json @@ -12,9 +12,6 @@ { "path": "../../../api" }, - { - "path": "../../../api-metrics" - }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/lerna.json b/lerna.json index 26c6e6b7bb..d97ab02a62 100644 --- a/lerna.json +++ b/lerna.json @@ -3,7 +3,6 @@ "npmClient": "npm", "packages": [ "api", - "api-metrics", "packages/*", "experimental/packages/*", "experimental/examples/*", diff --git a/packages/opentelemetry-core/src/platform/browser/globalThis.ts b/packages/opentelemetry-core/src/platform/browser/globalThis.ts index aa3c2fec6e..c438f2895f 100644 --- a/packages/opentelemetry-core/src/platform/browser/globalThis.ts +++ b/packages/opentelemetry-core/src/platform/browser/globalThis.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -// Updates to this file should also be replicated to @opentelemetry/api and -// @opentelemetry/api-metrics too. +// Updates to this file should also be replicated to @opentelemetry/api too. /** * - globalThis (New standard) diff --git a/tsconfig.base.json b/tsconfig.base.json index ca44078430..cbafb67678 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,6 +16,7 @@ "noImplicitReturns": true, "noUnusedLocals": true, "pretty": true, + "skipLibCheck": true, "sourceMap": true, "strict": true, "strictNullChecks": true, diff --git a/tsconfig.json b/tsconfig.json index d6642f0f02..371ba80055 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,6 @@ "experimental/packages/exporter-trace-otlp-grpc", "experimental/packages/exporter-trace-otlp-http", "experimental/packages/exporter-trace-otlp-proto", - "experimental/packages/opentelemetry-api-metrics", "experimental/packages/opentelemetry-exporter-metrics-otlp-grpc", "experimental/packages/opentelemetry-exporter-metrics-otlp-http", "experimental/packages/opentelemetry-exporter-metrics-otlp-proto", @@ -53,9 +52,6 @@ { "path": "api" }, - { - "path": "api-metrics" - }, { "path": "packages/opentelemetry-context-async-hooks" },