-
-
Save bobzoller/fb0502ee49a016b7b606 to your computer and use it in GitHub Desktop.
test case for new relic transaction issues w/node-fibers
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
exports.config = { | |
app_name : ['New Relic Hunter'], | |
license_key : 'abc', | |
logging : { | |
level : 'info' | |
} | |
}; |
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
{ | |
"name": "new-relic-hunter", | |
"version": "1.0.0", | |
"dependencies": { | |
"express": "*", | |
"fibers": "*", | |
"newrelic": "*" | |
} | |
} |
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
process.env.TZ = process.env.TZ || 'UTC'; | |
var agent = require('newrelic').agent; | |
var express = require('express'); | |
var Fiber = require('fibers'); | |
var Future = require('fibers/future'); | |
var api = Future.wrap(function(cb) { | |
return setTimeout(cb, 3000); | |
}); | |
var app = express(); | |
var fiberMiddleware = function(req, res, next) { | |
return Fiber(function() { | |
return next(); | |
}).run(); | |
}; | |
app.use(fiberMiddleware); | |
//app.all('/*', fiberMiddleware); | |
app.get('/one', function(req, res) { | |
var t; | |
console.log(req.method, req.url, (t = agent.getTransaction()) ? t.id : null); | |
api().wait(); | |
res.status(200).end(); | |
}); | |
app.get('/two', function(req, res) { | |
var t; | |
console.log(req.method, req.url, (t = agent.getTransaction()) ? t.id : null); | |
api().wait(); | |
res.status(200).end(); | |
}); | |
var server = app.listen(process.env.PORT || 3000, function(err) { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} else { | |
console.log('express server listening at http://%s:%s/', server.address().address, server.address().port); | |
} | |
}); |
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
#!/bin/sh | |
if [ "$PORT" == "" ]; then | |
PORT=3000 | |
fi | |
PORT=$PORT node server.js & | |
SERVER_PID=$! | |
sleep 5 | |
curl -sS http://localhost:$PORT/one & | |
CURL_PID_1=$! | |
sleep 1 | |
curl -sS http://localhost:$PORT/two & | |
CURL_PID_2=$! | |
wait $CURL_PID_1 $CURL_PID_2 | |
sleep 2 | |
kill $SERVER_PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment