Skip to content

Commit

Permalink
Merge branch 'main' into refactor/test-utils-transformer-types
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Dec 4, 2024
2 parents 8ccc2ec + fa78668 commit f6e7f7a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/update-otel-deps.yaml
Original file line number Diff line number Diff line change
@@ -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 [email protected]
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 }}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type * as mysqlTypes from 'mysql2';
import { MySQL2InstrumentationConfig } from './types';
import {
getConnectionAttributes,
getConnectionPrototypeToInstrument,
getDbStatement,
getSpanName,
once,
Expand All @@ -56,7 +57,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
['>=1.4.2 <4'],
(moduleExports: any) => {
const ConnectionPrototype: mysqlTypes.Connection =
moduleExports.Connection.prototype;
getConnectionPrototypeToInstrument(moduleExports.Connection);
if (isWrapped(ConnectionPrototype.query)) {
this._unwrap(ConnectionPrototype, 'query');
}
Expand Down
19 changes: 19 additions & 0 deletions plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// [email protected] 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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);
}
});
});
});
Expand Down

0 comments on commit f6e7f7a

Please sign in to comment.