Skip to content

Commit f6e7f7a

Browse files
authored
Merge branch 'main' into refactor/test-utils-transformer-types
2 parents 8ccc2ec + fa78668 commit f6e7f7a

File tree

8 files changed

+95
-18
lines changed

8 files changed

+95
-18
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Before creating a pull request, please make sure:
77
- You have read the guide for contributing
88
- See https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md
99
- You signed all your commits (otherwise we won't be able to merge the PR)
10-
- See https://github.com/open-telemetry/community/blob/main/CONTRIBUTING.md#sign-the-cla
10+
- See https://github.com/open-telemetry/community/blob/main/guides/contributor#sign-the-cla
1111
- You added unit tests for the new functionality
1212
- You mention in the PR description which issue it is addressing, e.g. "Fixes #xxx". This will auto-close
1313
the issue that your PR fixes (if such)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Create or Update OpenTelemetry Update PR
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
create-or-update-deps-pr:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Fork
11+
run: gh repo fork open-telemetry/opentelemetry-js-contrib
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
repository: opentelemetrybot/opentelemetry-js-contrib
18+
ref: main
19+
token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
20+
- name: Sync with upstream
21+
run: |
22+
git remote show origin
23+
git remote add upstream https://github.com/open-telemetry/opentelemetry-js-contrib.git
24+
git fetch upstream
25+
git reset --hard upstream/main
26+
git push origin main --force
27+
28+
- uses: actions/setup-node@v4
29+
with:
30+
cache: 'npm'
31+
cache-dependency-path: package-lock.json
32+
node-version: 22
33+
34+
- run: npm install -g npm@latest
35+
36+
- run: npm ci
37+
38+
- name: Create/Update Release PR
39+
run: |
40+
git config user.name opentelemetrybot
41+
git config user.email [email protected]
42+
git checkout -b feat/update-otel-deps
43+
node ./scripts/update-otel-deps.js
44+
git commit -am "feat(deps): update deps matching '@opentelemetry/*'"
45+
git push origin feat/update-otel-deps --force
46+
gh pr create --repo open-telemetry/opentelemetry-js-contrib --title 'chore: prepare next release' --body 'Updates all `@opentelemetry/*` dependencies to latest'
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ git merge upstream/main
8888

8989
Remember to always work in a branch of your local copy, as you might otherwise have to contend with conflicts in main.
9090

91-
Please also see [GitHub workflow](https://github.com/open-telemetry/community/blob/main/CONTRIBUTING.md#github-workflow) section of general project contributing guide.
91+
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.
9292

9393
## Development
9494

package-lock.json

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/opentelemetry-instrumentation-mysql2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/mocha": "7.0.2",
5151
"@types/node": "18.18.14",
5252
"@types/semver": "7.5.8",
53-
"mysql2": "3.11.3",
53+
"mysql2": "3.11.5",
5454
"nyc": "15.1.0",
5555
"rimraf": "5.0.10",
5656
"semver": "7.6.3",

plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type * as mysqlTypes from 'mysql2';
3131
import { MySQL2InstrumentationConfig } from './types';
3232
import {
3333
getConnectionAttributes,
34+
getConnectionPrototypeToInstrument,
3435
getDbStatement,
3536
getSpanName,
3637
once,
@@ -56,7 +57,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
5657
['>=1.4.2 <4'],
5758
(moduleExports: any) => {
5859
const ConnectionPrototype: mysqlTypes.Connection =
59-
moduleExports.Connection.prototype;
60+
getConnectionPrototypeToInstrument(moduleExports.Connection);
6061
if (isWrapped(ConnectionPrototype.query)) {
6162
this._unwrap(ConnectionPrototype, 'query');
6263
}

plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,22 @@ export const once = (fn: Function) => {
146146
return fn(...args);
147147
};
148148
};
149+
150+
export function getConnectionPrototypeToInstrument(connection: any) {
151+
const connectionPrototype = connection.prototype;
152+
const basePrototype = Object.getPrototypeOf(connectionPrototype);
153+
154+
// [email protected] included a refactoring, where most code was moved out of the `Connection` class and into a shared base
155+
// so we need to instrument that instead, see https://github.com/sidorares/node-mysql2/pull/3081
156+
// This checks if the functions we're instrumenting are there on the base - we cannot use the presence of a base
157+
// prototype since EventEmitter is the base for mysql2@<=3.11.4
158+
if (
159+
typeof basePrototype?.query === 'function' &&
160+
typeof basePrototype?.execute === 'function'
161+
) {
162+
return basePrototype;
163+
}
164+
165+
// otherwise instrument the connection directly.
166+
return connectionPrototype;
167+
}

plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,14 @@ describe('mysql2', () => {
223223
});
224224

225225
query.on('end', () => {
226-
assert.strictEqual(rows, 1);
227-
const spans = memoryExporter.getFinishedSpans();
228-
assert.strictEqual(spans.length, 1);
229-
assertSpan(spans[0], sql);
226+
try {
227+
assert.strictEqual(rows, 1);
228+
const spans = memoryExporter.getFinishedSpans();
229+
assert.strictEqual(spans.length, 1);
230+
assertSpan(spans[0], sql);
231+
} catch (e) {
232+
done(e);
233+
}
230234
done();
231235
});
232236
});
@@ -340,8 +344,12 @@ describe('mysql2', () => {
340344
const spans = memoryExporter.getFinishedSpans();
341345
assert.strictEqual(spans.length, 1);
342346
getLastQueries(1).then(([query]) => {
343-
assert.doesNotMatch(query, /.*traceparent.*/);
344-
done();
347+
try {
348+
assert.doesNotMatch(query, /.*traceparent.*/);
349+
done();
350+
} catch (e) {
351+
done(e);
352+
}
345353
});
346354
});
347355
});

0 commit comments

Comments
 (0)