elastic / elastic/apm-agent-nodejs
pg-native tests/support
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
The `pg` module, which we instrument, supports "native" binding usage as described at https://node-postgres.com/features/native
We should explicitly attempt to support and test this. Currently this looks like it mostly works (and some handling of the `.native` getter in the instrumentation suggests this was intentional). However, a few of the tests fail.
Starter patch
```diff
diff --git a/package.json b/package.json
index d3056dbd..94c048d6 100644
--- a/package.json
+++ b/package.json
@@ -188,6 +188,7 @@
"nyc": "^15.0.0",
"once": "^1.4.0",
"pg": "^8.7.1",
+ "pg-native": "^3.0.1",
"pug": "^3.0.1",
"redis": "^4.3.0",
"request": "^2.88.2",
diff --git a/test/instrumentation/modules/pg/pg.test.js b/test/instrumentation/modules/pg/pg.test.js
index e2699c02..b37c282a 100644
--- a/test/instrumentation/modules/pg/pg.test.js
+++ b/test/instrumentation/modules/pg/pg.test.js
@@ -25,7 +25,7 @@ var once = require('once')
var pgVersion = require('pg/package.json').version
var test = require('tape')
-var pg = require('pg')
+var pg = require('pg').native
var utils = require('./_utils')
var mockClient = require('../../../_mock_http_client')
const { NoopApmClient } = require('../../../../lib/apm-client/noop-apm-client')
```
Current (failing) test run
```
% node test/instrumentation/modules/pg/pg.test.js
TAP version 13
# pg.createClient
# basic query with callback
# client.query(sql, callback)
ok 1 no currentSpan in sync code after pg .query
ok 2 no currentSpan in pg .query callback
ok 3 null
ok 4 should be strictly equal
ok 5 should be strictly equal
ok 6 should be strictly equal
ok 7 should be strictly equal
ok 8 should be strictly equal
ok 9 should be strictly equal
ok 10 should be strictly equal
ok 11 should be strictly equal
ok 12 span.context.db
ok 13 span.context.service.target
ok 14 span.context.destination
# client.query(sql, values, callback)
ok 15 no currentSpan in sync code after pg .query
ok 16 no currentSpan in pg .query callback
ok 17 null
ok 18 should be strictly equal
ok 19 should be strictly equal
ok 20 should be strictly equal
ok 21 should be strictly equal
ok 22 should be strictly equal
ok 23 should be strictly equal
ok 24 should be strictly equal
ok 25 should be strictly equal
ok 26 span.context.db
ok 27 span.context.service.target
ok 28 span.context.destination
# client.query(options, callback)
ok 29 no currentSpan in sync code after pg .query
ok 30 no currentSpan in pg .query callback
ok 31 null
ok 32 should be strictly equal
ok 33 should be strictly equal
ok 34 should be strictly equal
ok 35 should be strictly equal
ok 36 should be strictly equal
ok 37 should be strictly equal
ok 38 should be strictly equal
ok 39 should be strictly equal
ok 40 span.context.db
ok 41 span.context.service.target
ok 42 span.context.destination
# client.query(options, values, callback)
ok 43 no currentSpan in sync code after pg .query
ok 44 no currentSpan in pg .query callback
ok 45 null
ok 46 should be strictly equal
ok 47 should be strictly equal
ok 48 should be strictly equal
ok 49 should be strictly equal
ok 50 should be strictly equal
ok 51 should be strictly equal
ok 52 should be strictly equal
ok 53 should be strictly equal
ok 54 span.context.db
ok 55 span.context.service.target
ok 56 span.context.destination
# client.query(options-with-values, callback)
ok 57 no currentSpan in sync code after pg .query
ok 58 no currentSpan in pg .query callback
ok 59 null
ok 60 should be strictly equal
ok 61 should be strictly equal
ok 62 should be strictly equal
ok 63 should be strictly equal
ok 64 should be strictly equal
ok 65 should be strictly equal
ok 66 should be strictly equal
ok 67 should be strictly equal
ok 68 span.context.db
ok 69 span.context.service.target
ok 70 span.context.destination
# client.query(sql) - no callback
ok 71 no currentSpan in sync code after pg .query
ok 72 should be strictly equal
ok 73 should be strictly equal
ok 74 should be strictly equal
ok 75 should be strictly equal
ok 76 should be strictly equal
ok 77 should be strictly equal
ok 78 should be strictly equal
ok 79 span.context.db
ok 80 span.context.service.target
ok 81 span.context.destination
# basic query streaming
# client.query(new Query(sql))
ok 82 no currentSpan in sync code after pg .query
ok 83 pg span should not be active in user code
ok 84 should be strictly equal
ok 85 pg span should not be active in user code
ok 86 should be strictly equal
ok 87 should be strictly equal
ok 88 should be strictly equal
ok 89 should be strictly equal
ok 90 should be strictly equal
ok 91 should be strictly equal
ok 92 should be strictly equal
ok 93 should be strictly equal
ok 94 span.context.db
ok 95 span.context.service.target
ok 96 span.context.destination
# basic query promise
# client.query(sql)
ok 97 no currentSpan in sync code after pg .query
ok 98 should be strictly equal
ok 99 should be strictly equal
ok 100 should be strictly equal
ok 101 should be strictly equal
ok 102 should be strictly equal
ok 103 should be strictly equal
ok 104 should be strictly equal
ok 105 should be strictly equal
ok 106 should be strictly equal
ok 107 span.context.db
ok 108 span.context.service.target
ok 109 span.context.destination
# client.query(sql, values)
ok 110 no currentSpan in sync code after pg .query
ok 111 should be strictly equal
ok 112 should be strictly equal
ok 113 should be strictly equal
ok 114 should be strictly equal
ok 115 should be strictly equal
ok 116 should be strictly equal
ok 117 should be strictly equal
ok 118 should be strictly equal
ok 119 should be strictly equal
ok 120 span.context.db
ok 121 span.context.service.target
ok 122 span.context.destination
# client.query(options)
ok 123 no currentSpan in sync code after pg .query
ok 124 should be strictly equal
ok 125 should be strictly equal
ok 126 should be strictly equal
ok 127 should be strictly equal
ok 128 should be strictly equal
ok 129 should be strictly equal
ok 130 should be strictly equal
ok 131 should be strictly equal
ok 132 should be strictly equal
ok 133 span.context.db
ok 134 span.context.service.target
ok 135 span.context.destination
# client.query(options, values)
ok 136 no currentSpan in sync code after pg .query
ok 137 should be strictly equal
ok 138 should be strictly equal
ok 139 should be strictly equal
ok 140 should be strictly equal
ok 141 should be strictly equal
ok 142 should be strictly equal
ok 143 should be strictly equal
ok 144 should be strictly equal
ok 145 should be strictly equal
ok 146 span.context.db
ok 147 span.context.service.target
ok 148 span.context.destination
# client.query(options-with-values)
ok 149 no currentSpan in sync code after pg .query
ok 150 should be strictly equal
ok 151 should be strictly equal
ok 152 should be strictly equal
ok 153 should be strictly equal
ok 154 should be strictly equal
ok 155 should be strictly equal
ok 156 should be strictly equal
ok 157 should be strictly equal
ok 158 should be strictly equal
ok 159 span.context.db
ok 160 span.context.service.target
ok 161 span.context.destination
# simultaneous queries
# on same connection
ok 162 null
ok 163 should be strictly equal
ok 164 null
ok 165 should be strictly equal
ok 166 null
ok 167 should be strictly equal
ok 168 should be strictly equal
ok 169 should be strictly equal
ok 170 should be strictly equal
ok 171 should be strictly equal
ok 172 should be strictly equal
ok 173 should be strictly equal
ok 174 should be strictly equal
ok 175 span.context.db
ok 176 span.context.service.target
ok 177 span.context.destination
ok 178 each span is a child of the transaction
ok 179 should be strictly equal
ok 180 should be strictly equal
ok 181 should be strictly equal
ok 182 should be strictly equal
ok 183 span.context.db
ok 184 span.context.service.target
ok 185 span.context.destination
ok 186 each span is a child of the transaction
ok 187 should be strictly equal
ok 188 should be strictly equal
ok 189 should be strictly equal
ok 190 should be strictly equal
ok 191 span.context.db
ok 192 span.context.service.target
ok 193 span.context.destination
ok 194 each span is a child of the transaction
# simultaneous transactions
ok 195 null
ok 196 should be strictly equal
ok 197 null
ok 198 should be strictly equal
ok 199 null
ok 200 should be strictly equal
ok 201 should be strictly equal
ok 202 should be strictly equal
ok 203 should be deeply equivalent
ok 204 transaction should have span
ok 205 should be strictly equal
ok 206 should be strictly equal
ok 207 should be strictly equal
ok 208 should be strictly equal
ok 209 span.context.db
ok 210 span.context.service.target
ok 211 span.context.destination
ok 212 the span is a child of the transaction
ok 213 transaction should have span
ok 214 should be strictly equal
ok 215 should be strictly equal
ok 216 should be strictly equal
ok 217 should be strictly equal
ok 218 span.context.db
ok 219 span.context.service.target
ok 220 span.context.destination
ok 221 the span is a child of the transaction
ok 222 transaction should have span
ok 223 should be strictly equal
ok 224 should be strictly equal
ok 225 should be strictly equal
ok 226 should be strictly equal
ok 227 span.context.db
ok 228 span.context.service.target
ok 229 span.context.destination
ok 230 the span is a child of the transaction
# pg.createPoolAndConnect
# basic query with callback
# pool.query(sql, callback)
ok 231 no currentSpan in sync code after pg .query
ok 232 no currentSpan in pg .query callback
ok 233 null
ok 234 should be strictly equal
ok 235 should be strictly equal
ok 236 should be strictly equal
ok 237 should be strictly equal
ok 238 should be strictly equal
ok 239 should be strictly equal
ok 240 should be strictly equal
ok 241 should be strictly equal
ok 242 span.context.db
ok 243 span.context.service.target
ok 244 span.context.destination
# pool.query(sql, values, callback)
ok 245 no currentSpan in sync code after pg .query
ok 246 no currentSpan in pg .query callback
ok 247 null
ok 248 should be strictly equal
ok 249 should be strictly equal
ok 250 should be strictly equal
ok 251 should be strictly equal
ok 252 should be strictly equal
ok 253 should be strictly equal
ok 254 should be strictly equal
ok 255 should be strictly equal
ok 256 span.context.db
ok 257 span.context.service.target
ok 258 span.context.destination
# pool.query(options, callback)
ok 259 no currentSpan in sync code after pg .query
ok 260 no currentSpan in pg .query callback
ok 261 null
ok 262 should be strictly equal
ok 263 should be strictly equal
ok 264 should be strictly equal
ok 265 should be strictly equal
ok 266 should be strictly equal
ok 267 should be strictly equal
ok 268 should be strictly equal
ok 269 should be strictly equal
ok 270 span.context.db
ok 271 span.context.service.target
ok 272 span.context.destination
# pool.query(options, values, callback)
ok 273 no currentSpan in sync code after pg .query
ok 274 no currentSpan in pg .query callback
ok 275 null
ok 276 should be strictly equal
ok 277 should be strictly equal
ok 278 should be strictly equal
ok 279 should be strictly equal
ok 280 should be strictly equal
ok 281 should be strictly equal
ok 282 should be strictly equal
ok 283 should be strictly equal
ok 284 span.context.db
ok 285 span.context.service.target
ok 286 span.context.destination
# pool.query(options-with-values, callback)
ok 287 no currentSpan in sync code after pg .query
ok 288 no currentSpan in pg .query callback
ok 289 null
ok 290 should be strictly equal
ok 291 should be strictly equal
ok 292 should be strictly equal
ok 293 should be strictly equal
ok 294 should be strictly equal
ok 295 should be strictly equal
ok 296 should be strictly equal
ok 297 should be strictly equal
ok 298 span.context.db
ok 299 span.context.service.target
ok 300 span.context.destination
# pool.query(sql) - no callback
ok 301 no currentSpan in sync code after pg .query
ok 302 should be strictly equal
ok 303 should be strictly equal
ok 304 should be strictly equal
ok 305 should be strictly equal
ok 306 should be strictly equal
ok 307 should be strictly equal
ok 308 should be strictly equal
ok 309 span.context.db
ok 310 span.context.service.target
ok 311 span.context.destination
# basic query streaming
# pool.query(new Query(sql))
ok 312 no currentSpan in sync code after pg .query
ok 313 pg span should not be active in user code
ok 314 should be strictly equal
ok 315 pg span should not be active in user code
ok 316 should be strictly equal
ok 317 should be strictly equal
ok 318 should be strictly equal
ok 319 should be strictly equal
ok 320 should be strictly equal
ok 321 should be strictly equal
ok 322 should be strictly equal
ok 323 should be strictly equal
ok 324 span.context.db
ok 325 span.context.service.target
ok 326 span.context.destination
# basic query promise
# pool.query(sql)
ok 327 no currentSpan in sync code after pg .query
ok 328 should be strictly equal
ok 329 should be strictly equal
ok 330 should be strictly equal
ok 331 should be strictly equal
ok 332 should be strictly equal
ok 333 should be strictly equal
ok 334 should be strictly equal
ok 335 should be strictly equal
ok 336 should be strictly equal
ok 337 span.context.db
ok 338 span.context.service.target
ok 339 span.context.destination
# pool.query(sql, values)
ok 340 no currentSpan in sync code after pg .query
ok 341 should be strictly equal
ok 342 should be strictly equal
ok 343 should be strictly equal
ok 344 should be strictly equal
ok 345 should be strictly equal
ok 346 should be strictly equal
ok 347 should be strictly equal
ok 348 should be strictly equal
ok 349 should be strictly equal
ok 350 span.context.db
ok 351 span.context.service.target
ok 352 span.context.destination
# pool.query(options)
ok 353 no currentSpan in sync code after pg .query
ok 354 should be strictly equal
ok 355 should be strictly equal
ok 356 should be strictly equal
ok 357 should be strictly equal
ok 358 should be strictly equal
ok 359 should be strictly equal
ok 360 should be strictly equal
ok 361 should be strictly equal
ok 362 should be strictly equal
ok 363 span.context.db
ok 364 span.context.service.target
ok 365 span.context.destination
# pool.query(options, values)
ok 366 no currentSpan in sync code after pg .query
ok 367 should be strictly equal
ok 368 should be strictly equal
ok 369 should be strictly equal
ok 370 should be strictly equal
ok 371 should be strictly equal
ok 372 should be strictly equal
ok 373 should be strictly equal
ok 374 should be strictly equal
ok 375 should be strictly equal
ok 376 span.context.db
ok 377 span.context.service.target
ok 378 span.context.destination
# pool.query(options-with-values)
ok 379 no currentSpan in sync code after pg .query
ok 380 should be strictly equal
ok 381 should be strictly equal
ok 382 should be strictly equal
ok 383 should be strictly equal
ok 384 should be strictly equal
ok 385 should be strictly equal
ok 386 should be strictly equal
ok 387 should be strictly equal
ok 388 should be strictly equal
ok 389 span.context.db
ok 390 span.context.service.target
ok 391 span.context.destination
# simultaneous queries
# on same connection
ok 392 null
ok 393 should be strictly equal
ok 394 null
ok 395 should be strictly equal
ok 396 null
ok 397 should be strictly equal
ok 398 should be strictly equal
ok 399 should be strictly equal
ok 400 should be strictly equal
ok 401 should be strictly equal
ok 402 should be strictly equal
ok 403 should be strictly equal
ok 404 should be strictly equal
ok 405 span.context.db
ok 406 span.context.service.target
ok 407 span.context.destination
ok 408 each span is a child of the transaction
ok 409 should be strictly equal
ok 410 should be strictly equal
ok 411 should be strictly equal
ok 412 should be strictly equal
ok 413 span.context.db
ok 414 span.context.service.target
ok 415 span.context.destination
ok 416 each span is a child of the transaction
ok 417 should be strictly equal
ok 418 should be strictly equal
ok 419 should be strictly equal
ok 420 should be strictly equal
ok 421 span.context.db
ok 422 span.context.service.target
ok 423 span.context.destination
ok 424 each span is a child of the transaction
# simultaneous transactions
ok 425 null
ok 426 should be strictly equal
ok 427 null
ok 428 should be strictly equal
ok 429 null
ok 430 should be strictly equal
ok 431 should be strictly equal
ok 432 should be strictly equal
ok 433 should be deeply equivalent
ok 434 transaction should have span
ok 435 should be strictly equal
ok 436 should be strictly equal
ok 437 should be strictly equal
ok 438 should be strictly equal
ok 439 span.context.db
ok 440 span.context.service.target
ok 441 span.context.destination
ok 442 the span is a child of the transaction
ok 443 transaction should have span
ok 444 should be strictly equal
ok 445 should be strictly equal
ok 446 should be strictly equal
ok 447 should be strictly equal
ok 448 span.context.db
ok 449 span.context.service.target
ok 450 span.context.destination
ok 451 the span is a child of the transaction
ok 452 transaction should have span
ok 453 should be strictly equal
ok 454 should be strictly equal
ok 455 should be strictly equal
ok 456 should be strictly equal
ok 457 span.context.db
ok 458 span.context.service.target
ok 459 span.context.destination
ok 460 the span is a child of the transaction
# simultaneous queries on different connections
ok 461 undefined
ok 462 undefined
ok 463 undefined
ok 464 null
ok 465 should be strictly equal
ok 466 null
ok 467 should be strictly equal
ok 468 null
ok 469 should be strictly equal
ok 470 should be strictly equal
ok 471 should be strictly equal
ok 472 should be strictly equal
ok 473 should be strictly equal
ok 474 should be strictly equal
ok 475 should be strictly equal
ok 476 should be strictly equal
ok 477 span.context.db
ok 478 span.context.service.target
ok 479 span.context.destination
not ok 480 each span is a child of the transaction
---
operator: equal
expected: '25dfccf95a762376'
actual: '7bf8e0ee911fb97e'
at: (/Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9)
stack: |-
Error: each span is a child of the transaction
at Test.assert [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:312:48)
at Test.bound [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at Test.strictEqual (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:476:7)
at Test.bound [as equal] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9
at Array.forEach ()
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:403:16
at Object._write (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:46:50)
at Object.sendSpan (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:50:12)
at /Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/index.js:519:28
at done (/Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/span.js:486:5)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
...
ok 481 should be strictly equal
ok 482 should be strictly equal
ok 483 should be strictly equal
ok 484 should be strictly equal
ok 485 span.context.db
ok 486 span.context.service.target
ok 487 span.context.destination
not ok 488 each span is a child of the transaction
---
operator: equal
expected: '25dfccf95a762376'
actual: '7bf8e0ee911fb97e'
at: (/Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9)
stack: |-
Error: each span is a child of the transaction
at Test.assert [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:312:48)
at Test.bound [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at Test.strictEqual (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:476:7)
at Test.bound [as equal] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9
at Array.forEach ()
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:403:16
at Object._write (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:46:50)
at Object.sendSpan (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:50:12)
at /Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/index.js:519:28
at done (/Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/span.js:486:5)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
...
ok 489 should be strictly equal
ok 490 should be strictly equal
ok 491 should be strictly equal
ok 492 should be strictly equal
ok 493 span.context.db
ok 494 span.context.service.target
ok 495 span.context.destination
not ok 496 each span is a child of the transaction
---
operator: equal
expected: '25dfccf95a762376'
actual: '7bf8e0ee911fb97e'
at: (/Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9)
stack: |-
Error: each span is a child of the transaction
at Test.assert [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:312:48)
at Test.bound [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at Test.strictEqual (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:476:7)
at Test.bound [as equal] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:405:9
at Array.forEach ()
at /Users/trentm/el/apm-agent-nodejs4/test/instrumentation/modules/pg/pg.test.js:403:16
at Object._write (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:46:50)
at Object.sendSpan (/Users/trentm/el/apm-agent-nodejs4/test/_mock_http_client.js:50:12)
at /Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/index.js:519:28
at done (/Users/trentm/el/apm-agent-nodejs4/lib/instrumentation/span.js:486:5)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
...
# connection.release()
ok 497 undefined
ok 498 undefined
ok 499 no currentSpan in sync code after pg .query
ok 500 no currentSpan in pg .query callback
ok 501 null
ok 502 should be strictly equal
not ok 503 test exited without ending: connection.release()
---
operator: fail
at: process. (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/index.js:165:8)
stack: |-
Error: test exited without ending: connection.release()
at Test.assert [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:312:48)
at Test.bound [as _assert] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at Test.fail (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:406:7)
at Test.bound [as fail] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at Test._exit (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:269:8)
at Test.bound [as _exit] (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/lib/test.js:95:17)
at process. (/Users/trentm/el/apm-agent-nodejs4/node_modules/tape/index.js:165:8)
at process.emit (node:events:513:28)
at process.callbackTrampoline (node:internal/async_hooks:130:17)
...
1..503
# tests 503
# pass 499
# fail 4
```
Contributor guide
Assessment
This issue has not been assessed yet.