Created
April 26, 2013 12:03
-
-
Save dasher/5466975 to your computer and use it in GitHub Desktop.
Revisions
-
dasher created this gist
Apr 26, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ // Relic integration point /** * Create a transactional scope in which instrumentation that will only add * trace segments to existing transactions will funciton. * * @param Agent agent The agent whose tracer should be used to create the * transaction. * @param Function callback The function to be run within the transaction. */ var runInTransaction = function runInTransaction(agent, callback) { return agent.tracer.transactionProxy(function () { var transaction = agent.getTransaction(); callback(transaction); })(); } var Q = require("q"); var agent = require("newrelic"); var coinbase = "litecoin"; runInTransaction(agent, function transactionInScope(transaction) { var iTX = agent.getTransaction(); var trace = transaction.getTrace(); var measurement = transaction.measure('Blockchain/'+coinbase+'/block'); // Start a timer transaction.timer.begin(); console.log("transaction", transaction); // a work unit var delay = function (delay) { var d = Q.defer(); setTimeout( function() { // stupid timeout to cause a little lag console.log("metric", metric); var metric = transaction .metrics .getOrCreateMetric('Blockchain/'+coinbase+'/block'); console.log("metric",metric); var stats = measurement.stats; if (stats.callCount < 1) { console.log("!OK"); console.log("stats", stats); } d.resolve(); } , delay); return d.promise; }; // setup some work to track // simple promise based approach Q.when(delay(1000), function () { // stop the timer trace.root.timer.end(); console.log("finalTx", transaction); console.log("metrics", transaction.metrics); console.log("unscoped", transaction.metrics.unscoped); // trace first - it was started inside the tx trace.end(); transaction.end(); }).then( function(){ agent.stop(); } ); });