|
| 1 | +const { loggingTransport } = require('@sentry-internal/node-integration-tests'); |
| 2 | +const Sentry = require('@sentry/node'); |
| 3 | + |
| 4 | +Sentry.init({ |
| 5 | + dsn: 'https://[email protected]/1337', |
| 6 | + release: '1.0', |
| 7 | + tracesSampleRate: 1.0, |
| 8 | + transport: loggingTransport, |
| 9 | +}); |
| 10 | + |
| 11 | +// Stop the process from exiting before the transaction is sent |
| 12 | +setInterval(() => {}, 1000); |
| 13 | + |
| 14 | +const mysql = require('mysql'); |
| 15 | +const genericPool = require('generic-pool'); |
| 16 | + |
| 17 | +const factory = { |
| 18 | + create: function () { |
| 19 | + return mysql.createConnection({ |
| 20 | + user: 'root', |
| 21 | + password: 'docker', |
| 22 | + }); |
| 23 | + }, |
| 24 | + destroy: function (client) { |
| 25 | + client.end(err => { |
| 26 | + if (err) { |
| 27 | + // eslint-disable-next-line no-console |
| 28 | + console.error('Error while disconnecting MySQL:', err); |
| 29 | + } |
| 30 | + }); |
| 31 | + }, |
| 32 | +}; |
| 33 | + |
| 34 | +const opts = { |
| 35 | + max: 10, |
| 36 | + min: 2, |
| 37 | +}; |
| 38 | + |
| 39 | +const myPool = genericPool.createPool(factory, opts); |
| 40 | + |
| 41 | +async function run() { |
| 42 | + await Sentry.startSpan( |
| 43 | + { |
| 44 | + op: 'transaction', |
| 45 | + name: 'Test Transaction', |
| 46 | + }, |
| 47 | + async () => { |
| 48 | + try { |
| 49 | + const client1 = await myPool.acquire(); |
| 50 | + const client2 = await myPool.acquire(); |
| 51 | + |
| 52 | + client1.query('SELECT NOW()', function () { |
| 53 | + myPool.release(client1); |
| 54 | + }); |
| 55 | + |
| 56 | + client2.query('SELECT 1 + 1 AS solution', function () { |
| 57 | + myPool.release(client2); |
| 58 | + }); |
| 59 | + } catch (err) { |
| 60 | + // eslint-disable-next-line no-console |
| 61 | + console.error('Error while pooling MySQL:', err); |
| 62 | + } finally { |
| 63 | + await myPool.drain(); |
| 64 | + await myPool.clear(); |
| 65 | + } |
| 66 | + }, |
| 67 | + ); |
| 68 | +} |
| 69 | + |
| 70 | +// eslint-disable-next-line @typescript-eslint/no-floating-promises |
| 71 | +run(); |
0 commit comments