Skip to content

[Config Registry] 6/8 Forbid use of System.Environment methods and adapt everywhere#7932

Merged
anna-git merged 28 commits intomasterfrom
anna/config-inversion-prevent-direct-env-use-6
Jan 20, 2026
Merged

[Config Registry] 6/8 Forbid use of System.Environment methods and adapt everywhere#7932
anna-git merged 28 commits intomasterfrom
anna/config-inversion-prevent-direct-env-use-6

Conversation

@anna-git
Copy link
Contributor

@anna-git anna-git commented Dec 9, 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. #7931 - Replace manual ConfigurationKeys by generated ones in the whole solution
  6. #7932 - Forbid use of System.Environment methods and adapt everywhere (this PR)
  7. #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() 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 force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 95b0301 to 39a7db5 Compare December 9, 2025 16:48
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 346d13a to 1440fdf Compare December 9, 2025 16:48
@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 39a7db5 to 7b7e9bf Compare December 9, 2025 21:04
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 1440fdf to dad2367 Compare December 9, 2025 21:04
anna-git added a commit that referenced this pull request Dec 9, 2025
…any string key (#7689)

## Context

Part of **Configuration Inversion (Step 4)** - Stack progress:
1. [#7548](#7548) - Add
GitLab step and JSON configuration file
2. [#7688](#7688) -
Cleanup configuration / platform keys + analyzers
3. [#7698](#7698) -
Source generator for ConfigurationKeys
4. **→ [#7689](#7689) -
Aliases handling and analyzers (this PR)**
5. [#7931](#7931) -
Replace manual ConfigurationKeys with generated version
6. #[7932](#7932 Forbid
use of System.Environment methods and adapt everywhere

## Summary

Adds source generator for configuration key aliases, integrates alias
resolution into `ConfigurationBuilder`, and adds Roslyn analyzers to
enforce proper configuration key usage.

## Changes

**Alias Source Generator:**
- `ConfigKeyAliasesSwitcherGenerator` reads aliases from
`supported-configurations.json`
- Auto-generates switch statements to resolve primary keys from aliases
- Generated for all target frameworks (net461, netstandard2.0,
netcoreapp3.1, net6.0)

**ConfigurationBuilder Improvements:**
- Integrated alias resolution directly into
`ConfigurationBuilder.WithKeys()`
- Removed manual fallback overloads throughout codebase
- Added `GetKeyWithAlias()` method to `IConfigurationSource` interface

**IntegrationSettings Special Handling:**
- Updated to use pattern-based key construction (e.g.,
`DD_TRACE_{INTEGRATION}_ENABLED`)
- Simplified configuration reading by leveraging alias system

**Roslyn Analyzers:**
- **DD0007**: `PlatformKeysAnalyzer` - Enforces use of `PlatformKeys`
for external platform environment variables
- **DD0008**: `ConfigurationBuilderWithKeysAnalyzer` - Enforces use of
[ConfigurationKeys](cci:2://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.Logging.cs:9:0-58:1)/`PlatformKeys`
constants in `ConfigurationBuilder.WithKeys()` calls

**Special Cases:**
- Fixed `DatadogLoggingFactory` to handle deprecated `DD_TRACE_LOG_PATH`
with proper analyzer suppression
- Updated configuration tests to work with alias resolution

## Motivation

Completes configuration inversion by:
- Auto-generating alias resolution from `supported-configurations.json`
- Eliminating manual fallback chains
- Enforcing compile-time validation of configuration keys
- Preventing hardcoded strings and typos

## Test Coverage

- Added `ConfigKeyAliasesSwitcherGeneratorTests` with comprehensive test
coverage
- Added `PlatformKeysAnalyzerTests` with 146 lines of tests
- Added `ConfigurationBuilderWithKeysAnalyzerTests` with 538 lines of
tests
- Updated existing configuration tests for alias support
- All tests pass with new alias system

## Related Work

Builds on #7548 (configuration registry), #7688 (PlatformKeys
separation), and #7698 (source generator for ConfigurationKeys).
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Dec 9, 2025

Execution-Time Benchmarks Report ⏱️

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
duration76.61 ± (76.54 - 76.95) ms76.42 ± (76.43 - 76.76) ms-0.3%
.NET Framework 4.8 - Bailout
duration80.86 ± (80.77 - 81.19) ms80.89 ± (80.90 - 81.33) ms+0.0%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1064.34 ± (1065.64 - 1074.35) ms1064.85 ± (1063.75 - 1070.66) ms+0.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms23.34 ± (23.28 - 23.40) ms23.40 ± (23.34 - 23.46) ms+0.3%✅⬆️
process.time_to_main_ms89.23 ± (89.02 - 89.44) ms89.77 ± (89.55 - 89.99) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.89 ± (10.88 - 10.89) MB10.92 ± (10.91 - 10.92) MB+0.3%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms23.43 ± (23.37 - 23.50) ms23.28 ± (23.23 - 23.34) ms-0.6%
process.time_to_main_ms91.14 ± (90.92 - 91.36) ms91.32 ± (91.12 - 91.52) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.92 ± (10.91 - 10.92) MB10.95 ± (10.95 - 10.96) MB+0.3%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms242.87 ± (238.73 - 247.00) ms239.55 ± (235.66 - 243.43) ms-1.4%
process.time_to_main_ms508.36 ± (507.59 - 509.12) ms508.95 ± (508.07 - 509.82) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.25 ± (48.23 - 48.27) MB48.30 ± (48.28 - 48.32) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms22.27 ± (22.22 - 22.32) ms21.97 ± (21.93 - 22.02) ms-1.3%
process.time_to_main_ms78.88 ± (78.68 - 79.07) ms77.83 ± (77.65 - 78.01) ms-1.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.60 ± (10.60 - 10.60) MB10.65 ± (10.65 - 10.65) MB+0.5%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms22.07 ± (22.01 - 22.14) ms21.99 ± (21.93 - 22.05) ms-0.4%
process.time_to_main_ms79.48 ± (79.28 - 79.67) ms78.71 ± (78.48 - 78.93) ms-1.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.69 ± (10.68 - 10.69) MB10.74 ± (10.74 - 10.74) MB+0.5%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms236.63 ± (232.29 - 240.96) ms237.30 ± (233.25 - 241.35) ms+0.3%✅⬆️
process.time_to_main_ms486.97 ± (486.09 - 487.84) ms482.22 ± (481.32 - 483.11) ms-1.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.95 ± (48.94 - 48.97) MB49.04 ± (49.02 - 49.06) MB+0.2%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 8 - Baseline
process.internal_duration_ms20.17 ± (20.13 - 20.21) ms20.13 ± (20.08 - 20.18) ms-0.2%
process.time_to_main_ms76.78 ± (76.62 - 76.95) ms76.22 ± (76.05 - 76.40) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.65 ± (7.64 - 7.65) MB7.67 ± (7.67 - 7.68) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms20.20 ± (20.14 - 20.26) ms20.25 ± (20.19 - 20.30) ms+0.2%✅⬆️
process.time_to_main_ms77.63 ± (77.45 - 77.81) ms77.79 ± (77.59 - 77.98) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.71 ± (7.70 - 7.72) MB7.73 ± (7.72 - 7.74) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms194.64 ± (193.93 - 195.35) ms193.46 ± (192.78 - 194.15) ms-0.6%
process.time_to_main_ms467.46 ± (466.64 - 468.28) ms467.45 ± (466.60 - 468.29) ms-0.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.80 ± (36.75 - 36.84) MB36.94 ± (36.90 - 36.98) MB+0.4%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.2%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.37 ± (192.17 - 192.99) ms191.86 ± (192.02 - 192.95) ms-0.3%
.NET Framework 4.8 - Bailout
duration195.89 ± (195.81 - 196.67) ms195.41 ± (195.33 - 195.85) ms-0.2%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1111.31 ± (1114.98 - 1122.32) ms1119.10 ± (1124.53 - 1134.45) ms+0.7%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms186.10 ± (185.70 - 186.50) ms186.69 ± (186.38 - 187.01) ms+0.3%✅⬆️
process.time_to_main_ms80.75 ± (80.51 - 81.00) ms80.11 ± (79.96 - 80.26) ms-0.8%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.15 - 16.20) MB16.16 ± (16.14 - 16.19) MB-0.1%
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.4%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms185.55 ± (185.27 - 185.84) ms186.25 ± (185.91 - 186.59) ms+0.4%✅⬆️
process.time_to_main_ms82.03 ± (81.90 - 82.16) ms81.84 ± (81.69 - 81.99) ms-0.2%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.21 ± (16.18 - 16.24) MB16.13 ± (16.09 - 16.16) MB-0.5%
runtime.dotnet.threads.count21 ± (21 - 21)20 ± (20 - 21)-0.9%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms435.61 ± (433.20 - 438.02) ms421.47 ± (418.05 - 424.89) ms-3.2%
process.time_to_main_ms471.27 ± (470.71 - 471.82) ms470.80 ± (470.16 - 471.44) ms-0.1%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.62 ± (58.52 - 58.73) MB58.84 ± (58.72 - 58.95) MB+0.4%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 6 - Baseline
process.internal_duration_ms191.86 ± (191.42 - 192.31) ms190.58 ± (190.23 - 190.92) ms-0.7%
process.time_to_main_ms70.20 ± (69.98 - 70.42) ms69.92 ± (69.76 - 70.09) ms-0.4%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.21 ± (16.12 - 16.31) MB16.18 ± (16.05 - 16.30) MB-0.2%
runtime.dotnet.threads.count18 ± (18 - 19)18 ± (18 - 18)-0.6%
.NET 6 - Bailout
process.internal_duration_ms189.64 ± (189.43 - 189.86) ms190.02 ± (189.72 - 190.33) ms+0.2%✅⬆️
process.time_to_main_ms70.68 ± (70.55 - 70.81) ms71.24 ± (71.12 - 71.35) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed15.84 ± (15.67 - 16.01) MB15.84 ± (15.66 - 16.01) MB-0.0%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.1%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms447.62 ± (445.05 - 450.20) ms447.66 ± (445.26 - 450.06) ms+0.0%✅⬆️
process.time_to_main_ms449.21 ± (448.73 - 449.69) ms450.57 ± (450.06 - 451.09) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.01 ± (58.89 - 59.12) MB58.81 ± (58.69 - 58.92) MB-0.3%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 8 - Baseline
process.internal_duration_ms189.17 ± (188.85 - 189.50) ms189.15 ± (188.74 - 189.56) ms-0.0%
process.time_to_main_ms69.87 ± (69.66 - 70.07) ms69.75 ± (69.54 - 69.97) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.76 ± (11.73 - 11.79) MB11.80 ± (11.78 - 11.83) MB+0.4%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.1%
.NET 8 - Bailout
process.internal_duration_ms188.44 ± (188.17 - 188.71) ms188.15 ± (187.88 - 188.41) ms-0.2%
process.time_to_main_ms70.62 ± (70.48 - 70.76) ms70.20 ± (70.10 - 70.29) ms-0.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.75 ± (11.68 - 11.81) MB11.91 ± (11.88 - 11.94) MB+1.4%✅⬆️
runtime.dotnet.threads.count19 ± (18 - 19)19 ± (19 - 19)+3.0%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms364.09 ± (362.59 - 365.58) ms363.44 ± (361.82 - 365.05) ms-0.2%
process.time_to_main_ms433.41 ± (432.78 - 434.03) ms434.79 ± (434.12 - 435.47) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.14 ± (48.09 - 48.19) MB48.13 ± (48.09 - 48.18) MB-0.0%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.9%✅⬆️
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 (77ms)  : 74, 79
    master - mean (77ms)  : 74, 80

    section Bailout
    This PR (7932) - mean (81ms)  : 78, 84
    master - mean (81ms)  : 78, 84

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (1,067ms)  : 1018, 1117
    master - mean (1,070ms)  : 1007, 1133

Loading
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 (120ms)  : 115, 126
    master - mean (120ms)  : 115, 124

    section Bailout
    This PR (7932) - mean (122ms)  : 120, 124
    master - mean (122ms)  : 118, 125

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (789ms)  : 726, 852
    master - mean (792ms)  : 725, 859

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7932) - mean (106ms)  : 103, 110
    master - mean (108ms)  : 103, 112

    section Bailout
    This PR (7932) - mean (107ms)  : 105, 110
    master - mean (108ms)  : 106, 110

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (752ms)  : 671, 833
    master - mean (758ms)  : 673, 843

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7932) - mean (104ms)  : 101, 108
    master - mean (105ms)  : 102, 108

    section Bailout
    This PR (7932) - mean (106ms)  : 102, 110
    master - mean (106ms)  : 103, 109

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (697ms)  : 671, 722
    master - mean (701ms)  : 679, 723

Loading
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 (192ms)  : 187, 198
    master - mean (193ms)  : 189, 196

    section Bailout
    This PR (7932) - mean (196ms)  : 193, 198
    master - mean (196ms)  : 192, 200

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (1,129ms)  : 1057, 1202
    master - mean (1,119ms)  : 1066, 1171

Loading
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 (275ms)  : 271, 279
    master - mean (276ms)  : 269, 283

    section Bailout
    This PR (7932) - mean (276ms)  : 272, 280
    master - mean (276ms)  : 272, 279

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (922ms)  : 875, 968
    master - mean (931ms)  : 890, 972

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7932) - mean (269ms)  : 263, 275
    master - mean (270ms)  : 262, 278

    section Bailout
    This PR (7932) - mean (269ms)  : 266, 273
    master - mean (268ms)  : 265, 272

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (926ms)  : 885, 967
    master - mean (927ms)  : 889, 964

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7932) - mean (269ms)  : 263, 274
    master - mean (269ms)  : 264, 273

    section Bailout
    This PR (7932) - mean (268ms)  : 264, 271
    master - mean (269ms)  : 265, 273

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (829ms)  : 805, 853
    master - mean (828ms)  : 810, 846

Loading

@anna-git anna-git force-pushed the anna/config-inversion-use-generate-config-keys-5 branch from 7b7e9bf to 8ba62d5 Compare December 10, 2025 11:44
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from dad2367 to f18f8e4 Compare December 10, 2025 11:44
@anna-git anna-git changed the title [Config Registry] 6/6 Forbid use of System.Environment methods and adapt everywhere [Config Registry] 6/7 Forbid use of System.Environment methods and adapt everywhere Dec 10, 2025
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch 2 times, most recently from 303b602 to 70df7c9 Compare December 10, 2025 14:26
@datadog-datadog-prod-us1

This comment has been minimized.

anna-git added a commit that referenced this pull request Dec 10, 2025
…nes in the whole solution (#7931)

(This PR is actually
#7697 that accidentally
got closed)

## Context

Part of **Configuration Inversion (Step 5)** - Stack progress:
1. [#7548](#7548) - Add
GitLab step and JSON configuration file
2. [#7688](#7688) -
Cleanup configuration / platform keys + source generator
3. [#7698](#7698) -
Aliases handling via source generator
4. [#7689](#7689) -
Analyzers for platform and ConfigurationBuilder
5. **→ [#7931](#7697) -
Replace manual ConfigurationKeys by generated ones in the whole solution
(this PR)**
6. [#7932](#7932) -
Forbid use of System.Environment methods and adapt everywhere
7. [#7937](#7937) -
Integration names to generated keys

## Summary of changes

Fixed the
[ConfigurationKeysGenerator](cci:2://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigurationKeysGenerator.cs:21:0-958:1)
to properly read and apply the
[configuration_keys_mapping.json](cci:7://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/configuration_keys_mapping.json:0:0-0:0)
file, and extracted common file header comments to a reusable constant.

**Key changes:**
- Fixed JSON array extraction in
[ParseMappingFile](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigurationKeysGenerator.cs:350:4-524:5)
method - the generator was incorrectly trying to extract the
`"mappings"` field as an object instead of an array
- Extracted configuration generator comments to
`Constants.ConfigurationGeneratorComment` for reuse across multiple
generators
- Updated both
[ConfigurationKeysGenerator](cci:2://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigurationKeysGenerator.cs:21:0-958:1)
and
[ConfigKeyAliasesSwitcherGenerator](cci:2://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/Configuration/ConfigKeyAliasesSwitcherGenerator.cs:24:0-340:1)
to use the shared constant
- Added documentation as to how to add a key now

## Reason for change

The
[configuration_keys_mapping.json](cci:7://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/configuration_keys_mapping.json:0:0-0:0)
file was being ignored during code generation, causing the generator to
produce incorrect constant names. This meant that any manual edits to
constant names in the mapping file were not being respected, and the
generated code would use auto-generated names instead of the explicitly
mapped ones.

Additionally, the file header comments explaining that files are
auto-generated were duplicated across generators, violating DRY
principles.

## Implementation details

1. **Fixed array extraction logic**: Replaced the call to
[JsonReader.ExtractJsonObjectSection()](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/Configuration/JsonReader.cs:16:4-91:5)
with custom array extraction code that:
   - Finds the `"mappings":` key in the JSON
   - Locates the opening `[` bracket
   - Tracks bracket nesting to find the matching closing `]`
   - Extracts the complete array content

2. **Resolved variable scope issue**: Reused existing `inString` and
`escapeNext` variables from the outer scope instead of redeclaring them,
fixing compilation errors.

3. **Centralized header comments**: Created
`Constants.ConfigurationGeneratorComment` containing the standardized
auto-generation notice and updated both generators to use it.

## Test coverage

- Verified the generator builds successfully without errors
- The mapping file is now properly parsed and applied during code
generation
- Generated constant names now match the mappings defined in
[configuration_keys_mapping.json](cci:7://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/configuration_keys_mapping.json:0:0-0:0)

## Other details

This fix ensures that the explicit naming conventions defined in
[configuration_keys_mapping.json](cci:7://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/configuration_keys_mapping.json:0:0-0:0)
are respected, maintaining consistency with the existing codebase and
preventing future confusion when constant names don't match their
expected values.

---------

Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com>
Base automatically changed from anna/config-inversion-use-generate-config-keys-5 to master December 10, 2025 14:56
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch 4 times, most recently from c89c676 to 41c88a5 Compare December 11, 2025 10:58
@anna-git anna-git marked this pull request as ready for review December 11, 2025 14:20
@anna-git anna-git requested review from a team as code owners December 11, 2025 14:20
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from b481629 to d8e691c Compare January 19, 2026 15:43
@anna-git anna-git enabled auto-merge (squash) January 19, 2026 16:08
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from d8e691c to cafe31e Compare January 19, 2026 16:36
@anna-git anna-git merged commit acbb3f9 into master Jan 20, 2026
158 of 160 checks passed
@anna-git anna-git deleted the anna/config-inversion-prevent-direct-env-use-6 branch January 20, 2026 11:03
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 20, 2026
@anna-git anna-git mentioned this pull request Jan 21, 2026
NachoEchevarria added a commit that referenced this pull request Jan 21, 2026
## Summary of changes

In [this PR](#7932),
benchmark tests were broken because of a compilation error. We did not
detect that until merged into master since the task run-benchmarks is
not required for merging into master.

` [ERR] RunBenchmarks:
C:\dd-trace-dotnet\tracer\test\benchmarks\Benchmarks.Trace\Asm\AppSecBenchmarkUtils.cs(79,47):
error CS7036: There is no argument given that corresponds to the
required parameter 'ddDotnetTracerHome' of
'WafLibraryInvoker.Initialize(string, string, string)'
[C:\dd-trace-dotnet\tracer\test\benchmarks\Benchmarks.Trace\Benchmarks.Trace.csproj::TargetFramework=net472]
    `
## Reason for change

## Implementation details

## Test coverage

## Other details
<!-- Fixes #{issue} -->


<!--  ⚠️ Note:

Where possible, please obtain 2 approvals prior to merging. Unless
CODEOWNERS specifies otherwise, for external teams it is typically best
to have one review from a team member, and one review from apm-dotnet.
Trivial changes do not require 2 reviews.

MergeQueue is NOT enabled in this repository. If you have write access
to the repo, the PR has 1-2 approvals (see above), and all of the
required checks have passed, you can use the Squash and Merge button to
merge the PR. If you don't have write access, or you need help, reach
out in the #apm-dotnet channel in Slack.
-->
@NachoEchevarria NachoEchevarria added type:performance Performance, speed, latency, resource usage (CPU, memory) area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) labels Jan 26, 2026
anna-git added a commit that referenced this pull request Jan 27, 2026
## Context

Part of **Configuration Inversion (Step 6)** - Stack progress:
1. [#7548](#7548) - Add
GitLab step and JSON configuration file
2. [#7688](#7688) -
Cleanup configuration / platform keys + source generator
3. [#7698](#7698) -
Aliases handling via source generator
4. [#7689](#7689) -
Analyzers for platform and ConfigurationBuilder
5. [#7931](#7931) -
Replace manual ConfigurationKeys by generated ones in the whole solution
6. [#7932](#7932) -
Forbid use of System.Environment methods and adapt everywhere
7. **→ [#7937](#7937) -
Integration names to generated keys (this PR)**
## Summary of changes

Extends the `EnumExtensionsGenerator` to generate
[IntegrationNameToKeys](cci:2://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/EnumExtensionsGenerator/IntegrationNameToKeys.g.cs:14:4-392:5)
class for the `IntegrationId` enum, providing centralized configuration
key mapping for integrations including enabled, analytics enabled, and
analytics sample rate keys. Also fixes AdoNet instrumentation
compilation error.

## Reason for change

- Eliminates code duplication in configuration key generation across the
codebase
- Provides compile-time safety for integration configuration key access
- Centralizes key pattern definitions with proper documentation
- Ensures consistency across all integration key formats (canonical,
mixed case, short aliases)

## Implementation details

- **Source Generator**: Extended `EnumExtensionsGenerator` with
[GenerateIntegrationNameToKeys](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace.SourceGenerators/EnumExtensions/Sources.cs:82:4-178:5)
method that generates:
- `AllIntegrationEnabledKeys` array containing all enabled configuration
keys
-
[GetIntegrationEnabledKeys(string)](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/EnumExtensionsGenerator/IntegrationNameToKeys.g.cs:102:8-197:9)
- returns enabled keys for an integration
-
[GetIntegrationAnalyticsEnabledKeys(string)](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/EnumExtensionsGenerator/IntegrationNameToKeys.g.cs:198:8-294:9)
- returns analytics enabled keys (marked obsolete)
-
[GetIntegrationAnalyticsSampleRateKeys(string)](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/EnumExtensionsGenerator/IntegrationNameToKeys.g.cs:295:8-391:9)
- returns analytics sample rate keys (marked obsolete)
- Key pattern constants (`IntegrationEnabledKeyPattern`,
`AnalyticsEnabledKeyPattern`, `AnalyticsSampleRateKeyPattern`)
- **Configuration**: Updated
[ConfigurationBuilder.WithIntegrationAnalyticsKey](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/ConfigurationSources/Telemetry/ConfigurationBuilder.cs:32:4-42:5)
and
[WithIntegrationAnalyticsSampleRateKey](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/src/Datadog.Trace/Configuration/ConfigurationSources/Telemetry/ConfigurationBuilder.cs:44:4-54:5)
to use generated methods

## Test coverage

- Added
[CanGenerateIntegrationNameToKeysForIntegrationId](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/test/Datadog.Trace.SourceGenerators.Tests/EnumExtensionsGeneratorTests.cs:411:4-527:5)
- verifies complete generated output with all three methods
- Added
[DoesNotGenerateIntegrationNameToKeysForNonIntegrationIdEnum](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/test/Datadog.Trace.SourceGenerators.Tests/EnumExtensionsGeneratorTests.cs:529:4-552:5)
- ensures generation only for `IntegrationId` enum
- Added
[IntegrationNameToKeysGeneratesCorrectKeyFormats](cci:1://file:///Users/anna.yafi/go/src/github.com/DataDog/dd-trace-dotnet3/tracer/test/Datadog.Trace.SourceGenerators.Tests/EnumExtensionsGeneratorTests.cs:554:4-670:5)
- validates key formats for various integration names
- All tests verify obsolete attributes, key patterns, and switch
expression logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) type:performance Performance, speed, latency, resource usage (CPU, memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants