Skip to content

Add class ConfigEnvSources to merge stable config and environment variables#6982

Merged
BridgeAR merged 6 commits intomasterfrom
mtoff/dcfg-getEnv-migration
Jan 22, 2026
Merged

Add class ConfigEnvSources to merge stable config and environment variables#6982
BridgeAR merged 6 commits intomasterfrom
mtoff/dcfg-getEnv-migration

Conversation

@mtoffl01
Copy link
Copy Markdown
Contributor

@mtoffl01 mtoffl01 commented Nov 24, 2025

Reviewer tips

The majority of code changes are just replacing getEnvironmentVariable with getValueFromEnvSources. Feel free to gloss over those changes once you get the idea from a few, and instead focus on:

  • packages/dd-trace/src/config-helper.js
  • packages/dd-trace-/src/config.js
  • packages/dd-trace-/src/profiling/...

Background

Currently, stable config files and environment variables are only processed when the Config class is instantiated, which happens in tracer.init(). This limits us from earlier access: code that runs before tracer.init() can't access stable config values.
This PR allows us to access stable config values before tracer.init(), when we peek at DD_TRACE env vars.
It also deduplicates configuration sourcing in profiler.

What does this PR do?

Introduces getValueFromEnvSources API in config-helper.js that resolves configuration from local stable config, environment variables, and fleet stable config in ascending priority order, before the Config singleton is initialized. This method can be used instead of getEnvironmentVariable when we want to see whether particular DD_TRACE configs have been set.

Key additions:

config-helper:

  • getValueFromEnvSources(): Queries for the value at specified config in fleet stable config, env var, and local stable config input, in that order
  • Comprehensive tests for the new config-helper functionality

profiler

  • Profiling config now consumes tracer Config fields: profiling/config.js reads options passed down from the main Config singleton, instead of re-reading them directly. For "DD_" configs that are not yet processed by the Config singleton, we use getValueFromEnvSources in order to resolve them from stable config inputs in addition to process.env
  • Profiling tests updated to mirror runtime behavior: profiling/config.spec.js and profiling/profiler.spec.js now construct profiling Config with a realistic agent URL (and hostname/port when relevant), matching what the tracer Config would provide at runtime, so tests exercise the same code paths the profiler uses in production.

Motivation

All environment variables must be set-able via stable config files: RFC

Note

Not all calls to getEnvironmentVariable were replaced by getResolvedEnv. In some cases, we are really looking for an environment variable that is a heuristic for a particular type of environment. Stable config is not relevant in these cases.

Plugin Checklist

Additional Notes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 24, 2025

Overall package size

Self size: 4.44 MB
Deduped: 5.26 MB
No deduping: 5.26 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.0 | 68.46 kB | 797.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-official

This comment has been minimized.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 86.46288% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.16%. Comparing base (aba6a5c) to head (8cc76b9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
packages/dd-trace/src/profiling/profiler.js 6.25% 15 Missing ⚠️
packages/dd-trace/src/telemetry/telemetry.js 86.27% 7 Missing ⚠️
...e/src/ci-visibility/exporters/test-worker/index.js 50.00% 2 Missing ⚠️
packages/dd-trace/src/llmobs/sdk.js 33.33% 2 Missing ⚠️
...ility/test-management/get-test-management-tests.js 50.00% 1 Missing ⚠️
packages/dd-trace/src/profiler.js 0.00% 1 Missing ⚠️
packages/dd-trace/src/proxy.js 50.00% 1 Missing ⚠️
packages/dd-trace/src/ritm.js 80.00% 1 Missing ⚠️
packages/dd-trace/src/telemetry/send-data.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6982      +/-   ##
==========================================
+ Coverage   86.12%   86.16%   +0.03%     
==========================================
  Files         513      513              
  Lines       22123    22147      +24     
==========================================
+ Hits        19054    19082      +28     
+ Misses       3069     3065       -4     
Flag Coverage Δ
aiguard-macos 99.09% <ø> (ø)
aiguard-ubuntu 99.09% <ø> (ø)
aiguard-windows 99.09% <ø> (ø)
apm-capabilities-tracing-macos 58.13% <79.55%> (+0.09%) ⬆️
apm-capabilities-tracing-ubuntu 58.12% <79.55%> (+0.09%) ⬆️
apm-capabilities-tracing-windows 57.73% <78.66%> (+0.06%) ⬆️
apm-integrations-child-process 99.19% <ø> (ø)
apm-integrations-couchbase-18 100.00% <ø> (ø)
apm-integrations-couchbase-eol 100.00% <ø> (ø)
appsec-express 62.46% <ø> (ø)
appsec-fastify 58.48% <ø> (ø)
appsec-graphql 53.41% <ø> (ø)
appsec-kafka 43.98% <ø> (ø)
appsec-ldapjs 46.04% <ø> (ø)
appsec-lodash 47.29% <ø> (ø)
appsec-macos 93.74% <ø> (ø)
appsec-mongodb-core 51.82% <ø> (ø)
appsec-mongoose 50.73% <ø> (ø)
appsec-mysql 54.20% <ø> (ø)
appsec-node-serialize 43.92% <ø> (ø)
appsec-passport 48.10% <ø> (ø)
appsec-postgres 54.55% <ø> (ø)
appsec-sourcing 33.80% <ø> (ø)
appsec-template 43.92% <ø> (ø)
appsec-ubuntu 93.74% <ø> (ø)
appsec-windows 93.74% <ø> (ø)
llmobs-ai 55.32% <33.33%> (ø)
llmobs-anthropic 45.46% <33.33%> (ø)
llmobs-bedrock 42.83% <33.33%> (ø)
llmobs-google-genai 48.73% <33.33%> (ø)
llmobs-langchain 52.31% <33.33%> (ø)
llmobs-openai 55.50% <33.33%> (ø)
llmobs-vertex-ai 47.46% <33.33%> (ø)
platform-core 87.23% <ø> (ø)
platform-instrumentations-misc 73.68% <ø> (ø)
platform-shimmer 98.82% <ø> (ø)
platform-unit-guardrails 89.47% <ø> (ø)
profiling-macos 70.74% <ø> (ø)
profiling-ubuntu 70.74% <ø> (ø)
profiling-windows 74.18% <44.44%> (-1.00%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mtoffl01 mtoffl01 added AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos core labels Nov 24, 2025
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Nov 24, 2025

Benchmarks

Benchmark execution time: 2026-01-22 10:44:16

Comparing candidate commit 8cc76b9 in PR branch mtoff/dcfg-getEnv-migration with baseline commit aba6a5c in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 231 metrics, 29 unstable metrics.

@mtoffl01 mtoffl01 changed the title Look in StableConfig & Env sources for config pre-init Create class ConfigEnvSources to merge stable config and environment variables Nov 24, 2025
@mtoffl01 mtoffl01 changed the title Create class ConfigEnvSources to merge stable config and environment variables Add class ConfigEnvSources to merge stable config and environment variables Nov 24, 2025
@mtoffl01 mtoffl01 force-pushed the mtoff/dcfg-getEnv-migration branch from eacb99d to a532c6a Compare December 4, 2025 17:12
Comment thread packages/dd-trace/src/config_stable.js Outdated
Comment thread packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js Outdated
@mtoffl01 mtoffl01 marked this pull request as ready for review December 4, 2025 21:14
@mtoffl01 mtoffl01 requested review from a team as code owners December 4, 2025 21:14
@mtoffl01 mtoffl01 requested review from BridgeAR and removed request for a team December 4, 2025 21:14
Comment thread packages/dd-trace/src/config-helper.js Outdated
Comment thread packages/dd-trace/src/config-helper.js Outdated
Comment thread packages/dd-trace/src/config-env-sources.js Outdated
Comment thread packages/dd-trace/src/config-env-sources.js Outdated
Comment thread packages/dd-trace/src/config-env-sources.js Outdated
Comment thread packages/dd-trace/src/config-helper.js Outdated
Comment thread packages/dd-trace/src/config/supported-configurations.json
Comment thread packages/dd-trace/src/config-helper.js Outdated
Comment thread packages/dd-trace/src/profiling/config.js
@BridgeAR BridgeAR force-pushed the mtoff/dcfg-getEnv-migration branch 2 times, most recently from 282f094 to 948ddde Compare December 29, 2025 16:35
Comment thread packages/dd-trace/src/plugin_manager.js Outdated
Comment thread packages/dd-trace/src/plugin_manager.js
Comment thread packages/dd-trace/src/plugins/util/ci.js Outdated
Comment thread packages/dd-trace/src/profiling/config.js Outdated
Comment thread packages/dd-trace/src/profiling/config.js Outdated
Comment thread packages/dd-trace/src/config-helper.js Outdated
Comment thread packages/dd-trace/src/config/helper.js
Comment thread packages/dd-trace/src/config/helper.js
Comment thread packages/dd-trace/src/telemetry/telemetry.js
Comment thread packages/dd-trace/src/telemetry/telemetry.js Outdated
Comment thread packages/dd-trace/src/exporters/agent/writer.js Outdated
Comment thread packages/dd-trace/src/exporters/agent/writer.js
Comment thread packages/dd-trace/src/startup-log.js
Comment on lines +224 to +226
if (errors.agentError) {
app.error = errors.agentError
errors.agentError = undefined
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure why this was never activated before. I am going to try to verify that before landing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bengl and me discussed it and the RFCs gone missing. We are going to activate it and see.

Comment thread packages/dd-trace/src/telemetry/telemetry.js
@BridgeAR BridgeAR force-pushed the mtoff/dcfg-getEnv-migration branch from c745a69 to b1308bc Compare January 12, 2026 21:38
Comment thread packages/dd-trace/src/config/stable.js
Comment thread packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js
Comment thread packages/datadog-instrumentations/src/otel-sdk-trace.js
Comment thread packages/dd-trace/src/ritm.js
@BridgeAR BridgeAR force-pushed the mtoff/dcfg-getEnv-migration branch from b1308bc to af99299 Compare January 20, 2026 01:34
Comment thread packages/dd-trace/src/profiling/config.js Outdated
Comment thread packages/dd-trace/src/profiling/config.js Outdated
Comment thread packages/dd-trace/src/profiling/config.js
Comment thread packages/dd-trace/src/profiling/profiler.js
Comment on lines +224 to +226
if (errors.agentError) {
app.error = errors.agentError
errors.agentError = undefined
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

Comment thread packages/dd-trace/test/config/helper.spec.js
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quite significant change and it's hard for me to properly review it. As far as I can see, we only have one dedicated test for telemetry: integration-tests/telemetry.spec.js - but it doesn't test very much. It would be good with all these changes if we could extend it a bit in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the changes with @bengl. Mostly it is types. There are a few changes around the host and the error cases and the repeated setTimeout to setInterval. I will work more with telemetry soon and add additional tests there, while this should be safe.

Comment thread packages/dd-trace/src/telemetry/telemetry.js Outdated
Copy link
Copy Markdown
Collaborator

@bengl bengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except changes we discussed verbally.

Copy link
Copy Markdown
Collaborator

@bengl bengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except changes we discussed verbally.

bengl
bengl previously approved these changes Jan 21, 2026
Copy link
Copy Markdown
Collaborator

@bengl bengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except changes we discussed verbally.

mtoffl01 and others added 4 commits January 22, 2026 00:26
fix circular dependency

Migrate civis call to use getEnvironmnetVariableSources instead

run linter

cleanup comments on config-env-sources

complete ci/init.js migration

migrate otel-sdk-trace.js

assert getResolvedEnv behaves just like getEnvironmentVariable when only envs exist

migrate register.js

migrate DD_TRACE_AWS_SDK_BATCH_PROPAGATION_ENABLED

migrate DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED and DD_TRACE_AZURE_SERVICEBUS_BATCH_LINKS_ENABLED

migrate cypress and cucumber DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER

migrate dd-trace-api, mocha and jest

migrate mongodb, playwright and vitest plugins

migrate index.js -- specifically for disablement env vars -- and update tests to call resetEnvConfigSources

migrate plugin_manager

migrate DD_API_KEY in proxy.js

Finish bulk migration

fix debugger test: reset configenvsources

Fix failing tests in ci

fix failing lambda tets and aws-sdk tests

whoops - include all changes to lambda tests

migrate DD_TRACE_ENCODING_DEBUG and DD_TRACE_EXPERIMENTAL_STATE_TRACKING

Try out not cachine env vars

update config-env-sources tests accordingly

Remove calls to resetConfigEnvSources in legacy tests

nits

restore exporter.spec.js

have Config re-use the stable config entries from ConfigEnvSources

Add doc for ConfigEnvSources

drop config-env-sources; just use config-helper

delete config env sources

try again to delete config-env-sources

Apply getValueFromEnvSources to rest of DD calls; fix serverless.js

fix ritm

fix more referecnes to config env sources

fix another import

fix calls to getEnvironmentVariables that need getValueFromEnvSources

pass 'config' all the way down into profiler; remove duplicate config resolution logic

use getValueFromEnvSources in profiler for DD_ configs

leave TODO
Potentially split this into multiple PRs
@BridgeAR BridgeAR force-pushed the mtoff/dcfg-getEnv-migration branch from 670b08c to e00b30a Compare January 21, 2026 23:29
@BridgeAR BridgeAR merged commit a995fee into master Jan 22, 2026
799 checks passed
@BridgeAR BridgeAR deleted the mtoff/dcfg-getEnv-migration branch January 22, 2026 10:55
dd-octo-sts Bot pushed a commit that referenced this pull request Jan 22, 2026
…nt variables (#6982)

This makes sure most environment variables will be reading from stable config.

In addition, much code is cleaned up, types are added, and small improvements
were added.

---------

Co-authored-by: Ruben Bridgewater <ruben.bridgewater@datadoghq.com>
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jan 22, 2026
BridgeAR added a commit that referenced this pull request Jan 22, 2026
…nt variables (#6982)

This makes sure most environment variables will be reading from stable config.

In addition, much code is cleaned up, types are added, and small improvements
were added.

---------

Co-authored-by: Ruben Bridgewater <ruben.bridgewater@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos core semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants