Skip to content

Conversation

@andrewlock
Copy link
Member

@andrewlock andrewlock commented Oct 28, 2025

Summary of changes

  • This is the big one
  • Update services to dynamically update when mutable settings or exporter settings change
  • Stop rebuilding everything when there's manual/remote configuration

Reason for change

This is the "endpoint" that we've been heading for - services only being disposed/rebuilt at the end of the app, and otherwise only rebuilding the necessary parts. For example - we don't need to tear down all the API factories when a customer changes a global tag via remote config; they only need to change if the ExporterSettings change.

The hope is that overall this reduces the overhead of using configuration in code and/or remote configuration, while also reducing the number of issues due to managing disposal of services.

Implementation details

Overall, this PR is kind of a pain. Moving from the "rebuild everything" to "reconfigure each service" couldn't be done piecemeal, so this is the one-shot PR. What's more, different services need different patterns (though we can probably consolidate some of them, this has taken a lot of work and I likely changed patterns unnecessarily in some places).

In general, there's a couple of patterns:

  • CI Vis doesn't let you change settings at runtime, so it never needs to respond to changes. It always just uses the "initial" settings
  • Debugger today doesn't respond to changes at runtime (except its own dynamic config), so for now we ignore Debugger too as it's not really a regression. I hope we can fix this soon though.
  • I've introduced the concept of Managed* versions of some services
    • These services generally "wrap" the existing type, delegating access to the underlying service, and handling settings changes
  • Many services only care about a sub-set of mutable settings, so they only update if they need to
  • Somewhat annoyingly, setting updates occur on a background thread, so we need to be careful about thread safety. Where necessary (most places) I've made sure access to a now-mutable service is done using Volatile.Read() (to ensure changes are visible) and are generally cached to a local variable (as the underlying field may be updated in the background).

Test coverage

In the vast majority of places, this should be covered by existing tests

I plan to add some additional integration tests around reconfiguring and a bunch of manual testing to make sure I'm confident.

Other details

I strongly recommend reviewing commit-by-commit. They're generally self-contained, and hopefully simple enough to understand one commit at a time.

https://datadoghq.atlassian.net/browse/LANGPLAT-819

Part of a config stack

This isn't the final PR in the stack, as there will be a bunch of cleaning up to do, but it's the final "implementation" PR

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch 3 times, most recently from 2bc63f6 to 34f0d90 Compare October 28, 2025 15:02
@andrewlock andrewlock force-pushed the andrew/settings/5-move-mutable-settings-off-tracer-settings branch from e347879 to 8c472a5 Compare October 28, 2025 15:02
@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from 34f0d90 to f1e1c7e Compare October 28, 2025 15:20
@andrewlock andrewlock force-pushed the andrew/settings/5-move-mutable-settings-off-tracer-settings branch from 8c472a5 to 8e19e3a Compare October 28, 2025 15:20
@datadog-official

This comment has been minimized.

