Skip to content

Commit ad73ca2

Browse files
committed
remove spurious ARs from dns, converting to 4-event system
1 parent 4c2f8e9 commit ad73ca2

5 files changed

Lines changed: 29 additions & 25 deletions

File tree

packages/datadog-instrumentations/src/dns.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function patchResolveShorthands (prototype) {
4848

4949
function wrap (prefix, fn, expectedArgs, rrtype) {
5050
const startCh = channel(prefix + ':start')
51-
const finishCh = channel(prefix + ':finish')
51+
const asyncEndCh = channel(prefix + ':async_end')
52+
const endCh = channel(prefix + ':end')
5253
const errorCh = channel(prefix + ':error')
5354

5455
const wrapped = function () {
@@ -67,28 +68,31 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
6768
startArgs.push(rrtype)
6869
}
6970

70-
const asyncResource = new AsyncResource('bound-anonymous-fn')
71-
return asyncResource.runInAsyncScope(() => {
72-
startCh.publish(startArgs)
71+
const context = { args: startArgs }
72+
startCh.publish(context)
7373

74-
arguments[arguments.length - 1] = asyncResource.bind(function (error, result) {
75-
if (error) {
76-
errorCh.publish(error)
77-
}
78-
finishCh.publish(result)
79-
cb.apply(this, arguments)
80-
})
74+
arguments[arguments.length - 1] = function (error, result) {
75+
if (error) {
76+
context.error = error
77+
errorCh.publish(context)
78+
}
79+
context.result = result
80+
asyncEndCh.publish(context)
81+
cb.apply(this, arguments)
82+
}
8183

82-
try {
83-
return fn.apply(this, arguments)
84+
try {
85+
return fn.apply(this, arguments)
8486
// TODO deal with promise versions when we support `dns/promises`
85-
} catch (error) {
86-
error.stack // trigger getting the stack at the original throwing point
87-
errorCh.publish(error)
88-
89-
throw error
90-
}
91-
})
87+
} catch (error) {
88+
error.stack // trigger getting the stack at the original throwing point
89+
context.error = error
90+
errorCh.publish(context)
91+
92+
throw error
93+
} finally {
94+
endCh.publish(context)
95+
}
9296
}
9397

9498
return shimmer.wrap(fn, wrapped)

packages/datadog-plugin-dns/src/lookup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DNSLookupPlugin extends ClientPlugin {
66
static get name () { return 'dns' }
77
static get operation () { return 'lookup' }
88

9-
start ([hostname]) {
9+
start ({ args: [hostname] }) {
1010
this.startSpan('dns.lookup', {
1111
service: this.config.service,
1212
resource: hostname,
@@ -19,7 +19,7 @@ class DNSLookupPlugin extends ClientPlugin {
1919
})
2020
}
2121

22-
finish (result) {
22+
finish ({ result }) {
2323
const span = this.activeSpan
2424

2525
if (Array.isArray(result)) {

packages/datadog-plugin-dns/src/lookup_service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DNSLookupServicePlugin extends ClientPlugin {
66
static get name () { return 'dns' }
77
static get operation () { return 'lookup_service' }
88

9-
start ([address, port]) {
9+
start ({ args: [address, port] }) {
1010
this.startSpan('dns.lookup_service', {
1111
service: this.config.service,
1212
resource: `${address}:${port}`,

packages/datadog-plugin-dns/src/resolve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DNSResolvePlugin extends ClientPlugin {
66
static get name () { return 'dns' }
77
static get operation () { return 'resolve' }
88

9-
start ([hostname, maybeType]) {
9+
start ({ args: [hostname, maybeType] }) {
1010
const rrtype = typeof maybeType === 'string' ? maybeType : 'A'
1111

1212
this.startSpan('dns.resolve', {

packages/datadog-plugin-dns/src/reverse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class DNSReversePlugin extends ClientPlugin {
66
static get name () { return 'dns' }
77
static get operation () { return 'reverse' }
88

9-
start ([ip]) {
9+
start ({ args: [ip] }) {
1010
this.startSpan('dns.reverse', {
1111
service: this.config.service,
1212
resource: ip,

0 commit comments

Comments
 (0)