Add crash/failure telemetry to MSBuild#13270
Open
YuliiaKovalova wants to merge 2 commits intomainfrom
Open
Conversation
e5aaf87 to
f205d92
Compare
Add CrashTelemetry data class and CrashTelemetryRecorder helper that capture rich exception information: exception type, inner exception type, stack trace hash (SHA-256 for bucketing without PII), top stack frame, HResult, exit type classification, criticality flag, MSBuild version, framework name, and host. CrashTelemetryRecorder centralizes recording and flushing logic used by all three crash telemetry emission points: 1. MSBuild.exe (XMake.Execute): - All catch blocks record crash telemetry via RecordCrashTelemetry - FlushCrashTelemetry in the finally block emits via TelemetryManager 2. API mode (BuildManager.EndBuild): - Catch block records crash telemetry for shutdown exceptions - _threadException (node crashes) is recorded before re-throwing - FlushCrashTelemetry emits via TelemetryManager 3. Unhandled exceptions (ExceptionHandling.UnhandledExceptionHandler): - RecordAndFlushCrashTelemetry immediately emits since process is dying All telemetry code is best-effort with catch-all guards to prevent secondary failures during crash handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f205d92 to
5c4a3f1
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive crash and failure telemetry to MSBuild to improve diagnostics and error tracking. The implementation introduces a new CrashTelemetry class that captures rich exception information including exception types, stack trace hashes (SHA-256 for PII-free bucketing), top stack frames, HResult codes, exit type classifications, criticality flags, MSBuild version, framework name, and host environment.
Changes:
- Adds
CrashTelemetryandCrashTelemetryRecorderclasses to capture and emit crash telemetry - Integrates crash telemetry recording into all exception catch blocks in
XMake.Execute()andBuildManager.EndBuild() - Adds unhandled exception handler support via
ExceptionHandling.UnhandledExceptionHandler
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Framework/Telemetry/CrashTelemetry.cs | Core telemetry data class with exception information, stack hashing, and property serialization |
| src/Framework/Telemetry/CrashTelemetryRecorder.cs | Centralized helper for recording and flushing crash telemetry with best-effort error handling |
| src/Framework/Telemetry/TelemetryConstants.cs | Adds "Crash" constant for crash activity naming |
| src/Framework/Telemetry/KnownTelemetry.cs | Adds static CrashTelemetry property for crash telemetry storage |
| src/MSBuild/XMake.cs | Integrates crash telemetry recording in all exception catch blocks and finally block flush |
| src/Build/BackEnd/BuildManager/BuildManager.cs | Adds crash telemetry recording for BuildManager exceptions and thread exceptions |
| src/Shared/ExceptionHandling.cs | Adds crash telemetry recording for truly unhandled exceptions |
…ts, fix exitType - Extract GetHostName() as shared method in XMake.cs and BuildManager.cs to eliminate duplicated host detection logic - Sanitize StackTop to redact file paths that may contain PII (usernames) while preserving method names and line numbers - Use consistent exitType 'EndBuildFailure' in BuildManager instead of exception.GetType().Name - Add CrashTelemetry_Tests with 8 tests covering PopulateFromException, GetProperties, GetActivityProperties, PII redaction, and null handling - Add comment clarifying why Initialize is needed in RecordAndFlushCrashTelemetry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add CrashTelemetry class that captures rich exception information including exception type, inner exception type, stack trace hash (SHA-256 for bucketing without PII), top stack frame, HResult, exit type classification, criticality flag, MSBuild version, framework name, and host environment.
Crash telemetry is emitted in two places:
The telemetry is recorded via KnownTelemetry.CrashTelemetry and flushed in the finally block of XMake.Execute() using TelemetryManager and the existing IActivity/ActivitySource infrastructure. All telemetry code is best-effort with catch-all guards to prevent secondary failures during crash handling.