-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add oracle instrumentation #182
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b23405
first hack at oracle instrumentation
d719aa6
add connectSync method
531ffee
add disclaimer about not instrumenting the reader
b7f3659
Merge tag 'v1.13.2'
6b2cfdc
integration tests for execute with connect and connectSync
387b46a
linting
da92a41
integration tests for reader methods
19ba629
Merge remote-tracking branch 'upstream/master'
2eb32d0
add prepared statement code and tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
'use strict' | ||
|
||
var logger = require('../logger').child({component: 'oracle'}) | ||
, shimmer = require('../shimmer') | ||
, parseSql = require('../db/parse-sql') | ||
, ORACLE = require('../metrics/names').ORACLE | ||
|
||
/** | ||
* | ||
* This instruments node-oracle's execute method. It doesn't instrument the reader portion of their api. | ||
* Since there is no reader.close method, it is unclear how to end the segment. It would make sense | ||
* to end it when the next row is null, signifying that the cursor has iterated all rows. | ||
* Other situations could occur, such as the client not iterating all of the rows, | ||
* which would end up in the segment never ending. | ||
* | ||
*/ | ||
|
||
|
||
function addSegment(tracer, sql) { | ||
var ps = parseSql(ORACLE.PREFIX, sql) | ||
var segmentName = ORACLE.STATEMENT + ps.model + '/' + ps.operation | ||
logger.trace({parsed: ps}, 'capturing oracle') | ||
|
||
return tracer.addSegment(segmentName, ps.recordMetrics.bind(ps)) | ||
} | ||
|
||
|
||
module.exports = function initialize(agent, oracle) { | ||
var tracer = agent.tracer | ||
|
||
function wrapExecute(connection) { | ||
shimmer.wrapMethod(connection, 'Oracle', 'execute', function cb_wrapMethod(execute) { | ||
return tracer.segmentProxy(function cb_segmentProxy(sql, params, cb) { | ||
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, sql) | ||
|
||
var end = function (err, response) { | ||
segment.end() | ||
logger.trace("oracle command trace segment ended by event for transaction %s.", | ||
transaction.id) | ||
return cb(err, response) | ||
} | ||
|
||
end = tracer.callbackProxy(end) | ||
|
||
logger.trace("Adding oracle command trace segment transaction %s.", | ||
transaction.id) | ||
return execute.call(this, sql, params, end) | ||
}) | ||
}) | ||
} | ||
|
||
function wrapReader(connection) { | ||
shimmer.wrapMethod(connection, 'Oracle', 'reader', function cb_wrapMethod(createReader) { | ||
return tracer.segmentProxy(function cb_segmentProxy(sql) { | ||
|
||
var reader = createReader.apply(this, arguments) | ||
if (!tracer.getTransaction() || arguments.length < 1) { | ||
return reader | ||
} | ||
|
||
var transaction = tracer.getTransaction() | ||
, segment = addSegment(tracer, sql) | ||
|
||
shimmer.wrapMethod(reader, 'Oracle', 'nextRow', function cb_wrapMethod(nextRow) { | ||
return tracer.segmentProxy(function cb_segmentProxy(cb) { | ||
if (!tracer.getTransaction() || arguments.length < 1) { | ||
logger.trace('not tracing because outside a transaction in oracle') | ||
return nextRow.apply(this, arguments) | ||
} | ||
|
||
var wrapped_cb = function (err, row) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
if (!row) { | ||
segment.end() | ||
logger.trace("oracle command trace segment ended by event for transaction %s.", | ||
transaction.id) | ||
return cb(err, row) | ||
} else { | ||
segment.touch() | ||
return cb(err, row) | ||
} | ||
} | ||
|
||
wrapped_cb = tracer.callbackProxy(wrapped_cb) | ||
|
||
logger.trace("Adding oracle command trace segment transaction %s.", | ||
transaction.id) | ||
return nextRow.call(this, wrapped_cb) | ||
|
||
}) | ||
}) | ||
|
||
shimmer.wrapMethod(reader, 'Oracle', 'nextRows', function cb_wrapMethod(nextRows) { | ||
return tracer.segmentProxy(function cb_segmentProxy(count, cb) { | ||
if (!tracer.getTransaction() || arguments.length < 1) { | ||
logger.trace('not tracing because outside a transaction in oracle') | ||
return nextRows.apply(this, arguments) | ||
} | ||
|
||
var wrapped_cb = function (err, rows) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
if (!rows || !rows.length) { | ||
segment.end() | ||
logger.trace("oracle command trace segment ended by event for transaction %s.", | ||
transaction.id) | ||
return cb(err, rows) | ||
} else { | ||
segment.touch() | ||
return cb(err, rows) | ||
} | ||
} | ||
|
||
wrapped_cb = tracer.callbackProxy(wrapped_cb) | ||
|
||
logger.trace("Adding oracle command trace segment transaction %s.", | ||
transaction.id) | ||
return nextRows.call(this, wrapped_cb) | ||
|
||
}) | ||
}) | ||
|
||
return reader | ||
|
||
}) | ||
}) | ||
} | ||
|
||
function wrapPrepare(connection) { | ||
shimmer.wrapMethod(connection, 'Oracle', 'prepare', function cb_wrapMethod(prepare) { | ||
|
||
return tracer.segmentProxy(function cb_segmentProxy(sql) { | ||
var prepared = prepare.call(this, sql) | ||
if (!tracer.getTransaction() || arguments.length < 1) { | ||
logger.trace('not tracing because outside a transaction in oracle') | ||
return prepare.call(this, sql) | ||
} | ||
|
||
var transaction = tracer.getTransaction() | ||
, segment = addSegment(tracer, sql) | ||
|
||
shimmer.wrapMethod(prepared, 'Oracle', 'execute', function cb_wrapMethod(execute) { | ||
|
||
return tracer.segmentProxy(function cb_segmentProxy(params, cb) { | ||
if (!tracer.getTransaction() || arguments.length < 1) { | ||
logger.trace('not tracing because outside a transaction in oracle') | ||
return execute.call(this, params, cb) | ||
} | ||
|
||
var wrapped_cb = function (err, response) { | ||
segment.end() | ||
logger.trace("oracle command trace segment ended by event for transaction %s.", | ||
transaction.id) | ||
return cb(err, response) | ||
} | ||
|
||
wrapped_cb = tracer.callbackProxy(wrapped_cb) | ||
|
||
return execute.call(this, params, wrapped_cb) | ||
}) | ||
}) | ||
|
||
logger.trace("Adding oracle command trace segment transaction %s.", | ||
transaction.id) | ||
return prepared | ||
}) | ||
}) | ||
} | ||
|
||
shimmer.wrapMethod(oracle, 'Oracle', 'connect', function cb_wrapMethod(connect) { | ||
return tracer.segmentProxy(function cb_segmentProxy(connectData, cb) { | ||
|
||
var end = function (err, connection) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
wrapExecute(connection) | ||
wrapReader(connection) | ||
wrapPrepare(connection) | ||
cb(null, connection) | ||
} | ||
|
||
end = tracer.callbackProxy(end) | ||
connect.call(this, connectData, end) | ||
}) | ||
}) | ||
|
||
shimmer.wrapMethod(oracle, 'Oracle', 'connectSync', function cb_wrapMethod(connectSync) { | ||
return tracer.segmentProxy(function cb_segmentProxy(connectionData) { | ||
var connection = connectSync.call(this, connectionData) | ||
wrapExecute(connection) | ||
wrapReader(connection) | ||
wrapPrepare(connection) | ||
return connection | ||
}) | ||
}) | ||
|
||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ module.exports = function() { | |
'pg', | ||
'redis', | ||
'restify', | ||
'oracle' | ||
] | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have had similar issues in our mongo instrumentation, I'll have to look into this a bit more, but it might be acceptable to have segments that are not guaranteed to have an end time, the concern would be leaking cursors, so this would only be possible if we can do it such a way that the segment can be gc'd when the client drops their ref to the cursor.