diff --git a/.github/component_owners.yml b/.github/component_owners.yml index db6f78b1ca..a178953c10 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -3,9 +3,12 @@ components: detectors/node/opentelemetry-resource-detector-alibaba-cloud: - legendecas detectors/node/opentelemetry-resource-detector-aws: - - willarmiros - detectors/node/opentelemetry-resource-detector-docker: + - carolabadeer + detectors/node/opentelemetry-resource-detector-container: - abhee11 + detectors/node/opentelemetry-resource-detector-instana: + - basti1302 + - kirrg001 metapackages/auto-instrumentations-node: - obecny metapackages/auto-instrumentations-web: @@ -13,7 +16,7 @@ components: packages/opentelemetry-host-metrics: - legendecas packages/opentelemetry-id-generator-aws-xray: - - willarmiros + - carolabadeer packages/opentelemetry-redis-common: - haddasbronfman plugins/node/instrumentation-amqplib: @@ -25,9 +28,9 @@ components: plugins/node/instrumentation-tedious: - rauno56 plugins/node/opentelemetry-instrumentation-aws-lambda: - - willarmiros + - carolabadeer plugins/node/opentelemetry-instrumentation-aws-sdk: - - willarmiros + - carolabadeer - blumamir plugins/node/opentelemetry-instrumentation-generic-pool: - rauno56 @@ -71,7 +74,7 @@ components: plugins/web/opentelemetry-instrumentation-user-interaction: - obecny propagators/opentelemetry-propagator-aws-xray: - - willarmiros + - carolabadeer propagators/opentelemetry-propagator-instana: - basti1302 - kirrg001 diff --git a/.github/workflows/close-stale.yml b/.github/workflows/close-stale.yml index 4cf64aa320..2d098a0068 100644 --- a/.github/workflows/close-stale.yml +++ b/.github/workflows/close-stale.yml @@ -7,7 +7,7 @@ jobs: stale: runs-on: ubuntu-latest steps: - - uses: actions/stale@v7 + - uses: actions/stale@v8 with: days-before-stale: 60 days-before-close: 14 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 0b79e7feb9..6cd76a49ea 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -8,13 +8,6 @@ jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v3 - id: release - with: - command: manifest - token: ${{secrets.RELEASE_PR_TOKEN}} - default-branch: main - # The logic below handles the npm publication: - name: Checkout Repository uses: actions/checkout@v3 @@ -46,6 +39,13 @@ jobs: npm install npx lerna bootstrap --no-ci + - uses: google-github-actions/release-please-action@v3 + id: release + with: + command: manifest + token: ${{secrets.RELEASE_PR_TOKEN}} + default-branch: main + # Release Please has already incremented versions and published tags, so we just # need to publish all unpublished versions to npm here # See: https://github.com/lerna/lerna/tree/main/commands/publish#bump-from-package diff --git a/.husky/commit-msg b/.husky/commit-msg deleted file mode 100755 index e8511eaeaf..0000000000 --- a/.husky/commit-msg +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx --no-install commitlint --edit $1 diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 5ff9cfbba4..67946c3423 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1 +1 @@ -{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.3","detectors/node/opentelemetry-resource-detector-aws":"1.2.1","detectors/node/opentelemetry-resource-detector-container":"0.2.1","detectors/node/opentelemetry-resource-detector-gcp":"0.27.4","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.4.0","metapackages/auto-instrumentations-node":"0.36.0","metapackages/auto-instrumentations-web":"0.31.0","packages/opentelemetry-host-metrics":"0.31.0","packages/opentelemetry-id-generator-aws-xray":"1.1.1","packages/opentelemetry-propagation-utils":"0.29.1","packages/opentelemetry-redis-common":"0.34.0","packages/opentelemetry-test-utils":"0.33.0","plugins/node/instrumentation-amqplib":"0.32.0","plugins/node/instrumentation-dataloader":"0.3.0","plugins/node/instrumentation-fs":"0.6.0","plugins/node/instrumentation-lru-memoizer":"0.32.0","plugins/node/instrumentation-mongoose":"0.32.0","plugins/node/instrumentation-socket.io":"0.33.0","plugins/node/instrumentation-tedious":"0.5.0","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.34.0","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.33.0","plugins/node/opentelemetry-instrumentation-bunyan":"0.31.0","plugins/node/opentelemetry-instrumentation-cassandra":"0.32.0","plugins/node/opentelemetry-instrumentation-connect":"0.31.0","plugins/node/opentelemetry-instrumentation-dns":"0.31.0","plugins/node/opentelemetry-instrumentation-express":"0.32.0","plugins/node/opentelemetry-instrumentation-fastify":"0.31.0","plugins/node/opentelemetry-instrumentation-generic-pool":"0.31.0","plugins/node/opentelemetry-instrumentation-graphql":"0.33.0","plugins/node/opentelemetry-instrumentation-hapi":"0.31.0","plugins/node/opentelemetry-instrumentation-ioredis":"0.33.1","plugins/node/opentelemetry-instrumentation-knex":"0.31.0","plugins/node/opentelemetry-instrumentation-koa":"0.34.0","plugins/node/opentelemetry-instrumentation-memcached":"0.31.0","plugins/node/opentelemetry-instrumentation-mongodb":"0.34.0","plugins/node/opentelemetry-instrumentation-mysql":"0.32.0","plugins/node/opentelemetry-instrumentation-mysql2":"0.33.0","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.32.0","plugins/node/opentelemetry-instrumentation-net":"0.31.0","plugins/node/opentelemetry-instrumentation-pg":"0.34.0","plugins/node/opentelemetry-instrumentation-pino":"0.33.0","plugins/node/opentelemetry-instrumentation-redis":"0.34.1","plugins/node/opentelemetry-instrumentation-redis-4":"0.34.1","plugins/node/opentelemetry-instrumentation-restify":"0.32.0","plugins/node/opentelemetry-instrumentation-router":"0.32.0","plugins/node/opentelemetry-instrumentation-winston":"0.31.0","plugins/web/opentelemetry-instrumentation-document-load":"0.31.0","plugins/web/opentelemetry-instrumentation-long-task":"0.32.0","plugins/web/opentelemetry-instrumentation-user-interaction":"0.32.0","plugins/web/opentelemetry-plugin-react-load":"0.28.1","propagators/opentelemetry-propagator-aws-xray":"1.1.1","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.1","propagators/opentelemetry-propagator-ot-trace":"0.26.2"} +{"detectors/node/opentelemetry-resource-detector-alibaba-cloud":"0.27.5","detectors/node/opentelemetry-resource-detector-aws":"1.2.3","detectors/node/opentelemetry-resource-detector-container":"0.2.3","detectors/node/opentelemetry-resource-detector-gcp":"0.28.1","detectors/node/opentelemetry-resource-detector-github":"0.27.0","detectors/node/opentelemetry-resource-detector-instana":"0.4.2","metapackages/auto-instrumentations-node":"0.36.6","metapackages/auto-instrumentations-web":"0.32.1","packages/opentelemetry-host-metrics":"0.32.1","packages/opentelemetry-id-generator-aws-xray":"1.1.1","packages/opentelemetry-propagation-utils":"0.29.3","packages/opentelemetry-redis-common":"0.35.0","packages/opentelemetry-test-utils":"0.33.2","plugins/node/instrumentation-amqplib":"0.32.3","plugins/node/instrumentation-dataloader":"0.4.1","plugins/node/instrumentation-fs":"0.7.2","plugins/node/instrumentation-lru-memoizer":"0.32.2","plugins/node/instrumentation-mongoose":"0.32.2","plugins/node/instrumentation-socket.io":"0.33.2","plugins/node/instrumentation-tedious":"0.5.2","plugins/node/opentelemetry-instrumentation-aws-lambda":"0.35.1","plugins/node/opentelemetry-instrumentation-aws-sdk":"0.34.1","plugins/node/opentelemetry-instrumentation-bunyan":"0.31.2","plugins/node/opentelemetry-instrumentation-cassandra":"0.32.2","plugins/node/opentelemetry-instrumentation-connect":"0.31.2","plugins/node/opentelemetry-instrumentation-dns":"0.31.3","plugins/node/opentelemetry-instrumentation-express":"0.32.2","plugins/node/opentelemetry-instrumentation-fastify":"0.31.2","plugins/node/opentelemetry-instrumentation-generic-pool":"0.31.2","plugins/node/opentelemetry-instrumentation-graphql":"0.34.1","plugins/node/opentelemetry-instrumentation-hapi":"0.31.2","plugins/node/opentelemetry-instrumentation-ioredis":"0.34.1","plugins/node/opentelemetry-instrumentation-knex":"0.31.2","plugins/node/opentelemetry-instrumentation-koa":"0.34.4","plugins/node/opentelemetry-instrumentation-memcached":"0.31.2","plugins/node/opentelemetry-instrumentation-mongodb":"0.34.2","plugins/node/opentelemetry-instrumentation-mysql":"0.33.1","plugins/node/opentelemetry-instrumentation-mysql2":"0.33.2","plugins/node/opentelemetry-instrumentation-nestjs-core":"0.32.3","plugins/node/opentelemetry-instrumentation-net":"0.31.2","plugins/node/opentelemetry-instrumentation-pg":"0.35.1","plugins/node/opentelemetry-instrumentation-pino":"0.33.2","plugins/node/opentelemetry-instrumentation-redis":"0.34.5","plugins/node/opentelemetry-instrumentation-redis-4":"0.34.4","plugins/node/opentelemetry-instrumentation-restify":"0.32.2","plugins/node/opentelemetry-instrumentation-router":"0.32.2","plugins/node/opentelemetry-instrumentation-winston":"0.31.2","plugins/web/opentelemetry-instrumentation-document-load":"0.32.1","plugins/web/opentelemetry-instrumentation-long-task":"0.32.3","plugins/web/opentelemetry-instrumentation-user-interaction":"0.32.2","plugins/web/opentelemetry-plugin-react-load":"0.28.1","propagators/opentelemetry-propagator-aws-xray":"1.2.0","propagators/opentelemetry-propagator-grpc-census-binary":"0.26.0","propagators/opentelemetry-propagator-instana":"0.2.1","propagators/opentelemetry-propagator-ot-trace":"0.26.2"} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 692d82b780..3c2b7513bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,27 @@ We'd love your help! +- [Report a bug or requesting feature](#report-a-bug-or-requesting-feature) +- [How to contribute](#how-to-contribute) + - [Before you start](#before-you-start) + - [Conventional commit](#conventional-commit) + - [Fork](#fork) + - [Running the tests](#running-the-tests) + - [Generating API documentation](#generating-api-documentation) + - [Generating CHANGELOG documentation](#generating-changelog-documentation) + - [Benchmarks](#benchmarks) +- [Component Ownership](#component-ownership) +- [Component Lifecycle](#component-lifecycle) + - [Unreleased](#unreleased) + - [Experimental](#experimental) + - [Beta](#beta) + - [Stable](#stable) + - [Unmaintained](#unmaintained) + - [Deprecated](#deprecated) +- [Contributing Vendor Components](#contributing-vendor-components) + - [Adding a New Vendor Component](#adding-a-new-vendor-component) + - [Removing Vendor Components](#removing-vendor-components) + ## Report a bug or requesting feature Reporting bugs is an important contribution. Please make sure to include: @@ -80,6 +101,67 @@ When two or more approaches must be compared, please write a benchmark in the be - `npm run bench` to run your benchmark. +## Component Ownership + +This repository contains many components which are maintained by more than the typical set of JS maintainers and approvers. +Each component in this repository SHOULD have a component owner who is responsible for maintaining it. +The README.md for each component SHOULD contain its owner, but the source of truth for component ownership is in [.github/component_owners.yml](.github/component_owners.yml). +Component owners are generally given authority to make decisions relating to implementation and feature requests for their components, provided they follow the best practices set out by the maintainers. +Component owners MUST do their best to maintain a high level of quality, security, performance, and specification compliance within their components. +Maintainers may override the decisions of component owners, but should only do so when they feel one or more of these traits is compromised. + +## Component Lifecycle + +This repository contains many components in various stages of the component lifecycle. +A component may be **unreleased**, **experimental**, **beta**, **stable**, **unmaintained**, or **deprecated**; see the below definitions for each stability level. +With the exception of the stable status, it is up to each individual [component owner](#component-ownership) to determine the status of a component. +A component may only be marked stable with the approval of a member of @open-telemetry/javascript-maintainers; see the definition of stable below for more details. + +### Unreleased + +Unreleased components are in active development and have not yet been released to NPM. +Unreleased packages should have the property `private` in their `package.json` set to `true`. + +### Experimental + +Experimental packages are in active development. +They should be considered unstable and potentially unsuitable for production use. +They are released to NPM for developers and early adopters. +Experimental components MUST have their major version set to `0`. +If a component does not have an explicit status in its README.md file, it should be considered to be experimental. + +### Beta + +Beta packages are not yet considered stable, but an effort should be made to preserve stability across versions if possible. +They may be ready for production use, but users should understand that their APIs or the telemetry they output MAY change if required. +Beta components MUST have their major version set to `0`. + +### Stable + +This is the highest level of quality and maintainership guarantee provided in this repository. +Stable packages should be considered stable and ready for production use. +In order for a package to be marked stable, it must meet the following requirements: + +- It MUST have a component owner that the JS maintainers feel confident will be responsive to issues and pull requests and will fulfill their responsibility competently. + If a component owner is not responsive to issues and PRs, the maintainers may assign a new owner or change the status of the component to unmaintained. +- All relevant specification relating to the component MUST be stable. For example, telemetry emitted by an instrumentation library should rely on a stable semantic convention. +- It MUST be reviewed and approved by a member of @open-telemetry/javascript-maintainers. + +Stable components MUST have their major version set to `1` or greater. + +### Unmaintained + +A component which does not have an assigned component owner, or has a component owner who has been unresponsive to issues and pull requests may be marked as unmaintained. +Unmaintained components may continue to work and receive updates and fixes from contributors, but may not receive immediate attention if there is a problem or feature request. +A component which is unmaintained may be deprecated if there is a problem that is not fixed in a timely manner. + +### Deprecated + +Deprecated components are no longer maintained and there are not currently plans to maintain them. +They may not work and there are no guarantees for fixes or new features. +Their source files may be deleted from the repository. +Any packages released from their source will be marked as deprecated in NPM. + ## Contributing Vendor Components This repo is generally meant for hosting components that work with popular open-source frameworks and tools. However, it is also possible to contribute components specific to a 3rd party vendor in this repo. diff --git a/README.md b/README.md index 6168d94a79..06cf359193 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ This project includes: **Resource Detectors**: OpenTelemetry can collect resource attributes of the entity that producing telemetry. For example, a process producing telemetry that is running in a container on Kubernetes has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name. All three of these attributes can be included in the `Resource`. +## Stability levels + +Stability level for components in this repository follow the definitions in [CONTRIBUTING.md](./CONTRIBUTING.md). + ## Supported Runtimes Packages in this repository have a variable range of support for Node.JS and browser versions which for each package depend on diff --git a/archive/opentelemetry-browser-extension-autoinjection/package.json b/archive/opentelemetry-browser-extension-autoinjection/package.json index 613cb2e2de..1efd629ff2 100644 --- a/archive/opentelemetry-browser-extension-autoinjection/package.json +++ b/archive/opentelemetry-browser-extension-autoinjection/package.json @@ -44,7 +44,6 @@ "eslint-plugin-header": "3.1.1", "eslint-plugin-import": "2.25.4", "eslint-plugin-json5": "0.1.4", - "gts": "3.1.0", "html-webpack-plugin": "5.3.2", "jimp": "0.16.1", "jsdom": "15.2.1", @@ -52,12 +51,12 @@ "null-loader": "4.0.1", "nyc": "15.1.0", "responsive-loader": "2.3.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "sinon-chrome": "3.0.1", "ts-loader": "9.2.5", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0" @@ -70,10 +69,10 @@ "@opentelemetry/core": "^1.8.0", "@opentelemetry/exporter-trace-otlp-http": "^0.34.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.35.1", "@opentelemetry/instrumentation-document-load": "^0.29.0", - "@opentelemetry/instrumentation-fetch": "^0.34.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.34.0", + "@opentelemetry/instrumentation-fetch": "^0.35.1", + "@opentelemetry/instrumentation-xml-http-request": "^0.35.1", "@opentelemetry/resources": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-web": "^1.8.0", diff --git a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/CHANGELOG.md index 0e2b0b8b12..875df530e8 100644 --- a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/CHANGELOG.md @@ -18,6 +18,18 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.32.0 to ^0.33.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + ## [0.27.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-alibaba-cloud-v0.26.2...resource-detector-alibaba-cloud-v0.27.0) (2022-05-14) diff --git a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json index 2c7a10b053..960f3c28ac 100644 --- a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json +++ b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resource-detector-alibaba-cloud", - "version": "0.27.3", + "version": "0.27.5", "description": "OpenTelemetry resource detector for Alibaba Cloud", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,18 +43,17 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nock": "12.0.3", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/detectors/node/opentelemetry-resource-detector-aws/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-aws/CHANGELOG.md index 54d32e45f2..1ee8654d58 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-aws/CHANGELOG.md @@ -18,6 +18,18 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.32.0 to ^0.33.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + ## [1.2.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-aws-v1.1.2...resource-detector-aws-v1.2.0) (2022-11-02) diff --git a/detectors/node/opentelemetry-resource-detector-aws/README.md b/detectors/node/opentelemetry-resource-detector-aws/README.md index 7522b32ae5..690c25700d 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/README.md +++ b/detectors/node/opentelemetry-resource-detector-aws/README.md @@ -3,11 +3,15 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @willarmiros +[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @carolabadeer Resource detector for Amazon Web Services. -Compatible with OpenTelemetry JS API and SDK `1.0+`. +## Status + +| Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility | +| ----------------------------------------- | ----------------------------------------------------- | --------------------- | +| [Stable](../../../CONTRIBUTING.md#stable) | @carolabadeer | API 1.0+
SDK 1.0+ | ## Installation diff --git a/detectors/node/opentelemetry-resource-detector-aws/package.json b/detectors/node/opentelemetry-resource-detector-aws/package.json index 11e334c6e8..f99a6d42c6 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/package.json +++ b/detectors/node/opentelemetry-resource-detector-aws/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resource-detector-aws", - "version": "1.2.1", + "version": "1.2.3", "description": "OpenTelemetry SDK resource detector for AWS", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -42,18 +42,17 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nock": "12.0.3", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetector.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetector.ts index 8f9964d2e5..44028c6ff6 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetector.ts @@ -80,7 +80,7 @@ export class AwsBeanstalkDetector implements Detector { [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: parsedData.deployment_id, }); - } catch (e) { + } catch (e: any) { diag.debug(`AwsBeanstalkDetector failed: ${e.message}`); return Resource.empty(); } diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetector.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetector.ts index 196e2a1cc0..d85deb558e 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetector.ts @@ -180,7 +180,7 @@ export class AwsEksDetector implements Detector { return str.substring(str.length - this.CONTAINER_ID_LENGTH); } } - } catch (e) { + } catch (e: any) { diag.warn(`AwsEksDetector failed to read container ID: ${e.message}`); } return undefined; diff --git a/detectors/node/opentelemetry-resource-detector-container/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-container/CHANGELOG.md index 771a433cf7..ba00ad3ac9 100644 --- a/detectors/node/opentelemetry-resource-detector-container/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-container/CHANGELOG.md @@ -12,6 +12,18 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.32.0 to ^0.33.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + ## [0.2.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-container-v0.1.2...resource-detector-container-v0.2.0) (2022-11-02) diff --git a/detectors/node/opentelemetry-resource-detector-container/package.json b/detectors/node/opentelemetry-resource-detector-container/package.json index 78689d8f37..c64a07b822 100644 --- a/detectors/node/opentelemetry-resource-detector-container/package.json +++ b/detectors/node/opentelemetry-resource-detector-container/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resource-detector-container", - "version": "0.2.1", + "version": "0.2.3", "description": "Opentelemetry resource detector to get container resource attributes", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -36,19 +36,18 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/mocha": "8.2.3", "@types/node": "^18.0.0", "@types/sinon": "10.0.2", "eslint-plugin-header": "^3.1.1", - "gts": "^3.1.0", "mocha": "7.2.0", "nock": "12.0.3", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md index c412d091e7..5e228b0e0f 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md @@ -18,6 +18,25 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.32.0 to ^0.33.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.28.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-gcp-v0.27.5...resource-detector-gcp-v0.28.0) (2023-02-08) + + +### Features + +* **detector-gcp:** collect hostname resource attribute from GCP Metadata API ([#1364](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1364)) ([33c57cc](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/33c57cc84a8b87ad3a58dde2014738deab1c375b)) + ## [0.27.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-gcp-v0.27.2...resource-detector-gcp-v0.27.3) (2022-11-02) diff --git a/detectors/node/opentelemetry-resource-detector-gcp/package.json b/detectors/node/opentelemetry-resource-detector-gcp/package.json index ee967ff069..fc7c6460a7 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/package.json +++ b/detectors/node/opentelemetry-resource-detector-gcp/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resource-detector-gcp", - "version": "0.27.4", + "version": "0.28.1", "description": "OpenTelemetry SDK resource detector for GCP", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -42,17 +42,16 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/semver": "7.3.8", - "gts": "3.1.0", "mocha": "7.2.0", "nock": "12.0.3", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" @@ -61,8 +60,7 @@ "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "gcp-metadata": "^5.0.0", - "semver": "7.3.5" + "gcp-metadata": "^5.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme" } diff --git a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts index 1d4139d70c..206bb4d1d3 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import * as semver from 'semver'; import * as gcpMetadata from 'gcp-metadata'; import { diag } from '@opentelemetry/api'; import { @@ -44,24 +43,24 @@ class GcpDetector implements Detector { * @param config The resource detection config */ async detect(_config?: ResourceDetectionConfig): Promise { - if ( - !semver.satisfies(process.version, '>=10') || - !(await gcpMetadata.isAvailable()) - ) { + if (!(await gcpMetadata.isAvailable())) { diag.debug('GcpDetector failed: GCP Metadata unavailable.'); return Resource.empty(); } - const [projectId, instanceId, zoneId, clusterName] = await Promise.all([ - this._getProjectId(), - this._getInstanceId(), - this._getZone(), - this._getClusterName(), - ]); + const [projectId, instanceId, zoneId, clusterName, hostname] = + await Promise.all([ + this._getProjectId(), + this._getInstanceId(), + this._getZone(), + this._getClusterName(), + this._getHostname(), + ]); const attributes: ResourceAttributes = {}; attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID] = projectId; attributes[SemanticResourceAttributes.HOST_ID] = instanceId; + attributes[SemanticResourceAttributes.HOST_NAME] = hostname; attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE] = zoneId; attributes[SemanticResourceAttributes.CLOUD_PROVIDER] = CloudProviderValues.GCP; @@ -125,6 +124,15 @@ class GcpDetector implements Detector { return ''; } } + + /** Gets hostname from GCP instance metadata. */ + private async _getHostname(): Promise { + try { + return await gcpMetadata.instance('hostname'); + } catch { + return ''; + } + } } export const gcpDetector = new GcpDetector(); diff --git a/detectors/node/opentelemetry-resource-detector-gcp/test/detectors/GcpDetector.test.ts b/detectors/node/opentelemetry-resource-detector-gcp/test/detectors/GcpDetector.test.ts index ee1b59b4e6..85f40e413f 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/test/detectors/GcpDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-gcp/test/detectors/GcpDetector.test.ts @@ -23,7 +23,6 @@ import { resetIsAvailableCache, } from 'gcp-metadata'; import * as nock from 'nock'; -import * as semver from 'semver'; import { gcpDetector } from '../../src'; import { assertCloudResource, @@ -42,127 +41,134 @@ const INSTANCE_ID_PATH = BASE_PATH + '/instance/id'; const PROJECT_ID_PATH = BASE_PATH + '/project/project-id'; const ZONE_PATH = BASE_PATH + '/instance/zone'; const CLUSTER_NAME_PATH = BASE_PATH + '/instance/attributes/cluster-name'; +const HOSTNAME_PATH = BASE_PATH + '/instance/hostname'; -(semver.satisfies(process.version, '>=10') ? describe : describe.skip)( - 'gcpDetector', - () => { - describe('.detect', () => { - before(() => { - nock.disableNetConnect(); - }); +describe('gcpDetector', () => { + describe('.detect', () => { + before(() => { + nock.disableNetConnect(); + }); - after(() => { - nock.enableNetConnect(); - delete process.env.KUBERNETES_SERVICE_HOST; - delete process.env.NAMESPACE; - delete process.env.CONTAINER_NAME; - delete process.env.HOSTNAME; - }); + after(() => { + nock.enableNetConnect(); + delete process.env.KUBERNETES_SERVICE_HOST; + delete process.env.NAMESPACE; + delete process.env.CONTAINER_NAME; + delete process.env.HOSTNAME; + }); - beforeEach(() => { - resetIsAvailableCache(); - nock.cleanAll(); - delete process.env.KUBERNETES_SERVICE_HOST; - delete process.env.NAMESPACE; - delete process.env.CONTAINER_NAME; - delete process.env.HOSTNAME; - }); + beforeEach(() => { + resetIsAvailableCache(); + nock.cleanAll(); + delete process.env.KUBERNETES_SERVICE_HOST; + delete process.env.NAMESPACE; + delete process.env.CONTAINER_NAME; + delete process.env.HOSTNAME; + }); - it('should return resource with GCP metadata', async () => { - const scope = nock(HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS) - .get(INSTANCE_ID_PATH) - // This number is too large to be safely represented by a JS number - // See https://github.com/googleapis/gcp-metadata/tree/fc2f0778138b36285643b2f716c485bf9614611f#take-care-with-large-number-valued-properties - .reply(200, () => '4520031799277581759', HEADERS) - .get(PROJECT_ID_PATH) - .reply(200, () => 'my-project-id', HEADERS) - .get(ZONE_PATH) - .reply(200, () => 'project/zone/my-zone', HEADERS) - .get(CLUSTER_NAME_PATH) - .reply(404); - const secondaryScope = nock(SECONDARY_HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS); - const resource: Resource = await gcpDetector.detect(); - secondaryScope.done(); - scope.done(); + it('should return resource with GCP metadata', async () => { + const scope = nock(HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS) + .get(INSTANCE_ID_PATH) + // This number is too large to be safely represented by a JS number + // See https://github.com/googleapis/gcp-metadata/tree/fc2f0778138b36285643b2f716c485bf9614611f#take-care-with-large-number-valued-properties + .reply(200, () => '4520031799277581759', HEADERS) + .get(PROJECT_ID_PATH) + .reply(200, () => 'my-project-id', HEADERS) + .get(ZONE_PATH) + .reply(200, () => 'project/zone/my-zone', HEADERS) + .get(CLUSTER_NAME_PATH) + .reply(404) + .get(HOSTNAME_PATH) + .reply(200, () => 'dev.my-project.local', HEADERS); + const secondaryScope = nock(SECONDARY_HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS); + const resource: Resource = await gcpDetector.detect(); + secondaryScope.done(); + scope.done(); - assertCloudResource(resource, { - provider: 'gcp', - accountId: 'my-project-id', - zone: 'my-zone', - }); - assertHostResource(resource, { id: '4520031799277581759' }); + assertCloudResource(resource, { + provider: 'gcp', + accountId: 'my-project-id', + zone: 'my-zone', }); + assertHostResource(resource, { + id: '4520031799277581759', + name: 'dev.my-project.local', + }); + }); - it('should populate K8s attributes when KUBERNETES_SERVICE_HOST is set', async () => { - process.env.KUBERNETES_SERVICE_HOST = 'my-host'; - process.env.NAMESPACE = 'my-namespace'; - process.env.HOSTNAME = 'my-hostname'; - process.env.CONTAINER_NAME = 'my-container-name'; - const scope = nock(HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS) - .get(INSTANCE_ID_PATH) - .reply(200, () => '4520031799277581759', HEADERS) - .get(CLUSTER_NAME_PATH) - .reply(200, () => 'my-cluster', HEADERS) - .get(PROJECT_ID_PATH) - .reply(200, () => 'my-project-id', HEADERS) - .get(ZONE_PATH) - .reply(200, () => 'project/zone/my-zone', HEADERS); - const secondaryScope = nock(SECONDARY_HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS); - const resource = await gcpDetector.detect(); - secondaryScope.done(); - scope.done(); + it('should populate K8s attributes when KUBERNETES_SERVICE_HOST is set', async () => { + process.env.KUBERNETES_SERVICE_HOST = 'my-host'; + process.env.NAMESPACE = 'my-namespace'; + process.env.HOSTNAME = 'my-hostname'; + process.env.CONTAINER_NAME = 'my-container-name'; + const scope = nock(HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS) + .get(INSTANCE_ID_PATH) + .reply(200, () => '4520031799277581759', HEADERS) + .get(CLUSTER_NAME_PATH) + .reply(200, () => 'my-cluster', HEADERS) + .get(PROJECT_ID_PATH) + .reply(200, () => 'my-project-id', HEADERS) + .get(ZONE_PATH) + .reply(200, () => 'project/zone/my-zone', HEADERS) + .get(HOSTNAME_PATH) + .reply(200, () => 'dev.my-project.local', HEADERS); + const secondaryScope = nock(SECONDARY_HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS); + const resource = await gcpDetector.detect(); + secondaryScope.done(); + scope.done(); - assertCloudResource(resource, { - provider: 'gcp', - accountId: 'my-project-id', - zone: 'my-zone', - }); - assertK8sResource(resource, { - clusterName: 'my-cluster', - podName: 'my-hostname', - namespaceName: 'my-namespace', - }); - assertContainerResource(resource, { name: 'my-container-name' }); + assertCloudResource(resource, { + provider: 'gcp', + accountId: 'my-project-id', + zone: 'my-zone', + }); + assertK8sResource(resource, { + clusterName: 'my-cluster', + podName: 'my-hostname', + namespaceName: 'my-namespace', }); + assertContainerResource(resource, { name: 'my-container-name' }); + }); - it('should return resource and empty data for non-available metadata attributes', async () => { - const scope = nock(HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS) - .get(PROJECT_ID_PATH) - .reply(200, () => 'my-project-id', HEADERS) - .get(ZONE_PATH) - .reply(413) - .get(INSTANCE_ID_PATH) - .reply(400, undefined, HEADERS) - .get(CLUSTER_NAME_PATH) - .reply(413); - const secondaryScope = nock(SECONDARY_HOST_ADDRESS) - .get(INSTANCE_PATH) - .reply(200, {}, HEADERS); - const resource = await gcpDetector.detect(); - secondaryScope.done(); - scope.done(); + it('should return resource and empty data for non-available metadata attributes', async () => { + const scope = nock(HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS) + .get(PROJECT_ID_PATH) + .reply(200, () => 'my-project-id', HEADERS) + .get(ZONE_PATH) + .reply(413) + .get(INSTANCE_ID_PATH) + .reply(400, undefined, HEADERS) + .get(CLUSTER_NAME_PATH) + .reply(413) + .get(HOSTNAME_PATH) + .reply(400, undefined, HEADERS); + const secondaryScope = nock(SECONDARY_HOST_ADDRESS) + .get(INSTANCE_PATH) + .reply(200, {}, HEADERS); + const resource = await gcpDetector.detect(); + secondaryScope.done(); + scope.done(); - assertCloudResource(resource, { - provider: 'gcp', - accountId: 'my-project-id', - zone: '', - }); + assertCloudResource(resource, { + provider: 'gcp', + accountId: 'my-project-id', + zone: '', }); + }); - it('returns empty resource if not detected', async () => { - const resource = await gcpDetector.detect(); - assertEmptyResource(resource); - }); + it('returns empty resource if not detected', async () => { + const resource = await gcpDetector.detect(); + assertEmptyResource(resource); }); - } -); + }); +}); diff --git a/detectors/node/opentelemetry-resource-detector-github/package.json b/detectors/node/opentelemetry-resource-detector-github/package.json index e0227a18d5..68516384f2 100644 --- a/detectors/node/opentelemetry-resource-detector-github/package.json +++ b/detectors/node/opentelemetry-resource-detector-github/package.json @@ -49,13 +49,12 @@ "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/resources": "^1.0.0" diff --git a/detectors/node/opentelemetry-resource-detector-instana/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-instana/CHANGELOG.md index 750990d5a1..7b8c167dfd 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-instana/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.4.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-instana-v0.4.1...resource-detector-instana-v0.4.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.4.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-instana-v0.4.0...resource-detector-instana-v0.4.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.4.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-instana-v0.3.0...resource-detector-instana-v0.4.0) (2022-11-16) diff --git a/detectors/node/opentelemetry-resource-detector-instana/README.md b/detectors/node/opentelemetry-resource-detector-instana/README.md index 531bf044f2..fef7b05bbd 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/README.md +++ b/detectors/node/opentelemetry-resource-detector-instana/README.md @@ -35,16 +35,11 @@ const globalResource = new Resource({ }); const sdk = new NodeSDK({ - autoDetectResources: false, resourceDetectors: [envDetector, processDetector, instanaAgentDetector], resource: globalResource, }); -(async () => { - await sdk.detectResources(); - - await sdk.start(); -}()); +sdk.start() ``` ## Useful links diff --git a/detectors/node/opentelemetry-resource-detector-instana/package.json b/detectors/node/opentelemetry-resource-detector-instana/package.json index df945306f3..f9275e4488 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/package.json +++ b/detectors/node/opentelemetry-resource-detector-instana/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/resource-detector-instana", - "version": "0.4.0", + "version": "0.4.2", "description": "OpenTelemetry SDK resource detector for Instana", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -40,18 +40,17 @@ }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", - "@opentelemetry/sdk-node": "^0.34.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", + "@opentelemetry/sdk-node": "^0.38.0", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/semver": "7.3.8", "mocha": "7.2.0", "nock": "12.0.3", - "gts": "3.1.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/resources": "^1.0.0", diff --git a/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts b/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts index 64968ad0fb..e036523240 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Detector, Resource } from '@opentelemetry/resources'; +import { Detector, Resource, IResource } from '@opentelemetry/resources'; import { diag } from '@opentelemetry/api'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import * as http from 'http'; @@ -22,7 +22,7 @@ class InstanaAgentDetector implements Detector { readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost'; readonly INSTANA_AGENT_DEFAULT_PORT = 42699; - async detect(): Promise { + async detect(): Promise { const host = process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST; const port = Number( @@ -112,7 +112,6 @@ class InstanaAgentDetector implements Detector { try { const data = JSON.parse(rawData); - if (data.pid && data.agentUuid) { return resolve(data); } diff --git a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts index 99f4deb336..ee8124f3cc 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts +++ b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorIntegrationTest.test.ts @@ -25,6 +25,11 @@ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' import { NodeSDK } from '@opentelemetry/sdk-node'; import { instanaAgentDetector } from '../src'; +const delay = (ms: number) => + new Promise(resolve => { + setTimeout(resolve, ms); + }); + describe('[Integration] instanaAgentDetector', () => { beforeEach(() => { nock.disableNetConnect(); @@ -36,7 +41,7 @@ describe('[Integration] instanaAgentDetector', () => { nock.cleanAll(); }); - it('should return merged resource', async () => { + it('#1 should return merged resource', async () => { const mockedReply = { pid: 123, agentUuid: '14:7d:da:ff:fe:e4:08:d5', @@ -53,16 +58,54 @@ describe('[Integration] instanaAgentDetector', () => { }); const sdk = new NodeSDK({ - autoDetectResources: false, resourceDetectors: [envDetector, processDetector, instanaAgentDetector], resource: globalResource, }); - // attributes are automatically merged! - await sdk.detectResources(); + sdk.start(); + + const resource = sdk['_resource']; + // await sdk.detectResources(); [< @opentelemetry/sdk-node@0.37.0] + // await resource.waitForAsyncAttributes?.(); [>= @opentelemetry/sdk-node@0.37.0] + await resource.waitForAsyncAttributes?.(); + + assert.equal(resource.attributes['process.pid'], 123); + assert.equal(resource.attributes['process.runtime.name'], 'nodejs'); + assert.equal(resource.attributes['service.name'], 'TestService'); + assert.equal( + resource.attributes['service.instance.id'], + '14:7d:da:ff:fe:e4:08:d5' + ); + + scope.done(); + }); + + it('#2 should return merged resource', async () => { + const mockedReply = { + pid: 123, + agentUuid: '14:7d:da:ff:fe:e4:08:d5', + }; + + const scope = nock('http://localhost:42699') + .persist() + .put('/com.instana.plugin.nodejs.discovery') + .reply(200, () => mockedReply); + + const serviceName = 'TestService'; + const globalResource = new Resource({ + [SemanticResourceAttributes.SERVICE_NAME]: serviceName, + }); + + const sdk = new NodeSDK({ + resourceDetectors: [envDetector, processDetector, instanaAgentDetector], + resource: globalResource, + }); + sdk.start(); const resource = sdk['_resource']; + await delay(500); + assert.equal(resource.attributes['process.pid'], 123); assert.equal(resource.attributes['process.runtime.name'], 'nodejs'); assert.equal(resource.attributes['service.name'], 'TestService'); diff --git a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorUnitTest.test.ts b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorUnitTest.test.ts index d95c4f85c5..6799d96013 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorUnitTest.test.ts +++ b/detectors/node/opentelemetry-resource-detector-instana/test/InstanaAgentDetectorUnitTest.test.ts @@ -138,7 +138,7 @@ describe('[UNIT] instanaAgentDetector', () => { try { await instanaAgentDetector.detect(); assert.ok(false, 'Expected to throw'); - } catch (err) { + } catch (err: any) { assert.equal(err.code, 'ECONNREFUSED'); } }); diff --git a/eslint.config.js b/eslint.config.js index 1b57d26fd1..2ebc6dc369 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,50 +2,64 @@ module.exports = { plugins: [ "@typescript-eslint", "header", - "import" - ], - extends: [ - "./node_modules/gts", + "node", + "prettier" ], + extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], parser: "@typescript-eslint/parser", parserOptions: { - "project": "./tsconfig.json" + "project": "./tsconfig.json" }, rules: { - "quotes": [2, "single", { "avoidEscape": true }], - "@typescript-eslint/no-this-alias": "off", + "quotes": ["error", "single", { "avoidEscape": true }], "eqeqeq": "off", "prefer-rest-params": "off", - "@typescript-eslint/naming-convention": [ - "error", - { - "selector": "memberLike", - "modifiers": ["private", "protected"], - "format": ["camelCase"], - "leadingUnderscore": "require" - } - ], - "@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }], - "arrow-parens": ["error", "as-needed"], - "prettier/prettier": ["error", { "singleQuote": true, "arrowParens": "avoid" }], + "no-shadow": "off", "node/no-deprecated-api": ["warn"], - "header/header": [2, "block", [{ - pattern: / \* Copyright The OpenTelemetry Authors[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the \"License\"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an \"AS IS\" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\./gm, - template: + "header/header": ["error", "block", [{ + pattern: / \* Copyright The OpenTelemetry Authors[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the \"License\"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an \"AS IS\" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\./gm, + template: `\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n ` - }]], - "import/no-extraneous-dependencies": ["error", { devDependencies: ["test/**/*.ts"] }], + }]] }, overrides: [ { - "files": ["test/**/*.ts"], - "rules": { + files: ['*.ts'], + rules: { + "@typescript-eslint/no-this-alias": "off", + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "memberLike", + "modifiers": ["private", "protected"], + "format": ["camelCase"], + "leadingUnderscore": "require" + } + ], + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }], + "@typescript-eslint/no-empty-function": ["off"], + "@typescript-eslint/ban-types": ["warn", { + "types": { + "Function": null, + } + }], + "@typescript-eslint/no-shadow": ["warn"], + } + }, + { + files: ["test/**/*.ts"], + rules: { "no-empty": "off", "@typescript-eslint/ban-ts-ignore": "off", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-var-requires": "off" + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-shadow": ["off"], + "@typescript-eslint/no-floating-promises": ["off"], + "@typescript-eslint/no-non-null-assertion": ["off"], + "@typescript-eslint/explicit-module-boundary-types": ["off"] } } ] diff --git a/examples/connect/package.json b/examples/connect/package.json index 0f1ec2f1cf..eb58fc2299 100644 --- a/examples/connect/package.json +++ b/examples/connect/package.json @@ -1,7 +1,7 @@ { "name": "connect-example", "private": true, - "version": "0.24.0", + "version": "0.25.0", "description": "Example of Connect integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -41,7 +41,7 @@ "@opentelemetry/exporter-zipkin": "^0.25.0", "@opentelemetry/exporter-collector": "^0.25.0", "@opentelemetry/instrumentation": "^0.25.0", - "@opentelemetry/instrumentation-connect": "^0.24.0", + "@opentelemetry/instrumentation-connect": "^0.25.0", "@opentelemetry/instrumentation-http": "^0.25.0", "@opentelemetry/sdk-trace-node": "^0.25.0", "@opentelemetry/resources": "^0.25.0", diff --git a/examples/fastify/README.md b/examples/fastify/README.md index 844b20a32c..378a46cf13 100644 --- a/examples/fastify/README.md +++ b/examples/fastify/README.md @@ -9,6 +9,12 @@ This is a simple example that demonstrates tracing calls made to Fastify API. Th - Span Events - Span Attributes +## Prerequisites + +Install [Docker Desktop](https://docs.docker.com/desktop), version 4.12.0 or later. + +If you have an existing Docker Engine installation, you can [install the docker-compose plugin](https://docs.docker.com/compose/install) instead. + ## Installation ```sh @@ -22,26 +28,26 @@ npm install - Run docker container with collector - ```sh - # from this directory - $ npm run docker:start - ``` + ```sh + # from this directory + $ npm run docker:start + ``` ### Server - Run the server - ```sh - # from this directory - $ npm run server - ``` + ```sh + # from this directory + $ npm run server + ``` - Run the client - ```sh - # from this directory - npm run client - ``` + ```sh + # from this directory + npm run client + ``` #### Zipkin UI diff --git a/examples/fastify/package.json b/examples/fastify/package.json index 1cae7b7aa9..f4d2a07c6b 100644 --- a/examples/fastify/package.json +++ b/examples/fastify/package.json @@ -6,8 +6,8 @@ "main": "index.js", "scripts": { "client": "node ./client.js", - "docker:start": "cd ./docker && docker-compose down && docker-compose up", - "docker:stop": "cd ./docker && docker-compose down", + "docker:start": "cd ./docker && docker compose down && docker compose up", + "docker:stop": "cd ./docker && docker compose down", "server": "node ./server.js" }, "repository": { diff --git a/examples/react-load/preact/docker/collector-config.yaml b/examples/react-load/preact/docker/collector-config.yaml index 2f64d8b4fc..377986bf2d 100644 --- a/examples/react-load/preact/docker/collector-config.yaml +++ b/examples/react-load/preact/docker/collector-config.yaml @@ -1,18 +1,25 @@ receivers: otlp: - endpoint: 0.0.0.0:55678 + protocols: + http: + cors: + allowed_origins: + - http://* + - https://* exporters: zipkin: - url: "http://zipkin-all-in-one:9411/api/v2/spans" + endpoint: "http://zipkin-all-in-one:9411/api/v2/spans" processors: batch: - queued_retry: service: pipelines: traces: receivers: [otlp] exporters: [zipkin] - processors: [batch, queued_retry] + processors: [batch] + telemetry: + logs: + level: "debug" diff --git a/examples/react-load/preact/docker/docker-compose.yaml b/examples/react-load/preact/docker/docker-compose.yaml index fee8f1aca0..ab8fead390 100644 --- a/examples/react-load/preact/docker/docker-compose.yaml +++ b/examples/react-load/preact/docker/docker-compose.yaml @@ -3,12 +3,12 @@ services: # Collector collector: - image: omnition/opentelemetry-collector-contrib:0.2.8 - command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] + image: otel/opentelemetry-collector-contrib:0.75.0 + command: ["--config=/conf/collector-config.yaml"] volumes: - ./collector-config.yaml:/conf/collector-config.yaml ports: - - "55678:55678" + - "4318:4318" depends_on: - zipkin-all-in-one diff --git a/examples/react-load/preact/package.json b/examples/react-load/preact/package.json index 63719c9754..4d72912152 100644 --- a/examples/react-load/preact/package.json +++ b/examples/react-load/preact/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "react-load-preact-example", - "version": "0.23.0", + "version": "0.24.0", "description": "Example of using @opentelemetry/plugin-react-load in browser with Preact", "main": "index.js", "scripts": { @@ -23,7 +23,7 @@ "tracing" ], "engines": { - "node": ">=8" + "node": ">=14" }, "author": "OpenTelemetry Authors", "license": "Apache-2.0", @@ -33,15 +33,14 @@ "devDependencies": { "identity-obj-proxy": "^3.0.0", "preact-cli": "^3.0.0", - "preact-render-spy": "^1.2.1", "sirv-cli": "1.0.3" }, "dependencies": { - "@opentelemetry/context-zone": "^0.25.0", - "@opentelemetry/exporter-collector": "^0.25.0", - "@opentelemetry/plugin-react-load": "^0.23.0", - "@opentelemetry/sdk-trace-base": "^0.25.0", - "@opentelemetry/sdk-trace-web": "^0.25.0", + "@opentelemetry/context-zone": "^1.11.0", + "@opentelemetry/exporter-trace-otlp-http": "^0.37.0", + "@opentelemetry/plugin-react-load": "^0.28.1", + "@opentelemetry/sdk-trace-base": "^1.11.0", + "@opentelemetry/sdk-trace-web": "^1.11.0", "preact": "^10.3.2", "preact-render-to-string": "^5.1.4", "preact-router": "^3.2.1" diff --git a/examples/react-load/preact/src/web-tracer.js b/examples/react-load/preact/src/web-tracer.js index 984374bfbe..b52d436e0a 100644 --- a/examples/react-load/preact/src/web-tracer.js +++ b/examples/react-load/preact/src/web-tracer.js @@ -1,14 +1,15 @@ import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; +import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api'; import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load'; import { ZoneContextManager } from '@opentelemetry/context-zone'; -import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; +import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; export default (serviceName) => { + diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); const provider = new WebTracerProvider(); - - const exporter = new CollectorTraceExporter({ - url: 'http://localhost:55678/v1/trace', + const exporter = new OTLPTraceExporter({ + url: 'http://localhost:4318/v1/traces', }); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); @@ -21,7 +22,6 @@ export default (serviceName) => { const tracer = provider.getTracer(serviceName); BaseOpenTelemetryComponent.setTracer(serviceName) - BaseOpenTelemetryComponent.setLogger(provider.logger) return tracer; } diff --git a/karma.webpack.js b/karma.webpack.js index 158e61c32e..546704817a 100644 --- a/karma.webpack.js +++ b/karma.webpack.js @@ -32,7 +32,10 @@ module.exports = { test: /\.ts$/, use: { loader: '@jsdevtools/coverage-istanbul-loader', - options: { esModules: true } + options: { + produceSourceMap: false, + esModules: true + } } }, // This setting configures Node polyfills for the browser that will be diff --git a/metapackages/auto-instrumentations-node/CHANGELOG.md b/metapackages/auto-instrumentations-node/CHANGELOG.md index 017d068361..9e86e111e1 100644 --- a/metapackages/auto-instrumentations-node/CHANGELOG.md +++ b/metapackages/auto-instrumentations-node/CHANGELOG.md @@ -52,6 +52,135 @@ * dependencies * @opentelemetry/instrumentation-express bumped from ^0.31.1 to ^0.31.2 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-aws-lambda bumped from ^0.34.1 to ^0.35.0 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-amqplib bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-dataloader bumped from ^0.3.1 to ^0.4.0 + * @opentelemetry/instrumentation-dns bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-nestjs-core bumped from ^0.32.1 to ^0.32.2 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-fs bumped from ^0.7.0 to ^0.7.1 + * @opentelemetry/instrumentation-graphql bumped from ^0.33.1 to ^0.33.2 + * @opentelemetry/instrumentation-ioredis bumped from ^0.33.2 to ^0.34.0 + * @opentelemetry/instrumentation-koa bumped from ^0.34.1 to ^0.34.2 + * @opentelemetry/instrumentation-pg bumped from ^0.34.1 to ^0.35.0 + * @opentelemetry/instrumentation-redis bumped from ^0.34.2 to ^0.34.3 + * @opentelemetry/instrumentation-redis-4 bumped from ^0.34.2 to ^0.34.3 + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-graphql bumped from ^0.33.2 to ^0.34.0 + * @opentelemetry/instrumentation-koa bumped from ^0.34.2 to ^0.34.3 + * @opentelemetry/instrumentation-redis bumped from ^0.34.3 to ^0.34.4 + +## [0.36.6](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-node-v0.36.5...auto-instrumentations-node-v0.36.6) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-amqplib bumped from ^0.32.2 to ^0.32.3 + * @opentelemetry/instrumentation-aws-lambda bumped from ^0.35.0 to ^0.35.1 + * @opentelemetry/instrumentation-aws-sdk bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-bunyan bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-cassandra-driver bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-connect bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-dataloader bumped from ^0.4.0 to ^0.4.1 + * @opentelemetry/instrumentation-dns bumped from ^0.31.2 to ^0.31.3 + * @opentelemetry/instrumentation-express bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-fs bumped from ^0.7.1 to ^0.7.2 + * @opentelemetry/instrumentation-fastify bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-generic-pool bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-graphql bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-hapi bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-ioredis bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-knex bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-koa bumped from ^0.34.3 to ^0.34.4 + * @opentelemetry/instrumentation-lru-memoizer bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-memcached bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-mongodb bumped from ^0.34.1 to ^0.34.2 + * @opentelemetry/instrumentation-mongoose bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-mysql bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-mysql2 bumped from ^0.33.1 to ^0.33.2 + * @opentelemetry/instrumentation-nestjs-core bumped from ^0.32.2 to ^0.32.3 + * @opentelemetry/instrumentation-net bumped from ^0.31.1 to ^0.31.2 + * @opentelemetry/instrumentation-pg bumped from ^0.35.0 to ^0.35.1 + * @opentelemetry/instrumentation-pino bumped from ^0.33.1 to ^0.33.2 + * @opentelemetry/instrumentation-redis bumped from ^0.34.4 to ^0.34.5 + * @opentelemetry/instrumentation-redis-4 bumped from ^0.34.3 to ^0.34.4 + * @opentelemetry/instrumentation-restify bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-router bumped from ^0.32.1 to ^0.32.2 + * @opentelemetry/instrumentation-socket.io bumped from ^0.33.1 to ^0.33.2 + * @opentelemetry/instrumentation-tedious bumped from ^0.5.1 to ^0.5.2 + * @opentelemetry/instrumentation-winston bumped from ^0.31.1 to ^0.31.2 + +## [0.36.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-node-v0.36.0...auto-instrumentations-node-v0.36.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-amqplib bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-aws-lambda bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-aws-sdk bumped from ^0.33.0 to ^0.34.0 + * @opentelemetry/instrumentation-bunyan bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-cassandra-driver bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-connect bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-dataloader bumped from ^0.3.0 to ^0.3.1 + * @opentelemetry/instrumentation-dns bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-express bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-fs bumped from ^0.6.0 to ^0.7.0 + * @opentelemetry/instrumentation-fastify bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-generic-pool bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-graphql bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-hapi bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-ioredis bumped from ^0.33.1 to ^0.33.2 + * @opentelemetry/instrumentation-knex bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-koa bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-lru-memoizer bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-memcached bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-mongodb bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-mongoose bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-mysql bumped from ^0.32.0 to ^0.33.0 + * @opentelemetry/instrumentation-mysql2 bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-nestjs-core bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-net bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-pg bumped from ^0.34.0 to ^0.34.1 + * @opentelemetry/instrumentation-pino bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-redis bumped from ^0.34.1 to ^0.34.2 + * @opentelemetry/instrumentation-redis-4 bumped from ^0.34.1 to ^0.34.2 + * @opentelemetry/instrumentation-restify bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-router bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-socket.io bumped from ^0.33.0 to ^0.33.1 + * @opentelemetry/instrumentation-tedious bumped from ^0.5.0 to ^0.5.1 + * @opentelemetry/instrumentation-winston bumped from ^0.31.0 to ^0.31.1 + ## [0.36.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-node-v0.35.0...auto-instrumentations-node-v0.36.0) (2022-12-20) diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index 95ab8cff0a..0795f15b77 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -3,17 +3,97 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-url] -This module provides a simple way to initialize multiple Node instrumentations. +## About + +This module provides a way to auto instrument any Node application to capture telemetry from a number of popular libraries and frameworks. +You can export the telemetry data in a variety of formats. Exporters, samplers, and more can be configured via [environment variables][env-var-url]. +The net result is the ability to gather telemetry data from a Node application without any code changes. + +This module also provides a simple way to manually initialize multiple Node instrumentations for use with the OpenTelemetry SDK. Compatible with OpenTelemetry JS API and SDK `1.0+`. ## Installation ```bash +npm install --save @opentelemetry/api npm install --save @opentelemetry/auto-instrumentations-node ``` -## Usage +## Usage: Auto Instrumentation + +This module includes auto instrumentation for all supported instrumentations and [all available data exporters][exporter-url]. +It provides a completely automatic, out-of-the-box experience. +Please see the [Supported Instrumentations](#supported-instrumentations) section for more information. + +Enable auto instrumentation by requiring this module using the [--require flag][require-url]: + +```shell +node --require '@opentelemetry/auto-instrumentations-node/register' app.js +``` + +If your Node application is encapsulated in a complex run script, you can also set it via an environment variable before running Node. + +```shell +env NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" +``` + +The module is highly configurable using environment variables. +Many aspects of the auto instrumentation's behavior can be configured for your needs, such as resource detectors, exporter choice, exporter configuration, trace context propagation headers, and much more. +Instrumentation configuration is not yet supported through environment variables. Users that require instrumentation configuration must initialize OpenTelemetry programmatically. + +```shell +export OTEL_TRACES_EXPORTER="otlp" +export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" +export OTEL_EXPORTER_OTLP_COMPRESSION="gzip" +export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://your-endpoint" +export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key" +export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-api-key=your-api-key" +export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace" +export OTEL_NODE_RESOURCE_DETECTORS="env,host,os" +export OTEL_SERVICE_NAME="client" +export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" +node app.js +``` + +By default, all SDK resource detectors are used, but you can use the environment variable OTEL_NODE_RESOURCE_DETECTORS to enable only certain detectors, or completely disable them: + +- `env` +- `host` +- `os` +- `process` +- `container` +- `alibaba` +- `aws` +- `gcp` +- `all` - enable all resource detectors +- `none` - disable resource detection + +For example, to enable only the `env`, `host` detectors: + +```shell +export OTEL_NODE_RESOURCE_DETECTORS="env,host" +``` + +To enable logging for troubleshooting, set the log level by setting the `OTEL_LOG_LEVEL` environment variable to one of the following: + +- `none` +- `error` +- `warn` +- `info` +- `debug` +- `verbose` +- `all` + +The default level is `info`. + +Notes: + +- In a production environment, it is recommended to set `OTEL_LOG_LEVEL`to `info`. +- Logs are always sent to console, no matter the environment, or debug level. +- Debug logs are extremely verbose. Enable debug logging only when needed. Debug logging negatively impacts the performance of your application. + +## Usage: Instrumentation Initialization OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages. @@ -62,26 +142,22 @@ registerInstrumentations({ - [@opentelemetry/instrumentation-connect](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-connect) - [@opentelemetry/instrumentation-dataloader](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-dataloader) - [@opentelemetry/instrumentation-dns](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns) -- [@opentelemetry/instrumentation-http](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http) -- [@opentelemetry/instrumentation-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-grpc) - [@opentelemetry/instrumentation-express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express) -- [@opentelemetry/instrumentation-koa](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa) -- [@opentelemetry/instrumentation-lru-memoizer](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer) - [@opentelemetry/instrumentation-fastify](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify) - [@opentelemetry/instrumentation-generic-pool](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-generic-pool) - [@opentelemetry/instrumentation-graphql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql) +- [@opentelemetry/instrumentation-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-grpc) - [@opentelemetry/instrumentation-hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi) - [@opentelemetry/instrumentation-http](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http) - [@opentelemetry/instrumentation-ioredis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis) -- [@opentelemetry/instrumentation-redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis) -- [@opentelemetry/instrumentation-pg](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg) - [@opentelemetry/instrumentation-knex](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex) - [@opentelemetry/instrumentation-koa](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa) +- [@opentelemetry/instrumentation-lru-memoizer](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer) - [@opentelemetry/instrumentation-memcached](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-memcached) - [@opentelemetry/instrumentation-mongodb](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb) - [@opentelemetry/instrumentation-mongoose](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose) -- [@opentelemetry/instrumentation-mysql2](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2) - [@opentelemetry/instrumentation-mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql) +- [@opentelemetry/instrumentation-mysql2](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2) - [@opentelemetry/instrumentation-nestjs-core](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core) - [@opentelemetry/instrumentation-net](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-net) - [@opentelemetry/instrumentation-pg](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg) @@ -104,3 +180,6 @@ APACHE 2.0 - See [LICENSE][license-url] for more information. [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat [npm-url]: https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fauto-instrumentations-node.svg +[env-var-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration +[exporter-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#otlp-exporter +[require-url]: https://nodejs.org/api/cli.html#-r---require-module diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index 78796154a3..49a91d7696 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/auto-instrumentations-node", - "version": "0.36.0", + "version": "0.36.6", "description": "Metapackage which bundles opentelemetry node core and contrib instrumentations", "author": "OpenTelemetry Authors", "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node#readme", @@ -13,6 +13,10 @@ }, "main": "build/src/index.js", "types": "build/src/index.d.ts", + "exports": { + ".": "./build/src/index.js", + "./register": "./build/src/register.js" + }, "repository": "open-telemetry/opentelemetry-js-contrib", "scripts": { "clean": "rimraf build/*", @@ -30,58 +34,63 @@ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.3.0" + "@opentelemetry/api": "^1.4.1" }, "devDependencies": { - "@opentelemetry/api": "^1.3.0", + "@opentelemetry/api": "^1.4.1", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/instrumentation-amqplib": "^0.32.0", - "@opentelemetry/instrumentation-aws-lambda": "^0.34.0", - "@opentelemetry/instrumentation-aws-sdk": "^0.33.0", - "@opentelemetry/instrumentation-bunyan": "^0.31.0", - "@opentelemetry/instrumentation-cassandra-driver": "^0.32.0", - "@opentelemetry/instrumentation-connect": "^0.31.0", - "@opentelemetry/instrumentation-dataloader": "^0.3.0", - "@opentelemetry/instrumentation-dns": "^0.31.0", - "@opentelemetry/instrumentation-express": "^0.32.0", - "@opentelemetry/instrumentation-fs": "^0.6.0", - "@opentelemetry/instrumentation-fastify": "^0.31.0", - "@opentelemetry/instrumentation-generic-pool": "^0.31.0", - "@opentelemetry/instrumentation-graphql": "^0.33.0", - "@opentelemetry/instrumentation-grpc": "^0.34.0", - "@opentelemetry/instrumentation-hapi": "^0.31.0", - "@opentelemetry/instrumentation-http": "^0.34.0", - "@opentelemetry/instrumentation-ioredis": "^0.33.1", - "@opentelemetry/instrumentation-knex": "^0.31.0", - "@opentelemetry/instrumentation-koa": "^0.34.0", - "@opentelemetry/instrumentation-lru-memoizer": "^0.32.0", - "@opentelemetry/instrumentation-memcached": "^0.31.0", - "@opentelemetry/instrumentation-mongodb": "^0.34.0", - "@opentelemetry/instrumentation-mongoose": "^0.32.0", - "@opentelemetry/instrumentation-mysql": "^0.32.0", - "@opentelemetry/instrumentation-mysql2": "^0.33.0", - "@opentelemetry/instrumentation-nestjs-core": "^0.32.0", - "@opentelemetry/instrumentation-net": "^0.31.0", - "@opentelemetry/instrumentation-pg": "^0.34.0", - "@opentelemetry/instrumentation-pino": "^0.33.0", - "@opentelemetry/instrumentation-redis": "^0.34.1", - "@opentelemetry/instrumentation-redis-4": "^0.34.1", - "@opentelemetry/instrumentation-restify": "^0.32.0", - "@opentelemetry/instrumentation-router": "^0.32.0", - "@opentelemetry/instrumentation-socket.io": "^0.33.0", - "@opentelemetry/instrumentation-tedious": "^0.5.0", - "@opentelemetry/instrumentation-winston": "^0.31.0" + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-amqplib": "^0.32.3", + "@opentelemetry/instrumentation-aws-lambda": "^0.35.1", + "@opentelemetry/instrumentation-aws-sdk": "^0.34.1", + "@opentelemetry/instrumentation-bunyan": "^0.31.2", + "@opentelemetry/instrumentation-cassandra-driver": "^0.32.2", + "@opentelemetry/instrumentation-connect": "^0.31.2", + "@opentelemetry/instrumentation-dataloader": "^0.4.1", + "@opentelemetry/instrumentation-dns": "^0.31.3", + "@opentelemetry/instrumentation-express": "^0.32.2", + "@opentelemetry/instrumentation-fs": "^0.7.2", + "@opentelemetry/instrumentation-fastify": "^0.31.2", + "@opentelemetry/instrumentation-generic-pool": "^0.31.2", + "@opentelemetry/instrumentation-graphql": "^0.34.1", + "@opentelemetry/instrumentation-grpc": "^0.38.0", + "@opentelemetry/instrumentation-hapi": "^0.31.2", + "@opentelemetry/instrumentation-http": "^0.38.0", + "@opentelemetry/instrumentation-ioredis": "^0.34.1", + "@opentelemetry/instrumentation-knex": "^0.31.2", + "@opentelemetry/instrumentation-koa": "^0.34.4", + "@opentelemetry/instrumentation-lru-memoizer": "^0.32.2", + "@opentelemetry/instrumentation-memcached": "^0.31.2", + "@opentelemetry/instrumentation-mongodb": "^0.34.2", + "@opentelemetry/instrumentation-mongoose": "^0.32.2", + "@opentelemetry/instrumentation-mysql": "^0.33.1", + "@opentelemetry/instrumentation-mysql2": "^0.33.2", + "@opentelemetry/instrumentation-nestjs-core": "^0.32.3", + "@opentelemetry/instrumentation-net": "^0.31.2", + "@opentelemetry/instrumentation-pg": "^0.35.1", + "@opentelemetry/instrumentation-pino": "^0.33.2", + "@opentelemetry/instrumentation-redis": "^0.34.5", + "@opentelemetry/instrumentation-redis-4": "^0.34.4", + "@opentelemetry/instrumentation-restify": "^0.32.2", + "@opentelemetry/instrumentation-router": "^0.32.2", + "@opentelemetry/instrumentation-socket.io": "^0.33.2", + "@opentelemetry/instrumentation-tedious": "^0.5.2", + "@opentelemetry/instrumentation-winston": "^0.31.2", + "@opentelemetry/resource-detector-alibaba-cloud": "^0.27.4", + "@opentelemetry/resource-detector-aws": "^1.2.2", + "@opentelemetry/resource-detector-container": "^0.2.2", + "@opentelemetry/resource-detector-gcp": "^0.28.0", + "@opentelemetry/resources": "^1.12.0", + "@opentelemetry/sdk-node": "^0.38.0" } } diff --git a/metapackages/auto-instrumentations-node/src/register.ts b/metapackages/auto-instrumentations-node/src/register.ts new file mode 100644 index 0000000000..a14538da66 --- /dev/null +++ b/metapackages/auto-instrumentations-node/src/register.ts @@ -0,0 +1,48 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as opentelemetry from '@opentelemetry/sdk-node'; +import { diag, DiagConsoleLogger } from '@opentelemetry/api'; +import { + getNodeAutoInstrumentations, + getResourceDetectorsFromEnv, +} from './utils'; + +diag.setLogger( + new DiagConsoleLogger(), + opentelemetry.core.getEnv().OTEL_LOG_LEVEL +); + +const sdk = new opentelemetry.NodeSDK({ + instrumentations: getNodeAutoInstrumentations(), + resourceDetectors: getResourceDetectorsFromEnv(), +}); + +try { + sdk.start(); + diag.info('OpenTelemetry automatic instrumentation started successfully'); +} catch (error) { + diag.error( + 'Error initializing OpenTelemetry SDK. Your application is not instrumented and will not produce telemetry', + error + ); +} + +process.on('SIGTERM', () => { + sdk + .shutdown() + .then(() => diag.debug('OpenTelemetry SDK terminated')) + .catch(error => diag.error('Error terminating OpenTelemetry SDK', error)); +}); diff --git a/metapackages/auto-instrumentations-node/src/utils.ts b/metapackages/auto-instrumentations-node/src/utils.ts index 6e8e6ecfae..0c194f7a30 100644 --- a/metapackages/auto-instrumentations-node/src/utils.ts +++ b/metapackages/auto-instrumentations-node/src/utils.ts @@ -54,6 +54,34 @@ import { SocketIoInstrumentation } from '@opentelemetry/instrumentation-socket.i import { TediousInstrumentation } from '@opentelemetry/instrumentation-tedious'; import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston'; +import { alibabaCloudEcsDetector } from '@opentelemetry/resource-detector-alibaba-cloud'; +import { + awsBeanstalkDetector, + awsEc2Detector, + awsEcsDetector, + awsEksDetector, + awsLambdaDetector, +} from '@opentelemetry/resource-detector-aws'; +import { containerDetector } from '@opentelemetry/resource-detector-container'; +import { gcpDetector } from '@opentelemetry/resource-detector-gcp'; +import { + Detector, + DetectorSync, + envDetectorSync, + hostDetectorSync, + osDetectorSync, + processDetectorSync, +} from '@opentelemetry/resources'; + +const RESOURCE_DETECTOR_CONTAINER = 'container'; +const RESOURCE_DETECTOR_ENVIRONMENT = 'env'; +const RESOURCE_DETECTOR_HOST = 'host'; +const RESOURCE_DETECTOR_OS = 'os'; +const RESOURCE_DETECTOR_PROCESS = 'process'; +const RESOURCE_DETECTOR_ALIBABA = 'alibaba'; +const RESOURCE_DETECTOR_AWS = 'aws'; +const RESOURCE_DETECTOR_GCP = 'gcp'; + const InstrumentationMap = { '@opentelemetry/instrumentation-amqplib': AmqplibInstrumentation, '@opentelemetry/instrumentation-aws-lambda': AwsLambdaInstrumentation, @@ -119,7 +147,7 @@ export function getNodeAutoInstrumentations( >) { const Instance = InstrumentationMap[name]; // Defaults are defined by the instrumentation itself - const userConfig = inputConfigs[name] ?? {}; + const userConfig: any = inputConfigs[name] ?? {}; if (userConfig.enabled === false) { diag.debug(`Disabling instrumentation for ${name}`); @@ -129,10 +157,56 @@ export function getNodeAutoInstrumentations( try { diag.debug(`Loading instrumentation for ${name}`); instrumentations.push(new Instance(userConfig)); - } catch (e) { + } catch (e: any) { diag.error(e); } } return instrumentations; } + +export function getResourceDetectorsFromEnv(): Array { + const resourceDetectors = new Map< + string, + Detector | DetectorSync | Detector[] + >([ + [RESOURCE_DETECTOR_CONTAINER, containerDetector], + [RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync], + [RESOURCE_DETECTOR_HOST, hostDetectorSync], + [RESOURCE_DETECTOR_OS, osDetectorSync], + [RESOURCE_DETECTOR_PROCESS, processDetectorSync], + [RESOURCE_DETECTOR_ALIBABA, alibabaCloudEcsDetector], + [RESOURCE_DETECTOR_GCP, gcpDetector], + [ + RESOURCE_DETECTOR_AWS, + [ + awsEc2Detector, + awsEcsDetector, + awsEksDetector, + awsBeanstalkDetector, + awsLambdaDetector, + ], + ], + ]); + + const resourceDetectorsFromEnv = + process.env.OTEL_NODE_RESOURCE_DETECTORS?.split(',') ?? ['all']; + + if (resourceDetectorsFromEnv.includes('all')) { + return [...resourceDetectors.values()].flat(); + } + + if (resourceDetectorsFromEnv.includes('none')) { + return []; + } + + return resourceDetectorsFromEnv.flatMap(detector => { + const resourceDetector = resourceDetectors.get(detector); + if (!resourceDetector) { + diag.error( + `Invalid resource detector "${detector}" specified in the environment variable OTEL_NODE_RESOURCE_DETECTORS` + ); + } + return resourceDetector || []; + }); +} diff --git a/metapackages/auto-instrumentations-node/test/register.test.ts b/metapackages/auto-instrumentations-node/test/register.test.ts new file mode 100644 index 0000000000..b3c0381274 --- /dev/null +++ b/metapackages/auto-instrumentations-node/test/register.test.ts @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { promisify } from 'util'; +import * as childProcess from 'child_process'; +import * as assert from 'assert'; + +const exec = promisify(childProcess.exec); + +describe('Register', function () { + this.timeout(5000); + it('can load auto instrumentation from command line', async () => { + process.env.OTEL_NODE_RESOURCE_DETECTORS = 'none'; + process.env.OTEL_TRACES_EXPORTER = 'console'; + + const { stdout } = await exec( + 'node --require ./build/src/register.js ./test/test-app/app.js' + ); + + assert.ok( + stdout.includes( + 'OpenTelemetry automatic instrumentation started successfully' + ) + ); + + //Check a span has been generated for the GET request done in app.js + assert.ok(stdout.includes("name: 'GET'")); + + delete process.env.OTEL_NODE_RESOURCE_DETECTORS; + delete process.env.OTEL_TRACES_EXPORTER; + }); +}); diff --git a/metapackages/auto-instrumentations-node/test/test-app/app.js b/metapackages/auto-instrumentations-node/test/test-app/app.js new file mode 100644 index 0000000000..1057acbce3 --- /dev/null +++ b/metapackages/auto-instrumentations-node/test/test-app/app.js @@ -0,0 +1,29 @@ +/* + * 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. + */ + +//Used in register.test.ts to mimic a JS app. +const http = require('http'); + +const options = { + hostname: 'example.com', + port: 80, + path: '/', + method: 'GET' +}; + +const req = http.request(options); + +req.end(); diff --git a/metapackages/auto-instrumentations-node/test/utils.test.ts b/metapackages/auto-instrumentations-node/test/utils.test.ts index 5707eed8f3..f295668d4f 100644 --- a/metapackages/auto-instrumentations-node/test/utils.test.ts +++ b/metapackages/auto-instrumentations-node/test/utils.test.ts @@ -19,6 +19,7 @@ import { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http'; import * as assert from 'assert'; import * as sinon from 'sinon'; import { getNodeAutoInstrumentations } from '../src'; +import { getResourceDetectorsFromEnv } from '../src/utils'; describe('utils', () => { describe('getNodeAutoInstrumentations', () => { @@ -87,6 +88,55 @@ describe('utils', () => { spy.args[0][0], `Provided instrumentation name "${name}" not found` ); + + spy.restore(); + }); + }); + + describe('getResourceDetectorsFromEnv', () => { + it('should return all resource detectors by default', () => { + assert.equal(getResourceDetectorsFromEnv().length, 12); + }); + + it('should return all resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "all"', () => { + process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all'; + + assert.equal(getResourceDetectorsFromEnv().length, 12); + + delete process.env.OTEL_NODE_RESOURCE_DETECTORS; + }); + + it('should return specific resource detectors depending on OTEL_NODE_RESOURCE_DETECTORS', () => { + process.env.OTEL_NODE_RESOURCE_DETECTORS = 'env,host'; + + const resourceDetectors = getResourceDetectorsFromEnv(); + + assert.equal(resourceDetectors.length, 2); + assert.equal(resourceDetectors[0].constructor.name, 'EnvDetectorSync'); + assert.equal(resourceDetectors[1].constructor.name, 'HostDetectorSync'); + + delete process.env.OTEL_NODE_RESOURCE_DETECTORS; + }); + + it('should return no resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "none" or a typo', () => { + const spy = sinon.stub(diag, 'error'); + process.env.OTEL_NODE_RESOURCE_DETECTORS = 'none'; + + assert.equal(getResourceDetectorsFromEnv().length, 0); + + assert.strictEqual(spy.callCount, 0); + + process.env.OTEL_NODE_RESOURCE_DETECTORS = 'test'; + + assert.equal(getResourceDetectorsFromEnv().length, 0); + + assert.strictEqual( + spy.args[0][0], + 'Invalid resource detector "test" specified in the environment variable OTEL_NODE_RESOURCE_DETECTORS' + ); + + spy.restore(); + delete process.env.OTEL_NODE_RESOURCE_DETECTORS; }); }); }); diff --git a/metapackages/auto-instrumentations-web/CHANGELOG.md b/metapackages/auto-instrumentations-web/CHANGELOG.md index dcf39c08c8..a15dda040d 100644 --- a/metapackages/auto-instrumentations-web/CHANGELOG.md +++ b/metapackages/auto-instrumentations-web/CHANGELOG.md @@ -6,6 +6,56 @@ * dependencies * @opentelemetry/instrumentation-user-interaction bumped from ^0.30.0 to ^0.30.1 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-document-load bumped from ^0.31.1 to ^0.31.2 + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-web-v0.32.0...auto-instrumentations-web-v0.32.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-document-load bumped from ^0.32.0 to ^0.32.1 + * @opentelemetry/instrumentation-user-interaction bumped from ^0.32.1 to ^0.32.2 + +## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-web-v0.31.2...auto-instrumentations-web-v0.32.0) (2023-04-06) + + +### Features + +* **instrumenation-document-load:** Add custom attributes to document load ([#1414](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1414)) ([98609c6](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/98609c69d951951edcaa3234914d04d7ae87e9b5)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-document-load bumped from ^0.31.2 to ^0.32.0 + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-web-v0.31.0...auto-instrumentations-web-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/instrumentation-document-load bumped from ^0.31.0 to ^0.31.1 + * @opentelemetry/instrumentation-user-interaction bumped from ^0.32.0 to ^0.32.1 + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/auto-instrumentations-web-v0.30.1...auto-instrumentations-web-v0.31.0) (2022-11-16) diff --git a/metapackages/auto-instrumentations-web/package.json b/metapackages/auto-instrumentations-web/package.json index c2b3753554..a8fddc2392 100644 --- a/metapackages/auto-instrumentations-web/package.json +++ b/metapackages/auto-instrumentations-web/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/auto-instrumentations-web", - "version": "0.31.0", + "version": "0.32.1", "description": "Metapackage which bundles opentelemetry node core and contrib instrumentations", "author": "OpenTelemetry Authors", "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-web#readme", @@ -40,7 +40,6 @@ "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", "babel-loader": "8.2.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -50,20 +49,20 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/instrumentation-document-load": "^0.31.0", - "@opentelemetry/instrumentation-fetch": "^0.34.0", - "@opentelemetry/instrumentation-user-interaction": "^0.32.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-document-load": "^0.32.1", + "@opentelemetry/instrumentation-fetch": "^0.38.0", + "@opentelemetry/instrumentation-user-interaction": "^0.32.2", + "@opentelemetry/instrumentation-xml-http-request": "^0.38.0" } } diff --git a/metapackages/auto-instrumentations-web/src/utils.ts b/metapackages/auto-instrumentations-web/src/utils.ts index b033b020f1..1127c0f1f2 100644 --- a/metapackages/auto-instrumentations-web/src/utils.ts +++ b/metapackages/auto-instrumentations-web/src/utils.ts @@ -15,7 +15,10 @@ */ import { diag } from '@opentelemetry/api'; -import { Instrumentation } from '@opentelemetry/instrumentation'; +import { + Instrumentation, + InstrumentationConfig, +} from '@opentelemetry/instrumentation'; import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load'; import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch'; import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction'; @@ -55,7 +58,7 @@ export function getWebAutoInstrumentations( >) { const Instance = InstrumentationMap[name]; // Defaults are defined by the instrumentation itself - const userConfig = inputConfigs[name] ?? {}; + const userConfig: InstrumentationConfig = inputConfigs[name] ?? {}; if (userConfig.enabled === false) { diag.debug(`Disabling instrumentation for ${name}`); @@ -65,7 +68,7 @@ export function getWebAutoInstrumentations( try { diag.debug(`Loading instrumentation for ${name}`); instrumentations.push(new Instance(userConfig)); - } catch (e) { + } catch (e: any) { diag.error(e); } } diff --git a/package.json b/package.json index ea02aba526..24049e1ff7 100644 --- a/package.json +++ b/package.json @@ -50,13 +50,16 @@ "@typescript-eslint/parser": "5.8.1", "eslint": "8.7.0", "eslint-config-airbnb-base": "15.0.0", + "eslint-config-prettier": "8.8.0", "eslint-plugin-header": "3.1.1", - "eslint-plugin-import": "2.25.4", - "gts": "3.1.0", + "eslint-plugin-import": "2.27.5", + "eslint-plugin-node": "11.1.0", + "eslint-plugin-prettier": "4.2.1", "husky": "7.0.4", "lerna": "5.5.2", "lerna-changelog": "2.2.0", - "typescript": "4.3.5" + "prettier": "2.8.7", + "typescript": "4.4.4" }, "changelog": { "labels": { diff --git a/packages/opentelemetry-host-metrics/CHANGELOG.md b/packages/opentelemetry-host-metrics/CHANGELOG.md index e8dceb7ddd..a5554b4787 100644 --- a/packages/opentelemetry-host-metrics/CHANGELOG.md +++ b/packages/opentelemetry-host-metrics/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/host-metrics-v0.32.0...host-metrics-v0.32.1) (2023-04-25) + + +### Bug Fixes + +* **host-metrics:** fallback to process.memoryUsage() ([#1471](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1471)) ([4d11d61](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/4d11d61b709cf12d7d02d31960cd7ccb67404b14)) + +## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/host-metrics-v0.31.0...host-metrics-v0.32.0) (2023-04-06) + + +### Features + +* **host-metrics:** Add process metrics ([#1449](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1449)) ([9268716](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/92687167f08ea7e3dec046ca7f2be86b337dd743)) +* **host-metrics:** update host metrics to collect metrics in batch ([#1450](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1450)) ([6c708d1](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/6c708d116264e395cf5eab94f3ba3250a8585c87)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/host-metrics-v0.30.1...host-metrics-v0.31.0) (2022-11-16) diff --git a/packages/opentelemetry-host-metrics/package.json b/packages/opentelemetry-host-metrics/package.json index 73d619f4ae..2a5fd25c0b 100644 --- a/packages/opentelemetry-host-metrics/package.json +++ b/packages/opentelemetry-host-metrics/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/host-metrics", - "version": "0.31.0", + "version": "0.32.1", "description": "OpenTelemetry Host Metrics for Node.js", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -50,13 +50,12 @@ "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/sdk-metrics": "^1.8.0", diff --git a/packages/opentelemetry-host-metrics/src/BaseMetrics.ts b/packages/opentelemetry-host-metrics/src/BaseMetrics.ts index e859a5f7cf..7066ed65d8 100644 --- a/packages/opentelemetry-host-metrics/src/BaseMetrics.ts +++ b/packages/opentelemetry-host-metrics/src/BaseMetrics.ts @@ -23,8 +23,6 @@ import { VERSION } from './version'; * Metrics Collector Configuration */ export interface MetricsCollectorConfig { - // maximum timeout to wait for stats collection default is 500ms - maxTimeoutUpdateMS?: number; // Meter Provider meterProvider?: metrics.MeterProvider; // Character to be used to join metrics - default is "." @@ -35,7 +33,6 @@ export interface MetricsCollectorConfig { url?: string; } -export const DEFAULT_MAX_TIMEOUT_UPDATE_MS = 500; const DEFAULT_NAME = 'opentelemetry-host-metrics'; /** @@ -43,14 +40,11 @@ const DEFAULT_NAME = 'opentelemetry-host-metrics'; */ export abstract class BaseMetrics { protected _logger = api.diag; - protected _maxTimeoutUpdateMS: number; protected _meter: api.Meter; private _name: string; constructor(config: MetricsCollectorConfig) { this._name = config.name || DEFAULT_NAME; - this._maxTimeoutUpdateMS = - config.maxTimeoutUpdateMS || DEFAULT_MAX_TIMEOUT_UPDATE_MS; const meterProvider = config.meterProvider! || api.metrics.getMeterProvider(); if (!config.meterProvider) { diff --git a/packages/opentelemetry-host-metrics/src/enum.ts b/packages/opentelemetry-host-metrics/src/enum.ts index e4d113afb7..a4ed9a637b 100644 --- a/packages/opentelemetry-host-metrics/src/enum.ts +++ b/packages/opentelemetry-host-metrics/src/enum.ts @@ -22,6 +22,9 @@ export enum METRIC_NAMES { NETWORK_DROPPED = 'system.network.dropped', NETWORK_ERRORS = 'system.network.errors', NETWORK_IO = 'system.network.io', + PROCESS_CPU_TIME = 'process.cpu.time', + PROCESS_CPU_UTILIZATION = 'process.cpu.utilization', + PROCESS_MEMORY_USAGE = 'process.memory.usage', } export enum CPU_LABELS { diff --git a/packages/opentelemetry-host-metrics/src/metric.ts b/packages/opentelemetry-host-metrics/src/metric.ts index 3dae2efbe4..e89b69887b 100644 --- a/packages/opentelemetry-host-metrics/src/metric.ts +++ b/packages/opentelemetry-host-metrics/src/metric.ts @@ -18,142 +18,156 @@ import { BaseMetrics } from './BaseMetrics'; import * as api from '@opentelemetry/api'; import * as enums from './enum'; -import { getCpuUsageData, getMemoryData } from './stats/common'; +import { + getCpuUsageData, + getMemoryData, + getProcessCpuUsageData, + getProcessMemoryData, +} from './stats/common'; import { getNetworkData } from './stats/si'; -import { CpuUsageData, MemoryData, NetworkData } from './types'; -import { throttle } from './util'; +import { + CpuUsageData, + MemoryData, + NetworkData, + ProcessCpuUsageData, +} from './types'; /** * Metrics Collector - collects metrics for CPU, Memory, Network */ export class HostMetrics extends BaseMetrics { - private _updateCpuTime( - observableResult: api.ObservableResult, + private _batchUpdateCpuUsages( + observableResult: api.BatchObservableResult, cpuUsages: CpuUsageData[] ): void { for (let i = 0, j = cpuUsages.length; i < j; i++) { const cpuUsage = cpuUsages[i]; - observableResult.observe(cpuUsage.user, { + observableResult.observe(this._cpuTime, cpuUsage.user, { state: enums.CPU_LABELS.USER, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.system, { + observableResult.observe(this._cpuTime, cpuUsage.system, { state: enums.CPU_LABELS.SYSTEM, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.idle, { + observableResult.observe(this._cpuTime, cpuUsage.idle, { state: enums.CPU_LABELS.IDLE, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.interrupt, { + observableResult.observe(this._cpuTime, cpuUsage.interrupt, { state: enums.CPU_LABELS.INTERRUPT, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.nice, { + observableResult.observe(this._cpuTime, cpuUsage.nice, { state: enums.CPU_LABELS.NICE, cpu: cpuUsage.cpuNumber, }); - } - } - private _updateCpuUtilisation( - observableResult: api.ObservableResult, - cpuUsages: CpuUsageData[] - ): void { - for (let i = 0, j = cpuUsages.length; i < j; i++) { - const cpuUsage = cpuUsages[i]; - observableResult.observe(cpuUsage.userP, { + observableResult.observe(this._cpuUtilization, cpuUsage.userP, { state: enums.CPU_LABELS.USER, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.systemP, { + observableResult.observe(this._cpuUtilization, cpuUsage.systemP, { state: enums.CPU_LABELS.SYSTEM, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.idleP, { + observableResult.observe(this._cpuUtilization, cpuUsage.idleP, { state: enums.CPU_LABELS.IDLE, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.interruptP, { + observableResult.observe(this._cpuUtilization, cpuUsage.interruptP, { state: enums.CPU_LABELS.INTERRUPT, cpu: cpuUsage.cpuNumber, }); - observableResult.observe(cpuUsage.niceP, { + observableResult.observe(this._cpuUtilization, cpuUsage.niceP, { state: enums.CPU_LABELS.NICE, cpu: cpuUsage.cpuNumber, }); } } - private _updateMemUsage( - observableResult: api.ObservableResult, - memUsage: MemoryData + private _batchUpdateProcessCpuUsages( + observableResult: api.BatchObservableResult, + processCpuUsage: ProcessCpuUsageData ): void { - observableResult.observe(memUsage.used, { - state: enums.MEMORY_LABELS.USED, + observableResult.observe(this._processCpuTime, processCpuUsage.user, { + state: enums.CPU_LABELS.USER, }); - observableResult.observe(memUsage.free, { - state: enums.MEMORY_LABELS.FREE, + observableResult.observe(this._processCpuTime, processCpuUsage.system, { + state: enums.CPU_LABELS.SYSTEM, }); + + observableResult.observe( + this._processCpuUtilization, + processCpuUsage.userP, + { + state: enums.CPU_LABELS.USER, + } + ); + observableResult.observe( + this._processCpuUtilization, + processCpuUsage.systemP, + { + state: enums.CPU_LABELS.SYSTEM, + } + ); } - private _updateMemUtilization( - observableResult: api.ObservableResult, + private _batchUpdateMemUsages( + observableResult: api.BatchObservableResult, memUsage: MemoryData ): void { - observableResult.observe(memUsage.usedP, { + observableResult.observe(this._memoryUsage, memUsage.used, { state: enums.MEMORY_LABELS.USED, }); - observableResult.observe(memUsage.freeP, { + observableResult.observe(this._memoryUsage, memUsage.free, { + state: enums.MEMORY_LABELS.FREE, + }); + + observableResult.observe(this._memoryUtilization, memUsage.usedP, { + state: enums.MEMORY_LABELS.USED, + }); + observableResult.observe(this._memoryUtilization, memUsage.freeP, { state: enums.MEMORY_LABELS.FREE, }); } - private _updateNetworkDropped( - observableResult: api.ObservableResult, + private _batchUpdateProcessMemUsage( + observableResult: api.BatchObservableResult, + memoryUsage: number + ): void { + observableResult.observe(this._processMemoryUsage, memoryUsage); + } + + private _batchUpdateNetworkData( + observableResult: api.BatchObservableResult, networkUsages: NetworkData[] ): void { for (let i = 0, j = networkUsages.length; i < j; i++) { const networkUsage = networkUsages[i]; - observableResult.observe(networkUsage.rx_dropped, { + observableResult.observe(this._networkDropped, networkUsage.rx_dropped, { [enums.NETWORK_LABELS.DEVICE]: networkUsage.iface, direction: enums.NETWORK_LABELS.RECEIVE, }); - observableResult.observe(networkUsage.tx_dropped, { + observableResult.observe(this._networkDropped, networkUsage.tx_dropped, { device: networkUsage.iface, direction: enums.NETWORK_LABELS.TRANSMIT, }); - } - } - private _updateNetworkErrors( - observableResult: api.ObservableResult, - networkUsages: NetworkData[] - ): void { - for (let i = 0, j = networkUsages.length; i < j; i++) { - const networkUsage = networkUsages[i]; - observableResult.observe(networkUsage.rx_errors, { + observableResult.observe(this._networkErrors, networkUsage.rx_errors, { device: networkUsage.iface, direction: enums.NETWORK_LABELS.RECEIVE, }); - observableResult.observe(networkUsage.tx_errors, { + observableResult.observe(this._networkErrors, networkUsage.tx_errors, { device: networkUsage.iface, direction: enums.NETWORK_LABELS.TRANSMIT, }); - } - } - private _updateNetworkIO( - observableResult: api.ObservableResult, - networkUsages: NetworkData[] - ): void { - for (let i = 0, j = networkUsages.length; i < j; i++) { - const networkUsage = networkUsages[i]; - observableResult.observe(networkUsage.rx_bytes, { + observableResult.observe(this._networkIo, networkUsage.rx_bytes, { device: networkUsage.iface, direction: enums.NETWORK_LABELS.RECEIVE, }); - observableResult.observe(networkUsage.tx_bytes, { + observableResult.observe(this._networkIo, networkUsage.tx_bytes, { device: networkUsage.iface, direction: enums.NETWORK_LABELS.TRANSMIT, }); @@ -164,63 +178,99 @@ export class HostMetrics extends BaseMetrics { * Creates metrics */ protected _createMetrics(): void { - this._meter - .createObservableCounter(enums.METRIC_NAMES.CPU_TIME, { + this._cpuTime = this._meter.createObservableCounter( + enums.METRIC_NAMES.CPU_TIME, + { description: 'Cpu time in seconds', unit: 's', - }) - .addCallback(observableResult => { - const cpuUsageData = this._getCpuUsageData(); - this._updateCpuTime(observableResult, cpuUsageData); - }); - this._meter - .createObservableGauge(enums.METRIC_NAMES.CPU_UTILIZATION, { + } + ); + this._cpuUtilization = this._meter.createObservableGauge( + enums.METRIC_NAMES.CPU_UTILIZATION, + { description: 'Cpu usage time 0-1', - }) - .addCallback(observableResult => { - const cpuUsageData = this._getCpuUsageData(); - this._updateCpuUtilisation(observableResult, cpuUsageData); - }); - this._meter - .createObservableGauge(enums.METRIC_NAMES.MEMORY_USAGE, { + } + ); + + this._memoryUsage = this._meter.createObservableGauge( + enums.METRIC_NAMES.MEMORY_USAGE, + { description: 'Memory usage in bytes', - }) - .addCallback(observableResult => { - const memoryUsageData = this._getMemoryData(); - this._updateMemUsage(observableResult, memoryUsageData); - }); - this._meter - .createObservableGauge(enums.METRIC_NAMES.MEMORY_UTILIZATION, { + } + ); + this._memoryUtilization = this._meter.createObservableGauge( + enums.METRIC_NAMES.MEMORY_UTILIZATION, + { description: 'Memory usage 0-1', - }) - .addCallback(observableResult => { - const memoryUsageData = this._getMemoryData(); - this._updateMemUtilization(observableResult, memoryUsageData); - }); - this._meter - .createObservableCounter(enums.METRIC_NAMES.NETWORK_DROPPED, { + } + ); + + this._networkDropped = this._meter.createObservableCounter( + enums.METRIC_NAMES.NETWORK_DROPPED, + { description: 'Network dropped packets', - }) - .addCallback(async observableResult => { - const networkData = await this._getNetworkData(); - this._updateNetworkDropped(observableResult, networkData); - }); - this._meter - .createObservableCounter(enums.METRIC_NAMES.NETWORK_ERRORS, { + } + ); + this._networkErrors = this._meter.createObservableCounter( + enums.METRIC_NAMES.NETWORK_ERRORS, + { description: 'Network errors counter', - }) - .addCallback(async observableResult => { - const networkData = await this._getNetworkData(); - this._updateNetworkErrors(observableResult, networkData); - }); - this._meter - .createObservableCounter(enums.METRIC_NAMES.NETWORK_IO, { + } + ); + this._networkIo = this._meter.createObservableCounter( + enums.METRIC_NAMES.NETWORK_IO, + { description: 'Network transmit and received bytes', - }) - .addCallback(async observableResult => { - const networkData = await this._getNetworkData(); - this._updateNetworkIO(observableResult, networkData); - }); + } + ); + + this._processCpuTime = this._meter.createObservableCounter( + enums.METRIC_NAMES.PROCESS_CPU_TIME, + { + description: 'Process Cpu time in seconds', + unit: 's', + } + ); + this._processCpuUtilization = this._meter.createObservableGauge( + enums.METRIC_NAMES.PROCESS_CPU_UTILIZATION, + { + description: 'Process Cpu usage time 0-1', + } + ); + this._processMemoryUsage = this._meter.createObservableGauge( + enums.METRIC_NAMES.PROCESS_MEMORY_USAGE, + { + description: 'Process Memory usage in bytes', + } + ); + + this._meter.addBatchObservableCallback( + async observableResult => { + const cpuUsages = getCpuUsageData(); + const memoryUsages = getMemoryData(); + const processCpuUsages = getProcessCpuUsageData(); + const processMemoryUsages = getProcessMemoryData(); + const networkData = await getNetworkData(); + + this._batchUpdateCpuUsages(observableResult, cpuUsages); + this._batchUpdateMemUsages(observableResult, memoryUsages); + this._batchUpdateProcessCpuUsages(observableResult, processCpuUsages); + this._batchUpdateProcessMemUsage(observableResult, processMemoryUsages); + this._batchUpdateNetworkData(observableResult, networkData); + }, + [ + this._cpuTime, + this._cpuUtilization, + this._memoryUsage, + this._memoryUtilization, + this._processCpuTime, + this._processCpuUtilization, + this._processMemoryUsage, + this._networkDropped, + this._networkErrors, + this._networkIo, + ] + ); } /** @@ -230,10 +280,15 @@ export class HostMetrics extends BaseMetrics { this._createMetrics(); } - private _getMemoryData = throttle(getMemoryData, this._maxTimeoutUpdateMS); - private _getCpuUsageData = throttle( - getCpuUsageData, - this._maxTimeoutUpdateMS - ); - private _getNetworkData = throttle(getNetworkData, this._maxTimeoutUpdateMS); + // The metrics are created in `_createMetrics`. + private _cpuTime!: api.ObservableCounter; + private _cpuUtilization!: api.ObservableGauge; + private _memoryUsage!: api.ObservableGauge; + private _memoryUtilization!: api.ObservableGauge; + private _processCpuTime!: api.ObservableCounter; + private _processCpuUtilization!: api.ObservableGauge; + private _processMemoryUsage!: api.ObservableGauge; + private _networkDropped!: api.ObservableCounter; + private _networkErrors!: api.ObservableCounter; + private _networkIo!: api.ObservableCounter; } diff --git a/packages/opentelemetry-host-metrics/src/stats/common.ts b/packages/opentelemetry-host-metrics/src/stats/common.ts index 28b73f09d2..b74522ae0d 100644 --- a/packages/opentelemetry-host-metrics/src/stats/common.ts +++ b/packages/opentelemetry-host-metrics/src/stats/common.ts @@ -16,7 +16,7 @@ import * as os from 'os'; -import { CpuUsageData, MemoryData } from '../types'; +import { CpuUsageData, MemoryData, ProcessCpuUsageData } from '../types'; const MILLISECOND = 1 / 1e3; let cpuUsageTime: number | undefined = undefined; @@ -61,6 +61,28 @@ export function getCpuUsageData(): CpuUsageData[] { }); } +/** + * It returns process cpu load delta from last time - to be used with SumObservers. + * When called first time it will return 0 and then delta will be calculated + */ +export function getProcessCpuUsageData(): ProcessCpuUsageData { + if (typeof cpuUsageTime !== 'number') { + cpuUsageTime = new Date().getTime() - process.uptime() * 1000; + } + const timeElapsed = (new Date().getTime() - cpuUsageTime) / 1000; + const cpuUsage: NodeJS.CpuUsage = process.cpuUsage(); + const user = cpuUsage.user * MILLISECOND; + const system = cpuUsage.system * MILLISECOND; + const userP = user / timeElapsed; + const systemP = system / timeElapsed; + return { + user, + system, + userP, + systemP, + }; +} + /** * Returns memory data as absolute values */ @@ -80,3 +102,17 @@ export function getMemoryData(): MemoryData { freeP: freeP, // this is frac part (0-1) }; } + +/** + * Returns process memory RSS + * The Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, + * including all C++ and JavaScript objects and code. + */ +export function getProcessMemoryData(): number { + // `process.memoryUsage.rss` is a faster alternative introduced in v14.18.0. + // Prefer it if available. + if (process.memoryUsage.rss) { + return process.memoryUsage.rss(); + } + return process.memoryUsage().rss; +} diff --git a/packages/opentelemetry-host-metrics/src/types.ts b/packages/opentelemetry-host-metrics/src/types.ts index 0e1aed4eb5..91d945012e 100644 --- a/packages/opentelemetry-host-metrics/src/types.ts +++ b/packages/opentelemetry-host-metrics/src/types.ts @@ -44,6 +44,16 @@ export interface CpuUsageData { niceP: number; } +/** + * Process CPU usage data + */ +export interface ProcessCpuUsageData { + system: number; + user: number; + systemP: number; + userP: number; +} + /** * Memory data */ diff --git a/packages/opentelemetry-host-metrics/src/util.ts b/packages/opentelemetry-host-metrics/src/util.ts index 2ad6d6c819..e26b0f7610 100644 --- a/packages/opentelemetry-host-metrics/src/util.ts +++ b/packages/opentelemetry-host-metrics/src/util.ts @@ -17,18 +17,3 @@ export function ObjectKeys(t: T) { return Object.keys(t) as (keyof T)[]; } - -export function throttle(fn: () => T, ms: number): () => T { - let memoized: T | undefined = undefined; - let timeout: ReturnType | null = null; - return () => { - if (timeout !== null) { - return memoized!; - } - memoized = fn(); - timeout = setTimeout(() => { - timeout = null; - }, ms); - return memoized; - }; -} diff --git a/packages/opentelemetry-host-metrics/test/metric.test.ts b/packages/opentelemetry-host-metrics/test/metric.test.ts index 72a1395ca5..39b4fdb8eb 100644 --- a/packages/opentelemetry-host-metrics/test/metric.test.ts +++ b/packages/opentelemetry-host-metrics/test/metric.test.ts @@ -27,7 +27,7 @@ import { import * as assert from 'assert'; import * as os from 'os'; import * as sinon from 'sinon'; -import { DEFAULT_MAX_TIMEOUT_UPDATE_MS, HostMetrics } from '../src'; +import { HostMetrics } from '../src'; const cpuJson = require('./mocks/cpu.json'); const networkJson = require('./mocks/network.json'); @@ -117,6 +117,15 @@ describe('Host Metrics', () => { sandbox.stub(SI, 'networkStats').callsFake(() => { return mockedSI.networkStats(); }); + sandbox.stub(process, 'cpuUsage').callsFake(() => { + return { + user: 90713560, + system: 63192630, + }; + }); + sandbox.stub(process.memoryUsage, 'rss').callsFake(() => { + return 123456; + }); reader = new TestMetricReader(); @@ -138,7 +147,6 @@ describe('Host Metrics', () => { dateStub.returns(process.uptime() * 1000 + INTERVAL); // invalidates throttles - sandbox.clock.tick(DEFAULT_MAX_TIMEOUT_UPDATE_MS); countSI = 0; }); afterEach(() => { @@ -211,6 +219,26 @@ describe('Host Metrics', () => { ensureValue(metric, { direction: 'receive', device: 'eth0' }, 123123); ensureValue(metric, { direction: 'transmit', device: 'eth0' }, 321321); }); + + it('should export Process CPU time metrics', async () => { + const metric = await getRecords(reader, 'process.cpu.time'); + + ensureValue(metric, { state: 'user' }, 90713.56); + ensureValue(metric, { state: 'system' }, 63192.630000000005); + }); + + it('should export Process CPU utilization metrics', async () => { + const metric = await getRecords(reader, 'process.cpu.utilization'); + + ensureValue(metric, { state: 'user' }, 30247.935978659552); + ensureValue(metric, { state: 'system' }, 21071.23374458153); + }); + + it('should export Process Memory usage metrics', async () => { + const metric = await getRecords(reader, 'process.memory.usage'); + + ensureValue(metric, {}, 123456); + }); }); }); diff --git a/packages/opentelemetry-host-metrics/test/util.test.ts b/packages/opentelemetry-host-metrics/test/util.test.ts deleted file mode 100644 index 573996c20a..0000000000 --- a/packages/opentelemetry-host-metrics/test/util.test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { throttle } from '../src/util'; -import * as sinon from 'sinon'; -import * as assert from 'assert'; - -describe('util', () => { - describe('throttle', () => { - let sandbox: sinon.SinonSandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.useFakeTimers(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should call the fn', () => { - let retValue = '1'; - const stub = sinon.stub(); - const throttled = throttle(stub, 100); - - // no return value is memoized, calls the fn. - stub.returns(retValue); - assert.strictEqual(throttled(), retValue); - assert.strictEqual(throttled(), retValue); - - sandbox.clock.tick(50); - // the return value is memoized, does not call the fn. - assert.strictEqual(throttled(), retValue); - assert.strictEqual(stub.callCount, 1); - - retValue = '2'; - stub.returns(retValue); - sandbox.clock.tick(50); - // no return value is memoized, calls the fn. - assert.strictEqual(throttled(), retValue); - assert.strictEqual(stub.callCount, 2); - }); - - it('should call the fn with exceptions', () => { - const stub = sinon.stub(); - const throttled = throttle(stub, 100); - - const error = new Error('foobar'); - stub.throws(error); - // no return value is memoized, throws. - assert.throws(throttled, error); - assert.throws(throttled, error); - stub.returns('1'); - assert.strictEqual(throttled(), '1'); - - sandbox.clock.tick(50); - assert.strictEqual(throttled(), '1'); - assert.strictEqual(stub.callCount, 3); - - sandbox.clock.tick(50); - // no return value is memoized, calls the fn. - assert.strictEqual(throttled(), '1'); - assert.strictEqual(stub.callCount, 4); - - // the return value is memoized, does not throw. - stub.throws(error); - assert.strictEqual(throttled(), '1'); - assert.strictEqual(stub.callCount, 4); - }); - }); -}); diff --git a/packages/opentelemetry-id-generator-aws-xray/README.md b/packages/opentelemetry-id-generator-aws-xray/README.md index 5b252f0b6f..707cddadbb 100644 --- a/packages/opentelemetry-id-generator-aws-xray/README.md +++ b/packages/opentelemetry-id-generator-aws-xray/README.md @@ -3,20 +3,22 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @willarmiros - The OpenTelemetry IdGenerator for AWS X-Ray generates trace IDs with its first four bytes set to the start time of the trace followed by a unique identifier consisting of 12 bytes of randomly generated numbers. OpenTelemetry offers an extension point which allows the usage of this custom IdGenerator as opposed to the out-of-the-box random IdGenerator, enabling compatibility with AWS X-Ray. -Compatible with OpenTelemetry JS API and SDK `1.0+`. +## Status + +| Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility | +| -------------------------------------- | ----------------------------------------------------- | --------------------- | +| [Stable](../../CONTRIBUTING.md#stable) | @carolabadeer | API 1.0+
SDK 1.0+ | ## Installation -` +```bash npm install --save @opentelemetry/id-generator-aws-xray -` +``` ## Usage diff --git a/packages/opentelemetry-id-generator-aws-xray/package.json b/packages/opentelemetry-id-generator-aws-xray/package.json index f0a317c4a1..2248ea5727 100644 --- a/packages/opentelemetry-id-generator-aws-xray/package.json +++ b/packages/opentelemetry-id-generator-aws-xray/package.json @@ -59,7 +59,6 @@ "@types/node": "18.11.7", "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -69,11 +68,11 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0" }, "dependencies": { diff --git a/packages/opentelemetry-propagation-utils/CHANGELOG.md b/packages/opentelemetry-propagation-utils/CHANGELOG.md index 7601526a81..1fdcd0a4d6 100644 --- a/packages/opentelemetry-propagation-utils/CHANGELOG.md +++ b/packages/opentelemetry-propagation-utils/CHANGELOG.md @@ -6,6 +6,18 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.31.0 to ^0.33.0 +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + ## [0.29.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/propagation-utils-v0.28.0...propagation-utils-v0.29.0) (2022-09-27) diff --git a/packages/opentelemetry-propagation-utils/package.json b/packages/opentelemetry-propagation-utils/package.json index 44d2e89f8d..013c3123a4 100644 --- a/packages/opentelemetry-propagation-utils/package.json +++ b/packages/opentelemetry-propagation-utils/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/propagation-utils", - "version": "0.29.1", + "version": "0.29.3", "description": "Propagation utilities for opentelemetry instrumentations", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -45,16 +45,15 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/mocha": "^9.1.1", "@types/node": "18.11.7", "@types/sinon": "^10.0.11", "expect": "29.2.0", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "sinon": "13.0.1", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/packages/opentelemetry-redis-common/CHANGELOG.md b/packages/opentelemetry-redis-common/CHANGELOG.md index a098eecb92..a1c1410417 100644 --- a/packages/opentelemetry-redis-common/CHANGELOG.md +++ b/packages/opentelemetry-redis-common/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.35.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/redis-common-v0.34.0...redis-common-v0.35.0) (2023-03-03) + + +### Features + +* **ioredis:** Update instrumentation-ioredis to version 5.x.x ([#1121](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1121)) ([f5f7ac6](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f5f7ac6196b5422e030a6913c491117a6a3a0690)) + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/redis-common-v0.33.0...redis-common-v0.34.0) (2022-12-20) diff --git a/packages/opentelemetry-redis-common/package.json b/packages/opentelemetry-redis-common/package.json index d2add794fe..e8622926c3 100644 --- a/packages/opentelemetry-redis-common/package.json +++ b/packages/opentelemetry-redis-common/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/redis-common", - "version": "0.34.0", + "version": "0.35.0", "description": "Redis utilities for redis instrumentations", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,10 +41,9 @@ "devDependencies": { "@types/mocha": "^9.1.1", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/packages/opentelemetry-redis-common/src/index.ts b/packages/opentelemetry-redis-common/src/index.ts index 03f0d2845a..eb093cb773 100644 --- a/packages/opentelemetry-redis-common/src/index.ts +++ b/packages/opentelemetry-redis-common/src/index.ts @@ -44,7 +44,7 @@ const serializationSubsets = [ export type DbStatementSerializer = ( cmdName: string, - cmdArgs: Array + cmdArgs: Array ) => string; /** diff --git a/packages/opentelemetry-test-utils/CHANGELOG.md b/packages/opentelemetry-test-utils/CHANGELOG.md index 4195ebaaa2..c6215dafe8 100644 --- a/packages/opentelemetry-test-utils/CHANGELOG.md +++ b/packages/opentelemetry-test-utils/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/contrib-test-utils-v0.33.1...contrib-test-utils-v0.33.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/contrib-test-utils-v0.33.0...contrib-test-utils-v0.33.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/contrib-test-utils-v0.32.0...contrib-test-utils-v0.33.0) (2022-11-16) diff --git a/packages/opentelemetry-test-utils/package.json b/packages/opentelemetry-test-utils/package.json index 72cee473c5..c88aa12eea 100644 --- a/packages/opentelemetry-test-utils/package.json +++ b/packages/opentelemetry-test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/contrib-test-utils", - "version": "0.33.0", + "version": "0.33.2", "description": "Test utilities for opentelemetry components", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,13 +43,12 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@types/node": "18.11.7", - "gts": "3.1.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.3.1", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@opentelemetry/resources": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", diff --git a/plugins/node/instrumentation-amqplib/CHANGELOG.md b/plugins/node/instrumentation-amqplib/CHANGELOG.md index c0484c1aa0..d17f68af9e 100644 --- a/plugins/node/instrumentation-amqplib/CHANGELOG.md +++ b/plugins/node/instrumentation-amqplib/CHANGELOG.md @@ -1,5 +1,42 @@ # Changelog +## [0.32.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-amqplib-v0.32.2...instrumentation-amqplib-v0.32.3) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-amqplib-v0.32.1...instrumentation-amqplib-v0.32.2) (2023-02-14) + + +### Bug Fixes + +* **amqplib:** stop importing from `amqplib` directly in compiled types ([#1394](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1394)) ([9d0198c](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/9d0198ca104a34726a7b41dd910df275e0c5336d)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-amqplib-v0.32.0...instrumentation-amqplib-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **amqplib:** use extracted context for message consuming ([#1354](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1354)) ([ad92673](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ad92673bd6dbf154b8c73968f34d1e836099dd35)) +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) +* **instrumentation-amqplib:** move `@types/amqplib` into dev deps ([#1320](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1320)) ([52136d8](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/52136d85064b0d451b3cc67530ee96f8bb8128af)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-amqplib-v0.31.0...instrumentation-amqplib-v0.32.0) (2022-11-16) diff --git a/plugins/node/instrumentation-amqplib/package.json b/plugins/node/instrumentation-amqplib/package.json index 6a4282a7e6..5c085d9bcb 100644 --- a/plugins/node/instrumentation-amqplib/package.json +++ b/plugins/node/instrumentation-amqplib/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-amqplib", - "version": "0.32.0", + "version": "0.32.3", "description": "OpenTelemetry automatic instrumentation for the `amqplib` package", "keywords": [ "amqplib", @@ -47,13 +47,13 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/amqplib": "^0.5.17" + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/semantic-conventions": "^1.0.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", + "@types/amqplib": "^0.5.17", "@types/lodash": "4.14.178", "@types/mocha": "8.2.3", "@types/sinon": "10.0.2", @@ -64,10 +64,9 @@ "mocha": "7.2.0", "ts-mocha": "10.0.0", "nyc": "15.1.0", - "gts": "3.1.0", - "sinon": "14.0.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "engines": { "node": ">=14" diff --git a/plugins/node/instrumentation-amqplib/src/amqplib.ts b/plugins/node/instrumentation-amqplib/src/amqplib.ts index 5d51a3dde5..17fd6e20b6 100644 --- a/plugins/node/instrumentation-amqplib/src/amqplib.ts +++ b/plugins/node/instrumentation-amqplib/src/amqplib.ts @@ -30,7 +30,6 @@ import { } from '@opentelemetry/core'; import { InstrumentationBase, - InstrumentationModuleDefinition, InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile, isWrapped, @@ -41,7 +40,13 @@ import { MessagingOperationValues, MessagingDestinationKindValues, } from '@opentelemetry/semantic-conventions'; -import type * as amqp from 'amqplib'; +import type { + Connection, + ConsumeMessage, + Message, + Options, + Replies, +} from 'amqplib'; import { AmqplibInstrumentationConfig, DEFAULT_CONFIG, @@ -64,7 +69,7 @@ import { } from './utils'; import { VERSION } from './version'; -export class AmqplibInstrumentation extends InstrumentationBase { +export class AmqplibInstrumentation extends InstrumentationBase { protected override _config!: AmqplibInstrumentationConfig; constructor(config?: AmqplibInstrumentationConfig) { @@ -79,31 +84,29 @@ export class AmqplibInstrumentation extends InstrumentationBase { this._config = Object.assign({}, DEFAULT_CONFIG, config); } - protected init(): InstrumentationModuleDefinition { - const channelModelModuleFile = - new InstrumentationNodeModuleFile( - 'amqplib/lib/channel_model.js', - ['>=0.5.5'], - this.patchChannelModel.bind(this), - this.unpatchChannelModel.bind(this) - ); + protected init() { + const channelModelModuleFile = new InstrumentationNodeModuleFile( + 'amqplib/lib/channel_model.js', + ['>=0.5.5'], + this.patchChannelModel.bind(this), + this.unpatchChannelModel.bind(this) + ); - const callbackModelModuleFile = - new InstrumentationNodeModuleFile( - 'amqplib/lib/callback_model.js', - ['>=0.5.5'], - this.patchChannelModel.bind(this), - this.unpatchChannelModel.bind(this) - ); + const callbackModelModuleFile = new InstrumentationNodeModuleFile( + 'amqplib/lib/callback_model.js', + ['>=0.5.5'], + this.patchChannelModel.bind(this), + this.unpatchChannelModel.bind(this) + ); - const connectModuleFile = new InstrumentationNodeModuleFile( + const connectModuleFile = new InstrumentationNodeModuleFile( 'amqplib/lib/connect.js', ['>=0.5.5'], this.patchConnect.bind(this), this.unpatchConnect.bind(this) ); - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( 'amqplib', ['>=0.5.5'], undefined, @@ -231,14 +234,14 @@ export class AmqplibInstrumentation extends InstrumentationBase { private getConnectPatch( original: ( - url: string | amqp.Options.Connect, + url: string | Options.Connect, socketOptions: any, - openCallback: (err: any, connection: amqp.Connection) => void - ) => amqp.Connection + openCallback: (err: any, connection: Connection) => void + ) => Connection ) { return function patchedConnect( this: unknown, - url: string | amqp.Options.Connect, + url: string | Options.Connect, socketOptions: any, openCallback: Function ) { @@ -246,7 +249,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { this, url, socketOptions, - function (this: unknown, err, conn: amqp.Connection) { + function (this: unknown, err, conn: Connection) { if (err == null) { const urlAttributes = getConnectionAttributesFromUrl(url); // the type of conn in @types/amqplib is amqp.Connection, but in practice the library send the @@ -321,7 +324,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { const self = this; return function ack( this: InstrumentationConsumeChannel, - message: amqp.Message, + message: Message, allUpToOrRequeue?: boolean, requeue?: boolean ): void { @@ -330,7 +333,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { const requeueResolved = endOperation === EndOperation.Reject ? allUpToOrRequeue : requeue; - const spansNotEnded: { msg: amqp.Message }[] = + const spansNotEnded: { msg: Message }[] = channel[CHANNEL_SPANS_NOT_ENDED] ?? []; const msgIndex = spansNotEnded.findIndex( msgDetails => msgDetails.msg === message @@ -367,7 +370,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { }; } - protected getConsumePatch( + private getConsumePatch( moduleVersion: string | undefined, original: Function ) { @@ -375,9 +378,9 @@ export class AmqplibInstrumentation extends InstrumentationBase { return function consume( this: InstrumentationConsumeChannel, queue: string, - onMessage: (msg: amqp.ConsumeMessage | null) => void, - options?: amqp.Options.Consume - ): Promise { + onMessage: (msg: ConsumeMessage | null) => void, + options?: Options.Consume + ): Promise { const channel = this; if ( !Object.prototype.hasOwnProperty.call(channel, CHANNEL_SPANS_NOT_ENDED) @@ -451,7 +454,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { msg[MESSAGE_STORED_SPAN] = span; } - context.with(trace.setSpan(context.active(), span), () => { + context.with(trace.setSpan(parentContext, span), () => { onMessage.call(this, msg); }); @@ -465,7 +468,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { }; } - protected getConfirmedPublishPatch( + private getConfirmedPublishPatch( moduleVersion: string | undefined, original: Function ) { @@ -475,8 +478,8 @@ export class AmqplibInstrumentation extends InstrumentationBase { exchange: string, routingKey: string, content: Buffer, - options?: amqp.Options.Publish, - callback?: (err: any, ok: amqp.Replies.Empty) => void + options?: Options.Publish, + callback?: (err: any, ok: Replies.Empty) => void ): boolean { const channel = this; const { span, modifiedOptions } = self.createPublishSpan( @@ -510,7 +513,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { const patchedOnConfirm = function ( this: unknown, err: any, - ok: amqp.Replies.Empty + ok: Replies.Empty ) { try { callback?.call(this, err, ok); @@ -562,7 +565,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { }; } - protected getPublishPatch( + private getPublishPatch( moduleVersion: string | undefined, original: Function ) { @@ -572,7 +575,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { exchange: string, routingKey: string, content: Buffer, - options?: amqp.Options.Publish + options?: Options.Publish ): boolean { if (isConfirmChannelTracing(context.active())) { // work already done @@ -623,7 +626,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { exchange: string, routingKey: string, channel: InstrumentationPublishChannel, - options?: amqp.Options.Publish + options?: Options.Publish ) { const normalizedExchange = normalizeExchange(exchange); @@ -689,7 +692,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { operation: EndOperation, requeue: boolean | undefined ) { - const spansNotEnded: { msg: amqp.Message }[] = + const spansNotEnded: { msg: Message }[] = channel[CHANNEL_SPANS_NOT_ENDED] ?? []; spansNotEnded.forEach(msgDetails => { this.endConsumerSpan(msgDetails.msg, isRejected, operation, requeue); @@ -699,7 +702,7 @@ export class AmqplibInstrumentation extends InstrumentationBase { private callConsumeEndHook( span: Span, - msg: amqp.ConsumeMessage, + msg: ConsumeMessage, rejected: boolean | null, endOperation: EndOperation ) { diff --git a/plugins/node/instrumentation-amqplib/src/types.ts b/plugins/node/instrumentation-amqplib/src/types.ts index 66c6140eeb..2e82b471b5 100644 --- a/plugins/node/instrumentation-amqplib/src/types.ts +++ b/plugins/node/instrumentation-amqplib/src/types.ts @@ -15,14 +15,13 @@ */ import { Span } from '@opentelemetry/api'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; -import type * as amqp from 'amqplib'; export interface PublishInfo { moduleVersion: string | undefined; exchange: string; routingKey: string; content: Buffer; - options?: amqp.Options.Publish; + options?: AmqplibPublishOptions; isConfirmChannel?: boolean; } @@ -32,11 +31,11 @@ export interface PublishConfirmedInfo extends PublishInfo { export interface ConsumeInfo { moduleVersion: string | undefined; - msg: amqp.ConsumeMessage; + msg: ConsumeMessage; } export interface ConsumeEndInfo { - msg: amqp.ConsumeMessage; + msg: ConsumeMessage; rejected: boolean | null; endOperation: EndOperation; } @@ -102,3 +101,74 @@ export interface AmqplibInstrumentationConfig extends InstrumentationConfig { export const DEFAULT_CONFIG: AmqplibInstrumentationConfig = { consumeTimeoutMs: 1000 * 60, // 1 minute }; + +// The following types are vendored from `@types/amqplib@0.10.1` - commit SHA: 4205e03127692a40b4871709a7134fe4e2ed5510 + +// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L108 +// This exists in `@types/amqplib` as `Options.Publish`. We're renaming things +// here to avoid importing the whole Options namespace. +export interface AmqplibPublishOptions { + expiration?: string | number; + userId?: string; + CC?: string | string[]; + + mandatory?: boolean; + persistent?: boolean; + deliveryMode?: boolean | number; + BCC?: string | string[]; + + contentType?: string; + contentEncoding?: string; + headers?: any; + priority?: number; + correlationId?: string; + replyTo?: string; + messageId?: string; + timestamp?: number; + type?: string; + appId?: string; +} + +// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L142 +export interface Message { + content: Buffer; + fields: MessageFields; + properties: MessageProperties; +} + +export interface ConsumeMessage extends Message { + fields: ConsumeMessageFields; +} + +export interface CommonMessageFields { + deliveryTag: number; + redelivered: boolean; + exchange: string; + routingKey: string; +} + +export interface MessageFields extends CommonMessageFields { + messageCount?: number; + consumerTag?: string; +} + +export interface ConsumeMessageFields extends CommonMessageFields { + deliveryTag: number; +} + +export interface MessageProperties { + contentType: any | undefined; + contentEncoding: any | undefined; + headers: any; + deliveryMode: any | undefined; + priority: any | undefined; + correlationId: any | undefined; + replyTo: any | undefined; + expiration: any | undefined; + messageId: any | undefined; + timestamp: any | undefined; + type: any | undefined; + userId: any | undefined; + appId: any | undefined; + clusterId: any | undefined; +} diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts index e9fbdf96e8..9f2ab1d81e 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts @@ -28,7 +28,7 @@ import { MessagingDestinationKindValues, SemanticAttributes, } from '@opentelemetry/semantic-conventions'; -import { context, SpanKind } from '@opentelemetry/api'; +import { Baggage, context, propagation, SpanKind } from '@opentelemetry/api'; import { asyncConfirmSend, asyncConsume, shouldTest } from './utils'; import { censoredUrl, @@ -36,12 +36,27 @@ import { TEST_RABBITMQ_HOST, TEST_RABBITMQ_PORT, } from './config'; +import { + CompositePropagator, + W3CBaggagePropagator, + W3CTraceContextPropagator, +} from '@opentelemetry/core'; const msgPayload = 'payload from test'; const queueName = 'queue-name-from-unittest'; describe('amqplib instrumentation callback model', () => { let conn: amqpCallback.Connection; + before(() => { + propagation.setGlobalPropagator( + new CompositePropagator({ + propagators: [ + new W3CBaggagePropagator(), + new W3CTraceContextPropagator(), + ], + }) + ); + }); before(function (done) { if (!shouldTest) { this.skip(); @@ -186,6 +201,35 @@ describe('amqplib instrumentation callback model', () => { }); }); + it('baggage is available while consuming', done => { + const baggageContext = propagation.setBaggage( + context.active(), + propagation.createBaggage({ + key1: { value: 'value1' }, + }) + ); + context.with(baggageContext, () => { + channel.sendToQueue(queueName, Buffer.from(msgPayload)); + let extractedBaggage: Baggage | undefined; + asyncConsume( + channel, + queueName, + [ + msg => { + extractedBaggage = propagation.getActiveBaggage(); + }, + ], + { + noAck: true, + } + ).then(() => { + expect(extractedBaggage).toBeDefined(); + expect(extractedBaggage!.getEntry('key1')).toBeDefined(); + done(); + }); + }); + }); + it('end span with ack sync', done => { channel.sendToQueue(queueName, Buffer.from(msgPayload)); diff --git a/plugins/node/instrumentation-dataloader/CHANGELOG.md b/plugins/node/instrumentation-dataloader/CHANGELOG.md index 6116c0cc7f..e68c02a4e1 100644 --- a/plugins/node/instrumentation-dataloader/CHANGELOG.md +++ b/plugins/node/instrumentation-dataloader/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [0.4.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dataloader-v0.4.0...instrumentation-dataloader-v0.4.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.4.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dataloader-v0.3.1...instrumentation-dataloader-v0.4.0) (2023-02-14) + + +### Features + +* **instrumentation-dataloader:** add dataloader name to span names ([#1345](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1345)) ([712b559](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/712b559416e0d86ef29ed06d46c180ef8360b411)) + +## [0.3.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dataloader-v0.3.0...instrumentation-dataloader-v0.3.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.3.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dataloader-v0.2.1...instrumentation-dataloader-v0.3.0) (2022-11-16) diff --git a/plugins/node/instrumentation-dataloader/package.json b/plugins/node/instrumentation-dataloader/package.json index 630445dd7d..06ced203ab 100644 --- a/plugins/node/instrumentation-dataloader/package.json +++ b/plugins/node/instrumentation-dataloader/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-dataloader", - "version": "0.3.0", + "version": "0.4.1", "description": "OpenTelemetry instrumentation for dataloader", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -52,17 +52,16 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "dataloader": "2.0.0", - "gts": "3.1.0", + "dataloader": "2.2.1", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-dataloader#readme" } diff --git a/plugins/node/instrumentation-dataloader/src/instrumentation.ts b/plugins/node/instrumentation-dataloader/src/instrumentation.ts index a7acddf805..7264d031ae 100644 --- a/plugins/node/instrumentation-dataloader/src/instrumentation.ts +++ b/plugins/node/instrumentation-dataloader/src/instrumentation.ts @@ -36,6 +36,9 @@ const MODULE_NAME = 'dataloader'; type DataloaderInternal = typeof Dataloader.prototype & { _batchLoadFn: Dataloader.BatchLoadFn; _batch: { spanLinks?: Link[] } | null; + + // TODO: Remove this once types on Dataloader get fixed https://github.com/graphql/dataloader/pull/334 + name?: string | null; }; type LoadFn = (typeof Dataloader.prototype)['load']; @@ -89,40 +92,53 @@ export class DataloaderInstrumentation extends InstrumentationBase { return hasParentSpan || !config.requireParentSpan; } + private getSpanName( + dataloader: DataloaderInternal, + operation: 'load' | 'loadMany' | 'batch' + ): string { + const dataloaderName = dataloader.name; + if (dataloaderName === undefined || dataloaderName === null) { + return `${MODULE_NAME}.${operation}`; + } + + return `${MODULE_NAME}.${operation} ${dataloaderName}`; + } + private _getPatchedConstructor( constructor: typeof Dataloader ): typeof Dataloader { const prototype = constructor.prototype; - const self = this; + const instrumentation = this; function PatchedDataloader( ...args: ConstructorParameters ) { const inst = new constructor(...args) as DataloaderInternal; - if (!self.isEnabled()) { + if (!instrumentation.isEnabled()) { return inst; } if (isWrapped(inst._batchLoadFn)) { - self._unwrap(inst, '_batchLoadFn'); + instrumentation._unwrap(inst, '_batchLoadFn'); } - self._wrap(inst, '_batchLoadFn', original => { + instrumentation._wrap(inst, '_batchLoadFn', original => { return function patchedBatchLoadFn( this: DataloaderInternal, ...args: Parameters> ) { - if (!self.isEnabled() || !self.shouldCreateSpans()) { + if ( + !instrumentation.isEnabled() || + !instrumentation.shouldCreateSpans() + ) { return original.call(this, ...args); } const parent = context.active(); - const span = self.tracer.startSpan( - `${MODULE_NAME}.batch`, - { - links: this._batch?.spanLinks as Link[] | undefined, - }, + const span = instrumentation.tracer.startSpan( + instrumentation.getSpanName(inst, 'batch'), + { links: this._batch?.spanLinks as Link[] | undefined }, parent ); @@ -164,7 +180,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { const instrumentation = this; return function patchedLoad( - this: typeof Dataloader.prototype, + this: DataloaderInternal, ...args: Parameters ) { if (!instrumentation.shouldCreateSpans()) { @@ -173,7 +189,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { const parent = context.active(); const span = instrumentation.tracer.startSpan( - `${MODULE_NAME}.load`, + instrumentation.getSpanName(this, 'load'), { kind: SpanKind.CLIENT }, parent ); @@ -222,7 +238,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { const instrumentation = this; return function patchedLoadMany( - this: typeof Dataloader.prototype, + this: DataloaderInternal, ...args: Parameters ) { if (!instrumentation.shouldCreateSpans()) { @@ -231,7 +247,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { const parent = context.active(); const span = instrumentation.tracer.startSpan( - `${MODULE_NAME}.loadMany`, + instrumentation.getSpanName(this, 'loadMany'), { kind: SpanKind.CLIENT }, parent ); diff --git a/plugins/node/instrumentation-dataloader/test/dataloader.test.ts b/plugins/node/instrumentation-dataloader/test/dataloader.test.ts index b7ca578a91..9686c21d2e 100644 --- a/plugins/node/instrumentation-dataloader/test/dataloader.test.ts +++ b/plugins/node/instrumentation-dataloader/test/dataloader.test.ts @@ -140,6 +140,29 @@ describe('DataloaderInstrumentation', () => { message: 'Error message', }); }); + + it('correctly uses dataloader name (if available)', async () => { + const namedDataloader = new Dataloader( + async keys => keys.map((_, idx) => idx), + { name: 'test-name' } + ); + + assert.strictEqual(await namedDataloader.load('test'), 0); + + // We should have exactly two spans (one for .load and one for the following batch) + assert.strictEqual(memoryExporter.getFinishedSpans().length, 2); + const [batchSpan, loadSpan] = memoryExporter.getFinishedSpans(); + + if ((namedDataloader as { name?: string | null }).name === undefined) { + // For versions of dataloader package that does not support name, we should + // not be adding anything to the names + assert.strictEqual(loadSpan.name, 'dataloader.load'); + assert.strictEqual(batchSpan.name, 'dataloader.batch'); + } else { + assert.strictEqual(loadSpan.name, 'dataloader.load test-name'); + assert.strictEqual(batchSpan.name, 'dataloader.batch test-name'); + } + }); }); describe('loadMany', () => { @@ -235,6 +258,33 @@ describe('DataloaderInstrumentation', () => { code: SpanStatusCode.UNSET, }); }); + + it('correctly uses a generated name in spans', async () => { + const namedDataloader = new Dataloader( + async keys => keys.map((_, idx) => idx), + { name: 'test-name' } + ); + + assert.deepStrictEqual(await namedDataloader.loadMany(['test']), [0]); + + // We should have exactly three spans (one for .loadMany, one for the underlying .load + // and one for the following batch) + assert.strictEqual(memoryExporter.getFinishedSpans().length, 3); + const [batchSpan, loadSpan, loadManySpan] = + memoryExporter.getFinishedSpans(); + + if ((namedDataloader as { name?: string | null }).name === undefined) { + // For versions of dataloader package that does not support name, we should + // not be adding anything to the names + assert.strictEqual(batchSpan.name, 'dataloader.batch'); + assert.strictEqual(loadManySpan.name, 'dataloader.loadMany'); + assert.strictEqual(loadSpan.name, 'dataloader.load'); + } else { + assert.strictEqual(batchSpan.name, 'dataloader.batch test-name'); + assert.strictEqual(loadManySpan.name, 'dataloader.loadMany test-name'); + assert.strictEqual(loadSpan.name, 'dataloader.load test-name'); + } + }); }); it('should not create anything if disabled', async () => { diff --git a/plugins/node/instrumentation-fs/CHANGELOG.md b/plugins/node/instrumentation-fs/CHANGELOG.md index 3c7feabca1..70a5e3083a 100644 --- a/plugins/node/instrumentation-fs/CHANGELOG.md +++ b/plugins/node/instrumentation-fs/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## [0.7.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fs-v0.7.1...instrumentation-fs-v0.7.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.7.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fs-v0.7.0...instrumentation-fs-v0.7.1) (2023-03-03) + + +### Bug Fixes + +* **instrumentation-fs:** allow realpath.native and realpathSync.native ([#1332](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1332)) ([ee0a59a](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ee0a59a59e94743b9411e10c09720a82c6586eb4)) +* **instrumentation-fs:** fix instrumentation of `fs/promises` ([#1375](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1375)) ([3ca874e](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/3ca874e45ebf4623e76cbe9305e55e820b6e03fd)) + +## [0.7.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fs-v0.6.0...instrumentation-fs-v0.7.0) (2023-02-07) + + +### Features + +* **instrumentation-fs:** require parent span ([#1335](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1335)) ([79b2d3f](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/79b2d3ff08904ce84c6bc48427cd98906c2f0d79)) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.6.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fs-v0.5.1...instrumentation-fs-v0.6.0) (2022-11-16) diff --git a/plugins/node/instrumentation-fs/package.json b/plugins/node/instrumentation-fs/package.json index 31f4102714..c40cd51e89 100644 --- a/plugins/node/instrumentation-fs/package.json +++ b/plugins/node/instrumentation-fs/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-fs", - "version": "0.6.0", + "version": "0.7.2", "description": "OpenTelemetry automatic instrumentation package for fs", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -50,17 +50,16 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "^10.0.11", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-fs#readme" diff --git a/plugins/node/instrumentation-fs/src/constants.ts b/plugins/node/instrumentation-fs/src/constants.ts index 4b2a8ac0fc..a8588aae8f 100644 --- a/plugins/node/instrumentation-fs/src/constants.ts +++ b/plugins/node/instrumentation-fs/src/constants.ts @@ -67,6 +67,7 @@ export const CALLBACK_FUNCTIONS: FMember[] = [ 'readFile', 'readlink', 'realpath', + 'realpath.native', 'rename', 'rm', // added in v14 'rmdir', @@ -111,6 +112,7 @@ export const SYNC_FUNCTIONS: FMember[] = [ 'readFileSync', 'readlinkSync', 'realpathSync', + 'realpathSync.native', 'renameSync', 'rmdirSync', 'rmSync', // added in v14 diff --git a/plugins/node/instrumentation-fs/src/instrumentation.ts b/plugins/node/instrumentation-fs/src/instrumentation.ts index e10bf16bad..048b8d7b34 100644 --- a/plugins/node/instrumentation-fs/src/instrumentation.ts +++ b/plugins/node/instrumentation-fs/src/instrumentation.ts @@ -36,17 +36,30 @@ import type { FsInstrumentationConfig, } from './types'; import { promisify } from 'util'; +import { indexFs } from './utils'; type FS = typeof fs; +type FSPromises = (typeof fs)['promises']; -const supportsPromises = parseInt(process.versions.node.split('.')[0], 10) > 8; +/** + * This is important for 2-level functions like `realpath.native` to retain the 2nd-level + * when patching the 1st-level. + */ +function patchedFunctionWithOriginalProperties< + T extends (...args: any[]) => ReturnType +>(patchedFunction: T, original: T): T { + return Object.assign(patchedFunction, original); +} export default class FsInstrumentation extends InstrumentationBase { constructor(config?: FsInstrumentationConfig) { super('@opentelemetry/instrumentation-fs', VERSION, config); } - init(): InstrumentationNodeModuleDefinition[] { + init(): ( + | InstrumentationNodeModuleDefinition + | InstrumentationNodeModuleDefinition + )[] { return [ new InstrumentationNodeModuleDefinition( 'fs', @@ -54,46 +67,47 @@ export default class FsInstrumentation extends InstrumentationBase { (fs: FS) => { this._diag.debug('Applying patch for fs'); for (const fName of SYNC_FUNCTIONS) { - if (isWrapped(fs[fName])) { - this._unwrap(fs, fName); + const { objectToPatch, functionNameToPatch } = indexFs(fs, fName); + + if (isWrapped(objectToPatch[functionNameToPatch])) { + this._unwrap(objectToPatch, functionNameToPatch); } this._wrap( - fs, - fName, + objectToPatch, + functionNameToPatch, this._patchSyncFunction.bind(this, fName) ); } for (const fName of CALLBACK_FUNCTIONS) { - if (isWrapped(fs[fName])) { - this._unwrap(fs, fName); + const { objectToPatch, functionNameToPatch } = indexFs(fs, fName); + if (isWrapped(objectToPatch[functionNameToPatch])) { + this._unwrap(objectToPatch, functionNameToPatch); } if (fName === 'exists') { // handling separately because of the inconsistent cb style: // `exists` doesn't have error as the first argument, but the result this._wrap( - fs, - fName, + objectToPatch, + functionNameToPatch, this._patchExistsCallbackFunction.bind(this, fName) ); continue; } this._wrap( - fs, - fName, + objectToPatch, + functionNameToPatch, this._patchCallbackFunction.bind(this, fName) ); } - if (supportsPromises) { - for (const fName of PROMISE_FUNCTIONS) { - if (isWrapped(fs.promises[fName])) { - this._unwrap(fs.promises, fName); - } - this._wrap( - fs.promises, - fName, - this._patchPromiseFunction.bind(this, fName) - ); + for (const fName of PROMISE_FUNCTIONS) { + if (isWrapped(fs.promises[fName])) { + this._unwrap(fs.promises, fName); } + this._wrap( + fs.promises, + fName, + this._patchPromiseFunction.bind(this, fName) + ); } return fs; }, @@ -101,20 +115,47 @@ export default class FsInstrumentation extends InstrumentationBase { if (fs === undefined) return; this._diag.debug('Removing patch for fs'); for (const fName of SYNC_FUNCTIONS) { - if (isWrapped(fs[fName])) { - this._unwrap(fs, fName); + const { objectToPatch, functionNameToPatch } = indexFs(fs, fName); + if (isWrapped(objectToPatch[functionNameToPatch])) { + this._unwrap(objectToPatch, functionNameToPatch); } } for (const fName of CALLBACK_FUNCTIONS) { - if (isWrapped(fs[fName])) { - this._unwrap(fs, fName); + const { objectToPatch, functionNameToPatch } = indexFs(fs, fName); + if (isWrapped(objectToPatch[functionNameToPatch])) { + this._unwrap(objectToPatch, functionNameToPatch); } } - if (supportsPromises) { - for (const fName of PROMISE_FUNCTIONS) { - if (isWrapped(fs.promises[fName])) { - this._unwrap(fs.promises, fName); - } + for (const fName of PROMISE_FUNCTIONS) { + if (isWrapped(fs.promises[fName])) { + this._unwrap(fs.promises, fName); + } + } + } + ), + new InstrumentationNodeModuleDefinition( + 'fs/promises', + ['*'], + (fsPromises: FSPromises) => { + this._diag.debug('Applying patch for fs/promises'); + for (const fName of PROMISE_FUNCTIONS) { + if (isWrapped(fsPromises[fName])) { + this._unwrap(fsPromises, fName); + } + this._wrap( + fsPromises, + fName, + this._patchPromiseFunction.bind(this, fName) + ); + } + return fsPromises; + }, + (fsPromises: FSPromises) => { + if (fsPromises === undefined) return; + this._diag.debug('Removing patch for fs/promises'); + for (const fName of PROMISE_FUNCTIONS) { + if (isWrapped(fsPromises[fName])) { + this._unwrap(fsPromises, fName); } } } @@ -127,7 +168,7 @@ export default class FsInstrumentation extends InstrumentationBase { original: T ): T { const instrumentation = this; - return function (this: any, ...args: any[]) { + const patchedFunction = function (this: any, ...args: any[]) { const activeContext = api.context.active(); if (!instrumentation._shouldTrace(activeContext)) { @@ -160,7 +201,7 @@ export default class FsInstrumentation extends InstrumentationBase { ); instrumentation._runEndHook(functionName, { args: args, span }); return res; - } catch (error) { + } catch (error: any) { span.recordException(error); span.setStatus({ message: error.message, @@ -172,6 +213,7 @@ export default class FsInstrumentation extends InstrumentationBase { span.end(); } }; + return patchedFunctionWithOriginalProperties(patchedFunction, original); } protected _patchCallbackFunction ReturnType>( @@ -179,7 +221,7 @@ export default class FsInstrumentation extends InstrumentationBase { original: T ): T { const instrumentation = this; - return function (this: any, ...args: any[]) { + const patchedFunction = function (this: any, ...args: any[]) { const activeContext = api.context.active(); if (!instrumentation._shouldTrace(activeContext)) { @@ -234,7 +276,7 @@ export default class FsInstrumentation extends InstrumentationBase { this, ...args ); - } catch (error) { + } catch (error: any) { span.recordException(error); span.setStatus({ message: error.message, @@ -253,11 +295,12 @@ export default class FsInstrumentation extends InstrumentationBase { return original.apply(this, args); } }; + return patchedFunctionWithOriginalProperties(patchedFunction, original); } protected _patchExistsCallbackFunction< T extends (...args: any[]) => ReturnType - >(functionName: FMember, original: T): T { + >(functionName: 'exists', original: T): T { const instrumentation = this; const patchedFunction = function (this: any, ...args: any[]) { const activeContext = api.context.active(); @@ -307,7 +350,7 @@ export default class FsInstrumentation extends InstrumentationBase { this, ...args ); - } catch (error) { + } catch (error: any) { span.recordException(error); span.setStatus({ message: error.message, @@ -325,18 +368,22 @@ export default class FsInstrumentation extends InstrumentationBase { return original.apply(this, args); } }; + const functionWithOriginalProperties = + patchedFunctionWithOriginalProperties(patchedFunction, original); // `exists` has a custom promisify function because of the inconsistent signature // replicating that on the patched function const promisified = function (path: unknown) { - return new Promise(resolve => patchedFunction(path, resolve)); + return new Promise(resolve => + functionWithOriginalProperties(path, resolve) + ); }; Object.defineProperty(promisified, 'name', { value: functionName }); - Object.defineProperty(patchedFunction, promisify.custom, { + Object.defineProperty(functionWithOriginalProperties, promisify.custom, { value: promisified, }); - return patchedFunction; + return functionWithOriginalProperties; } protected _patchPromiseFunction ReturnType>( @@ -344,7 +391,7 @@ export default class FsInstrumentation extends InstrumentationBase { original: T ): T { const instrumentation = this; - return async function (this: any, ...args: any[]) { + const patchedFunction = async function (this: any, ...args: any[]) { const activeContext = api.context.active(); if (!instrumentation._shouldTrace(activeContext)) { @@ -377,7 +424,7 @@ export default class FsInstrumentation extends InstrumentationBase { ); instrumentation._runEndHook(functionName, { args: args, span }); return res; - } catch (error) { + } catch (error: any) { span.recordException(error); span.setStatus({ message: error.message, @@ -389,6 +436,7 @@ export default class FsInstrumentation extends InstrumentationBase { span.end(); } }; + return patchedFunctionWithOriginalProperties(patchedFunction, original); } protected _runCreateHook( diff --git a/plugins/node/instrumentation-fs/src/types.ts b/plugins/node/instrumentation-fs/src/types.ts index 0b4e3caeef..fe0a4132c5 100644 --- a/plugins/node/instrumentation-fs/src/types.ts +++ b/plugins/node/instrumentation-fs/src/types.ts @@ -18,13 +18,40 @@ import type * as fs from 'fs'; import type * as api from '@opentelemetry/api'; import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; -export type FunctionPropertyNames = { - [K in keyof T]: T[K] extends Function ? K : never; -}[keyof T]; +export type FunctionPropertyNames = Exclude< + { + [K in keyof T]: T[K] extends Function ? K : never; + }[keyof T], + undefined +>; export type FunctionProperties = Pick>; -export type FMember = FunctionPropertyNames; -export type FPMember = FunctionPropertyNames<(typeof fs)['promises']>; +export type FunctionPropertyNamesTwoLevels = Exclude< + { + [K in keyof T]: { + [L in keyof T[K]]: L extends string + ? T[K][L] extends Function + ? K extends string + ? L extends string + ? `${K}.${L}` + : never + : never + : never + : never; + }[keyof T[K]]; + }[keyof T], + undefined +>; + +export type Member = + | FunctionPropertyNames + | FunctionPropertyNamesTwoLevels; +export type FMember = + | FunctionPropertyNames + | FunctionPropertyNamesTwoLevels; +export type FPMember = + | FunctionPropertyNames<(typeof fs)['promises']> + | FunctionPropertyNamesTwoLevels<(typeof fs)['promises']>; export type CreateHook = ( functionName: FMember | FPMember, diff --git a/plugins/node/instrumentation-fs/src/utils.ts b/plugins/node/instrumentation-fs/src/utils.ts new file mode 100644 index 0000000000..3a8c37149f --- /dev/null +++ b/plugins/node/instrumentation-fs/src/utils.ts @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { FunctionPropertyNames, FMember } from './types'; +import type * as fs from 'fs'; +type FS = typeof fs; + +export function splitTwoLevels( + functionName: FMember +): + | [FunctionPropertyNames & string] + | [FunctionPropertyNames & string, string] { + const memberParts = functionName.split('.'); + if (memberParts.length > 1) { + if (memberParts.length !== 2) + throw Error(`Invalid member function name ${functionName}`); + return memberParts as [FunctionPropertyNames & string, string]; + } else { + return [functionName as FunctionPropertyNames & string]; + } +} + +export function indexFs( + fs: FSObject, + member: FMember +): { objectToPatch: any; functionNameToPatch: string } { + if (!member) throw new Error(JSON.stringify({ member })); + const splitResult = splitTwoLevels(member); + const [functionName1, functionName2] = splitResult; + if (functionName2) { + return { + objectToPatch: fs[functionName1], + functionNameToPatch: functionName2, + }; + } else { + return { + objectToPatch: fs, + functionNameToPatch: functionName1, + }; + } +} diff --git a/plugins/node/instrumentation-fs/test/definitions.ts b/plugins/node/instrumentation-fs/test/definitions.ts index 551f104986..ed4a0673bc 100644 --- a/plugins/node/instrumentation-fs/test/definitions.ts +++ b/plugins/node/instrumentation-fs/test/definitions.ts @@ -17,16 +17,21 @@ import { FMember, FPMember } from '../src/types'; import * as fs from 'fs'; -export type FsFunction = FPMember & FMember; +export type FsFunction = FMember; export type Opts = { sync?: boolean; callback?: boolean; promise?: boolean; }; -export type Result = { error?: RegExp; result?: any; resultAsError?: any }; +export type Result = { + error?: RegExp; + result?: any; + resultAsError?: any; + hasPromiseVersion?: boolean; +}; export type TestCase = [FsFunction, any[], Result, any[], Opts?]; -export type TestCreator = ( - name: FsFunction, +export type TestCreator = ( + name: Member, args: any[], result: Result, spans: any[] @@ -77,6 +82,13 @@ const tests: TestCase[] = [ { resultAsError: true }, [{ name: 'fs %NAME' }], ], + ['realpath', ['/./'], { result: '/' }, [{ name: 'fs %NAME' }]], + [ + 'realpath.native', + ['/./'], + { result: '/', hasPromiseVersion: false }, + [{ name: 'fs %NAME' }], + ], ]; export default tests; diff --git a/plugins/node/instrumentation-fs/test/index.test.ts b/plugins/node/instrumentation-fs/test/fs.test.ts similarity index 76% rename from plugins/node/instrumentation-fs/test/index.test.ts rename to plugins/node/instrumentation-fs/test/fs.test.ts index cb49a5f5d0..e8f97b6ab2 100644 --- a/plugins/node/instrumentation-fs/test/index.test.ts +++ b/plugins/node/instrumentation-fs/test/fs.test.ts @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { context, trace, SpanStatusCode, SpanKind } from '@opentelemetry/api'; +import { context, trace } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { BasicTracerProvider, InMemorySpanExporter, - ReadableSpan, SimpleSpanProcessor, } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; @@ -28,8 +27,13 @@ import * as sinon from 'sinon'; import type * as FSType from 'fs'; import tests, { TestCase, TestCreator } from './definitions'; import type { FMember, FPMember, CreateHook, EndHook } from '../src/types'; - -const supportsPromises = parseInt(process.versions.node.split('.')[0], 10) > 8; +import { + CALLBACK_FUNCTIONS, + PROMISE_FUNCTIONS, + SYNC_FUNCTIONS, +} from '../src/constants'; +import { indexFs, splitTwoLevels } from '../src/utils'; +import { assertSpans, makeRootSpanName } from './utils'; const TEST_ATTRIBUTE = 'test.attr'; const TEST_VALUE = 'test.attr.value'; @@ -38,7 +42,7 @@ const createHook = sinon.spy( (fnName: FMember | FPMember, { args, span }) => { // `ts-node`, which we use via `ts-mocha` also patches module loading and creates // a lot of unrelated spans. Filter those out. - if (['readFileSync', 'existsSync'].includes(fnName)) { + if (['readFileSync', 'existsSync'].includes(fnName as string)) { const filename = args[0]; if (!/test\/fixtures/.test(filename)) { return false; @@ -87,24 +91,41 @@ describe('fs instrumentation', () => { context.disable(); }); - const syncTest: TestCreator = ( + const syncTest: TestCreator = ( name: FMember, args, { error, result, resultAsError = null }, spans ) => { - const syncName: FMember = `${name}Sync` as FMember; + const [functionNamePart1, functionNamePart2] = + splitTwoLevels(name); + const syncName = `${functionNamePart1}Sync${ + functionNamePart2 ? `.${functionNamePart2}` : '' + }` as FMember; const rootSpanName = `${syncName} test span`; it(`${syncName} ${error ? 'error' : 'success'}`, () => { + const { objectToPatch, functionNameToPatch } = indexFs(fs, syncName); const rootSpan = tracer.startSpan(rootSpanName); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); context.with(trace.setSpan(context.active(), rootSpan), () => { if (error) { - assert.throws(() => Reflect.apply(fs[syncName], fs, args), error); + assert.throws( + () => + Reflect.apply( + objectToPatch[functionNameToPatch], + objectToPatch, + args + ), + error + ); } else { assert.deepEqual( - Reflect.apply(fs[syncName], fs, args), + Reflect.apply( + objectToPatch[functionNameToPatch], + objectToPatch, + args + ), result ?? resultAsError ); } @@ -129,20 +150,21 @@ describe('fs instrumentation', () => { }); }; - const callbackTest: TestCreator = ( + const callbackTest: TestCreator = ( name: FMember, args, { error, result, resultAsError = null }, spans ) => { - const rootSpanName = `${name} test span`; + const rootSpanName = makeRootSpanName(name); it(`${name} ${error ? 'error' : 'success'}`, done => { + const { objectToPatch, functionNameToPatch } = indexFs(fs, name); const rootSpan = tracer.startSpan(rootSpanName); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); context.with(trace.setSpan(context.active(), rootSpan), () => { - (fs[name] as Function)( + (objectToPatch[functionNameToPatch] as Function)( ...args, (actualError: any | undefined, actualResult: any) => { assert.strictEqual(trace.getSpan(context.active()), rootSpan); @@ -199,13 +221,14 @@ describe('fs instrumentation', () => { }); }; - const promiseTest: TestCreator = ( + const promiseTest: TestCreator = ( name: FPMember, args, - { error, result, resultAsError = null }, + { error, result, resultAsError = null, hasPromiseVersion = true }, spans ) => { - const rootSpanName = `${name} test span`; + if (!hasPromiseVersion) return; + const rootSpanName = makeRootSpanName(name); it(`promises.${name} ${error ? 'error' : 'success'}`, async () => { const rootSpan = tracer.startSpan(rootSpanName); @@ -260,6 +283,43 @@ describe('fs instrumentation', () => { }); }; + describe('Synchronous API native', () => { + beforeEach(() => { + plugin.enable(); + }); + it('should not remove fs functions', () => { + const isNode14 = process.versions.node.startsWith('14'); + const node14MissingFunctionNames = new Set([ + 'cpSync', + 'cp', + 'promises.cp', + ]); + for (const fname of [...SYNC_FUNCTIONS, ...CALLBACK_FUNCTIONS]) { + // some function were added after node 14 + if (node14MissingFunctionNames.has(fname) && isNode14) continue; + + const { objectToPatch, functionNameToPatch } = indexFs(fs, fname); + assert.strictEqual( + typeof objectToPatch[functionNameToPatch], + 'function', + `fs.${fname} is not a function` + ); + } + for (const fname of PROMISE_FUNCTIONS) { + if (node14MissingFunctionNames.has(fname) && isNode14) continue; + const { objectToPatch, functionNameToPatch } = indexFs( + fs.promises, + fname + ); + assert.strictEqual( + typeof objectToPatch[functionNameToPatch], + 'function', + `fs.promises.${fname} is not a function` + ); + } + }); + }); + describe('Syncronous API', () => { const selection: TestCase[] = tests.filter( ([, , , , options = {}]) => options.sync !== false @@ -351,74 +411,25 @@ describe('fs instrumentation', () => { }); }); - if (supportsPromises) { - describe('Promise API', () => { - const selection: TestCase[] = tests.filter( - ([, , , , options = {}]) => options.promise !== false - ); + describe('Promise API', () => { + const selection: TestCase[] = tests.filter( + ([, , , , options = {}]) => options.promise !== false + ); - describe('Instrumentation enabled', () => { - selection.forEach(([name, args, result, spans]) => { - promiseTest(name as FPMember, args, result, spans); - }); + describe('Instrumentation enabled', () => { + selection.forEach(([name, args, result, spans]) => { + promiseTest(name as FPMember, args, result, spans); }); + }); - describe('Instrumentation disabled', () => { - beforeEach(() => { - plugin.disable(); - }); + describe('Instrumentation disabled', () => { + beforeEach(() => { + plugin.disable(); + }); - selection.forEach(([name, args, result]) => { - promiseTest(name as FPMember, args, result, []); - }); + selection.forEach(([name, args, result]) => { + promiseTest(name as FPMember, args, result, []); }); }); - } -}); - -const assertSpans = (spans: ReadableSpan[], expected: any) => { - assert.strictEqual( - spans.length, - expected.length, - `Expected ${expected.length} spans, got ${spans.length}(${spans - .map((s: any) => `"${s.name}"`) - .join(', ')})` - ); - - spans.forEach((span, i) => { - assertSpan(span, expected[i]); }); -}; - -const assertSpan = (span: ReadableSpan, expected: any) => { - assert(span); - assert.strictEqual(span.name, expected.name); - assert.strictEqual( - span.kind, - SpanKind.INTERNAL, - 'Expected to be of INTERNAL kind' - ); - if (expected.parentSpan) { - assert.strictEqual( - span.parentSpanId, - expected.parentSpan.spanContext().spanId - ); - } - if (expected.attributes) { - assert.deepEqual(span.attributes, expected.attributes); - } - if (expected.error) { - assert( - expected.error.test(span.status.message), - `Expected "${span.status.message}" to match ${expected.error}` - ); - assert.strictEqual(span.status.code, SpanStatusCode.ERROR); - } else { - assert.strictEqual( - span.status.code, - SpanStatusCode.UNSET, - 'Expected status to be unset' - ); - assert.strictEqual(span.status.message, undefined); - } -}; +}); diff --git a/plugins/node/instrumentation-fs/test/hooks.test.ts b/plugins/node/instrumentation-fs/test/fsHooks.test.ts similarity index 84% rename from plugins/node/instrumentation-fs/test/hooks.test.ts rename to plugins/node/instrumentation-fs/test/fsHooks.test.ts index a85c83fcc2..1ae9e5b0eb 100644 --- a/plugins/node/instrumentation-fs/test/hooks.test.ts +++ b/plugins/node/instrumentation-fs/test/fsHooks.test.ts @@ -24,8 +24,6 @@ import * as sinon from 'sinon'; import type * as FSType from 'fs'; import type { FsInstrumentationConfig } from '../src/types'; -const supportsPromises = parseInt(process.versions.node.split('.')[0], 10) > 8; - const createHookError = new Error('createHook failed'); const createHook = sinon.spy((_functionName: string) => { throw createHookError; @@ -107,7 +105,7 @@ describe('fs instrumentation: hooks', () => { it('should not shadow the error from original call when hooks throw', () => { try { fs.accessSync('./test/fixtures/readtest-404', fs.constants.R_OK); - } catch (e) { + } catch (e: any) { assertNotHookError(e); } @@ -142,23 +140,21 @@ describe('fs instrumentation: hooks', () => { }); }); - if (supportsPromises) { - describe('Promise API', () => { - it('should not fail the original successful call when hooks throw', async () => { - // eslint-disable-next-line node/no-unsupported-features/node-builtins - await fs.promises.access('./test/fixtures/readtest', fs.constants.R_OK); + describe('Promise API', () => { + it('should not fail the original successful call when hooks throw', async () => { + // eslint-disable-next-line node/no-unsupported-features/node-builtins + await fs.promises.access('./test/fixtures/readtest', fs.constants.R_OK); - assertSuccessfulCallHooks('access'); - }); + assertSuccessfulCallHooks('access'); + }); - it('should not shadow the error from original call when hooks throw', async () => { - // eslint-disable-next-line node/no-unsupported-features/node-builtins - await fs.promises - .access('./test/fixtures/readtest-404', fs.constants.R_OK) - .catch(assertNotHookError); + it('should not shadow the error from original call when hooks throw', async () => { + // eslint-disable-next-line node/no-unsupported-features/node-builtins + await fs.promises + .access('./test/fixtures/readtest-404', fs.constants.R_OK) + .catch(assertNotHookError); - assertFailingCallHooks('access'); - }); + assertFailingCallHooks('access'); }); - } + }); }); diff --git a/plugins/node/instrumentation-fs/test/fsPromises.test.ts b/plugins/node/instrumentation-fs/test/fsPromises.test.ts new file mode 100644 index 0000000000..9af00a13a5 --- /dev/null +++ b/plugins/node/instrumentation-fs/test/fsPromises.test.ts @@ -0,0 +1,148 @@ +/* + * 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 { context, trace } from '@opentelemetry/api'; +import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; +import { + BasicTracerProvider, + InMemorySpanExporter, + SimpleSpanProcessor, +} from '@opentelemetry/sdk-trace-base'; +import * as assert from 'assert'; +import Instrumentation from '../src'; +import * as sinon from 'sinon'; +import type * as FSPromisesType from 'fs/promises'; +import tests, { FsFunction, TestCase, TestCreator } from './definitions'; +import type { FPMember, EndHook } from '../src/types'; +import { assertSpans, makeRootSpanName } from './utils'; + +const TEST_ATTRIBUTE = 'test.attr'; +const TEST_VALUE = 'test.attr.value'; + +const endHook = sinon.spy((fnName, { args, span }) => { + span.setAttribute(TEST_ATTRIBUTE, TEST_VALUE); +}); +const pluginConfig = { + endHook, +}; +const provider = new BasicTracerProvider(); +const tracer = provider.getTracer('default'); +const memoryExporter = new InMemorySpanExporter(); +provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + +describe('fs/promises instrumentation', () => { + let contextManager: AsyncHooksContextManager; + let fsPromises: typeof FSPromisesType; + let plugin: Instrumentation; + + beforeEach(async () => { + contextManager = new AsyncHooksContextManager(); + context.setGlobalContextManager(contextManager.enable()); + plugin = new Instrumentation(pluginConfig); + plugin.setTracerProvider(provider); + plugin.enable(); + fsPromises = require('fs/promises'); + assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); + }); + + afterEach(() => { + plugin.disable(); + memoryExporter.reset(); + context.disable(); + }); + + const promiseTest: TestCreator = ( + name: FPMember, + args, + { error, result, resultAsError = null, hasPromiseVersion = true }, + spans + ) => { + if (!hasPromiseVersion) return; + const rootSpanName = makeRootSpanName(name); + it(`promises.${name} ${error ? 'error' : 'success'}`, async () => { + const rootSpan = tracer.startSpan(rootSpanName); + + assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); + await context + .with(trace.setSpan(context.active(), rootSpan), () => { + // eslint-disable-next-line node/no-unsupported-features/node-builtins + assert( + typeof fsPromises[name] === 'function', + `Expected fsPromises.${name} to be a function` + ); + return Reflect.apply(fsPromises[name], fsPromises, args); + }) + .then((actualResult: any) => { + if (error) { + assert.fail(`promises.${name} did not reject`); + } else { + assert.deepEqual(actualResult, result ?? resultAsError); + } + }) + .catch((actualError: any) => { + assert( + actualError instanceof Error, + `Expected caugth error to be instance of Error. Got ${actualError}` + ); + if (error) { + assert( + error.test(actualError?.message ?? ''), + `Expected "${actualError?.message}" to match ${error}` + ); + } else { + actualError.message = `Did not expect promises.${name} to reject: ${actualError.message}`; + assert.fail(actualError); + } + }); + rootSpan.end(); + assertSpans(memoryExporter.getFinishedSpans(), [ + ...spans.map((s: any) => { + const spanName = s.name.replace(/%NAME/, name); + const attributes = { + ...(s.attributes ?? {}), + }; + attributes[TEST_ATTRIBUTE] = TEST_VALUE; + return { + ...s, + name: spanName, + attributes, + }; + }), + { name: rootSpanName }, + ]); + }); + }; + + const selection: TestCase[] = tests.filter( + ([name, , , , options = {}]) => + options.promise !== false && name !== ('exists' as FsFunction) + ); + + describe('Instrumentation enabled', () => { + selection.forEach(([name, args, result, spans]) => { + promiseTest(name as FPMember, args, result, spans); + }); + }); + + describe('Instrumentation disabled', () => { + beforeEach(() => { + plugin.disable(); + }); + + selection.forEach(([name, args, result]) => { + promiseTest(name as FPMember, args, result, []); + }); + }); +}); diff --git a/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts b/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts new file mode 100644 index 0000000000..d69be21ed9 --- /dev/null +++ b/plugins/node/instrumentation-fs/test/fsPromisesHooks.test.ts @@ -0,0 +1,117 @@ +/* + * 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 { + BasicTracerProvider, + InMemorySpanExporter, + SimpleSpanProcessor, +} from '@opentelemetry/sdk-trace-base'; +import * as assert from 'assert'; +import Instrumentation from '../src'; +import * as sinon from 'sinon'; +import type * as FSPromisesType from 'fs/promises'; +import type { FsInstrumentationConfig } from '../src/types'; + +const createHookError = new Error('createHook failed'); +const createHook = sinon.spy((_functionName: string) => { + throw createHookError; +}); +const endHookError = new Error('endHook failed'); +const endHook = sinon.spy((_functionName: string) => { + throw endHookError; +}); +const pluginConfig = { + createHook, + endHook, +}; + +const provider = new BasicTracerProvider(); +const memoryExporter = new InMemorySpanExporter(); +provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + +const assertNotHookError = (err?: Error | null) => { + assert.ok( + err && + err.message !== createHookError.message && + err.message !== endHookError.message, + 'Hook error shadowed the error from the original call' + ); +}; + +const assertSuccessfulCallHooks = (expectedFunctionName: string) => { + const createHookCall = createHook.withArgs(expectedFunctionName); + sinon.assert.called(createHookCall); + sinon.assert.threw(createHookCall, createHookError); + + const endHookCall = endHook.withArgs(expectedFunctionName); + sinon.assert.called(endHookCall); + sinon.assert.threw(endHookCall, endHookError); + assert( + !(endHookCall.getCall(0).args as any)[1].error, + 'Did not expect an error' + ); +}; + +const assertFailingCallHooks = (expectedFunctionName: string) => { + const createHookCall = createHook.withArgs(expectedFunctionName); + sinon.assert.called(createHookCall); + sinon.assert.threw(createHookCall, createHookError); + + const endHookCall = endHook.withArgs(expectedFunctionName); + sinon.assert.called(endHookCall); + sinon.assert.threw(endHookCall, endHookError); + assert((endHookCall.getCall(0).args as any)[1].error, 'Expected an error'); +}; + +// This should equal `fs.constants.R_OK`. +// We are hard-coding this because Node 14 and below does not include `constants` in `fsPromises`. +const fsConstantsR_OK = 4; + +describe('fs/promises instrumentation: hooks', () => { + let plugin: Instrumentation; + let fsPromises: typeof FSPromisesType; + + beforeEach(async () => { + plugin = new Instrumentation(pluginConfig); + plugin.setTracerProvider(provider); + plugin.setConfig(pluginConfig as FsInstrumentationConfig); + plugin.enable(); + fsPromises = require('fs/promises'); + createHook.resetHistory(); + endHook.resetHistory(); + assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); + }); + + afterEach(() => { + plugin.disable(); + memoryExporter.reset(); + }); + + it('should not fail the original successful call when hooks throw', async () => { + // eslint-disable-next-line node/no-unsupported-features/node-builtins + await fsPromises.access('./test/fixtures/readtest', fsConstantsR_OK); + + assertSuccessfulCallHooks('access'); + }); + + it('should not shadow the error from original call when hooks throw', async () => { + // eslint-disable-next-line node/no-unsupported-features/node-builtins + await fsPromises + .access('./test/fixtures/readtest-404', fsConstantsR_OK) + .catch(assertNotHookError); + + assertFailingCallHooks('access'); + }); +}); diff --git a/plugins/node/instrumentation-fs/test/parent.test.ts b/plugins/node/instrumentation-fs/test/parent.test.ts index 607149adc0..9ca6d90059 100644 --- a/plugins/node/instrumentation-fs/test/parent.test.ts +++ b/plugins/node/instrumentation-fs/test/parent.test.ts @@ -25,8 +25,6 @@ import type { FsInstrumentationConfig } from '../src/types'; import * as api from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; -const supportsPromises = parseInt(process.versions.node.split('.')[0], 10) > 8; - const provider = new BasicTracerProvider(); const memoryExporter = new InMemorySpanExporter(); provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); @@ -95,22 +93,20 @@ describe('fs instrumentation: requireParentSpan', () => { ); }); - if (supportsPromises) { - it(`${prefix} a span with the promises API`, async () => { - await new Promise(resolve => { - api.context.with(ambientContext, () => { - fs.promises - .access('./test/fixtures/readtest', fs.constants.R_OK) - .finally(() => resolve(endRootSpan())); - }); + it(`${prefix} a span with the promises API`, async () => { + await new Promise(resolve => { + api.context.with(ambientContext, () => { + fs.promises + .access('./test/fixtures/readtest', fs.constants.R_OK) + .finally(() => resolve(endRootSpan())); }); - - assert.deepEqual( - memoryExporter.getFinishedSpans().length, - expectedSpanCount() - ); }); - } + + assert.deepEqual( + memoryExporter.getFinishedSpans().length, + expectedSpanCount() + ); + }); }; const withRootSpan = (fn: () => void) => { diff --git a/plugins/node/instrumentation-fs/test/utils.ts b/plugins/node/instrumentation-fs/test/utils.ts new file mode 100644 index 0000000000..a3f2cd33f7 --- /dev/null +++ b/plugins/node/instrumentation-fs/test/utils.ts @@ -0,0 +1,77 @@ +/* + * 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 { ReadableSpan } from '@opentelemetry/sdk-trace-base'; +import * as assert from 'assert'; +import { SpanKind, SpanStatusCode } from '@opentelemetry/api'; +import type { FMember } from '../src/types'; + +export const assertSpans = (spans: ReadableSpan[], expected: any) => { + assert.strictEqual( + spans.length, + expected.length, + `Expected ${expected.length} spans, got ${spans.length}(${spans + .map((s: any) => `"${s.name}"`) + .join(', ')})` + ); + + spans.forEach((span, i) => { + assertSpan(span, expected[i]); + }); +}; + +const assertSpan = (span: ReadableSpan, expected: any) => { + assert(span); + assert.strictEqual(span.name, expected.name); + assert.strictEqual( + span.kind, + SpanKind.INTERNAL, + 'Expected to be of INTERNAL kind' + ); + if (expected.parentSpan) { + assert.strictEqual( + span.parentSpanId, + expected.parentSpan.spanContext().spanId + ); + } + if (expected.attributes) { + assert.deepEqual(span.attributes, expected.attributes); + } + if (expected.error) { + assert( + expected.error.test(span.status.message), + `Expected "${span.status.message}" to match ${expected.error}` + ); + assert.strictEqual(span.status.code, SpanStatusCode.ERROR); + } else { + assert.strictEqual( + span.status.code, + SpanStatusCode.UNSET, + 'Expected status to be unset' + ); + assert.strictEqual(span.status.message, undefined); + } +}; + +export const makeRootSpanName = (name: FMember): string => { + let rsn: string; + if (Array.isArray(name)) { + rsn = `${name[0]}.${name[1]}`; + } else { + rsn = `${name}`; + } + rsn = `${rsn} test span`; + return rsn; +}; diff --git a/plugins/node/instrumentation-lru-memoizer/CHANGELOG.md b/plugins/node/instrumentation-lru-memoizer/CHANGELOG.md index 59a4f68b07..c8ef8b6d13 100644 --- a/plugins/node/instrumentation-lru-memoizer/CHANGELOG.md +++ b/plugins/node/instrumentation-lru-memoizer/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-lru-memoizer-v0.32.1...instrumentation-lru-memoizer-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-lru-memoizer-v0.32.0...instrumentation-lru-memoizer-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-lru-memoizer-v0.31.0...instrumentation-lru-memoizer-v0.32.0) (2022-11-16) diff --git a/plugins/node/instrumentation-lru-memoizer/package.json b/plugins/node/instrumentation-lru-memoizer/package.json index caec77996e..ff2a39aef4 100644 --- a/plugins/node/instrumentation-lru-memoizer/package.json +++ b/plugins/node/instrumentation-lru-memoizer/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-lru-memoizer", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry automatic instrumentation package for lru-memoizer", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,22 +43,21 @@ }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@types/lru-cache": "7.10.9", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "expect": "29.2.0", - "gts": "3.1.0", "lru-memoizer": "2.1.4", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer#readme" } diff --git a/plugins/node/instrumentation-mongoose/CHANGELOG.md b/plugins/node/instrumentation-mongoose/CHANGELOG.md index a3ed205e5e..205fe474f1 100644 --- a/plugins/node/instrumentation-mongoose/CHANGELOG.md +++ b/plugins/node/instrumentation-mongoose/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongoose-v0.32.1...instrumentation-mongoose-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongoose-v0.32.0...instrumentation-mongoose-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongoose-v0.31.1...instrumentation-mongoose-v0.32.0) (2022-11-16) diff --git a/plugins/node/instrumentation-mongoose/package.json b/plugins/node/instrumentation-mongoose/package.json index 99e77cf6a3..33358620a3 100644 --- a/plugins/node/instrumentation-mongoose/package.json +++ b/plugins/node/instrumentation-mongoose/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-mongoose", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry automatic instrumentation package for mongoose", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -46,23 +46,22 @@ }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "expect": "29.2.0", - "gts": "3.1.0", "mocha": "7.2.0", "mongoose": "6.5.2", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose#readme" diff --git a/plugins/node/instrumentation-mongoose/test/mongoose.test.ts b/plugins/node/instrumentation-mongoose/test/mongoose.test.ts index 9049762e0e..37ce6c70ec 100644 --- a/plugins/node/instrumentation-mongoose/test/mongoose.test.ts +++ b/plugins/node/instrumentation-mongoose/test/mongoose.test.ts @@ -44,7 +44,7 @@ describe('mongoose instrumentation', () => { useCreateIndex: true, dbName: DB_NAME, } as any); // TODO: amir - document older mongoose support - } catch (err) { + } catch (err: any) { // connect signature changed from mongo v5 to v6. // the following check tries both signatures, so test-all-versions // can run against both versions. diff --git a/plugins/node/instrumentation-socket.io/CHANGELOG.md b/plugins/node/instrumentation-socket.io/CHANGELOG.md index b0940745a7..77ef5af556 100644 --- a/plugins/node/instrumentation-socket.io/CHANGELOG.md +++ b/plugins/node/instrumentation-socket.io/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-socket.io-v0.33.1...instrumentation-socket.io-v0.33.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-socket.io-v0.33.0...instrumentation-socket.io-v0.33.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-socket.io-v0.32.0...instrumentation-socket.io-v0.33.0) (2022-12-20) diff --git a/plugins/node/instrumentation-socket.io/package.json b/plugins/node/instrumentation-socket.io/package.json index 8ffc90a3bf..513504f4a5 100644 --- a/plugins/node/instrumentation-socket.io/package.json +++ b/plugins/node/instrumentation-socket.io/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-socket.io", - "version": "0.33.0", + "version": "0.33.2", "description": "OpenTelemetry automatic instrumentation package for socket.io", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,23 +43,22 @@ }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "8.2.3", "@types/node": "18.11.7", "expect": "27.4.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "socket.io": "^4.1.3", "socket.io-client": "^4.1.3", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-socket.io#readme" diff --git a/plugins/node/instrumentation-tedious/CHANGELOG.md b/plugins/node/instrumentation-tedious/CHANGELOG.md index 8c767b5633..239ea8f525 100644 --- a/plugins/node/instrumentation-tedious/CHANGELOG.md +++ b/plugins/node/instrumentation-tedious/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.5.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-tedious-v0.5.1...instrumentation-tedious-v0.5.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.5.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-tedious-v0.5.0...instrumentation-tedious-v0.5.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.5.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-tedious-v0.4.1...instrumentation-tedious-v0.5.0) (2022-11-16) diff --git a/plugins/node/instrumentation-tedious/package.json b/plugins/node/instrumentation-tedious/package.json index a94a2675c5..5468815ee7 100644 --- a/plugins/node/instrumentation-tedious/package.json +++ b/plugins/node/instrumentation-tedious/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-tedious", - "version": "0.5.0", + "version": "0.5.2", "description": "OpenTelemetry instrumentation for `tedious`", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,21 +49,20 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "tedious": "14.1.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/tedious": "^4.0.6" }, diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-aws-lambda/CHANGELOG.md index 1a2705a522..360a1d4fac 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/CHANGELOG.md @@ -1,5 +1,38 @@ # Changelog +## [0.35.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-lambda-v0.35.0...instrumentation-aws-lambda-v0.35.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.35.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-lambda-v0.34.1...instrumentation-aws-lambda-v0.35.0) (2023-02-08) + + +### Features + +* **instrumentation-lambda:** Flush MeterProvider at end of handler ([#1370](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1370)) ([096129c](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/096129c9c1b68c7f6cccbfab42f8d2167bc40927)) + + +### Bug Fixes + +* **instrumentation/aws-lambda:** Ensure callback is only called once ([#1384](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1384)) ([d822f75](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/d822f75e10d6d0421fe8fbd4b1dca261de736e69)) + +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-lambda-v0.34.0...instrumentation-aws-lambda-v0.34.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/propagator-aws-xray bumped from ^1.1.1 to ^1.2.0 + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-lambda-v0.33.1...instrumentation-aws-lambda-v0.34.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/README.md b/plugins/node/opentelemetry-instrumentation-aws-lambda/README.md index 7251803be6..22a6095920 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/README.md +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/README.md @@ -3,7 +3,7 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @willarmiros +[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @carolabadeer This module provides automatic instrumentation for the [`AWS Lambda`](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html) module, which may be loaded using the [`@opentelemetry/sdk-trace-node`](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package and is included in the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle. diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json index b0ebe04f97..d1959d99ac 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-aws-lambda", - "version": "0.34.0", + "version": "0.35.1", "description": "OpenTelemetry AWS Lambda automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,18 +49,18 @@ "@opentelemetry/core": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", + "@opentelemetry/sdk-metrics": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.32.0", - "@opentelemetry/propagator-aws-xray": "^1.1.1", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/propagator-aws-xray": "^1.2.0", "@opentelemetry/resources": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/aws-lambda": "8.10.81" diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts index 76d4410240..0110293ef7 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts @@ -15,6 +15,7 @@ */ import * as path from 'path'; +import * as fs from 'fs'; import { InstrumentationBase, @@ -29,6 +30,7 @@ import { diag, trace, propagation, + MeterProvider, Span, SpanKind, SpanStatusCode, @@ -70,7 +72,8 @@ const headerGetter: TextMapGetter = { export const traceContextEnvironmentKey = '_X_AMZN_TRACE_ID'; export class AwsLambdaInstrumentation extends InstrumentationBase { - private _forceFlush?: () => Promise; + private _traceForceFlusher?: () => Promise; + private _metricForceFlusher?: () => Promise; constructor(protected override _config: AwsLambdaInstrumentationConfig = {}) { super('@opentelemetry/instrumentation-aws-lambda', VERSION, _config); @@ -97,8 +100,15 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { // Lambda loads user function using an absolute path. let filename = path.resolve(taskRoot, moduleRoot, module); if (!filename.endsWith('.js')) { - // Patching infrastructure currently requires a filename when requiring with an absolute path. - filename += '.js'; + // its impossible to know in advance if the user has a cjs or js file. + // check that the .js file exists otherwise fallback to next known possibility + try { + fs.statSync(`${filename}.js`); + filename += '.js'; + } catch (e) { + // fallback to .cjs + filename += '.cjs'; + } } return [ @@ -226,10 +236,10 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { override setTracerProvider(tracerProvider: TracerProvider) { super.setTracerProvider(tracerProvider); - this._forceFlush = this._getForceFlush(tracerProvider); + this._traceForceFlusher = this._traceForceFlush(tracerProvider); } - private _getForceFlush(tracerProvider: TracerProvider) { + private _traceForceFlush(tracerProvider: TracerProvider) { if (!tracerProvider) return undefined; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -246,6 +256,24 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { return undefined; } + override setMeterProvider(meterProvider: MeterProvider) { + super.setMeterProvider(meterProvider); + this._metricForceFlusher = this._metricForceFlush(meterProvider); + } + + private _metricForceFlush(meterProvider: MeterProvider) { + if (!meterProvider) return undefined; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const currentProvider: any = meterProvider; + + if (typeof currentProvider.forceFlush === 'function') { + return currentProvider.forceFlush.bind(currentProvider); + } + + return undefined; + } + private _wrapCallback(original: Callback, span: Span): Callback { const plugin = this; return function wrappedCallback(this: never, err, res) { @@ -283,17 +311,23 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { span.end(); - if (this._forceFlush) { - this._forceFlush().then( - () => callback(), - () => callback() - ); + const flushers = []; + if (this._traceForceFlusher) { + flushers.push(this._traceForceFlusher()); } else { diag.error( 'Spans may not be exported for the lambda function because we are not force flushing before callback.' ); - callback(); } + if (this._metricForceFlusher) { + flushers.push(this._metricForceFlusher()); + } else { + diag.error( + 'Metrics may not be exported for the lambda function because we are not force flushing before callback.' + ); + } + + Promise.all(flushers).then(callback, callback); } private _applyResponseHook( diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts index e57e43f2f0..0a067dc758 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.force-flush.test.ts @@ -28,8 +28,17 @@ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { Context } from 'aws-lambda'; import * as assert from 'assert'; import { ProxyTracerProvider, TracerProvider } from '@opentelemetry/api'; +import { + AggregationTemporality, + InMemoryMetricExporter, + MeterProvider, + PeriodicExportingMetricReader, +} from '@opentelemetry/sdk-metrics'; -const memoryExporter = new InMemorySpanExporter(); +const traceMemoryExporter = new InMemorySpanExporter(); +const metricMemoryExporter = new InMemoryMetricExporter( + AggregationTemporality.CUMULATIVE +); describe('force flush', () => { let instrumentation: AwsLambdaInstrumentation; @@ -42,13 +51,26 @@ describe('force flush', () => { awsRequestId: 'aws_request_id', } as Context; - const initializeHandler = (handler: string, provider: TracerProvider) => { + const initializeHandlerTracing = ( + handler: string, + provider: TracerProvider + ) => { process.env._HANDLER = handler; instrumentation = new AwsLambdaInstrumentation(); instrumentation.setTracerProvider(provider); }; + const initializeHandlerMetrics = ( + handler: string, + provider: MeterProvider + ) => { + process.env._HANDLER = handler; + + instrumentation = new AwsLambdaInstrumentation(); + instrumentation.setMeterProvider(provider); + }; + const lambdaRequire = (module: string) => require(path.resolve(__dirname, '..', module)); @@ -61,12 +83,13 @@ describe('force flush', () => { process.env = oldEnv; instrumentation.disable(); - memoryExporter.reset(); + traceMemoryExporter.reset(); + metricMemoryExporter.reset(); }); it('should force flush NodeTracerProvider', async () => { const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new BatchSpanProcessor(memoryExporter)); + provider.addSpanProcessor(new BatchSpanProcessor(traceMemoryExporter)); provider.register(); let forceFlushed = false; const forceFlush = () => @@ -75,7 +98,7 @@ describe('force flush', () => { resolve(); }); provider.forceFlush = forceFlush; - initializeHandler('lambda-test/sync.handler', provider); + initializeHandlerTracing('lambda-test/sync.handler', provider); await new Promise((resolve, reject) => { lambdaRequire('lambda-test/sync').handler( @@ -96,7 +119,9 @@ describe('force flush', () => { it('should force flush ProxyTracerProvider with NodeTracerProvider', async () => { const nodeTracerProvider = new NodeTracerProvider(); - nodeTracerProvider.addSpanProcessor(new BatchSpanProcessor(memoryExporter)); + nodeTracerProvider.addSpanProcessor( + new BatchSpanProcessor(traceMemoryExporter) + ); nodeTracerProvider.register(); const provider = new ProxyTracerProvider(); provider.setDelegate(nodeTracerProvider); @@ -107,7 +132,7 @@ describe('force flush', () => { resolve(); }); nodeTracerProvider.forceFlush = forceFlush; - initializeHandler('lambda-test/sync.handler', provider); + initializeHandlerTracing('lambda-test/sync.handler', provider); await new Promise((resolve, reject) => { lambdaRequire('lambda-test/sync').handler( @@ -125,4 +150,90 @@ describe('force flush', () => { assert.strictEqual(forceFlushed, true); }); + + it('should force flush MeterProvider', async () => { + const provider = new MeterProvider(); + provider.addMetricReader( + new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }) + ); + let forceFlushed = false; + const forceFlush = () => + new Promise(resolve => { + forceFlushed = true; + resolve(); + }); + provider.forceFlush = forceFlush; + initializeHandlerMetrics('lambda-test/sync.handler', provider); + + await new Promise((resolve, reject) => { + lambdaRequire('lambda-test/sync').handler( + 'arg', + ctx, + (err: Error, res: any) => { + if (err) { + reject(err); + } else { + resolve(res); + } + } + ); + }); + + assert.strictEqual(forceFlushed, true); + }); + + it('should callback once after force flush providers', async () => { + const nodeTracerProvider = new NodeTracerProvider(); + nodeTracerProvider.addSpanProcessor( + new BatchSpanProcessor(traceMemoryExporter) + ); + nodeTracerProvider.register(); + const tracerProvider = new ProxyTracerProvider(); + tracerProvider.setDelegate(nodeTracerProvider); + let tracerForceFlushed = false; + const tracerForceFlush = () => + new Promise(resolve => { + tracerForceFlushed = true; + resolve(); + }); + nodeTracerProvider.forceFlush = tracerForceFlush; + + const meterProvider = new MeterProvider(); + meterProvider.addMetricReader( + new PeriodicExportingMetricReader({ exporter: metricMemoryExporter }) + ); + let meterForceFlushed = false; + const meterForceFlush = () => + new Promise(resolve => { + meterForceFlushed = true; + resolve(); + }); + meterProvider.forceFlush = meterForceFlush; + + process.env._HANDLER = 'lambda-test/sync.handler'; + + instrumentation = new AwsLambdaInstrumentation(); + instrumentation.setTracerProvider(tracerProvider); + instrumentation.setMeterProvider(meterProvider); + + let callbackCount = 0; + await new Promise((resolve, reject) => { + lambdaRequire('lambda-test/sync').handler( + 'arg', + ctx, + (err: Error, res: any) => { + callbackCount++; + if (err) { + reject(err); + } else { + resolve(res); + } + } + ); + }); + + assert.strictEqual(tracerForceFlushed, true); + assert.strictEqual(meterForceFlushed, true); + assert.strictEqual(callbackCount, 1); + }); }); diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts index cabb6d0f37..681922fbee 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts @@ -51,9 +51,6 @@ import { AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray'; import { W3CTraceContextPropagator } from '@opentelemetry/core'; const memoryExporter = new InMemorySpanExporter(); -const provider = new NodeTracerProvider(); -provider.addSpanProcessor(new BatchSpanProcessor(memoryExporter)); -provider.register(); const assertSpanSuccess = (span: ReadableSpan) => { assert.strictEqual(span.kind, SpanKind.SERVER); @@ -118,8 +115,14 @@ describe('lambda handler', () => { ) => { process.env._HANDLER = handler; + const provider = new NodeTracerProvider(); + provider.addSpanProcessor(new BatchSpanProcessor(memoryExporter)); + provider.register(); + instrumentation = new AwsLambdaInstrumentation(config); instrumentation.setTracerProvider(provider); + + return provider; }; const lambdaRequire = (module: string) => @@ -214,7 +217,7 @@ describe('lambda handler', () => { let err: Error; try { await lambdaRequire('lambda-test/async').error('arg', ctx); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!.message, 'handler error'); @@ -231,7 +234,7 @@ describe('lambda handler', () => { let err: string; try { await lambdaRequire('lambda-test/async').stringerror('arg', ctx); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!, 'handler error'); @@ -301,7 +304,7 @@ describe('lambda handler', () => { ctx, (err: Error, res: any) => {} ); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!.message, 'handler error'); @@ -330,7 +333,7 @@ describe('lambda handler', () => { } ); }); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!.message, 'handler error'); @@ -351,7 +354,7 @@ describe('lambda handler', () => { ctx, (err: Error, res: any) => {} ); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!, 'handler error'); @@ -423,7 +426,7 @@ describe('lambda handler', () => { } ); }); - } catch (e) { + } catch (e: any) { err = e; } assert.strictEqual(err!, 'handler error'); @@ -667,7 +670,7 @@ describe('lambda handler', () => { return propagation.extract(context.active(), event.contextCarrier); }; - initializeHandler('lambda-test/async.handler', { + const provider = initializeHandler('lambda-test/async.handler', { disableAwsContextPropagation: true, eventContextExtractor: customExtractor, }); @@ -806,7 +809,7 @@ describe('lambda handler', () => { let err: Error; try { await lambdaRequire('lambda-test/async').error('arg', ctx); - } catch (e) { + } catch (e: any) { err = e; } const [span] = memoryExporter.getFinishedSpans(); @@ -833,7 +836,7 @@ describe('lambda handler', () => { let err: Error; try { lambdaRequire('lambda-test/sync').error('arg', ctx, () => {}); - } catch (e) { + } catch (e: any) { err = e; } const [span] = memoryExporter.getFinishedSpans(); @@ -858,5 +861,21 @@ describe('lambda handler', () => { assert.strictEqual(span.attributes[ERR_ATTR], error!.message); }); }); + + describe('.cjs lambda bundle', () => { + it('should export a valid span', async () => { + initializeHandler('lambda-test/commonjs.handler'); + const result = await lambdaRequire('lambda-test/commonjs.cjs').handler( + 'arg', + ctx + ); + assert.strictEqual(result, 'ok'); + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + assertSpanSuccess(span); + assert.strictEqual(span.parentSpanId, undefined); + }); + }); }); }); diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/test/lambda-test/commonjs.cjs b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/lambda-test/commonjs.cjs new file mode 100644 index 0000000000..3fc61adccf --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/test/lambda-test/commonjs.cjs @@ -0,0 +1,3 @@ +exports.handler = async function (event, context) { + return "ok"; +}; \ No newline at end of file diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-aws-sdk/CHANGELOG.md index 07ff694a46..0705b1ece4 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/CHANGELOG.md @@ -1,5 +1,66 @@ # Changelog +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-sdk-v0.34.0...instrumentation-aws-sdk-v0.34.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/propagation-utils bumped from ^0.29.2 to ^0.29.3 + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-sdk-v0.33.0...instrumentation-aws-sdk-v0.34.0) (2023-02-07) + + +### Features + +* add supported node versions for all packages ([#973](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/973)) ([baaacbd](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/baaacbdd35ca4baab0afae64647aa8c0380ee4b7)) +* AWS-SDK SNS Context propagation ([#728](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/728)) ([78cd4e1](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/78cd4e118e5a41107d84dfd1ae8c4c28e885b27e)) +* **aws-sdk:** add http status code attribute to aws sdk span ([#844](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/844)) ([09b8555](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/09b8555007c3c05ad046dd67925f3640a7b35fbe)) +* **aws-sdk:** lambda client instrumentation ([#916](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/916)) ([dc6c2b5](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/dc6c2b5121977814f854b674ec3e519f689637c9)) +* config option to extract sqs context from message payload ([#737](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/737)) ([28e2113](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/28e2113ec1091e73a1d1b62b48fee8c01c72afee)) +* **instrumentation-aws-sdk:** upstream aws-sdk instrumentation from ext-js ([#678](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/678)) ([f5851e7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f5851e72512117dbce571a42930a90c560dbf63d)) +* update core dependencies stable ^1.3.1 experimental ^0.29.2 ([141b155](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/141b155e344980b51264e26b26c117b2113bcef6)) +* update experimental deps to `^0.34.0`, core deps to `^1.8.0`, api to `^1.3.0` ([#1278](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1278)) ([e9fe8e1](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e9fe8e13e34f54e96c50525cadeb74ac048c5624)) +* update experimental Otel deps to ^0.31.0 ([#1096](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1096)) ([4c8843b](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/4c8843be14896d1159a622c07eb3a049401ccba1)) +* update experimental Otel deps to ^0.32.0 ([#1143](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1143)) ([6fb1911](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/6fb191139aed2ca763300dcf9adb51121a88f97e)) +* upstream mocha instrumentation testing plugin from ext-js [#621](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/621) ([#669](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/669)) ([a5170c4](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/a5170c494706a2bec3ba51e59966d0ca8a41d00e)) +* use latest instrumentation base ([#769](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/769)) ([7aff23e](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/7aff23ebebbe209fa3b78c2e7f513c9cd2231be4)) +* use Otel SDK 1.2/0.28 ([#984](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/984)) ([098c2ed](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/098c2ed6f9c5ab7bd865685018c0777245aab3b7)) + + +### Bug Fixes + +* avoid type imports of the aws-sdk package in the built assets ([#1066](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1066)) ([457be50](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/457be5035b9ba87211fe3553c901b7408dd2d593)) +* **aws-sdk:** avoid repeating MessageAttributeNames in sqs receiveMessage ([#1044](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1044)) ([4b4ded6](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/4b4ded6e5b781b9a9cb2c55102ec0949da062511)) +* **aws-sdk:** bump aws-sdk instrumentation version to align with previous release ([#1247](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1247)) ([fd2480a](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/fd2480a4ea7b4093da523ecbc30743a55f38ab6c)) +* **aws-sdk:** calc propagation fields count before context inject ([#738](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/738)) ([033cc1f](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/033cc1f7ed09c33e401b9514ed30d1160cf58899)) +* **aws-sdk:** set spanKind to CLIENT by default in v3 ([#1177](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1177)) ([d463695](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/d463695f5258875f1da0c7b17c20f7df93494d4e)) +* **aws-sdk:** sns span name should be with low cardinality ([#841](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/841)) ([7032a33](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/7032a33b6eef331ab327ab57b9bd3a1aed361fb2)) +* **aws-sdk:** sns-sqs extract the correct context key from message payload ([#761](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/761)) ([e5cae76](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e5cae76d90b5e6d2eb9c6cd5da984a07cdd5048c)) +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) +* **instrumentation-aws-sdk:** sqs message id missing on send command ([#968](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/968)) ([8b36fe1](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/8b36fe16abca0a6326d48e5a22fd9302f2936609)) +* **opentelemetry-instrumentation-aws-sdk:** error when ReturnConsumedCapacity is set to None ([#899](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/899)) ([e7ab4d0](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e7ab4d056b6663f593b47af7c3e8014a72a963fe)) +* rename lerna's --include-filtered-dependencies option ([#817](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/817)) ([cf268e7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/cf268e7a92b7800ad6dbec9ca77466f9ee03ee1a)) +* **sns-publish-test-v3:** add test for sns.publish for aws sdk v3 ([#1015](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1015)) ([0293d89](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/0293d897f789bdeb7b843f673be2c2dc62e16010)) +* use localhost for services in CI ([#816](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/816)) ([f497313](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f4973133e86549bbca301983085cc67788a10acd)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/propagation-utils bumped from ^0.29.1 to ^0.29.2 + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.10.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-aws-sdk-v0.9.3...instrumentation-aws-sdk-v0.10.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/README.md b/plugins/node/opentelemetry-instrumentation-aws-sdk/README.md index 6c6a49c893..63c7a4cd38 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/README.md +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/README.md @@ -3,7 +3,7 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @willarmiros @blumamir +[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @carolabadeer @blumamir This module provides automatic instrumentation for the [`aws-sdk` v2](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) and [`@aws-sdk` v3](https://github.com/aws/aws-sdk-js-v3) modules, which may be loaded using the [`@opentelemetry/sdk-trace-node`](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package and is included in the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle. diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json index fd44fdd373..d1714eebfe 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-aws-sdk", - "version": "0.33.0", + "version": "0.34.1", "description": "OpenTelemetry automatic instrumentation for the `aws-sdk` package", "keywords": [ "aws", @@ -47,9 +47,9 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "@opentelemetry/propagation-utils": "^0.29.1" + "@opentelemetry/propagation-utils": "^0.29.3" }, "devDependencies": { "@aws-sdk/client-dynamodb": "3.85.0", @@ -59,7 +59,7 @@ "@aws-sdk/client-sns": "3.85.0", "@aws-sdk/types": "3.78.0", "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "8.2.3", "@types/node": "18.11.7", @@ -67,12 +67,11 @@ "aws-sdk": "2.1008.0", "eslint": "8.7.0", "expect": "29.2.0", - "gts": "3.1.0", "mocha": "7.2.0", "nock": "13.2.1", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", "typescript": "4.3.4" diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-bunyan/CHANGELOG.md index 8cf8741110..284b791f9d 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-bunyan/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-bunyan-v0.31.1...instrumentation-bunyan-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-bunyan-v0.31.0...instrumentation-bunyan-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-bunyan-v0.30.1...instrumentation-bunyan-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/package.json b/plugins/node/opentelemetry-instrumentation-bunyan/package.json index c6687f1c84..6c3c66c7f1 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/package.json +++ b/plugins/node/opentelemetry-instrumentation-bunyan/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-bunyan", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry instrumentation for bunyan", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -55,17 +55,16 @@ "@types/node": "18.11.7", "@types/sinon": "10.0.2", "bunyan": "1.8.15", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@types/bunyan": "1.8.7" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-bunyan#readme" diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-cassandra/CHANGELOG.md index d1723c2f0d..ace63fe55e 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-cassandra/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-cassandra-driver-v0.32.1...instrumentation-cassandra-driver-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-cassandra-driver-v0.32.0...instrumentation-cassandra-driver-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-cassandra-driver-v0.31.0...instrumentation-cassandra-driver-v0.32.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/package.json b/plugins/node/opentelemetry-instrumentation-cassandra/package.json index 50d51b02b4..20eedc419a 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/package.json +++ b/plugins/node/opentelemetry-instrumentation-cassandra/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-cassandra-driver", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry instrumentation for cassandra-driver", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -48,7 +48,7 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", @@ -56,16 +56,15 @@ "@types/semver": "7.3.8", "@types/sinon": "10.0.2", "cassandra-driver": "4.6.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-cassandra#readme" diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts b/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts index bd696df85f..5be436877a 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts +++ b/plugins/node/opentelemetry-instrumentation-cassandra/test/cassandra-driver.test.ts @@ -109,6 +109,7 @@ function assertErrorSpan( const events = [ { name: 'exception', + droppedAttributesCount: 0, attributes: { [SemanticAttributes.EXCEPTION_STACKTRACE]: error.stack, [SemanticAttributes.EXCEPTION_MESSAGE]: error.message, @@ -204,7 +205,7 @@ describe('CassandraDriverInstrumentation', () => { it('creates an error span', async () => { try { await client.execute('selec * from'); - } catch (e) { + } catch (e: any) { assertErrorSpan('cassandra-driver.execute', e); return; } @@ -322,7 +323,7 @@ describe('CassandraDriverInstrumentation', () => { const query = 'insert into foobar'; try { await client.batch([query]); - } catch (e) { + } catch (e: any) { assertErrorSpan('cassandra-driver.batch', e); return; } diff --git a/plugins/node/opentelemetry-instrumentation-connect/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-connect/CHANGELOG.md index 1c65a240e1..7bb82f0c85 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-connect/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-connect-v0.31.1...instrumentation-connect-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-connect-v0.31.0...instrumentation-connect-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-connect-v0.30.1...instrumentation-connect-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-connect/package.json b/plugins/node/opentelemetry-instrumentation-connect/package.json index 790ad5e7d6..ebd9f11bcb 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/package.json +++ b/plugins/node/opentelemetry-instrumentation-connect/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-connect", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry connect automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -51,16 +51,15 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "connect": "3.7.0", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/connect": "3.4.35" }, diff --git a/plugins/node/opentelemetry-instrumentation-dns/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-dns/CHANGELOG.md index fbb0e93248..2bb4d8a55f 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-dns/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [0.31.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dns-v0.31.2...instrumentation-dns-v0.31.3) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dns-v0.31.1...instrumentation-dns-v0.31.2) (2023-02-14) + + +### Bug Fixes + +* **instrumentation-dns:** fix instrumentation of `dns/promises` ([#1377](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1377)) ([6d08157](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/6d08157300faf418e886315384e6b705a0e13683)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dns-v0.31.0...instrumentation-dns-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-dns-v0.30.1...instrumentation-dns-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-dns/package.json b/plugins/node/opentelemetry-instrumentation-dns/package.json index ca3b04ec97..7b5f5d7ff7 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/package.json +++ b/plugins/node/opentelemetry-instrumentation-dns/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-dns", - "version": "0.31.0", + "version": "0.31.3", "description": "OpenTelemetry dns automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -54,16 +54,15 @@ "@types/semver": "7.3.8", "@types/shimmer": "1.0.2", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "semver": "^7.3.2" }, diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-dns/src/enums/AttributeNames.ts index 2364b3769c..81bf053fad 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/enums/AttributeNames.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/enums/AttributeNames.ts @@ -15,7 +15,6 @@ */ export enum AttributeNames { // NOT ON OFFICIAL SPEC - DNS_ERROR_CODE = 'dns.error_code', DNS_ERROR_NAME = 'dns.error_name', DNS_ERROR_MESSAGE = 'dns.error_message', } diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts index 9a057ca0bd..319a27e1c1 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts @@ -22,13 +22,13 @@ import { isWrapped, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; -import * as semver from 'semver'; import { AddressFamily } from './enums/AddressFamily'; import { DnsInstrumentationConfig } from './types'; import * as utils from './utils'; import { VERSION } from './version'; import { Dns, + DnsPromises, LookupCallbackSignature, LookupPromiseSignature, } from './internal-types'; @@ -41,7 +41,10 @@ export class DnsInstrumentation extends InstrumentationBase { super('@opentelemetry/instrumentation-dns', VERSION, _config); } - init(): InstrumentationNodeModuleDefinition[] { + init(): ( + | InstrumentationNodeModuleDefinition + | InstrumentationNodeModuleDefinition + )[] { return [ new InstrumentationNodeModuleDefinition( 'dns', @@ -53,25 +56,37 @@ export class DnsInstrumentation extends InstrumentationBase { } // eslint-disable-next-line @typescript-eslint/no-explicit-any this._wrap(moduleExports, 'lookup', this._getLookup() as any); - // new promise methods in node >= 10.6.0 - // https://nodejs.org/docs/latest/api/dns.html#dns_dnspromises_lookup_hostname_options - if (semver.gte(process.version, '10.6.0')) { - this._wrap( - moduleExports.promises, - 'lookup', - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this._getLookup() as any - ); - } + this._wrap( + moduleExports.promises, + 'lookup', + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._getLookup() as any + ); return moduleExports; }, moduleExports => { if (moduleExports === undefined) return; diag.debug('Removing patch for dns'); this._unwrap(moduleExports, 'lookup'); - if (semver.gte(process.version, '10.6.0')) { - this._unwrap(moduleExports.promises, 'lookup'); + this._unwrap(moduleExports.promises, 'lookup'); + } + ), + new InstrumentationNodeModuleDefinition( + 'dns/promises', + ['*'], + moduleExports => { + diag.debug('Applying patch for dns/promises'); + if (isWrapped(moduleExports.lookup)) { + this._unwrap(moduleExports, 'lookup'); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._wrap(moduleExports, 'lookup', this._getLookup() as any); + return moduleExports; + }, + moduleExports => { + if (moduleExports === undefined) return; + diag.debug('Removing patch for dns/promises'); + this._unwrap(moduleExports, 'lookup'); } ), ]; @@ -124,7 +139,7 @@ export class DnsInstrumentation extends InstrumentationBase { () => original.apply(this, [hostname, ...args]), error => { if (error != null) { - utils.setError(error, span, process.version); + utils.setError(error, span); span.end(); } } @@ -138,7 +153,7 @@ export class DnsInstrumentation extends InstrumentationBase { ]), error => { if (error != null) { - utils.setError(error, span, process.version); + utils.setError(error, span); span.end(); } } @@ -149,7 +164,7 @@ export class DnsInstrumentation extends InstrumentationBase { span.end(); }, (e: NodeJS.ErrnoException) => { - utils.setError(e, span, process.version); + utils.setError(e, span); span.end(); } ); @@ -175,7 +190,7 @@ export class DnsInstrumentation extends InstrumentationBase { diag.debug('executing wrapped lookup callback function'); if (err !== null) { - utils.setError(err, span, process.version); + utils.setError(err, span); } else { utils.setLookupAttributes(span, address, family); } diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-dns/src/internal-types.ts index e3ae4e0f55..26638ba1a7 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/internal-types.ts @@ -15,8 +15,10 @@ */ import type * as dns from 'dns'; +import type * as dnsPromises from 'dns/promises'; export type Dns = typeof dns; +export type DnsPromises = typeof dnsPromises; export type LookupFunction = (( hostname: string, diff --git a/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts b/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts index 3d620d65ef..9fae671bca 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/src/utils.ts @@ -26,21 +26,13 @@ import { IgnoreMatcher } from './types'; * @param span the span to be set * @param nodeVersion the node version */ -export const setError = ( - err: NodeJS.ErrnoException, - span: Span, - nodeVersion: string -) => { - const { code, message, name } = err; +export const setError = (err: NodeJS.ErrnoException, span: Span) => { + const { message, name } = err; const attributes = { [AttributeNames.DNS_ERROR_MESSAGE]: message, [AttributeNames.DNS_ERROR_NAME]: name, } as SpanAttributes; - if (nodeVersion.startsWith('v12')) { - attributes[AttributeNames.DNS_ERROR_CODE] = code!; - } - span.setAttributes(attributes); span.setStatus({ @@ -146,7 +138,7 @@ export const isIgnored = ( return true; } } - } catch (e) { + } catch (e: any) { if (onException) { onException(e); } diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts index 51d92e8b96..c995ca0261 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/functionals/utils.test.ts @@ -154,7 +154,7 @@ describe('Utility', () => { { spanId: '', traceId: '', traceFlags: TraceFlags.NONE }, SpanKind.INTERNAL ); - utils.setError(new Error(errorMessage), span, process.versions.node); + utils.setError(new Error(errorMessage), span); const attributes = span.attributes; assert.strictEqual( attributes[AttributeNames.DNS_ERROR_MESSAGE], diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts index 8bd5ad698a..2aa4c20985 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-lookup.test.ts @@ -130,7 +130,7 @@ describe('dns.lookup()', () => { try { dns.lookup(hostname, -1, () => {}); assert.fail(); - } catch (error) { + } catch (error: any) { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); @@ -151,7 +151,7 @@ describe('dns.lookup()', () => { // tslint:disable-next-line:no-any dns.lookup(hostname as any, 4, () => {}); assert.fail(); - } catch (error) { + } catch (error: any) { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts new file mode 100644 index 0000000000..7489e25153 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dns-slash-promises-lookup.test.ts @@ -0,0 +1,223 @@ +/* + * 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 { + InMemorySpanExporter, + SimpleSpanProcessor, +} from '@opentelemetry/sdk-trace-base'; +import * as assert from 'assert'; +import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; +import { DnsInstrumentation } from '../../src'; +import type * as DnsPromisesType from 'dns/promises'; +import * as utils from '../utils/utils'; +import { assertSpan } from '../utils/assertSpan'; +import { SpanStatusCode } from '@opentelemetry/api'; + +const memoryExporter = new InMemorySpanExporter(); +const provider = new NodeTracerProvider(); +provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + +const supportsPromises = + parseInt(process.versions.node.split('.')[0], 10) >= 15; + +if (supportsPromises) { + describe('dns/promises.lookup()', () => { + let instrumentation: DnsInstrumentation; + let dnsPromises: typeof DnsPromisesType; + + before(function (done) { + // if node version is supported, it's mandatory for CI + if (process.env.CI) { + instrumentation = new DnsInstrumentation(); + instrumentation.setTracerProvider(provider); + dnsPromises = require('dns/promises'); + done(); + return; + } + + utils.checkInternet(isConnected => { + if (!isConnected) { + this.skip(); + // don't disturb people + } + done(); + }); + instrumentation = new DnsInstrumentation(); + instrumentation.setTracerProvider(provider); + dnsPromises = require('dns/promises'); + }); + + afterEach(() => { + memoryExporter.reset(); + }); + + after(() => { + instrumentation.disable(); + }); + + describe('with family param', () => { + [4, 6].forEach(ipversion => { + it(`should export a valid span with "family" arg to ${ipversion}`, async () => { + const hostname = 'google.com'; + const { address, family } = await dnsPromises.lookup(hostname, { + family: ipversion, + }); + assert.ok(address); + assert.ok(family); + + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + assertSpan(span, { addresses: [{ address, family }], hostname }); + }); + }); + }); + + describe('with no options param', () => { + it('should export a valid span', async () => { + const hostname = 'google.com'; + const { address, family } = await dnsPromises.lookup(hostname); + + assert.ok(address); + assert.ok(family); + + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + assertSpan(span, { addresses: [{ address, family }], hostname }); + }); + + describe('extended timeout', function () { + // Extending the default timeout as some environments are taking longer than 2 seconds to fail + // So rather than fail the test -- just take a little longer + this.timeout(10000); + + it('should export a valid span with error NOT_FOUND', async () => { + const hostname = 'áš•'; + try { + await dnsPromises.lookup(hostname); + assert.fail(); + } catch (error: any) { + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + + assert.strictEqual(spans.length, 1); + assertSpan(span, { + addresses: [], + hostname, + forceStatus: { + code: SpanStatusCode.ERROR, + message: error!.message, + }, + }); + } + }); + }); + + it('should export a valid span with error INVALID_ARGUMENT when "family" param is equal to -1', async () => { + const hostname = 'google.com'; + try { + await dnsPromises.lookup(hostname, { family: -1 }); + assert.fail(); + } catch (error: any) { + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + + assert.strictEqual(spans.length, 1); + assertSpan(span, { + addresses: [], + // tslint:disable-next-line:no-any + hostname: hostname as any, + forceStatus: { + code: SpanStatusCode.ERROR, + message: error!.message, + }, + }); + } + }); + + it('should export a valid span with error INVALID_ARGUMENT when "hostname" param is a number', async () => { + const hostname = 1234; + try { + await dnsPromises.lookup(hostname as any, { family: 4 }); + assert.fail(); + } catch (error: any) { + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + + assert.strictEqual(spans.length, 1); + assertSpan(span, { + addresses: [], + // tslint:disable-next-line:no-any + hostname: hostname as any, + forceStatus: { + code: SpanStatusCode.ERROR, + message: error!.message, + }, + }); + } + }); + }); + describe('with options param', () => { + [4, 6].forEach(ipversion => { + it(`should export a valid span with "family" to ${ipversion}`, async () => { + const hostname = 'google.com'; + const { address, family } = await dnsPromises.lookup(hostname, { + family: ipversion, + }); + + assert.ok(address); + assert.ok(family); + + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + + assertSpan(span, { addresses: [{ address, family }], hostname }); + }); + + it(`should export a valid span when setting "verbatim" property to true and "family" to ${ipversion}`, async () => { + const hostname = 'google.com'; + const { address, family } = await dnsPromises.lookup(hostname, { + family: ipversion, + verbatim: true, + }); + + assert.ok(address); + assert.ok(family); + + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + + assertSpan(span, { addresses: [{ address, family }], hostname }); + }); + }); + + it('should export a valid span when setting "all" property to true', async () => { + const hostname = 'montreal.ca'; + const addresses = await dnsPromises.lookup(hostname, { all: true }); + + assert.ok(addresses instanceof Array); + + const spans = memoryExporter.getFinishedSpans(); + const [span] = spans; + assert.strictEqual(spans.length, 1); + assertSpan(span, { addresses, hostname }); + }); + }); + }); +} diff --git a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts index 73e19f40e1..1338f43bac 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts +++ b/plugins/node/opentelemetry-instrumentation-dns/test/integrations/dnspromise-lookup.test.ts @@ -105,7 +105,7 @@ describe('dns.promises.lookup()', () => { try { await dns.promises.lookup(hostname); assert.fail(); - } catch (error) { + } catch (error: any) { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; @@ -127,7 +127,7 @@ describe('dns.promises.lookup()', () => { try { await dns.promises.lookup(hostname, { family: -1 }); assert.fail(); - } catch (error) { + } catch (error: any) { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; @@ -149,7 +149,7 @@ describe('dns.promises.lookup()', () => { try { await dns.promises.lookup(hostname as any, { family: 4 }); assert.fail(); - } catch (error) { + } catch (error: any) { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; diff --git a/plugins/node/opentelemetry-instrumentation-express/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-express/CHANGELOG.md index abdba1b095..fc1e4ef374 100644 --- a/plugins/node/opentelemetry-instrumentation-express/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-express/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-express-v0.32.1...instrumentation-express-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-express-v0.32.0...instrumentation-express-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-express-v0.31.3...instrumentation-express-v0.32.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-express/examples/package.json b/plugins/node/opentelemetry-instrumentation-express/examples/package.json index d9881839a1..e2d5cc1eaf 100644 --- a/plugins/node/opentelemetry-instrumentation-express/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/examples/package.json @@ -32,9 +32,9 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.32.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/instrumentation-express": "0.28.0", - "@opentelemetry/instrumentation-http": "^0.32.0", + "@opentelemetry/instrumentation-http": "^0.38.0", "@opentelemetry/resources": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", @@ -47,6 +47,6 @@ "devDependencies": { "@types/express": "^4.17.13", "ts-node": "^10.6.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/plugins/node/opentelemetry-instrumentation-express/package.json b/plugins/node/opentelemetry-instrumentation-express/package.json index 674811f90a..1db32213b7 100644 --- a/plugins/node/opentelemetry-instrumentation-express/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-express", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry express automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -56,18 +56,17 @@ "@types/node": "18.11.7", "@types/sinon": "10.0.9", "express": "4.17.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/express": "4.17.13" }, diff --git a/plugins/node/opentelemetry-instrumentation-fastify/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-fastify/CHANGELOG.md index d6bf732326..a4fef65d38 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-fastify/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fastify-v0.31.1...instrumentation-fastify-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fastify-v0.31.0...instrumentation-fastify-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-fastify-v0.30.1...instrumentation-fastify-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-fastify/package.json b/plugins/node/opentelemetry-instrumentation-fastify/package.json index 116d217738..cfde7f78e6 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/package.json +++ b/plugins/node/opentelemetry-instrumentation-fastify/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-fastify", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry fastify automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -48,23 +48,22 @@ "@fastify/express": "^2.0.2", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/instrumentation-http": "0.34.0", + "@opentelemetry/instrumentation-http": "0.38.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/express": "4.17.13", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "fastify": "^4.5.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify#readme" diff --git a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts index 15570129b7..8180eeb047 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts +++ b/plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts @@ -146,7 +146,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 5); - const span = spans[3]; + const span = spans[2]; assert.deepStrictEqual(span.attributes, { 'fastify.type': 'request_handler', 'plugin.name': 'fastify -> @fastify/express', @@ -168,7 +168,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 5); - const span = spans[3]; + const span = spans[2]; assert.deepStrictEqual(span.attributes, { 'fastify.type': 'request_handler', 'fastify.name': 'namedHandler', @@ -220,11 +220,11 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 6); - const changedRootSpan = spans[2]; - const span = spans[4]; + const changedRootSpan = spans[4]; + const span = spans[3]; assert.strictEqual(changedRootSpan.name, 'GET /test/:id'); assert.strictEqual(span.name, 'request handler - foo'); - assert.strictEqual(span.parentSpanId, spans[3].spanContext().spanId); + assert.strictEqual(span.parentSpanId, spans[2].spanContext().spanId); }); it('should create span for fastify express runConnect', async () => { @@ -247,7 +247,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 6); - const baseSpan = spans[2]; + const baseSpan = spans[4]; const span = spans[0]; assert.strictEqual(span.name, 'middleware - enhanceRequest'); assert.deepStrictEqual(span.attributes, { @@ -263,8 +263,8 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 6); - const baseSpan = spans[3]; - const span = spans[4]; + const baseSpan = spans[2]; + const span = spans[3]; assert.strictEqual(span.name, 'request handler - foo'); assert.deepStrictEqual(span.attributes, { 'plugin.name': 'subsystem', @@ -280,7 +280,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 6); - const span = spans[2]; + const span = spans[4]; assert.strictEqual(span.attributes['http.route'], '/test/:id'); }); @@ -289,7 +289,7 @@ describe('fastify', () => { assert.strictEqual(spans.length, 6); const baseSpan = spans[1]; - const span = spans[3]; + const span = spans[2]; assert.strictEqual(span.name, `middleware - ${ANONYMOUS_NAME}`); assert.deepStrictEqual(span.attributes, { 'fastify.type': 'middleware', @@ -306,7 +306,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 6); - const span = spans[4]; + const span = spans[3]; assert.strictEqual(span.name, 'request handler - anonymous'); assert.deepStrictEqual(span.status, { code: SpanStatusCode.ERROR, @@ -454,7 +454,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 5); - const span = spans[3]; + const span = spans[2]; assert.deepStrictEqual(span.attributes, { 'fastify.type': 'request_handler', 'plugin.name': 'fastify -> @fastify/express', @@ -487,7 +487,7 @@ describe('fastify', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 5); - const span = spans[3]; + const span = spans[2]; assert.deepStrictEqual(span.attributes, { 'fastify.type': 'request_handler', 'plugin.name': 'fastify -> @fastify/express', diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-generic-pool/CHANGELOG.md index d1f65efaaf..5dc40f5877 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-generic-pool-v0.31.1...instrumentation-generic-pool-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-generic-pool-v0.31.0...instrumentation-generic-pool-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-generic-pool-v0.30.0...instrumentation-generic-pool-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/package.json b/plugins/node/opentelemetry-instrumentation-generic-pool/package.json index eae64c64f9..33eef11c7b 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/package.json +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-generic-pool", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry Generic Pool automatic instrumentation package", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -53,16 +53,15 @@ "@types/node": "18.11.7", "@types/semver": "7.3.8", "generic-pool": "3.8.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "semver": "7.3.5", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/generic-pool": "^3.1.9" }, diff --git a/plugins/node/opentelemetry-instrumentation-graphql/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-graphql/CHANGELOG.md index db31c26569..ad90b3f5f8 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-graphql/CHANGELOG.md @@ -1,5 +1,37 @@ # Changelog +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-graphql-v0.34.0...instrumentation-graphql-v0.34.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-graphql-v0.33.2...instrumentation-graphql-v0.34.0) (2023-04-06) + + +### âš  BREAKING CHANGES + +* **gql:** conform GraphQL span name to spec ([#1444](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1444)) + +### Bug Fixes + +* **gql:** conform GraphQL span name to spec ([#1444](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1444)) ([7d070db](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/7d070db276dffd82faa906e8e4a8ed8dcb790c6d)) + +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-graphql-v0.33.1...instrumentation-graphql-v0.33.2) (2023-03-03) + + +### Bug Fixes + +* remove component attribute from instrumentations ([#1399](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1399)) ([e93a192](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e93a192b672c8db361bac83ad60294ca49b95361)) + +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-graphql-v0.33.0...instrumentation-graphql-v0.33.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-graphql-v0.32.0...instrumentation-graphql-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-graphql/package.json b/plugins/node/opentelemetry-instrumentation-graphql/package.json index 50ca91155e..0d3619a1ac 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/package.json +++ b/plugins/node/opentelemetry-instrumentation-graphql/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-graphql", - "version": "0.33.0", + "version": "0.34.1", "description": "OpenTelemetry @opentelemetry/instrumentation-graphql automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -53,16 +53,15 @@ "@types/mocha": "8.2.3", "@types/node": "18.11.7", "graphql": "^16.5.0", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts index d264930721..79032ab55d 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts @@ -14,7 +14,6 @@ * limitations under the License. */ export enum AttributeNames { - COMPONENT = 'graphql', SOURCE = 'graphql.source', FIELD_NAME = 'graphql.field.name', FIELD_PATH = 'graphql.field.path', diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts index 3803ef5880..438121605d 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts @@ -404,18 +404,21 @@ export class GraphQLInstrumentation extends InstrumentationBase { const span = this.tracer.startSpan(SpanNames.EXECUTE, {}); if (operation) { - const operationDefinition = + const { operation: operationType, name: nameNode } = operation as graphqlTypes.OperationDefinitionNode; - span.setAttribute( - AttributeNames.OPERATION_TYPE, - operationDefinition.operation - ); - if (operationDefinition.name) { - span.setAttribute( - AttributeNames.OPERATION_NAME, - operationDefinition.name.value - ); + span.setAttribute(AttributeNames.OPERATION_TYPE, operationType); + + const operationName = nameNode?.value; + + // https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/graphql/ + // > The span name MUST be of the format provided that graphql.operation.type and graphql.operation.name are available. + // > If graphql.operation.name is not available, the span SHOULD be named . + if (operationName) { + span.setAttribute(AttributeNames.OPERATION_NAME, operationName); + span.updateName(`${operationType} ${operationName}`); + } else { + span.updateName(operationType); } } else { let operationName = ' '; diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts index f5c908c3ea..e694fa8f49 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts @@ -169,7 +169,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -297,7 +297,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -395,7 +395,7 @@ describe('graphql', () => { executeSpan.attributes[`${AttributeNames.VARIABLES}id`], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query Query1'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -487,7 +487,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); }); @@ -555,7 +555,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); }); @@ -752,7 +752,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], undefined ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -848,7 +848,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], 'AddBook' ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'mutation AddBook'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -946,7 +946,7 @@ describe('graphql', () => { executeSpan.attributes[`${AttributeNames.VARIABLES}id`], 2 ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'query Query1'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -1044,7 +1044,7 @@ describe('graphql', () => { executeSpan.attributes[AttributeNames.OPERATION_NAME], 'AddBook' ); - assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); + assert.deepStrictEqual(executeSpan.name, 'mutation AddBook'); assert.deepStrictEqual(executeSpan.parentSpanId, undefined); }); @@ -1317,7 +1317,7 @@ describe('graphql', () => { // validate execute span is present const spans = exporter.getFinishedSpans(); - const executeSpans = spans.filter(s => s.name === SpanNames.EXECUTE); + const executeSpans = spans.filter(s => s.name === 'query'); assert.deepStrictEqual(executeSpans.length, 1); const [executeSpan] = executeSpans; assert.deepStrictEqual( @@ -1371,7 +1371,7 @@ describe('graphql', () => { ); // single execute span - const executeSpans = spans.filter(s => s.name === SpanNames.EXECUTE); + const executeSpans = spans.filter(s => s.name === 'query'); assert.deepStrictEqual(executeSpans.length, 1); }); }); diff --git a/plugins/node/opentelemetry-instrumentation-hapi/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-hapi/CHANGELOG.md index 0b926a512e..1ffe858da4 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-hapi/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-hapi-v0.31.1...instrumentation-hapi-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-hapi-v0.31.0...instrumentation-hapi-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-hapi-v0.30.1...instrumentation-hapi-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-hapi/package.json b/plugins/node/opentelemetry-instrumentation-hapi/package.json index 2caa49e01c..532833bfdf 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/package.json +++ b/plugins/node/opentelemetry-instrumentation-hapi/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-hapi", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry Hapi automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -52,16 +52,15 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/hapi__hapi": "20.0.9" }, diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts index 1e15b28276..e671041b54 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts @@ -57,7 +57,7 @@ export class HapiInstrumentation extends InstrumentationBase { protected init() { return new InstrumentationNodeModuleDefinition( HapiComponentName, - ['>=17.0.0'], + ['>=17 <21'], moduleExports => { if (!isWrapped(moduleExports.server)) { api.diag.debug('Patching Hapi.server'); @@ -348,7 +348,7 @@ export class HapiInstrumentation extends InstrumentationBase { undefined, ...params ); - } catch (err) { + } catch (err: any) { span.recordException(err); span.setStatus({ code: api.SpanStatusCode.ERROR, @@ -401,7 +401,7 @@ export class HapiInstrumentation extends InstrumentationBase { api.trace.setSpan(api.context.active(), span), () => oldHandler(...params) ); - } catch (err) { + } catch (err: any) { span.recordException(err); span.setStatus({ code: api.SpanStatusCode.ERROR, diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml b/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml index 5b1b56c88c..29bd4413db 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml @@ -1,6 +1,6 @@ ioredis: # Ignoring v4.19.0. Tests never ends. Caused by https://github.com/luin/ioredis/pull/1219 - versions: "^2.5.0 || ^3.2.2 || 4.14.1 || 4.16.3 || 4.17.3 || 4.18.0 || 4.19.2 || 4.19.4 || 4.22.0 || 4.24.5 || 4.26.0 || 4.27.2 || ^4.27.6" + versions: "^2.5.0 || ^3.2.2 || 4.14.1 || 4.16.3 || 4.17.3 || 4.18.0 || 4.19.2 || 4.19.4 || 4.22.0 || 4.24.5 || 4.26.0 || 4.27.2 || ^4.27.6 || 5.0.4 || ^5.2.4" commands: npm run test # Fix missing `contrib-test-utils` package diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md index d29dea2629..2cd7b7f802 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/CHANGELOG.md @@ -1,5 +1,47 @@ # Changelog +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.34.0...instrumentation-ioredis-v0.34.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.33.2...instrumentation-ioredis-v0.34.0) (2023-03-03) + + +### Features + +* **ioredis:** Update instrumentation-ioredis to version 5.x.x ([#1121](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1121)) ([f5f7ac6](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/f5f7ac6196b5422e030a6913c491117a6a3a0690)) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.34.0 to ^0.35.0 + +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.33.1...instrumentation-ioredis-v0.33.2) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-ioredis-v0.33.0...instrumentation-ioredis-v0.33.1) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/README.md b/plugins/node/opentelemetry-instrumentation-ioredis/README.md index a9d72ffd3d..61444f28e7 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/README.md +++ b/plugins/node/opentelemetry-instrumentation-ioredis/README.md @@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-ioredis ### Supported Versions -- `>=2.0.0 <5` +- `>=2.0.0 <6` ## Usage @@ -47,7 +47,7 @@ registerInstrumentations({ IORedis instrumentation has few options available to choose from. You can set the following: | Options | Type | Description | -| ----------------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | +|-------------------------|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------| | `dbStatementSerializer` | `DbStatementSerializer` | IORedis instrumentation will serialize db.statement using the specified function. | | `requestHook` | `RedisRequestCustomAttributeFunction` (function) | Function for adding custom attributes on db request. Receives params: `span, { moduleVersion, cmdName, cmdArgs }` | | `responseHook` | `RedisResponseCustomAttributeFunction` (function) | Function for adding custom attributes on db response | diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index d05e59cbaf..70eb4acfb3 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-ioredis", - "version": "0.33.1", + "version": "0.34.1", "description": "OpenTelemetry ioredis automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -52,28 +52,27 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/sinon": "10.0.9", "@types/node": "18.11.7", "cross-env": "7.0.3", - "gts": "3.1.0", - "ioredis": "4.27.7", + "ioredis": "5.2.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/redis-common": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/redis-common": "^0.35.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/ioredis": "4.26.6" + "@types/ioredis4": "npm:@types/ioredis@^4.28.10" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts index ac2d32b8d1..94f8b850ed 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts @@ -15,13 +15,13 @@ */ import { diag, trace, context, SpanKind } from '@opentelemetry/api'; -import type * as ioredisTypes from 'ioredis'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped, } from '@opentelemetry/instrumentation'; -import { IORedisInstrumentationConfig, IORedisCommand } from './types'; +import { IORedisInstrumentationConfig } from './types'; +import { IORedisCommand, RedisInterface } from './internal-types'; import { DbSystemValues, SemanticAttributes, @@ -35,9 +35,7 @@ const DEFAULT_CONFIG: IORedisInstrumentationConfig = { requireParentSpan: true, }; -export class IORedisInstrumentation extends InstrumentationBase< - typeof ioredisTypes -> { +export class IORedisInstrumentation extends InstrumentationBase { constructor(_config: IORedisInstrumentationConfig = {}) { super( '@opentelemetry/instrumentation-ioredis', @@ -46,11 +44,11 @@ export class IORedisInstrumentation extends InstrumentationBase< ); } - init(): InstrumentationNodeModuleDefinition[] { + init(): InstrumentationNodeModuleDefinition[] { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( 'ioredis', - ['>1 <5'], + ['>1', '<6'], (moduleExports, moduleVersion?: string) => { diag.debug('Applying patch for ioredis'); if (isWrapped(moduleExports.prototype.sendCommand)) { @@ -98,7 +96,7 @@ export class IORedisInstrumentation extends InstrumentationBase< private traceSendCommand = (original: Function, moduleVersion?: string) => { const instrumentation = this; - return function (this: ioredisTypes.Redis, cmd?: IORedisCommand) { + return function (this: RedisInterface, cmd?: IORedisCommand) { if (arguments.length < 1 || typeof cmd !== 'object') { return original.apply(this, arguments); } @@ -175,7 +173,7 @@ export class IORedisInstrumentation extends InstrumentationBase< }; return result; - } catch (error) { + } catch (error: any) { endSpan(span, error); throw error; } @@ -184,7 +182,7 @@ export class IORedisInstrumentation extends InstrumentationBase< private traceConnection = (original: Function) => { const instrumentation = this; - return function (this: ioredisTypes.Redis) { + return function (this: RedisInterface) { const config = instrumentation.getConfig() as IORedisInstrumentationConfig; const hasNoParentSpan = trace.getSpan(context.active()) === undefined; @@ -210,7 +208,7 @@ export class IORedisInstrumentation extends InstrumentationBase< const client = original.apply(this, arguments); endSpan(span, null); return client; - } catch (error) { + } catch (error: any) { endSpan(span, error); throw error; } diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/internal-types.ts new file mode 100644 index 0000000000..b399a1eb79 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/internal-types.ts @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { Command, Redis } from 'ioredis'; +import type * as LegacyIORedis from 'ioredis4'; + +interface LegacyIORedisCommand { + reject: (err: Error) => void; + resolve: (result: {}) => void; + promise: Promise<{}>; + args: Array; + callback: LegacyIORedis.CallbackFunction; + name: string; +} + +export type IORedisCommand = Command | LegacyIORedisCommand; +export type RedisInterface = Redis | LegacyIORedis.Redis; diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/src/types.ts b/plugins/node/opentelemetry-instrumentation-ioredis/src/types.ts index 66f3137484..5d32116a67 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/src/types.ts @@ -14,18 +14,10 @@ * limitations under the License. */ -import type * as ioredisTypes from 'ioredis'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; import { Span } from '@opentelemetry/api'; -export interface IORedisCommand { - reject: (err: Error) => void; - resolve: (result: {}) => void; - promise: Promise<{}>; - args: Array; - callback: ioredisTypes.CallbackFunction; - name: string; -} +export type CommandArgs = Array; /** * Function that can be used to serialize db.statement tag @@ -35,14 +27,14 @@ export interface IORedisCommand { * @returns serialized string that will be used as the db.statement attribute. */ export type DbStatementSerializer = ( - cmdName: IORedisCommand['name'], - cmdArgs: IORedisCommand['args'] + cmdName: string, + cmdArgs: CommandArgs ) => string; export interface IORedisRequestHookInformation { moduleVersion?: string; - cmdName: IORedisCommand['name']; - cmdArgs: IORedisCommand['args']; + cmdName: string; + cmdArgs: CommandArgs; } export interface RedisRequestCustomAttributeFunction { @@ -59,12 +51,7 @@ export interface RedisRequestCustomAttributeFunction { * The type of the response varies depending on the specific command. */ export interface RedisResponseCustomAttributeFunction { - ( - span: Span, - cmdName: IORedisCommand['name'], - cmdArgs: IORedisCommand['args'], - response: unknown - ): void; + (span: Span, cmdName: string, cmdArgs: CommandArgs, response: unknown): void; } /** diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts index a54ea1b812..5df678ea4d 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-ioredis/test/ioredis.test.ts @@ -81,7 +81,7 @@ const sanitizeEventForAssertion = (span: ReadableSpan) => { describe('ioredis', () => { const provider = new NodeTracerProvider(); - let ioredis: typeof ioredisTypes; + let ioredis: typeof ioredisTypes.default; let instrumentation: IORedisInstrumentation; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; @@ -188,14 +188,14 @@ describe('ioredis', () => { name: string; args: Array; expectedDbStatement: string; - method: (cb: ioredisTypes.CallbackFunction) => unknown; + method: (cb: ioredisTypes.Callback) => unknown; }> = [ { description: 'insert', name: 'hset', args: [hashKeyName, 'testField', 'testValue'], expectedDbStatement: `${hashKeyName} testField [1 other arguments]`, - method: (cb: ioredisTypes.CallbackFunction) => + method: (cb: ioredisTypes.Callback) => client.hset(hashKeyName, 'testField', 'testValue', cb), }, { @@ -203,7 +203,7 @@ describe('ioredis', () => { name: 'get', args: [testKeyName], expectedDbStatement: `${testKeyName}`, - method: (cb: ioredisTypes.CallbackFunction) => + method: (cb: ioredisTypes.Callback) => client.get(testKeyName, cb), }, ]; @@ -307,7 +307,7 @@ describe('ioredis', () => { // should throw 'ReplyError: ERR value is not an integer or out of range' // because the value im the key is not numeric and we try to increment it await client.incr('non-int-key'); - } catch (ex) { + } catch (ex: any) { const endedSpans = memoryExporter.getFinishedSpans(); assert.strictEqual(endedSpans.length, 2); const ioredisSpan = endedSpans[1]; @@ -960,7 +960,7 @@ describe('ioredis', () => { describe('setConfig - custom dbStatementSerializer config', () => { const dbStatementSerializer = ( cmdName: string, - cmdArgs: Array + cmdArgs: Array ) => { return Array.isArray(cmdArgs) && cmdArgs.length ? `FooBar_${cmdName} ${cmdArgs.join(',')}` diff --git a/plugins/node/opentelemetry-instrumentation-knex/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-knex/CHANGELOG.md index 4899a4891a..c4d63514bb 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-knex/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-knex-v0.31.1...instrumentation-knex-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-knex-v0.31.0...instrumentation-knex-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-knex-v0.30.1...instrumentation-knex-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 9a49d97f93..911ea3c18f 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-knex", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry Knex automatic instrumentation package", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -51,17 +51,16 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "knex": "0.95.9", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sqlite3": "5.0.3", + "rimraf": "4.2.0", + "sqlite3": "5.1.5", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex#readme" diff --git a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts index 8e90950660..f939160b0f 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts @@ -246,7 +246,7 @@ const assertSpans = (actualSpans: any[], expectedSpans: any[]) => { span.parentSpanId, expected.parentSpan?.spanContext().spanId ); - } catch (e) { + } catch (e: any) { e.message = `At span[${idx}]: ${e.message}`; throw e; } diff --git a/plugins/node/opentelemetry-instrumentation-koa/.tav.yml b/plugins/node/opentelemetry-instrumentation-koa/.tav.yml index 4f6d442e38..2cd22120aa 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-koa/.tav.yml @@ -1,3 +1,7 @@ +"@koa/router": + versions: "8.0.8 || 9.4.0 || 10.0.0 || 10.1.1 || 11.0.1 || >=12.0.0" + commands: npm run test + koa: # Testing ^2.7.0 covers at least 97% of the downloaded koa versions versions: "^2.7.0" diff --git a/plugins/node/opentelemetry-instrumentation-koa/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-koa/CHANGELOG.md index 393956fa28..25bbc422c4 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-koa/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.34.4](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-koa-v0.34.3...instrumentation-koa-v0.34.4) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.34.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-koa-v0.34.2...instrumentation-koa-v0.34.3) (2023-04-06) + + +### Bug Fixes + +* **@types/koa:** update @types/koa version to latest ([#1447](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1447)) ([5f180aa](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/5f180aa05d3140010642287de933c708e915b619)) + +## [0.34.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-koa-v0.34.1...instrumentation-koa-v0.34.2) (2023-03-03) + + +### Bug Fixes + +* remove component attribute from instrumentations ([#1399](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1399)) ([e93a192](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e93a192b672c8db361bac83ad60294ca49b95361)) + +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-koa-v0.34.0...instrumentation-koa-v0.34.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-koa-v0.33.0...instrumentation-koa-v0.34.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-koa/README.md b/plugins/node/opentelemetry-instrumentation-koa/README.md index 26f1d1a289..d964ca8c78 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/README.md +++ b/plugins/node/opentelemetry-instrumentation-koa/README.md @@ -17,7 +17,8 @@ npm install --save @opentelemetry/instrumentation-koa ### Supported Versions -- `^2.0.0` +- `koa`: `^2.0.0` +- `@koa/router`: `>=8` ## Usage diff --git a/plugins/node/opentelemetry-instrumentation-koa/examples/package.json b/plugins/node/opentelemetry-instrumentation-koa/examples/package.json index 71733c6b81..09fa88ab1e 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/examples/package.json @@ -30,12 +30,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib/issues" }, "dependencies": { - "@koa/router": "^9.3.1", + "@koa/router": "^12.0.0", "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.32.0", - "@opentelemetry/instrumentation-http": "^0.32.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-http": "^0.38.0", "@opentelemetry/instrumentation-koa": "^0.31.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", @@ -46,7 +46,7 @@ "devDependencies": { "cross-env": "^6.0.0", "ts-node": "^10.6.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "@types/koa": "^2.13.5" } } diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index c29ba96578..504b0781af 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-koa", - "version": "0.34.0", + "version": "0.34.4", "description": "OpenTelemetry Koa automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,7 +49,7 @@ "@opentelemetry/api": "^1.3.0" }, "devDependencies": { - "@koa/router": "9.4.0", + "@koa/router": "12.0.0", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", @@ -57,21 +57,20 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.9", - "gts": "3.1.0", "koa": "2.13.1", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/koa": "2.13.4", + "@types/koa": "2.13.6", "@types/koa__router": "8.0.7" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa#readme" diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts index 2a454e0ef8..f270875efa 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts @@ -33,15 +33,10 @@ import { AttributeNames } from './enums/AttributeNames'; import { VERSION } from './version'; import { getMiddlewareMetadata, isLayerIgnored } from './utils'; import { getRPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core'; -import { - kLayerPatched, - KoaComponentName, - KoaPatchedMiddleware, -} from './internal-types'; +import { kLayerPatched, KoaPatchedMiddleware } from './internal-types'; /** Koa instrumentation for OpenTelemetry */ export class KoaInstrumentation extends InstrumentationBase { - static readonly component = KoaComponentName; constructor(config: KoaInstrumentationConfig = {}) { super( '@opentelemetry/instrumentation-koa', @@ -216,7 +211,7 @@ export class KoaInstrumentation extends InstrumentationBase { return api.context.with(newContext, async () => { try { return await middlewareLayer(context, next); - } catch (err) { + } catch (err: any) { span.recordException(err); throw err; } finally { diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-koa/src/internal-types.ts index d228b0f4fc..05557e938a 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/internal-types.ts @@ -24,5 +24,3 @@ export const kLayerPatched: unique symbol = Symbol('koa-layer-patched'); export type KoaPatchedMiddleware = KoaMiddleware & { [kLayerPatched]?: boolean; }; - -export const KoaComponentName = 'koa'; diff --git a/plugins/node/opentelemetry-instrumentation-memcached/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-memcached/CHANGELOG.md index 38a20ce01f..7d7f658cdf 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-memcached/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-memcached-v0.31.1...instrumentation-memcached-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-memcached-v0.31.0...instrumentation-memcached-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-memcached-v0.30.1...instrumentation-memcached-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-memcached/package.json b/plugins/node/opentelemetry-instrumentation-memcached/package.json index 4e09f64ae2..5ed4ce9f71 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/package.json +++ b/plugins/node/opentelemetry-instrumentation-memcached/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-memcached", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry memcached automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,22 +49,21 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "cross-env": "7.0.3", - "gts": "3.1.0", "memcached": "2.2.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/memcached": "^2.2.6" }, diff --git a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts index 4639035b6a..01f116d0fc 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts @@ -301,7 +301,7 @@ const assertSpans = (actualSpans: any[], expectedSpans: any[]) => { span.parentSpanId, expected.parentSpan?.spanContext().spanId ); - } catch (e) { + } catch (e: any) { e.message = `At span[${idx}]: ${e.message}`; throw e; } diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/.tav.yml b/plugins/node/opentelemetry-instrumentation-mongodb/.tav.yml index 00de6af24f..c369d133f6 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-mongodb/.tav.yml @@ -2,7 +2,7 @@ mongodb: jobs: - versions: ">=3.3 <4" commands: npm run test - - versions: ">=4" + - versions: ">=4 <5" commands: npm run test-new-versions # Fix missing `contrib-test-utils` package diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md index 0d34a21eb6..caef8b4082 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-mongodb/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.34.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongodb-v0.34.1...instrumentation-mongodb-v0.34.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongodb-v0.34.0...instrumentation-mongodb-v0.34.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mongodb-v0.33.0...instrumentation-mongodb-v0.34.0) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json index f25bbe36ab..4f74cc9ff5 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json @@ -33,8 +33,8 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.32.0", - "@opentelemetry/instrumentation-http": "^0.32.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-http": "^0.38.0", "@opentelemetry/instrumentation-mongodb": "^0.32.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", @@ -44,6 +44,6 @@ "devDependencies": { "cross-env": "^7.0.3", "ts-node": "^10.6.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index b0232a3287..fc1526c84c 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-mongodb", - "version": "0.34.0", + "version": "0.34.2", "description": "OpenTelemetry mongodb automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -51,24 +51,24 @@ }, "devDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "mongodb": "3.6.11", "@types/mongodb": "3.6.20", + "@types/bson": "4.0.5", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/tsconfig.json b/plugins/node/opentelemetry-instrumentation-mongodb/tsconfig.json index 28be80d266..5c3680dd33 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/tsconfig.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../../tsconfig.base", "compilerOptions": { "rootDir": ".", - "outDir": "build" + "outDir": "build", + "skipLibCheck": true }, "include": [ "src/**/*.ts", diff --git a/plugins/node/opentelemetry-instrumentation-mysql/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-mysql/CHANGELOG.md index 543e160bf3..f5b1a6a6c1 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-mysql/CHANGELOG.md @@ -1,5 +1,39 @@ # Changelog +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql-v0.33.0...instrumentation-mysql-v0.33.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql-v0.32.0...instrumentation-mysql-v0.33.0) (2023-02-07) + + +### Features + +* **mysql:** Metrics for mysql ([#1220](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1220)) ([8b8bfeb](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/8b8bfebdd6b4f43a8df540979874a6c01c999957)) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) +* **mysql:** add enhancedDatabaseReporting to mysql ([#1337](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1337)) ([04d583b](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/04d583bc879c275d521ed5cbee84a3b79e1292eb)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql-v0.31.2...instrumentation-mysql-v0.32.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json b/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json index bf8dae57ec..5abdb9fd06 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json @@ -34,8 +34,8 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.32.0", - "@opentelemetry/instrumentation-http": "^0.32.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-http": "^0.38.0", "@opentelemetry/instrumentation-mysql": "^0.31.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", @@ -47,6 +47,6 @@ "@types/mysql": "^2.15.21", "cross-env": "^6.0.0", "ts-node": "^10.6.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index 6fdc09c186..8bf39d0c19 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-mysql", - "version": "0.32.0", + "version": "0.33.1", "description": "OpenTelemetry mysql automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,23 +49,22 @@ "@opentelemetry/api": "^1.3.0", "@opentelemetry/sdk-metrics": "^1.8.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.13", - "gts": "3.1.0", "mocha": "7.2.0", + "mysql": "2.18.1", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", - "mysql": "2.18.1", "@types/mysql": "2.15.19" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 77c319a480..8ef20b9e2b 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -73,8 +73,8 @@ export class MySQLInstrumentation extends InstrumentationBase< 'db.client.connections.usage', //TODO:: use semantic convention { description: - 'The number of connections that are currently in the state referenced by the attribute "state".', - unit: '{connections}', + 'The number of connections that are currently in state described by the state attribute.', + unit: '{connection}', } ); } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts index 6f2e11d307..9eb7e90827 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts @@ -22,7 +22,7 @@ import type { Query, QueryOptions, } from 'mysql'; -import * as mysqlTypes from 'mysql'; +import type * as mysqlTypes from 'mysql'; /** * Get an SpanAttributes map from a mysql connection config object diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts index ba79c40c9a..2bea7e88e5 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.metrics.test.ts @@ -159,9 +159,9 @@ describe('mysql@2.x-Metrics', () => { assert.strictEqual( metrics[0].descriptor.description, - 'The number of connections that are currently in the state referenced by the attribute "state".' + 'The number of connections that are currently in state described by the state attribute.' ); - assert.strictEqual(metrics[0].descriptor.unit, '{connections}'); + assert.strictEqual(metrics[0].descriptor.unit, '{connection}'); assert.strictEqual( metrics[0].descriptor.name, 'db.client.connections.usage' @@ -248,9 +248,9 @@ describe('mysql@2.x-Metrics', () => { assert.strictEqual(metrics[0].dataPointType, DataPointType.SUM); assert.strictEqual( metrics[0].descriptor.description, - 'The number of connections that are currently in the state referenced by the attribute "state".' + 'The number of connections that are currently in state described by the state attribute.' ); - assert.strictEqual(metrics[0].descriptor.unit, '{connections}'); + assert.strictEqual(metrics[0].descriptor.unit, '{connection}'); assert.strictEqual( metrics[0].descriptor.name, 'db.client.connections.usage' @@ -325,9 +325,9 @@ describe('mysql@2.x-Metrics', () => { assert.strictEqual( metrics[0].descriptor.description, - 'The number of connections that are currently in the state referenced by the attribute "state".' + 'The number of connections that are currently in state described by the state attribute.' ); - assert.strictEqual(metrics[0].descriptor.unit, '{connections}'); + assert.strictEqual(metrics[0].descriptor.unit, '{connection}'); assert.strictEqual( metrics[0].descriptor.name, 'db.client.connections.usage' diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml b/plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml index 83cb0a4139..36a11005c7 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml @@ -1,4 +1,7 @@ mysql2: + - versions: <4 >=3.2.0 || 3.1.0 || 3.0.0 + commands: npm run test + - versions: <3 >=2.3.2 || 2.3.0 || 2.2.5 || 2.1.0 # Skip 2.3.3 which installs types from git which takes 10m on it's own commands: npm run test diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-mysql2/CHANGELOG.md index d5050cbd71..b483cda31d 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-mysql2/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql2-v0.33.1...instrumentation-mysql2-v0.33.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql2-v0.33.0...instrumentation-mysql2-v0.33.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-mysql2-v0.32.1...instrumentation-mysql2-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/README.md b/plugins/node/opentelemetry-instrumentation-mysql2/README.md index c828c21e27..d0940894b7 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql2/README.md @@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-mysql2 ## Supported Versions -- `>= 1.4.2, < 3.0` +- `>= 1.4.2, < 4.0` ## Usage diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/package.json b/plugins/node/opentelemetry-instrumentation-mysql2/package.json index a9f95f18c9..1ffddf6d79 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql2/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-mysql2", - "version": "0.33.0", + "version": "0.33.2", "description": "OpenTelemetry mysql2 automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -49,24 +49,23 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/mocha": "7.0.2", "@types/mysql2": "github:types/mysql2", "@types/node": "18.11.7", "@types/semver": "7.3.8", - "gts": "3.1.0", "mocha": "7.2.0", "mysql2": "2.3.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "semver": "7.3.5", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts index fde904f2bf..682ebe0b04 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts @@ -50,7 +50,7 @@ export class MySQL2Instrumentation extends InstrumentationBase { return [ new InstrumentationNodeModuleDefinition( 'mysql2', - ['>= 1.4.2 < 3.0'], + ['>= 1.4.2 < 4.0'], (moduleExports: any, moduleVersion) => { api.diag.debug(`Patching mysql@${moduleVersion}`); diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-nestjs-core/CHANGELOG.md index 5f4420dcfe..d776e1988b 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [0.32.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-nestjs-core-v0.32.2...instrumentation-nestjs-core-v0.32.3) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-nestjs-core-v0.32.1...instrumentation-nestjs-core-v0.32.2) (2023-02-14) + + +### Bug Fixes + +* **vinyl-fs:** removed unnecessary dep types/vinyl-fs ([#1390](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1390)) ([5a8df08](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/5a8df0826b24c37ae5b992d5f68286f9742ce79f)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-nestjs-core-v0.32.0...instrumentation-nestjs-core-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-nestjs-core-v0.31.1...instrumentation-nestjs-core-v0.32.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json b/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json index 9c49edf48c..ec9eb1333c 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-nestjs-core", - "version": "0.32.0", + "version": "0.32.3", "description": "OpenTelemetry NestJS automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -15,7 +15,7 @@ "prewatch": "npm run precompile", "prepare": "npm run compile", "tdd": "npm run test -- --watch-extensions ts --watch", - "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "test": "nyc ts-mocha --timeout 5000 -p tsconfig.json 'test/**/*.test.ts'", "test-all-versions": "tav", "version:update": "node ../../../scripts/version-update.js" }, @@ -60,22 +60,20 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/semver": "7.3.8", - "@types/vinyl-fs": "2.4.12", "cross-env": "7.0.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "reflect-metadata": "0.1.13", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "rxjs": "7.3.0", "rxjs-compat": "6.6.7", "semver": "7.3.5", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core#readme" diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-nestjs-core/src/instrumentation.ts index aca8e53d11..30d2dc4f78 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/src/instrumentation.ts @@ -145,7 +145,7 @@ function createWrapNestFactoryCreate( return api.context.with(spanContext, async () => { try { return await original.apply(this, arguments as any); - } catch (e) { + } catch (e: any) { throw addError(span, e); } finally { span.end(); @@ -198,7 +198,7 @@ function createWrapCreateHandler(tracer: api.Tracer, moduleVersion?: string) { return api.context.with(spanContext, async () => { try { return await handler.apply(this, arguments as any); - } catch (e) { + } catch (e: any) { throw addError(span, e); } finally { span.end(); @@ -228,7 +228,7 @@ function createWrapHandler( return api.context.with(spanContext, async () => { try { return await handler.apply(this, arguments); - } catch (e) { + } catch (e: any) { throw addError(span, e); } finally { span.end(); diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts index 5405992128..b9efef6475 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/test/index.test.ts @@ -267,7 +267,7 @@ const assertSpans = (actualSpans: any[], expectedSpans: any[]) => { expected.parentSpan?.spanContext().spanId ); } - } catch (e) { + } catch (e: any) { e.message = `At span[${idx}] "${span.name}": ${e.message}`; throw e; } diff --git a/plugins/node/opentelemetry-instrumentation-net/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-net/CHANGELOG.md index c35f04aaf1..5df4e5b3ee 100644 --- a/plugins/node/opentelemetry-instrumentation-net/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-net/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-net-v0.31.1...instrumentation-net-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-net-v0.31.0...instrumentation-net-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) +* **instrumentation-net:** make tls span parent of net span ([#1342](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1342)) ([1ee197e](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/1ee197ed74e44054b092d0adcdac7f9db1a42737)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-net-v0.30.2...instrumentation-net-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-net/package.json b/plugins/node/opentelemetry-instrumentation-net/package.json index 5437cb5b63..a4501047f8 100644 --- a/plugins/node/opentelemetry-instrumentation-net/package.json +++ b/plugins/node/opentelemetry-instrumentation-net/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-net", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry net module automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -53,16 +53,15 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-net#readme" diff --git a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts index 9826c8dc27..1aefd0e466 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts @@ -199,7 +199,7 @@ describe('NetInstrumentation', () => { // socket.connect() will not throw before node@16 only closes socket.once(SocketEvent.CLOSE, assertSpan); socket.connect(undefined as unknown as string); - } catch (e) { + } catch (e: any) { // socket.connect() will throw in node@16 socket.removeListener(SocketEvent.CLOSE, assertSpan); assert.strictEqual( diff --git a/plugins/node/opentelemetry-instrumentation-pg/.tav.yml b/plugins/node/opentelemetry-instrumentation-pg/.tav.yml index 42321ea8b8..fa1d669474 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-pg/.tav.yml @@ -4,7 +4,3 @@ pg: peerDependencies: pg-pool@^3 pretest: npm run --prefix ../../../ lerna:link commands: npm run test - - versions: "7.3.0 || 7.12.1 || 7.18.2" - peerDependencies: pg-pool@^2 - pretest: npm run --prefix ../../../ lerna:link - commands: npm run test diff --git a/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md index 6d765bee3e..536c67b1d2 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-pg/CHANGELOG.md @@ -1,5 +1,46 @@ # Changelog +## [0.35.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.35.0...instrumentation-pg-v0.35.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.35.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.34.1...instrumentation-pg-v0.35.0) (2023-03-03) + + +### Features + +* **pg:** remove support for pg v7 ([#1393](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1393)) ([ae6d4f3](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ae6d4f39fc882d16e65e846218a69fb72586de3e)) + + +### Bug Fixes + +* **postgres:** pass 'arguments' to the connect callback ([#1395](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1395)) ([b02775f](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/b02775f0d9e84dea5463bb9a3883d0ad6ff1f500)) + +## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.34.0...instrumentation-pg-v0.34.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) +* **pg:** update requireParentSpan to skip instrumentation when parent not present ([#1343](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1343)) ([d23c329](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/d23c329a1581709ddc0f336fddfa1aa930f90c3f)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.34.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pg-v0.33.0...instrumentation-pg-v0.34.0) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-pg/README.md b/plugins/node/opentelemetry-instrumentation-pg/README.md index 3703143057..3f624bd3b3 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/README.md +++ b/plugins/node/opentelemetry-instrumentation-pg/README.md @@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-pg ### Supported Versions -- `>=7 <9` +- `>=8 <9` ## Usage diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 918375f69a..73350e61bc 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-pg", - "version": "0.34.0", + "version": "0.35.1", "description": "OpenTelemetry postgres automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -55,28 +55,27 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.2", "cross-env": "7.0.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "pg": "8.7.1", "pg-pool": "3.4.1", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "safe-stable-stringify": "^2.4.1", - "sinon": "14.0.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/pg": "8.6.1", "@types/pg-pool": "2.0.3" diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index e41ce010ae..a5eff14498 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -20,13 +20,19 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; -import { context, diag, trace, Span, SpanStatusCode } from '@opentelemetry/api'; +import { + context, + diag, + trace, + Span, + SpanStatusCode, + SpanKind, +} from '@opentelemetry/api'; import type * as pgTypes from 'pg'; import type * as pgPoolTypes from 'pg-pool'; import { PgClientConnect, PgClientExtended, - PgErrorCallback, PostgresCallback, PgPoolExtended, PgPoolCallback, @@ -39,7 +45,6 @@ import { DbSystemValues, } from '@opentelemetry/semantic-conventions'; import { VERSION } from './version'; -import { startSpan } from './utils'; const PG_POOL_COMPONENT = 'pg-pool'; @@ -59,7 +64,7 @@ export class PgInstrumentation extends InstrumentationBase { protected init() { const modulePG = new InstrumentationNodeModuleDefinition( 'pg', - ['7.*', '8.*'], + ['8.*'], moduleExports => { if (isWrapped(moduleExports.Client.prototype.query)) { this._unwrap(moduleExports.Client.prototype, 'query'); @@ -127,17 +132,19 @@ export class PgInstrumentation extends InstrumentationBase { private _getClientConnectPatch() { const plugin = this; return (original: PgClientConnect) => { - return function connect( - this: pgTypes.Client, - callback?: PgErrorCallback - ) { - const span = startSpan( - plugin.tracer, - plugin.getConfig(), + return function connect(this: pgTypes.Client, callback?: Function) { + if (utils.shouldSkipInstrumentation(plugin.getConfig())) { + return original.call(this, callback); + } + + const span = plugin.tracer.startSpan( `${PgInstrumentation.COMPONENT}.connect`, { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, - ...utils.getSemanticAttributesFromConnection(this), + kind: SpanKind.CLIENT, + attributes: { + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, + ...utils.getSemanticAttributesFromConnection(this), + }, } ); @@ -168,6 +175,10 @@ export class PgInstrumentation extends InstrumentationBase { `Patching ${PgInstrumentation.COMPONENT}.Client.prototype.query` ); return function query(this: PgClientExtended, ...args: unknown[]) { + if (utils.shouldSkipInstrumentation(plugin.getConfig())) { + return original.apply(this, args as never); + } + // client.query(text, cb?), client.query(text, values, cb?), and // client.query(configObj, cb?) are all valid signatures. We construct // a queryConfig obj from all (valid) signatures to build the span in a @@ -348,19 +359,21 @@ export class PgInstrumentation extends InstrumentationBase { const plugin = this; return (originalConnect: typeof pgPoolTypes.prototype.connect) => { return function connect(this: PgPoolExtended, callback?: PgPoolCallback) { + if (utils.shouldSkipInstrumentation(plugin.getConfig())) { + return originalConnect.call(this, callback as any); + } + // setup span - const span = startSpan( - plugin.tracer, - plugin.getConfig(), - `${PG_POOL_COMPONENT}.connect`, - { + const span = plugin.tracer.startSpan(`${PG_POOL_COMPONENT}.connect`, { + kind: SpanKind.CLIENT, + attributes: { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, ...utils.getSemanticAttributesFromConnection(this.options), [AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options.idleTimeoutMillis, [AttributeNames.MAX_CLIENT]: this.options.maxClient, - } - ); + }, + }); if (callback) { const parentSpan = trace.getSpan(context.active()); diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts index 546d84b9ee..1270814499 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/internal-types.ts @@ -46,8 +46,6 @@ export type PgPoolCallback = ( done: (release?: any) => void ) => void; -export type PgErrorCallback = (err: Error) => void; - export interface PgPoolOptionsParams { database: string; host: string; @@ -61,6 +59,4 @@ export interface PgPoolExtended extends pgPoolTypes { options: PgPoolOptionsParams; } -export type PgClientConnect = ( - callback?: (err: Error) => void -) => Promise | void; +export type PgClientConnect = (callback?: Function) => Promise | void; diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index 3cc25d45eb..2e4176817d 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -22,8 +22,6 @@ import { Tracer, SpanKind, diag, - INVALID_SPAN_CONTEXT, - Attributes, defaultTextMapSetter, ROOT_CONTEXT, } from '@opentelemetry/api'; @@ -36,7 +34,6 @@ import { import { PgClientExtended, PostgresCallback, - PgErrorCallback, PgPoolCallback, PgPoolExtended, PgParsedConnectionParams, @@ -116,24 +113,13 @@ export function getSemanticAttributesFromConnection( }; } -export function startSpan( - tracer: Tracer, - instrumentationConfig: PgInstrumentationConfig, - name: string, - attributes: Attributes -): Span { - // If a parent span is required but not present, use a noop span to propagate - // context without recording it. Adapted from opentelemetry-instrumentation-http: - // https://github.com/open-telemetry/opentelemetry-js/blob/597ea98e58a4f68bcd9aec5fd283852efe444cd6/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L660 - const currentSpan = trace.getSpan(context.active()); - if (instrumentationConfig.requireParentSpan && currentSpan === undefined) { - return trace.wrapSpanContext(INVALID_SPAN_CONTEXT); - } - - return tracer.startSpan(name, { - kind: SpanKind.CLIENT, - attributes, - }); +export function shouldSkipInstrumentation( + instrumentationConfig: PgInstrumentationConfig +) { + return ( + instrumentationConfig.requireParentSpan === true && + trace.getSpan(context.active()) === undefined + ); } // Create a span from our normalized queryConfig object, @@ -149,9 +135,12 @@ export function handleConfigQuery( const dbName = connectionParameters.database; const spanName = getQuerySpanName(dbName, queryConfig); - const span = startSpan(tracer, instrumentationConfig, spanName, { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, // required - ...getSemanticAttributesFromConnection(connectionParameters), + const span = tracer.startSpan(spanName, { + kind: SpanKind.CLIENT, + attributes: { + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, // required + ...getSemanticAttributesFromConnection(connectionParameters), + }, }); if (!queryConfig) { @@ -249,10 +238,7 @@ export function patchCallbackPGPool( }; } -export function patchClientConnectCallback( - span: Span, - cb: PgErrorCallback -): PgErrorCallback { +export function patchClientConnectCallback(span: Span, cb: Function): Function { return function patchedClientConnectCallback( this: pgTypes.Client, err: Error @@ -264,7 +250,7 @@ export function patchClientConnectCallback( }); } span.end(); - cb.call(this, err); + cb.apply(this, arguments); }; } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index 84b3a3ed7e..887c9236a4 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -44,10 +44,6 @@ import { SemanticAttributes, DbSystemValues, } from '@opentelemetry/semantic-conventions'; -import { isSupported } from './utils'; - -const pgVersion = require('pg/package.json').version; -const nodeVersion = process.versions.node; const memoryExporter = new InMemorySpanExporter(); @@ -118,8 +114,6 @@ describe('pg-pool', () => { const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) before(function () { - const skipForUnsupported = - process.env.IN_TAV && !isSupported(nodeVersion, pgVersion); const skip = () => { // this.skip() workaround // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 @@ -127,12 +121,6 @@ describe('pg-pool', () => { this.skip(); }; - if (skipForUnsupported) { - console.error( - ` pg - skipped - node@${nodeVersion} and pg@${pgVersion} are not compatible` - ); - skip(); - } if (!shouldTest) { skip(); } @@ -269,6 +257,23 @@ describe('pg-pool', () => { assert.strictEqual(resNoPromise, undefined, 'No promise is returned'); }); }); + + it('should not generate traces when requireParentSpan=true is specified', async () => { + // The pool gets shared between tests. We need to create a separate one + // to test cold start, which can cause nested spans + const newPool = new pgPool(CONFIG); + create({ + requireParentSpan: true, + }); + const client = await newPool.connect(); + try { + await client.query('SELECT NOW()'); + } finally { + client.release(); + } + const spans = memoryExporter.getFinishedSpans(); + assert.strictEqual(spans.length, 0); + }); }); describe('#pool.query()', () => { diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index 393da4ca0e..b78e036ab6 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -45,12 +45,8 @@ import { SemanticAttributes, DbSystemValues, } from '@opentelemetry/semantic-conventions'; -import { isSupported } from './utils'; import { addSqlCommenterComment } from '../src/utils'; -const pgVersion = require('pg/package.json').version; -const nodeVersion = process.versions.node; - const memoryExporter = new InMemorySpanExporter(); const CONFIG = { @@ -120,8 +116,6 @@ describe('pg', () => { } before(async function () { - const skipForUnsupported = - process.env.IN_TAV && !isSupported(nodeVersion, pgVersion); const skip = () => { // this.skip() workaround // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 @@ -129,12 +123,6 @@ describe('pg', () => { this.skip(); }; - if (skipForUnsupported) { - console.error( - ` pg - skipped - node@${nodeVersion} and pg@${pgVersion} are not compatible` - ); - skip(); - } if (!shouldTest) { skip(); } @@ -259,6 +247,17 @@ describe('pg', () => { assert.strictEqual(res, undefined, 'No promise is returned'); }); + it('should pass the client connection object in the callback function', done => { + connClient.connect(function (err: Error) { + // Even though the documented signature for connect() callback is `(err) => void` + // `pg` actually also passes the client if the connection was successful and some + // packages(`knex`) might rely on that + // https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/client.js#L282 + assert.strictEqual(arguments[1], connClient); + done(); + }); + }); + it('should return a promise if callback is not provided', done => { const resPromise = connClient.connect(); resPromise @@ -439,7 +438,7 @@ describe('pg', () => { try { assert.ok(resPromise); runCallbackTest(span, attributes, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); @@ -462,7 +461,7 @@ describe('pg', () => { try { assert.ok(resPromise); runCallbackTest(span, attributes, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); @@ -489,7 +488,7 @@ describe('pg', () => { }); assert.strictEqual(resPromise.command, 'SELECT'); runCallbackTest(span, attributes, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); @@ -508,7 +507,7 @@ describe('pg', () => { const resPromise = await client.query(query); assert.ok(resPromise); runCallbackTest(span, attributes, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); @@ -575,7 +574,7 @@ describe('pg', () => { try { assert.ok(resPromise); runCallbackTest(span, attributesAfterHook, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } } @@ -663,7 +662,7 @@ describe('pg', () => { try { assert.ok(resPromise); runCallbackTest(span, attributes, events); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } } @@ -797,7 +796,7 @@ describe('pg', () => { assert.equal(executedQueries.length, 1); assert.equal(executedQueries[0].text, query); assert.notEqual(query, commentedQuery); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); @@ -851,7 +850,7 @@ describe('pg', () => { assert.equal(executedQueries.length, 1); assert.equal(executedQueries[0].text, commentedQuery); assert.notEqual(query, commentedQuery); - } catch (e) { + } catch (e: any) { assert.ok(false, e.message); } }); diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts index 099ffa3bf4..2e6c8ca0d7 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts @@ -128,58 +128,35 @@ describe('utils.ts', () => { }); }); - describe('.startSpan()', () => { - it('starts real span when requireParentSpan=false', async () => { - const span = utils.startSpan(tracer, instrumentationConfig, 'spanName', { - key: 'value', - }); - span.end(); - - const readableSpan = getLatestSpan(); - - assert.strictEqual(readableSpan.name, 'spanName'); - assert.strictEqual(readableSpan.attributes['key'], 'value'); - assert.notDeepStrictEqual(readableSpan.spanContext, INVALID_SPAN_CONTEXT); + describe('.shouldSkipInstrumentation()', () => { + it('returns false when requireParentSpan=false', async () => { + assert.strictEqual( + utils.shouldSkipInstrumentation(instrumentationConfig), + false + ); }); - it('starts real span when requireParentSpan=true and there is a parent span', async () => { + it('returns false requireParentSpan=true and there is a parent span', async () => { const parent = tracer.startSpan('parentSpan'); context.with(trace.setSpan(context.active(), parent), () => { - const childSpan = utils.startSpan( - tracer, - { + assert.strictEqual( + utils.shouldSkipInstrumentation({ ...instrumentationConfig, requireParentSpan: true, - }, - 'childSpan', - { key: 'value' } - ); - childSpan.end(); - - const readableSpan = getLatestSpan(); - assert.strictEqual(readableSpan.name, 'childSpan'); - assert.strictEqual(readableSpan.attributes['key'], 'value'); - assert.notDeepStrictEqual( - readableSpan.spanContext, - INVALID_SPAN_CONTEXT + }), + false ); }); }); - it('creates placeholder span when requireParentSpan=true and there is no parent span', async () => { - const span = utils.startSpan( - tracer, - { + it('returns true when requireParentSpan=true and there is no parent span', async () => { + assert.strictEqual( + utils.shouldSkipInstrumentation({ ...instrumentationConfig, requireParentSpan: true, - }, - 'spanName', - { key: 'value' } + }), + true ); - span.end(); - - const readableSpan = getLatestSpan(); - assert.strictEqual(readableSpan, undefined); }); }); diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts deleted file mode 100644 index 1a42f5b57a..0000000000 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import * as assert from 'assert'; - -const matchVersions = /([0-9]+)\.([0-9]+)\.([0-9]+)/; -const getVersions = (semver: string) => { - const match = semver.match(matchVersions); - if (match) { - return { - major: parseInt(match[1], 10), - minor: parseInt(match[2], 10), - patch: parseInt(match[3], 10), - }; - } - throw new Error(`Unable to parse version: ${semver}`); -}; - -assert.deepStrictEqual(getVersions('1.23.45'), { - major: 1, - minor: 23, - patch: 45, -}); -assert.deepStrictEqual(getVersions('v2.23.45-beta21'), { - major: 2, - minor: 23, - patch: 45, -}); - -/* - We need to skip tests for pg@7 and node@14+ combination, because in pg@7 - the client never connects. - Fix landed in pg@8: https://github.com/brianc/node-postgres/pull/2171 - Ref: https://github.com/nodejs/node/issues/38247 -*/ -export const isSupported = ( - nodeVersion: string, - pgVersion: string -): boolean => { - try { - const { major: pgMajor } = getVersions(pgVersion); - const { major: nodeMajor } = getVersions(nodeVersion); - return !(pgMajor === 7 && nodeMajor >= 14); - } catch (e) { - return true; - } -}; - -assert.strictEqual(isSupported('16.0.0', '7.0.0'), false); -assert.strictEqual(isSupported('14.0.0', '7.0.0'), false); -assert.strictEqual(isSupported('12.0.0', '7.0.0'), true); -assert.strictEqual(isSupported('16.0.0', '8.0.0'), true); -assert.strictEqual(isSupported('12.0.0', '8.0.0'), true); diff --git a/plugins/node/opentelemetry-instrumentation-pino/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-pino/CHANGELOG.md index 275a543673..ad64e22773 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-pino/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.33.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pino-v0.33.1...instrumentation-pino-v0.33.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.33.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pino-v0.33.0...instrumentation-pino-v0.33.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.33.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-pino-v0.32.1...instrumentation-pino-v0.33.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-pino/package.json b/plugins/node/opentelemetry-instrumentation-pino/package.json index 57a72b50ae..b70350fe29 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/package.json +++ b/plugins/node/opentelemetry-instrumentation-pino/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-pino", - "version": "0.33.0", + "version": "0.33.2", "description": "OpenTelemetry instrumentation for pino", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -55,19 +55,18 @@ "@types/node": "18.11.7", "@types/semver": "7.3.8", "@types/sinon": "10.0.2", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "pino": "8.3.1", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "semver": "7.3.5", - "sinon": "14.0.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pino#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md index 49f7ca6e89..f82492d59e 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-redis-4/CHANGELOG.md @@ -1,5 +1,39 @@ # Changelog +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.34.0 to ^0.35.0 + +## [0.34.4](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-4-v0.34.3...instrumentation-redis-4-v0.34.4) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.34.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-4-v0.34.1...instrumentation-redis-4-v0.34.2) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-4-v0.34.0...instrumentation-redis-4-v0.34.1) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/package.json b/plugins/node/opentelemetry-instrumentation-redis-4/package.json index f2eb5ec0a7..9dde1c5864 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis-4/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-redis-4", - "version": "0.34.1", + "version": "0.34.4", "description": "Automatic OpenTelemetry instrumentation for redis package version 4", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -54,24 +54,23 @@ "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/core": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "cross-env": "7.0.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "redis": "4.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/redis-common": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/redis-common": "^0.35.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis-4#readme" diff --git a/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md index 6a4304734b..5e76746271 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-redis/CHANGELOG.md @@ -1,5 +1,47 @@ # Changelog +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/redis-common bumped from ^0.34.0 to ^0.35.0 + +## [0.34.5](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.34.4...instrumentation-redis-v0.34.5) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.1 to ^0.33.2 + +## [0.34.4](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.34.3...instrumentation-redis-v0.34.4) (2023-04-06) + + +### Bug Fixes + +* **deps:** update dependency redis to v3 [security] ([#1423](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1423)) ([31664ca](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/31664cac53f5a8c2ba57919cea594603021fdc9b)) +* **instrumentation-redis:** remove redis types from public API ([#1424](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1424)) ([861b867](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/861b867f5ff7e9b0891650f004462b88e2c707de)) + +## [0.34.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.34.1...instrumentation-redis-v0.34.2) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + + +### Dependencies + +* The following workspace dependencies were updated + * devDependencies + * @opentelemetry/contrib-test-utils bumped from ^0.33.0 to ^0.33.1 + ## [0.34.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-redis-v0.34.0...instrumentation-redis-v0.34.1) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-redis/examples/package.json b/plugins/node/opentelemetry-instrumentation-redis/examples/package.json index 70a8d7441a..d313a4dc02 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/examples/package.json @@ -34,20 +34,20 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.32.0", - "@opentelemetry/instrumentation-http": "^0.32.0", + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/instrumentation-http": "^0.38.0", "@opentelemetry/instrumentation-redis": "^0.32.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "axios": "^0.21.1", "express": "^4.17.1", - "redis": "^2.8.0" + "redis": "^3.1.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { "@types/express": "^4.17.14", "cross-env": "^6.0.0", "ts-node": "^10.6.0", - "typescript": "4.3.5" + "typescript": "4.4.4" } } diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index 339bce4872..ba761a43cd 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-redis", - "version": "0.34.1", + "version": "0.34.5", "description": "Automatic OpenTelemetry instrumentation for redis package version 2 and 3", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -54,26 +54,25 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/contrib-test-utils": "^0.33.0", + "@opentelemetry/contrib-test-utils": "^0.33.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", "cross-env": "7.0.3", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "redis": "3.1.2", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4", + "@types/redis": "2.8.31" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", - "@opentelemetry/redis-common": "^0.34.0", - "@opentelemetry/semantic-conventions": "^1.0.0", - "@types/redis": "2.8.31" + "@opentelemetry/instrumentation": "^0.38.0", + "@opentelemetry/redis-common": "^0.35.0", + "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts index 676a9a374b..819daa3398 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts @@ -20,7 +20,6 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition, } from '@opentelemetry/instrumentation'; -import type * as redisTypes from 'redis'; import { getTracedCreateClient, getTracedCreateStreamTrace, @@ -33,9 +32,7 @@ const DEFAULT_CONFIG: RedisInstrumentationConfig = { requireParentSpan: false, }; -export class RedisInstrumentation extends InstrumentationBase< - typeof redisTypes -> { +export class RedisInstrumentation extends InstrumentationBase { static readonly COMPONENT = 'redis'; constructor(protected override _config: RedisInstrumentationConfig = {}) { @@ -48,7 +45,7 @@ export class RedisInstrumentation extends InstrumentationBase< protected init() { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( 'redis', ['^2.6.0', '^3.0.0'], (moduleExports, moduleVersion) => { diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/types.ts b/plugins/node/opentelemetry-instrumentation-redis/src/types.ts index 5644a60187..32276281b4 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/types.ts @@ -16,15 +16,14 @@ import { Span } from '@opentelemetry/api'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; -import type * as redisTypes from 'redis'; // exported from -// https://github.com/NodeRedis/node_redis/blob/master/lib/command.js +// https://github.com/redis/node-redis/blob/v3.1.2/lib/command.js export interface RedisCommand { command: string; args: string[]; buffer_args: boolean; - callback: redisTypes.Callback; + callback: (err: Error | null, reply: unknown) => void; call_on_write: boolean; } diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts index 988c5c1a0f..7575e51376 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts @@ -158,7 +158,7 @@ export const getTracedInternalSendCommand = ( try { // Span will be ended in callback return original.apply(this, arguments); - } catch (rethrow) { + } catch (rethrow: any) { endSpan(span, rethrow); throw rethrow; // rethrow after ending span } diff --git a/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md index 5bc2799d58..84209a0656 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-restify/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-restify-v0.32.1...instrumentation-restify-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-restify-v0.32.0...instrumentation-restify-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-restify-v0.31.0...instrumentation-restify-v0.32.0) (2022-12-20) diff --git a/plugins/node/opentelemetry-instrumentation-restify/package.json b/plugins/node/opentelemetry-instrumentation-restify/package.json index 4b5f05904b..ea8c245ea0 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/package.json +++ b/plugins/node/opentelemetry-instrumentation-restify/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-restify", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry restify automatic instrumentation package", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -54,19 +54,18 @@ "@types/node": "18.11.7", "@types/restify": "4.3.8", "@types/semver": "^7.3.12", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", "restify": "8.6.1", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "semver": "^7.3.7", "test-all-versions": "^5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-restify#readme" diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts index a856359d96..9be36c8e17 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts @@ -257,7 +257,7 @@ export class RestifyInstrumentation extends InstrumentationBase { } span.end(); return result; - } catch (err) { + } catch (err: any) { span.recordException(err); span.end(); throw err; diff --git a/plugins/node/opentelemetry-instrumentation-router/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-router/CHANGELOG.md index 9daa1a7965..e855577f12 100644 --- a/plugins/node/opentelemetry-instrumentation-router/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-router/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-router-v0.32.1...instrumentation-router-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-router-v0.32.0...instrumentation-router-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-router-v0.31.0...instrumentation-router-v0.32.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-router/package.json b/plugins/node/opentelemetry-instrumentation-router/package.json index 16298bfefa..a179f2f6f2 100644 --- a/plugins/node/opentelemetry-instrumentation-router/package.json +++ b/plugins/node/opentelemetry-instrumentation-router/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-router", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry Router automatic instrumentation package", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -51,16 +51,15 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", "@types/node": "18.11.7", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "router": "1.3.5", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-router#readme" diff --git a/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts index c5b9309cf6..3b16b6eb9f 100644 --- a/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-router/test/index.test.ts @@ -128,7 +128,7 @@ const assertSpans = (actualSpans: any[], expectedSpans: any[]) => { assert.strictEqual(span.attributes['router.type'], expected.type); assert.strictEqual(typeof span.attributes['router.version'], 'string'); assert.strictEqual(span.attributes['http.route'], expected.route); - } catch (e) { + } catch (e: any) { e.message = `At span[${idx}]: ${e.message}`; throw e; } diff --git a/plugins/node/opentelemetry-instrumentation-winston/CHANGELOG.md b/plugins/node/opentelemetry-instrumentation-winston/CHANGELOG.md index 5e66b84296..376d16fdc2 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/CHANGELOG.md +++ b/plugins/node/opentelemetry-instrumentation-winston/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-winston-v0.31.1...instrumentation-winston-v0.31.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-winston-v0.31.0...instrumentation-winston-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-winston-v0.30.1...instrumentation-winston-v0.31.0) (2022-11-16) diff --git a/plugins/node/opentelemetry-instrumentation-winston/package.json b/plugins/node/opentelemetry-instrumentation-winston/package.json index 5b2e9c805d..a2c0c4e438 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/package.json +++ b/plugins/node/opentelemetry-instrumentation-winston/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-winston", - "version": "0.31.0", + "version": "0.31.2", "description": "OpenTelemetry instrumentation for winston", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -54,19 +54,19 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "@types/sinon": "10.0.2", - "gts": "3.1.0", + "@types/triple-beam": "^1.3.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "test-all-versions": "5.0.1", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "winston": "3.3.3", "winston2": "npm:winston@2.4.5" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.34.0" + "@opentelemetry/instrumentation": "^0.38.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme" } diff --git a/plugins/web/opentelemetry-instrumentation-document-load/CHANGELOG.md b/plugins/web/opentelemetry-instrumentation-document-load/CHANGELOG.md index 191497e9dc..82977e082f 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/CHANGELOG.md +++ b/plugins/web/opentelemetry-instrumentation-document-load/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-document-load-v0.32.0...instrumentation-document-load-v0.32.1) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-document-load-v0.31.2...instrumentation-document-load-v0.32.0) (2023-04-06) + + +### Features + +* **instrumenation-document-load:** Add custom attributes to document load ([#1414](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1414)) ([98609c6](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/98609c69d951951edcaa3234914d04d7ae87e9b5)) + +## [0.31.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-document-load-v0.31.1...instrumentation-document-load-v0.31.2) (2023-03-03) + + +### Bug Fixes + +* remove component attribute from instrumentations ([#1399](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1399)) ([e93a192](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e93a192b672c8db361bac83ad60294ca49b95361)) + +## [0.31.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-document-load-v0.31.0...instrumentation-document-load-v0.31.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.31.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-document-load-v0.30.1...instrumentation-document-load-v0.31.0) (2022-11-16) diff --git a/plugins/web/opentelemetry-instrumentation-document-load/README.md b/plugins/web/opentelemetry-instrumentation-document-load/README.md index c01b34bc3c..ec6595c57b 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/README.md +++ b/plugins/web/opentelemetry-instrumentation-document-load/README.md @@ -82,6 +82,28 @@ Because the browser does not send a trace context header for the initial page na ``` +## Optional : Add custom attributes to document load span if needed + +If it is needed to add custom attributes to the document load span,and/or document fetch span and/or resource fetch spans, respective functions to do so needs to be provided +as a config to the DocumentLoad Instrumentation as shown below. The attributes will be added to the respective spans +before the individual are spans are ended. If the function throws an error , no attributes will be added to the span and +the rest of the process continues. + +```js +const addCustomAttributesToSpan = (span: Span) => { + span.setAttribute('',''); +} +registerInstrumentations({ + instrumentations: [ + new DocumentLoadInstrumentation({ + applyCustomAttributesOnSpan: { + documentLoad: addCustomAttributesToSpan + } + }) + ] +}) +``` + See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a short example. ## Useful links diff --git a/plugins/web/opentelemetry-instrumentation-document-load/package.json b/plugins/web/opentelemetry-instrumentation-document-load/package.json index 85cc18e7b2..1b656f7fcb 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/package.json +++ b/plugins/web/opentelemetry-instrumentation-document-load/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-document-load", - "version": "0.31.0", + "version": "0.32.1", "description": "OpenTelemetry document-load automatic instrumentation package.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -57,7 +57,6 @@ "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", "babel-loader": "8.2.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -67,18 +66,18 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0" }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-web": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.0.0" diff --git a/plugins/web/opentelemetry-instrumentation-document-load/src/enums/AttributeNames.ts b/plugins/web/opentelemetry-instrumentation-document-load/src/enums/AttributeNames.ts index ad672fd016..0a351254b3 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/src/enums/AttributeNames.ts +++ b/plugins/web/opentelemetry-instrumentation-document-load/src/enums/AttributeNames.ts @@ -15,7 +15,6 @@ */ export enum AttributeNames { - COMPONENT = 'component', DOCUMENT_LOAD = 'documentLoad', DOCUMENT_FETCH = 'documentFetch', RESOURCE_FETCH = 'resourceFetch', diff --git a/plugins/web/opentelemetry-instrumentation-document-load/src/index.ts b/plugins/web/opentelemetry-instrumentation-document-load/src/index.ts index c464af622c..45cd8db559 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/src/index.ts +++ b/plugins/web/opentelemetry-instrumentation-document-load/src/index.ts @@ -16,3 +16,4 @@ export * from './instrumentation'; export * from './enums/AttributeNames'; +export * from './types'; diff --git a/plugins/web/opentelemetry-instrumentation-document-load/src/instrumentation.ts b/plugins/web/opentelemetry-instrumentation-document-load/src/instrumentation.ts index cd0fdccb84..a13f3845b3 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/src/instrumentation.ts +++ b/plugins/web/opentelemetry-instrumentation-document-load/src/instrumentation.ts @@ -31,8 +31,12 @@ import { } from '@opentelemetry/sdk-trace-web'; import { InstrumentationBase, - InstrumentationConfig, + safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; +import { + DocumentLoadCustomAttributeFunction, + DocumentLoadInstrumentationConfig, +} from './types'; import { AttributeNames } from './enums/AttributeNames'; import { VERSION } from './version'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; @@ -53,7 +57,7 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { * * @param config */ - constructor(config: InstrumentationConfig = {}) { + constructor(config: DocumentLoadInstrumentationConfig = {}) { super('@opentelemetry/instrumentation-document-load', VERSION, config); } @@ -113,6 +117,10 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { fetchSpan.setAttribute(SemanticAttributes.HTTP_URL, location.href); context.with(trace.setSpan(context.active(), fetchSpan), () => { addSpanNetworkEvents(fetchSpan, entries); + this._addCustomAttributesOnSpan( + fetchSpan, + this._getConfig().applyCustomAttributesOnSpan?.documentFetch + ); this._endSpan(fetchSpan, PTN.RESPONSE_END, entries); }); } @@ -141,7 +149,10 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { addSpanNetworkEvent(rootSpan, PTN.LOAD_EVENT_END, entries); addSpanPerformancePaintEvents(rootSpan); - + this._addCustomAttributesOnSpan( + rootSpan, + this._getConfig().applyCustomAttributesOnSpan?.documentLoad + ); this._endSpan(rootSpan, PTN.LOAD_EVENT_END, entries); }); } @@ -186,6 +197,10 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { if (span) { span.setAttribute(SemanticAttributes.HTTP_URL, resource.name); addSpanNetworkEvents(span, resource); + this._addCustomAttributesOnSpan( + span, + this._getConfig().applyCustomAttributesOnSpan?.resourceFetch + ); this._endSpan(span, PTN.RESPONSE_END, resource); } } @@ -214,7 +229,6 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { }, parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined ); - span.setAttribute(AttributeNames.COMPONENT, this.component); return span; } return undefined; @@ -232,6 +246,31 @@ export class DocumentLoadInstrumentation extends InstrumentationBase { } } + private _getConfig(): DocumentLoadInstrumentationConfig { + return this._config; + } + /** + * adds custom attributes to root span if configured + */ + private _addCustomAttributesOnSpan( + span: Span, + applyCustomAttributesOnSpan: DocumentLoadCustomAttributeFunction | undefined + ) { + if (applyCustomAttributesOnSpan) { + safeExecuteInTheMiddle( + () => applyCustomAttributesOnSpan(span), + error => { + if (!error) { + return; + } + + this._diag.error('addCustomAttributesOnSpan', error); + }, + true + ); + } + } + /** * implements enable function */ diff --git a/plugins/web/opentelemetry-instrumentation-document-load/src/types.ts b/plugins/web/opentelemetry-instrumentation-document-load/src/types.ts new file mode 100644 index 0000000000..0d96d53395 --- /dev/null +++ b/plugins/web/opentelemetry-instrumentation-document-load/src/types.ts @@ -0,0 +1,34 @@ +/* + * 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 } from '@opentelemetry/api'; +import { InstrumentationConfig } from '@opentelemetry/instrumentation'; + +export interface DocumentLoadCustomAttributeFunction { + (span: Span): void; +} + +/** + * DocumentLoadInstrumentationPlugin Config + */ +export interface DocumentLoadInstrumentationConfig + extends InstrumentationConfig { + /** Function for adding custom attributes on the document load, document fetch and or resource fetch spans */ + applyCustomAttributesOnSpan?: { + documentLoad?: DocumentLoadCustomAttributeFunction; + documentFetch?: DocumentLoadCustomAttributeFunction; + resourceFetch?: DocumentLoadCustomAttributeFunction; + }; +} diff --git a/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts b/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts index 6b7422df98..2545ce3b05 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts +++ b/plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts @@ -653,6 +653,96 @@ describe('DocumentLoad Instrumentation', () => { }); shouldExportCorrectSpan(); }); + + describe('add custom attributes to spans', () => { + let spyEntries: any; + beforeEach(() => { + spyEntries = sandbox.stub(window.performance, 'getEntriesByType'); + spyEntries.withArgs('navigation').returns([entries]); + spyEntries.withArgs('resource').returns(resources); + spyEntries.withArgs('paint').returns([]); + }); + afterEach(() => { + spyEntries.restore(); + }); + + it('should add attribute to document load span', done => { + plugin = new DocumentLoadInstrumentation({ + enabled: false, + applyCustomAttributesOnSpan: { + documentLoad: span => { + span.setAttribute('custom-key', 'custom-val'); + }, + }, + }); + plugin.enable(); + setTimeout(() => { + const rootSpan = exporter.getFinishedSpans()[3] as ReadableSpan; + assert.strictEqual(rootSpan.attributes['custom-key'], 'custom-val'); + assert.strictEqual(exporter.getFinishedSpans().length, 4); + done(); + }); + }); + + it('should add attribute to document fetch span', done => { + plugin = new DocumentLoadInstrumentation({ + enabled: false, + applyCustomAttributesOnSpan: { + documentFetch: span => { + span.setAttribute('custom-key', 'custom-val'); + }, + }, + }); + plugin.enable(); + setTimeout(() => { + const fetchSpan = exporter.getFinishedSpans()[0] as ReadableSpan; + assert.strictEqual(fetchSpan.attributes['custom-key'], 'custom-val'); + assert.strictEqual(exporter.getFinishedSpans().length, 4); + done(); + }); + }); + + it('should add attribute to resource fetch spans', done => { + plugin = new DocumentLoadInstrumentation({ + enabled: false, + applyCustomAttributesOnSpan: { + resourceFetch: span => { + span.setAttribute('custom-key', 'custom-val'); + }, + }, + }); + plugin.enable(); + setTimeout(() => { + const resourceSpan1 = exporter.getFinishedSpans()[1] as ReadableSpan; + const resourceSpan2 = exporter.getFinishedSpans()[2] as ReadableSpan; + assert.strictEqual( + resourceSpan1.attributes['custom-key'], + 'custom-val' + ); + assert.strictEqual( + resourceSpan2.attributes['custom-key'], + 'custom-val' + ); + assert.strictEqual(exporter.getFinishedSpans().length, 4); + done(); + }); + }); + it('should still create the spans if the function throws error', done => { + plugin = new DocumentLoadInstrumentation({ + enabled: false, + applyCustomAttributesOnSpan: { + documentLoad: span => { + throw new Error('test error'); + }, + }, + }); + plugin.enable(); + setTimeout(() => { + assert.strictEqual(exporter.getFinishedSpans().length, 4); + done(); + }); + }); + }); }); /** diff --git a/plugins/web/opentelemetry-instrumentation-long-task/CHANGELOG.md b/plugins/web/opentelemetry-instrumentation-long-task/CHANGELOG.md index 89db157592..2f7ff1c67c 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/CHANGELOG.md +++ b/plugins/web/opentelemetry-instrumentation-long-task/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [0.32.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-long-task-v0.32.2...instrumentation-long-task-v0.32.3) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-long-task-v0.32.1...instrumentation-long-task-v0.32.2) (2023-03-03) + + +### Bug Fixes + +* remove component attribute from instrumentations ([#1399](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1399)) ([e93a192](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/e93a192b672c8db361bac83ad60294ca49b95361)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-long-task-v0.32.0...instrumentation-long-task-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-long-task-v0.31.1...instrumentation-long-task-v0.32.0) (2022-11-16) diff --git a/plugins/web/opentelemetry-instrumentation-long-task/package.json b/plugins/web/opentelemetry-instrumentation-long-task/package.json index aa03cfaca6..a7eef4c1a0 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/package.json +++ b/plugins/web/opentelemetry-instrumentation-long-task/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-long-task", - "version": "0.32.0", + "version": "0.32.3", "description": "OpenTelemetry long task API automatic instrumentation package.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -56,7 +56,6 @@ "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", "babel-loader": "8.2.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -67,11 +66,11 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0", @@ -79,7 +78,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/sdk-trace-web": "^1.8.0" }, "peerDependencies": { diff --git a/plugins/web/opentelemetry-instrumentation-long-task/src/instrumentation.ts b/plugins/web/opentelemetry-instrumentation-long-task/src/instrumentation.ts index d39122d745..7b17907a89 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/src/instrumentation.ts +++ b/plugins/web/opentelemetry-instrumentation-long-task/src/instrumentation.ts @@ -25,9 +25,7 @@ import type { const LONGTASK_PERFORMANCE_TYPE = 'longtask'; export class LongTaskInstrumentation extends InstrumentationBase { - readonly component: string = 'long-task'; readonly version: string = VERSION; - moduleName = this.component; private _observer?: PerformanceObserver; override _config!: LongtaskInstrumentationConfig; @@ -66,7 +64,6 @@ export class LongTaskInstrumentation extends InstrumentationBase { diag.error('longtask instrumentation: observer callback failed', err); } } - span.setAttribute('component', this.component); span.setAttribute('longtask.name', entry.name); span.setAttribute('longtask.entry_type', entry.entryType); span.setAttribute('longtask.duration', entry.duration); diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/CHANGELOG.md b/plugins/web/opentelemetry-instrumentation-user-interaction/CHANGELOG.md index 00b9ee8df3..f603c6b9d3 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/CHANGELOG.md +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [0.32.2](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-user-interaction-v0.32.1...instrumentation-user-interaction-v0.32.2) (2023-04-25) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.38.0 ([#1468](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1468)) ([565a2b2](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/565a2b2c6fde88af3f5401ef6a5a9643d0d66349)) + +## [0.32.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-user-interaction-v0.32.0...instrumentation-user-interaction-v0.32.1) (2023-02-07) + + +### Bug Fixes + +* **deps:** update otel core experimental to ^0.35.1 ([#1358](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1358)) ([ff109b7](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/ff109b77928cc9a139a21c63d6b54399bb017fa4)) + ## [0.32.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/instrumentation-user-interaction-v0.31.1...instrumentation-user-interaction-v0.32.0) (2022-11-16) diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json index 6c5fd3d299..a7ce2daf67 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/instrumentation-user-interaction", - "version": "0.32.0", + "version": "0.32.2", "description": "OpenTelemetry UserInteraction automatic instrumentation package.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -50,7 +50,7 @@ "@babel/core": "7.15.0", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-zone-peer-dep": "^1.8.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.34.0", + "@opentelemetry/instrumentation-xml-http-request": "^0.38.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/jquery": "3.5.6", "@types/mocha": "7.0.2", @@ -58,7 +58,6 @@ "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", "babel-loader": "8.2.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -69,11 +68,11 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0", @@ -81,7 +80,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.34.0", + "@opentelemetry/instrumentation": "^0.38.0", "@opentelemetry/sdk-trace-web": "^1.8.0" }, "peerDependencies": { diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/src/enums/AttributeNames.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/src/enums/AttributeNames.ts index 811f328cdb..55121fd744 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/src/enums/AttributeNames.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/src/enums/AttributeNames.ts @@ -15,11 +15,8 @@ */ export enum AttributeNames { - COMPONENT = 'component', EVENT_TYPE = 'event_type', TARGET_ELEMENT = 'target_element', TARGET_XPATH = 'target_xpath', HTTP_URL = 'http.url', - // NOT ON OFFICIAL SPEC - HTTP_USER_AGENT = 'http.user_agent', } diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/src/instrumentation.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/src/instrumentation.ts index 24476e9c80..0b59b4bfbb 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/src/instrumentation.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/src/instrumentation.ts @@ -48,9 +48,8 @@ function defaultShouldPreventSpanCreation() { * addEventListener of HTMLElement */ export class UserInteractionInstrumentation extends InstrumentationBase { - readonly component: string = 'user-interaction'; readonly version = VERSION; - moduleName = this.component; + readonly moduleName: string = 'user-interaction'; private _spansData = new WeakMap(); private _zonePatched?: boolean; // for addEventListener/removeEventListener state @@ -134,12 +133,10 @@ export class UserInteractionInstrumentation extends InstrumentationBase eventName, { attributes: { - [AttributeNames.COMPONENT]: this.component, [AttributeNames.EVENT_TYPE]: eventName, [AttributeNames.TARGET_ELEMENT]: element.tagName, [AttributeNames.TARGET_XPATH]: xpath, [AttributeNames.HTTP_URL]: window.location.href, - [AttributeNames.HTTP_USER_AGENT]: navigator.userAgent, }, }, parentSpan @@ -157,7 +154,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase return span; } catch (e) { - api.diag.error(this.component, e); + this._diag.error('failed to start create new user interaction span', e); } return undefined; } @@ -575,7 +572,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase */ override enable() { const ZoneWithPrototype = this.getZoneWithPrototype(); - api.diag.debug( + this._diag.debug( 'applying patch to', this.moduleName, this.version, @@ -585,15 +582,15 @@ export class UserInteractionInstrumentation extends InstrumentationBase if (ZoneWithPrototype) { if (isWrapped(ZoneWithPrototype.prototype.runTask)) { this._unwrap(ZoneWithPrototype.prototype, 'runTask'); - api.diag.debug('removing previous patch from method runTask'); + this._diag.debug('removing previous patch from method runTask'); } if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) { this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask'); - api.diag.debug('removing previous patch from method scheduleTask'); + this._diag.debug('removing previous patch from method scheduleTask'); } if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) { this._unwrap(ZoneWithPrototype.prototype, 'cancelTask'); - api.diag.debug('removing previous patch from method cancelTask'); + this._diag.debug('removing previous patch from method cancelTask'); } this._zonePatched = true; @@ -618,13 +615,13 @@ export class UserInteractionInstrumentation extends InstrumentationBase targets.forEach(target => { if (isWrapped(target.addEventListener)) { this._unwrap(target, 'addEventListener'); - api.diag.debug( + this._diag.debug( 'removing previous patch from method addEventListener' ); } if (isWrapped(target.removeEventListener)) { this._unwrap(target, 'removeEventListener'); - api.diag.debug( + this._diag.debug( 'removing previous patch from method removeEventListener' ); } @@ -645,7 +642,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase */ override disable() { const ZoneWithPrototype = this.getZoneWithPrototype(); - api.diag.debug( + this._diag.debug( 'removing patch from', this.moduleName, this.version, diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/test/helper.test.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/test/helper.test.ts index bd669db29c..4e55e171f3 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/test/helper.test.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/test/helper.test.ts @@ -76,7 +76,6 @@ export function assertInteractionSpan( assert.strictEqual(span.name, name); const attributes = span.attributes; - assert.strictEqual(attributes.component, 'user-interaction'); assert.strictEqual(attributes.event_type, eventType); assert.strictEqual(attributes.target_element, 'BUTTON'); assert.strictEqual(attributes.target_xpath, `//*[@id="${elementId}"]`); diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts index eb3b15ebce..c62ef63ae2 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.nozone.test.ts @@ -304,7 +304,6 @@ describe('UserInteractionInstrumentation', () => { ); const attributes = spanClick.attributes; - assert.equal(attributes.component, 'user-interaction'); assert.equal(attributes.event_type, 'click'); assert.equal(attributes.target_element, 'BUTTON'); assert.equal(attributes.target_xpath, '//*[@id="testBtn"]'); diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts index 330e7f5879..792387e8c5 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/test/userInteraction.test.ts @@ -188,7 +188,6 @@ describe('UserInteractionInstrumentation', () => { ); const attributes = spanClick.attributes; - assert.equal(attributes.component, 'user-interaction'); assert.equal(attributes.event_type, 'click'); assert.equal(attributes.target_element, 'BUTTON'); assert.equal(attributes.target_xpath, '//*[@id="testBtn"]'); diff --git a/plugins/web/opentelemetry-plugin-react-load/package.json b/plugins/web/opentelemetry-plugin-react-load/package.json index f26e30c62f..12e25a268e 100644 --- a/plugins/web/opentelemetry-plugin-react-load/package.json +++ b/plugins/web/opentelemetry-plugin-react-load/package.json @@ -59,7 +59,6 @@ "@types/sinon": "10.0.2", "@types/webpack-env": "1.16.2", "babel-loader": "8.2.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -71,11 +70,11 @@ "nyc": "15.1.0", "react": "17.0.2", "react-dom": "17.0.2", - "rimraf": "3.0.2", - "sinon": "14.0.0", + "rimraf": "4.2.0", + "sinon": "15.0.1", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.7.2", "webpack-merge": "5.8.0" diff --git a/plugins/web/opentelemetry-plugin-react-load/src/BaseOpenTelemetryComponent.ts b/plugins/web/opentelemetry-plugin-react-load/src/BaseOpenTelemetryComponent.ts index 9cc976605f..9b46621027 100644 --- a/plugins/web/opentelemetry-plugin-react-load/src/BaseOpenTelemetryComponent.ts +++ b/plugins/web/opentelemetry-plugin-react-load/src/BaseOpenTelemetryComponent.ts @@ -127,7 +127,7 @@ export class BaseOpenTelemetryComponent extends React.Component { return original(); } ); - } catch (err) { + } catch (err: any) { span.setAttribute(AttributeNames.REACT_ERROR, err.stack); wasError = true; throw err; diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000000..ab9553d533 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,8 @@ +module.exports = { + arrowParens: 'avoid', + printWidth: 80, + trailingComma: 'es5', + tabWidth: 2, + semi: true, + singleQuote: true, +}; diff --git a/propagators/opentelemetry-propagator-aws-xray/CHANGELOG.md b/propagators/opentelemetry-propagator-aws-xray/CHANGELOG.md index 6d93f709a7..3104c626b7 100644 --- a/propagators/opentelemetry-propagator-aws-xray/CHANGELOG.md +++ b/propagators/opentelemetry-propagator-aws-xray/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.2.0](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/propagator-aws-xray-v1.1.1...propagator-aws-xray-v1.2.0) (2023-02-07) + + +### Features + +* **propagator/aws-xray:** Extract X-Ray header in a case-insensitive fashion ([#1328](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1328)) ([4227d8a](https://github.com/open-telemetry/opentelemetry-js-contrib/commit/4227d8a3df7b0782d76844e89d452e0432a704f4)) + ## [1.1.1](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/propagator-aws-xray-v1.1.0...propagator-aws-xray-v1.1.1) (2022-11-02) diff --git a/propagators/opentelemetry-propagator-aws-xray/README.md b/propagators/opentelemetry-propagator-aws-xray/README.md index dcd871de99..9f2cb4e307 100644 --- a/propagators/opentelemetry-propagator-aws-xray/README.md +++ b/propagators/opentelemetry-propagator-aws-xray/README.md @@ -3,13 +3,15 @@ [![NPM Published Version][npm-img]][npm-url] [![Apache License][license-image]][license-image] -[component owners](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/component_owners.yml): @willarmiros - The OpenTelemetry Propagator for AWS X-Ray provides HTTP header propagation for systems that are using AWS `X-Amzn-Trace-Id` format. This propagator translates the OpenTelemetry SpanContext into the equivalent AWS header format, for use with the OpenTelemetry JS SDK. `TraceState` is currently not propagated. -Compatible with OpenTelemetry JS API and SDK `1.0+`. +## Status + +| Maturity | [Component Owner](../../.github/component_owners.yml) | Compatibility | +| ----------------------------------------- | ----------------------------------------------------- | --------------------- | +| [Stable](../../../CONTRIBUTING.md#stable) | @carolabadeer | API 1.0+
SDK 1.0+ | ## Installation diff --git a/propagators/opentelemetry-propagator-aws-xray/package.json b/propagators/opentelemetry-propagator-aws-xray/package.json index e1a01e502f..0e70815c6b 100644 --- a/propagators/opentelemetry-propagator-aws-xray/package.json +++ b/propagators/opentelemetry-propagator-aws-xray/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/propagator-aws-xray", - "version": "1.1.1", + "version": "1.2.0", "description": "OpenTelemetry AWS Xray propagator provides context propagation for systems that are using AWS X-Ray format.", "main": "build/src/index.js", "module": "build/esm/index.js", @@ -52,7 +52,6 @@ "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/webpack-env": "1.16.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -62,10 +61,10 @@ "karma-webpack": "4.0.2", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0" }, "dependencies": { diff --git a/propagators/opentelemetry-propagator-aws-xray/src/AWSXRayPropagator.ts b/propagators/opentelemetry-propagator-aws-xray/src/AWSXRayPropagator.ts index 89215ef6f6..e06568d9ee 100644 --- a/propagators/opentelemetry-propagator-aws-xray/src/AWSXRayPropagator.ts +++ b/propagators/opentelemetry-propagator-aws-xray/src/AWSXRayPropagator.ts @@ -92,9 +92,18 @@ export class AWSXRayPropagator implements TextMapPropagator { carrier: unknown, getter: TextMapGetter ): SpanContext { - const traceHeader = getter.get(carrier, AWSXRAY_TRACE_ID_HEADER); - if (!traceHeader || typeof traceHeader !== 'string') + const headerKeys = getter.keys(carrier); + const relevantHeaderKey = headerKeys.find(e => { + return e.toLowerCase() === AWSXRAY_TRACE_ID_HEADER; + }); + if (!relevantHeaderKey) { return INVALID_SPAN_CONTEXT; + } + const traceHeader = getter.get(carrier, relevantHeaderKey); + + if (!traceHeader || typeof traceHeader !== 'string') { + return INVALID_SPAN_CONTEXT; + } let pos = 0; let trimmedPart: string; diff --git a/propagators/opentelemetry-propagator-aws-xray/test/AWSXRayPropagator.test.ts b/propagators/opentelemetry-propagator-aws-xray/test/AWSXRayPropagator.test.ts index c110745c83..5cf47916d5 100644 --- a/propagators/opentelemetry-propagator-aws-xray/test/AWSXRayPropagator.test.ts +++ b/propagators/opentelemetry-propagator-aws-xray/test/AWSXRayPropagator.test.ts @@ -299,6 +299,24 @@ describe('AWSXRayPropagator', () => { assert.deepStrictEqual(extractedSpanContext, undefined); }); + + it('extracts context in a case-insensitive fashion', () => { + carrier[AWSXRAY_TRACE_ID_HEADER.toUpperCase()] = + 'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar'; + const extractedSpanContext = trace + .getSpan( + xrayPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + ) + ?.spanContext(); + + assert.deepStrictEqual(extractedSpanContext, { + traceId: TRACE_ID, + spanId: SPAN_ID, + isRemote: true, + traceFlags: TraceFlags.SAMPLED, + }); + }); + describe('.fields()', () => { it('should return a field with AWS X-Ray Trace ID header', () => { const expectedField = xrayPropagator.fields(); diff --git a/propagators/opentelemetry-propagator-grpc-census-binary/package.json b/propagators/opentelemetry-propagator-grpc-census-binary/package.json index 289d486335..c19864f539 100644 --- a/propagators/opentelemetry-propagator-grpc-census-binary/package.json +++ b/propagators/opentelemetry-propagator-grpc-census-binary/package.json @@ -49,13 +49,12 @@ "@types/mocha": "7.0.2", "@types/node": "18.11.7", "grpc": "1.24.11", - "gts": "3.1.0", "mocha": "7.2.0", "nyc": "15.1.0", - "rimraf": "3.0.2", + "rimraf": "4.2.0", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5" + "typescript": "4.4.4" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/propagators/opentelemetry-propagator-grpc-census-binary#readme" } diff --git a/propagators/opentelemetry-propagator-instana/package.json b/propagators/opentelemetry-propagator-instana/package.json index 8abf16129c..e24f8b49b6 100644 --- a/propagators/opentelemetry-propagator-instana/package.json +++ b/propagators/opentelemetry-propagator-instana/package.json @@ -55,7 +55,6 @@ "@types/node": "18.11.7", "@types/webpack-env": "1.16.2", "assert": "2.0.0", - "gts": "3.1.0", "karma": "6.3.17", "karma-chrome-launcher": "3.1.1", "karma-coverage-istanbul-reporter": "3.0.3", @@ -67,7 +66,7 @@ "process": "0.11.10", "ts-loader": "8.3.0", "ts-mocha": "8.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.9.2" }, diff --git a/propagators/opentelemetry-propagator-ot-trace/package.json b/propagators/opentelemetry-propagator-ot-trace/package.json index 4e80a08f73..36bd939f5e 100644 --- a/propagators/opentelemetry-propagator-ot-trace/package.json +++ b/propagators/opentelemetry-propagator-ot-trace/package.json @@ -53,7 +53,6 @@ "@types/mocha": "8.2.3", "@types/node": "18.11.7", "@types/webpack-env": "1.16.2", - "gts": "3.1.0", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "karma": "6.3.16", "karma-chrome-launcher": "^3.1.1", @@ -65,7 +64,7 @@ "nyc": "15.1.0", "ts-loader": "8.3.0", "ts-mocha": "10.0.0", - "typescript": "4.3.5", + "typescript": "4.4.4", "webpack": "4.46.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/propagators/opentelemetry-propagator-ot-trace#readme" diff --git a/renovate.json b/renovate.json index d8b54711fc..80634068e2 100644 --- a/renovate.json +++ b/renovate.json @@ -26,6 +26,7 @@ } ], "ignoreDeps": ["lerna", "lerna-changelog"], + "ignorePaths": ["archive/**", "examples/**"], "assignees": ["@blumamir", "@dyladan", "@legendecas", "@Rauno56", "@vmarchaud"], "schedule": [ "before 3am on Friday"