-
Notifications
You must be signed in to change notification settings - Fork 580
fix(knex): connection attrs missing if connectionString used #1932
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(knex): connection attrs missing if connectionString used #1932
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1932 +/- ##
==========================================
- Coverage 91.02% 91.02% -0.01%
==========================================
Files 146 146
Lines 7478 7488 +10
Branches 1497 1502 +5
==========================================
+ Hits 6807 6816 +9
- Misses 671 672 +1
🚀 New features to boost your workflow:
|
const url = new URL(connectionString); | ||
return { | ||
host: url.hostname, | ||
port: parseInt(url.port || '5432', 10), |
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.
I'm interested in this pull request getting merged, so I thought I'd add some notes.
It looks like connectionString
is for both PostgreSQL and RedShift. It looks like the default port for RedShift is 5439.
I think you can check the URL protocol which should be postgres:
or redshift:
and set it to 5432/5439?
> (new URL("postgres://user:password@myhost/mydb")).protocol
'postgres:'
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.
Thanks for the comment. Yes I can do that. However we cannot then cover the case of CockroachDB which uses postgres
protocol, but has a different default port of 26257.
I will see how knex handles redshift connection string when port is not provided and try to match that functionality. In the end that is the right thing to do.
It looks like there's another in-flight PR that will also affect the same part of the code, we'll wait for this to land first (#2671). |
@@ -131,13 +131,19 @@ export class KnexInstrumentation extends InstrumentationBase<any> { | |||
return function wrapQuery(original: () => any) { | |||
return function wrapped_logging_method(this: any, query: any) { | |||
const config = this.client.config; | |||
const connection = utils.parseConnectionString( |
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.
Maybe we could pass the entire config.connection here and return the resulting values instead of having undefined checks in the attribute assignment further down?
I think this settles having a custom function returning the connection attributes, when we now have three different ways to configure them, what do you think @edosrecki ? I think it would be nice rolling this into this PR, I'd wait for @edosrecki to respond, if I'll make both changes it into a separate PR. |
Hi @edosrecki , thank you for your contribution. Recently the Database Semantic Conventions was marked as stabled, and with this a few changes came, for example, there are no longer attributes for Connection String, DB User, DB name, etc. And new attributes were added, such as DB namespace (that should include the removed attributes). Because of those changes, we don't want to add or update attributes that are no longer stable and should be removed instead. For this reason, I'll close this PR. You can still open a new PR focusing only on fixes related to the stable convention, and you can also help out with the migration (which would be very much appreciate it and I would be happy to review), but I can see that a lot has already been done here, so you can check if any attributes are missing. Here is an example of how I'm doing this migration for the PG package. Feel free to reach out to me if you have any questions! |
Which problem is this PR solving?
connectionString
property when initializingknex
(instead of specifying individual fields):database = undefined
:Short description of the changes
connectionString
is provided inknex
options, extract attributes from it (hostname, port, user, database).connectionString
and individual fields are used,connectionString
takes precedence: