Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 8 additions & 9 deletions packages/collector/src/announceCycle/unannounced.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ const {
secrets,
tracing,
util: { ensureNestedObjectExists },
coreConfig: { configNormalizers, configValidators }
coreConfig
} = require('@instana/core');

const { validateStackTraceMode, validateStackTraceLength } = configValidators.stackTraceValidation;

const { constants: tracingConstants } = tracing;

const agentConnection = require('../agentConnection');
Expand Down Expand Up @@ -274,7 +272,8 @@ function applyIgnoreEndpointsConfiguration(agentResponse) {
if (!ignoreEndpointsConfig) return;

ensureNestedObjectExists(agentOpts.config, ['tracing', 'ignoreEndpoints']);
agentOpts.config.tracing.ignoreEndpoints = configNormalizers.ignoreEndpoints.normalizeConfig(ignoreEndpointsConfig);
agentOpts.config.tracing.ignoreEndpoints =
coreConfig.configNormalizers.ignoreEndpoints.normalizeConfig(ignoreEndpointsConfig);
}

/**
Expand All @@ -289,9 +288,9 @@ function applyStackTraceConfiguration(agentResponse) {
ensureNestedObjectExists(agentOpts.config, ['tracing', 'global']);

if (globalConfig['stack-trace'] !== undefined) {
const stackTraceModeValidation = validateStackTraceMode(globalConfig['stack-trace']);
const stackTraceModeValidation = coreConfig.validate.validateStackTraceMode(globalConfig['stack-trace']);
if (stackTraceModeValidation.isValid) {
const normalizedStackTrace = configNormalizers.stackTrace.normalizeStackTraceModeFromAgent(
const normalizedStackTrace = coreConfig.configNormalizers.stackTrace.normalizeStackTraceModeFromAgent(
globalConfig['stack-trace']
);
if (normalizedStackTrace != null) {
Expand All @@ -303,9 +302,9 @@ function applyStackTraceConfiguration(agentResponse) {
}

if (globalConfig['stack-trace-length'] !== undefined) {
const stackTraceLengthValidation = validateStackTraceLength(globalConfig['stack-trace-length']);
const stackTraceLengthValidation = coreConfig.validate.validateStackTraceLength(globalConfig['stack-trace-length']);
if (stackTraceLengthValidation.isValid) {
const normalizedStackTraceLength = configNormalizers.stackTrace.normalizeStackTraceLengthFromAgent(
const normalizedStackTraceLength = coreConfig.configNormalizers.stackTrace.normalizeStackTraceLengthFromAgent(
globalConfig['stack-trace-length']
);
if (normalizedStackTraceLength != null) {
Expand All @@ -330,7 +329,7 @@ function applyDisableConfiguration(agentResponse) {
if (!disablingConfig) return;

ensureNestedObjectExists(agentOpts.config, ['tracing', 'disable']);
agentOpts.config.tracing.disable = configNormalizers.disable.normalizeExternalConfig({
agentOpts.config.tracing.disable = coreConfig.configNormalizers.disable.normalizeExternalConfig({
tracing: { disable: disablingConfig }
}).value;
}
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/config/configValidators/index.js

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions packages/core/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
'use strict';

const configNormalizers = require('./configNormalizers');
const configValidators = require('./configValidators');
const deepMerge = require('../util/deepMerge');
const { DEFAULT_STACK_TRACE_LENGTH, DEFAULT_STACK_TRACE_MODE, CONFIG_SOURCES } = require('../util/constants');
const { validateStackTraceMode, validateStackTraceLength } = require('./configValidators/stackTraceValidation');
const util = require('./util');
const validate = require('./validator');
const { validateStackTraceMode, validateStackTraceLength } = validate;

// @typedef {{ [x: string]: any }} configMeta
/** @type {configMeta} */
Expand Down Expand Up @@ -189,7 +188,7 @@ let defaults = {
const validSecretsMatcherModes = ['equals-ignore-case', 'equals', 'contains-ignore-case', 'contains', 'regex', 'none'];

module.exports.configNormalizers = configNormalizers;
module.exports.configValidators = configValidators;
module.exports.validate = validate;

/**
* @param {import('../core').GenericLogger} [_logger]
Expand Down
73 changes: 73 additions & 0 deletions packages/core/src/config/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

'use strict';

const { validStackTraceModes } = require('../util/constants');

/**
* @param {any} value
* @returns {number|undefined}
Expand Down Expand Up @@ -49,3 +51,74 @@ exports.validateTruthyBoolean = function validateTruthyBoolean(value) {
// Return true if value is truthy, undefined otherwise
return value ? true : undefined;
};

/**
* Validates the stack trace mode value.
*
* @param {*} value - The value to validate
* @returns {{ isValid: boolean, error: string | null }} - Validation result
*/
exports.validateStackTraceMode = function validateStackTraceMode(value) {
if (value === null) {
return { isValid: false, error: `The value cannot be null. Valid values are: ${validStackTraceModes.join(', ')}.` };
}

if (typeof value !== 'string') {
return {
isValid: false,
error: `The value has the non-supported type ${typeof value}. Valid values are: ${validStackTraceModes.join(
', '
)}.`
};
}

const normalizedValue = value.toLowerCase();
if (validStackTraceModes.includes(normalizedValue)) {
return { isValid: true, error: null };
}

return {
isValid: false,
error: `Invalid value: "${value}". Valid values are: ${validStackTraceModes.join(', ')}.`
};
};

/**
* Validates the stack trace length value.
*
* @param {*} value - The value to validate
* @returns {{ isValid: boolean, error: string | null }} - Validation result
*/
exports.validateStackTraceLength = function validateStackTraceLength(value) {
if (value == null) {
return { isValid: false, error: 'The value cannot be null' };
}

let parsedValue;

if (typeof value === 'number') {
parsedValue = value;
} else if (typeof value === 'string') {
parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
return {
isValid: false,
error: `The value ("${value}") cannot be parsed to a numerical value.`
};
}
} else {
return {
isValid: false,
error: `The value has the non-supported type ${typeof value}.`
};
}

if (!Number.isFinite(parsedValue)) {
return {
isValid: false,
error: `Invalid value: ${value}. Expected a number or numeric string.`
};
}

return { isValid: true, error: null };
};
Loading