Skip to content

Commit b0a3b4f

Browse files
wconti27BridgeAR
authored andcommitted
remove async storage from oracledb (#6217)
* remove async storage from oracledb
1 parent 70dd64b commit b0a3b4f

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

packages/datadog-instrumentations/src/oracledb.js

Lines changed: 39 additions & 33 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

@@ -14,11 +13,11 @@ const startChannel = channel('apm:oracledb:query:start')
1413
const errorChannel = channel('apm:oracledb:query:error')
1514
const finishChannel = channel('apm:oracledb:query:finish')
1615

17-
function finish (err) {
18-
if (err) {
19-
errorChannel.publish(err)
16+
function finish (ctx) {
17+
if (ctx.error) {
18+
errorChannel.publish(ctx)
2019
}
21-
finishChannel.publish()
20+
finishChannel.publish(ctx)
2221
}
2322

2423
addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
@@ -30,57 +29,64 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
3029

3130
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
3231
const cb = arguments[arguments.length - 1]
33-
const outerAr = new AsyncResource('apm:oracledb:outer-scope')
3432
arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function wrappedCb (err, result) {
35-
finish(err)
36-
return outerAr.runInAsyncScope(() => cb.apply(this, arguments))
33+
if (err) {
34+
ctx.error = err
35+
errorChannel.publish(ctx)
36+
}
37+
return finishChannel.runStores(ctx, () => {
38+
return cb.apply(this, arguments)
39+
})
3740
})
3841
}
3942

40-
return new AsyncResource('apm:oracledb:inner-scope').runInAsyncScope(() => {
41-
// The connAttrs are used to pass through the argument to the potential
42-
// serviceName method a user might have passed through as well as parsing
43-
// the connection string in v5.
44-
const connAttrs = connectionAttributes.get(this)
43+
// The connAttrs are used to pass through the argument to the potential
44+
// serviceName method a user might have passed through as well as parsing
45+
// the connection string in v5.
46+
const connAttrs = connectionAttributes.get(this)
4547

46-
const details = typeof this.hostName === 'string' ? this : this._impl
48+
const details = typeof this.hostName === 'string' ? this : this._impl
4749

48-
let hostname
49-
let port
50-
let dbInstance
50+
let hostname
51+
let port
52+
let dbInstance
5153

52-
if (details) {
53-
dbInstance = details.serviceName
54-
hostname = details.hostName ?? details.nscon?.ntAdapter?.hostName
55-
port = String(details.port ?? details.nscon?.ntAdapter?.port ?? '')
56-
}
54+
if (details) {
55+
dbInstance = details.serviceName
56+
hostname = details.hostName ?? details.nscon?.ntAdapter?.hostName
57+
port = String(details.port ?? details.nscon?.ntAdapter?.port ?? '')
58+
}
5759

58-
startChannel.publish({
59-
query: dbQuery,
60-
connAttrs,
61-
dbInstance,
62-
port,
63-
hostname,
64-
})
60+
const ctx = {
61+
dbInstance,
62+
port,
63+
hostname,
64+
query: dbQuery,
65+
connAttrs
66+
}
67+
68+
return startChannel.runStores(ctx, () => {
6569
try {
6670
let result = execute.apply(this, arguments)
6771

6872
if (typeof result?.then === 'function') {
6973
result = result.then(
7074
x => {
71-
finish()
75+
finish(ctx)
7276
return x
7377
},
7478
e => {
75-
finish(e)
79+
ctx.error = e
80+
finish(ctx)
7681
throw e
7782
}
7883
)
7984
}
8085

8186
return result
8287
} catch (err) {
83-
errorChannel.publish(err)
88+
ctx.error = err
89+
finish(ctx)
8490
throw err
8591
}
8692
})

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class OracledbPlugin extends DatabasePlugin {
1010
static system = 'oracle'
1111
static peerServicePrecursors = ['db.instance', 'db.hostname']
1212

13-
start ({ query, connAttrs, port, hostname, dbInstance }) {
13+
bindStart (ctx) {
14+
let { query, connAttrs, port, hostname, dbInstance } = ctx
15+
1416
const service = this.serviceName({ pluginConfig: this.config, params: connAttrs })
1517

1618
if (hostname === undefined) {
@@ -33,7 +35,9 @@ class OracledbPlugin extends DatabasePlugin {
3335
'db.hostname': hostname,
3436
[CLIENT_PORT_KEY]: port,
3537
}
36-
})
38+
}, ctx)
39+
40+
return ctx.currentStore
3741
}
3842
}
3943

0 commit comments

Comments
 (0)