aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
270 stars 155 forks source link

`aws-xray-sdk-postgres` does not work with `pg-copy-streams` #478

Open paya-cz opened 2 years ago

paya-cz commented 2 years ago

I use pg-copy-streams to stream CSV to a table, just like in the STDIN example. XRay-instrumented pg.Client will crash when used with pg-copy-streams:


type: TypeError message: cb is not a function

stack: TypeError: cb is not a function at Query.args.callback (/app/node_modules/aws-xray-sdk-postgres/lib/postgres_p.js:88:9) at Query.handleReadyForQuery (/app/node_modules/pg/lib/query.js:138:12) at Client._handleReadyForQuery (/app/node_modules/pg/lib/client.js:290:19) at Connection.emit (events.js:400:28) at /app/node_modules/pg/lib/connection.js:114:12 at Parser.parse (/app/node_modules/pg-protocol/src/parser.ts:104:9) at TLSSocket. (/app/node_modules/pg-protocol/src/index.ts:7:48) at TLSSocket.emit (events.js:400:28) at addChunk (internal/streams/readable.js:293:12) at readableAddChunk (internal/streams/readable.js:267:9)"


aws-xray-sdk-core: v3.3.4 aws-xray-sdk-postgres: v3.3.4

willarmiros commented 2 years ago

Hi @paya-cz,

Thanks for raising this, seems like a small bug in our postgres patcher where we're not checking if it's a function here, if you're open to make a quick PR + unit test: https://github.com/aws/aws-xray-sdk-node/blob/58737b4bec258331ec7aba30cd3f006a19341315/packages/postgres/lib/postgres_p.js#L72

If you need an immediate alternative, I would recommend checking out the AWS Distro for OpenTelemetry JS, which supports instrumenting many more JS libraries than this SDK including Postgres, and it has first-class support for AWS X-Ray.