[Debugger] Fix safe ToString handling for debugger collections#8747
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR narrows debugger “safe string fallback” behavior by ensuring that collection/dictionary support does not imply it’s safe/appropriate to call ToString() when capturing debugger snapshots. This keeps Redaction.IsSafeToCallToString() focused on simple/scalar-like types and avoids accidentally treating supported collections as safe for ToString()-based serialization.
Changes:
- Removed the
IsSupportedCollection(type)condition fromRedaction.IsSafeToCallToString()so collection support no longer marks a type as safe forToString(). - Added unit tests asserting common collections/dictionaries are not safe for
ToString()fallback behavior.
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/Redaction.cs | Tightens IsSafeToCallToString() to simple/allowlisted scalar-like types only. |
| tracer/test/Datadog.Trace.Tests/Debugger/SupportedTypesServiceTests.cs | Adds coverage ensuring common collections/dictionaries are not considered safe for ToString(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
BenchmarksBenchmark execution time: 2026-06-04 11:18:42 Comparing candidate commit defda0b in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 71 metrics, 0 unstable metrics, 57 known flaky benchmarks, 69 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8747) 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 (8747) - mean (75ms) : 71, 79
master - mean (73ms) : 71, 75
section Bailout
This PR (8747) - mean (77ms) : 75, 80
master - mean (77ms) : 74, 81
section CallTarget+Inlining+NGEN
This PR (8747) - mean (1,109ms) : 1062, 1155
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 (8747) - mean (116ms) : 111, 121
master - mean (114ms) : 110, 117
section Bailout
This PR (8747) - mean (115ms) : 112, 118
master - mean (118ms) : 113, 124
section CallTarget+Inlining+NGEN
This PR (8747) - mean (798ms) : 776, 820
master - mean (794ms) : 773, 814
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8747) - mean (103ms) : 97, 109
master - mean (103ms) : 97, 109
section Bailout
This PR (8747) - mean (104ms) : 100, 109
master - mean (105ms) : 100, 109
section CallTarget+Inlining+NGEN
This PR (8747) - mean (946ms) : 911, 981
master - mean (949ms) : 912, 986
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8747) - mean (100ms) : 97, 104
master - mean (99ms) : 95, 102
section Bailout
This PR (8747) - mean (103ms) : 98, 108
master - mean (101ms) : 98, 103
section CallTarget+Inlining+NGEN
This PR (8747) - mean (826ms) : 779, 872
master - mean (827ms) : 778, 876
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 (8747) - mean (198ms) : 193, 203
master - mean (201ms) : 194, 208
section Bailout
This PR (8747) - mean (203ms) : 199, 208
master - mean (204ms) : 199, 209
section CallTarget+Inlining+NGEN
This PR (8747) - mean (1,205ms) : 1167, 1243
master - mean (1,202ms) : 1152, 1252
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 (8747) - mean (286ms) : 281, 292
master - mean (287ms) : 280, 295
section Bailout
This PR (8747) - mean (286ms) : 279, 293
master - mean (288ms) : 283, 292
section CallTarget+Inlining+NGEN
This PR (8747) - mean (963ms) : 944, 981
master - mean (965ms) : 947, 983
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8747) - mean (279ms) : 273, 284
master - mean (279ms) : 273, 284
section Bailout
This PR (8747) - mean (278ms) : 274, 283
master - mean (278ms) : 273, 282
section CallTarget+Inlining+NGEN
This PR (8747) - mean (1,162ms) : 1134, 1190
master - mean (1,157ms) : 1120, 1193
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8747) - mean (275ms) : 270, 281
master - mean (278ms) : 272, 283
section Bailout
This PR (8747) - mean (277ms) : 271, 283
master - mean (278ms) : 272, 284
section CallTarget+Inlining+NGEN
This PR (8747) - mean (1,036ms) : 991, 1081
master - mean (1,036ms) : 987, 1086
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary of changes
ToString()is safe to call.Redaction.IsSafeToCallToString()limited to simple types and explicitly allowlisted scalar-like types.ToString()for safe string fallback behavior.Reason for change
IsSafeToCallToString()was reusingIsSupportedCollection(), which mixed two separate concepts: whether a type can be structurally handled as a debugger collection, and whether callingToString()is safe/useful.Implementation details
IsSupportedCollection(type)check fromRedaction.IsSafeToCallToString().List<T>,HashSet<T>,Dictionary<TKey,TValue>,Hashtable, andConditionalWeakTable<TKey,TValue>.Test coverage
SupportedTypesServiceTestsDebuggerExpressionLanguageTestsDebuggerSnapshotCreatorTests