Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add connectSync method
add tests - not implementing anything too useful,
pretty much copied what existing mysql instrumentation did.
  • Loading branch information
Ryan Quinn committed Nov 3, 2014
commit d719aa6480045901261593d1fe9265f294fd8902
67 changes: 41 additions & 26 deletions lib/instrumentation/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,60 @@ function addSegment(tracer, sql) {
return tracer.addSegment(segmentName, ps.recordMetrics.bind(ps))
}


module.exports = function initialize(agent, oracle) {
var tracer = agent.tracer

shimmer.wrapMethod(oracle, 'Oracle', 'connect', function cb_wrapMethod(connect) {
function wrapExecute(execute) {
return tracer.segmentProxy(function cb_segmentProxy() {
var cb = arguments[1]
connect.call(this, arguments[0], function (err, connection) {
shimmer.wrapMethod(connection, 'Oracle', 'execute', function cb_wrapMethod(execute) {
return tracer.segmentProxy(function cb_segmentProxy() {
if (!tracer.getTransaction() || arguments.length < 1) {
logger.trace('not tracing because outside a transaction in oracle')
return execute.apply(this, arguments)
}

if (!tracer.getTransaction() || arguments.length < 1) {
logger.trace('not tracing because outside a transaction in oracle')
return execute.apply(this, arguments)
}
var transaction = tracer.getTransaction()
, segment = addSegment(tracer, arguments[0])
, args = tracer.slice(arguments)
, position = args.length - 1
, last = args[position]

var transaction = tracer.getTransaction()
, segment = addSegment(tracer, arguments[0])
, args = tracer.slice(arguments)
, position = args.length - 1
, last = args[position]
var end = function (err, response) {
segment.end()
logger.trace("oracle command trace segment ended by event for transaction %s.",
transaction.id)
return last(err, response)
}

var end = function (err, response) {
segment.end()
logger.trace("oracle command trace segment ended by event for transaction %s.",
transaction.id)
return last(err, response)
}
end = tracer.callbackProxy(end)

end = tracer.callbackProxy(end)
logger.trace("Adding oracle command trace segment transaction %s.",
transaction.id)
return execute.call(this, arguments[0], arguments[1], end)
});
}

logger.trace("Adding oracle command trace segment transaction %s.",
transaction.id)

return execute.call(this, arguments[0], arguments[1], end)
})
shimmer.wrapMethod(oracle, 'Oracle', 'connect', function cb_wrapMethod(connect) {
return tracer.segmentProxy(function cb_segmentProxy() {
var cb = arguments[1]
connect.call(this, arguments[0], function (err, connection) {
shimmer.wrapMethod(connection, 'Oracle', 'execute', function cb_wrapMethod(execute) {
return wrapExecute(execute)
})
cb(null, connection)
})
})
})

shimmer.wrapMethod(oracle, 'Oracle', 'connectSync', function cb_wrapMethod(connectSync) {
return tracer.segmentProxy(function cb_segmentProxy() {
var connection = connectSync.call(this, arguments[0]);
shimmer.wrapMethod(connection, 'Oracle', 'execute', function cb_wrapMethod(execute) {
return wrapExecute(execute)
})
return connection;
})
})


}

50 changes: 50 additions & 0 deletions test/unit/instrumentation/oracle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict'

var path = require('path')
, chai = require('chai')
, expect = chai.expect
, helper = require('../../lib/agent_helper')


describe("agent instrumentation of Oracle", function () {
describe("shouldn't cause bootstrapping to fail", function () {
var agent
, initialize


before(function () {
agent = helper.loadMockedAgent()
initialize = require('../../../lib/instrumentation/oracle')
})

after(function () {
helper.unloadAgent(agent)
})

it("when passed no module", function () {
expect(function () { initialize(agent); }).not.throws()
})

it("when passed an empty module", function () {
expect(function () { initialize(agent, {}); }).not.throws()
})
})

describe("for each operation", function () {
it("should update the global database aggregate statistics")
it("should also update the global web aggregate statistics")
it("should update the aggregate statistics for the operation type")
it("should update the aggregate statistics for the specific query")
it("should update the scoped aggregate statistics for the operation type")
})

describe("should instrument", function () {
it("INSERT")
it("SELECT")
it("UPDATE")
it("DELETE")
it("EXPLAIN")
it("ALTER TABLE")
it("DROP TABLE")
})
})