diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 70fb482d60..0d8d88ca73 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -15,7 +15,7 @@ jobs: if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependencies') && !contains(github.event.pull_request.labels.*.name, 'Skip Changelog')}} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check for CHANGELOG changes run: | diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 659cde8d2f..f67b78fe0e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,17 +2,9 @@ name: "CodeQL Analysis" on: workflow_dispatch: - schedule: - # ┌───────────── minute (0 - 59) - # │ ┌───────────── hour (0 - 23) - # │ │ ┌───────────── day of the month (1 - 31) - # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) - # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) - # │ │ │ │ │ - # │ │ │ │ │ - # │ │ │ │ │ - # * * * * * - - cron: '30 1 * * *' + push: + branches: [ main ] + pull_request: jobs: CodeQL-Build: @@ -20,7 +12,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index cde3ca25c7..787e11a91e 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 79c0f720be..a8bb9e14dc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: with: node-version: '16' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Lint changelog file uses: avto-dev/markdown-lint@v1 diff --git a/.github/workflows/peer-api.yml b/.github/workflows/peer-api.yml index e6f52cccd7..bb5094ec40 100644 --- a/.github/workflows/peer-api.yml +++ b/.github/workflows/peer-api.yml @@ -14,7 +14,7 @@ jobs: image: node:20 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install lerna run: npm install -g lerna diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index e326aa822e..da15818d5f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -20,13 +20,18 @@ jobs: NPM_CONFIG_UNSAFE_PERM: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} - run: npm install -g npm@latest + if: ${{ matrix.node_version == '18' || matrix.node_version == '20' }} + + # npm@10.0.0 drops support for Node.js v14 and v16 + - run: npm install -g npm@"<10.0.0" + if: ${{ matrix.node_version == '14' || matrix.node_version == '16' }} - name: restore lerna id: cache @@ -41,6 +46,10 @@ jobs: experimental/packages/*/package-lock.json key: node-tests-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022 + # temporary fix for https://github.com/nrwl/nx/issues/19022 + - run: npm install --save-dev nx@16.7.4 @nx/devkit@16.7.4 + if: ${{ matrix.node_version == '14' }} + - name: Bootstrap run: | npm install --ignore-scripts @@ -66,11 +75,11 @@ jobs: NPM_CONFIG_UNSAFE_PERM: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '18' - run: npm install -g npm@latest @@ -98,6 +107,8 @@ jobs: npm run compile - name: Unit tests + env: + NODE_OPTIONS: --openssl-legacy-provider run: npm run test browser-tests: runs-on: ubuntu-latest @@ -105,7 +116,7 @@ jobs: NPM_CONFIG_UNSAFE_PERM: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: @@ -143,7 +154,7 @@ jobs: NPM_CONFIG_UNSAFE_PERM: true steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v4.0.0 - uses: actions/setup-node@v3 with: node-version: 16 @@ -185,7 +196,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: @@ -201,4 +212,9 @@ jobs: - name: Test working-directory: ./api - run: npm test + # running test:eol as node 8 is not supported anymore by the version of nyc we use, as we don't report coverage + # for this step we leave it out. + # Details: nyc requires istanbul-lib-report, which silently dropped support for Node.js v8 when going from + # 3.0.0 to 3.0.1 by requiring make-dir@^4.0.0 to fix https://github.com/advisories/GHSA-c2qf-rxjj-qqgw. + # make-dir does not support Node.js v8 anymore. + run: npm run test:eol diff --git a/.github/workflows/w3c-integration-test.yml b/.github/workflows/w3c-integration-test.yml index 443fe85fac..04c07379ab 100644 --- a/.github/workflows/w3c-integration-test.yml +++ b/.github/workflows/w3c-integration-test.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout 🛎️ - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: diff --git a/.nycrc b/.nycrc index 22383d8aba..eb64eeca29 100644 --- a/.nycrc +++ b/.nycrc @@ -8,7 +8,6 @@ "build/**/*.*", "src/index.ts", "src/platform/**/index.ts", - "src/platform/browser/*.ts", "src/version.ts", "test/**/*.*", ".eslintrc.js", diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ca36c051..53987c4169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,22 +11,65 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :rocket: (Enhancement) -* feat(exporter-metrics-otlp-*)!: add LowMemory metrics temporality preference [#3915](https://github.com/open-telemetry/opentelemetry-js/pull/3915) - * Breaking: From now on `AggregationTemporalityPreference` has to be used instead of `AggregationTemporality` when configuring the exporter. - * Adds support for [LowMemory temporality preference](https://github.com/open-telemetry/opentelemetry-specification/blob/f09624bb97e9be3be259733b93be507df18927bd/specification/metrics/sdk_exporters/otlp.md#additional-configuration) - * Adds support for `lowmemory` in `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` +### :bug: (Bug Fix) + +### :books: (Refine Doc) + +### :house: (Internal) + +* test: added a performance benchmark test for span creation [#4105](https://github.com/open-telemetry/opentelemetry-js/pull/4105) + +## 1.17.0 + +### :bug: (Bug Fix) + +* Revert "feat(api): add attributes argument to recordException API [#4071](https://github.com/open-telemetry/opentelemetry-js/pull/4071)" + * This feature was an unintentional breaking change introduced with API 1.5.0 + * This PR updates all SDK packages to allow API 1.6.0, where this change has been reverted. + +## 1.16.0 + +### :rocket: (Enhancement) + +* feat(sdk-metrics): implement MetricProducer specification [#4007](https://github.com/open-telemetry/opentelemetry-js/pull/4007) +* feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers [#4077](https://github.com/open-telemetry/opentelemetry-js/pull/4077) @aabmass + +### :bug: (Bug Fix) + +* fix(exporter-zipkin): rounding duration to the nearest int to be compliant with zipkin protocol [#4064](https://github.com/open-telemetry/opentelemetry-js/pull/4064) @n0cloud +* fix(sdk-metrics): metric names should be case-insensitive + +### :books: (Refine Doc) + +* docs(guidelines): add dependencies guidelines [#4040](https://github.com/open-telemetry/opentelemetry-js/pull/4040) + +## 1.15.2 + +### :bug: (Bug Fix) + +* fix(core): stop rounding to nearest int in hrTimeTo*seconds() functions [#4014](https://github.com/open-telemetry/opentelemetry-js/pull/4014/) @aabmass +* fix(sdk-metrics): ignore invalid metric values [#3988](https://github.com/open-telemetry/opentelemetry-js/pull/3988) @legendecas +* fix(core): add baggage support for values containing an equals sign [#3975](https://github.com/open-telemetry/opentelemetry-js/pull/3975) @krosenk729 + +## 1.15.1 + +### :bug: (Bug Fix) + +* Revert "feat(minification): Add noEmitHelpers, importHelpers and tslib as a dependency (#3914)" + [#4011](https://github.com/open-telemetry/opentelemetry-js/pull/4011) @dyladan + +## 1.15.0 ### :bug: (Bug Fix) * fix(opentelemetry-exporter-prometheus): Update default PrometheusExporter to not append a timestamp to match the text based exposition format [#3961](https://github.com/open-telemetry/opentelemetry-js/pull/3961) @JacksonWeber * fix(sdk-metrics): Update default Histogram's boundary to match OTEL's spec [#3893](https://github.com/open-telemetry/opentelemetry-js/pull/3893/) @chigia001 * fix(sdk-metrics): preserve startTime for cumulative ExponentialHistograms [#3934](https://github.com/open-telemetry/opentelemetry-js/pull/3934/) @aabmass - -### :books: (Refine Doc) +* fix(sdk-trace-web): add secureConnectionStart to https only [#3879](https://github.com/open-telemetry/opentelemetry-js/pull/3879) @Abinet18 ### :house: (Internal) -* feat(minification): [Minification] Add noEmitHelpers, importHelpers and tslib as a dependency [#3913](https://github.com/open-telemetry/opentelemetry-js/issues/3913) +* feat(minification): [Minification] Add noEmitHelpers, importHelpers and tslib as a dependency [#3913](https://github.com/open-telemetry/opentelemetry-js/issues/3913) @MSNev ## 1.14.0 @@ -42,7 +85,6 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) -* fix(sdk-trace-web): add secureConnectionStart to https only [#3879](https://github.com/open-telemetry/opentelemetry-js/pull/3879) @Abinet18 * fix(http-instrumentation): stop listening to `request`'s `close` event once it has emitted `response` [#3625](https://github.com/open-telemetry/opentelemetry-js/pull/3625) @SimenB * fix(sdk-node): fix initialization in bundled environments by not loading @opentelemetry/exporter-jaeger [#3739](https://github.com/open-telemetry/opentelemetry-js/pull/3739) @pichlermarc diff --git a/README.md b/README.md index ca72796747..c07b4e5924 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ ## About this project -This is the JavaScript version of [OpenTelemetry](https://opentelemetry.io/), a framework for collecting traces and metrics from applications. +This is the JavaScript version of [OpenTelemetry](https://opentelemetry.io/), a framework for collecting traces, metrics, and logs from applications. ## Quick Start @@ -109,24 +109,29 @@ If you are a library author looking to build OpenTelemetry into your library, pl ## Supported Runtimes -| Platform Version | Supported | -| ------------------- | ----------------------------------------------- | -| Node.JS `v18` | ✅ | -| Node.JS `v16` | ✅ | -| Node.JS `v14` | ✅ | -| Older Node Versions | See [Node Support](#node-support) | -| Web Browsers | ✅ See [Browser Support](#browser-support) below | +| Platform Version | Supported | +|---------------------|-----------------------------------------------| +| Node.JS `v18` | :heavy_check_mark: | +| Node.JS `v16` | :heavy_check_mark: | +| Node.JS `v14` | :heavy_check_mark: | +| Older Node Versions | See [Node Support](#node-support) | +| Web Browsers | See [Browser Support](#browser-support) below | ### Node Support Only Node.js Active or Maintenance LTS versions are supported. Previous versions of node *may* work, but they are not tested by OpenTelemetry and they are not guaranteed to work. -Please note that versions of Node.JS v8 prior to `v8.12.0` will NOT work, because OpenTelemetry Node depends on the `perf_hooks` module introduced in `v8.5.0` and `performance.timeOrigin` that is set correctly starting in `v8.12.0`. +Note that versions of Node.JS v8 prior to `v8.12.0` will NOT work, because OpenTelemetry Node depends on the +`perf_hooks` module introduced in `v8.5.0` and `performance.timeOrigin` that is set correctly starting in `v8.12.0`. ### Browser Support -Automated browser tests are run in the latest version of Headless Chrome. -There is currently no list of officially supported browsers, but OpenTelemetry is developed using standard web technologies with wide support and should work in currently supported versions of major browsers. +> [!IMPORTANT] +> Client instrumentation for the browser is **experimental** and mostly **unspecified**. If you are interested in +> helping out, get in touch with the [Client Instrumentation SIG][client-instrumentation-sig]. + +There is currently no list of officially supported browsers. OpenTelemetry is developed using standard web +technologies and aims to work in currently supported versions of major browsers. ## Package Version Compatibility @@ -136,19 +141,27 @@ There may also be API packages for experimental signals in the experimental dire All stable packages are released with the same version, and all experimental packages are released with the same version. The below table describes which versions of each set of packages are expected to work together. -| API | Stable Packages | Experimental Packages | -| ----- | --------------- | --------------------- | -| 1.3.x | 1.9.x | 0.35.x | -| 1.3.x | 1.8.x | 0.34.x | -| 1.2.x | 1.7.x | 0.33.x | -| 1.2.x | 1.6.x | 0.32.x | -| 1.1.x | 1.5.x | 0.31.x | -| 1.1.x | 1.4.x | 0.30.x | -| 1.1.x | 1.3.x | 0.29.x | -| 1.1.x | 1.2.x | 0.29.x | -| 1.1.x | 1.1.x | 0.28.x | -| 1.0.x | 1.0.x | 0.27.x | -| 1.0.x | 1.0.x | 0.26.x | +| Stable Packages | Experimental Packages | +|-----------------------------------------------------------------|-----------------------| +| 1.17.x | 0.43.x | +| 1.16.x | 0.42.x | +| 1.15.x | 0.41.x | +| 1.14.x | 0.40.x | +| 1.13.x | 0.39.x | +| 1.12.x | 0.38.x | +| 1.11.x | 0.37.x | +| 1.10.x | 0.36.x | +| 1.9.x | 0.35.x | +| 1.8.x (this and later versions require API >=1.3.0 for metrics) | 0.34.x | +| 1.7.x | 0.33.x | +| 1.6.x | 0.32.x | +| 1.5.x | 0.31.x | +| 1.4.x | 0.30.x | +| 1.3.x | 0.29.x | +| 1.2.x | 0.29.x | +| 1.1.x | 0.28.x | +| 1.0.x | 0.27.x | +| 1.0.x (this and later versions require API >=1.0.0 for traces) | 0.26.x | ## Versioning @@ -177,7 +190,7 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t #### Maintainers ([@open-telemetry/js-maintainers](https://github.com/orgs/open-telemetry/teams/javascript-maintainers)) -- [Amir Blum](https://github.com/blumamir), Aspecto +- [Amir Blum](https://github.com/blumamir), Keyval - [Chengzhong Wu](https://github.com/legendecas), Alibaba - [Daniel Dyla](https://github.com/dyladan), Dynatrace - [Marc Pichler](https://github.com/pichlermarc), Dynatrace @@ -190,13 +203,10 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t - [Haddas Bronfman](https://github.com/haddasbronfman), Cisco - [Hector Hernandez](https://github.com/hectorhdzg), Microsoft - [Jamie Danielson](https://github.com/JamieDanielson), Honeycomb -- [John Bley](https://github.com/johnbley), Splunk -- [Mark Wolff](https://github.com/markwolff), Microsoft - [Martin Kuba](https://github.com/martinkuba), Lightstep - [Matthew Wear](https://github.com/mwear), LightStep - [Naseem K. Ullah](https://github.com/naseemkullah), Transit - [Neville Wylie](https://github.com/MSNev), Microsoft -- [Olivier Albertini](https://github.com/OlivierAlbertini), Ville de Montréal - [Purvi Kanal](https://github.com/pkanal), Honeycomb - [Svetlana Brennan](https://github.com/svetlanabrennan), New Relic @@ -211,6 +221,9 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t - [Valentin Marchaud](https://github.com/vmarchaud), Maintainer - [Brandon Gonzalez](https://github.com/bg451), LightStep, Approver - [Roch Devost](https://github.com/rochdev), DataDog, Approver +- [John Bley](https://github.com/johnbley), Splunk, Approver +- [Mark Wolff](https://github.com/markwolff), Microsoft, Approver +- [Olivier Albertini](https://github.com/OlivierAlbertini), Ville de Montréal, Approver *Find more about the emeritus role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#emeritus-maintainerapprovertriager).* @@ -552,6 +565,8 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [up-for-grabs-issues]: https://github.com/open-telemetry/OpenTelemetry-js/issues?q=is%3Aissue+is%3Aopen+label%3Aup-for-grabs [good-first-issues]: https://github.com/open-telemetry/OpenTelemetry-js/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 +[client-instrumentation-sig]: https://docs.google.com/document/d/16Vsdh-DM72AfMg_FIt9yT9ExEWF4A_vRbQ3jRNBe09w/edit + [docs]: https://open-telemetry.github.io/opentelemetry-js [compliance-matrix]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md [CONTRIBUTING]: https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md diff --git a/api/.eslintrc.js b/api/.eslintrc.js index 7d5c10c7f9..08f88d4912 100644 --- a/api/.eslintrc.js +++ b/api/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "shared-node-browser": true }, - ...require('../eslint.config.js') + ...require('../eslint.base.js') } diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index 5b52050074..cba48a4149 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. ## Unreleased +## 1.6.0 + +### :bug: (Bug Fix) + +* Revert "feat(api): add attributes argument to recordException API [#4071](https://github.com/open-telemetry/opentelemetry-js/pull/4071)" + * This feature was an unintentional breaking change introduced with 1.5.0 + +## 1.5.0 + +### :rocket: (Enhancement) + +* feat(api): add attributes argument to recordException API [#4071](https://github.com/open-telemetry/opentelemetry-js/pull/4071) + ## 1.4.1 ### :bug: (Bug Fix) diff --git a/api/package.json b/api/package.json index 888e602e5e..2b677d2451 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/api", - "version": "1.4.1", + "version": "1.6.0", "description": "Public API for OpenTelemetry", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -23,9 +23,10 @@ "docs:test": "linkinator docs/out --silent && linkinator docs/*.md *.md --markdown --silent", "lint:fix": "eslint . --ext .ts --fix", "lint": "eslint . --ext .ts", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:webworker": "nyc karma start karma.worker.js --single-run", + "test:eol": "ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "test:webworker": "karma start karma.worker.js --single-run", "cycle-check": "dpdm --exit-code circular:1 src/index.ts", "version": "node ../scripts/version-update.js", "prewatch": "npm run precompile", @@ -62,21 +63,21 @@ "devDependencies": { "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack": "4.41.33", "@types/webpack-env": "1.16.3", "codecov": "3.8.3", "cross-var": "1.1.0", "dpdm": "3.13.1", - "istanbul-instrumenter-loader": "3.0.1", + "babel-plugin-istanbul": "6.1.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "memfs": "3.5.3", "mocha": "10.2.0", "nyc": "15.1.0", @@ -87,9 +88,6 @@ "unionfs": "4.5.1", "webpack": "4.46.0" }, - "dependencies": { - "tslib": "^2.3.1" - }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api", "sideEffects": false } diff --git a/api/src/metrics/Meter.ts b/api/src/metrics/Meter.ts index c399fc5fb7..1405ae7473 100644 --- a/api/src/metrics/Meter.ts +++ b/api/src/metrics/Meter.ts @@ -85,7 +85,7 @@ export interface Meter { * @param [options] the metric options. */ createUpDownCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( name: string, options?: MetricOptions @@ -100,7 +100,7 @@ export interface Meter { * @param [options] the metric options. */ createObservableGauge< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( name: string, options?: MetricOptions @@ -115,7 +115,7 @@ export interface Meter { * @param [options] the metric options. */ createObservableCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( name: string, options?: MetricOptions @@ -130,7 +130,7 @@ export interface Meter { * @param [options] the metric options. */ createObservableUpDownCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( name: string, options?: MetricOptions @@ -151,7 +151,7 @@ export interface Meter { * @param observables the observables associated with this batch observable callback */ addBatchObservableCallback< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( callback: BatchObservableCallback, observables: Observable[] @@ -167,7 +167,7 @@ export interface Meter { * @param observables the observables associated with this batch observable callback */ removeBatchObservableCallback< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, >( callback: BatchObservableCallback, observables: Observable[] diff --git a/api/src/metrics/Metric.ts b/api/src/metrics/Metric.ts index 36d773441e..533aa264b1 100644 --- a/api/src/metrics/Metric.ts +++ b/api/src/metrics/Metric.ts @@ -63,7 +63,7 @@ export enum ValueType { *
    */ export interface Counter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Increment value of counter by the input. Inputs must not be negative. @@ -72,7 +72,7 @@ export interface Counter< } export interface UpDownCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Increment value of counter by the input. Inputs may be negative. @@ -81,7 +81,7 @@ export interface UpDownCounter< } export interface Histogram< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Records a measurement. Value of the measurement must not be negative. @@ -103,7 +103,7 @@ export type MetricAttributeValue = AttributeValue; * The observable callback for Observable instruments. */ export type ObservableCallback< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > = ( observableResult: ObservableResult ) => void | Promise; @@ -112,13 +112,13 @@ export type ObservableCallback< * The observable callback for a batch of Observable instruments. */ export type BatchObservableCallback< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > = ( observableResult: BatchObservableResult ) => void | Promise; export interface Observable< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Sets up a function that will be called whenever a metric collection is initiated. @@ -134,11 +134,11 @@ export interface Observable< } export type ObservableCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > = Observable; export type ObservableUpDownCounter< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > = Observable; export type ObservableGauge< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > = Observable; diff --git a/api/src/metrics/ObservableResult.ts b/api/src/metrics/ObservableResult.ts index 5b4f9e962b..29a82db120 100644 --- a/api/src/metrics/ObservableResult.ts +++ b/api/src/metrics/ObservableResult.ts @@ -20,7 +20,7 @@ import { MetricAttributes, Observable } from './Metric'; * Interface that is being used in callback function for Observable Metric. */ export interface ObservableResult< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Observe a measurement of the value associated with the given attributes. @@ -41,7 +41,7 @@ export interface ObservableResult< * Interface that is being used in batch observable callback function. */ export interface BatchObservableResult< - AttributesTypes extends MetricAttributes = MetricAttributes + AttributesTypes extends MetricAttributes = MetricAttributes, > { /** * Observe a measurement of the value associated with the given attributes. diff --git a/doc/GUIDELINES.md b/doc/GUIDELINES.md new file mode 100644 index 0000000000..ea349fdde7 --- /dev/null +++ b/doc/GUIDELINES.md @@ -0,0 +1,35 @@ +# OpenTelemetry JS Code Contribution Guide + +This document outlines the essential guidelines for contributing code to the OpenTelemetry JS repository. These guidelines are designed to ensure consistency, stability, and the highest quality of code across the project. + +## Dependencies + +This section refers to `"dependencies"` and `"devDependencies"` entries in `package.json` file. +> [!IMPORTANT] +> Not all libraries follow [Semantic Versioning](https://semver.org/). Even those who do might occasionally introduce breaking changes due to human errors. Exceptions to the guidelines in this document MAY be granted by Approvers or Maintainers to work around this. + +### Development Dependencies + +`"devDependencies"` SHOULD be pinned to reduce the risk of autobreaking the build. Since we cannot use the `package-lock.json` file (because the libraries are distributed without it), control over the version our contributors will get is limited. By using pinned versions, we prevent potential disruptions caused by unpinned versions. + +**Example:** `^1.2.3` might inadvertently lead to version `1.2.6` which includes unintended breaking changes). + +> [!NOTE] +> As this approach might leave our project with outdated tooling, we adopt `renovate-bot`. This automated dependency update tool proactively opens pull requests upon the release of new patch/minor/major versions. The complete configuration for renovate-bot can be found in [renovate.json](../renovate.json) file. + +### @opentelemetry/* dependencies + +All packages from the `@opentelemetry/` namespace MUST have the same pinned version, as these dependencies are automatically updated on each release by lerna. + +**Example:** all packages under `packages/` should consistently maintain the same version, as should those under `experimental/packages/`. + +An exception is granted for dependencies on `@opentelemetry/api`, which, if used by the package SHOULD NOT be included as a `dependency`. `@opentelemetry/api` SHOULD be included as a `peerDependency` instead. The version range of the `peerDependency` SHOULD reflect the minimum supported, and SHOULD NOT allow versions greater than the latest released minor version. + +### Third-Party Library Dependencies + +Packages categorized as third-party and listed under the `"dependencies"` section (e.g., @grpc/grpc-js, @grpc/proto-loader, shimmer, etc.) should remain unpinned and utilize the caret (`^`) symbol. This approach offers several advantages: + +* Our users could get bug fixes of those 3rd-party packages easily, without waiting for us to update our library. +* In cases where multiple packages have dependencies on different versions of the same package, npm will opt for the most recent version, saving space and preventing potential disruptions. + +It's important to acknowledge that this approach does expose users to potential breaking changes arising from either human error or libraries that do not strictly follow to semver conventions. This trade-off is an inherent aspect of this approach. diff --git a/doc/metrics.md b/doc/metrics.md index 7162f43638..e2f2b5a147 100644 --- a/doc/metrics.md +++ b/doc/metrics.md @@ -20,7 +20,7 @@ _Metrics API Reference: { requestCounter.add(1, attributes); upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes); histogram.record(Math.random(), attributes); + exponentialHistogram.record(Math.random(), attributes); }, 1000); diff --git a/examples/otlp-exporter-node/package.json b/examples/otlp-exporter-node/package.json index bb5fa25136..5091af0836 100644 --- a/examples/otlp-exporter-node/package.json +++ b/examples/otlp-exporter-node/package.json @@ -1,7 +1,7 @@ { "name": "example-otlp-exporter-node", "private": true, - "version": "0.40.0", + "version": "0.43.0", "description": "Example of using @opentelemetry/collector-exporter in Node.js", "main": "index.js", "scripts": { @@ -29,17 +29,17 @@ }, "dependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/exporter-metrics-otlp-grpc": "0.40.0", - "@opentelemetry/exporter-metrics-otlp-http": "0.40.0", - "@opentelemetry/exporter-metrics-otlp-proto": "0.40.0", - "@opentelemetry/exporter-trace-otlp-grpc": "0.40.0", - "@opentelemetry/exporter-trace-otlp-http": "0.40.0", - "@opentelemetry/exporter-trace-otlp-proto": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/exporter-metrics-otlp-grpc": "0.43.0", + "@opentelemetry/exporter-metrics-otlp-http": "0.43.0", + "@opentelemetry/exporter-metrics-otlp-proto": "0.43.0", + "@opentelemetry/exporter-trace-otlp-grpc": "0.43.0", + "@opentelemetry/exporter-trace-otlp-http": "0.43.0", + "@opentelemetry/exporter-trace-otlp-proto": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/otlp-exporter-node" } diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 08c883e0a7..9bf558dd75 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -4,6 +4,81 @@ All notable changes to experimental packages in this project will be documented ## Unreleased +### :books: (Refine Doc) + +### :boom: Breaking Change + +* fix(exporter-logs-otlp-proto): change OTLPLogExporter to OTLPLogExporter [#4140](https://github.com/open-telemetry/opentelemetry-js/pull/4140) @Vunovati +* fix(sdk-node): remove explicit dependency on @opentelemetry/exporter-jaeger + * '@opentelemetry/exporter-jaeger' is no longer be a dependency of this package. To continue using '@opentelemetry/exporter-jaeger', please install it manually. + * NOTE: `@opentelemetry/exporter-jaeger` is deprecated, consider switching to one of the alternatives described [here](https://www.npmjs.com/package/@opentelemetry/exporter-jaeger) + +### :rocket: (Enhancement) + +* feat(exporter-metrics-otlp-proto): add esm build [#4099](https://github.com/open-telemetry/opentelemetry-js/pull/4099) @pichlermarc +* feat(opencensus-shim): implement OpenCensus metric producer [#4066](https://github.com/open-telemetry/opentelemetry-js/pull/4066) @aabmass + +### :bug: (Bug Fix) + +### :books: (Refine Doc) + +### :house: (Internal) + +## 0.43.0 + +### :bug: (Bug Fix) + +* Revert "feat(api): add attributes argument to recordException API [#4071](https://github.com/open-telemetry/opentelemetry-js/pull/4071)" + * This feature was an unintentional breaking change introduced with API 1.5.0 + * This PR updates all experimental packages to allow API 1.6.0, where this change has been reverted. + +## 0.42.0 + +### :boom: Breaking Change + +* chore(sdk-node): deprecate methods in favor of constructor options [#3996](https://github.com/open-telemetry/opentelemetry-js/pull/3996) @pichlermarc + * The following methods are now deprecated and will be removed in `0.43.0` + * `NodeSDK.configureTracerProvider()`, please use constructor options instead + * `NodeSDK.configureMeterProvider()`, please use constructor options instead + * `NodeSDK.configureLoggerProvider()`, please use constructor options instead + * `NodeSDK.addResource()`, please use constructor options instead + * `NodeSDK.detectResources()`, this is not necessary anymore, resources are now auto-detected on startup. +* chore(sdk-node): add notice that '@opentelemetry/exporter-jaeger' has to be installed manually in the next version [#4068](https://github.com/open-telemetry/opentelemetry-js/pull/4068) @pichlermarc + * Starting with 0.43.0 '@opentelemetry/exporter-jaeger' will no longer be a dependency of this package. To continue using '@opentelemetry/exporter-jaeger', please install it manually. + * NOTE: `@opentelemetry/exporter-jaeger` is deprecated, consider switching to one of the alternatives described [here](https://www.npmjs.com/package/@opentelemetry/exporter-jaeger) + +### :rocket: (Enhancement) + +* feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers [#4077](https://github.com/open-telemetry/opentelemetry-js/pull/4077) @aabmass + +### :bug: (Bug Fix) + +* fix(exporter-logs-otlp-http): add @opentelemetry/api-logs as dependency + +## 0.41.2 + +### :bug: (Bug Fix) + +* fix(opentelemetry-exporter-logs-otlp-http): Add otel-api as dev dep for tests as they are directly importing the api and which is breaking the web-sandbox tests which is using rollup +* fix(instrumentation-grpc): instrument @grpc/grpc-js Client methods [#3804](https://github.com/open-telemetry/opentelemetry-js/pull/3804) @pichlermarc + +## 0.41.1 + +### :books: (Refine Doc) + +* docs(sdk-metrics): add example of exponential histogram metric [#3855](https://github.com/open-telemetry/opentelemetry-js/pull/3855) @JamieDanielson + +### :rocket: (Enhancement) + +* feat(sdk-node): logs support added [#3969](https://github.com/open-telemetry/opentelemetry-js/pull/3969) @psk001 + +### :bug: (Bug Fix) + +* Revert "feat(minification): Add noEmitHelpers, importHelpers and tslib as a dependency (#3914)" + [#4011](https://github.com/open-telemetry/opentelemetry-js/pull/4011) @dyladan + +## 0.41.0 + ### :boom: Breaking Change * chore(instrumentation-grpc): Drop support for package `grpc`. [#3807](https://github.com/open-telemetry/opentelemetry-js/pull/3807) @llc1123 @@ -12,16 +87,17 @@ All notable changes to experimental packages in this project will be documented * feat(otlp-grpc-exporters): add support for UDS endpoints. [#3853](https://github.com/open-telemetry/opentelemetry-js/pull/3853) @llc1123 * feat(otlp-exporters): bump otlp proto to 0.20.0 [#3932](https://github.com/open-telemetry/opentelemetry-js/pull/3932) @pichlermarc +* feat(exporter-metrics-otlp-*): add LowMemory metrics temporality preference [#3915](https://github.com/open-telemetry/opentelemetry-js/pull/3915) @martinkuba + * Adds support for [LowMemory temporality preference](https://github.com/open-telemetry/opentelemetry-specification/blob/f09624bb97e9be3be259733b93be507df18927bd/specification/metrics/sdk_exporters/otlp.md#additional-configuration) + * Adds support for `lowmemory` in `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` ### :bug: (Bug Fix) * fix(exporter-logs-otlp-http): set useHex to true [#3875](https://github.com/open-telemetry/opentelemetry-js/pull/3875) @Nico385412 - fix(otlp-proto-exporter-base): add missing type import [#3937](https://github.com/open-telemetry/opentelemetry-js/pull/3937) @pichlermarc +* fix(otlp-proto-exporter-base): add missing type import [#3937](https://github.com/open-telemetry/opentelemetry-js/pull/3937) @pichlermarc * fix(example-opencensus-shim): avoid OpenCensus auto instrumentations [#3951](https://github.com/open-telemetry/opentelemetry-js/pull/3951) @llc1123 * fix(http-intrumentation): prevent request socket null from throwing uncaught error [#3858](https://github.com/open-telemetry/opentelemetry-js/pull/3858) @aodysseos -### :books: (Refine Doc) - ### :house: (Internal) * chore(instrumentation-grpc): Cleanup remnants of grpc-native support. [#3886](https://github.com/open-telemetry/opentelemetry-js/pull/3886) @llc1123 diff --git a/experimental/backwards-compatibility/node14/package.json b/experimental/backwards-compatibility/node14/package.json index a18a2795f4..5e7509407c 100644 --- a/experimental/backwards-compatibility/node14/package.json +++ b/experimental/backwards-compatibility/node14/package.json @@ -1,6 +1,6 @@ { "name": "backcompat-node14", - "version": "0.40.0", + "version": "0.43.0", "private": true, "description": "Backwards compatibility app for node 14 types and the OpenTelemetry Node.js SDK", "main": "index.js", @@ -9,9 +9,8 @@ "peer-api-check": "node ../../../scripts/peer-api-check.js" }, "dependencies": { - "@opentelemetry/sdk-node": "0.40.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/sdk-node": "0.43.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "devDependencies": { "@types/node": "14.18.25", diff --git a/experimental/backwards-compatibility/node16/package.json b/experimental/backwards-compatibility/node16/package.json index aaeb4db421..2c8c2f8e7f 100644 --- a/experimental/backwards-compatibility/node16/package.json +++ b/experimental/backwards-compatibility/node16/package.json @@ -1,6 +1,6 @@ { "name": "backcompat-node16", - "version": "0.40.0", + "version": "0.43.0", "private": true, "description": "Backwards compatibility app for node 16 types and the OpenTelemetry Node.js SDK", "main": "index.js", @@ -9,9 +9,8 @@ "peer-api-check": "node ../../../scripts/peer-api-check.js" }, "dependencies": { - "@opentelemetry/sdk-node": "0.40.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/sdk-node": "0.43.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "devDependencies": { "@types/node": "16.11.52", diff --git a/experimental/examples/.eslintrc.js b/experimental/examples/.eslintrc.js index 7927fa0c36..3f58849df9 100644 --- a/experimental/examples/.eslintrc.js +++ b/experimental/examples/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/experimental/examples/logs/package.json b/experimental/examples/logs/package.json index 0df41c352f..03ff3e05b1 100644 --- a/experimental/examples/logs/package.json +++ b/experimental/examples/logs/package.json @@ -1,14 +1,14 @@ { "name": "logs-example", - "version": "0.40.0", + "version": "0.43.0", "private": true, "scripts": { "start": "ts-node index.ts" }, "dependencies": { - "@opentelemetry/api": "^1.4.1", - "@opentelemetry/api-logs": "0.40.0", - "@opentelemetry/sdk-logs": "0.40.0" + "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api-logs": "0.41.0", + "@opentelemetry/sdk-logs": "0.41.0" }, "devDependencies": { "@types/node": "18.6.5", diff --git a/experimental/examples/opencensus-shim/README.md b/experimental/examples/opencensus-shim/README.md index 0738d67d89..6d95a91356 100644 --- a/experimental/examples/opencensus-shim/README.md +++ b/experimental/examples/opencensus-shim/README.md @@ -9,6 +9,8 @@ The example has: - Root Spans (on client), instrumented with OpenCensus's HTTP instrumentation - Child Span from a remote parent (on server), instrumented with OpenCensus's HTTP instrumentation - Another Child Span created in the server representing some work being done, instrumented manually with OpenTelemetry. +- Server metrics coming from OpenCensus's HTTP instrumentation, available through the +OpenTelemetry's Prometheus exporter. ## Installation @@ -64,6 +66,14 @@ Go to Jaeger with your browser and click on the "Servi

    +## Check the Prometheus metrics + +Load the Prometheus metrics endpoint of the server at in your +browser. You should see the `opencensus_io_http_server_*` related metrics in +the output. + +

    + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/experimental/examples/opencensus-shim/images/prom-metrics.png b/experimental/examples/opencensus-shim/images/prom-metrics.png new file mode 100644 index 0000000000..953e12253d Binary files /dev/null and b/experimental/examples/opencensus-shim/images/prom-metrics.png differ diff --git a/experimental/examples/opencensus-shim/package.json b/experimental/examples/opencensus-shim/package.json index fd231ef119..bd97c726c1 100644 --- a/experimental/examples/opencensus-shim/package.json +++ b/experimental/examples/opencensus-shim/package.json @@ -1,7 +1,7 @@ { "name": "opencensus-shim", "private": true, - "version": "0.40.0", + "version": "0.43.0", "description": "Example of using @opentelemetry/shim-opencensus in Node.js", "main": "index.js", "scripts": { @@ -27,15 +27,17 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/api": "1.4.1", - "@opentelemetry/sdk-trace-node": "1.14.0", "@opencensus/core": "0.1.0", + "@opencensus/instrumentation-http": "0.1.0", "@opencensus/nodejs-base": "0.1.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "@opentelemetry/exporter-trace-otlp-grpc": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/shim-opencensus": "0.40.0" + "@opentelemetry/api": "1.6.0", + "@opentelemetry/exporter-prometheus": "0.43.0", + "@opentelemetry/exporter-trace-otlp-grpc": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-node": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0", + "@opentelemetry/shim-opencensus": "0.43.0" }, - "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/examples/opencensus-shim", - "devDependencies": {} + "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/examples/opencensus-shim" } diff --git a/experimental/examples/opencensus-shim/server.js b/experimental/examples/opencensus-shim/server.js index 98ddcf5b60..00893bafe9 100644 --- a/experimental/examples/opencensus-shim/server.js +++ b/experimental/examples/opencensus-shim/server.js @@ -5,6 +5,8 @@ const setup = require('./setup'); const utils = require('./utils'); const { trace } = require('@opentelemetry/api'); +const oc = require('@opencensus/core'); + setup('opencensus-shim-example-server'); const http = require('http'); diff --git a/experimental/examples/opencensus-shim/setup.js b/experimental/examples/opencensus-shim/setup.js index 37206971e7..99bf8bf8b4 100644 --- a/experimental/examples/opencensus-shim/setup.js +++ b/experimental/examples/opencensus-shim/setup.js @@ -15,37 +15,64 @@ */ 'use strict'; -const { DiagConsoleLogger, diag, DiagLogLevel } = require('@opentelemetry/api'); +const { diag, metrics } = require('@opentelemetry/api'); const { NodeTracerProvider, BatchSpanProcessor, } = require('@opentelemetry/sdk-trace-node'); +const { MeterProvider } = require('@opentelemetry/sdk-metrics'); const { OTLPTraceExporter, } = require('@opentelemetry/exporter-trace-otlp-grpc'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); const { Resource } = require('@opentelemetry/resources'); const { SemanticResourceAttributes, } = require('@opentelemetry/semantic-conventions'); +const { OpenCensusMetricProducer } = require('@opentelemetry/shim-opencensus'); +const instrumentationHttp = require('@opencensus/instrumentation-http'); +const { TracingBase } = require('@opencensus/nodejs-base'); +const oc = require('@opencensus/core'); module.exports = function setup(serviceName) { - const tracing = require('@opencensus/nodejs-base'); + /** + * You can alternatively just use the @opentelemetry/nodejs package directly: + * + * ```js + * const tracing = require('@opencensus/nodejs'); + * ``` + */ + const tracing = new TracingBase(['http']); + tracing.tracer = new oc.CoreTracer(); - diag.setLogger(new DiagConsoleLogger(), { logLevel: DiagLogLevel.ALL }); - const provider = new NodeTracerProvider({ - resource: new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: serviceName, - }), + const resource = new Resource({ + [SemanticResourceAttributes.SERVICE_NAME]: serviceName, }); - provider.addSpanProcessor( + const tracerProvider = new NodeTracerProvider({ resource }); + tracerProvider.addSpanProcessor( new BatchSpanProcessor(new OTLPTraceExporter(), { scheduledDelayMillis: 5000, }) ); - provider.register(); + tracerProvider.register(); + + const meterProvider = new MeterProvider({ resource }); + meterProvider.addMetricReader( + new PrometheusExporter({ + metricProducers: [ + new OpenCensusMetricProducer({ + openCensusMetricProducerManager: + oc.Metrics.getMetricProducerManager(), + }), + ], + }) + ); + metrics.setGlobalMeterProvider(meterProvider); // Start OpenCensus tracing - tracing.start({ samplingRate: 1, logger: diag }); + tracing.start({ samplingRate: 1, logger: diag, stats: oc.globalStats }); + // Register OpenCensus HTTP stats views + instrumentationHttp.registerAllViews(oc.globalStats); - return provider; + return tracerProvider; }; diff --git a/experimental/examples/prometheus/package.json b/experimental/examples/prometheus/package.json index 037e147dc9..9a7beb79e1 100644 --- a/experimental/examples/prometheus/package.json +++ b/experimental/examples/prometheus/package.json @@ -1,6 +1,6 @@ { "name": "prometheus-example", - "version": "0.40.0", + "version": "0.43.0", "private": true, "description": "Example of using @opentelemetry/sdk-metrics and @opentelemetry/exporter-prometheus", "main": "index.js", @@ -11,7 +11,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/exporter-prometheus": "0.40.0", - "@opentelemetry/sdk-metrics": "1.14.0" + "@opentelemetry/exporter-prometheus": "0.43.0", + "@opentelemetry/sdk-metrics": "1.17.0" } } diff --git a/experimental/packages/api-events/.eslintrc.js b/experimental/packages/api-events/.eslintrc.js index 7654abb6ac..5cb19b0298 100644 --- a/experimental/packages/api-events/.eslintrc.js +++ b/experimental/packages/api-events/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "shared-node-browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/api-events/package.json b/experimental/packages/api-events/package.json index ec768c6188..c93878d909 100644 --- a/experimental/packages/api-events/package.json +++ b/experimental/packages/api-events/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/api-events", - "version": "0.40.0", + "version": "0.43.0", "description": "Public events API for OpenTelemetry", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -18,7 +18,7 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", - "test:browser": "nyc karma start --single-run", + "test:browser": "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", @@ -61,23 +61,22 @@ "access": "public" }, "dependencies": { - "@opentelemetry/api": "^1.0.0", - "tslib": "^2.3.1" + "@opentelemetry/api": "^1.0.0" }, "devDependencies": { "@types/mocha": "10.0.1", "@types/node": "18.6.5", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-loader": "8.4.0", diff --git a/experimental/packages/api-logs/.eslintrc.js b/experimental/packages/api-logs/.eslintrc.js index 7654abb6ac..5cb19b0298 100644 --- a/experimental/packages/api-logs/.eslintrc.js +++ b/experimental/packages/api-logs/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "shared-node-browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/api-logs/README.md b/experimental/packages/api-logs/README.md index b36d5bf06e..a4e3459f01 100644 --- a/experimental/packages/api-logs/README.md +++ b/experimental/packages/api-logs/README.md @@ -1,13 +1,19 @@ -# OpenTelemetry API for JavaScript +# OpenTelemetry Logs Bridge API for JavaScript [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -This package provides everything needed to interact with the unstable OpenTelemetry Logs API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser. +**Note: This is an experimental package under active development. New releases may include breaking changes.** -## Beta Software - Use at your own risk +This package provides everything needed to interact with the unstable OpenTelemetry Logs Bridge API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser. -The logs 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. +**Note: This module defines a log backend API. The API is not intended to be called by application developers directly. +It is provided for logging library authors to build log appenders, which use this API to bridge between existing +logging libraries and the OpenTelemetry log data model.** + +## Alpha Software - Use at your own risk + +The Logs Bridge 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 diff --git a/experimental/packages/api-logs/package.json b/experimental/packages/api-logs/package.json index 7be2db96e3..18806178ce 100644 --- a/experimental/packages/api-logs/package.json +++ b/experimental/packages/api-logs/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/api-logs", - "version": "0.40.0", + "version": "0.43.0", "description": "Public logs API for OpenTelemetry", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -18,7 +18,7 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", - "test:browser": "nyc karma start --single-run", + "test:browser": "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", @@ -61,23 +61,22 @@ "access": "public" }, "dependencies": { - "@opentelemetry/api": "^1.0.0", - "tslib": "^2.3.1" + "@opentelemetry/api": "^1.0.0" }, "devDependencies": { "@types/mocha": "10.0.1", "@types/node": "18.6.5", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-loader": "8.4.0", diff --git a/experimental/packages/exporter-logs-otlp-grpc/.eslintrc.js b/experimental/packages/exporter-logs-otlp-grpc/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/.eslintrc.js +++ b/experimental/packages/exporter-logs-otlp-grpc/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/exporter-logs-otlp-grpc/package.json b/experimental/packages/exporter-logs-otlp-grpc/package.json index 43dc22d223..82146ce439 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/package.json +++ b/experimental/packages/exporter-logs-otlp-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-logs-otlp-grpc", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Exporter allows user to send collected log records to the OpenTelemetry Collector", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -48,19 +48,19 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/api-logs": "0.40.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/resources": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/resources": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -73,11 +73,10 @@ }, "dependencies": { "@grpc/grpc-js": "^1.7.1", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-grpc-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/sdk-logs": "0.40.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-grpc-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/sdk-logs": "0.43.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-logs-otlp-grpc", "sideEffects": false diff --git a/experimental/packages/exporter-logs-otlp-http/.eslintrc.js b/experimental/packages/exporter-logs-otlp-http/.eslintrc.js index f3f22e8617..24f29328f9 100644 --- a/experimental/packages/exporter-logs-otlp-http/.eslintrc.js +++ b/experimental/packages/exporter-logs-otlp-http/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { node: true, browser: true, }, - ...require('../../../eslint.config.js'), + ...require('../../../eslint.base.js'), }; diff --git a/experimental/packages/exporter-logs-otlp-http/package.json b/experimental/packages/exporter-logs-otlp-http/package.json index a1ff957253..05b217da2d 100644 --- a/experimental/packages/exporter-logs-otlp-http/package.json +++ b/experimental/packages/exporter-logs-otlp-http/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-logs-otlp-http", - "version": "0.40.0", + "version": "0.43.0", "publishConfig": { "access": "public" }, @@ -38,7 +38,7 @@ "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -71,25 +71,25 @@ ], "sideEffects": false, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api-logs": "0.40.0", - "@opentelemetry/resources": "1.14.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/resources": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -101,13 +101,13 @@ "webpack-merge": "5.9.0" }, "peerDependencies": { - "@opentelemetry/api-logs": ">=0.38.0" + "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/sdk-logs": "0.40.0", - "tslib": "^2.3.1" + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/sdk-logs": "0.43.0" } } diff --git a/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts b/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts index 2ae11142ad..6dac23b580 100644 --- a/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-http/test/node/OTLPLogExporter.test.ts @@ -35,7 +35,10 @@ import { ExportResultCode } from '@opentelemetry/core'; let fakeRequest: PassThrough; class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/exporter-logs-otlp-http/tsconfig.esm.json b/experimental/packages/exporter-logs-otlp-http/tsconfig.esm.json index f7353a3e87..0edcb89fa7 100644 --- a/experimental/packages/exporter-logs-otlp-http/tsconfig.esm.json +++ b/experimental/packages/exporter-logs-otlp-http/tsconfig.esm.json @@ -9,6 +9,9 @@ "src/**/*.ts" ], "references": [ + { + "path": "../../../api" + }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/exporter-logs-otlp-http/tsconfig.esnext.json b/experimental/packages/exporter-logs-otlp-http/tsconfig.esnext.json index 7a3b4e394e..0c19aa0aaf 100644 --- a/experimental/packages/exporter-logs-otlp-http/tsconfig.esnext.json +++ b/experimental/packages/exporter-logs-otlp-http/tsconfig.esnext.json @@ -9,6 +9,9 @@ "src/**/*.ts" ], "references": [ + { + "path": "../../../api" + }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/exporter-logs-otlp-http/tsconfig.json b/experimental/packages/exporter-logs-otlp-http/tsconfig.json index e347a2eef9..96f229bb8e 100644 --- a/experimental/packages/exporter-logs-otlp-http/tsconfig.json +++ b/experimental/packages/exporter-logs-otlp-http/tsconfig.json @@ -9,6 +9,9 @@ "test/**/*.ts" ], "references": [ + { + "path": "../../../api" + }, { "path": "../../../packages/opentelemetry-core" }, diff --git a/experimental/packages/exporter-logs-otlp-proto/.eslintrc.js b/experimental/packages/exporter-logs-otlp-proto/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/exporter-logs-otlp-proto/.eslintrc.js +++ b/experimental/packages/exporter-logs-otlp-proto/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/exporter-logs-otlp-proto/README.md b/experimental/packages/exporter-logs-otlp-proto/README.md index 3a00476c32..30f1e8bb34 100644 --- a/experimental/packages/exporter-logs-otlp-proto/README.md +++ b/experimental/packages/exporter-logs-otlp-proto/README.md @@ -22,7 +22,7 @@ To see documentation and sample code for the metric exporter, see the [exporter- ```js const { LoggerProvider, SimpleLogRecordProcessor } = require('@opentelemetry/sdk-logs'); -const { OTLPLogsExporter } = require('@opentelemetry/exporter-logs-otlp-proto'); +const { OTLPLogExporter } = require('@opentelemetry/exporter-logs-otlp-proto'); const collectorOptions = { url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/logs @@ -32,7 +32,7 @@ const collectorOptions = { }; const logProvider = new LoggerProvider({resource: new Resource({'service.name': 'testApp'})}); -const logExporter = new OTLPLogsExporter(collectorOptions); +const logExporter = new OTLPLogExporter(collectorOptions); logProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(exporter)); const logger = logProvider.getLogger('test_log_instrumentation'); @@ -44,7 +44,7 @@ logger.emit({ ## Exporter Timeout Configuration -The OTLPLogsExporter has a timeout configuration option which is the maximum time, in milliseconds, the OTLP exporter will wait for each batch export. The default value is 10000ms. +The OTLPLogExporter has a timeout configuration option which is the maximum time, in milliseconds, the OTLP exporter will wait for each batch export. The default value is 10000ms. To override the default timeout duration, use the following options: @@ -57,7 +57,7 @@ To override the default timeout duration, use the following options: > `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` takes precedence and overrides `OTEL_EXPORTER_OTLP_TIMEOUT`. -+ Provide `timeoutMillis` to OTLPLogsExporter with `collectorOptions`: ++ Provide `timeoutMillis` to OTLPLogExporter with `collectorOptions`: ```js const collectorOptions = { @@ -68,7 +68,7 @@ To override the default timeout duration, use the following options: }, //an optional object containing custom headers to be sent with each request will only work with http }; - const exporter = new OTLPLogsExporter(collectorOptions); + const exporter = new OTLPLogExporter(collectorOptions); ``` > Providing `timeoutMillis` with `collectorOptions` takes precedence and overrides timeout set with environment variables. diff --git a/experimental/packages/exporter-logs-otlp-proto/package.json b/experimental/packages/exporter-logs-otlp-proto/package.json index 204414966f..4aa74b7eb2 100644 --- a/experimental/packages/exporter-logs-otlp-proto/package.json +++ b/experimental/packages/exporter-logs-otlp-proto/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-logs-otlp-proto", - "version": "0.40.0", + "version": "0.43.0", "description": "An OTLP exporter to send logs using protobuf over HTTP", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -21,7 +21,7 @@ "lint:fix": "eslint . --ext .ts --fix", "tdd": "npm run test -- --watch-extensions ts --watch", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -63,35 +63,44 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "karma": "6.4.2", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.2.1", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.36", + "karma-webpack": "4.0.2", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/api-logs": "0.40.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-proto-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-logs": "0.40.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-proto-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-logs": "0.43.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-logs-otlp-proto", "sideEffects": false diff --git a/experimental/packages/exporter-logs-otlp-proto/src/index.ts b/experimental/packages/exporter-logs-otlp-proto/src/index.ts index 9fde4be45b..dd74bc70be 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/index.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { OTLPLogsExporter } from './platform'; +export { OTLPLogExporter } from './platform'; diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogsExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts similarity index 98% rename from experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogsExporter.ts rename to experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts index 185d5094f1..fff28d4e77 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogsExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts @@ -37,7 +37,7 @@ const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURC /** * Collector Trace Exporter for Web */ -export class OTLPLogsExporter +export class OTLPLogExporter extends OTLPProtoExporterBrowserBase< ReadableLogRecord, IExportLogsServiceRequest diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/index.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/index.ts index e6968b3466..abaa4216f1 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/index.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { OTLPLogsExporter } from './OTLPLogsExporter'; +export { OTLPLogExporter } from './OTLPLogExporter'; diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/index.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/index.ts index 851ff9a015..86a29a341c 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/index.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { OTLPLogsExporter } from './node'; +export { OTLPLogExporter } from './node'; diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogsExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts similarity index 98% rename from experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogsExporter.ts rename to experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts index 88d97e21d3..53191c0625 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogsExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts @@ -37,7 +37,7 @@ const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURC /** * Collector Trace Exporter for Node */ -export class OTLPLogsExporter +export class OTLPLogExporter extends OTLPProtoExporterNodeBase< ReadableLogRecord, IExportLogsServiceRequest diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/index.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/index.ts index 4797b30651..2472e4a796 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/index.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { OTLPLogsExporter } from './OTLPLogsExporter'; +export { OTLPLogExporter } from './OTLPLogExporter'; diff --git a/experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogsExporter.test.ts b/experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogExporter.test.ts similarity index 81% rename from experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogsExporter.test.ts rename to experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogExporter.test.ts index 382a132c3e..6a76ed24a0 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogsExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/browser/OTLPLogExporter.test.ts @@ -16,19 +16,19 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; -import { OTLPLogsExporter } from '../../src/platform/browser/index'; +import { OTLPLogExporter } from '../../src/platform/browser/index'; -describe('OTLPLogsExporter - web', () => { - let collectorLogsExporter: OTLPLogsExporter; +describe('OTLPLogExporter - web', () => { + let collectorLogsExporter: OTLPLogExporter; describe('constructor', () => { let onInitSpy: any; beforeEach(() => { - onInitSpy = sinon.stub(OTLPLogsExporter.prototype, 'onInit'); + onInitSpy = sinon.stub(OTLPLogExporter.prototype, 'onInit'); const collectorExporterConfig = { hostname: 'foo', url: 'http://foo.bar.com', }; - collectorLogsExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorLogsExporter = new OTLPLogExporter(collectorExporterConfig); }); afterEach(() => { sinon.restore(); diff --git a/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts b/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts index 7b8c8e8b9a..54a752af1e 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts @@ -167,7 +167,10 @@ export function ensureExportLogsServiceRequestIsSet( } export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogsExporter.test.ts b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts similarity index 92% rename from experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogsExporter.test.ts rename to experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts index 994a2f0ea4..0810109e81 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogsExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/node/OTLPLogExporter.test.ts @@ -21,7 +21,7 @@ import * as http from 'http'; import * as sinon from 'sinon'; import { Stream, PassThrough } from 'stream'; import * as zlib from 'zlib'; -import { OTLPLogsExporter } from '../../src'; +import { OTLPLogExporter } from '../../src'; import { ensureExportLogsServiceRequestIsSet, ensureExportedLogRecordIsCorrect, @@ -42,8 +42,8 @@ import { ReadableLogRecord } from '@opentelemetry/sdk-logs'; let fakeRequest: PassThrough; -describe('OTLPLogsExporter - node with proto over http', () => { - let collectorExporter: OTLPLogsExporter; +describe('OTLPLogExporter - node with proto over http', () => { + let collectorExporter: OTLPLogExporter; let collectorExporterConfig: OTLPExporterNodeConfigBase; let logs: ReadableLogRecord[]; @@ -56,7 +56,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { const envSource = process.env; it('should use url defined in env that ends with root path and append version and signal path', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/logs` @@ -65,7 +65,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should use url defined in env without checking if path is already present', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/logs'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs` @@ -74,7 +74,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should use url defined in env and append version and signal', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs` @@ -84,7 +84,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { it('should override global exporter url with signal url defined in env', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.logs/'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT @@ -94,7 +94,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT}/` @@ -103,7 +103,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should not add root path when signal url defined in env contains root path but no path', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar/'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT}` @@ -112,7 +112,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should not add root path when signal url defined in env contains path', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar/v1/logs'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT}` @@ -121,7 +121,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should not add root path when signal url defined in env contains path and ends in /', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar/v1/logs/'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual( collectorExporter.url, `${envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT}` @@ -130,14 +130,14 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual(collectorExporter.headers.foo, 'bar'); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); it('should override global headers config with signal headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual(collectorExporter.headers.foo, 'boo'); assert.strictEqual(collectorExporter.headers.bar, 'foo'); envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = ''; @@ -156,7 +156,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { keepAlive: true, httpAgentOptions: { keepAliveMsecs: 2000 }, }; - collectorExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorExporter = new OTLPLogExporter(collectorExporterConfig); logs = []; logs.push(Object.assign({}, mockedReadableLogRecord)); }); @@ -286,7 +286,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { compression: CompressionAlgorithm.GZIP, httpAgentOptions: { keepAliveMsecs: 2000 }, }; - collectorExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorExporter = new OTLPLogExporter(collectorExporterConfig); logs = []; logs.push(Object.assign({}, mockedReadableLogRecord)); }); @@ -331,7 +331,7 @@ describe('OTLPLogsExporter - node with proto over http', () => { }); describe('export - real http request destroyed before response received', () => { - let collectorExporter: OTLPLogsExporter; + let collectorExporter: OTLPLogExporter; let collectorExporterConfig: OTLPExporterNodeConfigBase; let logs: ReadableLogRecord[]; const server = http.createServer((_, res) => { @@ -351,7 +351,7 @@ describe('export - real http request destroyed before response received', () => url: 'http://localhost:8082', timeoutMillis: 1, }; - collectorExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorExporter = new OTLPLogExporter(collectorExporterConfig); logs = []; logs.push(Object.assign({}, mockedReadableLogRecord)); @@ -368,7 +368,7 @@ describe('export - real http request destroyed before response received', () => url: 'http://localhost:8082', timeoutMillis: 100, }; - collectorExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorExporter = new OTLPLogExporter(collectorExporterConfig); logs = []; logs.push(Object.assign({}, mockedReadableLogRecord)); @@ -383,7 +383,7 @@ describe('export - real http request destroyed before response received', () => }); describe('export - real http request destroyed after response received', () => { - let collectorExporter: OTLPLogsExporter; + let collectorExporter: OTLPLogExporter; let collectorExporterConfig: OTLPExporterNodeConfigBase; let logs: ReadableLogRecord[]; @@ -401,7 +401,7 @@ describe('export - real http request destroyed after response received', () => { url: 'http://localhost:8082', timeoutMillis: 300, }; - collectorExporter = new OTLPLogsExporter(collectorExporterConfig); + collectorExporter = new OTLPLogExporter(collectorExporterConfig); logs = []; logs.push(Object.assign({}, mockedReadableLogRecord)); diff --git a/experimental/packages/exporter-trace-otlp-grpc/.eslintrc.js b/experimental/packages/exporter-trace-otlp-grpc/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/.eslintrc.js +++ b/experimental/packages/exporter-trace-otlp-grpc/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/exporter-trace-otlp-grpc/package.json b/experimental/packages/exporter-trace-otlp-grpc/package.json index fce71adbd5..80c2ea3a0c 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/package.json +++ b/experimental/packages/exporter-trace-otlp-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-trace-otlp-grpc", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -47,17 +47,17 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/otlp-exporter-base": "0.40.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -70,12 +70,11 @@ }, "dependencies": { "@grpc/grpc-js": "^1.7.1", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-grpc-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-grpc-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-trace-otlp-grpc", "sideEffects": false diff --git a/experimental/packages/exporter-trace-otlp-http/.eslintrc.js b/experimental/packages/exporter-trace-otlp-http/.eslintrc.js index e41d9a9299..c054089042 100644 --- a/experimental/packages/exporter-trace-otlp-http/.eslintrc.js +++ b/experimental/packages/exporter-trace-otlp-http/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/exporter-trace-otlp-http/package.json b/experimental/packages/exporter-trace-otlp-http/package.json index 9e55231aa6..cfc2522a53 100644 --- a/experimental/packages/exporter-trace-otlp-http/package.json +++ b/experimental/packages/exporter-trace-otlp-http/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-trace-otlp-http", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Trace Exporter allows user to send collected traces to the OpenTelemetry Collector", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -23,7 +23,7 @@ "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -63,24 +63,24 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -95,12 +95,11 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-trace-otlp-http", "sideEffects": false diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/nodeHelpers.ts b/experimental/packages/exporter-trace-otlp-http/test/node/nodeHelpers.ts index 1219f2d976..d2dce6517b 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/nodeHelpers.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/nodeHelpers.ts @@ -17,7 +17,10 @@ import { Stream } from 'stream'; export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/exporter-trace-otlp-proto/.eslintrc.js b/experimental/packages/exporter-trace-otlp-proto/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/exporter-trace-otlp-proto/.eslintrc.js +++ b/experimental/packages/exporter-trace-otlp-proto/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/exporter-trace-otlp-proto/package.json b/experimental/packages/exporter-trace-otlp-proto/package.json index 5f0deff40b..935b79963f 100644 --- a/experimental/packages/exporter-trace-otlp-proto/package.json +++ b/experimental/packages/exporter-trace-otlp-proto/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-trace-otlp-proto", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector using protobuf over HTTP", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -21,7 +21,7 @@ "lint:fix": "eslint . --ext .ts --fix", "tdd": "npm run test -- --watch-extensions ts --watch", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -62,33 +62,42 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "karma": "6.4.2", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.2.1", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.36", + "karma-webpack": "4.0.2", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-proto-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-proto-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-trace-otlp-proto", "sideEffects": false diff --git a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts index 5e2b71c573..ff6a9c7b85 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts @@ -261,7 +261,10 @@ export function ensureExportTraceServiceRequestIsSet( } export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/opentelemetry-browser-detector/.eslintrc.js b/experimental/packages/opentelemetry-browser-detector/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/opentelemetry-browser-detector/.eslintrc.js +++ b/experimental/packages/opentelemetry-browser-detector/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-browser-detector/package.json b/experimental/packages/opentelemetry-browser-detector/package.json index 788fb3dd99..d983979a06 100644 --- a/experimental/packages/opentelemetry-browser-detector/package.json +++ b/experimental/packages/opentelemetry-browser-detector/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/opentelemetry-browser-detector", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Resource Detector for Browser", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -14,7 +14,7 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", @@ -53,28 +53,37 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "karma": "6.4.2", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.2.1", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.36", + "karma-webpack": "4.0.2", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/browser-detector" } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/.eslintrc.js b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/.eslintrc.js +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json index cebe38c3c9..3c316d301f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-metrics-otlp-grpc", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -47,16 +47,16 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "1.4.1", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -69,13 +69,12 @@ }, "dependencies": { "@grpc/grpc-js": "^1.7.1", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/exporter-metrics-otlp-http": "0.40.0", - "@opentelemetry/otlp-grpc-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/exporter-metrics-otlp-http": "0.43.0", + "@opentelemetry/otlp-grpc-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc", "sideEffects": false diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/.eslintrc.js b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/.eslintrc.js index e41d9a9299..c054089042 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/.eslintrc.js +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index e26bbcd17b..8db6655f59 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-metrics-otlp-http", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -23,7 +23,7 @@ "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -63,24 +63,24 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -95,12 +95,11 @@ "@opentelemetry/api": "^1.3.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-exporter-metrics-otlp-http", "sideEffects": false diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts index 21177777f6..db8a4a32ed 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts @@ -109,7 +109,7 @@ export class OTLPMetricExporterBase< OTLPMetricExporterOptions, ResourceMetrics, IExportMetricsServiceRequest - > + >, > implements PushMetricExporter { public _otlpExporter: T; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts index 1219f2d976..d2dce6517b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts @@ -17,7 +17,10 @@ import { Stream } from 'stream'; export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/.eslintrc.js b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/.eslintrc.js +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json index f10cf504ca..52ce8df0a2 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json @@ -1,20 +1,22 @@ { "name": "@opentelemetry/exporter-metrics-otlp-proto", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector using protobuf over HTTP", "main": "build/src/index.js", + "module": "build/esm/index.js", + "esnext": "build/esnext/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { "prepublishOnly": "npm run compile", - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "tdd": "npm run test -- --watch-extensions ts --watch", - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "version": "node ../../../scripts/version-update.js", - "watch": "tsc -w", + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "npm run precompile", "peer-api-check": "node ../../../scripts/peer-api-check.js", @@ -35,6 +37,12 @@ "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", @@ -47,15 +55,15 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -67,14 +75,13 @@ "@opentelemetry/api": "^1.3.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/exporter-metrics-otlp-http": "0.40.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "@opentelemetry/otlp-proto-exporter-base": "0.40.0", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/exporter-metrics-otlp-http": "0.43.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "@opentelemetry/otlp-proto-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-exporter-metrics-otlp-proto", "sideEffects": false 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 0012f0c118..27b816fe10 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts @@ -224,7 +224,10 @@ export function ensureExportMetricsServiceRequestIsSet( } export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { + constructor( + private _code: number, + private _msg?: string + ) { super(); } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esm.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esm.json new file mode 100644 index 0000000000..b657f54211 --- /dev/null +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esm.json @@ -0,0 +1,37 @@ +{ + "extends": "../../../tsconfig.base.esm.json", + "compilerOptions": { + "outDir": "build/esm", + "rootDir": "src", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ], + "references": [ + { + "path": "../../../api" + }, + { + "path": "../../../packages/opentelemetry-core" + }, + { + "path": "../../../packages/opentelemetry-resources" + }, + { + "path": "../../../packages/sdk-metrics" + }, + { + "path": "../opentelemetry-exporter-metrics-otlp-http" + }, + { + "path": "../otlp-exporter-base" + }, + { + "path": "../otlp-proto-exporter-base" + }, + { + "path": "../otlp-transformer" + } + ] +} diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esnext.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esnext.json new file mode 100644 index 0000000000..31e46faeda --- /dev/null +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esnext.json @@ -0,0 +1,37 @@ +{ + "extends": "../../../tsconfig.base.esnext.json", + "compilerOptions": { + "outDir": "build/esnext", + "rootDir": "src", + "tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ], + "references": [ + { + "path": "../../../api" + }, + { + "path": "../../../packages/opentelemetry-core" + }, + { + "path": "../../../packages/opentelemetry-resources" + }, + { + "path": "../../../packages/sdk-metrics" + }, + { + "path": "../opentelemetry-exporter-metrics-otlp-http" + }, + { + "path": "../otlp-exporter-base" + }, + { + "path": "../otlp-proto-exporter-base" + }, + { + "path": "../otlp-transformer" + } + ] +} diff --git a/experimental/packages/opentelemetry-exporter-prometheus/.eslintrc.js b/experimental/packages/opentelemetry-exporter-prometheus/.eslintrc.js index f756f4488b..9baf1b4956 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/.eslintrc.js +++ b/experimental/packages/opentelemetry-exporter-prometheus/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-exporter-prometheus/package.json b/experimental/packages/opentelemetry-exporter-prometheus/package.json index 8ae497886f..5b55ececd8 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/package.json +++ b/experimental/packages/opentelemetry-exporter-prometheus/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-prometheus", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,14 +43,14 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": "1.4.1", - "@opentelemetry/semantic-conventions": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/semantic-conventions": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -61,10 +61,9 @@ "@opentelemetry/api": "^1.3.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-exporter-prometheus", "sideEffects": false diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts index 8f84c5134c..42e4fc41e8 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts @@ -62,6 +62,7 @@ export class PrometheusExporter extends MetricReader { aggregationSelector: _instrumentType => Aggregation.Default(), aggregationTemporalitySelector: _instrumentType => AggregationTemporality.CUMULATIVE, + metricProducers: config.metricProducers, }); this._host = config.host || diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts index f43c456813..78721a90c0 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/export/types.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { MetricProducer } from '@opentelemetry/sdk-metrics'; + /** * Configuration interface for prometheus exporter */ @@ -56,4 +58,12 @@ export interface ExporterConfig { * @default false */ preventServerStart?: boolean; + + /** + * **Note, this option is experimental**. Additional MetricProducers to use as a source of + * aggregated metric data in addition to the SDK's metric data. The resource returned by + * these MetricProducers is ignored; the SDK's resource will be used instead. + * @experimental + */ + metricProducers?: MetricProducer[]; } diff --git a/experimental/packages/opentelemetry-instrumentation-fetch/.eslintrc.js b/experimental/packages/opentelemetry-instrumentation-fetch/.eslintrc.js index e41d9a9299..c054089042 100644 --- a/experimental/packages/opentelemetry-instrumentation-fetch/.eslintrc.js +++ b/experimental/packages/opentelemetry-instrumentation-fetch/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-instrumentation-fetch/package.json b/experimental/packages/opentelemetry-instrumentation-fetch/package.json index c8f1bfcb39..948b357d5a 100644 --- a/experimental/packages/opentelemetry-instrumentation-fetch/package.json +++ b/experimental/packages/opentelemetry-instrumentation-fetch/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-fetch", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry fetch automatic instrumentation package.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -16,7 +16,7 @@ "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", "version": "node ../../../scripts/version-update.js", "tdd": "karma start", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "node ../../../scripts/version-update.js", @@ -54,26 +54,26 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-zone": "1.14.0", - "@opentelemetry/propagator-b3": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-zone": "1.17.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -88,11 +88,10 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/sdk-trace-web": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/sdk-trace-web": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-fetch", "sideEffects": false diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/.eslintignore b/experimental/packages/opentelemetry-instrumentation-grpc/.eslintignore index 378eac25d3..cd163f08be 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/.eslintignore +++ b/experimental/packages/opentelemetry-instrumentation-grpc/.eslintignore @@ -1 +1,2 @@ build +test/proto diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/.eslintrc.js b/experimental/packages/opentelemetry-instrumentation-grpc/.eslintrc.js index f756f4488b..9baf1b4956 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/.eslintrc.js +++ b/experimental/packages/opentelemetry-instrumentation-grpc/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/package.json b/experimental/packages/opentelemetry-instrumentation-grpc/package.json index f8b247ffa6..fbf07ae716 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/package.json +++ b/experimental/packages/opentelemetry-instrumentation-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-grpc", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry grpc automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -9,7 +9,7 @@ "prepublishOnly": "npm run compile", "compile": "tsc --build", "clean": "tsc --build --clean", - "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", + "test": "npm run protos:generate && nyc ts-mocha -p tsconfig.json test/**/*.test.ts", "tdd": "npm run test -- --watch-extensions ts --watch", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", @@ -18,7 +18,8 @@ "watch": "tsc --build --watch", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "node ../../../scripts/version-update.js", - "peer-api-check": "node ../../../scripts/peer-api-check.js" + "peer-api-check": "node ../../../scripts/peer-api-check.js", + "protos:generate": "cd test/fixtures && buf generate" }, "keywords": [ "opentelemetry", @@ -45,23 +46,27 @@ "access": "public" }, "devDependencies": { + "@bufbuild/buf": "1.21.0-1", "@grpc/grpc-js": "^1.7.1", "@grpc/proto-loader": "^0.7.3", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-async-hooks": "1.14.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/sdk-trace-node": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/sdk-trace-node": "1.17.0", + "@protobuf-ts/grpc-transport": "2.9.1", + "@protobuf-ts/runtime": "2.9.1", + "@protobuf-ts/runtime-rpc": "2.9.1", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/semver": "7.5.0", - "@types/sinon": "10.0.15", + "@types/semver": "7.5.2", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", - "semver": "7.5.3", + "semver": "7.5.4", "sinon": "15.1.2", "ts-mocha": "10.0.0", "typescript": "4.4.4" @@ -70,9 +75,8 @@ "@opentelemetry/api": "^1.3.0" }, "dependencies": { - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-grpc", "sideEffects": false diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts index c61edf771b..9e26062d1c 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts @@ -22,9 +22,8 @@ import type { GrpcJsInstrumentation } from './'; import type { GrpcClientFunc, SendUnaryDataCallback } from './types'; import type { metadataCaptureType } from '../internal-types'; -import { SpanStatusCode, propagation, context } from '@opentelemetry/api'; +import { propagation, context } from '@opentelemetry/api'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; -import { CALL_SPAN_ENDED } from './serverUtils'; import { AttributeNames } from '../enums/AttributeNames'; import { GRPC_STATUS_CODE_OK } from '../status-code'; import { @@ -32,6 +31,7 @@ import { _grpcStatusCodeToOpenTelemetryStatusCode, _methodIsIgnored, } from '../utils'; +import { errorMonitor } from 'events'; /** * Parse a package method list and return a list of methods to patch @@ -63,6 +63,91 @@ export function getMethodsToWrap( return methodList; } +/** + * Patches a callback so that the current span for this trace is also ended + * when the callback is invoked. + */ +export function patchedCallback( + span: Span, + callback: SendUnaryDataCallback +) { + const wrappedFn: SendUnaryDataCallback = ( + err: grpcJs.ServiceError | null, + res?: ResponseType + ) => { + if (err) { + if (err.code) { + span.setStatus(_grpcStatusCodeToSpanStatus(err.code)); + span.setAttribute(SemanticAttributes.RPC_GRPC_STATUS_CODE, err.code); + } + span.setAttributes({ + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + }); + } else { + span.setAttribute( + SemanticAttributes.RPC_GRPC_STATUS_CODE, + GRPC_STATUS_CODE_OK + ); + } + + span.end(); + callback(err, res); + }; + return context.bind(context.active(), wrappedFn); +} + +export function patchResponseMetadataEvent( + span: Span, + call: EventEmitter, + metadataCapture: metadataCaptureType +) { + call.on('metadata', (responseMetadata: any) => { + metadataCapture.client.captureResponseMetadata(span, responseMetadata); + }); +} + +export function patchResponseStreamEvents(span: Span, call: EventEmitter) { + // Both error and status events can be emitted + // the first one emitted set spanEnded to true + let spanEnded = false; + const endSpan = () => { + if (!spanEnded) { + span.end(); + spanEnded = true; + } + }; + context.bind(context.active(), call); + call.on(errorMonitor, (err: ServiceError) => { + if (spanEnded) { + return; + } + + span.setStatus({ + code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), + message: err.message, + }); + span.setAttributes({ + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + [SemanticAttributes.RPC_GRPC_STATUS_CODE]: err.code, + }); + + endSpan(); + }); + + call.on('status', (status: SpanStatus) => { + if (spanEnded) { + return; + } + + span.setStatus(_grpcStatusCodeToSpanStatus(status.code)); + span.setAttribute(SemanticAttributes.RPC_GRPC_STATUS_CODE, status.code); + + endSpan(); + }); +} + /** * Execute grpc client call. Apply completitionspan properties and end the * span on callback or receiving an emitted event. @@ -71,44 +156,9 @@ export function makeGrpcClientRemoteCall( metadataCapture: metadataCaptureType, original: GrpcClientFunc, args: unknown[], - metadata: Metadata, - self: Client + metadata: grpcJs.Metadata, + self: grpcJs.Client ): (span: Span) => EventEmitter { - /** - * Patches a callback so that the current span for this trace is also ended - * when the callback is invoked. - */ - function patchedCallback( - span: Span, - callback: SendUnaryDataCallback - ) { - const wrappedFn: SendUnaryDataCallback = ( - err: ServiceError | null, - res?: ResponseType - ) => { - if (err) { - if (err.code) { - span.setStatus(_grpcStatusCodeToSpanStatus(err.code)); - span.setAttribute(SemanticAttributes.RPC_GRPC_STATUS_CODE, err.code); - } - span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, - }); - } else { - span.setStatus({ code: SpanStatusCode.UNSET }); - span.setAttribute( - SemanticAttributes.RPC_GRPC_STATUS_CODE, - GRPC_STATUS_CODE_OK - ); - } - - span.end(); - callback(err, res); - }; - return context.bind(context.active(), wrappedFn); - } - return (span: Span) => { // if unary or clientStream if (!original.responseStream) { @@ -132,67 +182,18 @@ export function makeGrpcClientRemoteCall( // if server stream or bidi if (original.responseStream) { - // Both error and status events can be emitted - // the first one emitted set spanEnded to true - let spanEnded = false; - const endSpan = () => { - if (!spanEnded) { - span.end(); - spanEnded = true; - } - }; - context.bind(context.active(), call); - call.on('error', (err: ServiceError) => { - if (call[CALL_SPAN_ENDED]) { - return; - } - call[CALL_SPAN_ENDED] = true; - - span.setStatus({ - code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), - message: err.message, - }); - span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, - [SemanticAttributes.RPC_GRPC_STATUS_CODE]: err.code, - }); - - endSpan(); - }); - - call.on('status', (status: SpanStatus) => { - if (call[CALL_SPAN_ENDED]) { - return; - } - call[CALL_SPAN_ENDED] = true; - - span.setStatus(_grpcStatusCodeToSpanStatus(status.code)); - span.setAttribute(SemanticAttributes.RPC_GRPC_STATUS_CODE, status.code); - - endSpan(); - }); + patchResponseStreamEvents(span, call); } return call; }; } -/** - * Returns the metadata argument from user provided arguments (`args`) - */ -export function getMetadata( - this: GrpcJsInstrumentation, - original: GrpcClientFunc, - grpcClient: typeof grpcJs, - args: Array -): Metadata { - let metadata: Metadata; - +export function getMetadataIndex(args: Array): number { // This finds an instance of Metadata among the arguments. // A possible issue that could occur is if the 'options' parameter from // the user contains an '_internal_repr' as well as a 'getMap' function, // but this is an extremely rare case. - let metadataIndex = args.findIndex((arg: unknown | Metadata) => { + return args.findIndex((arg: unknown | Metadata) => { return ( arg && typeof arg === 'object' && @@ -200,22 +201,45 @@ export function getMetadata( typeof (arg as Metadata).getMap === 'function' ); }); +} + +/** + * Returns the metadata argument from user provided arguments (`args`) + * If no metadata is provided in `args`: adds empty metadata to `args` and returns that empty metadata + */ +export function extractMetadataOrSplice( + grpcLib: typeof grpcJs, + args: Array, + spliceIndex: number +) { + let metadata: grpcJs.Metadata; + const metadataIndex = getMetadataIndex(args); if (metadataIndex === -1) { - metadata = new grpcClient.Metadata(); - if (!original.requestStream) { - // unary or server stream - metadataIndex = 1; - } else { - // client stream or bidi - metadataIndex = 0; - } - args.splice(metadataIndex, 0, metadata); + // Create metadata if it does not exist + metadata = new grpcLib.Metadata(); + args.splice(spliceIndex, 0, metadata); } else { metadata = args[metadataIndex] as Metadata; } return metadata; } +/** + * Returns the metadata argument from user provided arguments (`args`) + * Adds empty metadata to arguments if the default is used. + */ +export function extractMetadataOrSpliceDefault( + grpcClient: typeof grpcJs, + original: GrpcClientFunc, + args: Array +): grpcJs.Metadata { + return extractMetadataOrSplice( + grpcClient, + args, + original.requestStream ? 0 : 1 + ); +} + /** * Inject opentelemetry trace context into `metadata` for use by another * grpc receiver diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts index 72ad45e3bd..36be79fd07 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts @@ -26,6 +26,7 @@ import type { loadPackageDefinition, GrpcObject, } from '@grpc/grpc-js'; + import type * as grpcJs from '@grpc/grpc-js'; import type { @@ -36,6 +37,7 @@ import type { MakeClientConstructorFunction, PackageDefinition, GrpcClientFunc, + ClientRequestFunction, } from './types'; import type { GrpcInstrumentationConfig } from '../types'; import type { metadataCaptureType } from '../internal-types'; @@ -47,6 +49,7 @@ import { SpanOptions, SpanKind, trace, + Span, } from '@opentelemetry/api'; import { InstrumentationNodeModuleDefinition, @@ -63,9 +66,19 @@ import { import { getMethodsToWrap, makeGrpcClientRemoteCall, - getMetadata, + extractMetadataOrSpliceDefault, + setSpanContext, + patchedCallback, + patchResponseStreamEvents, + patchResponseMetadataEvent, + extractMetadataOrSplice, } from './clientUtils'; -import { _extractMethodAndService, metadataCapture, URI_REGEX } from '../utils'; +import { + _extractMethodAndService, + metadataCapture, + URI_REGEX, + _methodIsIgnored, +} from '../utils'; import { AttributeValues } from '../enums/AttributeValues'; export class GrpcJsInstrumentation extends InstrumentationBase { @@ -121,6 +134,41 @@ export class GrpcJsInstrumentation extends InstrumentationBase { 'loadPackageDefinition', this._patchLoadPackageDefinition(moduleExports) ); + if (isWrapped(moduleExports.Client.prototype)) { + this._unwrap(moduleExports.Client.prototype, 'makeUnaryRequest'); + this._unwrap( + moduleExports.Client.prototype, + 'makeClientStreamRequest' + ); + this._unwrap( + moduleExports.Client.prototype, + 'makeServerStreamRequest' + ); + this._unwrap( + moduleExports.Client.prototype, + 'makeBidiStreamRequest' + ); + } + this._wrap( + moduleExports.Client.prototype, + 'makeUnaryRequest', + this._patchClientRequestMethod(moduleExports, false) as any + ); + this._wrap( + moduleExports.Client.prototype, + 'makeClientStreamRequest', + this._patchClientRequestMethod(moduleExports, false) as any + ); + this._wrap( + moduleExports.Client.prototype, + 'makeServerStreamRequest', + this._patchClientRequestMethod(moduleExports, true) as any + ); + this._wrap( + moduleExports.Client.prototype, + 'makeBidiStreamRequest', + this._patchClientRequestMethod(moduleExports, true) as any + ); return moduleExports; }, (moduleExports, version) => { @@ -131,6 +179,16 @@ export class GrpcJsInstrumentation extends InstrumentationBase { this._unwrap(moduleExports, 'makeClientConstructor'); this._unwrap(moduleExports, 'makeGenericClientConstructor'); this._unwrap(moduleExports, 'loadPackageDefinition'); + this._unwrap(moduleExports.Client.prototype, 'makeUnaryRequest'); + this._unwrap( + moduleExports.Client.prototype, + 'makeClientStreamRequest' + ); + this._unwrap( + moduleExports.Client.prototype, + 'makeServerStreamRequest' + ); + this._unwrap(moduleExports.Client.prototype, 'makeBidiStreamRequest'); } ), ]; @@ -257,6 +315,84 @@ export class GrpcJsInstrumentation extends InstrumentationBase { }; } + /** + * Patch for grpc.Client.make*Request(...) functions. + * Provides auto-instrumentation for client requests when using a Client without + * makeGenericClientConstructor/makeClientConstructor + */ + private _patchClientRequestMethod( + grpcLib: typeof grpcJs, + hasResponseStream: boolean + ): ( + original: ClientRequestFunction + ) => ClientRequestFunction { + const instrumentation = this; + return (original: ClientRequestFunction) => { + instrumentation._diag.debug( + 'patched makeClientStreamRequest on grpc client' + ); + + return function makeClientStreamRequest(this: grpcJs.Client) { + // method must always be at first position + const method = arguments[0]; + const { name, service, methodAttributeValue } = + instrumentation._splitMethodString(method); + + // Do not attempt to trace/inject context if method is ignored + if ( + method != null && + _methodIsIgnored( + methodAttributeValue, + instrumentation.getConfig().ignoreGrpcMethods + ) + ) { + return original.apply(this, [...arguments]); + } + + const modifiedArgs = [...arguments]; + const metadata = extractMetadataOrSplice(grpcLib, modifiedArgs, 4); + + const span = instrumentation.createClientSpan( + name, + methodAttributeValue, + service, + metadata + ); + instrumentation.extractNetMetadata(this, span); + + // Callback is only present when there is no responseStream + if (!hasResponseStream) { + // Replace the callback with the patched one if it is there. + // If the callback arg is not a function on the last position then the client will throw + // and never call the callback -> so there's nothing to patch + const lastArgIndex = modifiedArgs.length - 1; + const callback = modifiedArgs[lastArgIndex]; + if (typeof callback === 'function') { + modifiedArgs[lastArgIndex] = patchedCallback(span, callback); + } + } + + return context.with(trace.setSpan(context.active(), span), () => { + setSpanContext(metadata); + + const call = original.apply(this, [...modifiedArgs]); + patchResponseMetadataEvent( + span, + call, + instrumentation._metadataCapture + ); + + // Subscribe to response stream events when there's a response stream. + if (hasResponseStream) { + patchResponseStreamEvents(span, call); + } + + return call; + }); + }; + }; + } + /** * Entry point for applying client patches to `grpc.makeClientConstructor(...)` equivalents * @param this GrpcJsPlugin @@ -320,10 +456,10 @@ export class GrpcJsInstrumentation extends InstrumentationBase { function clientMethodTrace(this: Client) { const name = `grpc.${original.path.replace('/', '')}`; const args = [...arguments]; - const metadata = getMetadata.call( + const metadata = extractMetadataOrSpliceDefault.call( instrumentation, - original, grpcClient, + original, args ); const { service, method } = _extractMethodAndService(original.path); @@ -335,18 +471,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase { [SemanticAttributes.RPC_METHOD]: method, [SemanticAttributes.RPC_SERVICE]: service, }); - // set net.peer.* from target (e.g., "dns:otel-productcatalogservice:8080") as a hint to APMs - const parsedUri = URI_REGEX.exec(this.getChannel().getTarget()); - if (parsedUri != null && parsedUri.groups != null) { - span.setAttribute( - SemanticAttributes.NET_PEER_NAME, - parsedUri.groups['name'] - ); - span.setAttribute( - SemanticAttributes.NET_PEER_PORT, - parseInt(parsedUri.groups['port']) - ); - } + instrumentation.extractNetMetadata(this, span); instrumentation._metadataCapture.client.captureRequestMetadata( span, @@ -368,6 +493,51 @@ export class GrpcJsInstrumentation extends InstrumentationBase { }; } + private _splitMethodString(method: string) { + if (method == null) { + return { name: '', service: '', methodAttributeValue: '' }; + } + const name = `grpc.${method.replace('/', '')}`; + const { service, method: methodAttributeValue } = + _extractMethodAndService(method); + return { name, service, methodAttributeValue }; + } + + private createClientSpan( + name: string, + methodAttributeValue: string, + service: string, + metadata?: grpcJs.Metadata + ) { + const span = this.tracer + .startSpan(name, { kind: SpanKind.CLIENT }) + .setAttributes({ + [SemanticAttributes.RPC_SYSTEM]: 'grpc', + [SemanticAttributes.RPC_METHOD]: methodAttributeValue, + [SemanticAttributes.RPC_SERVICE]: service, + }); + + if (metadata != null) { + this._metadataCapture.client.captureRequestMetadata(span, metadata); + } + return span; + } + + private extractNetMetadata(client: grpcJs.Client, span: Span) { + // set net.peer.* from target (e.g., "dns:otel-productcatalogservice:8080") as a hint to APMs + const parsedUri = URI_REGEX.exec(client.getChannel().getTarget()); + if (parsedUri != null && parsedUri.groups != null) { + span.setAttribute( + SemanticAttributes.NET_PEER_NAME, + parsedUri.groups['name'] + ); + span.setAttribute( + SemanticAttributes.NET_PEER_PORT, + parseInt(parsedUri.groups['port']) + ); + } + } + /** * Utility function to patch *all* functions loaded through a proto file. * Recursively searches for Client classes and patches all methods, reversing the diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/types.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/types.ts index e9f15b45ab..06ca7c0b61 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/types.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/types.ts @@ -64,6 +64,10 @@ export type GrpcClientFunc = ((...args: unknown[]) => GrpcEmitter) & { export type ServerRegisterFunction = typeof Server.prototype.register; +export type ClientRequestFunction = ( + ...args: unknown[] +) => ReturnType; + export type MakeClientConstructorFunction = typeof makeGenericClientConstructor; export type { HandleCall } from '@grpc/grpc-js/build/src/server-call'; diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/.gitignore b/experimental/packages/opentelemetry-instrumentation-grpc/test/.gitignore new file mode 100644 index 0000000000..c9438a302c --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/.gitignore @@ -0,0 +1 @@ +/proto diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.gen.yaml b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.gen.yaml new file mode 100644 index 0000000000..a0aba044f1 --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.gen.yaml @@ -0,0 +1,9 @@ +version: v1 +plugins: + - plugin: buf.build/community/timostamm-protobuf-ts:v2.9.0 + out: ../../test/proto/ts/fixtures + opt: + - long_type_string + - generate_dependencies + - ts_nocheck + diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.lock b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.lock new file mode 100644 index 0000000000..65d8f1f75c --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.lock @@ -0,0 +1,8 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: googleapis + repository: googleapis + commit: cc916c31859748a68fd229a3c8d7a2e8 + digest: shake256:469b049d0eb04203d5272062636c078decefc96fec69739159c25d85349c50c34c7706918a8b216c5c27f76939df48452148cff8c5c3ae77fa6ba5c25c1b8bf8 diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.yaml b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.yaml new file mode 100644 index 0000000000..dc977e439a --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/fixtures/buf.yaml @@ -0,0 +1,9 @@ +version: v1 +lint: + use: + - DEFAULT +breaking: + use: + - FILE +deps: + - buf.build/googleapis/googleapis diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/grpc-protobuf-ts.test.ts b/experimental/packages/opentelemetry-instrumentation-grpc/test/grpc-protobuf-ts.test.ts new file mode 100644 index 0000000000..8e238a6acc --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/grpc-protobuf-ts.test.ts @@ -0,0 +1,831 @@ +/* + * 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 { GrpcInstrumentation } from '../src'; + +const instrumentation = new GrpcInstrumentation(); +instrumentation.enable(); +instrumentation.disable(); + +import { GrpcTransport } from '@protobuf-ts/grpc-transport'; +import * as grpc from '@grpc/grpc-js'; +import { GrpcTesterClient } from './proto/ts/fixtures/grpc-test.client'; +import { + InMemorySpanExporter, + NodeTracerProvider, + SimpleSpanProcessor, +} from '@opentelemetry/sdk-trace-node'; +import * as protoLoader from '@grpc/proto-loader'; +import * as path from 'path'; +import * as assert from 'assert'; +import { + context, + ContextManager, + propagation, + SpanKind, + trace, +} from '@opentelemetry/api'; +import { W3CTraceContextPropagator } from '@opentelemetry/core'; +import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; +import { startServer } from './helper'; +import { + assertExportedSpans, + assertNoSpansExported, + SpanAssertionFunction, + TestFunction, +} from './protobuf-ts-utils'; + +const memoryExporter = new InMemorySpanExporter(); +const PROTO_PATH = path.resolve(__dirname, './fixtures/grpc-test.proto'); +const NO_ERROR = grpc.status.UNAUTHENTICATED + 1; + +/** + * Creates a client generated via protobuf-ts that is using the {@link grpc.Client} class + * directly. + */ +function createClient() { + return new GrpcTesterClient( + new GrpcTransport({ + host: 'localhost:3333', + channelCredentials: grpc.credentials.createInsecure(), + }) + ); +} + +/** + * Loads the server from proto and starts it on port 3333. + */ +async function loadAndStartServer() { + const options = { + keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true, + }; + + // Reloading from proto is needed as only servers loaded after the + // instrumentation is enabled will be instrumented. + const packageDefinition = await protoLoader.load(PROTO_PATH, options); + const proto = grpc.loadPackageDefinition(packageDefinition).pkg_test; + return startServer(proto, 3333); +} + +/** + * Creates a list of test data that includes all possible cases of status codes + * returned by the server, the input for the server to provoke the status codes, + * and the expected result code that should be present on the span. + */ +function getStatusCodeTestData(): { + // Name of the key used in the test (OK, UNAUTHENTICATED, DATA_LOSS, ...) + key: string; + // Input for the server implementation that will provoke the status code from 'key' + input: number; + // The result code that should be present on the created span + expectedResultCode: number; +}[] { + const codes = Object.keys(grpc.status) + .filter(key => !isNaN(Number(grpc.status[key as any]))) + // Remove 'OK' as the test server has special behavior to provoke an 'OK' response + .filter(key => key !== 'OK') + // Create the test data + .map(key => { + return { + key: key, + input: Number(grpc.status[key as any]), + expectedResultCode: Number(grpc.status[key as any]), + }; + }); + + // Push 'OK' with special input to provoke 'OK' response from test-server + codes.push({ + key: 'OK', + input: NO_ERROR, + expectedResultCode: grpc.status.OK, + }); + + return codes; +} + +/** + * Creates tests that assert that no spans are created. + * @param statusCodeTestWithRootSpan function that creates tests that include a root span + * @param statusCodeTestNoRootSpan function that creates tests that do not include a root span + */ +function shouldNotCreateSpans( + statusCodeTestWithRootSpan: TestFunction, + statusCodeTestNoRootSpan: TestFunction +) { + describe('with root span', () => { + getStatusCodeTestData().forEach(({ key, input, expectedResultCode }) => { + statusCodeTestWithRootSpan( + input, + key, + expectedResultCode, + assertNoSpansExported + ); + }); + }); + + describe('without root span', () => { + getStatusCodeTestData().forEach(({ key, input, expectedResultCode }) => { + statusCodeTestNoRootSpan( + input, + key, + expectedResultCode, + assertNoSpansExported + ); + }); + }); +} + +describe('#grpc-protobuf', () => { + let client: GrpcTesterClient; + let server: grpc.Server; + const provider = new NodeTracerProvider(); + let contextManager: ContextManager; + provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + + before(() => { + propagation.setGlobalPropagator(new W3CTraceContextPropagator()); + instrumentation.setTracerProvider(provider); + }); + + beforeEach(() => { + memoryExporter.reset(); + contextManager = new AsyncHooksContextManager().enable(); + context.setGlobalContextManager(contextManager); + }); + + describe('client', async () => { + beforeEach(async () => { + instrumentation.enable(); + client = createClient(); + + server = await loadAndStartServer(); + }); + + afterEach(done => { + context.disable(); + server.tryShutdown(() => { + instrumentation.disable(); + done(); + }); + }); + + describe('makeUnaryRequest()', async () => { + async function act(status: number) { + return client.unaryMethod({ + num: status, + }); + } + + function statusCodeTestNoRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, async () => { + // Act + try { + const request = await act(input); + // Assert success results + assert.strictEqual(request.response.num, input); + } catch (e) { + // Assert failure results + assert.strictEqual(e.code, key); + } + // Assert span data + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'UnaryMethod', + expectedSpanStatus + ); + }); + } + + function statusCodeTestWithRootSpan( + input: number, + key: string, + expectedResultCode: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, async () => { + // Arrange + const span = provider + .getTracer('default') + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + return context.with( + trace.setSpan(context.active(), span), + async () => { + const rootSpan = trace.getSpan(context.active()); + assert.ok(rootSpan != null); + assert.deepStrictEqual(rootSpan, span); + + // Act + try { + const request = await act(input); + // Assert success results + assert.strictEqual(request.response.num, input); + } catch (e) { + // Assert failure results + assert.strictEqual(e.code, key); + } + + // Assert + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'UnaryMethod', + expectedResultCode, + rootSpan + ); + } + ); + }); + } + + describe('should create root client span and server child span', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestNoRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should create child client span when parent span exists', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestWithRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should not create any spans when disabled', () => { + beforeEach(done => { + instrumentation.disable(); + server.tryShutdown(() => { + loadAndStartServer().then(loadedServer => { + server = loadedServer; + done(); + }); + }); + }); + + afterEach(() => { + instrumentation.enable(); + }); + + shouldNotCreateSpans( + statusCodeTestWithRootSpan, + statusCodeTestNoRootSpan + ); + }); + }); + + describe('makeClientStreamRequest()', () => { + async function act(input: number) { + const call = client.clientStreamMethod({ + num: input, + }); + + await call.requests.send({ num: input }); + await call.requests.send({ num: input }); + await call.requests.complete(); + + return await call.response; + } + + async function statusCodeTestNoRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, async () => { + // Act + try { + const response = await act(input); + // Assert success results + assert.strictEqual(response.num, input * 2); + } catch (e) { + // Assert failure results + assert.strictEqual(e.code, key); + } + + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'ClientStreamMethod', + expectedSpanStatus + ); + }); + } + + async function statusCodeTestWithRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, async () => { + // Arrange + const span = provider + .getTracer('default') + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + return context.with( + trace.setSpan(context.active(), span), + async () => { + const rootSpan = trace.getSpan(context.active()); + assert.ok(rootSpan != null); + assert.deepStrictEqual(rootSpan, span); + + // Act + try { + const response = await act(input); + // Assert success results + assert.strictEqual(response.num, input * 2); + } catch (e) { + // Assert failure results + assert.strictEqual(e.code, key); + } + + // Assert + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'ClientStreamMethod', + expectedSpanStatus, + rootSpan + ); + } + ); + }); + } + + describe('should create root client span and server child span', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestNoRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should create child client span when parent span exists', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestWithRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should not create any spans when disabled', () => { + beforeEach(done => { + instrumentation.disable(); + server.tryShutdown(() => { + loadAndStartServer().then(loadedServer => { + server = loadedServer; + done(); + }); + }); + }); + + afterEach(() => { + instrumentation.enable(); + }); + + shouldNotCreateSpans( + statusCodeTestWithRootSpan, + statusCodeTestNoRootSpan + ); + }); + }); + + describe('makeServerStreamRequest()', () => { + function statusCodeTestNoRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, done => { + const serverStream = client.serverStreamMethod({ + num: input, + }); + + serverStream.responses.onMessage(message => { + assert.strictEqual(message.num, input); + }); + + function completeCallback() { + try { + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'ServerStreamMethod', + expectedSpanStatus + ); + } catch (err) { + // catch error and call done() to ensure an error message + // is shown in the test results instead of a test timeout + done(err); + return; + } + done(); + } + + serverStream.responses.onError(completeCallback); + serverStream.responses.onComplete(completeCallback); + }); + } + + function statusCodeTestWithRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, done => { + // Arrange + const span = provider + .getTracer('default') + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + context.with(trace.setSpan(context.active(), span), async () => { + const rootSpan = trace.getSpan(context.active()); + assert.ok(rootSpan != null); + assert.deepStrictEqual(rootSpan, span); + + // Act + const serverStream = client.serverStreamMethod({ + num: input, + }); + + serverStream.responses.onMessage(message => { + assert.strictEqual(message.num, input); + }); + + function completeCallback() { + try { + // Assert + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'ServerStreamMethod', + expectedSpanStatus, + rootSpan + ); + } catch (err) { + // catch error and call done() to ensure an error message + // is shown in the test results instead of a test timeout + done(err); + return; + } + done(); + } + + serverStream.responses.onError(completeCallback); + serverStream.responses.onComplete(completeCallback); + }); + }); + } + + describe('should create root client span and server child span', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestNoRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should create child client span when parent span exists', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestWithRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should not create any spans when disabled', () => { + beforeEach(done => { + instrumentation.disable(); + server.tryShutdown(() => { + loadAndStartServer().then(loadedServer => { + server = loadedServer; + done(); + }); + }); + }); + + afterEach(() => { + instrumentation.enable(); + }); + + shouldNotCreateSpans( + statusCodeTestWithRootSpan, + statusCodeTestNoRootSpan + ); + }); + }); + + describe('makeBidiStreamRequest()', () => { + function statusCodeTestNoRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, done => { + const bidiStream = client.bidiStreamMethod(); + + bidiStream.responses.onMessage(message => { + assert.strictEqual(message.num, input); + }); + + function completeHandler() { + try { + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'BidiStreamMethod', + expectedSpanStatus + ); + } catch (err) { + // catch error and call done() to ensure an error message + // is shown in the test results instead of a test timeout + done(err); + return; + } + done(); + } + + bidiStream.responses.onError(completeHandler); + bidiStream.responses.onComplete(completeHandler); + + bidiStream.requests.send({ + num: input, + }); + bidiStream.requests.send({ + num: input, + }); + bidiStream.requests.complete(); + }); + } + + function statusCodeTestWithRootSpan( + input: number, + key: string, + expectedSpanStatus: number, + assertSpans: SpanAssertionFunction + ) { + it('with status code: ' + key, done => { + // Arrange + const span = provider + .getTracer('default') + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + context.with(trace.setSpan(context.active(), span), () => { + const rootSpan = trace.getSpan(context.active()); + assert.ok(rootSpan != null); + assert.deepStrictEqual(rootSpan, span); + + // Act + const bidiStream = client.bidiStreamMethod(); + + function completeHandler() { + try { + assertSpans( + memoryExporter, + 'pkg_test.GrpcTester', + 'BidiStreamMethod', + expectedSpanStatus, + rootSpan + ); + } catch (err) { + // catch error and call done() to ensure an error message + // is shown in the test results instead of a test timeout + done(err); + return; + } + done(); + } + + bidiStream.responses.onMessage(message => { + assert.strictEqual(message.num, input); + }); + + bidiStream.responses.onError(completeHandler); + bidiStream.responses.onComplete(completeHandler); + + bidiStream.requests.send({ + num: input, + }); + bidiStream.requests.send({ + num: input, + }); + bidiStream.requests.complete(); + }); + }); + } + + describe('should create root client span and server child span', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestNoRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should create child client span when parent span exists', () => { + getStatusCodeTestData().forEach( + ({ key, input, expectedResultCode }) => { + statusCodeTestWithRootSpan( + input, + key, + expectedResultCode, + assertExportedSpans + ); + } + ); + }); + + describe('should not create any spans when disabled', () => { + beforeEach(done => { + instrumentation.disable(); + server.tryShutdown(() => { + loadAndStartServer().then(loadedServer => { + server = loadedServer; + done(); + }); + }); + }); + + afterEach(() => { + instrumentation.enable(); + }); + + shouldNotCreateSpans( + statusCodeTestWithRootSpan, + statusCodeTestNoRootSpan + ); + }); + }); + }); + + describe('should not produce telemetry when ignored via config', () => { + beforeEach(async () => { + instrumentation.disable(); + instrumentation.setConfig({ + ignoreGrpcMethods: [ + 'UnaryMethod', + new RegExp(/^camel.*Method$/), + (str: string) => str === 'BidiStreamMethod', + ], + }); + instrumentation.enable(); + client = createClient(); + + server = await loadAndStartServer(); + }); + + it('when filtered by exact string', async () => { + await client.unaryMethod({ num: NO_ERROR }); + assertNoSpansExported( + memoryExporter, + 'pkg_test.GrpcTester', + 'UnaryMethod', + grpc.status.OK + ); + }); + + it('when filtered by RegExp', async () => { + await client.camelCaseMethod({ num: NO_ERROR }); + assertNoSpansExported( + memoryExporter, + 'pkg_test.GrpcTester', + 'UnaryMethod', + grpc.status.OK + ); + }); + + it('when filtered by predicate', done => { + const stream = client.bidiStreamMethod({ num: NO_ERROR }); + stream.requests.send({ + num: NO_ERROR, + }); + stream.requests.complete(); + + stream.responses.onComplete(() => { + assertNoSpansExported( + memoryExporter, + 'pkg_test.GrpcTester', + 'UnaryMethod', + grpc.status.OK + ); + done(); + }); + }); + + afterEach(done => { + instrumentation.setConfig({}); + context.disable(); + server.tryShutdown(() => { + instrumentation.disable(); + done(); + }); + }); + }); + + describe('should capture metadata when set up in config', () => { + beforeEach(async () => { + instrumentation.setConfig({ + metadataToSpanAttributes: { + client: { + requestMetadata: ['client_metadata_key'], + responseMetadata: ['server_metadata_key'], + }, + server: { + requestMetadata: ['client_metadata_key'], + responseMetadata: ['server_metadata_key'], + }, + }, + }); + instrumentation.enable(); + client = createClient(); + + server = await loadAndStartServer(); + }); + + it('should capture client metadata', async () => { + await client.unaryMethod( + { num: NO_ERROR }, + { + meta: { + client_metadata_key: 'client_metadata_value', + }, + } + ); + const spans = memoryExporter.getFinishedSpans(); + assert.equal( + spans[0].attributes['rpc.request.metadata.client_metadata_key'], + 'client_metadata_value' + ); + }); + + afterEach(done => { + instrumentation.setConfig({}); + context.disable(); + server.tryShutdown(() => { + instrumentation.disable(); + done(); + }); + }); + }); +}); diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts b/experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts index 693cdeab46..9d861fd651 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts @@ -34,18 +34,18 @@ import * as assert from 'assert'; import * as protoLoader from '@grpc/proto-loader'; import { status as GrpcStatus, - requestCallback, ServerUnaryCall, + requestCallback, ServerReadableStream, - ServerWritableStream, ServerDuplexStream, + ServerWritableStream, Client, Metadata, ServiceError, Server, - ServerCredentials, credentials, loadPackageDefinition, + ServerCredentials, } from '@grpc/grpc-js'; import { assertPropagation, assertSpan } from './utils/assertionUtils'; import { promisify } from 'util'; @@ -109,13 +109,149 @@ const checkEqual = ? requestEqual(x)(y) : false; +const replicate = (request: TestRequestResponse) => { + const result: TestRequestResponse[] = []; + for (let i = 0; i < request.num; i++) { + result.push(request); + } + return result; +}; + +export async function startServer(proto: any, port: number) { + const MAX_ERROR_STATUS = GrpcStatus.UNAUTHENTICATED; + const server = new Server(); + + function getError(msg: string, code: number): ServiceError | null { + const err: ServiceError = { + ...new Error(msg), + name: msg, + message: msg, + code, + details: msg, + metadata: new Metadata(), + }; + return err; + } + + server.addService(proto.GrpcTester.service, { + // An error is emitted every time + // request.num <= MAX_ERROR_STATUS = (status.UNAUTHENTICATED) + // in those cases, erro.code = request.num + + // This method returns the request + // This method returns the request + unaryMethodWithMetadata( + call: ServerUnaryCall, + callback: requestCallback + ) { + const serverMetadata: any = new Metadata(); + serverMetadata.add('server_metadata_key', 'server_metadata_value'); + + call.sendMetadata(serverMetadata); + + call.request.num <= MAX_ERROR_STATUS + ? callback( + getError( + 'Unary Method with Metadata Error', + call.request.num + ) as ServiceError + ) + : callback(null, { num: call.request.num }); + }, + + // This method returns the request + unaryMethod( + call: ServerUnaryCall, + callback: requestCallback + ) { + call.request.num <= MAX_ERROR_STATUS + ? callback( + getError('Unary Method Error', call.request.num) as ServiceError + ) + : callback(null, { num: call.request.num }); + }, + + // This method returns the request + camelCaseMethod( + call: ServerUnaryCall, + callback: requestCallback + ) { + call.request.num <= MAX_ERROR_STATUS + ? callback( + getError('Unary Method Error', call.request.num) as ServiceError + ) + : callback(null, { num: call.request.num }); + }, + + // This method sums the requests + clientStreamMethod( + call: ServerReadableStream, + callback: requestCallback + ) { + let sum = 0; + let hasError = false; + let code = GrpcStatus.OK; + call.on('data', (data: TestRequestResponse) => { + sum += data.num; + if (data.num <= MAX_ERROR_STATUS) { + hasError = true; + code = data.num; + } + }); + call.on('end', () => { + hasError + ? callback(getError('Client Stream Method Error', code) as any) + : callback(null, { num: sum }); + }); + }, + + // This method returns an array that replicates the request, request.num of + // times + serverStreamMethod: (call: ServerWritableStream) => { + const result = replicate(call.request); + + if (call.request.num <= MAX_ERROR_STATUS) { + call.emit( + 'error', + getError('Server Stream Method Error', call.request.num) + ); + } else { + result.forEach(element => { + call.write(element); + }); + } + call.end(); + }, + + // This method returns the request + bidiStreamMethod: (call: ServerDuplexStream) => { + call.on('data', (data: TestRequestResponse) => { + if (data.num <= MAX_ERROR_STATUS) { + call.emit('error', getError('Server Stream Method Error', data.num)); + } else { + call.write(data); + } + }); + call.on('end', () => { + call.end(); + }); + }, + }); + const bindAwait = promisify(server.bindAsync); + await bindAwait.call( + server, + 'localhost:' + port, + ServerCredentials.createInsecure() + ); + server.start(); + return server; +} + export const runTests = ( plugin: GrpcInstrumentation, moduleName: string, grpcPort: number ) => { - const MAX_ERROR_STATUS = GrpcStatus.UNAUTHENTICATED; - const grpcClient = { unaryMethodWithMetadata: ( client: TestGrpcClient, @@ -275,138 +411,6 @@ export const runTests = ( let server: Server; let client: Client; - const replicate = (request: TestRequestResponse) => { - const result: TestRequestResponse[] = []; - for (let i = 0; i < request.num; i++) { - result.push(request); - } - return result; - }; - - async function startServer(proto: any) { - const server = new Server(); - - function getError(msg: string, code: number): ServiceError | null { - const err: ServiceError = { - ...new Error(msg), - name: msg, - message: msg, - code, - details: msg, - metadata: new Metadata(), - }; - return err; - } - - server.addService(proto.GrpcTester.service, { - // An error is emitted every time - // request.num <= MAX_ERROR_STATUS = (status.UNAUTHENTICATED) - // in those cases, erro.code = request.num - - // This method returns the request - unaryMethodWithMetadata( - call: ServerUnaryCall, - callback: requestCallback - ) { - const serverMetadata = new Metadata(); - serverMetadata.add('server_metadata_key', 'server_metadata_value'); - - call.sendMetadata(serverMetadata); - - call.request.num <= MAX_ERROR_STATUS - ? callback( - getError('Unary Method with Metadata Error', call.request.num) - ) - : callback(null, { num: call.request.num }); - }, - - // This method returns the request - unaryMethod( - call: ServerUnaryCall, - callback: requestCallback - ) { - call.request.num <= MAX_ERROR_STATUS - ? callback(getError('Unary Method Error', call.request.num)) - : callback(null, { num: call.request.num }); - }, - - // This method returns the request - camelCaseMethod( - call: ServerUnaryCall, - callback: requestCallback - ) { - call.request.num <= MAX_ERROR_STATUS - ? callback(getError('Unary Method Error', call.request.num)) - : callback(null, { num: call.request.num }); - }, - - // This method sums the requests - clientStreamMethod( - call: ServerReadableStream, - callback: requestCallback - ) { - let sum = 0; - let hasError = false; - let code = GrpcStatus.OK; - call.on('data', (data: TestRequestResponse) => { - sum += data.num; - if (data.num <= MAX_ERROR_STATUS) { - hasError = true; - code = data.num; - } - }); - call.on('end', () => { - hasError - ? callback(getError('Client Stream Method Error', code) as any) - : callback(null, { num: sum }); - }); - }, - - // This method returns an array that replicates the request, request.num of - // times - serverStreamMethod: (call: ServerWritableStream) => { - const result = replicate(call.request); - - if (call.request.num <= MAX_ERROR_STATUS) { - call.emit( - 'error', - getError('Server Stream Method Error', call.request.num) - ); - } else { - result.forEach(element => { - call.write(element); - }); - } - call.end(); - }, - - // This method returns the request - bidiStreamMethod: (call: ServerDuplexStream) => { - call.on('data', (data: TestRequestResponse) => { - if (data.num <= MAX_ERROR_STATUS) { - call.emit( - 'error', - getError('Server Stream Method Error', data.num) - ); - } else { - call.write(data); - } - }); - call.on('end', () => { - call.end(); - }); - }, - }); - const bindAwait = promisify(server.bindAsync); - await bindAwait.call( - server, - 'localhost:' + grpcPort, - ServerCredentials.createInsecure() - ); - server.start(); - return server; - } - function createClient(proto: any) { return new proto.GrpcTester( 'localhost:' + grpcPort, @@ -590,9 +594,7 @@ export const runTests = ( .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); return context.with(trace.setSpan(context.active(), span), async () => { const rootSpan = trace.getSpan(context.active()); - if (!rootSpan) { - return assert.ok(false); - } + assert.ok(rootSpan != null); assert.deepStrictEqual(rootSpan, span); const args = [client, method.request, method.metadata]; @@ -706,9 +708,7 @@ export const runTests = ( .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); return context.with(trace.setSpan(context.active(), span), async () => { const rootSpan = trace.getSpan(context.active()); - if (!rootSpan) { - return assert.ok(false); - } + assert.ok(rootSpan != null); assert.deepStrictEqual(rootSpan, span); const args = [client, insertError(method.request)(errorCode)]; @@ -768,7 +768,7 @@ export const runTests = ( const packageDefinition = await protoLoader.load(PROTO_PATH, options); const proto = loadPackageDefinition(packageDefinition).pkg_test; - server = await startServer(proto); + server = await startServer(proto, grpcPort); client = createClient(proto); }); @@ -811,7 +811,7 @@ export const runTests = ( const packageDefinition = await protoLoader.load(PROTO_PATH, options); const proto = loadPackageDefinition(packageDefinition).pkg_test; - server = await startServer(proto); + server = await startServer(proto, grpcPort); client = createClient(proto); }); @@ -845,7 +845,7 @@ export const runTests = ( const packageDefinition = await protoLoader.load(PROTO_PATH, options); const proto = loadPackageDefinition(packageDefinition).pkg_test; - server = await startServer(proto); + server = await startServer(proto, grpcPort); client = createClient(proto); }); @@ -889,7 +889,7 @@ export const runTests = ( const packageDefinition = await protoLoader.load(PROTO_PATH, options); const proto = loadPackageDefinition(packageDefinition).pkg_test; - server = await startServer(proto); + server = await startServer(proto, grpcPort); client = createClient(proto); }); @@ -976,7 +976,7 @@ export const runTests = ( const packageDefinition = await protoLoader.load(PROTO_PATH, options); const proto = loadPackageDefinition(packageDefinition).pkg_test; - server = await startServer(proto); + server = await startServer(proto, grpcPort); client = createClient(proto); }); diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/test/protobuf-ts-utils.ts b/experimental/packages/opentelemetry-instrumentation-grpc/test/protobuf-ts-utils.ts new file mode 100644 index 0000000000..2fc2a3d1be --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation-grpc/test/protobuf-ts-utils.ts @@ -0,0 +1,111 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Span, SpanKind } from '@opentelemetry/api'; +import * as assert from 'assert'; + +import { + InMemorySpanExporter, + ReadableSpan, +} from '@opentelemetry/sdk-trace-base'; +import { assertPropagation, assertSpan } from './utils/assertionUtils'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; + +export type SpanAssertionFunction = ( + exporter: InMemorySpanExporter, + rpcService: string, + rpcMethod: string, + expectedSpanStatus: number, + rootSpan?: Span +) => void; + +export type TestFunction = ( + input: number, + errorKey: string, + expectedResultCode: number, + assertSpans: SpanAssertionFunction +) => void; + +function validateSpans( + clientSpan: ReadableSpan, + serverSpan: ReadableSpan, + rpcService: string, + rpcMethod: string, + status: number +) { + const validations = { + name: `grpc.${rpcService}/${rpcMethod}`, + netPeerName: 'localhost', + status: status, + netPeerPort: 3333, + }; + + assert.strictEqual( + clientSpan.spanContext().traceId, + serverSpan.spanContext().traceId + ); + assertPropagation(serverSpan, clientSpan); + + assertSpan('grpc', serverSpan, SpanKind.SERVER, validations); + assertSpan('grpc', clientSpan, SpanKind.CLIENT, validations); + assert.strictEqual( + clientSpan.attributes[SemanticAttributes.RPC_METHOD], + rpcMethod + ); + assert.strictEqual( + clientSpan.attributes[SemanticAttributes.RPC_SERVICE], + rpcService + ); +} + +export function assertNoSpansExported( + exporter: InMemorySpanExporter, + _rpcService: string, + _rpcMethod: string, + _expectedSpanStatus: number, + _rootSpan?: Span +) { + const spans = exporter.getFinishedSpans(); + assert.strictEqual(spans.length, 0); +} + +export function assertExportedSpans( + exporter: InMemorySpanExporter, + rpcService: string, + rpcMethod: string, + expectedSpanStatus: number, + rootSpan?: Span +) { + const spans = exporter.getFinishedSpans(); + assert.strictEqual(spans.length, 2); + const serverSpan = spans[0]; + const clientSpan = spans[1]; + + validateSpans( + clientSpan, + serverSpan, + rpcService, + rpcMethod, + expectedSpanStatus + ); + + if (rootSpan) { + assert.strictEqual( + rootSpan?.spanContext().traceId, + serverSpan.spanContext().traceId + ); + assert.strictEqual(rootSpan?.spanContext().spanId, clientSpan.parentSpanId); + } +} diff --git a/experimental/packages/opentelemetry-instrumentation-http/.eslintrc.js b/experimental/packages/opentelemetry-instrumentation-http/.eslintrc.js index f756f4488b..9baf1b4956 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/.eslintrc.js +++ b/experimental/packages/opentelemetry-instrumentation-http/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-instrumentation-http/package.json b/experimental/packages/opentelemetry-instrumentation-http/package.json index c39d34ace9..aebe37781d 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/package.json +++ b/experimental/packages/opentelemetry-instrumentation-http/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-http", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry http/https automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -45,23 +45,23 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-async-hooks": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/sdk-trace-node": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/sdk-trace-node": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", "@types/request-promise-native": "1.0.18", - "@types/semver": "7.5.0", - "@types/sinon": "10.0.15", + "@types/semver": "7.5.2", + "@types/sinon": "10.0.16", "@types/superagent": "4.1.18", - "axios": "1.4.0", + "axios": "1.5.0", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", + "nock": "13.3.3", "nyc": "15.1.0", "request": "2.88.2", "request-promise-native": "1.0.9", @@ -74,11 +74,10 @@ "@opentelemetry/api": "^1.3.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "semver": "^7.5.1", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/semantic-conventions": "1.17.0", + "semver": "^7.5.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http", "sideEffects": false diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts index 15ca92a45e..9422bbc9ef 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts @@ -105,7 +105,7 @@ export class HttpInstrumentation extends InstrumentationBase { init(): [ InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleDefinition + InstrumentationNodeModuleDefinition, ] { return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()]; } @@ -237,7 +237,7 @@ export class HttpInstrumentation extends InstrumentationBase { // https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback // https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198 return function outgoingGetRequest< - T extends http.RequestOptions | string | url.URL + T extends http.RequestOptions | string | url.URL, >(options: T, ...args: HttpRequestArgs): http.ClientRequest { const req = clientRequest(options, ...args); req.end(); diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/.eslintrc.js b/experimental/packages/opentelemetry-instrumentation-xml-http-request/.eslintrc.js index b50dfd815b..7364a382d0 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/.eslintrc.js +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "browser": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/package.json b/experimental/packages/opentelemetry-instrumentation-xml-http-request/package.json index 4eb469da07..511f4fe3e0 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/package.json +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-xml-http-request", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry XMLHttpRequest automatic instrumentation package.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -16,7 +16,7 @@ "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", "version": "node ../../../scripts/version-update.js", "tdd": "karma start", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "node ../../../scripts/version-update.js", @@ -54,26 +54,26 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-zone": "1.14.0", - "@opentelemetry/propagator-b3": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-zone": "1.17.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -88,11 +88,10 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/sdk-trace-web": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/sdk-trace-web": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-xml-http-request", "sideEffects": false diff --git a/experimental/packages/opentelemetry-instrumentation/.eslintrc.js b/experimental/packages/opentelemetry-instrumentation/.eslintrc.js index e41d9a9299..c054089042 100644 --- a/experimental/packages/opentelemetry-instrumentation/.eslintrc.js +++ b/experimental/packages/opentelemetry-instrumentation/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-instrumentation/package.json b/experimental/packages/opentelemetry-instrumentation/package.json index 944258ad8f..ca9e9df4e8 100644 --- a/experimental/packages/opentelemetry-instrumentation/package.json +++ b/experimental/packages/opentelemetry-instrumentation/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation", - "version": "0.40.0", + "version": "0.43.0", "description": "Base class for node which OpenTelemetry instrumentation modules extend", "author": "OpenTelemetry Authors", "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation", @@ -51,7 +51,7 @@ "test:cjs": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "test:esm": "nyc node --experimental-loader=./hook.mjs ../../../node_modules/mocha/bin/mocha 'test/node/*.test.mjs' test/node/*.test.mjs", "test": "npm run test:cjs && npm run test:esm", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -72,36 +72,35 @@ }, "dependencies": { "@types/shimmer": "^1.0.2", - "import-in-the-middle": "1.4.1", + "import-in-the-middle": "1.4.2", "require-in-the-middle": "^7.1.1", - "semver": "^7.5.1", - "shimmer": "^1.2.1", - "tslib": "^2.3.1" + "semver": "^7.5.2", + "shimmer": "^1.2.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/sdk-metrics": "1.14.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/sdk-metrics": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/semver": "7.5.0", - "@types/sinon": "10.0.15", + "@types/semver": "7.5.2", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts index 0b238b42b8..24c76056a1 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { InstrumentationBase } from './instrumentation'; +export * from './instrumentation'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts index 1fc5f5e14a..cdaf8858ce 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts @@ -14,10 +14,4 @@ * limitations under the License. */ -export { - InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationModuleFile, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, -} from './node'; +export * from './node'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts index d3df10491f..842797c341 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts @@ -13,10 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { InstrumentationBase } from './instrumentation'; -export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition'; -export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile'; -export { - InstrumentationModuleDefinition, - InstrumentationModuleFile, -} from './types'; +export * from './instrumentation'; +export * from './instrumentationNodeModuleDefinition'; +export * from './instrumentationNodeModuleFile'; +export * from './types'; diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs b/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs index 715dbdbff2..f09097cd79 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs +++ b/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs @@ -18,7 +18,7 @@ import * as assert from 'assert'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, -} from '../../build/src/platform/index.js'; +} from '../../build/src/index.js'; import * as exported from 'test-esm-module'; class TestInstrumentationWrapFn extends InstrumentationBase { diff --git a/experimental/packages/opentelemetry-sdk-node/.eslintrc.js b/experimental/packages/opentelemetry-sdk-node/.eslintrc.js index f756f4488b..9baf1b4956 100644 --- a/experimental/packages/opentelemetry-sdk-node/.eslintrc.js +++ b/experimental/packages/opentelemetry-sdk-node/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/opentelemetry-sdk-node/README.md b/experimental/packages/opentelemetry-sdk-node/README.md index 2e09308958..b5086b8668 100644 --- a/experimental/packages/opentelemetry-sdk-node/README.md +++ b/experimental/packages/opentelemetry-sdk-node/README.md @@ -36,6 +36,7 @@ Before any other module in your application is loaded, you must initialize the S If you fail to initialize the SDK or initialize it too late, no-op implementations will be provided to any library which acquires a tracer or meter from the API. This example uses Jaeger and Prometheus, but exporters exist for [other tracing backends][other-tracing-backends]. +As shown in the installation instructions, exporters passed to the SDK must be installed alongside `@opentelemetry/sdk-node`. ```javascript const opentelemetry = require("@opentelemetry/sdk-node"); diff --git a/experimental/packages/opentelemetry-sdk-node/package.json b/experimental/packages/opentelemetry-sdk-node/package.json index 5db8e3ced7..8517a07617 100644 --- a/experimental/packages/opentelemetry-sdk-node/package.json +++ b/experimental/packages/opentelemetry-sdk-node/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-node", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry SDK for Node.js", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -17,7 +17,8 @@ "watch": "tsc --build --watch", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "npm run precompile", - "peer-api-check": "node ../../../scripts/peer-api-check.js" + "peer-api-check": "node ../../../scripts/peer-api-check.js", + "postinstall": "node -e \"console.log(\\\"\\x1b[95m%s\\x1b[0m\\\", \\\"@opentelemetry/sdk-node - warning: Starting with 0.44.0 '@opentelemetry/exporter-jaeger' will no longer be automatically installed by this package. To continue using '@opentelemetry/exporter-jaeger', please install it manually.\\n(NOTE: '@opentelemetry/exporter-jaeger' is deprecated, consider switching to one of the alternatives described in https://www.npmjs.com/package/@opentelemetry/exporter-jaeger)\\\");\"" }, "keywords": [ "opentelemetry", @@ -44,37 +45,38 @@ "access": "public" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/exporter-jaeger": "1.14.0", - "@opentelemetry/exporter-trace-otlp-grpc": "0.40.0", - "@opentelemetry/exporter-trace-otlp-http": "0.40.0", - "@opentelemetry/exporter-trace-otlp-proto": "0.40.0", - "@opentelemetry/exporter-zipkin": "1.14.0", - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/sdk-trace-node": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/exporter-jaeger": "1.17.0", + "@opentelemetry/exporter-trace-otlp-grpc": "0.43.0", + "@opentelemetry/exporter-trace-otlp-http": "0.43.0", + "@opentelemetry/exporter-trace-otlp-proto": "0.43.0", + "@opentelemetry/exporter-zipkin": "1.17.0", + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-logs": "0.43.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/sdk-trace-node": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.5.0" + "@opentelemetry/api": ">=1.3.0 <1.7.0" }, "devDependencies": { - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-async-hooks": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/exporter-jaeger": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/semver": "7.5.0", - "@types/sinon": "10.0.15", + "@types/semver": "7.5.2", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", - "semver": "7.5.3", + "semver": "7.5.4", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", diff --git a/experimental/packages/opentelemetry-sdk-node/src/index.ts b/experimental/packages/opentelemetry-sdk-node/src/index.ts index d246174208..891288ee6e 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/index.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/index.ts @@ -17,6 +17,7 @@ export * as api from '@opentelemetry/api'; export * as contextBase from '@opentelemetry/api'; export * as core from '@opentelemetry/core'; +export * as logs from '@opentelemetry/sdk-logs'; export * as metrics from '@opentelemetry/sdk-metrics'; export * as node from '@opentelemetry/sdk-trace-node'; export * as resources from '@opentelemetry/resources'; diff --git a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts index 07921a88b9..30a1bea790 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts @@ -21,6 +21,7 @@ import { diag, DiagConsoleLogger, } from '@opentelemetry/api'; +import { logs } from '@opentelemetry/api-logs'; import { InstrumentationOption, registerInstrumentations, @@ -35,6 +36,7 @@ import { Resource, ResourceDetectionConfig, } from '@opentelemetry/resources'; +import { LogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs'; import { MeterProvider, MetricReader, View } from '@opentelemetry/sdk-metrics'; import { BatchSpanProcessor, @@ -63,6 +65,13 @@ export type MeterProviderConfig = { views?: View[]; }; +export type LoggerProviderConfig = { + /** + * Reference to the LoggerRecordProcessor instance by the NodeSDK + */ + logRecordProcessor: LogRecordProcessor; +}; + export class NodeSDK { private _tracerProviderConfig?: { tracerConfig: NodeTracerConfig; @@ -70,6 +79,7 @@ export class NodeSDK { contextManager?: ContextManager; textMapPropagator?: TextMapPropagator; }; + private _loggerProviderConfig?: LoggerProviderConfig; private _meterProviderConfig?: MeterProviderConfig; private _instrumentations: InstrumentationOption[]; @@ -79,6 +89,7 @@ export class NodeSDK { private _autoDetectResources: boolean; private _tracerProvider?: NodeTracerProvider | TracerProviderWithEnvExporters; + private _loggerProvider?: LoggerProvider; private _meterProvider?: MeterProvider; private _serviceName?: string; @@ -140,6 +151,13 @@ export class NodeSDK { ); } + if (configuration.logRecordProcessor) { + const loggerProviderConfig: LoggerProviderConfig = { + logRecordProcessor: configuration.logRecordProcessor, + }; + this.configureLoggerProvider(loggerProviderConfig); + } + if (configuration.metricReader || configuration.views) { const meterProviderConfig: MeterProviderConfig = {}; if (configuration.metricReader) { @@ -160,7 +178,14 @@ export class NodeSDK { this._instrumentations = instrumentations; } - /** Set configurations required to register a NodeTracerProvider */ + /** + * + * @deprecated Please pass {@code sampler}, {@code generalLimits}, {@code spanLimits}, {@code resource}, + * {@code IdGenerator}, {@code spanProcessor}, {@code contextManager} and {@code textMapPropagator}, + * to the constructor options instead. + * + * Set configurations needed to register a TracerProvider + */ public configureTracerProvider( tracerConfig: NodeTracerConfig, spanProcessor: SpanProcessor, @@ -175,7 +200,39 @@ export class NodeSDK { }; } - /** Set configurations needed to register a MeterProvider */ + /** + * @deprecated Please pass {@code logRecordProcessor} to the constructor options instead. + * + * Set configurations needed to register a LoggerProvider + */ + public configureLoggerProvider(config: LoggerProviderConfig): void { + // nothing is set yet, we can set config and then return + if (this._loggerProviderConfig == null) { + this._loggerProviderConfig = config; + return; + } + + // make sure we do not override existing logRecordProcessor with other logRecordProcessors. + if ( + this._loggerProviderConfig.logRecordProcessor != null && + config.logRecordProcessor != null + ) { + throw new Error( + 'LogRecordProcessor passed but LogRecordProcessor has already been configured.' + ); + } + + // set logRecordProcessor, but make sure we do not override existing logRecordProcessors with null/undefined. + if (config.logRecordProcessor != null) { + this._loggerProviderConfig.logRecordProcessor = config.logRecordProcessor; + } + } + + /** + * @deprecated Please pass {@code views} and {@code reader} to the constructor options instead. + * + * Set configurations needed to register a MeterProvider + */ public configureMeterProvider(config: MeterProviderConfig): void { // nothing is set yet, we can set config and return. if (this._meterProviderConfig == null) { @@ -206,7 +263,12 @@ export class NodeSDK { } } - /** Detect resource attributes */ + /** + * @deprecated Resources are detected automatically on {@link NodeSDK.start()}, when the {@code autoDetectResources} + * constructor option is set to {@code true} or left {@code undefined}. + * + * Detect resource attributes + */ public detectResources(): void { if (this._disabled) { return; @@ -219,13 +281,18 @@ export class NodeSDK { this.addResource(detectResourcesSync(internalConfig)); } - /** Manually add a resource */ + /** + * @deprecated Please pre-merge resources and pass them to the constructor + * + * Manually add a Resource + * @param resource + */ public addResource(resource: IResource): void { this._resource = this._resource.merge(resource); } /** - * Once the SDK has been configured, call this method to construct SDK components and register them with the OpenTelemetry API. + * Call this method to construct SDK components and register them with the OpenTelemetry API. */ public start(): void { if (this._disabled) { @@ -269,6 +336,19 @@ export class NodeSDK { propagator: this._tracerProviderConfig?.textMapPropagator, }); + if (this._loggerProviderConfig) { + const loggerProvider = new LoggerProvider({ + resource: this._resource, + }); + loggerProvider.addLogRecordProcessor( + this._loggerProviderConfig.logRecordProcessor + ); + + this._loggerProvider = loggerProvider; + + logs.setGlobalLoggerProvider(loggerProvider); + } + if (this._meterProviderConfig) { const meterProvider = new MeterProvider({ resource: this._resource, @@ -299,6 +379,9 @@ export class NodeSDK { if (this._tracerProvider) { promises.push(this._tracerProvider.shutdown()); } + if (this._loggerProvider) { + promises.push(this._loggerProvider.shutdown()); + } if (this._meterProvider) { promises.push(this._meterProvider.shutdown()); } diff --git a/experimental/packages/opentelemetry-sdk-node/src/types.ts b/experimental/packages/opentelemetry-sdk-node/src/types.ts index 03efc31142..9292e0ae70 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/types.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/types.ts @@ -18,6 +18,7 @@ import type { ContextManager } from '@opentelemetry/api'; import { TextMapPropagator } from '@opentelemetry/api'; import { InstrumentationOption } from '@opentelemetry/instrumentation'; import { Detector, DetectorSync, IResource } from '@opentelemetry/resources'; +import { LogRecordProcessor } from '@opentelemetry/sdk-logs'; import { MetricReader, View } from '@opentelemetry/sdk-metrics'; import { Sampler, @@ -31,6 +32,7 @@ export interface NodeSDKConfiguration { autoDetectResources: boolean; contextManager: ContextManager; textMapPropagator: TextMapPropagator; + logRecordProcessor: LogRecordProcessor; metricReader: MetricReader; views: View[]; instrumentations: InstrumentationOption[]; diff --git a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts index 7a385a7604..6fb76f3dad 100644 --- a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts +++ b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts @@ -59,6 +59,12 @@ import { Resource, } from '@opentelemetry/resources'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; +import { logs } from '@opentelemetry/api-logs'; +import { + SimpleLogRecordProcessor, + InMemoryLogRecordExporter, + LoggerProvider, +} from '@opentelemetry/sdk-logs'; const DefaultContextManager = semver.gte(process.version, '14.8.0') ? AsyncLocalStorageContextManager @@ -112,6 +118,7 @@ describe('Node SDK', () => { 'tracer provider should not have changed' ); assert.ok(!(metrics.getMeterProvider() instanceof MeterProvider)); + assert.ok(!(logs.getLoggerProvider() instanceof LoggerProvider)); delete env.OTEL_TRACES_EXPORTER; }); @@ -233,6 +240,40 @@ describe('Node SDK', () => { await sdk.shutdown(); delete env.OTEL_TRACES_EXPORTER; }); + + it('should register a logger provider if a log record processor is provided', async () => { + env.OTEL_TRACES_EXPORTER = 'none'; + const logRecordExporter = new InMemoryLogRecordExporter(); + const logRecordProcessor = new SimpleLogRecordProcessor( + logRecordExporter + ); + const sdk = new NodeSDK({ + logRecordProcessor: logRecordProcessor, + autoDetectResources: false, + }); + + sdk.start(); + + assert.strictEqual( + context['_getContextManager'](), + ctxManager, + 'context manager should not change' + ); + assert.strictEqual( + propagation['_getGlobalPropagator'](), + propagator, + 'propagator should not change' + ); + assert.strictEqual( + (trace.getTracerProvider() as ProxyTracerProvider).getDelegate(), + delegate, + 'tracer provider should not have changed' + ); + + assert.ok(logs.getLoggerProvider() instanceof LoggerProvider); + await sdk.shutdown(); + delete env.OTEL_TRACES_EXPORTER; + }); }); async function waitForNumberOfMetrics( @@ -406,6 +447,28 @@ describe('Node SDK', () => { ); }); + it('should throw error when calling configureLoggerProvider when logRecordProcessor is already configured', () => { + const logRecordExporter = new InMemoryLogRecordExporter(); + const logRecordProcessor = new SimpleLogRecordProcessor(logRecordExporter); + const sdk = new NodeSDK({ + logRecordProcessor: logRecordProcessor, + autoDetectResources: false, + }); + + assert.throws( + () => { + sdk.configureLoggerProvider({ + logRecordProcessor: logRecordProcessor, + }); + }, + (error: Error) => { + return error.message.includes( + 'LogRecordProcessor passed but LogRecordProcessor has already been configured.' + ); + } + ); + }); + describe('detectResources', async () => { beforeEach(() => { process.env.OTEL_RESOURCE_ATTRIBUTES = diff --git a/experimental/packages/opentelemetry-sdk-node/tsconfig.json b/experimental/packages/opentelemetry-sdk-node/tsconfig.json index add730f8bc..94c80b8846 100644 --- a/experimental/packages/opentelemetry-sdk-node/tsconfig.json +++ b/experimental/packages/opentelemetry-sdk-node/tsconfig.json @@ -39,6 +39,9 @@ { "path": "../../../packages/sdk-metrics" }, + { + "path": "../api-logs" + }, { "path": "../exporter-trace-otlp-grpc" }, @@ -50,6 +53,9 @@ }, { "path": "../opentelemetry-instrumentation" + }, + { + "path": "../sdk-logs" } ] } diff --git a/experimental/packages/otlp-exporter-base/.eslintrc.js b/experimental/packages/otlp-exporter-base/.eslintrc.js index e41d9a9299..c054089042 100644 --- a/experimental/packages/otlp-exporter-base/.eslintrc.js +++ b/experimental/packages/otlp-exporter-base/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/otlp-exporter-base/package.json b/experimental/packages/otlp-exporter-base/package.json index de1a701996..7981365842 100644 --- a/experimental/packages/otlp-exporter-base/package.json +++ b/experimental/packages/otlp-exporter-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/otlp-exporter-base", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry OTLP Exporter base (for internal use only)", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -24,7 +24,7 @@ "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -61,25 +61,33 @@ "access": "public" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0" }, "devDependencies": { - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", - "lerna": "7.1.1", + "karma": "6.4.2", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.2.1", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.36", + "karma-webpack": "4.0.2", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", "nyc": "15.1.0", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts b/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts index c960305783..2c55a7f91c 100644 --- a/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts +++ b/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts @@ -33,7 +33,7 @@ import { configureExporterTimeout } from './util'; export abstract class OTLPExporterBase< T extends OTLPExporterConfigBase, ExportItem, - ServiceRequest + ServiceRequest, > { public readonly url: string; public readonly hostname: string | undefined; diff --git a/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts b/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts index 57556d81a5..2888e317df 100644 --- a/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts +++ b/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts @@ -27,7 +27,7 @@ import { getEnv, baggageUtils } from '@opentelemetry/core'; */ export abstract class OTLPExporterBrowserBase< ExportItem, - ServiceRequest + ServiceRequest, > extends OTLPExporterBase { protected _headers: Record; private _useXHR: boolean = false; diff --git a/experimental/packages/otlp-exporter-base/src/platform/node/OTLPExporterNodeBase.ts b/experimental/packages/otlp-exporter-base/src/platform/node/OTLPExporterNodeBase.ts index 088a0fd0a0..5a8b1dfdfa 100644 --- a/experimental/packages/otlp-exporter-base/src/platform/node/OTLPExporterNodeBase.ts +++ b/experimental/packages/otlp-exporter-base/src/platform/node/OTLPExporterNodeBase.ts @@ -30,7 +30,7 @@ import { getEnv, baggageUtils } from '@opentelemetry/core'; */ export abstract class OTLPExporterNodeBase< ExportItem, - ServiceRequest + ServiceRequest, > extends OTLPExporterBase< OTLPExporterNodeConfigBase, ExportItem, diff --git a/experimental/packages/otlp-grpc-exporter-base/.eslintrc.js b/experimental/packages/otlp-grpc-exporter-base/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/otlp-grpc-exporter-base/.eslintrc.js +++ b/experimental/packages/otlp-grpc-exporter-base/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/otlp-grpc-exporter-base/package.json b/experimental/packages/otlp-grpc-exporter-base/package.json index 4956fbee14..cfa48c56e8 100644 --- a/experimental/packages/otlp-grpc-exporter-base/package.json +++ b/experimental/packages/otlp-grpc-exporter-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/otlp-grpc-exporter-base", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry OTLP-gRPC Exporter base (for internal use only)", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -48,21 +48,21 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/otlp-transformer": "0.40.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cpx": "1.5.0", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", - "protobufjs-cli": "1.1.1", + "protobufjs-cli": "1.1.2", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", @@ -73,10 +73,9 @@ }, "dependencies": { "@grpc/grpc-js": "^1.7.1", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "protobufjs": "^7.2.3", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "protobufjs": "^7.2.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-grpc-exporter-base", "sideEffects": false diff --git a/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts b/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts index 884505daa8..b4f06472c6 100644 --- a/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts +++ b/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts @@ -34,7 +34,7 @@ import { */ export abstract class OTLPGRPCExporterNodeBase< ExportItem, - ServiceRequest + ServiceRequest, > extends OTLPExporterBase< OTLPGRPCExporterConfigNode, ExportItem, diff --git a/experimental/packages/otlp-proto-exporter-base/.eslintrc.js b/experimental/packages/otlp-proto-exporter-base/.eslintrc.js index 3ed0fbeba3..9cfb3fd423 100644 --- a/experimental/packages/otlp-proto-exporter-base/.eslintrc.js +++ b/experimental/packages/otlp-proto-exporter-base/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "node": true, }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/otlp-proto-exporter-base/package.json b/experimental/packages/otlp-proto-exporter-base/package.json index 0587dc9de5..d350c263f6 100644 --- a/experimental/packages/otlp-proto-exporter-base/package.json +++ b/experimental/packages/otlp-proto-exporter-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/otlp-proto-exporter-base", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenTelemetry OTLP-HTTP-protobuf Exporter base (for internal use only)", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -59,17 +59,17 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": "1.4.1", + "@babel/core": "7.22.20", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", - "protobufjs-cli": "1.1.1", + "protobufjs-cli": "1.1.2", "sinon": "15.1.2", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", @@ -79,10 +79,9 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/otlp-exporter-base": "0.40.0", - "protobufjs": "^7.2.3", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "protobufjs": "^7.2.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-proto-exporter-base", "sideEffects": false diff --git a/experimental/packages/otlp-proto-exporter-base/src/platform/browser/OTLPProtoExporterBrowserBase.ts b/experimental/packages/otlp-proto-exporter-base/src/platform/browser/OTLPProtoExporterBrowserBase.ts index 34c80d6e82..4bc9e5c70a 100644 --- a/experimental/packages/otlp-proto-exporter-base/src/platform/browser/OTLPProtoExporterBrowserBase.ts +++ b/experimental/packages/otlp-proto-exporter-base/src/platform/browser/OTLPProtoExporterBrowserBase.ts @@ -30,7 +30,7 @@ import { getExportRequestProto } from '../util'; */ export abstract class OTLPProtoExporterBrowserBase< ExportItem, - ServiceRequest + ServiceRequest, > extends OTLPExporterBaseMain { constructor(config: OTLPExporterConfigBase = {}) { super(config); diff --git a/experimental/packages/otlp-proto-exporter-base/src/platform/node/OTLPProtoExporterNodeBase.ts b/experimental/packages/otlp-proto-exporter-base/src/platform/node/OTLPProtoExporterNodeBase.ts index c0ff4b6b39..17804c47b4 100644 --- a/experimental/packages/otlp-proto-exporter-base/src/platform/node/OTLPProtoExporterNodeBase.ts +++ b/experimental/packages/otlp-proto-exporter-base/src/platform/node/OTLPProtoExporterNodeBase.ts @@ -36,7 +36,7 @@ type SendFn = ( */ export abstract class OTLPProtoExporterNodeBase< ExportItem, - ServiceRequest + ServiceRequest, > extends OTLPExporterBaseMain { private _send!: SendFn; diff --git a/experimental/packages/otlp-transformer/.eslintrc.js b/experimental/packages/otlp-transformer/.eslintrc.js index b9004d2025..0fe1bbf975 100644 --- a/experimental/packages/otlp-transformer/.eslintrc.js +++ b/experimental/packages/otlp-transformer/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "shared-node-browser": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer/package.json index 4e2a831389..9e138a5cd2 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer/package.json @@ -4,7 +4,7 @@ "publishConfig": { "access": "public" }, - "version": "0.40.0", + "version": "0.43.0", "description": "Transform OpenTelemetry SDK data into OTLP", "module": "build/esm/index.js", "esnext": "build/esnext/index.js", @@ -20,7 +20,7 @@ "lint:fix": "eslint . --ext .ts --fix", "tdd": "npm run test -- --watch-extensions ts --watch", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "prewatch": "node ../../../scripts/version-update.js", "watch": "tsc --build -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "peer-api-check": "node ../../../scripts/peer-api-check.js", @@ -54,22 +54,22 @@ "README.md" ], "peerDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.5.0" + "@opentelemetry/api": ">=1.3.0 <1.7.0" }, "devDependencies": { - "@opentelemetry/api": "1.4.1", + "@opentelemetry/api": "1.6.0", "@types/mocha": "10.0.1", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-loader": "8.4.0", @@ -78,13 +78,12 @@ "webpack": "4.46.0" }, "dependencies": { - "@opentelemetry/api-logs": "0.40.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-logs": "0.40.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-logs": "0.43.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-transformer", "sideEffects": false diff --git a/experimental/packages/sdk-logs/.eslintrc.js b/experimental/packages/sdk-logs/.eslintrc.js index 0c986a856c..fc24af194b 100644 --- a/experimental/packages/sdk-logs/.eslintrc.js +++ b/experimental/packages/sdk-logs/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { mocha: true, node: true, }, - ...require('../../../eslint.config.js'), + ...require('../../../eslint.base.js'), }; diff --git a/experimental/packages/sdk-logs/package.json b/experimental/packages/sdk-logs/package.json index be245fbe15..f35a643c07 100644 --- a/experimental/packages/sdk-logs/package.json +++ b/experimental/packages/sdk-logs/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-logs", - "version": "0.40.0", + "version": "0.43.0", "publishConfig": { "access": "public" }, @@ -33,7 +33,7 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", @@ -68,33 +68,38 @@ ], "sideEffects": false, "peerDependencies": { - "@opentelemetry/api": ">=1.4.0 <1.5.0", + "@opentelemetry/api": ">=1.4.0 <1.7.0", "@opentelemetry/api-logs": ">=0.39.1" }, "devDependencies": { - "@opentelemetry/api": ">=1.4.0 <1.5.0", - "@opentelemetry/api-logs": "0.40.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": ">=1.4.0 <1.7.0", + "@opentelemetry/api-logs": "0.43.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", + "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0" } } diff --git a/experimental/packages/sdk-logs/src/export/BatchLogRecordProcessorBase.ts b/experimental/packages/sdk-logs/src/export/BatchLogRecordProcessorBase.ts index 92d42fe44b..027f103c07 100644 --- a/experimental/packages/sdk-logs/src/export/BatchLogRecordProcessorBase.ts +++ b/experimental/packages/sdk-logs/src/export/BatchLogRecordProcessorBase.ts @@ -42,7 +42,10 @@ export abstract class BatchLogRecordProcessorBase private _timer: NodeJS.Timeout | undefined; private _shutdownOnce: BindOnceFuture; - constructor(private readonly _exporter: LogRecordExporter, config?: T) { + constructor( + private readonly _exporter: LogRecordExporter, + config?: T + ) { const env = getEnv(); this._maxExportBatchSize = config?.maxExportBatchSize ?? env.OTEL_BLRP_MAX_EXPORT_BATCH_SIZE; diff --git a/experimental/packages/shim-opencensus/.eslintrc.js b/experimental/packages/shim-opencensus/.eslintrc.js index f756f4488b..9baf1b4956 100644 --- a/experimental/packages/shim-opencensus/.eslintrc.js +++ b/experimental/packages/shim-opencensus/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../../eslint.config.js') + ...require('../../../eslint.base.js') } diff --git a/experimental/packages/shim-opencensus/README.md b/experimental/packages/shim-opencensus/README.md index e79cfc0f43..66e4d6e3d7 100644 --- a/experimental/packages/shim-opencensus/README.md +++ b/experimental/packages/shim-opencensus/README.md @@ -13,11 +13,11 @@ More details are available in the [OpenCensus Compatibility Specification](https npm install --save @opentelemetry/shim-opencensus ``` -## Usage +## Tracing usage ### Installing the shim's require-in-the-middle hook -This is the recommended way to use the shim. +This is the recommended way to use the shim for tracing. This package provides a `require-in-the-middle` hook which replaces OpenCensus's `CoreTracer` class with a shim implementation that writes to the OpenTelemetry API. This will cause all @@ -72,6 +72,25 @@ tracer.startRootSpan({name: 'main'}, rootSpan => { }); ``` +## Metrics usage + +OpenCensus metrics can be collected and sent to an OpenTelemetry exporter by providing the +`OpenCensusMetricProducer` to your `MetricReader`. For example, to export OpenCensus metrics +through the OpenTelemetry Prometheus exporter: + +```js +meterProvider.addMetricReader( + new PrometheusExporter({ + metricProducers: [ + new OpenCensusMetricProducer({ + openCensusMetricProducerManager: + oc.Metrics.getMetricProducerManager(), + }), + ], + }) +); +``` + ## Example See [examples/opencensus-shim](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/examples/opencensus-shim) for a short example. diff --git a/experimental/packages/shim-opencensus/package.json b/experimental/packages/shim-opencensus/package.json index 636efed876..2e24690be8 100644 --- a/experimental/packages/shim-opencensus/package.json +++ b/experimental/packages/shim-opencensus/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/shim-opencensus", - "version": "0.40.0", + "version": "0.43.0", "description": "OpenCensus to OpenTelemetry shim", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,15 +49,15 @@ }, "devDependencies": { "@opencensus/core": "0.1.0", - "@opentelemetry/api": "1.4.1", - "@opentelemetry/context-async-hooks": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -69,10 +69,11 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-metrics": "1.17.0", "require-in-the-middle": "^7.1.1", - "semver": "^7.5.1", - "tslib": "^2.3.1" + "semver": "^7.5.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/shim-opencensus", "sideEffects": false diff --git a/experimental/packages/shim-opencensus/src/OpenCensusMetricProducer.ts b/experimental/packages/shim-opencensus/src/OpenCensusMetricProducer.ts new file mode 100644 index 0000000000..04d4a06738 --- /dev/null +++ b/experimental/packages/shim-opencensus/src/OpenCensusMetricProducer.ts @@ -0,0 +1,104 @@ +/* + * Copyright 2018, OpenCensus Authors + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 oc from '@opencensus/core'; +import { Resource } from '@opentelemetry/resources'; +import { + CollectionResult, + MetricData, + MetricProducer, + ScopeMetrics, +} from '@opentelemetry/sdk-metrics'; +import { mapOcMetric } from './metric-transform'; +import { VERSION } from './version'; + +const SCOPE = { + name: '@opentelemetry/shim-opencensus', + version: VERSION, +} as const; + +interface OpenCensusMetricProducerOptions { + /** + * An instance of OpenCensus MetricProducerManager. If not provided, + * `oc.Metrics.getMetricProducerManager()` will be used. + */ + openCensusMetricProducerManager?: oc.MetricProducerManager; +} + +/** + * A {@link MetricProducer} which collects metrics from OpenCensus. Provide an instance to your + * {@link MetricReader} when you create it to include all OpenCensus metrics in the collection + * result: + * + * @example + * ``` + * const meterProvider = new MeterProvider(); + * const reader = new PeriodicExportingMetricReader({ + * metricProducers: [new OpenCensusMetricProducer()], + * exporter: exporter, + * }); + * meterProvider.addMetricReader(reader); + * ``` + */ +export class OpenCensusMetricProducer implements MetricProducer { + private _openCensusMetricProducerManager: oc.MetricProducerManager; + + constructor(options?: OpenCensusMetricProducerOptions) { + this._openCensusMetricProducerManager = + options?.openCensusMetricProducerManager ?? + oc.Metrics.getMetricProducerManager(); + } + + async collect(): Promise { + const metrics = await this._collectOpenCensus(); + const scopeMetrics: ScopeMetrics[] = + metrics.length === 0 + ? [] + : [ + { + scope: SCOPE, + metrics, + }, + ]; + + return { + errors: [], + resourceMetrics: { + // Resource is ignored by the SDK, it just uses the SDK's resource + resource: Resource.EMPTY, + scopeMetrics, + }, + }; + } + + private async _collectOpenCensus(): Promise { + const metrics: MetricData[] = []; + + // The use of oc.Metrics.getMetricProducerManager() was adapted from + // https://github.com/census-instrumentation/opencensus-node/blob/d46c8891b15783803d724b717db9a8c22cb73d6a/packages/opencensus-exporter-stackdriver/src/stackdriver-monitoring.ts#L122 + for (const metricProducer of this._openCensusMetricProducerManager.getAllMetricProducer()) { + for (const metric of metricProducer.getMetrics()) { + const metricData = mapOcMetric(metric); + if (metricData !== null) { + metrics.push(metricData); + } + } + } + + return metrics; + } +} diff --git a/experimental/packages/shim-opencensus/src/ShimSpan.ts b/experimental/packages/shim-opencensus/src/ShimSpan.ts index 498c73e5e7..e4eaf47a2d 100644 --- a/experimental/packages/shim-opencensus/src/ShimSpan.ts +++ b/experimental/packages/shim-opencensus/src/ShimSpan.ts @@ -17,7 +17,7 @@ import * as oc from '@opencensus/core'; import { ShimTracer } from './ShimTracer'; import { AttributeValue, Span, SpanStatusCode, diag } from '@opentelemetry/api'; -import { mapMessageEvent, reverseMapSpanContext } from './transform'; +import { mapMessageEvent, reverseMapSpanContext } from './trace-transform'; // Copied from // https://github.com/census-instrumentation/opencensus-node/blob/v0.1.0/packages/opencensus-core/src/trace/model/span.ts#L61 diff --git a/experimental/packages/shim-opencensus/src/ShimTracer.ts b/experimental/packages/shim-opencensus/src/ShimTracer.ts index f5e8164e3c..c276b99e53 100644 --- a/experimental/packages/shim-opencensus/src/ShimTracer.ts +++ b/experimental/packages/shim-opencensus/src/ShimTracer.ts @@ -26,7 +26,7 @@ import { Tracer, } from '@opentelemetry/api'; import { DEFAULT_SPAN_NAME, ShimSpan } from './ShimSpan'; -import { mapSpanContext, mapSpanKind } from './transform'; +import { mapSpanContext, mapSpanKind } from './trace-transform'; import { shimPropagation } from './propagation'; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/experimental/packages/shim-opencensus/src/index.ts b/experimental/packages/shim-opencensus/src/index.ts index 5df2f6c315..8889608ec3 100644 --- a/experimental/packages/shim-opencensus/src/index.ts +++ b/experimental/packages/shim-opencensus/src/index.ts @@ -15,4 +15,5 @@ */ export { ShimTracer } from './ShimTracer'; +export { OpenCensusMetricProducer } from './OpenCensusMetricProducer'; export { installShim, uninstallShim } from './shim'; diff --git a/experimental/packages/shim-opencensus/src/metric-transform.ts b/experimental/packages/shim-opencensus/src/metric-transform.ts new file mode 100644 index 0000000000..bc136d0ed2 --- /dev/null +++ b/experimental/packages/shim-opencensus/src/metric-transform.ts @@ -0,0 +1,211 @@ +/* + * 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 oc from '@opencensus/core'; +import { Attributes, HrTime, ValueType, diag } from '@opentelemetry/api'; +import { + AggregationTemporality, + DataPoint, + DataPointType, + GaugeMetricData, + HistogramMetricData, + InstrumentType, + MetricData, + SumMetricData, +} from '@opentelemetry/sdk-metrics'; + +type BaseMetric = Omit; +interface MappedType { + type: InstrumentType; + valueType: ValueType; + dataPointType: + | DataPointType.GAUGE + | DataPointType.SUM + | DataPointType.HISTOGRAM; +} +const ZEROED_HRTIME: HrTime = [0, 0]; + +export function mapOcMetric(metric: oc.Metric): MetricData | null { + const { description, name, unit, type } = metric.descriptor; + const mappedType = mapOcMetricDescriptorType(type); + if (mappedType === null) { + return null; + } + + const baseMetric: BaseMetric = { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + descriptor: { + description, + name, + unit, + type: mappedType.type, + valueType: mappedType.valueType, + }, + }; + + switch (mappedType.dataPointType) { + case DataPointType.GAUGE: + return gauge(metric, mappedType.dataPointType, baseMetric); + case DataPointType.SUM: + return sum(metric, mappedType.dataPointType, baseMetric); + case DataPointType.HISTOGRAM: + return histogram(metric, mappedType.dataPointType, baseMetric); + } +} + +function mapOcMetricDescriptorType( + type: oc.MetricDescriptorType +): MappedType | null { + switch (type) { + case oc.MetricDescriptorType.GAUGE_INT64: + return { + type: InstrumentType.OBSERVABLE_GAUGE, + valueType: ValueType.INT, + dataPointType: DataPointType.GAUGE, + }; + case oc.MetricDescriptorType.GAUGE_DOUBLE: + return { + type: InstrumentType.OBSERVABLE_GAUGE, + valueType: ValueType.DOUBLE, + dataPointType: DataPointType.GAUGE, + }; + + case oc.MetricDescriptorType.CUMULATIVE_INT64: + return { + type: InstrumentType.COUNTER, + valueType: ValueType.INT, + dataPointType: DataPointType.SUM, + }; + case oc.MetricDescriptorType.CUMULATIVE_DOUBLE: + return { + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + dataPointType: DataPointType.SUM, + }; + + case oc.MetricDescriptorType.CUMULATIVE_DISTRIBUTION: + return { + type: InstrumentType.HISTOGRAM, + valueType: ValueType.DOUBLE, + dataPointType: DataPointType.HISTOGRAM, + }; + + case oc.MetricDescriptorType.SUMMARY: + case oc.MetricDescriptorType.GAUGE_DISTRIBUTION: + case oc.MetricDescriptorType.UNSPECIFIED: + diag.warn( + 'Got unsupported metric MetricDescriptorType from OpenCensus: %s', + type + ); + return null; + } +} + +function gauge( + metric: oc.Metric, + dataPointType: DataPointType.GAUGE, + baseMetric: BaseMetric +): GaugeMetricData { + return { + ...baseMetric, + dataPoints: dataPoints(metric, value => value as number), + dataPointType, + }; +} + +function sum( + metric: oc.Metric, + dataPointType: DataPointType.SUM, + baseMetric: BaseMetric +): SumMetricData { + return { + ...baseMetric, + dataPoints: dataPoints(metric, value => value as number), + isMonotonic: true, + dataPointType, + }; +} + +function histogram( + metric: oc.Metric, + dataPointType: DataPointType.HISTOGRAM, + baseMetric: BaseMetric +): HistogramMetricData { + return { + ...baseMetric, + dataPoints: dataPoints(metric, value => { + const { + bucketOptions: { + explicit: { bounds }, + }, + buckets, + count, + sum: distSum, + } = value as oc.DistributionValue; + + return { + buckets: { + boundaries: bounds, + counts: buckets.map(bucket => bucket.count), + }, + count, + sum: distSum, + }; + }), + dataPointType, + }; +} + +function dataPoints( + metric: oc.Metric, + valueMapper: (value: oc.TimeSeriesPoint['value']) => T +): DataPoint[] { + return metric.timeseries.flatMap(ts => { + const attributes = zipOcLabels(metric.descriptor.labelKeys, ts.labelValues); + + // use zeroed hrTime if it is undefined, which probably shouldn't happen + const startTime = ocTimestampToHrTime(ts.startTimestamp) ?? ZEROED_HRTIME; + + // points should be an array with a single value, so this will return a single point per + // attribute set. + return ts.points.map( + (point): DataPoint => ({ + startTime, + attributes, + value: valueMapper(point.value), + endTime: ocTimestampToHrTime(point.timestamp) ?? ZEROED_HRTIME, + }) + ); + }); +} + +function ocTimestampToHrTime(ts: oc.Timestamp | undefined): HrTime | null { + if (ts === undefined || ts.seconds === null) { + return null; + } + return [ts.seconds, ts.nanos ?? 0]; +} + +function zipOcLabels( + labelKeys: oc.LabelKey[], + labelValues: oc.LabelValue[] +): Attributes { + const attributes: Attributes = {}; + for (let i = 0; i < labelKeys.length; i++) { + attributes[labelKeys[i].key] = labelValues[i].value ?? ''; + } + return attributes; +} diff --git a/experimental/packages/shim-opencensus/src/propagation.ts b/experimental/packages/shim-opencensus/src/propagation.ts index deb2509fa7..e0045fe7d9 100644 --- a/experimental/packages/shim-opencensus/src/propagation.ts +++ b/experimental/packages/shim-opencensus/src/propagation.ts @@ -23,7 +23,7 @@ import { TextMapGetter, TextMapSetter, } from '@opentelemetry/api'; -import { mapSpanContext, reverseMapSpanContext } from './transform'; +import { mapSpanContext, reverseMapSpanContext } from './trace-transform'; class Getter implements TextMapGetter { constructor(private ocGetter: oc.HeaderGetter) {} diff --git a/experimental/packages/shim-opencensus/src/transform.ts b/experimental/packages/shim-opencensus/src/trace-transform.ts similarity index 100% rename from experimental/packages/shim-opencensus/src/transform.ts rename to experimental/packages/shim-opencensus/src/trace-transform.ts diff --git a/experimental/packages/shim-opencensus/test/OpenCensusMetricProducer.test.ts b/experimental/packages/shim-opencensus/test/OpenCensusMetricProducer.test.ts new file mode 100644 index 0000000000..15b9cc1a6b --- /dev/null +++ b/experimental/packages/shim-opencensus/test/OpenCensusMetricProducer.test.ts @@ -0,0 +1,118 @@ +/* + * 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 oc from '@opencensus/core'; +import { ValueType } from '@opentelemetry/api'; +import { Resource } from '@opentelemetry/resources'; +import { + AggregationTemporality, + DataPointType, + SumMetricData, +} from '@opentelemetry/sdk-metrics'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import { OpenCensusMetricProducer } from '../src/OpenCensusMetricProducer'; + +describe('OpenCensusMetricProducer', () => { + beforeEach(() => { + oc.globalStats.clear(); + sinon.useFakeTimers(); + }); + + afterEach(() => { + sinon.restore(); + }); + + // Since the resource is replaced by the SDK anyway + it('should return an empty Resource', async () => { + const producer = new OpenCensusMetricProducer(); + const resourceMetrics = await producer.collect(); + + assert.deepStrictEqual( + resourceMetrics.resourceMetrics.resource, + Resource.EMPTY + ); + }); + + it('should return no errors when no metrics are collected from OpenCensus', async () => { + const producer = new OpenCensusMetricProducer(); + const resourceMetrics = await producer.collect(); + assert.strictEqual(resourceMetrics.errors.length, 0); + }); + + it('should elide the scope when no metrics are collected from OpenCensus', async () => { + // No OpenCensus setup so won't produce any metrics + const producer = new OpenCensusMetricProducer(); + const resourceMetrics = await producer.collect(); + assert.strictEqual(resourceMetrics.resourceMetrics.scopeMetrics.length, 0); + }); + + it('should include OpenCensus metrics', async () => { + // Initialize OC metrics with one counter, adapted from + // https://opencensus.io/quickstart/nodejs/metrics/ + const measure = oc.globalStats.createMeasureDouble( + 'measure', + oc.MeasureUnit.MS + ); + const tagKey = { name: 'label1' }; + oc.globalStats.registerView( + oc.globalStats.createView( + 'measure', + measure, + oc.AggregationType.SUM, + [tagKey], + 'Test OC description' + ) + ); + + const tagMap = new oc.TagMap(); + tagMap.set(tagKey, { value: 'tagvalue' }); + oc.globalStats.record([{ measure, value: 125 }], tagMap); + + const producer = new OpenCensusMetricProducer(); + const resourceMetrics = await producer.collect(); + + assert.strictEqual(resourceMetrics.errors.length, 0); + assert.strictEqual(resourceMetrics.resourceMetrics.scopeMetrics.length, 1); + assert.strictEqual( + resourceMetrics.resourceMetrics.scopeMetrics[0].scope.name, + '@opentelemetry/shim-opencensus' + ); + assert.strictEqual( + resourceMetrics.resourceMetrics.scopeMetrics[0].metrics.length, + 1 + ); + const ocMetric = resourceMetrics.resourceMetrics.scopeMetrics[0] + .metrics[0] as SumMetricData; + assert.deepStrictEqual(ocMetric.descriptor, { + description: 'Test OC description', + name: 'measure', + type: 'COUNTER', + unit: 'ms', + valueType: ValueType.DOUBLE, + }); + assert.strictEqual(ocMetric.dataPoints[0].value, 125); + assert.deepStrictEqual(ocMetric.dataPoints[0].attributes, { + label1: 'tagvalue', + }); + assert.strictEqual(ocMetric.dataPointType, DataPointType.SUM); + assert.strictEqual(ocMetric.isMonotonic, true); + assert.strictEqual( + ocMetric.aggregationTemporality, + AggregationTemporality.CUMULATIVE + ); + }); +}); diff --git a/experimental/packages/shim-opencensus/test/metric-transform.test.ts b/experimental/packages/shim-opencensus/test/metric-transform.test.ts new file mode 100644 index 0000000000..289fbefd0c --- /dev/null +++ b/experimental/packages/shim-opencensus/test/metric-transform.test.ts @@ -0,0 +1,321 @@ +/* + * 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 { mapOcMetric } from '../src/metric-transform'; + +import * as oc from '@opencensus/core'; +import { ValueType } from '@opentelemetry/api'; +import { + AggregationTemporality, + DataPointType, + GaugeMetricData, + HistogramMetricData, + InstrumentType, + SumMetricData, +} from '@opentelemetry/sdk-metrics'; +import * as assert from 'assert'; + +describe('metric-transform', () => { + it('should map OpenCensus CUMULATIVE_INT64 to Sum', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.CUMULATIVE_INT64, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [{ timestamp: { seconds: 20, nanos: 20 }, value: 5 }], + }, + ], + }); + + assert.deepStrictEqual(metricData, { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.SUM, + dataPoints: [ + { + attributes: { key1: 'value1', key2: 'value2' }, + endTime: [20, 20], + startTime: [10, 10], + value: 5, + }, + ], + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: InstrumentType.COUNTER, + unit: 'ocUnit', + valueType: ValueType.INT, + }, + isMonotonic: true, + } as SumMetricData); + }); + + it('should map OpenCensus CUMULATIVE_DOUBLE to Sum', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.CUMULATIVE_DOUBLE, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [{ timestamp: { seconds: 20, nanos: 20 }, value: 5.5 }], + }, + ], + }); + + assert.deepStrictEqual(metricData, { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.SUM, + dataPoints: [ + { + attributes: { key1: 'value1', key2: 'value2' }, + endTime: [20, 20], + startTime: [10, 10], + value: 5.5, + }, + ], + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: InstrumentType.COUNTER, + unit: 'ocUnit', + valueType: ValueType.DOUBLE, + }, + isMonotonic: true, + } as SumMetricData); + }); + + it('should map OpenCensus CUMULATIVE_DISTRIBUTION to Histogram', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.CUMULATIVE_DISTRIBUTION, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [ + { + timestamp: { seconds: 20, nanos: 20 }, + value: { + bucketOptions: { + explicit: { + bounds: [1, 10, 100], + }, + }, + buckets: [ + { count: 0 }, + { count: 1 }, + { count: 2 }, + { count: 3 }, + ], + count: 6, + sum: 121, + sumOfSquaredDeviation: 4, + }, + }, + ], + }, + ], + }); + + assert.deepStrictEqual(metricData, { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.HISTOGRAM, + dataPoints: [ + { + attributes: { key1: 'value1', key2: 'value2' }, + endTime: [20, 20], + startTime: [10, 10], + value: { + buckets: { + boundaries: [1, 10, 100], + counts: [0, 1, 2, 3], + }, + count: 6, + sum: 121, + }, + }, + ], + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: InstrumentType.HISTOGRAM, + unit: 'ocUnit', + valueType: ValueType.DOUBLE, + }, + } as HistogramMetricData); + }); + + it('should map OpenCensus GAUGE_INT64 to Gauge', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.GAUGE_INT64, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [{ timestamp: { seconds: 20, nanos: 20 }, value: 5 }], + }, + ], + }); + + assert.deepStrictEqual(metricData, { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.GAUGE, + dataPoints: [ + { + attributes: { key1: 'value1', key2: 'value2' }, + endTime: [20, 20], + startTime: [10, 10], + value: 5, + }, + ], + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: InstrumentType.OBSERVABLE_GAUGE, + unit: 'ocUnit', + valueType: ValueType.INT, + }, + } as GaugeMetricData); + }); + + it('should map OpenCensus GAUGE_DOUBLE to Gauge', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.GAUGE_DOUBLE, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [{ timestamp: { seconds: 20, nanos: 20 }, value: 5.5 }], + }, + ], + }); + + assert.deepStrictEqual(metricData, { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.GAUGE, + dataPoints: [ + { + attributes: { key1: 'value1', key2: 'value2' }, + endTime: [20, 20], + startTime: [10, 10], + value: 5.5, + }, + ], + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: InstrumentType.OBSERVABLE_GAUGE, + unit: 'ocUnit', + valueType: ValueType.DOUBLE, + }, + } as GaugeMetricData); + }); + + it('should drop unsupported OpenCensus GAUGE_DISTRIBUTION', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.GAUGE_DISTRIBUTION, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [{ timestamp: { seconds: 20, nanos: 20 }, value: 5 }], + }, + ], + }); + assert.deepStrictEqual(metricData, null); + }); + + it('should drop unsupported OpenCensus SUMMARY', () => { + const metricData = mapOcMetric({ + descriptor: { + description: 'ocDescription', + name: 'ocMetricName', + type: oc.MetricDescriptorType.SUMMARY, + unit: 'ocUnit', + labelKeys: [ + { key: 'key1', description: '' }, + { key: 'key2', description: '' }, + ], + }, + timeseries: [ + { + startTimestamp: { seconds: 10, nanos: 10 }, + labelValues: [{ value: 'value1' }, { value: 'value2' }], + points: [ + { + timestamp: { seconds: 20, nanos: 20 }, + value: { count: 5, sum: 10 }, + }, + ], + }, + ], + }); + assert.deepStrictEqual(metricData, null); + }); +}); diff --git a/experimental/packages/shim-opencensus/test/transform.test.ts b/experimental/packages/shim-opencensus/test/trace-transform.test.ts similarity index 98% rename from experimental/packages/shim-opencensus/test/transform.test.ts rename to experimental/packages/shim-opencensus/test/trace-transform.test.ts index 9a7f90cda0..6aacd5e951 100644 --- a/experimental/packages/shim-opencensus/test/transform.test.ts +++ b/experimental/packages/shim-opencensus/test/trace-transform.test.ts @@ -19,14 +19,14 @@ import { mapSpanContext, mapSpanKind, reverseMapSpanContext, -} from '../src/transform'; +} from '../src/trace-transform'; import * as oc from '@opencensus/core'; import { SpanKind } from '@opentelemetry/api'; import { TraceState } from '@opentelemetry/core'; import * as assert from 'assert'; -describe('transform', () => { +describe('trace-transform', () => { describe('mapSpanKind', () => { it('should return undefined with undefined input', () => { assert.strictEqual(mapSpanKind(undefined), undefined); diff --git a/experimental/packages/shim-opencensus/tsconfig.json b/experimental/packages/shim-opencensus/tsconfig.json index 91cebb5ad5..145dd31760 100644 --- a/experimental/packages/shim-opencensus/tsconfig.json +++ b/experimental/packages/shim-opencensus/tsconfig.json @@ -18,8 +18,14 @@ { "path": "../../../packages/opentelemetry-core" }, + { + "path": "../../../packages/opentelemetry-resources" + }, { "path": "../../../packages/opentelemetry-sdk-trace-base" + }, + { + "path": "../../../packages/sdk-metrics" } ] } diff --git a/integration-tests/propagation-validation-server/package.json b/integration-tests/propagation-validation-server/package.json index 880251c503..e54a18825c 100644 --- a/integration-tests/propagation-validation-server/package.json +++ b/integration-tests/propagation-validation-server/package.json @@ -1,6 +1,6 @@ { "name": "propagation-validation-server", - "version": "1.14.0", + "version": "1.17.0", "description": "server for w3c tests", "main": "validation_server.js", "private": true, @@ -12,13 +12,12 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/context-async-hooks": "1.14.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "axios": "1.4.0", + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "axios": "1.5.0", "body-parser": "1.19.0", - "express": "4.17.3", - "tslib": "^2.3.1" + "express": "4.17.3" }, "devDependencies": { "typescript": "4.4.4" diff --git a/karma.base.js b/karma.base.js index 7df76d7b13..2af2869368 100644 --- a/karma.base.js +++ b/karma.base.js @@ -19,12 +19,12 @@ module.exports = { hostname: 'localhost', browsers: ['ChromeHeadless'], frameworks: ['mocha'], - coverageIstanbulReporter: { - reports: ['html', 'json'], - dir: '.nyc_output', - fixWebpackSourcePaths: true + coverageReporter: { + type : 'json', + subdir: '.', + dir : '.nyc_output/' }, - reporters: ['spec', 'coverage-istanbul'], + reporters: ['spec', 'coverage'], files: ['test/index-webpack.ts'], preprocessors: { 'test/index-webpack*.ts': ['webpack'] diff --git a/karma.webpack.js b/karma.webpack.js index 138112547b..b7fa7acb97 100644 --- a/karma.webpack.js +++ b/karma.webpack.js @@ -31,8 +31,10 @@ module.exports = { exclude: /(node_modules|\.test\.[tj]sx?$)/, test: /\.ts$/, use: { - loader: 'istanbul-instrumenter-loader', - options: { esModules: true }, + loader: 'babel-loader', + options: { + plugins: ['babel-plugin-istanbul'], + } }, }, // This setting configures Node polyfills for the browser that will be diff --git a/package.json b/package.json index c0b6c172ef..6d5460207d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test:browser": "lerna run test:browser", "test:webworker": "lerna run test:webworker", "test:backcompat": "lerna run test:backcompat", + "test:bench": "lerna run test:bench", "bootstrap": "lerna bootstrap --hoist --nohoist='zone.js'", "changelog": "lerna-changelog", "codecov": "lerna run codecov", @@ -65,23 +66,23 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "5.59.11", "@typescript-eslint/parser": "5.59.11", - "eslint": "8.22.0", - "eslint-config-prettier": "8.5.0", + "benchmark": "2.1.4", + "eslint": "8.44.0", + "eslint-config-prettier": "9.0.0", "eslint-plugin-header": "3.1.1", "eslint-plugin-node": "11.1.0", - "eslint-plugin-prettier": "4.2.1", - "gh-pages": "5.0.0", - "lerna": "7.1.1", - "@lerna/legacy-package-management": "7.1.1", - "linkinator": "5.0.1", - "markdownlint-cli": "0.35.0", - "prettier": "2.8.8", - "semver": "7.5.3", + "eslint-plugin-prettier": "5.0.0", + "gh-pages": "6.0.0", + "lerna": "7.1.5", + "@lerna/legacy-package-management": "7.1.5", + "linkinator": "5.0.2", + "markdownlint-cli": "0.36.0", + "prettier": "3.0.3", + "semver": "7.5.4", "typedoc": "0.22.18", "typedoc-plugin-missing-exports": "1.0.0", "typedoc-plugin-resolve-crossmodule-references": "0.2.2", - "typescript": "4.4.4", - "tslib": "^2.3.1" + "typescript": "4.4.4" }, "changelog": { "repo": "open-telemetry/opentelemetry-js", diff --git a/packages/opentelemetry-context-async-hooks/.eslintrc.js b/packages/opentelemetry-context-async-hooks/.eslintrc.js index f726f3becb..3d9af536bb 100644 --- a/packages/opentelemetry-context-async-hooks/.eslintrc.js +++ b/packages/opentelemetry-context-async-hooks/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-context-async-hooks/package.json b/packages/opentelemetry-context-async-hooks/package.json index 64366b205c..181fc92dce 100644 --- a/packages/opentelemetry-context-async-hooks/package.json +++ b/packages/opentelemetry-context-async-hooks/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/context-async-hooks", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry AsyncHooks-based Context Manager", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,23 +43,20 @@ "publishConfig": { "access": "public" }, - "dependencies": { - "tslib": "^2.3.1" - }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-async-hooks", "sideEffects": false diff --git a/packages/opentelemetry-context-zone-peer-dep/.eslintrc.js b/packages/opentelemetry-context-zone-peer-dep/.eslintrc.js index f21c674001..7561e7f833 100644 --- a/packages/opentelemetry-context-zone-peer-dep/.eslintrc.js +++ b/packages/opentelemetry-context-zone-peer-dep/.eslintrc.js @@ -7,5 +7,5 @@ module.exports = { "globals": { "Zone": "readonly" }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-context-zone-peer-dep/package.json b/packages/opentelemetry-context-zone-peer-dep/package.json index 9904e9da84..0a673ab480 100644 --- a/packages/opentelemetry-context-zone-peer-dep/package.json +++ b/packages/opentelemetry-context-zone-peer-dep/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/context-zone-peer-dep", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Context Zone with peer dependency for zone.js", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -16,7 +16,7 @@ "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "npm run precompile", @@ -53,24 +53,24 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "@types/zone.js": "0.5.12", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -82,12 +82,9 @@ "zone.js": "0.11.4" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "zone.js": "^0.10.2 || ^0.11.0" }, - "dependencies": { - "tslib": "^2.3.1" - }, "sideEffects": false, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-zone-peer-dep" } diff --git a/packages/opentelemetry-context-zone/.eslintrc.js b/packages/opentelemetry-context-zone/.eslintrc.js index c21aa0e358..a374ccda6a 100644 --- a/packages/opentelemetry-context-zone/.eslintrc.js +++ b/packages/opentelemetry-context-zone/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "browser": true, "commonjs": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-context-zone/package.json b/packages/opentelemetry-context-zone/package.json index 84a937ce93..76adff9578 100644 --- a/packages/opentelemetry-context-zone/package.json +++ b/packages/opentelemetry-context-zone/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/context-zone", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Context Zone", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -50,10 +50,10 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", "codecov": "3.8.3", @@ -63,7 +63,7 @@ "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -75,9 +75,8 @@ "webpack-merge": "5.9.0" }, "dependencies": { - "@opentelemetry/context-zone-peer-dep": "1.14.0", - "zone.js": "^0.11.0", - "tslib": "^2.3.1" + "@opentelemetry/context-zone-peer-dep": "1.17.0", + "zone.js": "^0.11.0" }, "sideEffects": true, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-zone" diff --git a/packages/opentelemetry-core/.eslintrc.js b/packages/opentelemetry-core/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-core/.eslintrc.js +++ b/packages/opentelemetry-core/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index 23e11a9e5c..bb1e010b22 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/core", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Core provides constants and utilities shared by all OpenTelemetry SDK packages.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -18,7 +18,7 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts --exclude 'test/platform/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "tdd": "npm run tdd:node", "tdd:node": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", @@ -64,21 +64,21 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -88,11 +88,10 @@ "webpack": "4.46.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-core", "sideEffects": false diff --git a/packages/opentelemetry-core/src/baggage/utils.ts b/packages/opentelemetry-core/src/baggage/utils.ts index 991b8a89a6..bb8b4b0155 100644 --- a/packages/opentelemetry-core/src/baggage/utils.ts +++ b/packages/opentelemetry-core/src/baggage/utils.ts @@ -61,10 +61,14 @@ export function parsePairKeyValue( if (valueProps.length <= 0) return; const keyPairPart = valueProps.shift(); if (!keyPairPart) return; - const keyPair = keyPairPart.split(BAGGAGE_KEY_PAIR_SEPARATOR); - if (keyPair.length !== 2) return; - const key = decodeURIComponent(keyPair[0].trim()); - const value = decodeURIComponent(keyPair[1].trim()); + const separatorIndex = keyPairPart.indexOf(BAGGAGE_KEY_PAIR_SEPARATOR); + if (separatorIndex <= 0) return; + const key = decodeURIComponent( + keyPairPart.substring(0, separatorIndex).trim() + ); + const value = decodeURIComponent( + keyPairPart.substring(separatorIndex + 1).trim() + ); let metadata; if (valueProps.length > 0) { metadata = baggageEntryMetadataFromString( diff --git a/packages/opentelemetry-core/src/common/time.ts b/packages/opentelemetry-core/src/common/time.ts index 8dd650a992..8d3051b00c 100644 --- a/packages/opentelemetry-core/src/common/time.ts +++ b/packages/opentelemetry-core/src/common/time.ts @@ -129,7 +129,7 @@ export function hrTimeToNanoseconds(time: api.HrTime): number { * @param time */ export function hrTimeToMilliseconds(time: api.HrTime): number { - return Math.round(time[0] * 1e3 + time[1] / 1e6); + return time[0] * 1e3 + time[1] / 1e6; } /** @@ -137,7 +137,7 @@ export function hrTimeToMilliseconds(time: api.HrTime): number { * @param time */ export function hrTimeToMicroseconds(time: api.HrTime): number { - return Math.round(time[0] * 1e6 + time[1] / 1e3); + return time[0] * 1e6 + time[1] / 1e3; } /** diff --git a/packages/opentelemetry-core/src/utils/callback.ts b/packages/opentelemetry-core/src/utils/callback.ts index ebbad5f96b..56c900c2ab 100644 --- a/packages/opentelemetry-core/src/utils/callback.ts +++ b/packages/opentelemetry-core/src/utils/callback.ts @@ -22,11 +22,14 @@ import { Deferred } from './promise'; export class BindOnceFuture< R, This = unknown, - T extends (this: This, ...args: unknown[]) => R = () => R + T extends (this: This, ...args: unknown[]) => R = () => R, > { private _isCalled = false; private _deferred = new Deferred(); - constructor(private _callback: T, private _that: This) {} + constructor( + private _callback: T, + private _that: This + ) {} get isCalled() { return this._isCalled; diff --git a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts index c30bfb3014..801496513f 100644 --- a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts +++ b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts @@ -181,9 +181,9 @@ describe('W3CBaggagePropagator', () => { describe('.extract()', () => { const baggageValue = - 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; + 'key1=d4cda95b==,key3=c88815a7, keyn = valn, keym =valm'; const expected = propagation.createBaggage({ - key1: { value: 'd4cda95b' }, + key1: { value: 'd4cda95b==' }, key3: { value: 'c88815a7' }, keyn: { value: 'valn' }, keym: { value: 'valm' }, @@ -217,7 +217,7 @@ describe('W3CBaggagePropagator', () => { it('should extract context of a sampled span when the headerValue comes as array with multiple items', () => { carrier[BAGGAGE_HEADER] = [ - 'key1=d4cda95b,key3=c88815a7, keyn = valn', + 'key1=d4cda95b==,key3=c88815a7, keyn = valn', 'keym =valm', ]; const extractedBaggage = propagation.getBaggage( @@ -282,10 +282,6 @@ describe('W3CBaggagePropagator', () => { header: '289371298nekjh2939299283jbk2b', baggage: undefined, }, - invalidDoubleEqual: { - header: 'key1==value;key2=value2', - baggage: undefined, - }, invalidWrongKeyValueFormat: { header: 'key1:value;key2=value2', baggage: undefined, @@ -295,7 +291,7 @@ describe('W3CBaggagePropagator', () => { baggage: undefined, }, mixInvalidAndValidKeys: { - header: 'key1==value,key2=value2', + header: 'key1:value,key2=value2', baggage: propagation.createBaggage({ key2: { value: 'value2', diff --git a/packages/opentelemetry-core/test/utils/merge.test.ts b/packages/opentelemetry-core/test/utils/merge.test.ts index 76e9ab2fe0..56c08c8321 100644 --- a/packages/opentelemetry-core/test/utils/merge.test.ts +++ b/packages/opentelemetry-core/test/utils/merge.test.ts @@ -272,7 +272,10 @@ class A { } class B extends A { - constructor(name = 'foo', private _ver = 1) { + constructor( + name = 'foo', + private _ver = 1 + ) { super(name); } getVer() { diff --git a/packages/opentelemetry-exporter-jaeger/.eslintrc.js b/packages/opentelemetry-exporter-jaeger/.eslintrc.js index f726f3becb..3d9af536bb 100644 --- a/packages/opentelemetry-exporter-jaeger/.eslintrc.js +++ b/packages/opentelemetry-exporter-jaeger/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index 3b4164d3f9..9e94b5f268 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-jaeger", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Exporter Jaeger allows user to send collected traces to Jaeger", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -45,15 +45,15 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/resources": "1.14.0", + "@opentelemetry/resources": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", + "nock": "13.3.3", "nyc": "15.1.0", "sinon": "15.1.2", "ts-mocha": "10.0.0", @@ -63,11 +63,10 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "jaeger-client": "^3.15.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0", + "jaeger-client": "^3.15.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-exporter-jaeger", "sideEffects": false diff --git a/packages/opentelemetry-exporter-jaeger/src/version.js b/packages/opentelemetry-exporter-jaeger/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/opentelemetry-exporter-jaeger/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/packages/opentelemetry-exporter-zipkin/.eslintrc.js b/packages/opentelemetry-exporter-zipkin/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-exporter-zipkin/.eslintrc.js +++ b/packages/opentelemetry-exporter-zipkin/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index bbe473b650..681d997e34 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-zipkin", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Zipkin Exporter allows the user to send collected traces to Zipkin.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -23,7 +23,7 @@ "lint:fix": "eslint . --ext .ts --fix", "tdd": "npm run test -- --watch-extensions ts --watch", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "version": "node ../../scripts/version-update.js", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", @@ -60,25 +60,25 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@opentelemetry/api": "^1.0.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", + "nock": "13.3.3", "nyc": "15.1.0", "sinon": "15.1.2", "ts-loader": "8.4.0", @@ -92,11 +92,10 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-exporter-zipkin", "sideEffects": false diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index 94983057f6..54392321f8 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -48,7 +48,7 @@ export function toZipkinSpan( id: span.spanContext().spanId, kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind], timestamp: hrTimeToMicroseconds(span.startTime), - duration: hrTimeToMicroseconds(span.duration), + duration: Math.round(hrTimeToMicroseconds(span.duration)), localEndpoint: { serviceName }, tags: _toZipkinTags(span, statusCodeTagName, statusErrorTagName), annotations: span.events.length diff --git a/packages/opentelemetry-exporter-zipkin/src/version.js b/packages/opentelemetry-exporter-zipkin/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/opentelemetry-exporter-zipkin/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index 65a06922af..810b9e32f9 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -85,8 +85,8 @@ describe('transform', () => { timestamp: hrTimeToMicroseconds(span.events[0].time), }, ], - duration: hrTimeToMicroseconds( - hrTimeDuration(span.startTime, span.endTime) + duration: Math.round( + hrTimeToMicroseconds(hrTimeDuration(span.startTime, span.endTime)) ), id: span.spanContext().spanId, localEndpoint: { @@ -128,8 +128,8 @@ describe('transform', () => { assert.deepStrictEqual(zipkinSpan, { kind: 'SERVER', annotations: undefined, - duration: hrTimeToMicroseconds( - hrTimeDuration(span.startTime, span.endTime) + duration: Math.round( + hrTimeToMicroseconds(hrTimeDuration(span.startTime, span.endTime)) ), id: span.spanContext().spanId, localEndpoint: { @@ -179,8 +179,8 @@ describe('transform', () => { assert.deepStrictEqual(zipkinSpan, { kind: item.zipkin, annotations: undefined, - duration: hrTimeToMicroseconds( - hrTimeDuration(span.startTime, span.endTime) + duration: Math.round( + hrTimeToMicroseconds(hrTimeDuration(span.startTime, span.endTime)) ), id: span.spanContext().spanId, localEndpoint: { diff --git a/packages/opentelemetry-propagator-b3/.eslintrc.js b/packages/opentelemetry-propagator-b3/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-propagator-b3/.eslintrc.js +++ b/packages/opentelemetry-propagator-b3/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-propagator-b3/package.json b/packages/opentelemetry-propagator-b3/package.json index 89dcef29be..353c87b20f 100644 --- a/packages/opentelemetry-propagator-b3/package.json +++ b/packages/opentelemetry-propagator-b3/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/propagator-b3", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry B3 propagator provides context propagation for systems that are using the B3 header format", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -51,20 +51,18 @@ "access": "public" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-loader": "8.4.0", diff --git a/packages/opentelemetry-propagator-b3/src/version.js b/packages/opentelemetry-propagator-b3/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/opentelemetry-propagator-b3/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/packages/opentelemetry-propagator-jaeger/.eslintrc.js b/packages/opentelemetry-propagator-jaeger/.eslintrc.js index b23ee98fc0..3913d6d94b 100644 --- a/packages/opentelemetry-propagator-jaeger/.eslintrc.js +++ b/packages/opentelemetry-propagator-jaeger/.eslintrc.js @@ -4,5 +4,5 @@ module.exports = { "commonjs": true, "browser": true, }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-propagator-jaeger/package.json b/packages/opentelemetry-propagator-jaeger/package.json index de2e90601f..8d7a70c84b 100644 --- a/packages/opentelemetry-propagator-jaeger/package.json +++ b/packages/opentelemetry-propagator-jaeger/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/propagator-jaeger", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Jaeger propagator provides HTTP header propagation for systems that are using Jaeger HTTP header format.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -10,7 +10,7 @@ "prepublishOnly": "npm run compile", "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/index-webpack.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "tdd": "npm run tdd:node", "tdd:node": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", @@ -54,21 +54,21 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -78,11 +78,10 @@ "webpack": "4.46.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-propagator-jaeger", "sideEffects": false diff --git a/packages/opentelemetry-propagator-jaeger/src/version.js b/packages/opentelemetry-propagator-jaeger/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/packages/opentelemetry-resources/.eslintrc.js b/packages/opentelemetry-resources/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-resources/.eslintrc.js +++ b/packages/opentelemetry-resources/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index 17de24f223..311ea9d90b 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resources", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry SDK resources", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -22,8 +22,8 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:browser": "nyc karma start --single-run", - "test:webworker": "nyc karma start karma.worker.js --single-run", + "test:browser": "karma start --single-run", + "test:webworker": "karma start karma.worker.js --single-run", "tdd": "npm run test -- --watch-extensions ts --watch", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", @@ -61,24 +61,24 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "codecov": "3.8.3", "cross-var": "1.1.0", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", + "nock": "13.3.3", "nyc": "15.1.0", "sinon": "15.1.2", "ts-mocha": "10.0.0", @@ -88,12 +88,11 @@ "webpack-merge": "5.9.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-resources", "sideEffects": false diff --git a/packages/opentelemetry-resources/src/detect-resources.ts b/packages/opentelemetry-resources/src/detect-resources.ts index be6943f81d..4fa477a4f8 100644 --- a/packages/opentelemetry-resources/src/detect-resources.ts +++ b/packages/opentelemetry-resources/src/detect-resources.ts @@ -26,7 +26,7 @@ import { IResource } from './IResource'; * does not resolve until all the underlying detectors have resolved, unlike * detectResourcesSync. * - * @deprecated use detectResourceSync() instead. + * @deprecated use detectResourcesSync() instead. * @param config Configuration for resource detection */ export const detectResources = async ( diff --git a/packages/opentelemetry-sdk-trace-base/.eslintrc.js b/packages/opentelemetry-sdk-trace-base/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-sdk-trace-base/.eslintrc.js +++ b/packages/opentelemetry-sdk-trace-base/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-sdk-trace-base/package.json b/packages/opentelemetry-sdk-trace-base/package.json index 6cceaa64d5..600caa4294 100644 --- a/packages/opentelemetry-sdk-trace-base/package.json +++ b/packages/opentelemetry-sdk-trace-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-trace-base", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Tracing", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -18,8 +18,9 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", - "test:browser": "nyc karma start --single-run", - "test:webworker": "nyc karma start karma.worker.js --single-run", + "test:browser": "karma start --single-run", + "test:webworker": "karma start karma.worker.js --single-run", + "test:bench": "node test/performance/benchmark/index.js", "tdd": "npm run tdd:node", "tdd:node": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", @@ -64,23 +65,23 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", "@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -90,13 +91,12 @@ "webpack": "4.46.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-base", "sideEffects": false diff --git a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts index d760ff5809..7d84e0c734 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts @@ -46,7 +46,10 @@ export abstract class BatchSpanProcessorBase private _shutdownOnce: BindOnceFuture; private _droppedSpansCount: number = 0; - constructor(private readonly _exporter: SpanExporter, config?: T) { + constructor( + private readonly _exporter: SpanExporter, + config?: T + ) { const env = getEnv(); this._maxExportBatchSize = typeof config?.maxExportBatchSize === 'number' @@ -200,8 +203,8 @@ export abstract class BatchSpanProcessorBase doExport(); } else { Promise.all( - pendingResources.map(resource => - resource.waitForAsyncAttributes?.() + pendingResources.map( + resource => resource.waitForAsyncAttributes?.() ) ).then(doExport, err => { globalErrorHandler(err); diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js new file mode 100644 index 0000000000..83558ea01f --- /dev/null +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('./span'); diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js new file mode 100644 index 0000000000..ac978a6140 --- /dev/null +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js @@ -0,0 +1,43 @@ +/* + * 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 Benchmark = require('benchmark'); +const { BasicTracerProvider } = require('../../../build/src'); + +const tracerProvider = new BasicTracerProvider(); +const tracer = tracerProvider.getTracer('test') + +const suite = new Benchmark.Suite(); + +suite.on('cycle', event => { + console.log(String(event.target)); +}); + +suite.add('create spans (10 attributes)', function() { + const span = tracer.startSpan('span'); + span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('cccccccccccccccccccc', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('dddddddddddddddddddd', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('ffffffffffffffffffff', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('gggggggggggggggggggg', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa'); +}); + +suite.run(); diff --git a/packages/opentelemetry-sdk-trace-node/.eslintrc.js b/packages/opentelemetry-sdk-trace-node/.eslintrc.js index f726f3becb..3d9af536bb 100644 --- a/packages/opentelemetry-sdk-trace-node/.eslintrc.js +++ b/packages/opentelemetry-sdk-trace-node/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-sdk-trace-node/package.json b/packages/opentelemetry-sdk-trace-node/package.json index bd4fb782fe..0bdcc4a090 100644 --- a/packages/opentelemetry-sdk-trace-node/package.json +++ b/packages/opentelemetry-sdk-trace-node/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-trace-node", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Node SDK provides automatic telemetry (tracing, metrics, etc) for Node.js applications", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -45,16 +45,16 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", - "@opentelemetry/resources": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/semver": "7.5.0", - "@types/sinon": "10.0.15", + "@types/semver": "7.5.2", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -62,16 +62,15 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/context-async-hooks": "1.14.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/propagator-b3": "1.14.0", - "@opentelemetry/propagator-jaeger": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "semver": "^7.5.1", - "tslib": "^2.3.1" + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/propagator-jaeger": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "semver": "^7.5.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node", "sideEffects": false diff --git a/packages/opentelemetry-sdk-trace-web/.eslintrc.js b/packages/opentelemetry-sdk-trace-web/.eslintrc.js index 86d794e2f5..359356edd4 100644 --- a/packages/opentelemetry-sdk-trace-web/.eslintrc.js +++ b/packages/opentelemetry-sdk-trace-web/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "browser": true, }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-sdk-trace-web/package.json b/packages/opentelemetry-sdk-trace-web/package.json index b3bfc15586..ebbf2a4025 100644 --- a/packages/opentelemetry-sdk-trace-web/package.json +++ b/packages/opentelemetry-sdk-trace-web/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-trace-web", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry Web Tracer", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -17,8 +17,8 @@ "codecov:webworker": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", - "test:browser": "nyc karma start --single-run", - "test:webworker": "nyc karma start karma.worker.js --single-run", + "test:browser": "karma start --single-run", + "test:webworker": "karma start karma.worker.js --single-run", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", "prewatch": "npm run precompile", @@ -55,29 +55,29 @@ "access": "public" }, "devDependencies": { - "@babel/core": "7.22.5", - "@opentelemetry/api": ">=1.0.0 <1.5.0", - "@opentelemetry/context-zone": "1.14.0", - "@opentelemetry/propagator-b3": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "@types/jquery": "3.5.16", + "@babel/core": "7.22.20", + "@opentelemetry/api": ">=1.0.0 <1.7.0", + "@opentelemetry/context-zone": "1.17.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@types/jquery": "3.5.19", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", - "istanbul-instrumenter-loader": "3.0.1", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-jquery": "0.2.4", "karma-mocha": "2.0.1", "karma-mocha-webworker": "1.3.0", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", @@ -89,13 +89,12 @@ "webpack-merge": "5.9.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-web", "sideEffects": false diff --git a/packages/opentelemetry-semantic-conventions/.eslintrc.js b/packages/opentelemetry-semantic-conventions/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/opentelemetry-semantic-conventions/.eslintrc.js +++ b/packages/opentelemetry-semantic-conventions/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-semantic-conventions/package.json b/packages/opentelemetry-semantic-conventions/package.json index c7585e68f3..0cc05eb2dd 100644 --- a/packages/opentelemetry-semantic-conventions/package.json +++ b/packages/opentelemetry-semantic-conventions/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/semantic-conventions", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry semantic conventions", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -51,20 +51,17 @@ "devDependencies": { "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", - "nock": "13.3.1", + "nock": "13.3.3", "nyc": "15.1.0", "sinon": "15.1.2", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, - "dependencies": { - "tslib": "^2.3.1" - }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions", "sideEffects": false } diff --git a/packages/opentelemetry-shim-opentracing/.eslintrc.js b/packages/opentelemetry-shim-opentracing/.eslintrc.js index f726f3becb..3d9af536bb 100644 --- a/packages/opentelemetry-shim-opentracing/.eslintrc.js +++ b/packages/opentelemetry-shim-opentracing/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index 9b05c66d6c..f328e7fce4 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/shim-opentracing", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTracing to OpenTelemetry shim", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -42,28 +42,27 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0", - "@opentelemetry/propagator-b3": "1.14.0", - "@opentelemetry/propagator-jaeger": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", + "@opentelemetry/api": ">=1.0.0 <1.7.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/propagator-jaeger": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", "@types/mocha": "10.0.1", "@types/node": "18.6.5", "codecov": "3.8.3", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.5.0" + "@opentelemetry/api": ">=1.0.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/semantic-conventions": "1.14.0", - "opentracing": "^0.14.4", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0", + "opentracing": "^0.14.4" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-shim-opentracing", "sideEffects": false diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index cd3749a681..2da2f80003 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -261,7 +261,7 @@ describe('OpenTracing Shim', () => { assert.strictEqual(otSpan.links.length, 1); assert.deepStrictEqual( hrTimeToMilliseconds(otSpan.startTime), - Math.round(now + adjustment + performance.timeOrigin) + now + adjustment + performance.timeOrigin ); assert.deepStrictEqual(otSpan.attributes, opentracingOptions.tags); }); @@ -495,7 +495,7 @@ describe('OpenTracing Shim', () => { const adjustment = otSpan['_performanceOffset']; assert.deepStrictEqual( hrTimeToMilliseconds(otSpan.endTime), - Math.round(now + adjustment + performance.timeOrigin) + now + adjustment + performance.timeOrigin ); }); diff --git a/packages/sdk-metrics/.eslintrc.js b/packages/sdk-metrics/.eslintrc.js index f726f3becb..3d9af536bb 100644 --- a/packages/sdk-metrics/.eslintrc.js +++ b/packages/sdk-metrics/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/sdk-metrics/package.json b/packages/sdk-metrics/package.json index 2e327b6acd..3d4f5b299e 100644 --- a/packages/sdk-metrics/package.json +++ b/packages/sdk-metrics/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/sdk-metrics", - "version": "1.14.0", + "version": "1.17.0", "description": "OpenTelemetry metrics SDK", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -12,7 +12,7 @@ "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "tdd": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", @@ -54,34 +54,39 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.5.0", + "@babel/core": "7.22.20", + "@opentelemetry/api": ">=1.3.0 <1.7.0", "@types/lodash.merge": "4.6.7", "@types/mocha": "10.0.1", "@types/node": "18.6.5", - "@types/sinon": "10.0.15", + "@types/sinon": "10.0.16", + "babel-plugin-istanbul": "6.1.1", "codecov": "3.8.3", "cross-var": "1.1.0", "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.1", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.36", "karma-webpack": "4.0.2", - "lerna": "7.1.1", + "lerna": "7.1.5", "mocha": "10.2.0", "nyc": "15.1.0", "sinon": "15.1.2", + "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "webpack": "4.46.0", + "webpack-cli": "4.10.0", + "webpack-merge": "5.9.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.5.0" + "@opentelemetry/api": ">=1.3.0 <1.7.0" }, "dependencies": { - "@opentelemetry/core": "1.14.0", - "@opentelemetry/resources": "1.14.0", - "lodash.merge": "^4.6.2", - "tslib": "^2.3.1" + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "lodash.merge": "^4.6.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/sdk-metrics", "sideEffects": false diff --git a/packages/sdk-metrics/src/InstrumentDescriptor.ts b/packages/sdk-metrics/src/InstrumentDescriptor.ts index 01eabe2614..ac742fc0ee 100644 --- a/packages/sdk-metrics/src/InstrumentDescriptor.ts +++ b/packages/sdk-metrics/src/InstrumentDescriptor.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import { MetricOptions, ValueType } from '@opentelemetry/api'; +import { MetricOptions, ValueType, diag } from '@opentelemetry/api'; import { View } from './view/View'; +import { equalsCaseInsensitive } from './utils'; /** * Supported types of metric instruments. @@ -45,6 +46,11 @@ export function createInstrumentDescriptor( type: InstrumentType, options?: MetricOptions ): InstrumentDescriptor { + if (!isValidName(name)) { + diag.warn( + `Invalid metric name: "${name}". The metric name should be a ASCII string with a length no greater than 255 characters.` + ); + } return { name, type, @@ -71,10 +77,18 @@ export function isDescriptorCompatibleWith( descriptor: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor ) { + // Names are case-insensitive strings. return ( - descriptor.name === otherDescriptor.name && + equalsCaseInsensitive(descriptor.name, otherDescriptor.name) && descriptor.unit === otherDescriptor.unit && descriptor.type === otherDescriptor.type && descriptor.valueType === otherDescriptor.valueType ); } + +// ASCII string with a length no greater than 255 characters. +// NB: the first character counted separately from the rest. +const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,254}$/i; +export function isValidName(name: string): boolean { + return name.match(NAME_REGEXP) != null; +} diff --git a/packages/sdk-metrics/src/Instruments.ts b/packages/sdk-metrics/src/Instruments.ts index d99c621c0b..f665952f05 100644 --- a/packages/sdk-metrics/src/Instruments.ts +++ b/packages/sdk-metrics/src/Instruments.ts @@ -48,6 +48,12 @@ export class SyncInstrument { attributes: MetricAttributes = {}, context: Context = contextApi.active() ) { + if (typeof value !== 'number') { + diag.warn( + `non-number value provided to metric ${this._descriptor.name}: ${value}` + ); + return; + } if ( this._descriptor.valueType === ValueType.INT && !Number.isInteger(value) @@ -56,6 +62,10 @@ export class SyncInstrument { `INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); + // ignore non-finite values. + if (!Number.isInteger(value)) { + return; + } } this._writableMetricStorage.record( value, diff --git a/packages/sdk-metrics/src/ObservableResult.ts b/packages/sdk-metrics/src/ObservableResult.ts index 31e194290c..9298a46d93 100644 --- a/packages/sdk-metrics/src/ObservableResult.ts +++ b/packages/sdk-metrics/src/ObservableResult.ts @@ -41,6 +41,12 @@ export class ObservableResultImpl implements ObservableResult { * Observe a measurement of the value associated with the given attributes. */ observe(value: number, attributes: MetricAttributes = {}): void { + if (typeof value !== 'number') { + diag.warn( + `non-number value provided to metric ${this._descriptor.name}: ${value}` + ); + return; + } if ( this._descriptor.valueType === ValueType.INT && !Number.isInteger(value) @@ -49,6 +55,10 @@ export class ObservableResultImpl implements ObservableResult { `INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); + // ignore non-finite values. + if (!Number.isInteger(value)) { + return; + } } this._buffer.set(attributes, value); } @@ -79,6 +89,12 @@ export class BatchObservableResultImpl implements BatchObservableResult { map = new AttributeHashMap(); this._buffer.set(metric, map); } + if (typeof value !== 'number') { + diag.warn( + `non-number value provided to metric ${metric._descriptor.name}: ${value}` + ); + return; + } if ( metric._descriptor.valueType === ValueType.INT && !Number.isInteger(value) @@ -87,6 +103,10 @@ export class BatchObservableResultImpl implements BatchObservableResult { `INT value type cannot accept a floating-point value for ${metric._descriptor.name}, ignoring the fractional digits.` ); value = Math.trunc(value); + // ignore non-finite values. + if (!Number.isInteger(value)) { + return; + } } map.set(attributes, value); } diff --git a/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts b/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts index 51c71ee211..bceb86b8ec 100644 --- a/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts +++ b/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts @@ -52,7 +52,10 @@ class HighLow { static combine(h1: HighLow, h2: HighLow): HighLow { return new HighLow(Math.min(h1.low, h2.low), Math.max(h1.high, h2.high)); } - constructor(public low: number, public high: number) {} + constructor( + public low: number, + public high: number + ) {} } const MAX_SCALE = 20; diff --git a/packages/sdk-metrics/src/export/MetricReader.ts b/packages/sdk-metrics/src/export/MetricReader.ts index 3bc4c63a06..8aad601d70 100644 --- a/packages/sdk-metrics/src/export/MetricReader.ts +++ b/packages/sdk-metrics/src/export/MetricReader.ts @@ -18,7 +18,7 @@ import * as api from '@opentelemetry/api'; import { AggregationTemporality } from './AggregationTemporality'; import { MetricProducer } from './MetricProducer'; import { CollectionResult } from './MetricData'; -import { callWithTimeout } from '../utils'; +import { FlatMap, callWithTimeout } from '../utils'; import { InstrumentType } from '../InstrumentDescriptor'; import { CollectionOptions, @@ -45,6 +45,13 @@ export interface MetricReaderOptions { * not configured, cumulative is used for all instruments. */ aggregationTemporalitySelector?: AggregationTemporalitySelector; + /** + * **Note, this option is experimental**. Additional MetricProducers to use as a source of + * aggregated metric data in addition to the SDK's metric data. The resource returned by + * these MetricProducers is ignored; the SDK's resource will be used instead. + * @experimental + */ + metricProducers?: MetricProducer[]; } /** @@ -55,8 +62,10 @@ export abstract class MetricReader { // Tracks the shutdown state. // TODO: use BindOncePromise here once a new version of @opentelemetry/core is available. private _shutdown = false; - // MetricProducer used by this instance. - private _metricProducer?: MetricProducer; + // Additional MetricProducers which will be combined with the SDK's output + private _metricProducers: MetricProducer[]; + // MetricProducer used by this instance which produces metrics from the SDK + private _sdkMetricProducer?: MetricProducer; private readonly _aggregationTemporalitySelector: AggregationTemporalitySelector; private readonly _aggregationSelector: AggregationSelector; @@ -66,20 +75,26 @@ export abstract class MetricReader { this._aggregationTemporalitySelector = options?.aggregationTemporalitySelector ?? DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR; + this._metricProducers = options?.metricProducers ?? []; } /** - * Set the {@link MetricProducer} used by this instance. + * Set the {@link MetricProducer} used by this instance. **This should only be called by the + * SDK and should be considered internal.** * + * To add additional {@link MetricProducer}s to a {@link MetricReader}, pass them to the + * constructor as {@link MetricReaderOptions.metricProducers}. + * + * @internal * @param metricProducer */ setMetricProducer(metricProducer: MetricProducer) { - if (this._metricProducer) { + if (this._sdkMetricProducer) { throw new Error( 'MetricReader can not be bound to a MeterProvider again.' ); } - this._metricProducer = metricProducer; + this._sdkMetricProducer = metricProducer; this.onInitialized(); } @@ -130,7 +145,7 @@ export abstract class MetricReader { * Collect all metrics from the associated {@link MetricProducer} */ async collect(options?: CollectionOptions): Promise { - if (this._metricProducer === undefined) { + if (this._sdkMetricProducer === undefined) { throw new Error('MetricReader is not bound to a MetricProducer'); } @@ -139,9 +154,37 @@ export abstract class MetricReader { throw new Error('MetricReader is shutdown'); } - return this._metricProducer.collect({ - timeoutMillis: options?.timeoutMillis, - }); + const [sdkCollectionResults, ...additionalCollectionResults] = + await Promise.all([ + this._sdkMetricProducer.collect({ + timeoutMillis: options?.timeoutMillis, + }), + ...this._metricProducers.map(producer => + producer.collect({ + timeoutMillis: options?.timeoutMillis, + }) + ), + ]); + + // Merge the results, keeping the SDK's Resource + const errors = sdkCollectionResults.errors.concat( + FlatMap(additionalCollectionResults, result => result.errors) + ); + const resource = sdkCollectionResults.resourceMetrics.resource; + const scopeMetrics = + sdkCollectionResults.resourceMetrics.scopeMetrics.concat( + FlatMap( + additionalCollectionResults, + result => result.resourceMetrics.scopeMetrics + ) + ); + return { + resourceMetrics: { + resource, + scopeMetrics, + }, + errors, + }; } /** diff --git a/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts b/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts index 2371ecb67f..5ecafff682 100644 --- a/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts +++ b/packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts @@ -25,6 +25,7 @@ import { MetricReader } from './MetricReader'; import { PushMetricExporter } from './MetricExporter'; import { callWithTimeout, TimeoutError } from '../utils'; import { diag } from '@opentelemetry/api'; +import { MetricProducer } from './MetricProducer'; export type PeriodicExportingMetricReaderOptions = { /** @@ -40,6 +41,13 @@ export type PeriodicExportingMetricReaderOptions = { * Milliseconds for the async observable callback to timeout. */ exportTimeoutMillis?: number; + /** + * **Note, this option is experimental**. Additional MetricProducers to use as a source of + * aggregated metric data in addition to the SDK's metric data. The resource returned by + * these MetricProducers is ignored; the SDK's resource will be used instead. + * @experimental + */ + metricProducers?: MetricProducer[]; }; /** @@ -59,6 +67,7 @@ export class PeriodicExportingMetricReader extends MetricReader { ), aggregationTemporalitySelector: options.exporter.selectAggregationTemporality?.bind(options.exporter), + metricProducers: options.metricProducers, }); if ( diff --git a/packages/sdk-metrics/src/index.ts b/packages/sdk-metrics/src/index.ts index 4760da3ccc..c9623707f2 100644 --- a/packages/sdk-metrics/src/index.ts +++ b/packages/sdk-metrics/src/index.ts @@ -54,6 +54,8 @@ export { InMemoryMetricExporter } from './export/InMemoryMetricExporter'; export { ConsoleMetricExporter } from './export/ConsoleMetricExporter'; +export { MetricCollectOptions, MetricProducer } from './export/MetricProducer'; + export { InstrumentDescriptor, InstrumentType } from './InstrumentDescriptor'; export { MeterProvider, MeterProviderOptions } from './MeterProvider'; diff --git a/packages/sdk-metrics/src/state/MeterSharedState.ts b/packages/sdk-metrics/src/state/MeterSharedState.ts index 330d293eea..099a21c0d7 100644 --- a/packages/sdk-metrics/src/state/MeterSharedState.ts +++ b/packages/sdk-metrics/src/state/MeterSharedState.ts @@ -110,7 +110,7 @@ export class MeterSharedState { private _registerMetricStorage< MetricStorageType extends MetricStorageConstructor, - R extends InstanceType + R extends InstanceType, >( descriptor: InstrumentDescriptor, MetricStorageType: MetricStorageType diff --git a/packages/sdk-metrics/src/utils.ts b/packages/sdk-metrics/src/utils.ts index 835de92fe1..9a8f80abde 100644 --- a/packages/sdk-metrics/src/utils.ts +++ b/packages/sdk-metrics/src/utils.ts @@ -190,3 +190,7 @@ export function binarySearchLB(arr: number[], value: number): number { } return -1; } + +export function equalsCaseInsensitive(lhs: string, rhs: string): boolean { + return lhs.toLowerCase() === rhs.toLowerCase(); +} diff --git a/packages/sdk-metrics/src/version.js b/packages/sdk-metrics/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/sdk-metrics/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/packages/sdk-metrics/src/view/Aggregation.ts b/packages/sdk-metrics/src/view/Aggregation.ts index f36394c5bc..821b55ec2f 100644 --- a/packages/sdk-metrics/src/view/Aggregation.ts +++ b/packages/sdk-metrics/src/view/Aggregation.ts @@ -125,7 +125,10 @@ export class ExplicitBucketHistogramAggregation extends Aggregation { * @param boundaries the bucket boundaries of the histogram aggregation * @param _recordMinMax If set to true, min and max will be recorded. Otherwise, min and max will not be recorded. */ - constructor(boundaries: number[], private readonly _recordMinMax = true) { + constructor( + boundaries: number[], + private readonly _recordMinMax = true + ) { super(); if (boundaries === undefined || boundaries.length === 0) { throw new Error('HistogramAggregator should be created with boundaries.'); diff --git a/packages/sdk-metrics/test/InstrumentDescriptor.test.ts b/packages/sdk-metrics/test/InstrumentDescriptor.test.ts index 7d8796cbf1..5bf3196693 100644 --- a/packages/sdk-metrics/test/InstrumentDescriptor.test.ts +++ b/packages/sdk-metrics/test/InstrumentDescriptor.test.ts @@ -17,8 +17,13 @@ import * as assert from 'assert'; import { createInstrumentDescriptor, + InstrumentDescriptor, InstrumentType, + isValidName, + isDescriptorCompatibleWith, } from '../src/InstrumentDescriptor'; +import { invalidNames, validNames } from './util'; +import { ValueType } from '@opentelemetry/api'; describe('InstrumentDescriptor', () => { describe('createInstrumentDescriptor', () => { @@ -35,4 +40,105 @@ describe('InstrumentDescriptor', () => { }); } }); + + describe('isDescriptorCompatibleWith', () => { + const tests: [ + string, + boolean, + InstrumentDescriptor, + InstrumentDescriptor, + ][] = [ + [ + 'Compatible with identical descriptors', + true, + { + name: 'foo', + description: 'any descriptions', + unit: 'kB', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + { + name: 'foo', + description: 'any descriptions', + unit: 'kB', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + ], + [ + 'Compatible with case-insensitive names', + true, + { + name: 'foo', + description: '', + unit: '', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + { + name: 'FoO', + description: '', + unit: '', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + ], + [ + 'Incompatible with different names', + false, + { + name: 'foo', + description: '', + unit: '', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + { + name: 'foobar', + description: '', + unit: '', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + ], + [ + 'Incompatible with case-sensitive units', + false, + { + name: 'foo', + description: '', + unit: 'kB', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + { + name: 'foo', + description: '', + unit: 'kb', + type: InstrumentType.COUNTER, + valueType: ValueType.DOUBLE, + }, + ], + ]; + for (const test of tests) { + it(test[0], () => { + assert.ok(isDescriptorCompatibleWith(test[2], test[3]) === test[1]); + }); + } + }); + + describe('isValidName', () => { + it('should validate names', () => { + for (const invalidName of invalidNames) { + assert.ok( + !isValidName(invalidName), + `${invalidName} should be invalid` + ); + } + for (const validName of validNames) { + assert.ok(isValidName(validName), `${validName} should be valid`); + } + }); + }); }); diff --git a/packages/sdk-metrics/test/Instruments.test.ts b/packages/sdk-metrics/test/Instruments.test.ts index 8651643fa3..80f834f30c 100644 --- a/packages/sdk-metrics/test/Instruments.test.ts +++ b/packages/sdk-metrics/test/Instruments.test.ts @@ -74,9 +74,14 @@ describe('Instruments', () => { }); counter.add(1); - // floating-point value should be trunc-ed. - counter.add(1.1); counter.add(1, { foo: 'bar' }); + // floating-point values should be trunc-ed. + counter.add(1.1); + // non-finite/non-number values should be ignored. + counter.add(Infinity); + counter.add(-Infinity); + counter.add(NaN); + counter.add('1' as any); await validateExport(cumulativeReader, { descriptor: { name: 'test', @@ -124,10 +129,13 @@ describe('Instruments', () => { }); counter.add(1); - // add floating-point value. - counter.add(1.1); counter.add(1, { foo: 'bar' }); + // add floating-point values. + counter.add(1.1); counter.add(1.2, { foo: 'bar' }); + // non-number values should be ignored. + counter.add('1' as any); + await validateExport(cumulativeReader, { dataPointType: DataPointType.SUM, isMonotonic: true, @@ -197,6 +205,13 @@ describe('Instruments', () => { upDownCounter.add(-1.1); upDownCounter.add(4, { foo: 'bar' }); upDownCounter.add(1.1, { foo: 'bar' }); + + // non-finite/non-number values should be ignored. + upDownCounter.add(Infinity); + upDownCounter.add(-Infinity); + upDownCounter.add(NaN); + upDownCounter.add('1' as any); + await validateExport(deltaReader, { descriptor: { name: 'test', @@ -230,6 +245,8 @@ describe('Instruments', () => { upDownCounter.add(-1.1); upDownCounter.add(4, { foo: 'bar' }); upDownCounter.add(1.1, { foo: 'bar' }); + // non-number values should be ignored. + upDownCounter.add('1' as any); await validateExport(deltaReader, { dataPointType: DataPointType.SUM, isMonotonic: false, @@ -283,6 +300,12 @@ describe('Instruments', () => { histogram.record(0.1); histogram.record(100, { foo: 'bar' }); histogram.record(0.1, { foo: 'bar' }); + // non-finite/non-number values should be ignored. + histogram.record(Infinity); + histogram.record(-Infinity); + histogram.record(NaN); + histogram.record('1' as any); + await validateExport(deltaReader, { descriptor: { name: 'test', @@ -427,6 +450,9 @@ describe('Instruments', () => { histogram.record(0.1); histogram.record(100, { foo: 'bar' }); histogram.record(0.1, { foo: 'bar' }); + // non-number values should be ignored. + histogram.record('1' as any); + await validateExport(deltaReader, { dataPointType: DataPointType.HISTOGRAM, dataPoints: [ diff --git a/packages/sdk-metrics/test/Meter.test.ts b/packages/sdk-metrics/test/Meter.test.ts index 4ffe41607d..e40d6aa507 100644 --- a/packages/sdk-metrics/test/Meter.test.ts +++ b/packages/sdk-metrics/test/Meter.test.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import { Observable } from '@opentelemetry/api'; +import { Observable, diag } from '@opentelemetry/api'; import * as assert from 'assert'; +import * as sinon from 'sinon'; import { CounterInstrument, HistogramInstrument, @@ -27,78 +28,86 @@ import { import { Meter } from '../src/Meter'; import { MeterProviderSharedState } from '../src/state/MeterProviderSharedState'; import { MeterSharedState } from '../src/state/MeterSharedState'; -import { defaultInstrumentationScope, defaultResource } from './util'; +import { + defaultInstrumentationScope, + defaultResource, + invalidNames, + validNames, +} from './util'; describe('Meter', () => { + afterEach(() => { + sinon.restore(); + }); + describe('createCounter', () => { - it('should create counter', () => { + testWithNames('counter', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const counter = meter.createCounter('foobar'); + const counter = meter.createCounter(name); assert(counter instanceof CounterInstrument); }); }); describe('createUpDownCounter', () => { - it('should create up down counter', () => { + testWithNames('UpDownCounter', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const upDownCounter = meter.createUpDownCounter('foobar'); + const upDownCounter = meter.createUpDownCounter(name); assert(upDownCounter instanceof UpDownCounterInstrument); }); }); describe('createHistogram', () => { - it('should create histogram', () => { + testWithNames('Histogram', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const histogram = meter.createHistogram('foobar'); + const histogram = meter.createHistogram(name); assert(histogram instanceof HistogramInstrument); }); }); describe('createObservableGauge', () => { - it('should create observable gauge', () => { + testWithNames('ObservableGauge', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const observableGauge = meter.createObservableGauge('foobar'); + const observableGauge = meter.createObservableGauge(name); assert(observableGauge instanceof ObservableGaugeInstrument); }); }); describe('createObservableCounter', () => { - it('should create observable counter', () => { + testWithNames('ObservableCounter', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const observableCounter = meter.createObservableCounter('foobar'); + const observableCounter = meter.createObservableCounter(name); assert(observableCounter instanceof ObservableCounterInstrument); }); }); describe('createObservableUpDownCounter', () => { - it('should create observable up-down-counter', () => { + testWithNames('ObservableUpDownCounter', name => { const meterSharedState = new MeterSharedState( new MeterProviderSharedState(defaultResource), defaultInstrumentationScope ); const meter = new Meter(meterSharedState); - const observableUpDownCounter = - meter.createObservableUpDownCounter('foobar'); + const observableUpDownCounter = meter.createObservableUpDownCounter(name); assert( observableUpDownCounter instanceof ObservableUpDownCounterInstrument ); @@ -167,3 +176,22 @@ describe('Meter', () => { }); }); }); + +function testWithNames(type: string, tester: (name: string) => void) { + for (const invalidName of invalidNames) { + it(`should warn with invalid name ${invalidName} for ${type}`, () => { + const warnStub = sinon.spy(diag, 'warn'); + tester(invalidName); + assert.strictEqual(warnStub.callCount, 1); + assert.ok(warnStub.calledWithMatch('Invalid metric name')); + }); + } + + for (const validName of validNames) { + it(`should not warn with valid name ${validName} for ${type}`, () => { + const warnStub = sinon.spy(diag, 'warn'); + tester(validName); + assert.strictEqual(warnStub.callCount, 0); + }); + } +} diff --git a/packages/sdk-metrics/test/ObservableResult.test.ts b/packages/sdk-metrics/test/ObservableResult.test.ts index f07b3f9f21..9aacc46066 100644 --- a/packages/sdk-metrics/test/ObservableResult.test.ts +++ b/packages/sdk-metrics/test/ObservableResult.test.ts @@ -63,8 +63,27 @@ describe('ObservableResultImpl', () => { valueType: ValueType.INT, }); observableResult.observe(1.1, {}); + // should ignore non-finite/non-number values. + observableResult.observe(Infinity, {}); + observableResult.observe(-Infinity, {}); + observableResult.observe(NaN, {}); + assert.strictEqual(observableResult._buffer.get({}), 1); }); + + it('should ignore non-number values', () => { + const observableResult = new ObservableResultImpl({ + name: 'test', + description: '', + type: InstrumentType.COUNTER, + unit: '', + valueType: ValueType.INT, + }); + + observableResult.observe('1' as any, {}); + + assert.strictEqual(observableResult._buffer.get({}), undefined); + }); }); }); @@ -126,7 +145,34 @@ describe('BatchObservableResultImpl', () => { ); observableResult.observe(observable, 1.1, {}); + // should ignore non-finite/non-number values. + observableResult.observe(observable, Infinity, {}); + observableResult.observe(observable, -Infinity, {}); + observableResult.observe(observable, NaN, {}); assert.strictEqual(observableResult._buffer.get(observable)?.get({}), 1); }); + + it('should ignore invalid values', () => { + const observableResult = new BatchObservableResultImpl(); + const observable = new ObservableInstrument( + { + name: 'test', + description: '', + type: InstrumentType.COUNTER, + unit: '', + valueType: ValueType.INT, + }, + [], + new ObservableRegistry() + ); + + observableResult.observe(observable, '1' as any, {}); + observableResult.observe(/** invalid observable */ {} as any, 1, {}); + assert.strictEqual( + observableResult._buffer.get(observable)!.get({}), + undefined + ); + assert.strictEqual(observableResult._buffer.size, 1); + }); }); }); diff --git a/packages/sdk-metrics/test/export/MetricReader.test.ts b/packages/sdk-metrics/test/export/MetricReader.test.ts index 297622982d..c0643a60da 100644 --- a/packages/sdk-metrics/test/export/MetricReader.test.ts +++ b/packages/sdk-metrics/test/export/MetricReader.test.ts @@ -20,7 +20,13 @@ import { MeterProvider } from '../../src/MeterProvider'; import { assertRejects } from '../test-utils'; import { emptyResourceMetrics, TestMetricProducer } from './TestMetricProducer'; import { TestMetricReader } from './TestMetricReader'; -import { Aggregation, AggregationTemporality } from '../../src'; +import { + Aggregation, + AggregationTemporality, + DataPointType, + InstrumentType, + ScopeMetrics, +} from '../../src'; import { DEFAULT_AGGREGATION_SELECTOR, DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR, @@ -29,6 +35,39 @@ import { assertAggregationSelector, assertAggregationTemporalitySelector, } from './utils'; +import { defaultResource } from '../util'; +import { ValueType } from '@opentelemetry/api'; +import { Resource } from '@opentelemetry/resources'; + +const testScopeMetrics: ScopeMetrics[] = [ + { + scope: { + name: 'additionalMetricProducerMetrics', + }, + metrics: [ + { + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.SUM, + dataPoints: [ + { + attributes: {}, + value: 1, + startTime: [0, 0], + endTime: [1, 0], + }, + ], + descriptor: { + name: 'additionalCounter', + unit: '', + type: InstrumentType.COUNTER, + description: '', + valueType: ValueType.INT, + }, + isMonotonic: true, + }, + ], + }, +]; describe('MetricReader', () => { describe('setMetricProducer', () => { @@ -83,20 +122,91 @@ describe('MetricReader', () => { assertRejects(reader.collect(), /MetricReader is shutdown/); }); - it('should call MetricProduce.collect with timeout', async () => { + it('should call MetricProducer.collect with timeout', async () => { const reader = new TestMetricReader(); const producer = new TestMetricProducer(); reader.setMetricProducer(producer); - const collectStub = sinon.stub(producer, 'collect'); + const collectSpy = sinon.spy(producer, 'collect'); await reader.collect({ timeoutMillis: 20 }); - assert(collectStub.calledOnce); - const args = collectStub.args[0]; + assert(collectSpy.calledOnce); + const args = collectSpy.args[0]; assert.deepStrictEqual(args, [{ timeoutMillis: 20 }]); await reader.shutdown(); }); + + it('should collect metrics from the SDK and the additional metricProducers', async () => { + const meterProvider = new MeterProvider({ resource: defaultResource }); + const additionalProducer = new TestMetricProducer({ + resourceMetrics: { + resource: new Resource({ + shouldBeDiscarded: 'should-be-discarded', + }), + scopeMetrics: testScopeMetrics, + }, + }); + const reader = new TestMetricReader({ + metricProducers: [additionalProducer], + }); + meterProvider.addMetricReader(reader); + + // Make a measurement + meterProvider + .getMeter('someSdkMetrics') + .createCounter('sdkCounter') + .add(5, { hello: 'world' }); + const collectionResult = await reader.collect(); + + assert.strictEqual(collectionResult.errors.length, 0); + // Should keep the SDK's Resource only + assert.deepStrictEqual( + collectionResult.resourceMetrics.resource, + defaultResource + ); + assert.strictEqual( + collectionResult.resourceMetrics.scopeMetrics.length, + 2 + ); + const [sdkScopeMetrics, additionalScopeMetrics] = + collectionResult.resourceMetrics.scopeMetrics; + + assert.strictEqual(sdkScopeMetrics.scope.name, 'someSdkMetrics'); + assert.strictEqual( + additionalScopeMetrics.scope.name, + 'additionalMetricProducerMetrics' + ); + + await reader.shutdown(); + }); + + it('should merge the errors from the SDK and all metricProducers', async () => { + const meterProvider = new MeterProvider(); + const reader = new TestMetricReader({ + metricProducers: [ + new TestMetricProducer({ errors: ['err1'] }), + new TestMetricProducer({ errors: ['err2'] }), + ], + }); + meterProvider.addMetricReader(reader); + + // Provide a callback throwing an error too + meterProvider + .getMeter('someSdkMetrics') + .createObservableCounter('sdkCounter') + .addCallback(result => { + throw 'errsdk'; + }); + const collectionResult = await reader.collect(); + + assert.deepStrictEqual(collectionResult.errors, [ + 'errsdk', + 'err1', + 'err2', + ]); + await reader.shutdown(); + }); }); describe('selectAggregation', () => { diff --git a/packages/sdk-metrics/test/export/TestMetricProducer.ts b/packages/sdk-metrics/test/export/TestMetricProducer.ts index 29137d62a4..d4865724c3 100644 --- a/packages/sdk-metrics/test/export/TestMetricProducer.ts +++ b/packages/sdk-metrics/test/export/TestMetricProducer.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CollectionResult } from '../../src/export/MetricData'; +import { CollectionResult, ResourceMetrics } from '../../src/export/MetricData'; import { MetricProducer } from '../../src/export/MetricProducer'; import { defaultResource } from '../util'; @@ -24,10 +24,21 @@ export const emptyResourceMetrics = { }; export class TestMetricProducer implements MetricProducer { + private resourceMetrics: ResourceMetrics; + private errors: unknown[]; + + constructor(params?: { + resourceMetrics?: ResourceMetrics; + errors?: unknown[]; + }) { + this.resourceMetrics = params?.resourceMetrics ?? emptyResourceMetrics; + this.errors = params?.errors ?? []; + } + async collect(): Promise { return { - resourceMetrics: { resource: defaultResource, scopeMetrics: [] }, - errors: [], + resourceMetrics: this.resourceMetrics, + errors: this.errors, }; } } diff --git a/packages/sdk-metrics/test/export/TestMetricReader.ts b/packages/sdk-metrics/test/export/TestMetricReader.ts index 61727322a4..46fd41c045 100644 --- a/packages/sdk-metrics/test/export/TestMetricReader.ts +++ b/packages/sdk-metrics/test/export/TestMetricReader.ts @@ -31,7 +31,7 @@ export class TestMetricReader extends MetricReader { } getMetricCollector(): MetricCollector { - return this['_metricProducer'] as MetricCollector; + return this['_sdkMetricProducer'] as MetricCollector; } } diff --git a/packages/sdk-metrics/test/util.ts b/packages/sdk-metrics/test/util.ts index fa7a54b07f..ef081cf67a 100644 --- a/packages/sdk-metrics/test/util.ts +++ b/packages/sdk-metrics/test/util.ts @@ -66,6 +66,9 @@ export const defaultInstrumentationScope: InstrumentationScope = { schemaUrl: 'https://opentelemetry.io/schemas/1.7.0', }; +export const invalidNames = ['', 'a'.repeat(256), '1a', '-a', '.a', '_a']; +export const validNames = ['a', 'a'.repeat(255), 'a1', 'a-1', 'a.1', 'a_1']; + export const commonValues: number[] = [1, -1, 1.0, Infinity, -Infinity, NaN]; export const commonAttributes: MetricAttributes[] = [ {}, diff --git a/packages/template/.eslintrc.js b/packages/template/.eslintrc.js index 9dfe62f9b8..36847df9fb 100644 --- a/packages/template/.eslintrc.js +++ b/packages/template/.eslintrc.js @@ -5,5 +5,5 @@ module.exports = { "node": true, "browser": true }, - ...require('../../eslint.config.js') + ...require('../../eslint.base.js') } diff --git a/packages/template/package.json b/packages/template/package.json index 00876cf2c4..b7836e5409 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/template", - "version": "1.14.0", + "version": "1.17.0", "private": true, "publishConfig": { "access": "restricted" @@ -47,7 +47,7 @@ "Add/change these to scripts if browser is supported": { "compile": "tsc --build tsconfig.json", "clean": "tsc --build --clean tsconfig.json", - "test:browser": "nyc karma start --single-run", + "test:browser": "karma start --single-run", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "watch": "tsc --build --watch tsconfig.json" }, @@ -80,12 +80,9 @@ "devDependencies": { "@types/node": "18.6.5", "cross-var": "1.1.0", - "lerna": "7.1.1", + "lerna": "7.1.5", "typescript": "4.4.4" }, - "dependencies": { - "tslib": "^2.3.1" - }, "Add these to devDependencies for testing": { "@types/mocha": "9.1.1", "@types/sinon": "10.0.13", @@ -97,10 +94,10 @@ }, "Add these to devDependencies if browser is targeted": { "@types/webpack-env": "1.16.0", - "istanbul-instrumenter-loader": "3.0.1", - "karma": "5.2.3", + "babel-plugin-istanbul": "6.1.1", + "karma": "6.4.2", "karma-chrome-launcher": "3.1.0", - "karma-coverage-istanbul-reporter": "3.0.3", + "karma-coverage": "2.2.0", "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", "karma-webpack": "4.0.2", diff --git a/packages/template/src/version.js b/packages/template/src/version.js new file mode 100644 index 0000000000..2090d63abf --- /dev/null +++ b/packages/template/src/version.js @@ -0,0 +1,20 @@ +"use strict"; +/* + * 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. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.VERSION = void 0; +// this is autogenerated file, see scripts/version-update.js +exports.VERSION = '1.16.0'; diff --git a/renovate.json b/renovate.json index 5a106908e4..c7d143d797 100644 --- a/renovate.json +++ b/renovate.json @@ -19,14 +19,9 @@ { "matchPackageNames": ["typescript", "webpack", "webpack-cli"], "dependencyDashboardApproval": true - }, - { - "matchPaths": ["experimental/backwards-compatibility/**"], - "matchPackageNames": ["@types/node"], - "enabled": false } ], - "ignoreDeps": ["@opentelemetry/api", "@opentelemetry/resources_1.9.0"], + "ignoreDeps": ["@opentelemetry/api", "@opentelemetry/resources_1.9.0", "@types/node"], "assignees": ["@blumamir", "@dyladan", "@legendecas", "@pichlermarc"], "labels": ["dependencies"] } diff --git a/selenium-tests/package.json b/selenium-tests/package.json index 6d7726c134..9592f050de 100644 --- a/selenium-tests/package.json +++ b/selenium-tests/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/selenium-tests", - "version": "1.14.0", + "version": "1.17.0", "private": true, "description": "OpenTelemetry Selenium Tests", "main": "index.js", @@ -31,16 +31,16 @@ "access": "restricted" }, "devDependencies": { - "@babel/core": "7.22.5", + "@babel/core": "7.22.20", "@babel/plugin-proposal-class-properties": "7.18.6", - "@babel/plugin-proposal-decorators": "7.22.5", - "@babel/plugin-transform-runtime": "7.22.5", - "@babel/preset-env": "7.22.5", + "@babel/plugin-proposal-decorators": "7.22.15", + "@babel/plugin-transform-runtime": "7.22.15", + "@babel/preset-env": "7.22.20", "@opentelemetry/api": "^1.0.0", "babel-loader": "8.3.0", "babel-polyfill": "6.26.0", "browserstack-local": "1.4.8", - "chromedriver": "114.0.2", + "chromedriver": "116.0.0", "dotenv": "16.0.0", "fast-safe-stringify": "2.1.1", "geckodriver": "3.0.1", @@ -56,16 +56,16 @@ "@opentelemetry/api": "^1.0.0" }, "dependencies": { - "@opentelemetry/context-zone-peer-dep": "1.14.0", - "@opentelemetry/core": "1.14.0", - "@opentelemetry/exporter-trace-otlp-http": "0.40.0", - "@opentelemetry/exporter-zipkin": "1.14.0", - "@opentelemetry/instrumentation": "0.40.0", - "@opentelemetry/instrumentation-fetch": "0.40.0", - "@opentelemetry/instrumentation-xml-http-request": "0.40.0", - "@opentelemetry/sdk-metrics": "1.14.0", - "@opentelemetry/sdk-trace-base": "1.14.0", - "@opentelemetry/sdk-trace-web": "1.14.0", + "@opentelemetry/context-zone-peer-dep": "1.17.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/exporter-trace-otlp-http": "0.43.0", + "@opentelemetry/exporter-zipkin": "1.17.0", + "@opentelemetry/instrumentation": "0.43.0", + "@opentelemetry/instrumentation-fetch": "0.43.0", + "@opentelemetry/instrumentation-xml-http-request": "0.43.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/sdk-trace-web": "1.17.0", "zone.js": "0.11.4" } } diff --git a/tsconfig.base.json b/tsconfig.base.json index 84e684c8a5..cbafb67678 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -21,8 +21,7 @@ "strict": true, "strictNullChecks": true, "target": "es2017", - "useUnknownInCatchVariables": false, - "importHelpers": true + "useUnknownInCatchVariables": false }, "exclude": [ "node_modules" diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 2fec210b9a..29491b46ef 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -29,6 +29,9 @@ { "path": "experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json" }, + { + "path": "experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esm.json" + }, { "path": "experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json" }, diff --git a/tsconfig.esnext.json b/tsconfig.esnext.json index c5970c9c5c..031a2e5609 100644 --- a/tsconfig.esnext.json +++ b/tsconfig.esnext.json @@ -29,6 +29,9 @@ { "path": "experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esnext.json" }, + { + "path": "experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.esnext.json" + }, { "path": "experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json" }, diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo new file mode 100644 index 0000000000..bd9c8b8eab --- /dev/null +++ b/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"version":"4.4.4"} \ No newline at end of file