Skip to content

Conversation

@anna-git
Copy link
Contributor

@anna-git anna-git commented Dec 4, 2025

Context

Part of Configuration Inversion (Step 6) - Stack progress:

  1. #7548 - Add GitLab step and JSON configuration file
  2. #7688 - Cleanup configuration / platform keys + source generator
  3. #7698 - Aliases handling via source generator
  4. #7689 - Analyzers for platform and ConfigurationBuilder
  5. #7697 - Replace manual ConfigurationKeys by generated ones in the whole solution (this PR)
  6. #7905 - Forbid use of System.Environment methods and adapt everywhere (this PR)
    I'll update the PR summary to mention the YAML documentation file:

Summary of changes

Banned direct System.Environment.GetEnvironmentVariable() usage and migrated all environment variable access to use EnvironmentHelpers with strongly-typed ConfigurationKeys and PlatformKeys constants.

Key changes:

  • Banned System.Environment.GetEnvironmentVariable() via BannedApiAnalyzers
  • Added EnvironmentGetEnvironmentVariableAnalyzer (DD0009) to enforce ConfigurationKeys/PlatformKeys usage only
  • Nested PlatformKeys by category (Ci, Aws, AzureAppService, ServiceFabric, DotNet)
  • Migrated ~50+ files across CI Visibility, AWS Lambda, AppSec, Telemetry, Profiler, and Agent components
  • Added missing keys to supported-configurations.json and their documentation to supported-configurations-docs.yaml

Reason for change

Direct System.Environment.GetEnvironmentVariable() calls with string literals are error-prone. Centralizing through EnvironmentHelpers with strongly-typed constants provides compile-time validation, discoverability, and refactoring safety.

Implementation details

  1. Banned API enforcement - Added BannedSymbols.txt and configured .editorconfig to treat RS0030 as error (vendored code excluded)
  2. Custom analyzer - DD0009 validates all EnvironmentHelpers calls accept only ConfigurationKeys/PlatformKeys constants, rejecting hardcoded strings
  3. PlatformKeys organization - Nested by category for better discoverability
  4. EnvironmentHelpers refactoring - Added overloads for nested class constants, maintained backward compatibility
  5. Configuration documentation - Added missing configuration keys to supported-configurations.json and comprehensive XML documentation to supported-configurations-docs.yaml, which the source generator uses to generate XML doc comments in ConfigurationKeys classes

Test coverage

  • ✅ Comprehensive analyzer tests covering valid/invalid scenarios
  • ✅ All existing unit tests pass
  • ✅ Banned API analyzer correctly flags direct System.Environment usage

Other details

+2,600/-940 lines. No breaking changes, negligible performance impact.

@anna-git anna-git changed the title Anna/config inversion prevent direct env use 6 [Config Registry] inversion prevent direct env use 6 Dec 4, 2025
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 3cf027a to 9d07021 Compare December 4, 2025 16:46
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 8ee1b57 to 534627b Compare December 4, 2025 16:47
@anna-git anna-git changed the title [Config Registry] inversion prevent direct env use 6 [Config Registry] 6/6 Forbid use of System.Environment methods and adapt everywhere Dec 4, 2025
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 9d07021 to 3fae9ea Compare December 9, 2025 11:38
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 534627b to f6f071c Compare December 9, 2025 11:38
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 3fae9ea to faad2d7 Compare December 9, 2025 12:27
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch 2 times, most recently from 8e858f0 to 58cf443 Compare December 9, 2025 12:39
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from faad2d7 to 91a3181 Compare December 9, 2025 14:55
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 58cf443 to ed14287 Compare December 9, 2025 14:55
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 91a3181 to 95b0301 Compare December 9, 2025 15:43
Base automatically changed from anna/config-inversion-use-generate-config-keys-5 to anna/config-inversion-configuration-analyzers-4 December 9, 2025 15:43
@anna-git anna-git closed this Dec 9, 2025
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from ed14287 to 346d13a Compare December 9, 2025 15:43
@datadog-official
Copy link

datadog-official bot commented Dec 9, 2025

⚠️ Tests

⚠️ Warnings

🧪 1 Test failed

❄️ Known flaky: StableConfigWhenProfilingEnabled from Datadog.Profiler.IntegrationTests.SingleStepInstrumentation.SingleStepInstrumentationTest (Datadog)
The test Samples.BuggyBits is running for too long or was lost

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ed14287 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants