Skip to content

Commit

Permalink
Fix original url instanceOf url.URL (#4955)
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien authored Nov 28, 2024
1 parent 2ad4cd0 commit ec3f210
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/datadog-instrumentations/src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ addHook({ name: names }, function (url) {
isURL: true
})
}

static [Symbol.hasInstance] (instance) {
return instance instanceof URL
}
}
})

Expand Down
8 changes: 8 additions & 0 deletions packages/datadog-instrumentations/test/url.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

Expand Down Expand Up @@ -68,6 +69,13 @@ names.forEach(name => {
}, sinon.match.any)
})

it('instanceof should work also for original instances', () => {
const OriginalUrl = Object.getPrototypeOf(url.URL)
const originalUrl = new OriginalUrl('https://www.datadoghq.com')

assert.isTrue(originalUrl instanceof url.URL)
})

;['host', 'origin', 'hostname'].forEach(property => {
it(`should publish on get ${property}`, () => {
const urlObject = new url.URL('/path', 'https://www.datadoghq.com')
Expand Down

0 comments on commit ec3f210

Please sign in to comment.