Skip to content

Commit

Permalink
feat: add knex@3 support (#3659)
Browse files Browse the repository at this point in the history
Co-authored-by: Trent Mick <[email protected]>
  • Loading branch information
dependabot[bot] and trentm authored Oct 18, 2023
1 parent 2892fcf commit aeae1dc
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 47 deletions.
10 changes: 8 additions & 2 deletions .tav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ bluebird:
# - 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
# - knex 3.0.0 min supported node is v16
knex-v0.10-v0.17:
name: knex
# Latest 0.16 release was in 2019, therefore only test first and last in this range.
Expand All @@ -189,12 +190,17 @@ knex-v0.17-v0.21:
knex-v0.21-v1:
name: knex
node: '>=10.22.0'
versions: '0.21.21 || 0.95.15' # latest minors subset of '>=0.21 <1'
versions: '0.21.21 || ^0.95.15' # latest majors subset of '>=0.21 <1'
commands: node test/instrumentation/modules/pg/knex.test.js
knex-v1-v3:
name: knex
node: '>=12.0.0'
versions: '1.0.7 || 2.4.2' # latest minors subset of '>=1 <3'
versions: '1.0.7 || ^2.5.1' # latest majors subset of '>=1 <3'
commands: node test/instrumentation/modules/pg/knex.test.js
knex-v3-:
name: knex
node: '>=16'
versions: '^3.0.1'
commands: node test/instrumentation/modules/pg/knex.test.js

ws-old:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ See the <<upgrade-to-v4>> guide.
See <https://github.com/elastic/ecs-logging-nodejs/pull/152>.
({issues}3195[#3195])
* Add knex@3 instrumentation. ({pull}3659[#3659])
[float]
===== Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ please create a new topic in the https://discuss.elastic.co/c/apm[Elastic APM di
[options="header"]
|=================================================
|Module |Version |Note
|https://www.npmjs.com/package/knex[knex] |>=0.10.0 <3.0.0 | Provides better span stack traces for 'pg' and 'mysql' spans.
|https://www.npmjs.com/package/knex[knex] |>=0.10.0 <4.0.0 | Provides better span stack traces for 'pg' and 'mysql' spans.
|=================================================

[float]
Expand Down
23 changes: 7 additions & 16 deletions lib/instrumentation/modules/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ module.exports = function (Knex, agent, { version, enabled }) {
if (!enabled) {
return Knex;
}
if (agent._conf.spanStackTraceMinDuration < 0) {
agent.logger.trace(
'not instrumenting knex because not capturing span stack traces (spanStackTraceMinDuration=%s)',
agent._conf.spanStackTraceMinDuration,
if (!semver.satisfies(version, '>=0.10.0 <4.0.0')) {
agent.logger.debug(
`knex@${version} is not supported, skipping knex instrumentation`,
);
return Knex;
}

if (semver.gte(version, '3.0.0')) {
agent.logger.debug('knex version %s not supported - aborting...', version);
return Knex;
}
if (
semver.satisfies(version, '>=1 <3') &&
semver.lt(process.version, '12.0.0')
) {
agent.logger.debug(
'knex version %s does not support node %s, skipping knex instrumentation',
version,
process.version,
if (agent._conf.spanStackTraceMinDuration < 0) {
agent.logger.trace(
'not instrumenting knex because not capturing span stack traces (spanStackTraceMinDuration=%s)',
agent._conf.spanStackTraceMinDuration,
);
return Knex;
}
Expand Down
50 changes: 25 additions & 25 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"https-pem": "^3.0.0",
"ioredis": "^5.1.0",
"js-yaml": "^4.1.0",
"knex": "^2.4.2",
"knex": "^3.0.1",
"koa": "^2.11.0",
"koa-bodyparser": "^4.3.0",
"koa-router": "^12.0.0",
Expand Down
4 changes: 2 additions & 2 deletions test/instrumentation/modules/pg/knex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var agent = require('../../../..').start({
var knexVersion = require('knex/package').version;
var semver = require('semver');

// 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
if (
(semver.gte(knexVersion, '0.18.0') && semver.lt(process.version, '8.6.0')) ||
(semver.gte(knexVersion, '0.21.0') &&
semver.lt(process.version, '10.22.0')) ||
(semver.gte(knexVersion, '1.0.0') && semver.lt(process.version, '12.0.0'))
(semver.gte(knexVersion, '1.0.0') && semver.lt(process.version, '12.0.0')) ||
(semver.gte(knexVersion, '3.0.0') && semver.lt(process.version, '16.0.0'))
) {
console.log(
`# SKIP knex@${knexVersion} does not support node ${process.version}`,
Expand Down

0 comments on commit aeae1dc

Please sign in to comment.