From d44b7c84e56f37e433362fd09e6a436f5f70ef55 Mon Sep 17 00:00:00 2001 From: rochdev Date: Fri, 25 Oct 2019 16:48:29 -0400 Subject: [PATCH] fix tedious support now that exported classes are read-only --- packages/datadog-plugin-tedious/src/index.js | 38 ++++---------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/packages/datadog-plugin-tedious/src/index.js b/packages/datadog-plugin-tedious/src/index.js index 6b4a8927f3c..845ff456059 100644 --- a/packages/datadog-plugin-tedious/src/index.js +++ b/packages/datadog-plugin-tedious/src/index.js @@ -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) { @@ -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) } } ]