Skip to content
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

Mysql adding query values in instrumented mysql query #256

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 10 additions & 3 deletions lib/instrumentation/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var dbutils = require('../db/utils')
var properties = require('../util/properties')
var sqlString = require('sqlString')


module.exports = function initialize(agent, mysql, moduleName, shim) {
Expand Down Expand Up @@ -121,7 +122,7 @@ function wrapQueriable(shim, queriable, isPoolQuery) {
return true
}

function extractQueryArgs(shim, args) {
function extractQueryArgs(shim, args, queriable) {
var query = ''
var callback = null

Expand All @@ -137,6 +138,12 @@ function extractQueryArgs(shim, args) {
// Then determine the query values and callback parameters.
if (shim.isArray(args[1])) {
// query({opts|sql}, values, callback)
var conf = queriable.config
conf = (conf && conf.connectionConfig) || conf
try {
// populate the query with the values
query = sqlString.format(query, args[1], conf.stringifyObjects, conf.timezone)
} catch (ex) { }
callback = 2
} else {
// query({opts|sql}, callback)
Expand All @@ -151,7 +158,7 @@ function extractQueryArgs(shim, args) {

function describeQuery(shim, queryFn, fnName, args) {
shim.logger.trace('Recording query')
var extractedArgs = extractQueryArgs(shim, args)
var extractedArgs = extractQueryArgs(shim, args, this)

// Pull out instance attributes.
var parameters = getInstanceParameters(shim, this, extractedArgs.query)
Expand All @@ -173,7 +180,7 @@ function describeQuery(shim, queryFn, fnName, args) {

function describePoolQuery(shim, queryFn, fnName, args) {
shim.logger.trace('Recording pool query')
var extractedArgs = extractQueryArgs(shim, args)
var extractedArgs = extractQueryArgs(shim, args, this)
return {
stream: true,
query: null,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"https-proxy-agent": "^0.3.5",
"json-stringify-safe": "^5.0.0",
"readable-stream": "^2.1.4",
"semver": "^5.3.0"
"semver": "^5.3.0",
"sqlstring": "^2.3.0"
},
"optionalDependencies": {
"@newrelic/native-metrics": "^2.1.0"
Expand Down
3 changes: 2 additions & 1 deletion test/unit/licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"https-proxy-agent": "MIT",
"json-stringify-safe": "ISC",
"readable-stream": "MIT",
"semver": "ISC"
"semver": "ISC",
"sqlstring": "MIT"
}