@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from f1e1c7e to c2b6a1c Compare October 28, 2025 18:13
@andrewlock andrewlock requested review from a team as code owners October 28, 2025 18:13
@andrewlock andrewlock requested review from link04 and removed request for a team October 28, 2025 18:13
@andrewlock andrewlock force-pushed the andrew/settings/5-move-mutable-settings-off-tracer-settings branch from 8e19e3a to 7940c31 Compare October 28, 2025 18:13
@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from c2b6a1c to 48c7644 Compare October 29, 2025 08:57
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Oct 29, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (7724) 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
duration74.77 ± (74.81 - 75.73) ms73.57 ± (73.54 - 74.23) ms-1.6%
.NET Framework 4.8 - Bailout
duration78.90 ± (78.98 - 79.69) ms77.57 ± (77.78 - 78.69) ms-1.7%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1092.49 ± (1092.97 - 1101.04) ms1096.10 ± (1098.18 - 1106.62) ms+0.3%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.98 ± (22.90 - 23.06) ms22.85 ± (22.78 - 22.92) ms-0.5%
process.time_to_main_ms87.58 ± (87.15 - 88.02) ms85.83 ± (85.44 - 86.22) ms-2.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.89 - 10.90) MB10.88 ± (10.87 - 10.88) MB-0.2%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.81 ± (22.74 - 22.87) ms22.73 ± (22.66 - 22.79) ms-0.4%
process.time_to_main_ms88.24 ± (87.90 - 88.57) ms87.34 ± (86.90 - 87.78) ms-1.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.93 - 10.94) MB10.91 ± (10.91 - 10.91) MB-0.2%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms220.11 ± (219.05 - 221.16) ms216.67 ± (215.31 - 218.03) ms-1.6%
process.time_to_main_ms545.21 ± (543.98 - 546.43) ms540.27 ± (539.15 - 541.40) ms-0.9%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed52.63 ± (52.61 - 52.65) MB52.61 ± (52.58 - 52.64) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms21.58 ± (21.51 - 21.65) ms21.61 ± (21.54 - 21.67) ms+0.1%✅⬆️
process.time_to_main_ms75.26 ± (74.94 - 75.57) ms73.92 ± (73.61 - 74.23) ms-1.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.60 ± (10.59 - 10.60) MB10.60 ± (10.59 - 10.60) MB-0.0%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.51 ± (21.45 - 21.57) ms21.44 ± (21.40 - 21.49) ms-0.3%
process.time_to_main_ms76.30 ± (75.94 - 76.65) ms74.71 ± (74.44 - 74.98) ms-2.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.65 ± (10.64 - 10.65) MB10.65 ± (10.64 - 10.65) MB+0.0%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms205.98 ± (204.54 - 207.43) ms203.83 ± (202.75 - 204.91) ms-1.0%
process.time_to_main_ms511.62 ± (510.83 - 512.41) ms502.68 ± (501.42 - 503.94) ms-1.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed51.76 ± (51.72 - 51.80) MB51.57 ± (51.52 - 51.63) MB-0.4%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms19.79 ± (19.72 - 19.85) ms19.69 ± (19.63 - 19.76) ms-0.5%
process.time_to_main_ms74.49 ± (74.16 - 74.81) ms73.08 ± (72.76 - 73.40) ms-1.9%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.66 - 7.67) MB7.63 ± (7.62 - 7.64) MB-0.4%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.73 ± (19.67 - 19.79) ms19.66 ± (19.59 - 19.72) ms-0.4%
process.time_to_main_ms75.27 ± (75.04 - 75.51) ms74.31 ± (74.01 - 74.61) ms-1.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.72 ± (7.71 - 7.72) MB7.67 ± (7.66 - 7.68) MB-0.6%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms188.43 ± (187.42 - 189.44) ms188.97 ± (187.91 - 190.03) ms+0.3%✅⬆️
process.time_to_main_ms486.98 ± (485.97 - 487.99) ms476.48 ± (475.59 - 477.38) ms-2.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed38.98 ± (38.94 - 39.02) MB38.68 ± (38.64 - 38.71) MB-0.8%
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.0%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration191.32 ± (190.93 - 191.68) ms192.16 ± (191.97 - 192.78) ms+0.4%✅⬆️
.NET Framework 4.8 - Bailout
duration194.71 ± (194.33 - 194.98) ms195.62 ± (195.38 - 195.99) ms+0.5%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1154.81 ± (1160.54 - 1170.47) ms1157.17 ± (1159.13 - 1165.78) ms+0.2%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms186.52 ± (186.14 - 186.89) ms187.17 ± (186.86 - 187.49) ms+0.4%✅⬆️
process.time_to_main_ms80.34 ± (80.11 - 80.57) ms80.68 ± (80.46 - 80.91) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.09 ± (16.06 - 16.12) MB16.04 ± (16.01 - 16.07) MB-0.3%
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)-0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms185.60 ± (185.25 - 185.95) ms187.07 ± (186.71 - 187.42) ms+0.8%✅⬆️
process.time_to_main_ms81.39 ± (81.21 - 81.56) ms82.01 ± (81.85 - 82.17) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.17 ± (16.14 - 16.20) MB16.10 ± (16.07 - 16.12) MB-0.5%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)-0.5%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms392.07 ± (389.61 - 394.53) ms392.99 ± (390.67 - 395.30) ms+0.2%✅⬆️
process.time_to_main_ms513.73 ± (513.00 - 514.45) ms517.30 ± (516.60 - 517.99) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed62.93 ± (62.78 - 63.09) MB62.95 ± (62.79 - 63.10) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms189.61 ± (189.18 - 190.04) ms190.69 ± (190.36 - 191.01) ms+0.6%✅⬆️
process.time_to_main_ms68.97 ± (68.79 - 69.16) ms69.19 ± (69.06 - 69.32) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed15.89 ± (15.73 - 16.05) MB15.84 ± (15.68 - 16.00) MB-0.3%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.6%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.35 ± (189.97 - 190.74) ms190.28 ± (190.02 - 190.55) ms-0.0%
process.time_to_main_ms70.44 ± (70.28 - 70.60) ms70.30 ± (70.19 - 70.41) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed15.90 ± (15.73 - 16.07) MB15.91 ± (15.74 - 16.07) MB+0.0%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.4%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms408.75 ± (405.58 - 411.92) ms402.83 ± (400.95 - 404.71) ms-1.4%
process.time_to_main_ms484.54 ± (483.98 - 485.10) ms478.71 ± (478.19 - 479.22) ms-1.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed62.00 ± (61.85 - 62.16) MB62.40 ± (62.27 - 62.54) MB+0.6%✅⬆️
runtime.dotnet.threads.count30 ± (29 - 30)29 ± (29 - 30)-0.0%
.NET 8 - Baseline
process.internal_duration_ms188.53 ± (188.15 - 188.91) ms189.29 ± (188.98 - 189.60) ms+0.4%✅⬆️
process.time_to_main_ms68.92 ± (68.73 - 69.11) ms68.75 ± (68.60 - 68.90) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.72 ± (11.70 - 11.75) MB11.71 ± (11.67 - 11.74) MB-0.1%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.3%
.NET 8 - Bailout
process.internal_duration_ms188.68 ± (188.20 - 189.15) ms188.77 ± (188.38 - 189.15) ms+0.0%✅⬆️
process.time_to_main_ms69.88 ± (69.72 - 70.04) ms70.00 ± (69.86 - 70.14) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.76 ± (11.72 - 11.80) MB11.81 ± (11.78 - 11.84) MB+0.4%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.3%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms356.37 ± (354.86 - 357.88) ms358.29 ± (356.45 - 360.12) ms+0.5%✅⬆️
process.time_to_main_ms462.29 ± (461.64 - 462.95) ms455.42 ± (454.77 - 456.07) ms-1.5%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.49 ± (50.46 - 50.53) MB50.36 ± (50.33 - 50.39) MB-0.3%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
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 (7724) - mean (74ms)  : 69, 79
    master - mean (75ms)  : 68, 82

    section Bailout
    This PR (7724) - mean (78ms)  : 72, 85
    master - mean (79ms)  : 74, 84

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (1,102ms)  : 1042, 1163
    master - mean (1,097ms)  : 1039, 1155

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 (7724) - mean (116ms)  : 108, 123
    master - mean (118ms)  : 110, 126

    section Bailout
    This PR (7724) - mean (117ms)  : 108, 126
    master - mean (118ms)  : 113, 124

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (792ms)  : 762, 823
    master - mean (805ms)  : 777, 834

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7724) - mean (102ms)  : 96, 108
    master - mean (104ms)  : 98, 109

    section Bailout
    This PR (7724) - mean (103ms)  : 98, 107
    master - mean (105ms)  : 99, 111

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (735ms)  : 706, 764
    master - mean (759ms)  : 726, 792

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7724) - mean (101ms)  : 95, 107
    master - mean (103ms)  : 95, 111

    section Bailout
    This PR (7724) - mean (102ms)  : 96, 108
    master - mean (103ms)  : 98, 109

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (698ms)  : 668, 728
    master - mean (719ms)  : 694, 744

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 (7724) - mean (192ms)  : 188, 196
    master - mean (191ms)  : 188, 195

    section Bailout
    This PR (7724) - mean (196ms)  : 193, 199
    master - mean (195ms)  : 191, 198

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (1,162ms)  : 1114, 1211
    master - mean (1,166ms)  : 1090, 1241

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 (7724) - mean (276ms)  : 271, 281
    master - mean (275ms)  : 269, 281

    section Bailout
    This PR (7724) - mean (277ms)  : 272, 282
    master - mean (275ms)  : 271, 280

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (944ms)  : 898, 990
    master - mean (943ms)  : 904, 981

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7724) - mean (268ms)  : 263, 273
    master - mean (267ms)  : 261, 273

    section Bailout
    This PR (7724) - mean (268ms)  : 265, 272
    master - mean (269ms)  : 262, 276

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (911ms)  : 878, 945
    master - mean (925ms)  : 878, 973

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (7724) - mean (268ms)  : 263, 272
    master - mean (267ms)  : 261, 272

    section Bailout
    This PR (7724) - mean (268ms)  : 264, 273
    master - mean (268ms)  : 260, 275

    section CallTarget+Inlining+NGEN
    This PR (7724) - mean (845ms)  : 820, 870
    master - mean (849ms)  : 822, 877

Loading

Also:
- slight refactor of LogFormatter to reduce some allocation
- ignore "previous" when creating DirectLogSubmissionManager (seeing as that won't be a thing soon)
…n't respond to changes

I left it like this because the debugger already doesn't respond to changes like other services do
- Move statsd instance creation to separate factory
- Create a StatsdManager to handle automatic updating in response to setting changes
- Always create a statsd instance, as it's hard to know if we're _ever_ going to need one, and reduces some of the compexity
This isn't necessary with the current design, and it causes issues today
@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from 85a6731 to 5ee2a7f Compare November 6, 2025 08:32
@andrewlock andrewlock force-pushed the andrew/settings/5-move-mutable-settings-off-tracer-settings branch from 10c89c9 to 741db4f Compare November 6, 2025 08:32
@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from 5ee2a7f to 53d59b0 Compare November 6, 2025 11:54
Make sure we can't dispose a stats consumer that's in use (as it will throw)
Rework to use a "lease" mechanism to track usages
Make passing in a statsmanager required
@andrewlock andrewlock force-pushed the andrew/settings/5-remove-mutablesettings branch from 53d59b0 to 95e3713 Compare November 6, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants