Skip to content

fix(knex): make stack traces work in 0.18+ #1497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/instrumentation/modules/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var symbols = require('../../symbols')

module.exports = function (Knex, agent, { version, enabled }) {
if (!enabled) return Knex
if (semver.gte(version, '0.18.0')) {
if (semver.gte(version, '0.21.0')) {
agent.logger.debug('knex version %s not supported - aborting...', version)
return Knex
}
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/shimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function logger () {
}

function isFunction (funktion) {
return funktion && {}.toString.call(funktion) === '[object Function]'
return typeof funktion === 'function'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Qard Wow, nice find!

This was also updated in the upstream shimmer module last year: othiym23/shimmer@ec15ba2

I wonder why typeof wasn't used originally.

Why was this making knex fail btw? I would love to know what knex did to fail this check 🤔 Did they use async or generator functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They started using async functions.

}

function wrap (nodule, name, wrapper) {
Expand Down
11 changes: 3 additions & 8 deletions test/instrumentation/modules/pg/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,9 @@ function assertBasicQuery (t, data) {
t.equal(data.spans[0].type, 'db')
t.equal(data.spans[0].subtype, 'postgresql')
t.equal(data.spans[0].action, 'query')

// From 0.18 on, knex uses a bluebird queue internally,
// which terminates the stacktrace before user code.
if (semver.lt(knexVersion, '0.18.0')) {
t.ok(data.spans[0].stacktrace.some(function (frame) {
return frame.function === 'userLandCode'
}), 'include user-land code frame')
}
t.ok(data.spans[0].stacktrace.some(function (frame) {
return frame.function === 'userLandCode'
}), 'include user-land code frame')
}

function createClient (t, cb) {
Expand Down