Skip to content

Commit

Permalink
Add instrumentation for Q
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlavin committed Feb 10, 2016
1 parent 90762c3 commit efea1d5
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/instrumentation/q.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

var wrap = require('../shimmer').wrapMethod

module.exports = initialize

function initialize(agent, Q) {
if (Q.nextTick) {
wrap(Q, 'Q.nextTick', 'nextTick', function wrapUninstrumented(original, method) {
return agent.tracer.wrapFunctionFirstNoSegment(original, method)
})
}
}
1 change: 1 addition & 0 deletions lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function instrumentations() {
'node-cassandra-cql',
'cassandra-driver',
'pg',
'q',
'redis',
'restify',
'oracle'
Expand Down
79 changes: 79 additions & 0 deletions test/integration/instrumentation/q.tap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict'

var test = require('tap').test
var helper = require('../../lib/agent_helper')

function QContext(test, agent) {
this.agent = agent;
this.test = test;
}

QContext.prototype.assertTransaction = function assertTransaction(transaction) {
this.test.equal(this.agent.getTransaction(), transaction)
this.test.equal(this.agent.getTransaction().trace.root.children.length, 0)
}

test('Q.ninvoke', function testQNInvoke(t) {
var agent = setupAgent(t)
var Q = require('q')
var qContext = new QContext(t, agent)

var firstTest = Q.defer()
var secondTest = Q.defer()

helper.runInTransaction(agent, function transactionWrapper(transaction) {
Q.ninvoke(function anonymous() {
qContext.assertTransaction(transaction)
firstTest.resolve()
})
})

helper.runInTransaction(agent, function transactionWrapper(transaction) {
Q.ninvoke(function anonymous() {
qContext.assertTransaction(transaction)
secondTest.resolve()
})
})

Q.all([firstTest, secondTest])
.then(function done() {
t.end()
})
})

test('Q.then', function testQNInvoke(t) {
var agent = setupAgent(t)
var Q = require('q')
var qContext = new QContext(t, agent)

var firstTest = Q.defer()
var secondTest = Q.defer()

helper.runInTransaction(agent, function transactionWrapper(transaction) {
Q(true).then(function anonymous() {
qContext.assertTransaction(transaction)
firstTest.resolve()
})
})

helper.runInTransaction(agent, function transactionWrapper(transaction) {
Q(true).then(function anonymous() {
qContext.assertTransaction(transaction)
secondTest.resolve()
})
})

Q.all([firstTest, secondTest])
.then(function done() {
t.end()
})
})

function setupAgent(t) {
var agent = helper.instrumentMockedAgent()
t.tearDown(function tearDown() {
helper.unloadAgent(agent)
})

return agent
}

2 comments on commit efea1d5

@shadone
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch breaks Q in a major way. We have just hit this in our production server - after autoscaling and getting new EC2 instances (which automatically does npm install) we got the latest version of newrelic module 1.25.2, all hell broke loose after this.

   [ ESC[32m'TypeError: Q.nextTick.runAfter is not a function'ESC[39m,
     ESC[32m'    at trackRejection (/var/app/current/node_modules/q/q.js:1057:20)'ESC[39m,
     ESC[32m'    at reject (/var/app/current/node_modules/q/q.js:1131:5)'ESC[39m,
     ESC[32m'    at _fulfilled (/var/app/current/node_modules/q/q.js:836:20)'ESC[39m,
     ESC[32m'    at self.promiseDispatch.done (/var/app/current/node_modules/q/q.js:863:30)'ESC[39m,
     ESC[32m'    at Promise.promise.promiseDispatch (/var/app/current/node_modules/q/q.js:796:13)'ESC[39m,
     ESC[32m'    at /var/app/current/node_modules/q/q.js:604:44'ESC[39m,
     ESC[32m'    at runSingle (/var/app/current/node_modules/q/q.js:137:13)'ESC[39m,
     ESC[32m'    at flush (/var/app/current/node_modules/q/q.js:125:13)'ESC[39m,
     ESC[32m'    at doNTCallback0 (node.js:419:9)'ESC[39m,
     ESC[32m'    at process._tickDomainCallback [as _tickCallback] (node.js:389:13)'ESC[39m ] }

@lykkin
Copy link
Contributor

@lykkin lykkin commented on efea1d5 Feb 18, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.