@datadog/browser-core
Advanced tools
Comparing version 1.26.1 to 1.26.2
@@ -9,3 +9,2 @@ "use strict"; | ||
var utils_1 = require("../tools/utils"); | ||
var configuration_1 = require("./configuration"); | ||
var internalMonitoring_1 = require("./internalMonitoring"); | ||
@@ -100,3 +99,3 @@ var tracekit_1 = require("./tracekit"); | ||
function handleCompleteRequest(type, request) { | ||
if (!configuration_1.isIntakeRequest(request.url, configuration) && (isRejected(request) || isServerError(request))) { | ||
if (!configuration.isIntakeUrl(request.url) && (isRejected(request) || isServerError(request))) { | ||
errorObservable.notify({ | ||
@@ -103,0 +102,0 @@ message: format(type) + " error " + request.method + " " + request.url, |
@@ -48,2 +48,3 @@ import { BuildEnv, Datacenter } from '../boot/init'; | ||
version?: string; | ||
useAlternateIntakeDomains?: boolean; | ||
useCrossSiteSessionCookie?: boolean; | ||
@@ -67,2 +68,3 @@ useSecureSessionCookie?: boolean; | ||
isEnabled: (feature: string) => boolean; | ||
isIntakeUrl: (url: string) => boolean; | ||
replica?: ReplicaConfiguration; | ||
@@ -78,3 +80,2 @@ }; | ||
export declare function buildCookieOptions(userConfiguration: UserConfiguration): CookieOptions; | ||
export declare function isIntakeRequest(url: string, configuration: Configuration): boolean; | ||
export {}; |
@@ -6,3 +6,2 @@ "use strict"; | ||
var cookie_1 = require("../browser/cookie"); | ||
var urlPolyfill_1 = require("../tools/urlPolyfill"); | ||
var utils_1 = require("../tools/utils"); | ||
@@ -37,2 +36,14 @@ exports.DEFAULT_CONFIGURATION = { | ||
}; | ||
var ENDPOINTS = { | ||
alternate: { | ||
logs: 'logs', | ||
rum: 'rum', | ||
trace: 'trace', | ||
}, | ||
classic: { | ||
logs: 'browser', | ||
rum: 'rum', | ||
trace: 'public-trace', | ||
}, | ||
}; | ||
function buildConfiguration(userConfiguration, buildEnv) { | ||
@@ -53,7 +64,9 @@ var transportConfiguration = { | ||
: []; | ||
var intakeType = userConfiguration.useAlternateIntakeDomains ? 'alternate' : 'classic'; | ||
var intakeUrls = getIntakeUrls(intakeType, transportConfiguration, userConfiguration.replica !== undefined); | ||
var configuration = tslib_1.__assign({ cookieOptions: buildCookieOptions(userConfiguration), isEnabled: function (feature) { | ||
return utils_1.includes(enableExperimentalFeatures, feature); | ||
}, logsEndpoint: getEndpoint('browser', transportConfiguration), proxyHost: userConfiguration.proxyHost, rumEndpoint: getEndpoint('rum', transportConfiguration), service: userConfiguration.service, traceEndpoint: getEndpoint('public-trace', transportConfiguration) }, exports.DEFAULT_CONFIGURATION); | ||
}, logsEndpoint: getEndpoint(intakeType, 'logs', transportConfiguration), proxyHost: userConfiguration.proxyHost, rumEndpoint: getEndpoint(intakeType, 'rum', transportConfiguration), service: userConfiguration.service, traceEndpoint: getEndpoint(intakeType, 'trace', transportConfiguration), isIntakeUrl: function (url) { return intakeUrls.some(function (intakeUrl) { return url.indexOf(intakeUrl) === 0; }); } }, exports.DEFAULT_CONFIGURATION); | ||
if (userConfiguration.internalMonitoringApiKey) { | ||
configuration.internalMonitoringEndpoint = getEndpoint('browser', transportConfiguration, 'browser-agent-internal-monitoring'); | ||
configuration.internalMonitoringEndpoint = getEndpoint(intakeType, 'logs', transportConfiguration, 'browser-agent-internal-monitoring'); | ||
} | ||
@@ -82,5 +95,5 @@ if ('allowedTracingOrigins' in userConfiguration) { | ||
applicationId: userConfiguration.replica.applicationId, | ||
internalMonitoringEndpoint: getEndpoint('browser', replicaTransportConfiguration, 'browser-agent-internal-monitoring'), | ||
logsEndpoint: getEndpoint('browser', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint('rum', replicaTransportConfiguration), | ||
internalMonitoringEndpoint: getEndpoint(intakeType, 'logs', replicaTransportConfiguration, 'browser-agent-internal-monitoring'), | ||
logsEndpoint: getEndpoint(intakeType, 'logs', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint(intakeType, 'rum', replicaTransportConfiguration), | ||
}; | ||
@@ -102,3 +115,3 @@ } | ||
exports.buildCookieOptions = buildCookieOptions; | ||
function getEndpoint(type, conf, source) { | ||
function getEndpoint(intakeType, endpointType, conf, source) { | ||
var tags = "sdk_version:" + conf.sdkVersion + | ||
@@ -108,3 +121,3 @@ ("" + (conf.env ? ",env:" + conf.env : '')) + | ||
("" + (conf.version ? ",version:" + conf.version : '')); | ||
var datadogHost = type + "-http-intake.logs." + conf.site; | ||
var datadogHost = getHost(intakeType, endpointType, conf.site); | ||
var host = conf.proxyHost ? conf.proxyHost : datadogHost; | ||
@@ -116,14 +129,31 @@ var proxyParameter = conf.proxyHost ? "ddhost=" + datadogHost + "&" : ''; | ||
} | ||
function isIntakeRequest(url, configuration) { | ||
return (urlPolyfill_1.getPathName(url).indexOf('/v1/input/') !== -1 && | ||
(urlPolyfill_1.haveSameOrigin(url, configuration.logsEndpoint) || | ||
urlPolyfill_1.haveSameOrigin(url, configuration.rumEndpoint) || | ||
urlPolyfill_1.haveSameOrigin(url, configuration.traceEndpoint) || | ||
(!!configuration.internalMonitoringEndpoint && urlPolyfill_1.haveSameOrigin(url, configuration.internalMonitoringEndpoint)) || | ||
(!!configuration.replica && | ||
(urlPolyfill_1.haveSameOrigin(url, configuration.replica.logsEndpoint) || | ||
urlPolyfill_1.haveSameOrigin(url, configuration.replica.rumEndpoint) || | ||
urlPolyfill_1.haveSameOrigin(url, configuration.replica.internalMonitoringEndpoint))))); | ||
function getHost(intakeType, endpointType, site) { | ||
var endpoint = ENDPOINTS[intakeType][endpointType]; | ||
if (intakeType === 'classic') { | ||
return endpoint + "-http-intake.logs." + site; | ||
} | ||
var domainParts = site.split('.'); | ||
var extension = domainParts.pop(); | ||
var suffix = domainParts.join('-') + "." + extension; | ||
return endpoint + ".browser-intake-" + suffix; | ||
} | ||
exports.isIntakeRequest = isIntakeRequest; | ||
function getIntakeUrls(intakeType, conf, withReplica) { | ||
if (conf.proxyHost) { | ||
return ["https://" + conf.proxyHost + "/v1/input/"]; | ||
} | ||
var sites = [conf.site]; | ||
if (conf.buildMode === init_1.BuildMode.STAGING && withReplica) { | ||
sites.push(init_1.INTAKE_SITE[init_1.Datacenter.US]); | ||
} | ||
var urls = []; | ||
var endpointTypes = Object.keys(ENDPOINTS[intakeType]); | ||
for (var _i = 0, sites_1 = sites; _i < sites_1.length; _i++) { | ||
var site = sites_1[_i]; | ||
for (var _a = 0, endpointTypes_1 = endpointTypes; _a < endpointTypes_1.length; _a++) { | ||
var endpointType = endpointTypes_1[_a]; | ||
urls.push("https://" + getHost(intakeType, endpointType, site) + "/v1/input/"); | ||
} | ||
} | ||
return urls; | ||
} | ||
function mustUseSecureCookie(userConfiguration) { | ||
@@ -130,0 +160,0 @@ return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie; |
@@ -1,2 +0,2 @@ | ||
export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration, isIntakeRequest, buildCookieOptions, } from './domain/configuration'; | ||
export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration, buildCookieOptions } from './domain/configuration'; | ||
export { startAutomaticErrorCollection, ErrorObservable } from './domain/automaticErrorCollection'; | ||
@@ -3,0 +3,0 @@ export { computeStackTrace } from './domain/tracekit'; |
@@ -6,3 +6,2 @@ "use strict"; | ||
exports.DEFAULT_CONFIGURATION = configuration_1.DEFAULT_CONFIGURATION; | ||
exports.isIntakeRequest = configuration_1.isIntakeRequest; | ||
exports.buildCookieOptions = configuration_1.buildCookieOptions; | ||
@@ -9,0 +8,0 @@ var automaticErrorCollection_1 = require("./domain/automaticErrorCollection"); |
@@ -10,2 +10,11 @@ "use strict"; | ||
traceEndpoint: 'https://trace-intake.com/v1/input/abcde?foo=bar', | ||
isIntakeUrl: function (url) { | ||
var intakeUrls = [ | ||
'https://monitoring-intake.com/v1/input/', | ||
'https://logs-intake.com/v1/input/', | ||
'https://rum-intake.com/v1/input/', | ||
'https://trace-intake.com/v1/input/', | ||
]; | ||
return intakeUrls.some(function (intakeUrl) { return url.indexOf(intakeUrl) === 0; }); | ||
}, | ||
}; | ||
@@ -12,0 +21,0 @@ function isSafari() { |
@@ -7,3 +7,2 @@ import { __spreadArrays } from "tslib"; | ||
import { jsonStringify, ONE_MINUTE, RequestType } from '../tools/utils'; | ||
import { isIntakeRequest } from './configuration'; | ||
import { monitor } from './internalMonitoring'; | ||
@@ -92,3 +91,3 @@ import { computeStackTrace, report } from './tracekit'; | ||
function handleCompleteRequest(type, request) { | ||
if (!isIntakeRequest(request.url, configuration) && (isRejected(request) || isServerError(request))) { | ||
if (!configuration.isIntakeUrl(request.url) && (isRejected(request) || isServerError(request))) { | ||
errorObservable.notify({ | ||
@@ -95,0 +94,0 @@ message: format(type) + " error " + request.method + " " + request.url, |
@@ -48,2 +48,3 @@ import { BuildEnv, Datacenter } from '../boot/init'; | ||
version?: string; | ||
useAlternateIntakeDomains?: boolean; | ||
useCrossSiteSessionCookie?: boolean; | ||
@@ -67,2 +68,3 @@ useSecureSessionCookie?: boolean; | ||
isEnabled: (feature: string) => boolean; | ||
isIntakeUrl: (url: string) => boolean; | ||
replica?: ReplicaConfiguration; | ||
@@ -78,3 +80,2 @@ }; | ||
export declare function buildCookieOptions(userConfiguration: UserConfiguration): CookieOptions; | ||
export declare function isIntakeRequest(url: string, configuration: Configuration): boolean; | ||
export {}; |
import { __assign } from "tslib"; | ||
import { BuildMode, Datacenter, INTAKE_SITE } from '../boot/init'; | ||
import { getCurrentSite } from '../browser/cookie'; | ||
import { getPathName, haveSameOrigin } from '../tools/urlPolyfill'; | ||
import { includes, ONE_KILO_BYTE, ONE_SECOND } from '../tools/utils'; | ||
@@ -34,2 +33,14 @@ export var DEFAULT_CONFIGURATION = { | ||
}; | ||
var ENDPOINTS = { | ||
alternate: { | ||
logs: 'logs', | ||
rum: 'rum', | ||
trace: 'trace', | ||
}, | ||
classic: { | ||
logs: 'browser', | ||
rum: 'rum', | ||
trace: 'public-trace', | ||
}, | ||
}; | ||
export function buildConfiguration(userConfiguration, buildEnv) { | ||
@@ -50,7 +61,9 @@ var transportConfiguration = { | ||
: []; | ||
var intakeType = userConfiguration.useAlternateIntakeDomains ? 'alternate' : 'classic'; | ||
var intakeUrls = getIntakeUrls(intakeType, transportConfiguration, userConfiguration.replica !== undefined); | ||
var configuration = __assign({ cookieOptions: buildCookieOptions(userConfiguration), isEnabled: function (feature) { | ||
return includes(enableExperimentalFeatures, feature); | ||
}, logsEndpoint: getEndpoint('browser', transportConfiguration), proxyHost: userConfiguration.proxyHost, rumEndpoint: getEndpoint('rum', transportConfiguration), service: userConfiguration.service, traceEndpoint: getEndpoint('public-trace', transportConfiguration) }, DEFAULT_CONFIGURATION); | ||
}, logsEndpoint: getEndpoint(intakeType, 'logs', transportConfiguration), proxyHost: userConfiguration.proxyHost, rumEndpoint: getEndpoint(intakeType, 'rum', transportConfiguration), service: userConfiguration.service, traceEndpoint: getEndpoint(intakeType, 'trace', transportConfiguration), isIntakeUrl: function (url) { return intakeUrls.some(function (intakeUrl) { return url.indexOf(intakeUrl) === 0; }); } }, DEFAULT_CONFIGURATION); | ||
if (userConfiguration.internalMonitoringApiKey) { | ||
configuration.internalMonitoringEndpoint = getEndpoint('browser', transportConfiguration, 'browser-agent-internal-monitoring'); | ||
configuration.internalMonitoringEndpoint = getEndpoint(intakeType, 'logs', transportConfiguration, 'browser-agent-internal-monitoring'); | ||
} | ||
@@ -79,5 +92,5 @@ if ('allowedTracingOrigins' in userConfiguration) { | ||
applicationId: userConfiguration.replica.applicationId, | ||
internalMonitoringEndpoint: getEndpoint('browser', replicaTransportConfiguration, 'browser-agent-internal-monitoring'), | ||
logsEndpoint: getEndpoint('browser', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint('rum', replicaTransportConfiguration), | ||
internalMonitoringEndpoint: getEndpoint(intakeType, 'logs', replicaTransportConfiguration, 'browser-agent-internal-monitoring'), | ||
logsEndpoint: getEndpoint(intakeType, 'logs', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint(intakeType, 'rum', replicaTransportConfiguration), | ||
}; | ||
@@ -97,3 +110,3 @@ } | ||
} | ||
function getEndpoint(type, conf, source) { | ||
function getEndpoint(intakeType, endpointType, conf, source) { | ||
var tags = "sdk_version:" + conf.sdkVersion + | ||
@@ -103,3 +116,3 @@ ("" + (conf.env ? ",env:" + conf.env : '')) + | ||
("" + (conf.version ? ",version:" + conf.version : '')); | ||
var datadogHost = type + "-http-intake.logs." + conf.site; | ||
var datadogHost = getHost(intakeType, endpointType, conf.site); | ||
var host = conf.proxyHost ? conf.proxyHost : datadogHost; | ||
@@ -111,13 +124,31 @@ var proxyParameter = conf.proxyHost ? "ddhost=" + datadogHost + "&" : ''; | ||
} | ||
export function isIntakeRequest(url, configuration) { | ||
return (getPathName(url).indexOf('/v1/input/') !== -1 && | ||
(haveSameOrigin(url, configuration.logsEndpoint) || | ||
haveSameOrigin(url, configuration.rumEndpoint) || | ||
haveSameOrigin(url, configuration.traceEndpoint) || | ||
(!!configuration.internalMonitoringEndpoint && haveSameOrigin(url, configuration.internalMonitoringEndpoint)) || | ||
(!!configuration.replica && | ||
(haveSameOrigin(url, configuration.replica.logsEndpoint) || | ||
haveSameOrigin(url, configuration.replica.rumEndpoint) || | ||
haveSameOrigin(url, configuration.replica.internalMonitoringEndpoint))))); | ||
function getHost(intakeType, endpointType, site) { | ||
var endpoint = ENDPOINTS[intakeType][endpointType]; | ||
if (intakeType === 'classic') { | ||
return endpoint + "-http-intake.logs." + site; | ||
} | ||
var domainParts = site.split('.'); | ||
var extension = domainParts.pop(); | ||
var suffix = domainParts.join('-') + "." + extension; | ||
return endpoint + ".browser-intake-" + suffix; | ||
} | ||
function getIntakeUrls(intakeType, conf, withReplica) { | ||
if (conf.proxyHost) { | ||
return ["https://" + conf.proxyHost + "/v1/input/"]; | ||
} | ||
var sites = [conf.site]; | ||
if (conf.buildMode === BuildMode.STAGING && withReplica) { | ||
sites.push(INTAKE_SITE[Datacenter.US]); | ||
} | ||
var urls = []; | ||
var endpointTypes = Object.keys(ENDPOINTS[intakeType]); | ||
for (var _i = 0, sites_1 = sites; _i < sites_1.length; _i++) { | ||
var site = sites_1[_i]; | ||
for (var _a = 0, endpointTypes_1 = endpointTypes; _a < endpointTypes_1.length; _a++) { | ||
var endpointType = endpointTypes_1[_a]; | ||
urls.push("https://" + getHost(intakeType, endpointType, site) + "/v1/input/"); | ||
} | ||
} | ||
return urls; | ||
} | ||
function mustUseSecureCookie(userConfiguration) { | ||
@@ -124,0 +155,0 @@ return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie; |
@@ -1,2 +0,2 @@ | ||
export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration, isIntakeRequest, buildCookieOptions, } from './domain/configuration'; | ||
export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration, buildCookieOptions } from './domain/configuration'; | ||
export { startAutomaticErrorCollection, ErrorObservable } from './domain/automaticErrorCollection'; | ||
@@ -3,0 +3,0 @@ export { computeStackTrace } from './domain/tracekit'; |
@@ -1,2 +0,2 @@ | ||
export { DEFAULT_CONFIGURATION, isIntakeRequest, buildCookieOptions, } from './domain/configuration'; | ||
export { DEFAULT_CONFIGURATION, buildCookieOptions } from './domain/configuration'; | ||
export { startAutomaticErrorCollection } from './domain/automaticErrorCollection'; | ||
@@ -3,0 +3,0 @@ export { computeStackTrace } from './domain/tracekit'; |
@@ -8,2 +8,11 @@ import { __assign, __awaiter, __generator } from "tslib"; | ||
traceEndpoint: 'https://trace-intake.com/v1/input/abcde?foo=bar', | ||
isIntakeUrl: function (url) { | ||
var intakeUrls = [ | ||
'https://monitoring-intake.com/v1/input/', | ||
'https://logs-intake.com/v1/input/', | ||
'https://rum-intake.com/v1/input/', | ||
'https://trace-intake.com/v1/input/', | ||
]; | ||
return intakeUrls.some(function (intakeUrl) { return url.indexOf(intakeUrl) === 0; }); | ||
}, | ||
}; | ||
@@ -10,0 +19,0 @@ export function isSafari() { |
{ | ||
"name": "@datadog/browser-core", | ||
"version": "1.26.1", | ||
"version": "1.26.2", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,3 @@ "main": "cjs/index.js", | ||
}, | ||
"gitHead": "8647da50e87ae8f103ba7e5e5397dc95cf41eb6c" | ||
"gitHead": "973ea9cafa295be60787cdb4a02ee00425554fdd" | ||
} |
@@ -6,3 +6,3 @@ import { FetchCompleteContext, resetFetchProxy, startFetchProxy } from '../browser/fetchProxy' | ||
import { jsonStringify, ONE_MINUTE, RequestType } from '../tools/utils' | ||
import { Configuration, isIntakeRequest } from './configuration' | ||
import { Configuration } from './configuration' | ||
import { monitor } from './internalMonitoring' | ||
@@ -98,3 +98,3 @@ import { computeStackTrace, Handler, report, StackTrace } from './tracekit' | ||
function handleCompleteRequest(type: RequestType, request: XhrCompleteContext | FetchCompleteContext) { | ||
if (!isIntakeRequest(request.url, configuration) && (isRejected(request) || isServerError(request))) { | ||
if (!configuration.isIntakeUrl(request.url) && (isRejected(request) || isServerError(request))) { | ||
errorObservable.notify({ | ||
@@ -101,0 +101,0 @@ message: `${format(type)} error ${request.method} ${request.url}`, |
import { BuildEnv, BuildMode, Datacenter } from '../boot/init' | ||
import { buildConfiguration, isIntakeRequest } from './configuration' | ||
import { buildConfiguration } from './configuration' | ||
@@ -55,5 +55,5 @@ describe('configuration', () => { | ||
it('should replace endpoint host add set it as a query parameter', () => { | ||
const configuration = buildConfiguration({ clientToken, proxyHost: 'proxy.io' }, usEnv) | ||
const configuration = buildConfiguration({ clientToken, site: 'datadoghq.eu', proxyHost: 'proxy.io' }, usEnv) | ||
expect(configuration.rumEndpoint).toMatch(/^https:\/\/proxy\.io\//) | ||
expect(configuration.rumEndpoint).toContain('?ddhost=rum-http-intake.logs.datadoghq.com&') | ||
expect(configuration.rumEndpoint).toContain('?ddhost=rum-http-intake.logs.datadoghq.eu&') | ||
}) | ||
@@ -108,13 +108,35 @@ }) | ||
describe('isIntakeRequest', () => { | ||
describe('isIntakeUrl', () => { | ||
it('should not detect non intake request', () => { | ||
const configuration = buildConfiguration({ clientToken }, usEnv) | ||
expect(isIntakeRequest('https://www.foo.com', configuration)).toBe(false) | ||
expect(configuration.isIntakeUrl('https://www.foo.com')).toBe(false) | ||
}) | ||
it('should detect intake request', () => { | ||
it('should detect intake request for EU site', () => { | ||
const configuration = buildConfiguration({ clientToken, site: 'datadoghq.eu' }, usEnv) | ||
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.datadoghq.eu/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.datadoghq.eu/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://public-trace-http-intake.logs.datadoghq.eu/v1/input/xxx')).toBe(true) | ||
}) | ||
it('should detect intake request for US site', () => { | ||
const configuration = buildConfiguration({ clientToken }, usEnv) | ||
expect(isIntakeRequest('https://rum-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(isIntakeRequest('https://browser-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(isIntakeRequest('https://public-trace-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe( | ||
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://public-trace-http-intake.logs.datadoghq.com/v1/input/xxx')).toBe(true) | ||
}) | ||
it('should detect alternate intake domains for US site', () => { | ||
const configuration = buildConfiguration({ clientToken, useAlternateIntakeDomains: true }, usEnv) | ||
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://trace.browser-intake-datadoghq.com/v1/input/xxx')).toBe(true) | ||
}) | ||
it('should handle sites with subdomains and classic intake', () => { | ||
const configuration = buildConfiguration({ clientToken, site: 'us3.datadoghq.com' }, usEnv) | ||
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.us3.datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.us3.datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://public-trace-http-intake.logs.us3.datadoghq.com/v1/input/xxx')).toBe( | ||
true | ||
@@ -124,7 +146,22 @@ ) | ||
it('should handle sites with subdomains and alternate intake', () => { | ||
const configuration = buildConfiguration( | ||
{ clientToken, site: 'us3.datadoghq.com', useAlternateIntakeDomains: true }, | ||
usEnv | ||
) | ||
expect(configuration.isIntakeUrl('https://rum.browser-intake-us3-datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://logs.browser-intake-us3-datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://trace.browser-intake-us3-datadoghq.com/v1/input/xxx')).toBe(true) | ||
}) | ||
it('should detect proxy intake request', () => { | ||
let configuration = buildConfiguration({ clientToken, proxyHost: 'www.proxy.com' }, usEnv) | ||
expect(isIntakeRequest('https://www.proxy.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(configuration.isIntakeUrl('https://www.proxy.com/v1/input/xxx')).toBe(true) | ||
configuration = buildConfiguration( | ||
{ clientToken, proxyHost: 'www.proxy.com', useAlternateIntakeDomains: true }, | ||
usEnv | ||
) | ||
expect(configuration.isIntakeUrl('https://www.proxy.com/v1/input/xxx')).toBe(true) | ||
configuration = buildConfiguration({ clientToken, proxyHost: 'www.proxy.com/custom/path' }, usEnv) | ||
expect(isIntakeRequest('https://www.proxy.com/custom/path/v1/input/xxx', configuration)).toBe(true) | ||
expect(configuration.isIntakeUrl('https://www.proxy.com/custom/path/v1/input/xxx')).toBe(true) | ||
}) | ||
@@ -134,3 +171,3 @@ | ||
const configuration = buildConfiguration({ clientToken, proxyHost: 'www.proxy.com' }, usEnv) | ||
expect(isIntakeRequest('https://www.proxy.com/foo', configuration)).toBe(false) | ||
expect(configuration.isIntakeUrl('https://www.proxy.com/foo')).toBe(false) | ||
}) | ||
@@ -143,10 +180,23 @@ | ||
) | ||
expect(isIntakeRequest('https://rum-http-intake.logs.foo.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(isIntakeRequest('https://browser-http-intake.logs.foo.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(isIntakeRequest('https://public-trace-http-intake.logs.foo.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.foo.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.foo.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://public-trace-http-intake.logs.foo.com/v1/input/xxx')).toBe(true) | ||
expect(isIntakeRequest('https://rum-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(isIntakeRequest('https://browser-http-intake.logs.datadoghq.com/v1/input/xxx', configuration)).toBe(true) | ||
expect(configuration.isIntakeUrl('https://rum-http-intake.logs.datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://browser-http-intake.logs.datadoghq.com/v1/input/xxx')).toBe(true) | ||
}) | ||
it('should detect replica intake request with alternate intake domains', () => { | ||
const configuration = buildConfiguration( | ||
{ clientToken, site: 'foo.com', replica: { clientToken }, useAlternateIntakeDomains: true }, | ||
{ ...usEnv, buildMode: BuildMode.STAGING } | ||
) | ||
expect(configuration.isIntakeUrl('https://rum.browser-intake-foo.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://logs.browser-intake-foo.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://trace.browser-intake-foo.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.com/v1/input/xxx')).toBe(true) | ||
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.com/v1/input/xxx')).toBe(true) | ||
}) | ||
}) | ||
}) |
import { BuildEnv, BuildMode, Datacenter, INTAKE_SITE } from '../boot/init' | ||
import { CookieOptions, getCurrentSite } from '../browser/cookie' | ||
import { getPathName, haveSameOrigin } from '../tools/urlPolyfill' | ||
import { includes, ONE_KILO_BYTE, ONE_SECOND } from '../tools/utils' | ||
@@ -58,2 +57,3 @@ | ||
useAlternateIntakeDomains?: boolean | ||
useCrossSiteSessionCookie?: boolean | ||
@@ -83,2 +83,3 @@ useSecureSessionCookie?: boolean | ||
isEnabled: (feature: string) => boolean | ||
isIntakeUrl: (url: string) => boolean | ||
@@ -109,2 +110,17 @@ // only on staging build mode | ||
const ENDPOINTS = { | ||
alternate: { | ||
logs: 'logs', | ||
rum: 'rum', | ||
trace: 'trace', | ||
}, | ||
classic: { | ||
logs: 'browser', | ||
rum: 'rum', | ||
trace: 'public-trace', | ||
}, | ||
} | ||
type IntakeType = keyof typeof ENDPOINTS | ||
type EndpointType = keyof (typeof ENDPOINTS)[IntakeType] | ||
export function buildConfiguration(userConfiguration: UserConfiguration, buildEnv: BuildEnv): Configuration { | ||
@@ -127,2 +143,4 @@ const transportConfiguration: TransportConfiguration = { | ||
const intakeType: IntakeType = userConfiguration.useAlternateIntakeDomains ? 'alternate' : 'classic' | ||
const intakeUrls = getIntakeUrls(intakeType, transportConfiguration, userConfiguration.replica !== undefined) | ||
const configuration: Configuration = { | ||
@@ -133,7 +151,9 @@ cookieOptions: buildCookieOptions(userConfiguration), | ||
}, | ||
logsEndpoint: getEndpoint('browser', transportConfiguration), | ||
logsEndpoint: getEndpoint(intakeType, 'logs', transportConfiguration), | ||
proxyHost: userConfiguration.proxyHost, | ||
rumEndpoint: getEndpoint('rum', transportConfiguration), | ||
rumEndpoint: getEndpoint(intakeType, 'rum', transportConfiguration), | ||
service: userConfiguration.service, | ||
traceEndpoint: getEndpoint('public-trace', transportConfiguration), | ||
traceEndpoint: getEndpoint(intakeType, 'trace', transportConfiguration), | ||
isIntakeUrl: (url) => intakeUrls.some((intakeUrl) => url.indexOf(intakeUrl) === 0), | ||
...DEFAULT_CONFIGURATION, | ||
@@ -143,3 +163,4 @@ } | ||
configuration.internalMonitoringEndpoint = getEndpoint( | ||
'browser', | ||
intakeType, | ||
'logs', | ||
transportConfiguration, | ||
@@ -183,8 +204,9 @@ 'browser-agent-internal-monitoring' | ||
internalMonitoringEndpoint: getEndpoint( | ||
'browser', | ||
intakeType, | ||
'logs', | ||
replicaTransportConfiguration, | ||
'browser-agent-internal-monitoring' | ||
), | ||
logsEndpoint: getEndpoint('browser', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint('rum', replicaTransportConfiguration), | ||
logsEndpoint: getEndpoint(intakeType, 'logs', replicaTransportConfiguration), | ||
rumEndpoint: getEndpoint(intakeType, 'rum', replicaTransportConfiguration), | ||
} | ||
@@ -210,3 +232,8 @@ } | ||
function getEndpoint(type: string, conf: TransportConfiguration, source?: string) { | ||
function getEndpoint( | ||
intakeType: IntakeType, | ||
endpointType: EndpointType, | ||
conf: TransportConfiguration, | ||
source?: string | ||
) { | ||
const tags = | ||
@@ -217,3 +244,3 @@ `sdk_version:${conf.sdkVersion}` + | ||
`${conf.version ? `,version:${conf.version}` : ''}` | ||
const datadogHost = `${type}-http-intake.logs.${conf.site}` | ||
const datadogHost = getHost(intakeType, endpointType, conf.site) | ||
const host = conf.proxyHost ? conf.proxyHost : datadogHost | ||
@@ -227,18 +254,33 @@ const proxyParameter = conf.proxyHost ? `ddhost=${datadogHost}&` : '' | ||
export function isIntakeRequest(url: string, configuration: Configuration) { | ||
return ( | ||
getPathName(url).indexOf('/v1/input/') !== -1 && | ||
(haveSameOrigin(url, configuration.logsEndpoint) || | ||
haveSameOrigin(url, configuration.rumEndpoint) || | ||
haveSameOrigin(url, configuration.traceEndpoint) || | ||
(!!configuration.internalMonitoringEndpoint && haveSameOrigin(url, configuration.internalMonitoringEndpoint)) || | ||
(!!configuration.replica && | ||
(haveSameOrigin(url, configuration.replica.logsEndpoint) || | ||
haveSameOrigin(url, configuration.replica.rumEndpoint) || | ||
haveSameOrigin(url, configuration.replica.internalMonitoringEndpoint)))) | ||
) | ||
function getHost(intakeType: IntakeType, endpointType: EndpointType, site: string) { | ||
const endpoint = ENDPOINTS[intakeType][endpointType] | ||
if (intakeType === 'classic') { | ||
return `${endpoint}-http-intake.logs.${site}` | ||
} | ||
const domainParts = site.split('.') | ||
const extension = domainParts.pop() | ||
const suffix = `${domainParts.join('-')}.${extension}` | ||
return `${endpoint}.browser-intake-${suffix}` | ||
} | ||
function getIntakeUrls(intakeType: IntakeType, conf: TransportConfiguration, withReplica: boolean) { | ||
if (conf.proxyHost) { | ||
return [`https://${conf.proxyHost}/v1/input/`] | ||
} | ||
const sites = [conf.site] | ||
if (conf.buildMode === BuildMode.STAGING && withReplica) { | ||
sites.push(INTAKE_SITE[Datacenter.US]) | ||
} | ||
const urls = [] | ||
const endpointTypes = Object.keys(ENDPOINTS[intakeType]) as EndpointType[] | ||
for (const site of sites) { | ||
for (const endpointType of endpointTypes) { | ||
urls.push(`https://${getHost(intakeType, endpointType, site)}/v1/input/`) | ||
} | ||
} | ||
return urls | ||
} | ||
function mustUseSecureCookie(userConfiguration: UserConfiguration) { | ||
return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie | ||
} |
@@ -1,8 +0,2 @@ | ||
export { | ||
DEFAULT_CONFIGURATION, | ||
Configuration, | ||
UserConfiguration, | ||
isIntakeRequest, | ||
buildCookieOptions, | ||
} from './domain/configuration' | ||
export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration, buildCookieOptions } from './domain/configuration' | ||
export { startAutomaticErrorCollection, ErrorObservable } from './domain/automaticErrorCollection' | ||
@@ -9,0 +3,0 @@ export { computeStackTrace } from './domain/tracekit' |
@@ -9,2 +9,12 @@ import { Configuration } from '../domain/configuration' | ||
traceEndpoint: 'https://trace-intake.com/v1/input/abcde?foo=bar', | ||
isIntakeUrl: (url: string) => { | ||
const intakeUrls = [ | ||
'https://monitoring-intake.com/v1/input/', | ||
'https://logs-intake.com/v1/input/', | ||
'https://rum-intake.com/v1/input/', | ||
'https://trace-intake.com/v1/input/', | ||
] | ||
return intakeUrls.some((intakeUrl) => url.indexOf(intakeUrl) === 0) | ||
}, | ||
} | ||
@@ -11,0 +21,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
654082
13403