From 8bfa21feda79cab00a42b6a1bb30f87eb7935841 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:00:36 -0800 Subject: [PATCH 1/3] fix(docs): broken link for community contribution lifecycle and processes (#2576) --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CONTRIBUTING.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8a17e1d13d..deea23fa1d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -7,7 +7,7 @@ Before creating a pull request, please make sure: - You have read the guide for contributing - See https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md - You signed all your commits (otherwise we won't be able to merge the PR) - - See https://github.com/open-telemetry/community/blob/main/CONTRIBUTING.md#sign-the-cla + - See https://github.com/open-telemetry/community/blob/main/guides/contributor#sign-the-cla - You added unit tests for the new functionality - You mention in the PR description which issue it is addressing, e.g. "Fixes #xxx". This will auto-close the issue that your PR fixes (if such) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3cbc3f38e..cd9be4f60e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,7 +88,7 @@ git merge upstream/main Remember to always work in a branch of your local copy, as you might otherwise have to contend with conflicts in main. -Please also see [GitHub workflow](https://github.com/open-telemetry/community/blob/main/CONTRIBUTING.md#github-workflow) section of general project contributing guide. +Please also see [GitHub workflow](https://github.com/open-telemetry/community/blob/main/guides/contributor/processes.md#github-workflow) section of general project contributing guide. ## Development From e674b1b4278558e5952fc67b5d3fee22b46a2d77 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Wed, 4 Dec 2024 17:05:09 +0100 Subject: [PATCH 2/3] fix(instrumentation-mysql2): instrument connection on 3.11.5 (#2579) --- package-lock.json | 17 ++++++++-------- .../package.json | 2 +- .../src/instrumentation.ts | 3 ++- .../src/utils.ts | 19 ++++++++++++++++++ .../test/mysql.test.ts | 20 +++++++++++++------ 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index f50df50692..976a703a94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26284,9 +26284,9 @@ } }, "node_modules/mysql2": { - "version": "3.11.3", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.3.tgz", - "integrity": "sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==", + "version": "3.11.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.5.tgz", + "integrity": "sha512-0XFu8rUmFN9vC0ME36iBvCUObftiMHItrYFhlCRvFWbLgpNqtC4Br/NmZX1HNCszxT0GGy5QtP+k3Q3eCJPaYA==", "dev": true, "license": "MIT", "dependencies": { @@ -26309,6 +26309,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "dev": true, + "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" }, @@ -37853,7 +37854,7 @@ "@types/mocha": "7.0.2", "@types/node": "18.18.14", "@types/semver": "7.5.8", - "mysql2": "3.11.3", + "mysql2": "3.11.5", "nyc": "15.1.0", "rimraf": "5.0.10", "semver": "7.6.3", @@ -48554,7 +48555,7 @@ "@types/mocha": "7.0.2", "@types/node": "18.18.14", "@types/semver": "7.5.8", - "mysql2": "3.11.3", + "mysql2": "3.11.5", "nyc": "15.1.0", "rimraf": "5.0.10", "semver": "7.6.3", @@ -63019,9 +63020,9 @@ } }, "mysql2": { - "version": "3.11.3", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.3.tgz", - "integrity": "sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==", + "version": "3.11.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.5.tgz", + "integrity": "sha512-0XFu8rUmFN9vC0ME36iBvCUObftiMHItrYFhlCRvFWbLgpNqtC4Br/NmZX1HNCszxT0GGy5QtP+k3Q3eCJPaYA==", "dev": true, "requires": { "aws-ssl-profiles": "^1.1.1", diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/package.json b/plugins/node/opentelemetry-instrumentation-mysql2/package.json index dcf3806e56..20de228c25 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql2/package.json @@ -50,7 +50,7 @@ "@types/mocha": "7.0.2", "@types/node": "18.18.14", "@types/semver": "7.5.8", - "mysql2": "3.11.3", + "mysql2": "3.11.5", "nyc": "15.1.0", "rimraf": "5.0.10", "semver": "7.6.3", diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts index 7557cf7a01..8c90080980 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts @@ -31,6 +31,7 @@ import type * as mysqlTypes from 'mysql2'; import { MySQL2InstrumentationConfig } from './types'; import { getConnectionAttributes, + getConnectionPrototypeToInstrument, getDbStatement, getSpanName, once, @@ -56,7 +57,7 @@ export class MySQL2Instrumentation extends InstrumentationBase=1.4.2 <4'], (moduleExports: any) => { const ConnectionPrototype: mysqlTypes.Connection = - moduleExports.Connection.prototype; + getConnectionPrototypeToInstrument(moduleExports.Connection); if (isWrapped(ConnectionPrototype.query)) { this._unwrap(ConnectionPrototype, 'query'); } diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index 0a045ff45a..bb0fb763d3 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -146,3 +146,22 @@ export const once = (fn: Function) => { return fn(...args); }; }; + +export function getConnectionPrototypeToInstrument(connection: any) { + const connectionPrototype = connection.prototype; + const basePrototype = Object.getPrototypeOf(connectionPrototype); + + // mysql2@3.11.5 included a refactoring, where most code was moved out of the `Connection` class and into a shared base + // so we need to instrument that instead, see https://github.com/sidorares/node-mysql2/pull/3081 + // This checks if the functions we're instrumenting are there on the base - we cannot use the presence of a base + // prototype since EventEmitter is the base for mysql2@<=3.11.4 + if ( + typeof basePrototype?.query === 'function' && + typeof basePrototype?.execute === 'function' + ) { + return basePrototype; + } + + // otherwise instrument the connection directly. + return connectionPrototype; +} diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts index a11480418c..ef14d7d982 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts @@ -223,10 +223,14 @@ describe('mysql2', () => { }); query.on('end', () => { - assert.strictEqual(rows, 1); - const spans = memoryExporter.getFinishedSpans(); - assert.strictEqual(spans.length, 1); - assertSpan(spans[0], sql); + try { + assert.strictEqual(rows, 1); + const spans = memoryExporter.getFinishedSpans(); + assert.strictEqual(spans.length, 1); + assertSpan(spans[0], sql); + } catch (e) { + done(e); + } done(); }); }); @@ -340,8 +344,12 @@ describe('mysql2', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans.length, 1); getLastQueries(1).then(([query]) => { - assert.doesNotMatch(query, /.*traceparent.*/); - done(); + try { + assert.doesNotMatch(query, /.*traceparent.*/); + done(); + } catch (e) { + done(e); + } }); }); }); From fa7866839888612ebc129cff6cf8515e72ba8f18 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Wed, 4 Dec 2024 17:41:38 +0100 Subject: [PATCH 3/3] ci: add workflow to update otel dependencies (#2536) --- .github/workflows/update-otel-deps.yaml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/update-otel-deps.yaml diff --git a/.github/workflows/update-otel-deps.yaml b/.github/workflows/update-otel-deps.yaml new file mode 100644 index 0000000000..05cf5a7eb2 --- /dev/null +++ b/.github/workflows/update-otel-deps.yaml @@ -0,0 +1,48 @@ +name: Create or Update OpenTelemetry Update PR + +on: + workflow_dispatch: + +jobs: + create-or-update-deps-pr: + runs-on: ubuntu-latest + steps: + - name: Fork + run: gh repo fork open-telemetry/opentelemetry-js-contrib + env: + GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v4 + with: + repository: opentelemetrybot/opentelemetry-js-contrib + ref: main + token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + - name: Sync with upstream + run: | + git remote show origin + git remote add upstream https://github.com/open-telemetry/opentelemetry-js-contrib.git + git fetch upstream + git reset --hard upstream/main + git push origin main --force + + - uses: actions/setup-node@v4 + with: + cache: 'npm' + cache-dependency-path: package-lock.json + node-version: 22 + + - run: npm install -g npm@latest + + - run: npm ci + + - name: Create/Update Release PR + run: | + git config user.name opentelemetrybot + git config user.email 107717825+opentelemetrybot@users.noreply.github.com + git checkout -b feat/update-otel-deps + node ./scripts/update-otel-deps.js + git commit -am "feat(deps): update deps matching '@opentelemetry/*'" + git push origin feat/update-otel-deps --force + gh pr create --repo open-telemetry/opentelemetry-js-contrib --title 'chore: prepare next release' --body 'Updates all `@opentelemetry/*` dependencies to latest' + env: + GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}