Add a new single-span diagnostic observer for ASP.NET Core#7964
Add a new single-span diagnostic observer for ASP.NET Core#7964andrewlock merged 11 commits intomasterfrom
Conversation
|
bdd3a0f to
88205c8
Compare
tracer/src/Datadog.Trace/Configuration/supported-configurations-docs.yaml
Outdated
Show resolved
Hide resolved
tracer/src/Datadog.Trace/Configuration/configuration_keys_mapping.json
Outdated
Show resolved
Hide resolved
## Summary of changes Adds a `ValueStringBuilder` implementation, based on the one used internally in the .NET runtime ## Reason for change - We can stackalloc the `Span<char>` - It's a bit faster than our existing `StringBuilderCache` implementation, and in some places that matters. ## Implementation details - Made in .NET 6 only for simplicity. We _could_ expose it earlier, but I wanted this for the updated aspnetcore integration, so .NET6+ only for now is good enough - It's not without risks in its usage, so we have to be careful about things like passing it around (i.e. avoid doing that completely, for safety) - Uses an array pool backed implementation (again, built into .NET 6) ## Test coverage Imported the unit tests from the runtime too ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-842 Part of a stack - #7962 👈 - #7963 - #7964 - #7966 - #7965
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (7964) 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 (7964) - mean (68ms) : 67, 70
master - mean (69ms) : 66, 71
section Bailout
This PR (7964) - mean (72ms) : 71, 73
master - mean (72ms) : 71, 73
section CallTarget+Inlining+NGEN
This PR (7964) - mean (1,012ms) : 954, 1071
master - mean (1,005ms) : 969, 1041
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 (7964) - mean (106ms) : 103, 109
master - mean (106ms) : 102, 110
section Bailout
This PR (7964) - mean (107ms) : 106, 108
master - mean (107ms) : 105, 108
section CallTarget+Inlining+NGEN
This PR (7964) - mean (746ms) : 689, 803
master - mean (744ms) : 687, 802
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7964) - mean (93ms) : 91, 96
master - mean (94ms) : 91, 96
section Bailout
This PR (7964) - mean (94ms) : 93, 95
master - mean (94ms) : 93, 95
section CallTarget+Inlining+NGEN
This PR (7964) - mean (711ms) : 683, 740
master - mean (707ms) : 676, 738
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7964) - mean (92ms) : 89, 96
master - mean (92ms) : 89, 94
section Bailout
This PR (7964) - mean (93ms) : 92, 95
master - mean (93ms) : 92, 94
section CallTarget+Inlining+NGEN
This PR (7964) - mean (631ms) : 617, 644
master - mean (633ms) : 617, 649
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 (7964) - mean (192ms) : 188, 197
master - mean (193ms) : 189, 197
section Bailout
This PR (7964) - mean (196ms) : 192, 199
master - mean (195ms) : 193, 198
section CallTarget+Inlining+NGEN
This PR (7964) - mean (1,109ms) : 1059, 1160
master - mean (1,104ms) : 1055, 1153
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 (7964) - mean (276ms) : 270, 282
master - mean (274ms) : 269, 280
section Bailout
This PR (7964) - mean (277ms) : 272, 282
master - mean (276ms) : 273, 280
section CallTarget+Inlining+NGEN
This PR (7964) - mean (931ms) : 891, 970
master - mean (926ms) : 880, 972
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7964) - mean (270ms) : 264, 276
master - mean (268ms) : 263, 273
section Bailout
This PR (7964) - mean (269ms) : 265, 272
master - mean (268ms) : 264, 272
section CallTarget+Inlining+NGEN
This PR (7964) - mean (928ms) : 890, 966
master - mean (926ms) : 895, 956
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7964) - mean (273ms) : 264, 281
master - mean (267ms) : 262, 272
section Bailout
This PR (7964) - mean (274ms) : 264, 283
master - mean (267ms) : 264, 270
section CallTarget+Inlining+NGEN
This PR (7964) - mean (826ms) : 802, 851
master - mean (820ms) : 802, 838
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
00fe314 to
e8369e2
Compare
bc14e1f to
accaca2
Compare
BenchmarksBenchmark execution time: 2026-01-05 09:18:46 Comparing candidate commit de692e8 in PR branch Found 6 performance improvements and 3 performance regressions! Performance is the same for 159 metrics, 18 unstable metrics. scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
|
e8369e2 to
bb0fb1b
Compare
accaca2 to
383da45
Compare
## Summary of changes Small perf tweaks for existing `AspNetCoreDiagnosticObserver` ## Reason for change While experimenting with single span observer, noticed some (safe) tweaks we could make to the existing implementation. There are some other improvements we could make as well, but those are a little riskier, so may be best to delay them. ## Implementation details - Use `HttpContext.Items[string]` instead of `HttpContext.Features.Get<T>` as it's a bit faster - Make `Tracer`/`Security`/`Iast` inputs readonly, instead of using a null-coalesce with every access - Move check outside of `AddHeaderTagsToSpan` given common case is to avoid the function call ## Test coverage Covered by existing tests ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-842 Part of a stack - #7962 - #7963 👈 - #7964 - #7966 - #7965
a356866 to
04d208f
Compare
Co-authored-by: Lucas Pimentel <lucas.pimentel@datadoghq.com>
04d208f to
de692e8
Compare
GreenMatan
left a comment
There was a problem hiding this comment.
Left a comment regarding code duplication
tracer/src/Datadog.Trace/DiagnosticListeners/SingleSpanAspNetCoreDiagnosticObserver.cs
Show resolved
Hide resolved
## Summary of changes Creates an optimized version of `AspNetCoreResourceNameHelper` for use by the single-span Diagnostic observer. ## Reason for change We have the opportunity for a variety of optimizations thanks to not creating the MVC span, and the fact that we're .NET 6+. We could potentially include some or all of these optimizations in the existing observer path, but for safety/simplicity I'd rather keep it isolated for now, and we can look at expanding it more broadly later ## Implementation details - Use the `ValueStringBuilder` to build a resource name - Don't pre-grab MVC route values, wait to see if we have route params from them first - Write directly into the builder as `ToLowerInvariant`, instead of doing an extra ToLower() at the end ## Test coverage Added unit tests that use the existing data for the other implementations, to confirm it's identical. It's also covered indirectly by the integration tests ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-842 Part of a stack - #7962 - #7963 - #7964 - #7966 👈 - #7965
…7965) ## Summary of changes Adds a micro and macro benchmark for the new observer ## Reason for change Want to verify that it has performance benefits ## Implementation details - Added new scenario for macro - Duplicated existing scenario for micro and run. I would like to have had these as the same methods, but the "global" nature of diagnostic observers makes this difficult I think. ## Test coverage I'll manually trigger a run of the macro ## Other details https://datadoghq.atlassian.net/browse/LANGPLAT-842 Part of a stack - #7962 - #7963 - #7964 - #7966 - #7965 👈
Summary of changes
Adds a new
DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLEDin which we omit the MVC spanReason for change
Implementation details
DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLEDfor opting in to the new behaviour.Test coverage
Other details
https://datadoghq.atlassian.net/browse/LANGPLAT-842
Part of a stack
ValueStringBuilderfor .NET 6 #7962AspNetCoreDiagnosticObserver#7963AspNetCoreResourceNameHelper#7966I experimented with some other perf improvements, but they didn't provide a significant improvement, so I reverted:
IEndpointMetadatacollection. The work to do that was too much, and you can't cache in some cases anyway so not worth itWebTagsout to remove the IP headers unless we need them. They're disabled by default, so it just increase the size of the tags object, but wasn't a big enough improvement to make the complexity worth it.RequestTrackingFeatureobjects. This one may actually be worth exploring again later, but I didn't see any improvement in my testing, as they're just not very big and only last 1 request.