Skip to content

Commit

Permalink
Add pipeline to Mongodb query (#5299)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Vandeputte <[email protected]>
  • Loading branch information
tlhunter and vdpjulien authored Feb 19, 2025
1 parent 34d89b1 commit b27a955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/datadog-plugin-mongodb-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function getQuery (cmd) {
if (!cmd || typeof cmd !== 'object' || Array.isArray(cmd)) return
if (cmd.query) return sanitizeBigInt(limitDepth(cmd.query))
if (cmd.filter) return sanitizeBigInt(limitDepth(cmd.filter))
if (cmd.pipeline) return sanitizeBigInt(limitDepth(cmd.pipeline))
}

function getResource (plugin, ns, query, operationName) {
Expand Down
19 changes: 19 additions & 0 deletions packages/datadog-plugin-mongodb-core/test/mongodb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ describe('Plugin', () => {
}).toArray()
})

it('should log the aggregate pipeline in mongodb.query', done => {
agent
.use(traces => {
const span = traces[0][0]
const resource = 'aggregate test.$cmd'
const query = '[{"$match":{"_id":"1234"}},{"$project":{"_id":1}}]'

expect(span).to.have.property('resource', resource)
expect(span.meta).to.have.property('mongodb.query', query)
})
.then(done)
.catch(done)

collection.aggregate([
{ $match: { _id: '1234' } },
{ $project: { _id: 1 } }
]).toArray()
})

it('should use the toJSON method of objects if it exists', done => {
const id = '123456781234567812345678'

Expand Down

0 comments on commit b27a955

Please sign in to comment.