Skip to content

fix(core): ensured env vars take precedence over in-code config#2409

Open
aryamohanan wants to merge 14 commits intofix-config-precedencefrom
fix-config-order
Open

fix(core): ensured env vars take precedence over in-code config#2409
aryamohanan wants to merge 14 commits intofix-config-precedencefrom
fix-config-order

Conversation

@aryamohanan
Copy link
Copy Markdown
Contributor

@aryamohanan aryamohanan commented Mar 16, 2026

This is the first PR addressing configuration precedence.

The goal of this change is to ensure the correct order between environment variables and in-code configuration:

env > in-code

Currently, the precedence between these two sources is mixed. This PR corrects that behavior.

Added missing logging in the configuration file when a config is set.

Scope of This PR

This PR only fixes the precedence between:

  • Environment variables
  • In-code configuration

Agent configuration precedence will be addressed in separate follow-up PRs.

Future Work

Additional PRs will follow to correct the agent configuration order.

Migration Plan

This change will be released in the next major version (v6), planned for Q2 2026.

ref https://jsw.ibm.com/browse/INSTA-80965

Epic : https://jsw.ibm.com/browse/INSTA-817

@aryamohanan aryamohanan changed the title Fix config order fix(config): ensure env vars take precedence over in-code config Mar 16, 2026
@aryamohanan aryamohanan marked this pull request as ready for review March 18, 2026 07:11
@aryamohanan aryamohanan requested a review from a team as a code owner March 18, 2026 07:11
@aryamohanan aryamohanan added feature-branch Target is a feat branch and removed merge later labels Mar 18, 2026
@aryamohanan aryamohanan changed the title fix(config): ensure env vars take precedence over in-code config fix(config): ensured env vars take precedence over in-code config Mar 18, 2026
@kirrg001
Copy link
Copy Markdown
Contributor

I'd suggest to rename the commit to:

fix(core): ensured env vars take precedence over in-code config
refs xy

BREAKING CHANGES: xy

And add a TODO for the other packages e.g. collector needs an update too. See normalizeConfig.

@aryamohanan aryamohanan changed the title fix(config): ensured env vars take precedence over in-code config fix(core): ensured env vars take precedence over in-code config Mar 25, 2026
return;
}

if (process.env['INSTANA_TRACING_DISABLE_EOL_EVENTS'] === 'false') {
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.

This config conditions pattern repeat everywhere in the config file. I am sure we can write a helper FN for it. I'd suggest to add a TODO as lower prio.

* @param {InstanaConfig} config
*/
function normalizeIgnoreEndpoints(config) {
if (!config.tracing.ignoreEndpoints) {
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.

This can be removed IMO - not part of this PR.
It would be good also to normalize these checks as a TODO for later.

Usually we do

if (config.tracing.ignoreEndpointsDisableSuppression === true) {
if (typeof ignoreEndpointsConfig !== 'object' || Array.isArray(ignoreEndpointsConfig)) {

To see if the value is set and right.

logger.warn(
`The value of ${envVarKey} ("${envVarVal}") is not numerical or cannot be parsed to a numerical value. Assuming the default value ${defaultValue}.`
);
return defaultValue;
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.

If env is set and invalid, should we not check if in-code is set? 🤔
And if in-code is not set, we fallback to default.

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.

Hmm, that’s an interesting thought. We might need a validator for all configurations. Not part of this PR maybe; we can discuss it.

However, repeatedly validating – both at the environment level once and, if it fails, then in-code – feels like overkill.

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.

We might need a validator for all configurations

Yeah validation of all incoming values would be the best before checking its precense.

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.

Not part of this PR yeah

);
config.serviceName = process.env['INSTANA_SERVICE_NAME'];
} else if (config.serviceName != null && typeof config.serviceName === 'string') {
logger.debug(`Service name has been configured via config: ${config.serviceName}`);
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.

We need a refactoring card.

We merge the user config in line 164

if (userConfig !== null) {
targetConfig = Object.assign({}, userConfig);
}

And in the normalize functions we do nothing because we already know that

function normalizeServiceName(config) {

is the user config. This is really hard to read.
And then we just do a debug log here.

There is different refactoring approaches to this.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-branch Target is a feat branch v6

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants