Skip to content

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
duration68.36 ± (68.34 - 68.56) ms68.40 ± (68.42 - 68.63) ms+0.0%✅⬆️
.NET Framework 4.8 - Bailout
duration72.26 ± (72.17 - 72.38) ms72.25 ± (72.18 - 72.44) ms-0.0%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1001.90 ± (1004.29 - 1009.74) ms1007.66 ± (1012.22 - 1021.54) ms+0.6%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.86 ± (21.82 - 21.89) ms21.97 ± (21.94 - 21.99) ms+0.5%✅⬆️
process.time_to_main_ms78.50 ± (78.39 - 78.62) ms78.74 ± (78.59 - 78.88) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.92 ± (10.92 - 10.93) MB10.94 ± (10.94 - 10.95) MB+0.1%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.72 ± (21.70 - 21.74) ms21.81 ± (21.79 - 21.83) ms+0.4%✅⬆️
process.time_to_main_ms79.77 ± (79.69 - 79.85) ms79.92 ± (79.81 - 80.02) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.96 ± (10.96 - 10.97) MB10.95 ± (10.95 - 10.96) MB-0.1%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms238.76 ± (234.48 - 243.04) ms237.87 ± (233.60 - 242.15) ms-0.4%
process.time_to_main_ms470.07 ± (469.61 - 470.54) ms473.63 ± (473.01 - 474.25) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.16 ± (48.14 - 48.18) MB48.22 ± (48.19 - 48.24) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.6%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms20.65 ± (20.62 - 20.67) ms20.57 ± (20.53 - 20.60) ms-0.4%
process.time_to_main_ms68.13 ± (68.02 - 68.25) ms68.04 ± (67.92 - 68.16) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.62) MB10.62 ± (10.62 - 10.63) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.52 ± (20.49 - 20.55) ms20.46 ± (20.44 - 20.48) ms-0.3%
process.time_to_main_ms68.84 ± (68.78 - 68.91) ms68.90 ± (68.84 - 68.95) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.67 ± (10.66 - 10.67) MB10.72 ± (10.72 - 10.73) MB+0.5%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms243.38 ± (241.04 - 245.73) ms245.01 ± (242.91 - 247.11) ms+0.7%✅⬆️
process.time_to_main_ms440.19 ± (439.71 - 440.67) ms441.50 ± (440.97 - 442.03) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.68 ± (48.64 - 48.72) MB48.67 ± (48.64 - 48.70) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.6%
.NET 8 - Baseline
process.internal_duration_ms18.87 ± (18.85 - 18.89) ms18.80 ± (18.78 - 18.83) ms-0.4%
process.time_to_main_ms67.15 ± (67.04 - 67.26) ms67.53 ± (67.41 - 67.64) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.68 ± (7.67 - 7.69) MB7.66 ± (7.66 - 7.67) MB-0.2%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.84 ± (18.81 - 18.88) ms18.80 ± (18.77 - 18.83) ms-0.2%
process.time_to_main_ms68.41 ± (68.32 - 68.49) ms68.41 ± (68.34 - 68.49) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.78 ± (7.77 - 7.80) MB7.72 ± (7.71 - 7.73) MB-0.8%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms178.81 ± (177.79 - 179.82) ms179.38 ± (178.52 - 180.24) ms+0.3%✅⬆️
process.time_to_main_ms425.88 ± (425.21 - 426.55) ms426.62 ± (426.06 - 427.18) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.32 ± (36.29 - 36.35) MB36.33 ± (36.30 - 36.36) MB+0.0%✅⬆️
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.44 ± (192.48 - 193.29) ms192.98 ± (192.97 - 193.85) ms+0.3%✅⬆️
.NET Framework 4.8 - Bailout
duration196.57 ± (196.32 - 197.20) ms196.58 ± (196.35 - 197.02) ms+0.0%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1108.14 ± (1109.67 - 1117.15) ms1109.90 ± (1113.02 - 1121.10) ms+0.2%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms188.47 ± (188.07 - 188.88) ms187.35 ± (187.07 - 187.63) ms-0.6%
process.time_to_main_ms80.38 ± (80.14 - 80.63) ms80.04 ± (79.87 - 80.20) ms-0.4%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.04 ± (16.01 - 16.06) MB16.09 ± (16.06 - 16.11) MB+0.3%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms186.71 ± (186.44 - 186.98) ms186.99 ± (186.66 - 187.32) ms+0.2%✅⬆️
process.time_to_main_ms81.18 ± (81.07 - 81.30) ms81.68 ± (81.54 - 81.83) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.15) MB16.23 ± (16.20 - 16.26) MB+0.7%✅⬆️
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (21 - 21)+0.4%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms419.43 ± (416.11 - 422.74) ms418.73 ± (415.54 - 421.93) ms-0.2%
process.time_to_main_ms475.41 ± (474.77 - 476.05) ms476.79 ± (475.94 - 477.63) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.63 ± (58.51 - 58.75) MB58.81 ± (58.71 - 58.91) MB+0.3%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 30)29 ± (29 - 30)-0.0%
.NET 6 - Baseline
process.internal_duration_ms192.23 ± (191.89 - 192.56) ms192.27 ± (191.93 - 192.60) ms+0.0%✅⬆️
process.time_to_main_ms69.35 ± (69.19 - 69.51) ms69.42 ± (69.25 - 69.60) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.07 - 16.29) MB16.36 ± (16.28 - 16.44) MB+1.1%✅⬆️
runtime.dotnet.threads.count19 ± (18 - 19)19 ± (19 - 19)+0.4%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms191.25 ± (190.91 - 191.59) ms191.41 ± (191.15 - 191.67) ms+0.1%✅⬆️
process.time_to_main_ms70.22 ± (70.11 - 70.33) ms70.32 ± (70.22 - 70.41) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.05 - 16.30) MB16.29 ± (16.17 - 16.42) MB+0.7%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.9%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms450.67 ± (447.64 - 453.71) ms451.53 ± (448.62 - 454.43) ms+0.2%✅⬆️
process.time_to_main_ms444.57 ± (444.07 - 445.08) ms445.22 ± (444.71 - 445.72) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.49 ± (58.37 - 58.61) MB58.35 ± (58.23 - 58.48) MB-0.2%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (29 - 30)-0.1%
.NET 8 - Baseline
process.internal_duration_ms190.31 ± (189.98 - 190.64) ms189.75 ± (189.50 - 190.00) ms-0.3%
process.time_to_main_ms68.94 ± (68.77 - 69.11) ms68.86 ± (68.68 - 69.03) ms-0.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.78 ± (11.74 - 11.81) MB11.76 ± (11.73 - 11.79) MB-0.1%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.2%
.NET 8 - Bailout
process.internal_duration_ms189.74 ± (189.47 - 190.01) ms189.86 ± (189.51 - 190.20) ms+0.1%✅⬆️
process.time_to_main_ms70.02 ± (69.92 - 70.12) ms70.16 ± (70.03 - 70.29) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.85 ± (11.80 - 11.90) MB11.79 ± (11.77 - 11.82) MB-0.5%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+2.5%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms363.34 ± (361.99 - 364.68) ms362.92 ± (361.32 - 364.53) ms-0.1%
process.time_to_main_ms428.47 ± (427.79 - 429.14) ms428.51 ± (427.96 - 429.07) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.93 ± (47.90 - 47.96) MB47.97 ± (47.94 - 48.01) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (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 (69ms)  : 67, 70
    master - mean (68ms)  : 67, 70

    section Bailout
    This PR (7932) - mean (72ms)  : 71, 74
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (1,017ms)  : 951, 1083
    master - mean (1,007ms)  : 967, 1047

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 (106ms)  : 104, 108
    master - mean (106ms)  : 103, 108

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

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (735ms)  : 663, 806
    master - mean (735ms)  : 672, 799

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7932) - mean (93ms)  : 91, 95
    master - mean (94ms)  : 92, 96

    section Bailout
    This PR (7932) - mean (94ms)  : 93, 95
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (711ms)  : 671, 750
    master - mean (709ms)  : 672, 747

Loading
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, 95
    master - mean (92ms)  : 90, 94

    section Bailout
    This PR (7932) - mean (93ms)  : 92, 94
    master - mean (93ms)  : 92, 95

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (634ms)  : 618, 650
    master - mean (633ms)  : 616, 650

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 (193ms)  : 189, 198
    master - mean (193ms)  : 189, 197

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

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (1,117ms)  : 1058, 1176
    master - mean (1,113ms)  : 1058, 1169

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 (276ms)  : 272, 280
    master - mean (277ms)  : 271, 282

    section Bailout
    This PR (7932) - mean (277ms)  : 273, 281
    master - mean (276ms)  : 273, 279

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (927ms)  : 877, 976
    master - mean (922ms)  : 871, 974

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

    section Bailout
    This PR (7932) - mean (270ms)  : 267, 273
    master - mean (269ms)  : 264, 274

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (922ms)  : 873, 971
    master - mean (923ms)  : 874, 972

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

    section Bailout
    This PR (7932) - mean (269ms)  : 264, 274
    master - mean (269ms)  : 265, 272

    section CallTarget+Inlining+NGEN
    This PR (7932) - mean (822ms)  : 803, 841
    master - mean (822ms)  : 800, 845

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 <[email protected]>
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 2 times, most recently from f164b06 to 756c6b3 Compare January 5, 2026 14:27
Copy link
Contributor

@GreenMatan GreenMatan left a comment

Choose a reason for hiding this comment

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

reviewed debugger related code change

@anna-git anna-git changed the title [Config Registry] 6/7 Forbid use of System.Environment methods and adapt everywhere [Config Registry] 6/8 Forbid use of System.Environment methods and adapt everywhere Jan 8, 2026
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch 2 times, most recently from 60360fa to 6e67a5d Compare January 9, 2026 10:26
@anna-git anna-git force-pushed the anna/config-inversion-prevent-direct-env-use-6 branch from 6e67a5d to 7e8b0c6 Compare January 9, 2026 12:33
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.

4 participants