Skip to content

Commit 077e088

Browse files
committed
migrating tedious to use runStores
1 parent bd378cd commit 077e088

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

packages/datadog-instrumentations/src/tedious.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
const {
44
channel,
5-
addHook,
6-
AsyncResource
5+
addHook
76
} = require('./helpers/instrument')
87
const shimmer = require('../../datadog-shimmer')
98

@@ -22,30 +21,26 @@ addHook({ name: 'tedious', versions: ['>=1.0.0'] }, tedious => {
2221
return makeRequest.apply(this, arguments)
2322
}
2423

25-
const callbackResource = new AsyncResource('bound-anonymous-fn')
26-
const asyncResource = new AsyncResource('bound-anonymous-fn')
27-
2824
const connectionConfig = this.config
25+
const ctx = { queryOrProcedure, connectionConfig }
2926

30-
return asyncResource.runInAsyncScope(() => {
31-
const payload = { queryOrProcedure, connectionConfig }
32-
startCh.publish(payload)
33-
queryParent[queryField] = payload.sql
27+
return startCh.runStores(ctx, () => {
28+
queryParent[queryField] = ctx.sql
3429

35-
const cb = callbackResource.bind(request.callback, request)
36-
request.callback = asyncResource.bind(function (error) {
30+
const cb = request.callback
31+
request.callback = function (error, ...args) {
3732
if (error) {
38-
errorCh.publish(error)
33+
ctx.error = error
34+
errorCh.publish(ctx)
3935
}
40-
finishCh.publish(undefined)
41-
42-
return cb.apply(this, arguments)
43-
}, null, request)
36+
return finishCh.runStores(ctx, cb, this, error, ...args)
37+
}
4438

4539
try {
4640
return makeRequest.apply(this, arguments)
4741
} catch (error) {
48-
errorCh.publish(error)
42+
ctx.error = error
43+
errorCh.publish(ctx)
4944

5045
throw error
5146
}

packages/datadog-plugin-tedious/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TediousPlugin extends DatabasePlugin {
88
static get operation () { return 'request' } // TODO: change to match other database plugins
99
static get system () { return 'mssql' }
1010

11-
start (payload) {
11+
bindStart (payload) {
1212
const service = this.serviceName({ pluginConfig: this.config, system: this.system })
1313
const span = this.startSpan(this.operationName(), {
1414
service,
@@ -24,11 +24,12 @@ class TediousPlugin extends DatabasePlugin {
2424
'db.name': payload.connectionConfig.options.database,
2525
'db.instance': payload.connectionConfig.options.instanceName
2626
}
27-
})
27+
}, payload)
2828

2929
// SQL Server includes comments when caching queries
3030
// For that reason we allow service mode but not full mode
3131
payload.sql = this.injectDbmQuery(span, payload.queryOrProcedure, service, true)
32+
return payload.currentStore
3233
}
3334
}
3435

packages/dd-trace/src/plugins/storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class StoragePlugin extends ClientPlugin {
1111
this.system = this.constructor.system || this.component
1212
}
1313

14-
startSpan (name, options) {
14+
startSpan (name, options, ctx) {
1515
if (!options.service && this.system) {
1616
options.service = `${this.tracer._service}-${this.system}`
1717
}
1818

19-
return super.startSpan(name, options)
19+
return super.startSpan(name, options, ctx)
2020
}
2121
}
2222

0 commit comments

Comments
 (0)