@@ -11,7 +11,7 @@ const tagger = require('./tagger')
1111const get = require ( '../../datadog-core/src/utils/src/get' )
1212const has = require ( '../../datadog-core/src/utils/src/has' )
1313const set = require ( '../../datadog-core/src/utils/src/set' )
14- const { isTrue, isFalse } = require ( './util' )
14+ const { isTrue, isFalse, normalizeProfilingEnabledValue } = require ( './util' )
1515const { GIT_REPOSITORY_URL , GIT_COMMIT_SHA } = require ( './plugins/util/tags' )
1616const { getGitMetadataFromGitProperties, removeUserSensitiveInfo } = require ( './git_properties' )
1717const { updateConfig } = require ( './telemetry' )
@@ -236,6 +236,12 @@ function reformatSpanSamplingRules (rules) {
236236
237237class Config {
238238 constructor ( options = { } ) {
239+ if ( ! isInServerlessEnvironment ( ) ) {
240+ // Bail out early if we're in a serverless environment, stable config isn't supported
241+ const StableConfig = require ( './config_stable' )
242+ this . stableConfig = new StableConfig ( )
243+ }
244+
239245 options = {
240246 ...options ,
241247 appsec : options . appsec != null ? options . appsec : options . experimental ?. appsec ,
@@ -244,13 +250,24 @@ class Config {
244250
245251 // Configure the logger first so it can be used to warn about other configs
246252 const logConfig = log . getConfig ( )
247- this . debug = logConfig . enabled
253+ this . debug = log . isEnabled (
254+ this . stableConfig ?. fleetEntries ?. DD_TRACE_DEBUG ,
255+ this . stableConfig ?. localEntries ?. DD_TRACE_DEBUG
256+ )
248257 this . logger = coalesce ( options . logger , logConfig . logger )
249- this . logLevel = coalesce ( options . logLevel , logConfig . logLevel )
250-
258+ this . logLevel = log . getLogLevel (
259+ options . logLevel ,
260+ this . stableConfig ?. fleetEntries ?. DD_TRACE_LOG_LEVEL ,
261+ this . stableConfig ?. localEntries ?. DD_TRACE_LOG_LEVEL
262+ )
251263 log . use ( this . logger )
252264 log . toggle ( this . debug , this . logLevel )
253265
266+ // Process stable config warnings, if any
267+ for ( const warning of this . stableConfig ?. warnings ?? [ ] ) {
268+ log . warn ( warning )
269+ }
270+
254271 checkIfBothOtelAndDdEnvVarSet ( )
255272
256273 const DD_API_KEY = coalesce (
@@ -337,7 +354,9 @@ class Config {
337354 }
338355
339356 this . _applyDefaults ( )
357+ this . _applyLocalStableConfig ( )
340358 this . _applyEnvironment ( )
359+ this . _applyFleetStableConfig ( )
341360 this . _applyOptions ( options )
342361 this . _applyCalculated ( )
343362 this . _applyRemote ( { } )
@@ -576,6 +595,45 @@ class Config {
576595 this . _setValue ( defaults , 'trace.dynamoDb.tablePrimaryKeys' , undefined )
577596 }
578597
598+ _applyLocalStableConfig ( ) {
599+ const obj = setHiddenProperty ( this , '_localStableConfig' , { } )
600+ this . _applyStableConfig ( this . stableConfig ?. localEntries ?? { } , obj )
601+ }
602+
603+ _applyFleetStableConfig ( ) {
604+ const obj = setHiddenProperty ( this , '_fleetStableConfig' , { } )
605+ this . _applyStableConfig ( this . stableConfig ?. fleetEntries ?? { } , obj )
606+ }
607+
608+ _applyStableConfig ( config , obj ) {
609+ const {
610+ DD_APPSEC_ENABLED ,
611+ DD_APPSEC_SCA_ENABLED ,
612+ DD_DATA_STREAMS_ENABLED ,
613+ DD_DYNAMIC_INSTRUMENTATION_ENABLED ,
614+ DD_ENV ,
615+ DD_IAST_ENABLED ,
616+ DD_LOGS_INJECTION ,
617+ DD_PROFILING_ENABLED ,
618+ DD_RUNTIME_METRICS_ENABLED ,
619+ DD_SERVICE ,
620+ DD_VERSION
621+ } = config
622+
623+ this . _setBoolean ( obj , 'appsec.enabled' , DD_APPSEC_ENABLED )
624+ this . _setBoolean ( obj , 'appsec.sca.enabled' , DD_APPSEC_SCA_ENABLED )
625+ this . _setBoolean ( obj , 'dsmEnabled' , DD_DATA_STREAMS_ENABLED )
626+ this . _setBoolean ( obj , 'dynamicInstrumentation.enabled' , DD_DYNAMIC_INSTRUMENTATION_ENABLED )
627+ this . _setString ( obj , 'env' , DD_ENV )
628+ this . _setBoolean ( obj , 'iast.enabled' , DD_IAST_ENABLED )
629+ this . _setBoolean ( obj , 'logInjection' , DD_LOGS_INJECTION )
630+ const profilingEnabled = normalizeProfilingEnabledValue ( DD_PROFILING_ENABLED )
631+ this . _setString ( obj , 'profiling.enabled' , profilingEnabled )
632+ this . _setBoolean ( obj , 'runtimeMetrics' , DD_RUNTIME_METRICS_ENABLED )
633+ this . _setString ( obj , 'service' , DD_SERVICE )
634+ this . _setString ( obj , 'version' , DD_VERSION )
635+ }
636+
579637 _applyEnvironment ( ) {
580638 const {
581639 AWS_LAMBDA_FUNCTION_NAME ,
@@ -831,16 +889,13 @@ class Config {
831889 this . _envUnprocessed . peerServiceMapping = DD_TRACE_PEER_SERVICE_MAPPING
832890 }
833891 this . _setString ( env , 'port' , DD_TRACE_AGENT_PORT )
834- const profilingEnabledEnv = coalesce (
835- DD_EXPERIMENTAL_PROFILING_ENABLED ,
836- DD_PROFILING_ENABLED ,
837- this . _isInServerlessEnvironment ( ) ? 'false' : undefined
892+ const profilingEnabled = normalizeProfilingEnabledValue (
893+ coalesce (
894+ DD_EXPERIMENTAL_PROFILING_ENABLED ,
895+ DD_PROFILING_ENABLED ,
896+ this . _isInServerlessEnvironment ( ) ? 'false' : undefined
897+ )
838898 )
839- const profilingEnabled = isTrue ( profilingEnabledEnv )
840- ? 'true'
841- : isFalse ( profilingEnabledEnv )
842- ? 'false'
843- : profilingEnabledEnv === 'auto' ? 'auto' : undefined
844899 this . _setString ( env , 'profiling.enabled' , profilingEnabled )
845900 this . _setString ( env , 'profiling.exporters' , DD_PROFILING_EXPORTERS )
846901 this . _setBoolean ( env , 'profiling.sourceMap' , DD_PROFILING_SOURCE_MAP && ! isFalse ( DD_PROFILING_SOURCE_MAP ) )
@@ -1347,9 +1402,33 @@ class Config {
13471402 // eslint-disable-next-line @stylistic/js/max-len
13481403 // https://github.com/DataDog/dd-go/blob/prod/trace/apps/tracer-telemetry-intake/telemetry-payload/static/config_norm_rules.json
13491404 _merge ( ) {
1350- const containers = [ this . _remote , this . _options , this . _env , this . _calculated , this . _defaults ]
1351- const origins = [ 'remote_config' , 'code' , 'env_var' , 'calculated' , 'default' ]
1352- const unprocessedValues = [ this . _remoteUnprocessed , this . _optsUnprocessed , this . _envUnprocessed , { } , { } ]
1405+ const containers = [
1406+ this . _remote ,
1407+ this . _options ,
1408+ this . _fleetStableConfig ,
1409+ this . _env ,
1410+ this . _localStableConfig ,
1411+ this . _calculated ,
1412+ this . _defaults
1413+ ]
1414+ const origins = [
1415+ 'remote_config' ,
1416+ 'code' ,
1417+ 'fleet_stable_config' ,
1418+ 'env_var' ,
1419+ 'local_stable_config' ,
1420+ 'calculated' ,
1421+ 'default'
1422+ ]
1423+ const unprocessedValues = [
1424+ this . _remoteUnprocessed ,
1425+ this . _optsUnprocessed ,
1426+ { } ,
1427+ this . _envUnprocessed ,
1428+ { } ,
1429+ { } ,
1430+ { }
1431+ ]
13531432 const changes = [ ]
13541433
13551434 for ( const name in this . _defaults ) {
0 commit comments