From ac26b8db6da13a5df9d123d7f786075713bb545e Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:27:00 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Tweak=20query=20parameters=20for?= =?UTF-8?q?=20internal=20analytics=20(#1918)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/endpointBuilder.spec.ts | 8 +++++++ .../domain/configuration/endpointBuilder.ts | 22 +++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/core/src/domain/configuration/endpointBuilder.spec.ts b/packages/core/src/domain/configuration/endpointBuilder.spec.ts index a47463d3c6..3e9109423c 100644 --- a/packages/core/src/domain/configuration/endpointBuilder.spec.ts +++ b/packages/core/src/domain/configuration/endpointBuilder.spec.ts @@ -26,6 +26,14 @@ describe('endpointBuilder', () => { expect(createEndpointBuilder(initConfiguration, 'logs', []).build('xhr')).not.toContain('&batch_time=') expect(createEndpointBuilder(initConfiguration, 'sessionReplay', []).build('xhr')).not.toContain('&batch_time=') }) + + it('should not start with ddsource for internal analytics mode', () => { + const url = createEndpointBuilder({ ...initConfiguration, internalAnalyticsSubdomain: 'foo' }, 'rum', []).build( + 'xhr' + ) + expect(url).not.toContain('/rum?ddsource') + expect(url).toContain('ddsource=browser') + }) }) describe('proxyUrl', () => { diff --git a/packages/core/src/domain/configuration/endpointBuilder.ts b/packages/core/src/domain/configuration/endpointBuilder.ts index b40566231a..8445cacab2 100644 --- a/packages/core/src/domain/configuration/endpointBuilder.ts +++ b/packages/core/src/domain/configuration/endpointBuilder.ts @@ -41,18 +41,22 @@ export function createEndpointBuilder( if (retry) { tags.push(`retry_count:${retry.count}`, `retry_after:${retry.lastFailureStatus}`) } - let parameters = - 'ddsource=browser' + - `&ddtags=${encodeURIComponent(tags.join(','))}` + - `&dd-api-key=${clientToken}` + - `&dd-evp-origin-version=${encodeURIComponent(__BUILD_ENV__SDK_VERSION__)}` + - '&dd-evp-origin=browser' + - `&dd-request-id=${generateUUID()}` + const parameters = [ + 'ddsource=browser', + `ddtags=${encodeURIComponent(tags.join(','))}`, + `dd-api-key=${clientToken}`, + `dd-evp-origin-version=${encodeURIComponent(__BUILD_ENV__SDK_VERSION__)}`, + 'dd-evp-origin=browser', + `dd-request-id=${generateUUID()}`, + ] if (endpointType === 'rum') { - parameters += `&batch_time=${timeStampNow()}` + parameters.push(`batch_time=${timeStampNow()}`) } - const endpointUrl = `${baseUrl}?${parameters}` + if (initConfiguration.internalAnalyticsSubdomain) { + parameters.reverse() + } + const endpointUrl = `${baseUrl}?${parameters.join('&')}` return proxyUrl ? `${proxyUrl}?ddforward=${encodeURIComponent(endpointUrl)}` : endpointUrl },