[Debugger] Improve no capture reason in collection serializer#8746
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refines debugger snapshot serialization for collections so notCapturedReason is reported accurately at timeout/collection-size boundaries (especially when null items are skipped from JSON output), and adds targeted tests to lock in the corrected behavior.
Changes:
- Adjust collection enumeration accounting to track “visited” items separately from serialized JSON elements (so skipped null entries still count toward limits).
- Improve
notCapturedReasonselection fortimeoutandcollectionSize, avoiding false positives when enumeration has effectively completed. - Add focused unit tests covering exact-limit, null-item, oversized, and cancellation/timeout boundary scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tracer/src/Datadog.Trace/Debugger/Snapshots/DebuggerSnapshotSerializer.cs |
Updates collection enumeration logic and notCapturedReason computation for timeout/size limits. |
tracer/test/Datadog.Trace.Tests/Debugger/DebuggerSnapshotCreatorTests.cs |
Adds tests and helpers to validate boundary conditions for collection serialization limits and cancellation behavior. |
Comments suppressed due to low confidence (1)
tracer/src/Datadog.Trace/Debugger/Snapshots/DebuggerSnapshotSerializer.cs:398
enumeratedItemCountis incremented immediately afterMoveNext()succeeds, beforeCurrentis retrieved. IfCurrentthrows (e.g., collection modified during enumeration), the loop breaks withenumeratedItemCountpotentially equal toMaxCollectionSize, which can incorrectly setnotCapturedReasontocollectionSizeeven though enumeration stopped due to an error. Incrementing the counter only after successfully readingCurrentpreserves the intended "count visited items (including nulls)" behavior while avoiding misclassification onCurrentfailures.
try
{
if (!enumerator.MoveNext())
{
enumerationCompleted = true;
break;
}
enumeratedItemCount++;
}
catch (InvalidOperationException e)
{
Log.Error(e, "Error serializing enumerable when calling MoveNext. Error={Error}. Depth={CurrentDepth}", e.Message, property1: currentDepth);
break;
}
object current = null;
try
{
current = enumerator.Current;
}
catch (InvalidOperationException e)
{
Log.Error(e, "Error serializing enumerable when calling Current. Error={Error}. Depth={CurrentDepth}", e.Message, property1: currentDepth);
break;
}
if (current == null)
{
// skipping null element
continue;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8746) 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 (8746) - mean (73ms) : 71, 76
master - mean (74ms) : 71, 78
section Bailout
This PR (8746) - mean (77ms) : 75, 80
master - mean (78ms) : 75, 80
section CallTarget+Inlining+NGEN
This PR (8746) - mean (1,109ms) : 1047, 1171
master - mean (1,105ms) : 1051, 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 (8746) - mean (113ms) : 109, 116
master - mean (115ms) : 109, 121
section Bailout
This PR (8746) - mean (117ms) : 113, 122
master - mean (115ms) : 112, 118
section CallTarget+Inlining+NGEN
This PR (8746) - mean (792ms) : 765, 819
master - mean (798ms) : 772, 824
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8746) - mean (104ms) : 98, 109
master - mean (101ms) : 96, 105
section Bailout
This PR (8746) - mean (105ms) : 100, 110
master - mean (104ms) : 98, 109
section CallTarget+Inlining+NGEN
This PR (8746) - mean (955ms) : 913, 997
master - mean (944ms) : 904, 985
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8746) - mean (99ms) : 95, 102
master - mean (99ms) : 95, 103
section Bailout
This PR (8746) - mean (104ms) : 99, 109
master - mean (100ms) : 98, 102
section CallTarget+Inlining+NGEN
This PR (8746) - mean (824ms) : 780, 868
master - mean (821ms) : 780, 862
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 (8746) - mean (199ms) : 193, 205
master - mean (199ms) : 192, 206
section Bailout
This PR (8746) - mean (202ms) : 199, 205
master - mean (204ms) : 199, 208
section CallTarget+Inlining+NGEN
This PR (8746) - mean (1,190ms) : 1151, 1229
master - mean (1,201ms) : 1156, 1246
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 (8746) - mean (284ms) : 275, 293
master - mean (288ms) : 281, 294
section Bailout
This PR (8746) - mean (286ms) : 277, 294
master - mean (289ms) : 283, 294
section CallTarget+Inlining+NGEN
This PR (8746) - mean (959ms) : 935, 984
master - mean (965ms) : 947, 982
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8746) - mean (276ms) : 271, 282
master - mean (281ms) : 275, 287
section Bailout
This PR (8746) - mean (277ms) : 270, 284
master - mean (280ms) : 276, 283
section CallTarget+Inlining+NGEN
This PR (8746) - mean (1,158ms) : 1121, 1196
master - mean (1,166ms) : 1122, 1210
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8746) - mean (275ms) : 269, 281
master - mean (277ms) : 271, 283
section Bailout
This PR (8746) - mean (275ms) : 268, 281
master - mean (277ms) : 271, 282
section CallTarget+Inlining+NGEN
This PR (8746) - mean (1,038ms) : 999, 1077
master - mean (1,038ms) : 1004, 1072
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-06-04 10:41:20 Comparing candidate commit 70152e6 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 71 metrics, 0 unstable metrics, 62 known flaky benchmarks, 64 flaky benchmarks without significant changes.
|
Summary of changes
DebuggerSnapshotSerializer.timeoutorcollectionSizewhen all collection items were already visited.Reason for change
notCapturedReasonvalues around timeout and collection-size boundaries.maxCollectionSize.Implementation details
ICollection.Countas the source of truth for total collection size.Test coverage
DebuggerSnapshotCreatorTests.Limits_CollectionDebuggerSnapshotCreatorTests.ObjectStructure_EmptyArray|DebuggerSnapshotCreatorTests.ObjectStructure_EmptyList|DebuggerSnapshotCreatorTests.Limits_LargeCollection