From a879c7d73257131130f60ab69ea11983c6069e71 Mon Sep 17 00:00:00 2001 From: Ugaitz Urien Date: Thu, 28 Nov 2024 14:55:30 +0100 Subject: [PATCH] Fix original url instanceOf url.URL (#4955) --- packages/datadog-instrumentations/src/url.js | 4 ++++ packages/datadog-instrumentations/test/url.spec.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/datadog-instrumentations/src/url.js b/packages/datadog-instrumentations/src/url.js index 18edb0079e3..67bef7e8947 100644 --- a/packages/datadog-instrumentations/src/url.js +++ b/packages/datadog-instrumentations/src/url.js @@ -59,6 +59,10 @@ addHook({ name: names }, function (url) { isURL: true }) } + + static [Symbol.hasInstance] (instance) { + return instance instanceof URL + } } }) diff --git a/packages/datadog-instrumentations/test/url.spec.js b/packages/datadog-instrumentations/test/url.spec.js index defb8f08193..57b99e5f897 100644 --- a/packages/datadog-instrumentations/test/url.spec.js +++ b/packages/datadog-instrumentations/test/url.spec.js @@ -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'] @@ -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')