Skip to content

Commit

Permalink
👷 Tweak query parameters for internal analytics (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan authored Jan 5, 2023
1 parent 0e419cb commit ac26b8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
22 changes: 13 additions & 9 deletions packages/core/src/domain/configuration/endpointBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit ac26b8d

Please sign in to comment.