-
Notifications
You must be signed in to change notification settings - Fork 98
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: add support for pg 7 changes #702
Conversation
99eb8fe
to
01b4244
Compare
Didn't look at the code yet but CI is failing. |
01b4244
to
9e901cb
Compare
Codecov Report
@@ Coverage Diff @@
## master #702 +/- ##
==========================================
- Coverage 91.02% 90.77% -0.26%
==========================================
Files 29 29
Lines 1438 1485 +47
Branches 280 293 +13
==========================================
+ Hits 1309 1348 +39
- Misses 52 57 +5
- Partials 77 80 +3
Continue to review full report at Codecov.
|
src/plugins/plugin-pg.ts
Outdated
span.addLabel('values', pgQuery.values); | ||
const args: pg_6.QueryReturnValue[] = | ||
Array.prototype.slice.call(arguments, 0); | ||
if (args.length >= 1) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-pg.ts
Outdated
// - ...[text: string, values?: Array<any>] | ||
// See: https://node-postgres.com/guides/upgrading | ||
|
||
if (args.length >= 1) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-pg.ts
Outdated
|
||
if (args.length >= 1) { | ||
// Extract query text and values, if needed. | ||
if (api.enhancedDatabaseReportingEnabled()) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/plugins/plugin-pg.ts
Outdated
span.addLabel('error', err); | ||
} | ||
if (res) { | ||
span.addLabel('row_count', res.rowCount); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This PR converts the PostGreSQL tracing plugin to TypeScript, makes changes to support the new API in pg@7, adds a few more tests, and changes the way
value
labels are collected.pg@7
.plugin-pg.ts
to ES6 + type annotations, and installspg@7
types. There should be no behavioral change.pg@7
, based on source code and the upgrade guide.pg@6
, an object is always returned byClient#query
, and is simultaneously aPromise[Like]
, anEventEmitter
, and an object{ text: string; values?: Array, callback?: Function }
.pg@7
, the return value ofClient#query
is either aPromise
,EventEmitter
, orundefined
, depending on the input parameters.values
from the output object ofClient#query
; inpg@7
, these fields are not guaranteed to exist, so we must gather them from input parameters instead. However, there is a mismatch betweenvalues
gotten from input and output; outputvalues
are coerced to strings and escaped to avoid SQL injection. So to keep things consistent, we now also getvalues
from the inputs toClient#query
inpg@6
. (I don't think that these values being unescaped should pose a threat because their values are simply stored, not executed; feel free to dispute that.)Submittable
s. Converting this test to idiomatic TypeScript is out of the scope of this PR.