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

[WIP] Instrument tedious MSSQL driver #277

Closed
wants to merge 16 commits into from
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
- cassandra
- postgresql
- rabbitmq
- docker
before_install:
- ./bin/travis-setup.sh
install: if [ "$SUITE" != "smoke" ]; then npm ci; fi
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ To run the tests you need an openssl command-line binary, and some services:
* Cassandra
* Memcached
* MongoDB
* MSSQL
* MySQL
* Postgres
* Redis
Expand Down
11 changes: 11 additions & 0 deletions bin/docker-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ if docker ps -a | grep -q "nr_node_rabbit"; then
else
docker run -d --name nr_node_rabbit -p 5672:5672 rabbitmq:3;
fi

if docker ps -a | grep -q "nr_node_mssql"; then
docker start nr_node_mssql;
else
docker run -d --name nr_node_mssql \
-e 'ACCEPT_EULA=Y' \
-e 'SA_PASSWORD=Passw0rd@123' \
-e 'MSSQL_PID=Developer' \
-p 1433:1433 \
mcr.microsoft.com/mssql/server:2017-latest-ubuntu
fi
7 changes: 7 additions & 0 deletions bin/travis-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ fi

# Always install time.
sudo apt-get install -qq time

docker run -d \
-e 'ACCEPT_EULA=Y' \
-e 'SA_PASSWORD=Passw0rd@123' \
-e 'MSSQL_PID=Developer' \
-p 1433:1433 \
mcr.microsoft.com/mssql/server:2017-latest-ubuntu
67 changes: 67 additions & 0 deletions lib/instrumentation/tedious.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'

function extractSqlFromTediousRequest(shim, original, name, args) {
var request = args[0]

if (request.parametersByName.statement && request.parametersByName.statement.value) {
return request.parametersByName.statement.value
}

return request.sqlTextOrProcedure
}

function bindSegmentRequestCallback(shim, opFunc, opName, segment, args) {
var request = args[0]

segment.addAttribute('port', this.config.options.port)
segment.addAttribute('server', this.config.server)

request.callback = shim.bindSegment(request.callback, segment)
}

module.exports = function initialize(agent, tedious, moduleName, shim) {
shim.setDatastore(shim.MSSQL)

var proto = tedious && tedious.Connection && tedious.Connection.prototype

if (!proto) {
return
}
var defaultSqlParser = shim.queryParser

shim.setParser(function queryParser(sql) {
var parsed = defaultSqlParser(sql)
if (parsed.operation === 'other') {
return {
operation: 'ExecuteProcedure',
query: sql,
collection: sql
}
}

return parsed
})
shim.recordQuery(proto, 'makeRequest', function recordMakeRequest() {
return {
callback: bindSegmentRequestCallback,
query: extractSqlFromTediousRequest
}
})

var transactionOperations = [
'commitTransaction',
'rollbackTransaction',
'saveTransaction',
'beginTransaction'
]

shim.recordOperation(proto, transactionOperations, {callback: shim.FIRST})
shim.recordOperation(proto, ['reset'], {callback: shim.FIRST})

var connectionOperations = [
'cancel',
'close'
]

shim.recordOperation(proto, connectionOperations)
}
1 change: 1 addition & 0 deletions lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function instrumentations() {
'redis': {type: MODULE_TYPE.DATASTORE},
'restify': {type: MODULE_TYPE.WEB_FRAMEWORK},
'superagent': {module: '@newrelic/superagent'},
'tedious': {type: MODULE_TYPE.DATASTORE},
'oracle': {type: null},
'vision': {type: MODULE_TYPE.WEB_FRAMEWORK},
'when': {type: null}
Expand Down
1 change: 1 addition & 0 deletions lib/shim/datastore-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DATASTORE_NAMES = {
DYNAMODB: 'DynamoDB',
MEMCACHED: 'Memcache',
MONGODB: 'MongoDB',
MSSQL: 'MSSQL',
MYSQL: 'MySQL',
NEPTUNE: 'Neptune',
POSTGRES: 'Postgres',
Expand Down
8 changes: 8 additions & 0 deletions lib/util/sql/obfuscate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ dialects.postgres = [
unmatchedPairs(/'|\/\*|\*\/|(?:\$(?!\?))/)
]

dialects.mssql = [
replacer(join(
[doubleQuote, singleQuote, comment, multilineComment, uuid, hex, boolean, number],
'gi'
)),
unmatchedPairs(/'|\/\*|\*\/|(?:\$(?!\?))/)
]

dialects.cassandra = [
replacer(join(
[singleQuote, comment, multilineComment, uuid, hex, boolean, number],
Expand Down
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"should": "*",
"sinon": "^4.5.0",
"tap": "^12.6.1",
"tedious": "^6.1.1",
"temp": "^0.8.1",
"through": "^2.3.6",
"when": "*"
Expand Down
Loading