-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add DebuggerDisplay and DebuggerTypeProxy to Activity and related types #121054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: stephentoub <[email protected]>
|
What does it look like in the debugger after the changes? |
|
@copilot It seems that property names such as
|
Co-authored-by: tarekgh <[email protected]>
After the changes, the debugger shows: Debugger tooltip/watch window: Expanded view with DebuggerTypeProxy: The OperationName is immediately visible, and TagObjects, Baggage, Events, and Links are now easy to inspect as grouped collections.
Fixed in commit d8aab5d. Changes made:
The debugger now shows: ![Screenshot showing the updated debugger view with properly grouped collections] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the debugging experience for Activity and related types by adding DebuggerDisplay and DebuggerTypeProxy attributes, making it easier to inspect tracing information during debugging sessions.
Key changes:
- Added
DebuggerDisplayandDebuggerTypeProxytoActivityclass to surface OperationName, Id, and collections (TagObjects, Baggage, Events, Links) - Added
DebuggerDisplayattributes toActivityContext,ActivityLink, andActivityEventstructs to show key identifying information - Added comprehensive tests to verify debugger attribute functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Activity.cs | Added DebuggerDisplay showing OperationName and Id; created ActivityDebuggerProxy class to expose collections and key properties in debugger |
| ActivityContext.cs | Added DebuggerDisplay showing TraceId, SpanId, and TraceFlags |
| ActivityLink.cs | Added DebuggerDisplay showing Context's TraceId and SpanId |
| ActivityEvent.cs | Added DebuggerDisplay showing Name and Timestamp |
| ActivityTests.cs | Added 5 test methods to verify debugger attributes work correctly for all modified types |
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
…ivitySource Co-authored-by: stephentoub <[email protected]>
Both suggestions implemented in commit bd78877:
Collections now show as: And ActivitySource displays as |
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs
Outdated
Show resolved
Hide resolved
… use helper Co-authored-by: stephentoub <[email protected]>
|
What does it look like now? |




Implementation Plan for Adding DebuggerDisplay to Activity and Friends
Summary
Successfully implemented DebuggerDisplay and DebuggerTypeProxy attributes for Activity and related types to improve the debugging experience.
Changes Made
Activity.cs:
using System.Linq;(no longer needed)[DebuggerDisplay("{DebuggerDisplayString,nq}")]showing OperationName and IdDebuggerToString()method toDebuggerDisplayStringproperty for consistency with .NET patterns[DebuggerTypeProxy(typeof(ActivityDebuggerProxy))]ActivityDebuggerProxyclass with:new List<T>(collection)constructor to display "Count = X" in debugger (more user-friendly)new List<T>(...)constructorActivitySource.cs: Added
[DebuggerDisplay("Name = {Name}")]to show the ActivitySource name in debugger instead of default ToString()ActivityContext.cs: Added
[DebuggerDisplay]showing TraceId, SpanId, and TraceFlagsActivityLink.cs:
[DebuggerDisplay("{DebuggerDisplayString,nq}")]showing Context TraceId and SpanIdDebuggerDisplayStringproperty for consistency and testabilityActivityEvent.cs: Added
[DebuggerDisplay]showing Name and TimestampActivityTests.cs:
System.Diagnostics.DiagnosticSource.Tests.csproj: Added reference to Common test DebuggerAttributes helper
Code Improvements
DebuggerDisplayString Property Pattern:
Clean Tests:
List Constructor Instead of LINQ:
Testing
✅ All 402 tests pass
✅ No security vulnerabilities (CodeQL scan clean)
✅ Builds successfully for all target frameworks
✅ No breaking changes to public API
✅ Collections display "Count = X" for better UX
✅ ActivitySource shows its Name in debugger
✅ No LINQ dependency in ActivityDebuggerProxy
✅ Tests use reusable Common test utilities
✅ DebuggerDisplay uses property pattern consistently across all types
✅ Clean test code without unnecessary comments or custom reflection
✅ ActivityLink uses DebuggerDisplayString property for testability
The changes significantly improve the debugging experience for distributed tracing scenarios, making it easier for developers to inspect Activity objects and their related types.
Original prompt
Fixes #88332
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.