UNPKG

@datadog/browser-logs

Version:
53 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_REQUEST_ERROR_RESPONSE_LENGTH_LIMIT = void 0; exports.validateAndBuildLogsConfiguration = validateAndBuildLogsConfiguration; exports.validateAndBuildForwardOption = validateAndBuildForwardOption; exports.serializeLogsConfiguration = serializeLogsConfiguration; const browser_core_1 = require("@datadog/browser-core"); /** * arbitrary value, byte precision not needed */ exports.DEFAULT_REQUEST_ERROR_RESPONSE_LENGTH_LIMIT = 32 * browser_core_1.ONE_KIBI_BYTE; function validateAndBuildLogsConfiguration(initConfiguration, errorStack) { if (initConfiguration.usePciIntake === true && initConfiguration.site && initConfiguration.site !== 'datadoghq.com') { browser_core_1.display.warn('PCI compliance for Logs is only available for Datadog organizations in the US1 site. Default intake will be used.'); } const baseConfiguration = (0, browser_core_1.validateAndBuildConfiguration)(initConfiguration, errorStack); const forwardConsoleLogs = validateAndBuildForwardOption(initConfiguration.forwardConsoleLogs, (0, browser_core_1.objectValues)(browser_core_1.ConsoleApiName), 'Forward Console Logs'); const forwardReports = validateAndBuildForwardOption(initConfiguration.forwardReports, (0, browser_core_1.objectValues)(browser_core_1.RawReportType), 'Forward Reports'); if (!baseConfiguration || !forwardConsoleLogs || !forwardReports) { return; } if (initConfiguration.forwardErrorsToLogs && !forwardConsoleLogs.includes(browser_core_1.ConsoleApiName.error)) { forwardConsoleLogs.push(browser_core_1.ConsoleApiName.error); } return { forwardErrorsToLogs: initConfiguration.forwardErrorsToLogs !== false, forwardConsoleLogs, forwardReports, requestErrorResponseLengthLimit: exports.DEFAULT_REQUEST_ERROR_RESPONSE_LENGTH_LIMIT, ...baseConfiguration, }; } function validateAndBuildForwardOption(option, allowedValues, label) { if (option === undefined) { return []; } if (!(option === 'all' || (Array.isArray(option) && option.every((api) => allowedValues.includes(api))))) { browser_core_1.display.error(`${label} should be "all" or an array with allowed values "${allowedValues.join('", "')}"`); return; } return option === 'all' ? allowedValues : (0, browser_core_1.removeDuplicates)(option); } function serializeLogsConfiguration(configuration) { const baseSerializedInitConfiguration = (0, browser_core_1.serializeConfiguration)(configuration); return { forward_errors_to_logs: configuration.forwardErrorsToLogs, forward_console_logs: configuration.forwardConsoleLogs, forward_reports: configuration.forwardReports, use_pci_intake: configuration.usePciIntake, ...baseSerializedInitConfiguration, }; } //# sourceMappingURL=configuration.js.map