[Config Registry] 6/7 Forbid use of System.Environment methods and adapt everywhere
Context
Part of Configuration Inversion (Step 6) - Stack progress:
- #7548 - Add GitLab step and JSON configuration file
- #7688 - Cleanup configuration / platform keys + source generator
- #7698 - Aliases handling via source generator
- #7689 - Analyzers for platform and ConfigurationBuilder
- #7931 - Replace manual ConfigurationKeys by generated ones in the whole solution
- → #7932 - Forbid use of System.Environment methods and adapt everywhere (this PR)
- #7937 - Integration names to generated keys
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()viaBannedApiAnalyzers - Added
EnvironmentGetEnvironmentVariableAnalyzer(DD0009) to enforce ConfigurationKeys/PlatformKeysusage only - Nested
PlatformKeysby 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
- Banned API enforcement - Added
BannedSymbols.txtand configured.editorconfigto treat RS0030 as error (vendored code excluded) - Custom analyzer - DD0009 validates all
EnvironmentHelperscalls accept only ConfigurationKeys/PlatformKeysconstants, rejecting hardcoded strings - PlatformKeys organization - Nested by category for better discoverability
- EnvironmentHelpers refactoring - Added overloads for nested class constants, maintained backward compatibility
- 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.Environmentusage
Other details
+2,600/-940 lines. No breaking changes, negligible performance impact.
Execution-Time Benchmarks Report :stopwatch:
Execution-time results for samples comparing This PR (7932) and master.
✅ No regressions detected - check the details below
Full Metrics Comparison
FakeDbCommand
| Metric | Master (Mean ± 95% CI) | Current (Mean ± 95% CI) | Change | Status |
|---|---|---|---|---|
| .NET Framework 4.8 - Baseline | ||||
| duration | 68.24 ± (68.23 - 68.42) ms | 68.26 ± (68.24 - 68.43) ms | +0.0% | ✅⬆️ |
| .NET Framework 4.8 - Bailout | ||||
| duration | 71.98 ± (71.93 - 72.16) ms | 72.08 ± (72.00 - 72.23) ms | +0.1% | ✅⬆️ |
| .NET Framework 4.8 - CallTarget+Inlining+NGEN | ||||
| duration | 1004.14 ± (1010.66 - 1020.72) ms | 1001.57 ± (1004.49 - 1011.87) ms | -0.3% | ✅ |
| .NET Core 3.1 - Baseline | ||||
| process.internal_duration_ms | 22.02 ± (21.98 - 22.06) ms | 21.93 ± (21.89 - 21.97) ms | -0.4% | ✅ |
| process.time_to_main_ms | 78.78 ± (78.61 - 78.95) ms | 78.86 ± (78.68 - 79.03) ms | +0.1% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 10.91 ± (10.90 - 10.91) MB | 10.91 ± (10.90 - 10.91) MB | +0.0% | ✅⬆️ |
| runtime.dotnet.threads.count | 12 ± (12 - 12) | 12 ± (12 - 12) | +0.0% | ✅ |
| .NET Core 3.1 - Bailout | ||||
| process.internal_duration_ms | 21.93 ± (21.91 - 21.96) ms | 21.88 ± (21.85 - 21.92) ms | -0.2% | ✅ |
| process.time_to_main_ms | 79.86 ± (79.78 - 79.95) ms | 80.07 ± (79.95 - 80.18) ms | +0.3% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 10.94 ± (10.94 - 10.95) MB | 10.95 ± (10.95 - 10.95) MB | +0.1% | ✅⬆️ |
| runtime.dotnet.threads.count | 13 ± (13 - 13) | 13 ± (13 - 13) | +0.0% | ✅ |
| .NET Core 3.1 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 210.36 ± (208.88 - 211.85) ms | 210.41 ± (209.05 - 211.77) ms | +0.0% | ✅⬆️ |
| process.time_to_main_ms | 471.25 ± (470.64 - 471.87) ms | 472.06 ± (471.44 - 472.68) ms | +0.2% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 48.09 ± (48.07 - 48.12) MB | 48.06 ± (48.04 - 48.08) MB | -0.1% | ✅ |
| runtime.dotnet.threads.count | 28 ± (28 - 28) | 28 ± (28 - 28) | +0.0% | ✅ |
| .NET 6 - Baseline | ||||
| process.internal_duration_ms | 20.79 ± (20.77 - 20.82) ms | 20.66 ± (20.63 - 20.68) ms | -0.7% | ✅ |
| process.time_to_main_ms | 68.40 ± (68.26 - 68.54) ms | 68.02 ± (67.93 - 68.12) ms | -0.5% | ✅ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 10.59 ± (10.58 - 10.59) MB | 10.63 ± (10.63 - 10.64) MB | +0.4% | ✅⬆️ |
| runtime.dotnet.threads.count | 10 ± (10 - 10) | 10 ± (10 - 10) | +0.0% | ✅ |
| .NET 6 - Bailout | ||||
| process.internal_duration_ms | 20.72 ± (20.70 - 20.75) ms | 20.56 ± (20.54 - 20.58) ms | -0.8% | ✅ |
| process.time_to_main_ms | 69.16 ± (69.10 - 69.23) ms | 68.88 ± (68.84 - 68.93) ms | -0.4% | ✅ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 10.71 ± (10.71 - 10.72) MB | 10.68 ± (10.67 - 10.68) MB | -0.3% | ✅ |
| runtime.dotnet.threads.count | 11 ± (11 - 11) | 11 ± (11 - 11) | +0.0% | ✅ |
| .NET 6 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 200.41 ± (199.51 - 201.32) ms | 200.06 ± (198.89 - 201.23) ms | -0.2% | ✅ |
| process.time_to_main_ms | 440.66 ± (439.87 - 441.44) ms | 436.91 ± (436.40 - 437.43) ms | -0.8% | ✅ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 48.45 ± (48.40 - 48.50) MB | 48.24 ± (48.16 - 48.32) MB | -0.4% | ✅ |
| runtime.dotnet.threads.count | 28 ± (28 - 28) | 28 ± (28 - 28) | +0.0% | ✅⬆️ |
| .NET 8 - Baseline | ||||
| process.internal_duration_ms | 18.82 ± (18.79 - 18.85) ms | 18.80 ± (18.78 - 18.83) ms | -0.1% | ✅ |
| process.time_to_main_ms | 67.21 ± (67.10 - 67.31) ms | 66.97 ± (66.88 - 67.07) ms | -0.3% | ✅ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 7.65 ± (7.65 - 7.66) MB | 7.69 ± (7.68 - 7.70) MB | +0.4% | ✅⬆️ |
| runtime.dotnet.threads.count | 10 ± (10 - 10) | 10 ± (10 - 10) | +0.0% | ✅ |
| .NET 8 - Bailout | ||||
| process.internal_duration_ms | 18.70 ± (18.68 - 18.73) ms | 18.78 ± (18.76 - 18.81) ms | +0.4% | ✅⬆️ |
| process.time_to_main_ms | 68.06 ± (68.01 - 68.11) ms | 68.07 ± (68.02 - 68.12) ms | +0.0% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 7.72 ± (7.71 - 7.73) MB | 7.75 ± (7.74 - 7.77) MB | +0.5% | ✅⬆️ |
| runtime.dotnet.threads.count | 11 ± (11 - 11) | 11 ± (11 - 11) | +0.0% | ✅ |
| .NET 8 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 179.05 ± (178.19 - 179.90) ms | 179.32 ± (178.22 - 180.42) ms | +0.2% | ✅⬆️ |
| process.time_to_main_ms | 422.60 ± (422.13 - 423.07) ms | 423.51 ± (422.90 - 424.12) ms | +0.2% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 0 ± (0 - 0) | 0 ± (0 - 0) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 36.31 ± (36.28 - 36.34) MB | 36.31 ± (36.28 - 36.35) MB | +0.0% | ✅⬆️ |
| runtime.dotnet.threads.count | 27 ± (27 - 27) | 27 ± (27 - 27) | -0.1% | ✅ |
HttpMessageHandler
| Metric | Master (Mean ± 95% CI) | Current (Mean ± 95% CI) | Change | Status |
|---|---|---|---|---|
| .NET Framework 4.8 - Baseline | ||||
| duration | 193.39 ± (193.35 - 194.00) ms | 193.10 ± (193.33 - 194.09) ms | -0.2% | ✅ |
| .NET Framework 4.8 - Bailout | ||||
| duration | 196.97 ± (196.95 - 197.77) ms | 196.81 ± (196.75 - 197.27) ms | -0.1% | ✅ |
| .NET Framework 4.8 - CallTarget+Inlining+NGEN | ||||
| duration | 1111.82 ± (1115.44 - 1124.23) ms | 1112.76 ± (1119.34 - 1129.64) ms | +0.1% | ✅⬆️ |
| .NET Core 3.1 - Baseline | ||||
| process.internal_duration_ms | 189.44 ± (189.00 - 189.88) ms | 187.79 ± (187.38 - 188.20) ms | -0.9% | ✅ |
| process.time_to_main_ms | 80.86 ± (80.65 - 81.08) ms | 81.02 ± (80.78 - 81.26) ms | +0.2% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 3 ± (3 - 3) | 3 ± (3 - 3) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 16.08 ± (16.06 - 16.11) MB | 16.16 ± (16.14 - 16.19) MB | +0.5% | ✅⬆️ |
| runtime.dotnet.threads.count | 20 ± (20 - 20) | 20 ± (20 - 20) | +0.5% | ✅⬆️ |
| .NET Core 3.1 - Bailout | ||||
| process.internal_duration_ms | 187.26 ± (187.02 - 187.50) ms | 188.11 ± (187.79 - 188.43) ms | +0.5% | ✅⬆️ |
| process.time_to_main_ms | 82.11 ± (81.95 - 82.27) ms | 82.31 ± (82.16 - 82.47) ms | +0.3% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 3 ± (3 - 3) | 3 ± (3 - 3) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 16.17 ± (16.14 - 16.19) MB | 16.22 ± (16.19 - 16.25) MB | +0.3% | ✅⬆️ |
| runtime.dotnet.threads.count | 21 ± (21 - 21) | 21 ± (21 - 21) | +0.5% | ✅⬆️ |
| .NET Core 3.1 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 398.17 ± (395.26 - 401.08) ms | 398.02 ± (394.57 - 401.47) ms | -0.0% | ✅ |
| process.time_to_main_ms | 474.49 ± (473.87 - 475.11) ms | 473.91 ± (473.04 - 474.78) ms | -0.1% | ✅ |
| runtime.dotnet.exceptions.count | 3 ± (3 - 3) | 3 ± (3 - 3) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 58.08 ± (57.93 - 58.24) MB | 58.71 ± (58.55 - 58.87) MB | +1.1% | ✅⬆️ |
| runtime.dotnet.threads.count | 29 ± (29 - 29) | 29 ± (29 - 30) | +0.1% | ✅⬆️ |
| .NET 6 - Baseline | ||||
| process.internal_duration_ms | 192.09 ± (191.70 - 192.47) ms | 194.45 ± (193.95 - 194.95) ms | +1.2% | ✅⬆️ |
| process.time_to_main_ms | 69.83 ± (69.64 - 70.01) ms | 70.48 ± (70.29 - 70.68) ms | +0.9% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 16.20 ± (16.08 - 16.32) MB | 16.33 ± (16.31 - 16.36) MB | +0.8% | ✅⬆️ |
| runtime.dotnet.threads.count | 19 ± (18 - 19) | 19 ± (19 - 19) | +2.2% | ✅⬆️ |
| .NET 6 - Bailout | ||||
| process.internal_duration_ms | 191.49 ± (191.16 - 191.82) ms | 193.58 ± (193.15 - 194.01) ms | +1.1% | ✅⬆️ |
| process.time_to_main_ms | 70.81 ± (70.70 - 70.92) ms | 71.58 ± (71.41 - 71.76) ms | +1.1% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 16.27 ± (16.16 - 16.39) MB | 16.31 ± (16.24 - 16.39) MB | +0.2% | ✅⬆️ |
| runtime.dotnet.threads.count | 19 ± (19 - 20) | 20 ± (19 - 20) | +1.5% | ✅⬆️ |
| .NET 6 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 411.39 ± (408.89 - 413.89) ms | 412.91 ± (410.58 - 415.25) ms | +0.4% | ✅⬆️ |
| process.time_to_main_ms | 445.57 ± (444.98 - 446.16) ms | 450.02 ± (449.24 - 450.79) ms | +1.0% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 59.30 ± (59.19 - 59.42) MB | 59.18 ± (59.05 - 59.30) MB | -0.2% | ✅ |
| runtime.dotnet.threads.count | 30 ± (29 - 30) | 29 ± (29 - 30) | -0.1% | ✅ |
| .NET 8 - Baseline | ||||
| process.internal_duration_ms | 190.85 ± (190.48 - 191.21) ms | 190.53 ± (190.24 - 190.81) ms | -0.2% | ✅ |
| process.time_to_main_ms | 69.52 ± (69.35 - 69.70) ms | 69.34 ± (69.19 - 69.49) ms | -0.3% | ✅ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 11.73 ± (11.70 - 11.76) MB | 11.70 ± (11.67 - 11.73) MB | -0.2% | ✅ |
| runtime.dotnet.threads.count | 18 ± (18 - 18) | 18 ± (18 - 18) | +0.2% | ✅⬆️ |
| .NET 8 - Bailout | ||||
| process.internal_duration_ms | 189.72 ± (189.46 - 189.97) ms | 190.07 ± (189.82 - 190.31) ms | +0.2% | ✅⬆️ |
| process.time_to_main_ms | 70.35 ± (70.26 - 70.44) ms | 70.65 ± (70.51 - 70.79) ms | +0.4% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 11.86 ± (11.83 - 11.89) MB | 11.78 ± (11.75 - 11.81) MB | -0.7% | ✅ |
| runtime.dotnet.threads.count | 19 ± (19 - 19) | 19 ± (19 - 19) | -0.2% | ✅ |
| .NET 8 - CallTarget+Inlining+NGEN | ||||
| process.internal_duration_ms | 365.97 ± (364.58 - 367.35) ms | 365.41 ± (364.06 - 366.75) ms | -0.2% | ✅ |
| process.time_to_main_ms | 427.54 ± (426.84 - 428.25) ms | 428.45 ± (427.93 - 428.96) ms | +0.2% | ✅⬆️ |
| runtime.dotnet.exceptions.count | 4 ± (4 - 4) | 4 ± (4 - 4) | +0.0% | ✅ |
| runtime.dotnet.mem.committed | 47.98 ± (47.95 - 48.01) MB | 47.96 ± (47.94 - 47.98) MB | -0.0% | ✅ |
| runtime.dotnet.threads.count | 29 ± (29 - 29) | 29 ± (29 - 29) | -0.1% | ✅ |
Comparison explanation
Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
- Welch test with statistical test for significance of 5%
- Only results indicating a difference greater than 5% and 5 ms are considered.
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.
Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).
Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (68ms) : 67, 70
master - mean (68ms) : 67, 70
section Bailout
This PR (7932) - mean (72ms) : 71, 73
master - mean (72ms) : 71, 73
section CallTarget+Inlining+NGEN
This PR (7932) - mean (1,008ms) : 955, 1061
master - mean (1,016ms) : 942, 1090
FakeDbCommand (.NET Core 3.1)
gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (106ms) : 102, 110
master - mean (106ms) : 104, 108
section Bailout
This PR (7932) - mean (107ms) : 105, 109
master - mean (107ms) : 106, 108
section CallTarget+Inlining+NGEN
This PR (7932) - mean (709ms) : 681, 738
master - mean (710ms) : 683, 736
FakeDbCommand (.NET 6)
gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (93ms) : 92, 95
master - mean (94ms) : 92, 96
section Bailout
This PR (7932) - mean (94ms) : 93, 95
master - mean (95ms) : 93, 96
section CallTarget+Inlining+NGEN
This PR (7932) - mean (664ms) : 646, 682
master - mean (668ms) : 635, 701
FakeDbCommand (.NET 8)
gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (92ms) : 90, 94
master - mean (92ms) : 90, 94
section Bailout
This PR (7932) - mean (93ms) : 91, 94
master - mean (93ms) : 91, 94
section CallTarget+Inlining+NGEN
This PR (7932) - mean (630ms) : 616, 644
master - mean (629ms) : 614, 644
HttpMessageHandler (.NET Framework 4.8)
gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (194ms) : 190, 198
master - mean (194ms) : 190, 197
section Bailout
This PR (7932) - mean (197ms) : 195, 199
master - mean (197ms) : 193, 201
section CallTarget+Inlining+NGEN
This PR (7932) - mean (1,124ms) : 1046, 1203
master - mean (1,120ms) : 1054, 1186
HttpMessageHandler (.NET Core 3.1)
gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (278ms) : 271, 285
master - mean (279ms) : 270, 288
section Bailout
This PR (7932) - mean (279ms) : 274, 283
master - mean (277ms) : 274, 281
section CallTarget+Inlining+NGEN
This PR (7932) - mean (907ms) : 851, 962
master - mean (905ms) : 854, 955
HttpMessageHandler (.NET 6)
gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (274ms) : 266, 281
master - mean (271ms) : 266, 275
section Bailout
This PR (7932) - mean (273ms) : 266, 281
master - mean (270ms) : 266, 274
section CallTarget+Inlining+NGEN
This PR (7932) - mean (894ms) : 850, 939
master - mean (891ms) : 840, 942
HttpMessageHandler (.NET 8)
gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7932) - mean (269ms) : 265, 274
master - mean (270ms) : 265, 274
section Bailout
This PR (7932) - mean (270ms) : 267, 274
master - mean (270ms) : 266, 273
section CallTarget+Inlining+NGEN
This PR (7932) - mean (825ms) : 796, 854
master - mean (824ms) : 802, 846
✅ Tests
🎉 All green!
❄️ No new flaky tests detected
🧪 All tests passed
🔗 Commit SHA: b7ac294 | Docs | Datadog PR Page | Was this helpful? Give us feedback!