@@ -11,7 +11,7 @@ const tagger = require('./tagger')
11
11
const get = require ( '../../datadog-core/src/utils/src/get' )
12
12
const has = require ( '../../datadog-core/src/utils/src/has' )
13
13
const set = require ( '../../datadog-core/src/utils/src/set' )
14
- const { isTrue, isFalse } = require ( './util' )
14
+ const { isTrue, isFalse, normalizeProfilingEnabledValue } = require ( './util' )
15
15
const { GIT_REPOSITORY_URL , GIT_COMMIT_SHA } = require ( './plugins/util/tags' )
16
16
const { getGitMetadataFromGitProperties, removeUserSensitiveInfo } = require ( './git_properties' )
17
17
const { updateConfig } = require ( './telemetry' )
@@ -236,6 +236,12 @@ function reformatSpanSamplingRules (rules) {
236
236
237
237
class Config {
238
238
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
+
239
245
options = {
240
246
...options ,
241
247
appsec : options . appsec != null ? options . appsec : options . experimental ?. appsec ,
@@ -244,13 +250,24 @@ class Config {
244
250
245
251
// Configure the logger first so it can be used to warn about other configs
246
252
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
+ )
248
257
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
+ )
251
263
log . use ( this . logger )
252
264
log . toggle ( this . debug , this . logLevel )
253
265
266
+ // Process stable config warnings, if any
267
+ for ( const warning of this . stableConfig ?. warnings ?? [ ] ) {
268
+ log . warn ( warning )
269
+ }
270
+
254
271
checkIfBothOtelAndDdEnvVarSet ( )
255
272
256
273
const DD_API_KEY = coalesce (
@@ -337,7 +354,9 @@ class Config {
337
354
}
338
355
339
356
this . _applyDefaults ( )
357
+ this . _applyLocalStableConfig ( )
340
358
this . _applyEnvironment ( )
359
+ this . _applyFleetStableConfig ( )
341
360
this . _applyOptions ( options )
342
361
this . _applyCalculated ( )
343
362
this . _applyRemote ( { } )
@@ -576,6 +595,45 @@ class Config {
576
595
this . _setValue ( defaults , 'trace.dynamoDb.tablePrimaryKeys' , undefined )
577
596
}
578
597
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
+
579
637
_applyEnvironment ( ) {
580
638
const {
581
639
AWS_LAMBDA_FUNCTION_NAME ,
@@ -831,16 +889,13 @@ class Config {
831
889
this . _envUnprocessed . peerServiceMapping = DD_TRACE_PEER_SERVICE_MAPPING
832
890
}
833
891
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
+ )
838
898
)
839
- const profilingEnabled = isTrue ( profilingEnabledEnv )
840
- ? 'true'
841
- : isFalse ( profilingEnabledEnv )
842
- ? 'false'
843
- : profilingEnabledEnv === 'auto' ? 'auto' : undefined
844
899
this . _setString ( env , 'profiling.enabled' , profilingEnabled )
845
900
this . _setString ( env , 'profiling.exporters' , DD_PROFILING_EXPORTERS )
846
901
this . _setBoolean ( env , 'profiling.sourceMap' , DD_PROFILING_SOURCE_MAP && ! isFalse ( DD_PROFILING_SOURCE_MAP ) )
@@ -1347,9 +1402,33 @@ class Config {
1347
1402
// eslint-disable-next-line @stylistic/js/max-len
1348
1403
// https://github.com/DataDog/dd-go/blob/prod/trace/apps/tracer-telemetry-intake/telemetry-payload/static/config_norm_rules.json
1349
1404
_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
+ ]
1353
1432
const changes = [ ]
1354
1433
1355
1434
for ( const name in this . _defaults ) {
0 commit comments