[Runtime Metrics] Enables Runtime Metrics by Default for .NET 6+#8267
[Runtime Metrics] Enables Runtime Metrics by Default for .NET 6+#8267
Conversation
When DD_RUNTIME_METRICS_ENABLED is not explicitly set and the runtime is .NET 6+, default to enabled with the System.Diagnostics.Metrics-based collector. This avoids known EventPipe issues (dotnet/runtime#103480, dotnet/runtime#111368). Existing explicit configurations are preserved: - DD_RUNTIME_METRICS_ENABLED=true keeps EventListener unless DD_RUNTIME_METRICS_DIAGNOSTICS_METRICS_API_ENABLED is also set. - DD_RUNTIME_METRICS_ENABLED=false remains disabled. Also fix RuntimeMetricsWriter to dispose DiagnosticsMetricsRuntimeMetricsListener on .NET 6+ (MeterListener is safe to dispose, unlike EventListener). Made-with: Cursor
Made-with: Cursor
BenchmarksBenchmark execution time: 2026-03-05 17:54:25 Comparing candidate commit febef96 in PR branch Found 11 performance improvements and 7 performance regressions! Performance is the same for 160 metrics, 14 unstable metrics. scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0
scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8267) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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:
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 chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (77ms) : 74, 79
master - mean (74ms) : 72, 76
section Bailout
This PR (8267) - mean (81ms) : 79, 84
master - mean (78ms) : 76, 80
section CallTarget+Inlining+NGEN
This PR (8267) - mean (1,102ms) : 1054, 1149
master - mean (1,075ms) : 1032, 1119
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 (8267) - mean (118ms) : 115, 122
master - mean (114ms) : 110, 118
section Bailout
This PR (8267) - mean (119ms) : 117, 122
master - mean (115ms) : 113, 118
section CallTarget+Inlining+NGEN
This PR (8267) - mean (773ms) : 724, 822
master - mean (784ms) : 738, 830
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (107ms) : 103, 111
master - mean (102ms) : 99, 106
section Bailout
This PR (8267) - mean (108ms) : 106, 111
master - mean (104ms) : 101, 106
section CallTarget+Inlining+NGEN
This PR (8267) - mean (777ms) : 701, 853
master - mean (762ms) : 707, 818
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (105ms) : 101, 109
master - mean (100ms) : 97, 103
section Bailout
This PR (8267) - mean (106ms) : 104, 109
master - mean (102ms) : 100, 104
section CallTarget+Inlining+NGEN
This PR (8267) - mean (710ms) : 667, 752
master - mean (680ms) : 653, 707
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 (8267) - mean (198ms) : 192, 204
master - mean (195ms) : 191, 199
section Bailout
This PR (8267) - mean (201ms) : 196, 206
master - mean (198ms) : 195, 202
section CallTarget+Inlining+NGEN
This PR (8267) - mean (1,164ms) : 1104, 1225
master - mean (1,155ms) : 1103, 1207
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 (8267) - mean (282ms) : 271, 293
master - mean (280ms) : 275, 285
section Bailout
This PR (8267) - mean (281ms) : 277, 285
master - mean (280ms) : 275, 285
section CallTarget+Inlining+NGEN
This PR (8267) - mean (940ms) : 887, 992
master - mean (948ms) : 904, 992
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (274ms) : 268, 280
master - mean (271ms) : 265, 276
section Bailout
This PR (8267) - mean (273ms) : 268, 277
master - mean (271ms) : 267, 276
section CallTarget+Inlining+NGEN
This PR (8267) - mean (940ms) : 863, 1017
master - mean (942ms) : 908, 976
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (273ms) : 267, 280
master - mean (272ms) : 266, 278
section Bailout
This PR (8267) - mean (273ms) : 266, 279
master - mean (271ms) : 267, 276
section CallTarget+Inlining+NGEN
This PR (8267) - mean (852ms) : 816, 888
master - mean (834ms) : 812, 856
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
andrewlock
left a comment
There was a problem hiding this comment.
LGTM, just some minor suggestions on wording and cleanup
tracer/src/Datadog.Trace/Configuration/supported-configurations.yaml
Outdated
Show resolved
Hide resolved
tracer/src/Datadog.Trace/Configuration/supported-configurations.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: febef96826
ℹ️ 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".
| } | ||
|
|
||
| #if NET6_0_OR_GREATER | ||
| RuntimeMetricsEnabled = runtimeMetricsEnabledResult.WithDefault(true); |
There was a problem hiding this comment.
Honor OTEL_METRICS_EXPORTER when defaulting runtime metrics
This new default unconditionally enables runtime metrics on .NET 6+ whenever DD_RUNTIME_METRICS_ENABLED is unset, which means OTEL_METRICS_EXPORTER=none no longer disables runtime metrics in that common “OTel-only” configuration. Because OTEL_METRICS_EXPORTER is still parsed above for overlap/validation, users who previously relied on none to suppress metric emission will now unexpectedly start RuntimeMetricsWriter and emit DogStatsD runtime metrics.
Useful? React with 👍 / 👎.
| // to avoid EventPipe crash/leak issues (dotnet/runtime#103480, dotnet/runtime#111368). | ||
| // Explicit DD_RUNTIME_METRICS_ENABLED=true users on .NET 6/7 keep EventListener | ||
| // to preserve ASP.NET Core EventCounter metrics not available via Diagnostics on < .NET 8. | ||
| var diagnosticsDefault = !runtimeMetricsEnabledResult.ConfigurationResult.IsPresent || FrameworkDescription.Instance.RuntimeVersion.Major >= 8; |
There was a problem hiding this comment.
Treat invalid DD_RUNTIME_METRICS_ENABLED as unset here
The diagnostics-listener default is keyed only on IsPresent, not validity, so on .NET 6/7 an invalid DD_RUNTIME_METRICS_ENABLED value (e.g., typo) falls back to RuntimeMetricsEnabled=true but computes diagnosticsDefault=false here. That pushes the process onto the RuntimeEventListener path instead of Diagnostics, reintroducing the EventPipe crash/leak risk this change is trying to avoid for defaulted configurations.
Useful? React with 👍 / 👎.
Summary of changes
Enable runtime metrics by default on .NET 6+ using the Diagnostics listener for services where the config is unset otherwise continue to use EventListener, and default existing explicit users to Diagnostics on .NET 8+ since there is no loss of ASP.NET Core Metrics.
Reason for change
Runtime metrics are currently opt-in. The EventListener/EventPipe implementation has known runtime bugs: shutdown crashes (dotnet/runtime#103480) and CPU/memory leaks (dotnet/runtime#111368). The Diagnostics listener avoids these and has comparable or better performance in our tests.
See RFC: Enabling .NET Runtime Metrics by Default — Option A.
Implementation details
Configuration logic for
DD_RUNTIME_METRICS_ENABLED:trueon .NET 6+Configuration logic for
DD_RUNTIME_METRICS_DIAGNOSTICS_METRICS_API_ENABLED:true(full metric coverage including ASP.NET Core meters)DD_RUNTIME_METRICS_ENABLEDnot set: defaults totrueDD_RUNTIME_METRICS_ENABLED=true: defaults tofalse(keeps EventListener to preserve ASP.NET Core EventCounter metrics)The .NET 8 check uses
Environment.Version.Major >= 8.Also fixes
RuntimeMetricsWriterto disposeDiagnosticsMetricsRuntimeMetricsListeneron .NET 6+ (MeterListeneris safe to dispose, unlikeEventListener).Test coverage
[InlineData]inRuntimeMetricsEnabledtest to expecttruewhen unset on .NET 6+.RuntimeMetrics_DefaultsToDignosticsOnNet6Plus_WhenNotExplicitlySet.RuntimeMetrics_ExplicitEnable_RespectsExplicitDiagnosticsFlag(explicittrue/falsecases).RuntimeMetrics_ExplicitEnable_DefaultsToDiagnosticsOnNet8Plus(net8.0 TFM).RuntimeMetrics_ExplicitEnable_DefaultsToEventListenerOnNet6And7(net6.0/net7.0 TFMs).RuntimeMetrics_ExplicitDisable_OverridesDefault.Other details
Part of Enabling .NET Runtime Metrics by Default. Should land after the PRs below are merged which include necessary fixes:
Moving forward
After this lands, monitor:
DD_RUNTIME_METRICS_ENABLEDandDD_RUNTIME_METRICS_DIAGNOSTICS_METRICS_API_ENABLEDusage to track adoption of the new defaults.contention_time, ASP.NET Core counters,compacting_gctag) after upgrading.DD_RUNTIME_METRICS_DIAGNOSTICS_METRICS_API_ENABLED=truefor all .NET 6+ in a later release once the .NET 6/7 EventCounter gap is documented and communicated.