diff --git a/packages/dd-trace/src/config-env-sources.js b/packages/dd-trace/src/config-env-sources.js index ab27a386bf7..ceee9ffbaf3 100644 --- a/packages/dd-trace/src/config-env-sources.js +++ b/packages/dd-trace/src/config-env-sources.js @@ -9,18 +9,21 @@ class ConfigEnvSources { let localStableConfig = {} let fleetStableConfig = {} + let stableConfigWarnings = [] if (!isServerless) { const result = this.#loadStableConfig() if (result) { localStableConfig = result.localEntries fleetStableConfig = result.fleetEntries + stableConfigWarnings = result.warnings } } // Expose raw stable config on the instance this.localStableConfig = localStableConfig this.fleetStableConfig = fleetStableConfig + this.stableConfigWarnings = stableConfigWarnings } #loadStableConfig () { @@ -28,7 +31,6 @@ class ConfigEnvSources { const StableConfig = require('./config_stable') const instance = new StableConfig() return { - instance, localEntries: instance.localEntries ?? {}, fleetEntries: instance.fleetEntries ?? {}, warnings: instance.warnings ?? [] diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index 898877e5f36..0c16716349e 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -18,6 +18,7 @@ const { isInServerlessEnvironment, getIsGCPFunction, getIsAzureFunction } = requ const { ORIGIN_KEY } = require('./constants') const { appendRules } = require('./payload-tagging/config') const { getEnvironmentVariable: getEnv, getEnvironmentVariables } = require('./config-helper') +const { getConfigEnvSources } = require('./config-env-sources') const defaults = require('./config_defaults') const path = require('path') const { DD_MAJOR } = require('../../../version') @@ -272,8 +273,12 @@ class Config { constructor (options = {}) { if (!isInServerlessEnvironment()) { // Bail out early if we're in a serverless environment, stable config isn't supported - const StableConfig = require('./config_stable') - this.stableConfig = new StableConfig() + const configEnvSources = getConfigEnvSources() + this.stableConfig = { + fleetEntries: configEnvSources.fleetStableConfig, + localEntries: configEnvSources.localStableConfig, + warnings: configEnvSources.stableConfigWarnings + } } const envs = getEnvironmentVariables() diff --git a/packages/dd-trace/src/config_stable.js b/packages/dd-trace/src/config_stable.js index 3f4b73e6e59..bbd459772b3 100644 --- a/packages/dd-trace/src/config_stable.js +++ b/packages/dd-trace/src/config_stable.js @@ -17,7 +17,6 @@ class StableConfig { return } - // cache the file reads const localConfig = this._readConfigFromPath(localConfigPath) const fleetConfig = this._readConfigFromPath(fleetConfigPath) if (!localConfig && !fleetConfig) { diff --git a/packages/dd-trace/test/config.spec.js b/packages/dd-trace/test/config.spec.js index 42dd9ff9250..effb4a10951 100644 --- a/packages/dd-trace/test/config.spec.js +++ b/packages/dd-trace/test/config.spec.js @@ -14,6 +14,7 @@ require('./setup/core') const { GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES } = require('../src/constants') const { getEnvironmentVariable, getEnvironmentVariables } = require('../src/config-helper') +const { resetConfigEnvSources } = require('../src/config-env-sources') const { assertObjectContains } = require('../../../integration-tests/helpers') const { DD_MAJOR } = require('../../../version') @@ -2819,6 +2820,7 @@ describe('Config', () => { tempDir = fs.mkdtempSync(path.join(baseTempDir, 'config-test-')) process.env.DD_TEST_LOCAL_CONFIG_PATH = path.join(tempDir, 'local.yaml') process.env.DD_TEST_FLEET_CONFIG_PATH = path.join(tempDir, 'fleet.yaml') + resetConfigEnvSources() }) afterEach(() => { @@ -2872,6 +2874,8 @@ rules: configuration: DD_SERVICE: service_local_stable `) + resetConfigEnvSources() + const config2 = getConfig() expect(config2).to.have.property( 'service', @@ -2881,6 +2885,8 @@ rules: // 3. Env > Local stable > Default process.env.DD_SERVICE = 'service_env' + resetConfigEnvSources() + const config3 = getConfig() expect(config3).to.have.property( 'service', @@ -2901,6 +2907,7 @@ rules: configuration: DD_SERVICE: service_fleet_stable `) + resetConfigEnvSources() const config4 = getConfig() expect(config4).to.have.property( 'service', @@ -3040,6 +3047,7 @@ apm_configuration_default: DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING: "all" DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH: 5 `) + resetConfigEnvSources() let config = getConfig() expect(config).to.have.property('apiKey', 'local-api-key') expect(config).to.have.property('appKey', 'local-app-key') @@ -3054,6 +3062,7 @@ apm_configuration_default: process.env.DD_APP_KEY = 'env-app-key' process.env.DD_INSTRUMENTATION_INSTALL_ID = 'env-install-id' process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = '7' + resetConfigEnvSources() config = getConfig() expect(config).to.have.property('apiKey', 'env-api-key') expect(config).to.have.property('appKey', 'env-app-key') @@ -3080,6 +3089,7 @@ rules: DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING: "all" DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH: 15 `) + resetConfigEnvSources() config = getConfig() expect(config).to.have.property('apiKey', 'fleet-api-key') expect(config).to.have.property('appKey', 'fleet-app-key')