forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenario-withMysql2.js
53 lines (46 loc) · 1.39 KB
/
scenario-withMysql2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');
Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.knexIntegration()],
});
// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);
const knex = require('knex').default;
const mysql2Client = knex({
client: 'mysql2',
connection: {
host: 'localhost',
port: 3307,
user: 'root',
password: 'docker',
database: 'tests',
},
});
async function run() {
await Sentry.startSpan(
{
name: 'Test Transaction',
op: 'transaction',
},
async () => {
try {
await mysql2Client.schema.createTable('User', table => {
table.increments('id').notNullable().primary({ constraintName: 'User_pkey' });
table.timestamp('createdAt', { precision: 3 }).notNullable().defaultTo(mysql2Client.fn.now(3));
table.text('email').notNullable();
table.text('name').notNullable();
});
await mysql2Client('User').insert({ name: 'jane', email: '[email protected]' });
await mysql2Client('User').select('*');
} finally {
await mysql2Client.destroy();
}
},
);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();