-
-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
40 changes: 40 additions & 0 deletions
40
...packages/node-integration-tests/suites/tracing-experimental/mysql/withConnect/scenario.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
|
||
}); | ||
|
||
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(); | ||
}); | ||
}); | ||
}, | ||
); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing-experimental/mysql/withConnect/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createRunner } from '../../../../utils/runner'; | ||
|
||
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', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
test('should auto-instrument `mysql` package when using connection.connect()', done => { | ||
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...ages/node-integration-tests/suites/tracing-experimental/mysql/withoutCallback/scenario.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
|
||
password: 'docker', | ||
|
||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
}, | ||
); |
31 changes: 31 additions & 0 deletions
31
...packages/node-integration-tests/suites/tracing-experimental/mysql/withoutCallback/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createRunner } from '../../../../utils/runner'; | ||
|
||
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', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
test('should auto-instrument `mysql` package when using query without callback', done => { | ||
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...kages/node-integration-tests/suites/tracing-experimental/mysql/withoutConnect/scenario.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
|
||
password: 'docker', | ||
|
||
}); | ||
|
||
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(); | ||
}); | ||
}); | ||
}, | ||
); |
31 changes: 31 additions & 0 deletions
31
dev-packages/node-integration-tests/suites/tracing-experimental/mysql/withoutConnect/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createRunner } from '../../../../utils/runner'; | ||
|
||
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', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
test('should auto-instrument `mysql` package without connection.connect()', done => { | ||
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.