diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8197a4f89fb..8eb99d71405 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,7 +28,6 @@ jobs: run: | npm run lint npm run lint:examples - npm run lint:markdown - name: Lint doc files run: | diff --git a/.github/workflows/publish-to-npm.yml b/.github/workflows/publish-to-npm.yml new file mode 100644 index 00000000000..b51678268ab --- /dev/null +++ b/.github/workflows/publish-to-npm.yml @@ -0,0 +1,31 @@ +name: Publish packages to NPM + +on: + workflow_dispatch: + +jobs: + release-to-npm: + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + + - run: npm ci + + - run: npm run compile + + - name: Publish to npm + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + NPM_CONFIG_PROVENANCE: true + run: npx lerna publish --concurrency 1 from-package --no-push --no-private --no-git-tag-version --no-verify-access --yes diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 11bf4a9c7ad..55db4052849 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -48,6 +48,8 @@ jobs: run: npm run test - name: Report Coverage uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: verbose: true node-windows-tests: @@ -102,6 +104,8 @@ jobs: run: npm run test:browser - name: Report Coverage uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: verbose: true webworker-tests: @@ -128,6 +132,8 @@ jobs: run: npm run test:webworker - name: Report Coverage uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: verbose: true api-eol-node-test: diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad9ff304de..7194d8ba174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se * fix(resources): prevent circular import (resource -> detector -> resource -> ...) [#4653](https://github.com/open-telemetry/opentelemetry-js/pull/4653) @pichlermarc * fixes a circular import warning which would appear in rollup when bundling `@opentelemetry/resources` * fix(exporter-metrics-otlp-grpc): add explicit otlp-exporter-base dependency to exporter-metrics-otlp-grpc [#4678](https://github.com/open-telemetry/opentelemetry-js/pull/4678) @AkselAllas +* fix(resources) wait for async attributes for detecting resources [#4687](https://github.com/open-telemetry/opentelemetry-js/pull/4687) @ziolekjj ## 1.24.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 516e67d5242..7c4c6fc0e47 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,9 +29,9 @@ detailed instructions, see [development](#development) below. ```sh git clone https://github.com/open-telemetry/opentelemetry-js.git cd opentelemetry-js -npm install +npm ci npm run compile -npm test +npm run test ``` ## Pull Request Merge Guidelines @@ -164,7 +164,7 @@ Most of the commands needed for development are accessed as [npm scripts](https: This will install all dependencies for the root project and all modules managed by `npm workspaces`. ```sh -npm install +npm ci ``` ### Compile modules @@ -223,6 +223,16 @@ To run the unit tests continuously in watch mode while developing, use: npm run tdd ``` +Packages that are expected to run in the browser have browser specific tests: + +```sh +# Run browser-specific test +npm run test:browser + +# Run web worker test +npm run test:webworker +``` + ### Linting This project uses `eslint` to lint source code. Just like tests and compilation, linting can be done for all packages or only a single package. @@ -247,13 +257,21 @@ cd packages/opentelemetry-module-name npm run lint:fix ``` -Similarly, Markdown files (such as README.md files) can be linted: +The default lint command will check majority of files, including Markdown files (such as README.md files), but you +also have the option to check just the Markdown files with: ```sh npm run lint:markdown npm run lint:markdown:fix # can automatically fix some Markdown rules ``` +The default command doesn't check the examples folder. To lint just the examples, use the script: + +```sh +npm run lint:examples +npm run lint:examples:fix # can automatically fix some errors +``` + ### Generating docs We use [typedoc](https://www.npmjs.com/package/typedoc) to generate the api documentation. @@ -293,10 +311,10 @@ export const _globalThis = typeof globalThis === 'object' ? globalThis : global; /// packages/opentelemetry-core/src/platform/browser/globalThis.ts export const _globalThis: typeof globalThis = typeof globalThis === 'object' ? globalThis : - typeof self === 'object' ? self : - typeof window === 'object' ? window : - typeof global === 'object' ? global : - {} as typeof globalThis; + typeof self === 'object' ? self : + typeof window === 'object' ? window : + typeof global === 'object' ? global : + {} as typeof globalThis; ``` Even though the implementation may differ, the exported names must be aligned. diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 37252e92ccc..e0a1a1a5c3a 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -7,6 +7,21 @@ All notable changes to experimental packages in this project will be documented ### :boom: Breaking Change +* feat(exporter-*-otlp-*)!: rewrite exporter config logic for testability [#4971](https://github.com/open-telemetry/opentelemetry-js/pull/4971) @pichlermarc + * (user-facing) `getDefaultUrl` was intended for internal use has been removed from all exporters + * (user-facing) `getUrlFromConfig` was intended for internal use and has been removed from all exporters + * (user-facing) `hostname` was intended for internal use and has been removed from all exporters + * (user-facing) `url` was intended for internal use and has been removed from all exporters + * (user-facing) `timeoutMillis` was intended for internal use and has been removed from all exporters + * (user-facing) `onInit` was intended for internal use and has been removed from all exporters +* feat(otlp-exporter-base)!: do not export functions that are intended for internal use [#4971](https://github.com/open-telemetry/opentelemetry-js/pull/4971) @pichlermarc + * Drops the following functions and types that were intended for internal use from the package exports: + * `parseHeaders` + * `appendResourcePathToUrl` + * `appendResourcePathToUrlIfNeeded` + * `configureExporterTimeout` + * `invalidTimeout` + ### :rocket: (Enhancement) * feat(api-logs): Add delegating no-op logger provider [#4861](https://github.com/open-telemetry/opentelemetry-js/pull/4861) @hectorhdzg @@ -22,13 +37,6 @@ All notable changes to experimental packages in this project will be documented * fix(sdk-events): remove devDependencies to old `@opentelemetry/api-logs@0.52.0`, `@opentelemetry/api-events@0.52.0` packages [#5013](https://github.com/open-telemetry/opentelemetry-js/pull/5013) @pichlermarc * fix(sdk-logs): remove devDependencies to old `@opentelemetry/api-logs@0.52.0` [#5013](https://github.com/open-telemetry/opentelemetry-js/pull/5013) @pichlermarc * fix(sdk-logs): align LogRecord#setAttribute type with types from `@opentelemetry/api-logs@0.53.0` [#5013](https://github.com/open-telemetry/opentelemetry-js/pull/5013) @pichlermarc -* feat(exporter-*-otlp-*)!: rewrite exporter config logic for testability [#4971](https://github.com/open-telemetry/opentelemetry-js/pull/4971) @pichlermarc - * (user-facing) `getDefaultUrl` was intended for internal use has been removed from all exporters - * (user-facing) `getUrlFromConfig` was intended for internal use and has been removed from all exporters - * (user-facing) `hostname` was intended for internal use and has been removed from all exporters - * (user-facing) `url` was intended for internal use and has been removed from all exporters - * (user-facing) `timeoutMillis` was intended for internal use and has been removed from all exporters - * (user-facing) `onInit` was intended for internal use and has been removed from all exporters * fix(exporter-*-otlp-*): fixes a bug where signal-specific environment variables would not be applied and the trace-specific one was used instead [#4971](https://github.com/open-telemetry/opentelemetry-js/pull/4971) @pichlermarc * Fixes: * `OTEL_EXPORTER_OTLP_METRICS_COMPRESSION` @@ -39,14 +47,8 @@ All notable changes to experimental packages in this project will be documented * `OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY` * `OTEL_EXPORTER_OTLP_METRICS_INSECURE` * `OTEL_EXPORTER_OTLP_LOGS_INSECURE` -* feat(otlp-exporter-base)!: do not export functions that are intended for internal use [#4971](https://github.com/open-telemetry/opentelemetry-js/pull/4971) @pichlermarc - * Drops the following functions and types that were intended for internal use from the package exports: - * `parseHeaders` - * `appendResourcePathToUrl` - * `appendResourcePathToUrlIfNeeded` - * `configureExporterTimeout` - * `invalidTimeout` * fix(sdk-node): use warn instead of error on unknown OTEL_NODE_RESOURCE_DETECTORS values [#5034](https://github.com/open-telemetry/opentelemetry-js/pull/5034) +* fix(exporter-logs-otlp-proto): Use correct config type in Node constructor ### :books: (Refine Doc) diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts index 828a11cbc6d..d897208389e 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts @@ -15,8 +15,8 @@ */ import { - OTLPExporterConfigBase, OTLPExporterNodeBase, + OTLPExporterNodeConfigBase, } from '@opentelemetry/otlp-exporter-base'; import { IExportLogsServiceResponse, @@ -37,7 +37,7 @@ export class OTLPLogExporter extends OTLPExporterNodeBase implements LogRecordExporter { - constructor(config: OTLPExporterConfigBase = {}) { + constructor(config: OTLPExporterNodeConfigBase = {}) { super( config, ProtobufLogsSerializer, diff --git a/experimental/packages/otlp-grpc-exporter-base/test/configuration/otlp-grpc-configuration.test.ts b/experimental/packages/otlp-grpc-exporter-base/test/configuration/otlp-grpc-configuration.test.ts index 097612a18d2..4653e8be568 100644 --- a/experimental/packages/otlp-grpc-exporter-base/test/configuration/otlp-grpc-configuration.test.ts +++ b/experimental/packages/otlp-grpc-exporter-base/test/configuration/otlp-grpc-configuration.test.ts @@ -26,6 +26,7 @@ import { createSslCredentials, } from '../../src/grpc-exporter-transport'; import * as fs from 'fs'; +import { VERSION } from '../../src/version'; describe('mergeOtlpGrpcConfigurationWithDefaults', function () { describe('metadata', function () { @@ -56,7 +57,7 @@ describe('mergeOtlpGrpcConfigurationWithDefaults', function () { foo: 'foo-user', // does not use fallback if the user has set something bar: 'bar-fallback', // uses fallback if there is no value set baz: 'baz-user', // does not drop user-set metadata if there is no fallback for it - 'user-agent': 'OTel-OTLP-Exporter-JavaScript/0.53.0', + 'user-agent': 'OTel-OTLP-Exporter-JavaScript/' + VERSION, }); }); @@ -81,7 +82,7 @@ describe('mergeOtlpGrpcConfigurationWithDefaults', function () { ); assert.deepStrictEqual(config.metadata().getMap(), { - 'user-agent': 'OTel-OTLP-Exporter-JavaScript/0.53.0', + 'user-agent': 'OTel-OTLP-Exporter-JavaScript/' + VERSION, }); }); @@ -94,7 +95,7 @@ describe('mergeOtlpGrpcConfigurationWithDefaults', function () { ); assert.deepStrictEqual(config.metadata().getMap(), { - 'user-agent': 'OTel-OTLP-Exporter-JavaScript/0.53.0', + 'user-agent': 'OTel-OTLP-Exporter-JavaScript/' + VERSION, }); }); }); diff --git a/integration-tests/tracecontext-integration-test.sh b/integration-tests/tracecontext-integration-test.sh index 6096b9198f3..cf3d94c056a 100755 --- a/integration-tests/tracecontext-integration-test.sh +++ b/integration-tests/tracecontext-integration-test.sh @@ -8,6 +8,8 @@ mkdir -p target rm -rf ./target/trace-context git clone https://github.com/w3c/trace-context ./target/trace-context cd ./target/trace-context && git checkout $TRACECONTEXT_GIT_TAG && cd - +python3 -m venv ./.venv +source ./.venv/bin/activate pip3 install setuptools; pip3 install aiohttp; node ./integration-tests/propagation-validation-server/validation-server.js 1>&2 & diff --git a/package.json b/package.json index 5341baed1c6..dc11f3e0d25 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,9 @@ "docs": "typedoc --readme none && touch docs/.nojekyll", "docs-deploy": "gh-pages --dotfiles --dist docs", "docs:test": "linkinator docs --silent --retry && linkinator doc/*.md --skip http://localhost:3000 --skip http://localhost:9464 --silent --retry", - "lint": "lerna run lint", + "lint": "lerna run lint && npm run lint:markdown", "lint:changed": "lerna run --concurrency 1 --stream lint --since HEAD --exclude-dependents", - "lint:fix": "lerna run lint:fix", + "lint:fix": "lerna run lint:fix && npm run lint:markdown:fix", "lint:fix:changed": "lerna run --concurrency 1 --stream lint:fix --since HEAD --exclude-dependents", "lint:examples": "eslint --no-error-on-unmatched-pattern ./examples/**/*.js", "lint:examples:fix": "eslint --no-error-on-unmatched-pattern ./examples/**/*.js --fix", diff --git a/packages/opentelemetry-resources/src/detect-resources.ts b/packages/opentelemetry-resources/src/detect-resources.ts index 4fa477a4f81..0bfa13cac8b 100644 --- a/packages/opentelemetry-resources/src/detect-resources.ts +++ b/packages/opentelemetry-resources/src/detect-resources.ts @@ -70,6 +70,7 @@ export const detectResourcesSync = ( if (isPromiseLike(resourceOrPromise)) { const createPromise = async () => { const resolvedResource = await resourceOrPromise; + await resolvedResource.waitForAsyncAttributes?.(); return resolvedResource.attributes; }; resource = new Resource({}, createPromise()); diff --git a/packages/opentelemetry-resources/test/detect-resources.test.ts b/packages/opentelemetry-resources/test/detect-resources.test.ts index 0db97057db9..7c3b1a212c9 100644 --- a/packages/opentelemetry-resources/test/detect-resources.test.ts +++ b/packages/opentelemetry-resources/test/detect-resources.test.ts @@ -28,7 +28,10 @@ describe('detectResourcesSync', () => { it('handles resource detectors which return Promise', async () => { const detector: Detector = { async detect() { - return new Resource({ sync: 'fromsync' }); + return new Resource( + { sync: 'fromsync' }, + Promise.resolve().then(() => ({ async: 'fromasync' })) + ); }, }; const resource = detectResourcesSync({ @@ -38,6 +41,7 @@ describe('detectResourcesSync', () => { await resource.waitForAsyncAttributes?.(); assert.deepStrictEqual(resource.attributes, { sync: 'fromsync', + async: 'fromasync', }); });