@@ -957,28 +957,40 @@ function normalizePreloadOpentelemetry({ userConfig = {}, defaultConfig = {}, fi
957957/**
958958 * Updates configuration values dynamically from external sources (e.g., agent)
959959 *
960- * @param {Object.<string, any> } externalConfig
961- * @param {number } source
962- */
963- exports . update = function update ( externalConfig , source ) {
960+ * @param {Object } [params]
961+ * @param {Record<string, any> } [params.externalConfig]
962+ * @param {number } [params.source]
963+ * @param {Record<string, any> } [params.target=currentConfig]
964+ * @param {string } [params.basePath='config']
965+ * @returns {Record<string, any> }
966+ */
967+ exports . update = function update ( { externalConfig = { } , source, target = currentConfig , basePath = 'config' } = { } ) {
964968 if ( ! externalConfig || typeof externalConfig !== 'object' || Object . keys ( externalConfig ) . length === 0 ) {
965969 return currentConfig ;
966970 }
967971
968972 Object . keys ( externalConfig ) . forEach ( key => {
969- const configPath = `config .${ key } ` ;
970- const currentMeta = configStore . get ( configPath ) ;
973+ const path = `${ basePath } .${ key } ` ;
974+ const currentMeta = configStore . get ( path ) ;
971975
972976 if ( currentMeta && currentMeta . source < source ) {
973- logger . debug ( `[config] Skipping ${ key } : current source ${ currentMeta . source } > incoming ${ source } ` ) ;
974- return currentConfig ;
977+ logger . debug ( `[config] Skipping ${ path } : current source ${ currentMeta . source } > incoming ${ source } ` ) ;
978+ return ;
975979 }
976980
977- /** @type {Record<string, any> } */
978- const configAsRecord = currentConfig ;
979- configAsRecord [ key ] = deepMerge ( configAsRecord [ key ] , externalConfig [ key ] ) ;
981+ const incomingValue = externalConfig [ key ] ;
982+
983+ if ( incomingValue && typeof incomingValue === 'object' && ! Array . isArray ( incomingValue ) ) {
984+ if ( ! target [ key ] || typeof target [ key ] !== 'object' ) {
985+ target [ key ] = { } ;
986+ }
980987
981- configStore . set ( configPath , { source } ) ;
988+ update ( { externalConfig : incomingValue , source, target : target [ key ] , basePath : path } ) ;
989+ } else {
990+ target [ key ] = incomingValue ;
991+ configStore . set ( path , { source } ) ;
992+ }
982993 } ) ;
994+
983995 return currentConfig ;
984996} ;
0 commit comments