-
Notifications
You must be signed in to change notification settings - Fork 550
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
fix(instr-knex): handle config provider functions #2286
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2286 +/- ##
==========================================
- Coverage 90.97% 90.30% -0.67%
==========================================
Files 146 147 +1
Lines 7492 7264 -228
Branches 1502 1509 +7
==========================================
- Hits 6816 6560 -256
- Misses 676 704 +28
|
9a2050d
to
404bf1c
Compare
connectionSettings gets set for static configs: https://github.com/knex/knex/blob/f6ea8122b61af25cb20f445ee0d731d0a8eed567/lib/client.js#L76 and for config provider functions: https://github.com/knex/knex/blob/f6ea8122b61af25cb20f445ee0d731d0a8eed567/lib/client.js#L256
404bf1c
to
3fcb711
Compare
I've been getting test failures caused by network flakes:
If someone with permissions could rerun the tests for me, that would be much appreciated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thank you for contributing a fix to this issue, and also for adding useful links to provide more context for the review.
I do have one question - since the connection can be an async function that can resolves sometime in the future, is it possible that if a quesy is made very early, that the connectionSettings are still not resolved? Do you think it's worth adding a test for this case?
@blumamir I just tried writing a test for this case:
It does pass, as I believe knex must resolve the config function before attempting to make any queries. However, without being able to hook into the implementation of knex, this test seems inherently racey, since there is no way to guarantee that we start trying to run the query before resolving the config function. Do you think it is still worth adding? |
@blumamir What are the next steps for trying to land this PR? |
Which problem is this PR solving?
The knex connection configuration can be set with a static object, or with a function. From the knex docs:
This instrumentation didn't handle the function case previously, resulting in
undefined
in the span name and a bunch of missing attributes.Short description of the changes
Instead of accessing properties in
client.config.connection
, the instrumentation should be accessingclient.connectionSettings
. This gets set for static configs here and for config provider functions here