-
-
Save trentm/147d46b4d1835375e79bdfd366c0b665 to your computer and use it in GitHub Desktop.
This file contains 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
const apm = require('./').start({ // elastic-apm-node | |
captureSpanStackTraces: false, | |
serviceName: 'play-mysql2-run-context', | |
// disableInstrumentations: 'mysql2,mysql', | |
// asyncHooks: false | |
}) | |
var t0, t1, t2 | |
// const mysql = require('mysql') | |
const mysql = require('mysql2') | |
t0 = apm.startTransaction('t0-connect') | |
const conn = mysql.createConnection({ user: 'root' }) | |
t1 = apm.startTransaction('t1-first-select') | |
conn.query('SELECT 1 + 1 AS solution', function (err, results) { | |
console.log('SELECT 1+1: err=%s results=%o %s', err, results, apm._instrumentation._runCtxMgr) | |
var s = apm.startSpan('s1'); if (s) s.end() // manual span | |
}) | |
t2 = apm.startTransaction('t2-second-select') | |
conn.query('SELECT 2 + 2 AS solution', function (err, results) { | |
console.log('SELECT 2+2: err=%s results=%o %s', err, results, apm._instrumentation._runCtxMgr) | |
var s = apm.startSpan('s2'); if (s) s.end() // manual span | |
}) | |
// Lazily shutdown after everything above is finished. | |
setTimeout(() => { | |
console.log('Done') | |
t2.end() | |
t1.end() | |
t0.end() | |
conn.end() | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment