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

chore: add TAV tests for mongoose #3408

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .ci/tav.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"memcached",
"mongodb",
"mongodb-core",
"mongoose",
Copy link
Member

Choose a reason for hiding this comment

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

THis puts us at 34 * 7 = 238 combinations, so still under the 256 GH actions jobs limit. All good.

"mysql",
"mysql2",
"next",
Expand Down
21 changes: 21 additions & 0 deletions .tav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ mongodb:
node: '>=14.20.1'
commands: node test/instrumentation/modules/mongodb.test.js

# mongoose
# - v5 is still maintained (v5.13.14 on 2021-12-27). v5.7.0 switched from `mongodb-core`
# to `mongodb`. Testing we are not affected by the switch with a subset of 294 releases
# - v6 has 94 releases. Testing a subset
# - v7 was released recently (2023-02-27)
mongoose-5:
name: mongoose
versions: '5.0.0 || 5.3.2 || 5.5.10 || 5.9.2 || 5.11.2 || 5.13.14 || 5.13.17'
node: '>=4.0.0'
commands: node test/instrumentation/modules/mongoose.test.js
mongoose-6:
name: mongoose
versions: '6.0.0 || 6.1.2 || 6.2.9 || 6.4.5 || 6.7.1 || 6.10.4 || 6.11.1'
node: '>=12.0.0'
commands: node test/instrumentation/modules/mongoose.test.js
mongoose-7:
name: mongoose
versions: '7.0.0 || 7.0.4 || 7.1.0 || 7.1.2 || 7.2.1 || 7.2.2'
trentm marked this conversation as resolved.
Show resolved Hide resolved
node: '>=14.20.1'
commands: node test/instrumentation/modules/mongoose.test.js

# Bluebird is effectively deprecated (https://github.com/petkaantonov/bluebird#%EF%B8%8Fnote%EF%B8%8F).
# Testing the full set of supported bluebird releases (`>=2 <4`) is currently
# 119 releases. The last release was in 2019. Testing that many is a waste of
Expand Down
2 changes: 2 additions & 0 deletions dev-utils/gen-notice.sh
Copy link
Member

Choose a reason for hiding this comment

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

Now that mongoose is in devDeps, I think the change in this file can be dropped as well.

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ npm ls --omit=dev --all --parseable \
"measured-reporting": "license.node-measured.txt",
"object-identity-map": "license.MIT.txt",
"set-cookie-serde": "license.MIT.txt",
"sift": "license.MIT.txt",
"ip": "license.MIT.txt",
}
const allowNoLicFile = [
"binary-search" // CC is a public domain dedication, no need for license text.
Expand Down
1 change: 1 addition & 0 deletions docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ so those should be supported as well.
|https://www.npmjs.com/package/mongodb[mongodb] |>=3.3.0 <6 |Will instrument all queries
|https://www.npmjs.com/package/mongojs[mongojs] |>=1.0.0 <2.7.0 |Supported via mongodb-core
|https://www.npmjs.com/package/mongoose[mongoose] |>=4.0.0 <5.7.0 |Supported via mongodb-core
|https://www.npmjs.com/package/mongoose[mongoose] |>=5.7.0 <8 |Supported via mongodb
|https://www.npmjs.com/package/mysql[mysql] |^2.0.0 |Will instrument all queries
|https://www.npmjs.com/package/mysql2[mysql2] |>=1.0.0 <4.0.0 |Will instrument all queries
|https://www.npmjs.com/package/pg[pg] |>=4.0.0 <9.0.0 |Will instrument all queries
Expand Down
60 changes: 60 additions & 0 deletions examples/trace-mongoose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/

// A small example showing Elastic APM tracing the 'mongoose' package.
//
// This assumes a MongoDB server running on localhost. You can use:
// npm run docker:start mongodb
// to start a MongoDB docker container. Then `npm run docker:stop` to stop it.
//
// Some of the following code is adapted from
// https://github.com/Automattic/mongoose/tree/master/examples/statics

const apm = require('../').start({ // elastic-apm-node
serviceName: 'example-trace-mongoose',
logUncaughtExceptions: true
})

const mongoose = require('mongoose')

const DB_URL = 'mongodb://localhost:27017/example-trace-mongoose'

// Define a schema.
const PersonSchema = new mongoose.Schema({
name: String,
age: Number,
birthday: Date
})
mongoose.model('Person', PersonSchema)

async function run () {
// For tracing spans to be created, there must be an active transaction.
// Typically, a transaction is automatically started for incoming HTTP
// requests to a Node.js server. However, because this script is not running
// an HTTP server, we manually start a transaction. More details at:
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
const t1 = apm.startTransaction('t1')

const Person = mongoose.model('Person')
await mongoose.connect(DB_URL)

const bill = await Person.create({
name: 'bill',
age: 25,
birthday: new Date().setFullYear((new Date().getFullYear() - 25))
})
console.log('Person added to db: %s', bill)

const result = await Person.find({})
console.log('find result:', result)

// Cleanup.
await Person.deleteMany()
await mongoose.disconnect()
t1.end()
}

run()
Loading