-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): Add mysql
auto instrumentation tests for @sentry/node-experimental
#10255
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,12 @@ Sentry.init({ | |
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
debug: true, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
// Must be required after Sentry is initialized | ||
const { MongoClient } = require('mongodb'); | ||
|
||
|
@@ -40,8 +42,6 @@ async function run() { | |
} | ||
}, | ||
); | ||
|
||
Sentry.flush(2000); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node-experimental'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const mysql = require('mysql'); | ||
|
||
const connection = mysql.createConnection({ | ||
user: 'root', | ||
password: 'docker', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "docker" is used as [password](1).
|
||
}); | ||
|
||
connection.connect(function (err) { | ||
if (err) { | ||
return; | ||
} | ||
}); | ||
|
||
Sentry.startSpanManual( | ||
{ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}, | ||
span => { | ||
connection.query('SELECT 1 + 1 AS solution', function () { | ||
connection.query('SELECT NOW()', ['1', '2'], () => { | ||
span.end(); | ||
connection.end(); | ||
}); | ||
}); | ||
}, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node-experimental'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const mysql = require('mysql'); | ||
|
||
const connection = mysql.createConnection({ | ||
user: 'root', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "root" is used as [user name](1).
|
||
password: 'docker', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "docker" is used as [password](1).
|
||
}); | ||
|
||
connection.connect(function (err) { | ||
if (err) { | ||
return; | ||
} | ||
}); | ||
|
||
Sentry.startSpan( | ||
{ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}, | ||
span => { | ||
const query = connection.query('SELECT 1 + 1 AS solution'); | ||
const query2 = connection.query('SELECT NOW()', ['1', '2']); | ||
|
||
query.on('end', () => { | ||
query2.on('end', () => { | ||
// Wait a bit to ensure the queries completed | ||
setTimeout(() => { | ||
span.end(); | ||
}, 500); | ||
}); | ||
}); | ||
}, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node-experimental'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const mysql = require('mysql'); | ||
|
||
const connection = mysql.createConnection({ | ||
user: 'root', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "root" is used as [user name](1).
|
||
password: 'docker', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "docker" is used as [password](1).
|
||
}); | ||
|
||
Sentry.startSpanManual( | ||
{ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}, | ||
span => { | ||
connection.query('SELECT 1 + 1 AS solution', function () { | ||
connection.query('SELECT NOW()', ['1', '2'], () => { | ||
span.end(); | ||
connection.end(); | ||
}); | ||
}); | ||
}, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { createRunner } from '../../../utils/runner'; | ||
|
||
conditionalTest({ min: 14 })('mysql auto instrumentation', () => { | ||
test('should auto-instrument `mysql` package when using connection.connect()', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
expect.objectContaining({ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario-withConnect.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); | ||
|
||
test('should auto-instrument `mysql` package when using query without callback', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
expect.objectContaining({ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario-withoutCallback.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); | ||
|
||
test('should auto-instrument `mysql` package without connection.connect()', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
expect.objectContaining({ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'db.system': 'mysql', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 3306, | ||
'db.user': 'root', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario-withoutConnect.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); | ||
}); |
Check failure
Code scanning / CodeQL
Hard-coded credentials