[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-13 21:08:46 Comparing candidate commit b063425 in PR branch Found 9 performance improvements and 9 performance regressions! Performance is the same for 163 metrics, 11 unstable metrics. scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1
scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
scenario:Benchmarks.Trace.NLogBenchmark.EnrichedLog net6.0
scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1
scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1
|
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 (75ms) : 73, 77
master - mean (76ms) : 74, 77
section Bailout
This PR (8267) - mean (80ms) : 77, 82
master - mean (81ms) : 78, 84
section CallTarget+Inlining+NGEN
This PR (8267) - mean (1,095ms) : 1050, 1139
master - mean (1,111ms) : 1064, 1158
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) : 114, 121
master - mean (119ms) : 116, 122
section Bailout
This PR (8267) - mean (120ms) : 117, 122
master - mean (120ms) : 117, 123
section CallTarget+Inlining+NGEN
This PR (8267) - mean (765ms) : 741, 788
master - mean (767ms) : 745, 789
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (104ms) : 101, 107
master - mean (105ms) : 102, 107
section Bailout
This PR (8267) - mean (106ms) : 103, 109
master - mean (106ms) : 103, 109
section CallTarget+Inlining+NGEN
This PR (8267) - mean (747ms) : 706, 788
master - mean (735ms) : 692, 778
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (103ms) : 100, 106
master - mean (104ms) : 101, 107
section Bailout
This PR (8267) - mean (104ms) : 101, 106
master - mean (106ms) : 103, 108
section CallTarget+Inlining+NGEN
This PR (8267) - mean (687ms) : 662, 712
master - mean (669ms) : 648, 690
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 (195ms) : 190, 200
master - mean (194ms) : 189, 200
section Bailout
This PR (8267) - mean (198ms) : 195, 201
master - mean (198ms) : 194, 202
section CallTarget+Inlining+NGEN
This PR (8267) - mean (1,164ms) : 1100, 1228
master - mean (1,156ms) : 1094, 1218
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 (279ms) : 270, 287
master - mean (279ms) : 273, 285
section Bailout
This PR (8267) - mean (284ms) : 274, 294
master - mean (278ms) : 274, 282
section CallTarget+Inlining+NGEN
This PR (8267) - mean (913ms) : 877, 949
master - mean (903ms) : 868, 938
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (275ms) : 265, 286
master - mean (272ms) : 266, 278
section Bailout
This PR (8267) - mean (273ms) : 268, 278
master - mean (273ms) : 268, 277
section CallTarget+Inlining+NGEN
This PR (8267) - mean (942ms) : 910, 974
master - mean (916ms) : 884, 948
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8267) - mean (271ms) : 265, 277
master - mean (271ms) : 265, 276
section Bailout
This PR (8267) - mean (269ms) : 265, 272
master - mean (270ms) : 266, 274
section CallTarget+Inlining+NGEN
This PR (8267) - mean (837ms) : 806, 869
master - mean (825ms) : 801, 849
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
andrewlock
left a comment
There was a problem hiding this comment.
LGTM, just some minor suggestions on wording and cleanup
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".
zacharycmontoya
left a comment
There was a problem hiding this comment.
Looks good! I have some small comments that I'd like to see resolved and incorporated before merging
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).The runtime metrics collector selected depends on the runtime version and whether
DD_RUNTIME_METRICS_ENABLEDwas explicitly configured:DD_RUNTIME_METRICS_ENABLEDtruetrue(explicit)falseOTEL_METRICS_EXPORTER=noneNote for .NET 6/7 users who explicitly set
DD_RUNTIME_METRICS_ENABLED=trueand want to opt into the new Diagnostics-based collector (at the cost of losing ASP.NET Core EventCounter metrics): also setDD_RUNTIME_METRICS_DIAGNOSTICS_METRICS_API_ENABLED=true.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.