Skip to content

Commit fee3625

Browse files
authored
chore(config): preserved existing values when applying partial updates (#2506)
External config updates now deep-merge nested plain objects into the existing normalized config instead of replacing them at the top level.
1 parent b5fc15e commit fee3625

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

packages/core/src/config/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,11 @@ exports.update = function update(externalConfig, source) {
974974
return currentConfig;
975975
}
976976

977-
/** @type {any} */ (currentConfig)[key] = externalConfig[key];
977+
/** @type {Record<string, any>} */
978+
const configAsRecord = currentConfig;
979+
configAsRecord[key] = deepMerge(configAsRecord[key], externalConfig[key]);
980+
978981
configStore.set(configPath, { source });
979-
logger.debug(`[config] Updated ${key} from source ${source}: ${JSON.stringify(externalConfig[key])}`);
980982
});
981983
return currentConfig;
982984
};

packages/core/src/config/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exports.resolve = function resolve({ envValue, inCodeValue, agentValue, defaultV
4444
default: defaultValue
4545
};
4646

47-
CONFIG_PRIORITY.find(sourceKey => {
47+
CONFIG_PRIORITY.some(sourceKey => {
4848
const rawValue = inputs[/** @type {keyof typeof inputs} */ (sourceKey)];
4949

5050
if (rawValue === undefined && sourceKey !== 'default') {

packages/core/test/config/normalizeConfig_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,32 @@ describe('config.normalizeConfig', () => {
16441644

16451645
expect(config.preloadOpentelemetry).to.be.true;
16461646
});
1647+
1648+
it('should preserve existing tracing config when agent updates tracing partially', () => {
1649+
const config = coreConfig.normalize();
1650+
1651+
expect(config.tracing.kafka.traceCorrelation).to.be.true;
1652+
expect(config.tracing.http.extraHttpHeadersToCapture).to.deep.equal([]);
1653+
1654+
coreConfig.update(
1655+
{
1656+
tracing: {
1657+
http: {
1658+
extraHttpHeadersToCapture: ['x-instana-test']
1659+
}
1660+
}
1661+
},
1662+
CONFIG_SOURCES.AGENT
1663+
);
1664+
1665+
expect(config.tracing.http.extraHttpHeadersToCapture).to.deep.equal(['x-instana-test']);
1666+
expect(config.tracing.kafka).to.deep.equal({
1667+
traceCorrelation: true
1668+
});
1669+
expect(config.tracing.kafka.traceCorrelation).to.be.true;
1670+
expect(config.tracing.enabled).to.be.true;
1671+
expect(config.tracing.spanBatchingEnabled).to.be.false;
1672+
});
16471673
});
16481674
});
16491675

0 commit comments

Comments
 (0)