-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): Improve mysql integration #8923
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { assertSentryTransaction, TestEnv } from '../../../../../utils'; | ||
|
||
test('should auto-instrument `mysql` package when using connection.connect()', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
}, | ||
}, | ||
|
||
{ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
}, | ||
}, | ||
], | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import mysql from 'mysql'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], | ||
}); | ||
|
||
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).
|
||
}); | ||
|
||
const transaction = Sentry.startTransaction({ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
connection.query('SELECT 1 + 1 AS solution'); | ||
connection.query('SELECT NOW()', ['1', '2']); | ||
|
||
// Wait a bit to ensure the queries completed | ||
setTimeout(() => { | ||
transaction.finish(); | ||
}, 500); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { assertSentryTransaction, TestEnv } from '../../../../../utils'; | ||
|
||
test('should auto-instrument `mysql` package when using query without callback', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
}, | ||
}, | ||
|
||
{ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
}, | ||
}, | ||
], | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import mysql from 'mysql'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], | ||
}); | ||
|
||
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).
|
||
}); | ||
|
||
const transaction = Sentry.startTransaction({ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
connection.query('SELECT 1 + 1 AS solution', function () { | ||
connection.query('SELECT NOW()', ['1', '2'], () => { | ||
if (transaction) transaction.finish(); | ||
connection.end(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { assertSentryTransaction, TestEnv } from '../../../../utils'; | ||
import { assertSentryTransaction, TestEnv } from '../../../../../utils'; | ||
|
||
test('should auto-instrument `mysql` package.', async () => { | ||
test('should auto-instrument `mysql` package without connection.connect()', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
|
@@ -14,6 +14,9 @@ test('should auto-instrument `mysql` package.', async () => { | |
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to sanity-check (becaus afaict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, we do not :D |
||
}, | ||
}, | ||
|
||
|
@@ -22,6 +25,9 @@ test('should auto-instrument `mysql` package.', async () => { | |
op: 'db', | ||
data: { | ||
'db.system': 'mysql', | ||
'server.address': 'localhost', | ||
'server.port': 3306, | ||
'db.user': 'root', | ||
}, | ||
}, | ||
], | ||
|
Check failure
Code scanning / CodeQL
Hard-coded credentials