Skip to content
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: plugin-pg] Support Query config object again #3085

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/datadog-instrumentations/src/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function wrapQuery (query) {
const callbackResource = new AsyncResource('bound-anonymous-fn')
const asyncResource = new AsyncResource('bound-anonymous-fn')
const processId = this.processID
let pgQuery = {
text: arguments[0]
}
let pgQuery = typeof arguments[0] === 'object' ? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why clone the object instead of passing it as-is? It seems like before the regression it wasn't cloned.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, I don't totally understand why this was a mutable let in the first place or why we are overwriting this on line 57 from the queue (or what the queue is). It feels like an overloaded variable with two totally separate uses. So was trying to as closely preserve the original authors intent here. Feel free to update this though or take the findings and do something different with them too (there's an alternative approach I describe as well)! I'm not wedded to the specifics, was kind of just trying to show the specific issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a fix for this has actually landed in #3087

...arguments[0]
} : { text: arguments[0] }

return asyncResource.runInAsyncScope(() => {
startCh.publish({
Expand All @@ -41,7 +41,7 @@ function wrapQuery (query) {
processId
})

arguments[0] = pgQuery.text
arguments[0] = pgQuery

const finish = asyncResource.bind(function (error) {
if (error) {
Expand Down
20 changes: 20 additions & 0 deletions packages/datadog-plugin-pg/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ describe('Plugin', () => {
})
})

it('should send queries to agent when using query config of format', done => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('resource', `SELECT $1::text as message`)
done()
})

const query = {
text: 'SELECT $1::text as message',
values: ['test']
}

client.query(query, (err, result) => {
if (err) throw err

client.end((err) => {
if (err) throw err
})
})
})

if (semver.intersects(version, '>=5.1')) { // initial promise support
it('should do automatic instrumentation when using promises', done => {
agent.use(traces => {
Expand Down