WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Closed
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
4 changes: 3 additions & 1 deletion packages/dd-trace/src/config-env-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ 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 () {
try {
const StableConfig = require('./config_stable')
const instance = new StableConfig()
return {
instance,
localEntries: instance.localEntries ?? {},
fleetEntries: instance.fleetEntries ?? {},
warnings: instance.warnings ?? []
Expand Down
9 changes: 7 additions & 2 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion packages/dd-trace/src/config_stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class StableConfig {
return
}

// cache the file reads
const localConfig = this._readConfigFromPath(localConfigPath)
const fleetConfig = this._readConfigFromPath(fleetConfigPath)
if (!localConfig && !fleetConfig) {
Expand Down
10 changes: 10 additions & 0 deletions packages/dd-trace/test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -2872,6 +2874,8 @@ rules:
configuration:
DD_SERVICE: service_local_stable
`)
resetConfigEnvSources()

const config2 = getConfig()
expect(config2).to.have.property(
'service',
Expand All @@ -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',
Expand All @@ -2901,6 +2907,7 @@ rules:
configuration:
DD_SERVICE: service_fleet_stable
`)
resetConfigEnvSources()
const config4 = getConfig()
expect(config4).to.have.property(
'service',
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down