Create `SettingsManager` for managing mutable settings and ExporterSettings by andrewlock · Pull Request #7695 · DataDog/dd-trace-dotnet
andrewlock added a commit that referenced this pull request
Oct 22, 2025…tIntegrationAnalyticsSampleRate()` (#7544) ## Summary of changes Fix usages of `IsIntegrationEnabled()`, `IsErrorStatusCode()`, and `GetIntegrationAnalyticsSampleRate()` to use `MutableSettings` instead of `TracerSettings` ## Reason for change These functions are dependent on `MutableSettings`, and are exposed there, so making sure we call the methods there, and remove the delegation from `TracerSettings` entirely. ## Implementation details - Find and replace usages - Remove the old delegating methods ## Test coverage Just a refactor, so covered by existing tests ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-819 Part of a config stack - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 👈 - #7695
Base automatically changed from andrew/settings/4b-fix-integration-enabled to master
October 22, 2025 12:16
andrewlock
changed the base branch from
master
to
andrew/settings/4b-helper
This was referenced
Oct 28, 2025This was referenced
Oct 28, 2025
andrewlock
deleted the
andrew/settings/4-mutable-settings-service
branch
andrewlock added a commit that referenced this pull request
Nov 26, 2025…7723) ## Summary of changes Instead of exposing settings like `ServiceVerion` and `Environment` on `TracerSettings`, only expose them on `MutableSettings` ## Reason for change This is all part of the refactoring towards having `TracerSettings` being an immutable settings object, that's created once on app startup, and fixed for the lifetime. `ServiceVerion` and `Environment` currently delegate to the `MutableSettings` object stored on `TracerSettings`, but are going to move that elsewhere shortly so that consumers can subscribe to changes ## Implementation details For this PR, it's just a case of changing `TracerSettings.XXX` => `TracerSettings.Mutable.XXX`. A future PR will then subsequently "fix" these usages properly. This is just a small step to be able to remove the mutable properties from `TracerSettings` ## Test coverage Just a refactoring, covered by existing tests. ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-819 Part of a config stack - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 - #7721 - #7722 - #7695 - #7723 👈 - #7724 - #7796
andrewlock added a commit that referenced this pull request
Nov 26, 2025… config changes (#7796) ## Summary of changes A fix for #7724 to handle telemetry reporting in dynamic config "reset" scenarios ## Reason for change The system tests for #7724 were failing in some dynamic configuration scenarios. Specifically, the tests were sending remote config _without_ any configuration values "i.e. 'reset to use defaults'" and were waiting a telemetry update. However, we never sent it, because there was "no telemetry to record". Note that we _did_ correctly apply the new configuration, we just didn't report the telemetry correctly, primarily due to limitations in the telemetry protocol. This PR adds a fix for that, and will be merged into #7724. ## Implementation details The solution is to "remember" the telemetry from the default mutable configuration values, _without_ any dynamic sources, and "replay" this telemetry when we update telemetry. This feels kind of hacky, but it's something I suspected we might need to do, and had been avoiding up to this point because we do a "full reconfigure" anyway. ## Test coverage Added a specific unit test that mimics the behaviour of the system-test (i.e. an "empty" dynamic config response) and confirms the telemetry is recorded as expected ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-819 Part of a config stack - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 - #7721 - #7722 - #7695 - #7723 - #7724 - #7796 👈 Unlike other PRs in the stack, I'll merge this directly into #7724 to fix the tests there, just thought I'd keep this separate for easier reviewing
andrewlock added a commit that referenced this pull request
Nov 26, 2025… config changes (#7796) ## Summary of changes A fix for #7724 to handle telemetry reporting in dynamic config "reset" scenarios ## Reason for change The system tests for #7724 were failing in some dynamic configuration scenarios. Specifically, the tests were sending remote config _without_ any configuration values "i.e. 'reset to use defaults'" and were waiting a telemetry update. However, we never sent it, because there was "no telemetry to record". Note that we _did_ correctly apply the new configuration, we just didn't report the telemetry correctly, primarily due to limitations in the telemetry protocol. This PR adds a fix for that, and will be merged into #7724. ## Implementation details The solution is to "remember" the telemetry from the default mutable configuration values, _without_ any dynamic sources, and "replay" this telemetry when we update telemetry. This feels kind of hacky, but it's something I suspected we might need to do, and had been avoiding up to this point because we do a "full reconfigure" anyway. ## Test coverage Added a specific unit test that mimics the behaviour of the system-test (i.e. an "empty" dynamic config response) and confirms the telemetry is recorded as expected ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-819 Part of a config stack - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 - #7721 - #7722 - #7695 - #7723 - #7724 - #7796 👈 Unlike other PRs in the stack, I'll merge this directly into #7724 to fix the tests there, just thought I'd keep this separate for easier reviewing
andrewlock added a commit that referenced this pull request
Nov 26, 2025…building (#7724) ## 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 - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 - #7721 - #7722 - #7695 - #7723 - #7724 👈 - #7796 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
andrewlock added a commit that referenced this pull request
Nov 27, 2025## Summary of changes Updates a couple of places where we're calling `Tracer.Instance` where we don't need to ## Reason for change In one of my other PRs I accidentally broke something that should _only_ have affected integration tests, but a bunch of unit tests broke. It highlighted where they were using `Tracer.Instance` and setting the global tracer for tests. In other places, it revealed that code that tests that _looked_ independent of other tests really wasn't... Calling `Tracer.Instance` potentially does a _lot_ of work, as it initializes the tracer. It's also hard to follow if we're making static calls out in places we don't need to. So just pass through the settings we want instead. ## Implementation details Instead of calling `Tracer.Instance.Settings`, use the value of `Tracer` or `TracerSettings` that's already available wherever possible. It makes the tests cleaner too. ## Test coverage Same coverage, just a bit cleaner ## Other details Included as part of the config stack, just because I already refactored some of this code, and can't be bothered to faff with merge conflicts: https://datadoghq.atlassian.net/browse/LANGPLAT-819 - #7522 - #7525 - #7530 - #7532 - #7543 - #7544 - #7721 - #7722 - #7695 - #7723 - #7724 - #7744 👈
andrewlock added a commit that referenced this pull request
Dec 9, 2025…Logger` logs injection (#7880) ## Summary of changes Fixes a bug where `ILogger` logs injection injects the wrong values when a customer changes service/env/version using manual instrumentation. ## Reason for change This has been a bug for a _long_ time. Basically we cache a `DatadogLoggingScope` instance on app startup, and then we _always_ use it for injection. If the settings change, we didn't refresh this value, and so would inject the wrong settings. A unit test confirmed this behaviour. ## Implementation details I opted for a simple fix for now, especially seeing as this hasn't been flagged as a bug in escalations etc - Store the current `MutableSettings` for the trace on the `DatadogLoggingScope` - When calling `AddScope`, check if the _current_ `MutableSettings` match the ones for the provided scope - If they do, use the cached logging scope - If they don't, create a new one, update the cached scope Overall, this works, as long as changes are one way, i.e. we don't have much overlap of traces with different MutableSettings. This probably won't be a problem, hence why I took this approach, but it feels a bit hacky. The other option is to expose the `_cachedFormat` on MutableSettings or `PerTraceSettings` directly instead, and then have `DatadogLoggingScope` grab the ambient `CurrentPerTraceSettings.Settings` value. This is a bit neater in that it removes the chance of ping-pong between logging scope instances if there are overlapping traces, but it's also a bit meh because it's moving very integration-specific stuff into somewhere more "global". But maybe this is just a facility we _should create 🤷♂️ What do people think? ## Test coverage Added unit tests. They fail before this PR, and pass afterwards ## Other details Noticed while I was looking for any fallout from #7695
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters