-
Notifications
You must be signed in to change notification settings - Fork 127
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
mysql2 probe #541
Open
realhidden
wants to merge
1
commit into
RuntimeTools:master
Choose a base branch
from
realhidden:mysql2-probe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
mysql2 probe #541
Changes from all commits
Commits
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,87 @@ | ||
/******************************************************************************* | ||
* Copyright 2015 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
'use strict'; | ||
var Probe = require('../lib/probe.js'); | ||
var aspect = require('../lib/aspect.js'); | ||
var request = require('../lib/request.js'); | ||
var util = require('util'); | ||
var am = require('../'); | ||
|
||
function MySql2Probe() { | ||
Probe.call(this, 'mysql2'); | ||
} | ||
util.inherits(MySql2Probe, Probe); | ||
|
||
MySql2Probe.prototype.attach = function(name, target) { | ||
var that = this; | ||
if (name != 'mysql2') return target; | ||
target.__ddProbeAttached__ = true; | ||
var data = {}; | ||
aspect.after(target, 'createConnection', data, function(target, methodName, args, probeData, rc) { | ||
aspect.before(rc, 'query', function(target, methodName, methodArgs, probeData) { | ||
var method = 'query'; | ||
that.metricsProbeStart(probeData, method, methodArgs); | ||
that.requestProbeStart(probeData, method, methodArgs); | ||
if (aspect.findCallbackArg(methodArgs) != undefined) { | ||
aspect.aroundCallback(methodArgs, probeData, function(target, args) { | ||
// Call the transaction link with a name and the callback for strong trace | ||
var callbackPosition = aspect.findCallbackArg(methodArgs); | ||
if (typeof callbackPosition != 'undefined') { | ||
aspect.strongTraceTransactionLink('mysql2: ', method, methodArgs[callbackPosition]); | ||
} | ||
|
||
that.metricsProbeEnd(probeData, method, methodArgs); | ||
that.requestProbeEnd(probeData, method, methodArgs); | ||
}); | ||
} | ||
}); | ||
return rc; | ||
}); | ||
return target; | ||
}; | ||
|
||
/* | ||
* Lightweight metrics probe for MySQL queries | ||
* | ||
* These provide: | ||
* time: time event started | ||
* query: The SQL executed | ||
* duration: the time for the request to respond | ||
*/ | ||
MySql2Probe.prototype.metricsEnd = function(probeData, method, methodArgs) { | ||
if (probeData && probeData.timer) { | ||
probeData.timer.stop(); | ||
var eventTimer = probeData.timer; | ||
am.emit('mysql', { | ||
time: eventTimer.startTimeMillis, | ||
query: JSON.stringify(methodArgs[0]), | ||
duration: eventTimer.timeDelta, | ||
}); | ||
} | ||
}; | ||
|
||
/* | ||
* Heavyweight request probes for MySQL queries | ||
*/ | ||
MySql2Probe.prototype.requestStart = function(probeData, method, methodArgs) { | ||
probeData.req = request.startRequest('mysql', 'query', false, probeData.timer); | ||
}; | ||
|
||
MySql2Probe.prototype.requestEnd = function(probeData, method, methodArgs) { | ||
if (probeData && probeData.req) probeData.req.stop({ sql: JSON.stringify(methodArgs[0]) }); | ||
}; | ||
|
||
module.exports = MySql2Probe; |
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.
If
mysql
andmysql2
have identical APIs, can this file not bemodule.exports = require('./mysql-probe');
? This might side-step test concerns, because it wouldn't introduce any new code.