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

fix tedious support now that exported classes are read-only #726

Merged
merged 1 commit into from
Oct 30, 2019
Merged
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
38 changes: 7 additions & 31 deletions packages/datadog-plugin-tedious/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ const tx = require('../../dd-trace/src/plugins/util/tx')

const procnameRegex = /^sp_[a-z]+$/

function createWrapRequestClass (tracer) {
return function wrapRequestClass (Request) {
class RequestWithTrace extends Request {
constructor (sqlTextOrProcedure, callback) {
super(sqlTextOrProcedure, callback)
tracer.scope().bind(this)
}
}

return RequestWithTrace
}
}

function createWrapConnectionClass (tracer) {
return function wrapConnectionClass (Connection) {
class ConnectionWithTrace extends Connection {
constructor (config) {
super(config)
tracer.scope().bind(this)
}
}

return ConnectionWithTrace
}
}

function createWrapMakeRequest (tracer, config) {
return function wrapMakeRequest (makeRequest) {
return function makeRequestWithTrace (request) {
Expand Down Expand Up @@ -113,22 +87,24 @@ module.exports = [
name: 'tedious',
versions: [ '>=1.0.0' ],
patch (tedious, tracer, config) {
this.wrap(tedious, 'Request', createWrapRequestClass(tracer))
this.wrap(tedious, 'Connection', createWrapConnectionClass(tracer))
this.wrap(tedious.Connection.prototype, 'makeRequest', createWrapMakeRequest(tracer, config))

if (tedious.BulkLoad && tedious.BulkLoad.prototype.getRowStream) {
this.wrap(tedious.BulkLoad.prototype, 'getRowStream', createWrapGetRowStream(tracer))
}

tracer.scope().bind(tedious.Request.prototype)
tracer.scope().bind(tedious.Connection.prototype)
},
unpatch (tedious) {
this.unwrap(tedious, 'Request')
this.unwrap(tedious, 'Connection')
unpatch (tedious, tracer) {
this.unwrap(tedious.Connection.prototype, 'makeRequest')

if (tedious.BulkLoad) {
this.unwrap(tedious.BulkLoad.prototype, 'getRowStream')
}

tracer.scope().unbind(tedious.Request.prototype)
tracer.scope().unbind(tedious.Connection.prototype)
}
}
]