Skip to content

Commit aad593b

Browse files
authored
fix address tag for dns lookups with all option (DataDog#2031)
1 parent 9f10b95 commit aad593b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class DNSPlugin extends Plugin {
4444
this.enter(span, store)
4545
}, (result) => {
4646
const { span } = storage.getStore()
47-
span.setTag('dns.address', result)
47+
const address = Array.isArray(result) ? result[0].address : result
48+
span.setTag('dns.address', address)
4849
span.finish()
4950
})
5051

packages/datadog-plugin-dns/test/index.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ describe('Plugin', () => {
4141
dns.lookup('localhost', 4, (err, address, family) => err && done(err))
4242
})
4343

44+
it('should instrument lookup with all addresses', done => {
45+
const options = {
46+
family: 4,
47+
all: true
48+
}
49+
50+
agent
51+
.use(traces => {
52+
expect(traces[0][0]).to.deep.include({
53+
name: 'dns.lookup',
54+
service: 'test',
55+
resource: 'localhost'
56+
})
57+
expect(traces[0][0].meta).to.deep.include({
58+
'span.kind': 'client',
59+
'dns.hostname': 'localhost',
60+
'dns.address': '127.0.0.1'
61+
})
62+
})
63+
.then(done)
64+
.catch(done)
65+
66+
dns.lookup('localhost', options, (err, address, family) => err && done(err))
67+
})
68+
4469
it('should instrument errors correctly', done => {
4570
agent
4671
.use(traces => {

0 commit comments

Comments
 (0)