Skip to content

Commit ec3f210

Browse files
authored
Fix original url instanceOf url.URL (#4955)
1 parent 2ad4cd0 commit ec3f210

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/datadog-instrumentations/src/url.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ addHook({ name: names }, function (url) {
5959
isURL: true
6060
})
6161
}
62+
63+
static [Symbol.hasInstance] (instance) {
64+
return instance instanceof URL
65+
}
6266
}
6367
})
6468

packages/datadog-instrumentations/test/url.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const agent = require('../../dd-trace/test/plugins/agent')
4+
const { assert } = require('chai')
45
const { channel } = require('../src/helpers/instrument')
56
const names = ['url', 'node:url']
67

@@ -68,6 +69,13 @@ names.forEach(name => {
6869
}, sinon.match.any)
6970
})
7071

72+
it('instanceof should work also for original instances', () => {
73+
const OriginalUrl = Object.getPrototypeOf(url.URL)
74+
const originalUrl = new OriginalUrl('https://www.datadoghq.com')
75+
76+
assert.isTrue(originalUrl instanceof url.URL)
77+
})
78+
7179
;['host', 'origin', 'hostname'].forEach(property => {
7280
it(`should publish on get ${property}`, () => {
7381
const urlObject = new url.URL('/path', 'https://www.datadoghq.com')

0 commit comments

Comments
 (0)