Skip to content
Draft
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
21 changes: 8 additions & 13 deletions packages/core/src/config/configNormalizers/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ exports.normalize = function normalize(config) {
try {
// Disable all tracing if explicitly set 'disable' to true
if (config.tracing.disable === true) {
logger?.info('Tracing has been disabled via "tracing.disable: true" configuration.');
logger?.debug('[config] config:tracing.disable = true');

return true;
}
const hasDisableConfig = isDisableConfigNonEmpty(config);

if (hasDisableConfig) {
logger?.info(
`Tracing selectively disabled as per "tracing.disable" configuration: ${JSON.stringify(config.tracing.disable)}`
);
logger?.debug(`[config] config:tracing.disable = ${JSON.stringify(config.tracing.disable)}`);
}

// Fallback to environment variables if `disable` is not explicitly configured
Expand Down Expand Up @@ -101,7 +100,7 @@ function getDisableFromEnv() {
const envVarValue = process.env.INSTANA_TRACING_DISABLE;

if (envVarValue === 'true') {
logger?.info('Tracing has been disabled via environment variable "INSTANA_TRACING_DISABLE=true".');
logger?.debug('[config] env:INSTANA_TRACING_DISABLE = true');
return true;
}

Expand All @@ -114,24 +113,20 @@ function getDisableFromEnv() {
disable.groups = categorized.groups;
}

logger?.info(`Tracing has been disabled via "INSTANA_TRACING_DISABLE=${envVarValue}"`);
logger?.debug(`[config] env:INSTANA_TRACING_DISABLE = ${envVarValue}`);
}
}

if (process.env.INSTANA_TRACING_DISABLE_INSTRUMENTATIONS) {
disable.instrumentations = parseEnvVar(process.env.INSTANA_TRACING_DISABLE_INSTRUMENTATIONS);
logger?.info(
`Tracing instrumentations disabled via "INSTANA_TRACING_DISABLE_INSTRUMENTATIONS": ${JSON.stringify(
disable.instrumentations
)}`
logger?.debug(
`[config] env:INSTANA_TRACING_DISABLE_INSTRUMENTATIONS = ${process.env.INSTANA_TRACING_DISABLE_INSTRUMENTATIONS}`
);
}

if (process.env.INSTANA_TRACING_DISABLE_GROUPS) {
disable.groups = parseEnvVar(process.env.INSTANA_TRACING_DISABLE_GROUPS);
logger?.info(
`Tracing instrumentation groups disabled via "INSTANA_TRACING_DISABLE_GROUPS": ${JSON.stringify(disable.groups)}`
);
logger?.debug(`[config] env:INSTANA_TRACING_DISABLE_GROUPS = ${process.env.INSTANA_TRACING_DISABLE_GROUPS}`);
}

return Object.keys(disable).length > 0 ? disable : null;
Expand Down
32 changes: 27 additions & 5 deletions packages/core/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ module.exports.normalize = (userConfig, defaultsOverride = {}) => {
function normalizeServiceName(config) {
if (config.serviceName == null && process.env.INSTANA_SERVICE_NAME) {
config.serviceName = process.env.INSTANA_SERVICE_NAME;
logger.debug(`[config] env:INSTANA_SERVICE_NAME = ${process.env.INSTANA_SERVICE_NAME}`);
} else if (config.serviceName != null && typeof config.serviceName === 'string') {
logger.debug(`[config] config:config.serviceName = ${config.serviceName}`);
}
if (config.serviceName != null && typeof config.serviceName !== 'string') {
logger.warn(
Expand All @@ -197,6 +200,9 @@ function normalizeServiceName(config) {
function normalizePackageJsonPath(config) {
if (config.packageJsonPath == null && process.env.INSTANA_PACKAGE_JSON_PATH) {
config.packageJsonPath = process.env.INSTANA_PACKAGE_JSON_PATH;
logger.debug(`[config] env:INSTANA_PACKAGE_JSON_PATH = ${process.env.INSTANA_PACKAGE_JSON_PATH}`);
} else if (config.packageJsonPath != null && typeof config.packageJsonPath === 'string') {
logger.debug(`[config] config:config.packageJsonPath = ${config.packageJsonPath}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about we use the prefix "incode"?

}
if (config.packageJsonPath != null && typeof config.packageJsonPath !== 'string') {
logger.warn(
Expand Down Expand Up @@ -295,7 +301,7 @@ function normalizeUseOpentelemetry(config) {
*/
function normalizeAutomaticTracingEnabled(config) {
if (!config.tracing.enabled) {
logger.info('Not enabling automatic tracing as tracing in general is explicitly disabled via config.');
logger.debug('Not enabling automatic tracing as tracing in general is explicitly disabled via config.');
config.tracing.automaticTracingEnabled = false;
return;
}
Expand Down Expand Up @@ -373,6 +379,9 @@ function normalizeTracingHttp(config) {
return;
} else if (!config.tracing.http.extraHttpHeadersToCapture && fromEnvVar) {
config.tracing.http.extraHttpHeadersToCapture = fromEnvVar;
logger.debug(`[config] env:INSTANA_EXTRA_HTTP_HEADERS = ${process.env.INSTANA_EXTRA_HTTP_HEADERS}`);
} else if (config.tracing.http.extraHttpHeadersToCapture) {
logger.debug('[config] config:config.tracing.http.extraHttpHeadersToCapture');
}
if (!Array.isArray(config.tracing.http.extraHttpHeadersToCapture)) {
logger.warn(
Expand Down Expand Up @@ -538,7 +547,8 @@ function normalizeDisableW3cTraceCorrelation(config) {
config.tracing.disableW3cTraceCorrelation = util.resolveBooleanConfigWithTruthyEnv({
envVar: 'INSTANA_DISABLE_W3C_TRACE_CORRELATION',
configValue: config.tracing.disableW3cTraceCorrelation,
defaultValue: defaults.tracing.disableW3cTraceCorrelation
defaultValue: defaults.tracing.disableW3cTraceCorrelation,
configPath: 'config.tracing.disableW3cTraceCorrelation'
});
}

Expand Down Expand Up @@ -574,6 +584,18 @@ function normalizeSecrets(config) {
fromEnvVar = parseSecretsEnvVar(process.env.INSTANA_SECRETS);
}

if (config.secrets.matcherMode) {
logger.debug(`[config] config:config.secrets.matcherMode = ${config.secrets.matcherMode}`);
} else if (fromEnvVar.matcherMode) {
logger.debug(`[config] env:INSTANA_SECRETS (matcherMode) = ${fromEnvVar.matcherMode}`);
}

if (config.secrets.keywords) {
logger.debug('[config] config:config.secrets.keywords');
} else if (fromEnvVar.keywords) {
logger.debug('[config] env:INSTANA_SECRETS (keywords)');
}

config.secrets.matcherMode = config.secrets.matcherMode || fromEnvVar.matcherMode || defaults.secrets.matcherMode;
config.secrets.keywords = config.secrets.keywords || fromEnvVar.keywords || defaults.secrets.keywords;

Expand Down Expand Up @@ -674,7 +696,7 @@ function normalizeIgnoreEndpoints(config) {
// Case 1: Use in-code configuration if available
if (Object.keys(ignoreEndpointsConfig).length) {
config.tracing.ignoreEndpoints = configNormalizers.ignoreEndpoints.normalizeConfig(ignoreEndpointsConfig);
logger.debug(`Ignore endpoints have been configured: ${JSON.stringify(config.tracing.ignoreEndpoints)}`);
logger.debug('[config] config:config.tracing.ignoreEndpoints');
return;
}

Expand All @@ -686,7 +708,7 @@ function normalizeIgnoreEndpoints(config) {
process.env.INSTANA_IGNORE_ENDPOINTS_PATH
);

logger.debug(`Ignore endpoints have been configured: ${JSON.stringify(config.tracing.ignoreEndpoints)}`);
logger.debug('[config] env:INSTANA_IGNORE_ENDPOINTS_PATH');
return;
}

Expand All @@ -695,7 +717,7 @@ function normalizeIgnoreEndpoints(config) {
// Provides a simple way to configure ignored operations via environment variables.
if (process.env.INSTANA_IGNORE_ENDPOINTS) {
config.tracing.ignoreEndpoints = configNormalizers.ignoreEndpoints.fromEnv(process.env.INSTANA_IGNORE_ENDPOINTS);
logger.debug(`Ignore endpoints have been configured: ${JSON.stringify(config.tracing.ignoreEndpoints)}`);
logger.debug('[config] env:INSTANA_IGNORE_ENDPOINTS');
}
}

Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/config/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports.resolveNumericConfig = function resolveNumericConfig({ envVar, configVal
if (envRaw != null) {
const envParsed = toValidNumber(envRaw);
if (envParsed !== undefined) {
logger.debug(`[config] env:${envVar} = ${envParsed}`);
return envParsed;
}

Expand All @@ -43,6 +44,7 @@ exports.resolveNumericConfig = function resolveNumericConfig({ envVar, configVal
if (configValue != null) {
const configParsed = toValidNumber(configValue);
if (configParsed !== undefined) {
logger.debug(`[config] config:${configPath} = ${configValue}`);
return configParsed;
}

Expand Down Expand Up @@ -84,6 +86,7 @@ function parseBooleanFromEnv(envValue) {
*/
exports.resolveBooleanConfig = function resolveBooleanConfig({ envVar, configValue, defaultValue, configPath }) {
if (typeof configValue === 'boolean') {
logger.debug(`[config] config:${configPath} = ${configValue}`);
return configValue;
}

Expand All @@ -99,6 +102,7 @@ exports.resolveBooleanConfig = function resolveBooleanConfig({ envVar, configVal
const envParsed = parseBooleanFromEnv(envValue);

if (envParsed !== undefined) {
logger.debug(`[config] env:${envVar} = ${envParsed}`);
return envParsed;
}

Expand Down Expand Up @@ -127,11 +131,14 @@ exports.resolveBooleanConfigWithInvertedEnv = function resolveBooleanConfigWithI
configPath
}) {
if (typeof configValue === 'boolean') {
logger.debug(`[config] config:${configPath} = ${configValue}`);

return configValue;
}

const envValue = process.env[envVar];
if (envValue === 'true') {
logger.debug(`[config] env:${envVar} = true (inverted to false)`);
return false;
}

Expand All @@ -154,19 +161,23 @@ exports.resolveBooleanConfigWithInvertedEnv = function resolveBooleanConfigWithI
* @param {string} params.envVar - Environment variable name
* @param {boolean|undefined|null} params.configValue - Config value
* @param {boolean} params.defaultValue - Default value
* @param {string} [params.configPath]
* @returns {boolean}
*/
exports.resolveBooleanConfigWithTruthyEnv = function resolveBooleanConfigWithTruthyEnv({
envVar,
configValue,
defaultValue
defaultValue,
configPath
}) {
if (typeof configValue === 'boolean') {
logger.debug(`[config] config:${configPath} = ${configValue}`);
return configValue;
}

const envValue = process.env[envVar];
if (envValue) {
logger.debug(`[config] env:${envVar} = ${envValue}`);
return true;
}

Expand Down