Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 [RUMF-1089] Cleanup legacy intake URLs #1214

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export interface InitConfiguration {
env?: string | undefined
version?: string | undefined

useAlternateIntakeDomains?: boolean | undefined
intakeApiVersion?: 1 | 2 | undefined

useCrossSiteSessionCookie?: boolean | undefined
useSecureSessionCookie?: boolean | undefined
trackSessionAcrossSubdomains?: boolean | undefined
Expand Down
79 changes: 20 additions & 59 deletions packages/core/src/domain/configuration/endpointBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
import { BuildEnv } from '../../boot/init'
import { timeStampNow } from '../../tools/timeUtils'
import { generateUUID, includes } from '../../tools/utils'
import { generateUUID } from '../../tools/utils'
import { InitConfiguration } from './configuration'

export const ENDPOINTS = {
alternate: {
logs: 'logs',
rum: 'rum',
sessionReplay: 'session-replay',
},
classic: {
logs: 'browser',
rum: 'rum',
// session-replay has no classic endpoint
sessionReplay: undefined,
},
}
logs: 'logs',
rum: 'rum',
sessionReplay: 'session-replay',
} as const
Comment on lines +7 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we start to prepare the list of breaking changes with every v4 PR? something like what we did for v3 https://github.com/DataDog/browser-sdk/blob/main/CHANGELOG.md#v300

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do it in a following PR


const INTAKE_TRACKS = {
logs: 'logs',
rum: 'rum',
sessionReplay: 'replay',
}

export type EndpointType = keyof typeof ENDPOINTS[IntakeType]
type EndpointType = keyof typeof ENDPOINTS

export const INTAKE_SITE_US = 'datadoghq.com'
const INTAKE_SITE_US3 = 'us3.datadoghq.com'
const INTAKE_SITE_GOV = 'ddog-gov.com'
const INTAKE_SITE_EU = 'datadoghq.eu'

const CLASSIC_ALLOWED_SITES = [INTAKE_SITE_US, INTAKE_SITE_EU]
const INTAKE_V1_ALLOWED_SITES = [INTAKE_SITE_US, INTAKE_SITE_US3, INTAKE_SITE_EU, INTAKE_SITE_GOV]

type IntakeType = keyof typeof ENDPOINTS
export type EndpointBuilder = ReturnType<typeof createEndpointBuilder>

export function createEndpointBuilder(
Expand All @@ -43,17 +28,7 @@ export function createEndpointBuilder(
source?: string
) {
const sdkVersion = buildEnv.sdkVersion
const {
site = INTAKE_SITE_US,
clientToken,
env,
proxyHost,
proxyUrl,
service,
version,
intakeApiVersion,
useAlternateIntakeDomains,
} = initConfiguration
const { site = INTAKE_SITE_US, clientToken, env, proxyHost, proxyUrl, service, version } = initConfiguration

const host = buildHost(endpointType)
const path = buildPath(endpointType)
Expand All @@ -75,19 +50,15 @@ export function createEndpointBuilder(
}

function buildHost(endpointType: EndpointType) {
if (shouldUseAlternateDomain(endpointType)) {
const endpoint = ENDPOINTS.alternate[endpointType]
const domainParts = site.split('.')
const extension = domainParts.pop()
const suffix = `${domainParts.join('-')}.${extension!}`
return `${endpoint}.browser-intake-${suffix}`
}
const endpoint = ENDPOINTS.classic[endpointType]!
return `${endpoint}-http-intake.logs.${site}`
const endpoint = ENDPOINTS[endpointType]
const domainParts = site.split('.')
const extension = domainParts.pop()
const suffix = `${domainParts.join('-')}.${extension!}`
return `${endpoint}.browser-intake-${suffix}`
}

function buildPath(endpointType: EndpointType) {
return shouldUseIntakeV2(endpointType) ? `/api/v2/${INTAKE_TRACKS[endpointType]}` : `/v1/input/${clientToken}`
return `/api/v2/${INTAKE_TRACKS[endpointType]}`
}

function buildQueryParameters(endpointType: EndpointType, source?: string) {
Expand All @@ -97,15 +68,13 @@ export function createEndpointBuilder(
`${service ? `,service:${service}` : ''}` +
`${version ? `,version:${version}` : ''}`

let parameters = `ddsource=${source || 'browser'}&ddtags=${encodeURIComponent(tags)}`

if (shouldUseIntakeV2(endpointType)) {
parameters +=
`&dd-api-key=${clientToken}` +
`&dd-evp-origin-version=${encodeURIComponent(sdkVersion)}` +
`&dd-evp-origin=browser` +
`&dd-request-id=${generateUUID()}`
}
let parameters =
`ddsource=${source || 'browser'}` +
`&ddtags=${encodeURIComponent(tags)}` +
`&dd-api-key=${clientToken}` +
`&dd-evp-origin-version=${encodeURIComponent(sdkVersion)}` +
`&dd-evp-origin=browser` +
`&dd-request-id=${generateUUID()}`

if (endpointType === 'rum') {
parameters += `&batch_time=${timeStampNow()}`
Expand All @@ -114,14 +83,6 @@ export function createEndpointBuilder(
return parameters
}

function shouldUseIntakeV2(endpointType?: EndpointType): boolean {
return intakeApiVersion === 2 || !includes(INTAKE_V1_ALLOWED_SITES, site) || endpointType === 'sessionReplay'
}

function shouldUseAlternateDomain(endpointType?: EndpointType): boolean {
return useAlternateIntakeDomains || !includes(CLASSIC_ALLOWED_SITES, site) || endpointType === 'sessionReplay'
}

return {
build,
buildIntakeUrl,
Expand Down
Loading