Skip to content

Instantly share code, notes, and snippets.

@kovetskiy
Created January 25, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovetskiy/af7d69475626ab5cb0a6282970c45e57 to your computer and use it in GitHub Desktop.
Save kovetskiy/af7d69475626ab5cb0a6282970c45e57 to your computer and use it in GitHub Desktop.
var apm = require('elastic-apm-node').start()
var http = require('http')
var process = require('process')
function sleep(time) {
var stop = new Date().getTime();
while(new Date().getTime() < stop + time) {
;
}
}
function serve(op) {
if (op == "error") {
throw new Error("oops, a test error!")
}
console.log("sleep", op)
sleep(parseInt(op))
}
http.createServer(function (req, res) {
apm.setTransactionName(req.method +' ' + req.url)
op = req.url.substr(1)
console.log(op)
try {
serve(op)
} catch (err) {
apm.captureError(err)
}
res.end()
}).listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment