Skip to content

Commit aeae1dc

Browse files
feat: add knex@3 support (#3659)
Co-authored-by: Trent Mick <[email protected]>
1 parent 2892fcf commit aeae1dc

File tree

7 files changed

+46
-47
lines changed

7 files changed

+46
-47
lines changed

.tav.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ bluebird:
175175
# - knex 0.18.0 min supported node is v8
176176
# - knex 0.21.0 min supported node is v10
177177
# - knex 1.0.0 min supported node is v12
178+
# - knex 3.0.0 min supported node is v16
178179
knex-v0.10-v0.17:
179180
name: knex
180181
# Latest 0.16 release was in 2019, therefore only test first and last in this range.
@@ -189,12 +190,17 @@ knex-v0.17-v0.21:
189190
knex-v0.21-v1:
190191
name: knex
191192
node: '>=10.22.0'
192-
versions: '0.21.21 || 0.95.15' # latest minors subset of '>=0.21 <1'
193+
versions: '0.21.21 || ^0.95.15' # latest majors subset of '>=0.21 <1'
193194
commands: node test/instrumentation/modules/pg/knex.test.js
194195
knex-v1-v3:
195196
name: knex
196197
node: '>=12.0.0'
197-
versions: '1.0.7 || 2.4.2' # latest minors subset of '>=1 <3'
198+
versions: '1.0.7 || ^2.5.1' # latest majors subset of '>=1 <3'
199+
commands: node test/instrumentation/modules/pg/knex.test.js
200+
knex-v3-:
201+
name: knex
202+
node: '>=16'
203+
versions: '^3.0.1'
198204
commands: node test/instrumentation/modules/pg/knex.test.js
199205

200206
ws-old:

CHANGELOG.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ See the <<upgrade-to-v4>> guide.
5353
See <https://github.com/elastic/ecs-logging-nodejs/pull/152>.
5454
({issues}3195[#3195])
5555
56+
* Add knex@3 instrumentation. ({pull}3659[#3659])
57+
5658
[float]
5759
===== Bug fixes
5860

docs/supported-technologies.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ please create a new topic in the https://discuss.elastic.co/c/apm[Elastic APM di
167167
[options="header"]
168168
|=================================================
169169
|Module |Version |Note
170-
|https://www.npmjs.com/package/knex[knex] |>=0.10.0 <3.0.0 | Provides better span stack traces for 'pg' and 'mysql' spans.
170+
|https://www.npmjs.com/package/knex[knex] |>=0.10.0 <4.0.0 | Provides better span stack traces for 'pg' and 'mysql' spans.
171171
|=================================================
172172

173173
[float]

lib/instrumentation/modules/knex.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,17 @@ module.exports = function (Knex, agent, { version, enabled }) {
1919
if (!enabled) {
2020
return Knex;
2121
}
22-
if (agent._conf.spanStackTraceMinDuration < 0) {
23-
agent.logger.trace(
24-
'not instrumenting knex because not capturing span stack traces (spanStackTraceMinDuration=%s)',
25-
agent._conf.spanStackTraceMinDuration,
22+
if (!semver.satisfies(version, '>=0.10.0 <4.0.0')) {
23+
agent.logger.debug(
24+
`knex@${version} is not supported, skipping knex instrumentation`,
2625
);
2726
return Knex;
2827
}
2928

30-
if (semver.gte(version, '3.0.0')) {
31-
agent.logger.debug('knex version %s not supported - aborting...', version);
32-
return Knex;
33-
}
34-
if (
35-
semver.satisfies(version, '>=1 <3') &&
36-
semver.lt(process.version, '12.0.0')
37-
) {
38-
agent.logger.debug(
39-
'knex version %s does not support node %s, skipping knex instrumentation',
40-
version,
41-
process.version,
29+
if (agent._conf.spanStackTraceMinDuration < 0) {
30+
agent.logger.trace(
31+
'not instrumenting knex because not capturing span stack traces (spanStackTraceMinDuration=%s)',
32+
agent._conf.spanStackTraceMinDuration,
4233
);
4334
return Knex;
4435
}

package-lock.json

+25-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
"https-pem": "^3.0.0",
175175
"ioredis": "^5.1.0",
176176
"js-yaml": "^4.1.0",
177-
"knex": "^2.4.2",
177+
"knex": "^3.0.1",
178178
"koa": "^2.11.0",
179179
"koa-bodyparser": "^4.3.0",
180180
"koa-router": "^12.0.0",

test/instrumentation/modules/pg/knex.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ var agent = require('../../../..').start({
2626
var knexVersion = require('knex/package').version;
2727
var semver = require('semver');
2828

29-
// knex 0.18.0 min supported node is v8, knex 0.21.0 min supported node is v10, knex 1.0.0 min supported node is v12
3029
if (
3130
(semver.gte(knexVersion, '0.18.0') && semver.lt(process.version, '8.6.0')) ||
3231
(semver.gte(knexVersion, '0.21.0') &&
3332
semver.lt(process.version, '10.22.0')) ||
34-
(semver.gte(knexVersion, '1.0.0') && semver.lt(process.version, '12.0.0'))
33+
(semver.gte(knexVersion, '1.0.0') && semver.lt(process.version, '12.0.0')) ||
34+
(semver.gte(knexVersion, '3.0.0') && semver.lt(process.version, '16.0.0'))
3535
) {
3636
console.log(
3737
`# SKIP knex@${knexVersion} does not support node ${process.version}`,

0 commit comments

Comments
 (0)