-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Re-enable telemetry for global.json state - set error writer to swallow expected error messages #51089
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
Re-enable telemetry for global.json state - set error writer to swallow expected error messages #51089
Conversation
|
This PR is targeting |
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 re-enables telemetry for global.json state while preventing unwanted error messages from appearing in stderr. The solution involves using hostfxr_set_error_writer to temporarily suppress expected SDK resolution errors during telemetry data collection.
- Adds a new
GetGlobalJsonStatemethod that safely extracts global.json information without printing errors - Introduces native interop bindings for the hostfxr error writer functionality
- Updates the telemetry collection code to use the new error-suppressed method
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| NETCoreSdkResolverNativeWrapper.cs | Adds new GetGlobalJsonState method with error suppression |
| Interop.cs | Adds native function bindings for hostfxr error writer |
| Program.cs | Updates telemetry code to use new error-suppressed method |
src/Resolvers/Microsoft.DotNet.NativeWrapper/NETCoreSdkResolverNativeWrapper.cs
Show resolved
Hide resolved
|
@elinor-fung for GA target the |
…ow expected error messages
bb0cc87 to
13a8022
Compare
|
Retargeted to |
src/Resolvers/Microsoft.DotNet.NativeWrapper/NETCoreSdkResolverNativeWrapper.cs
Outdated
Show resolved
Hide resolved
src/Resolvers/Microsoft.DotNet.NativeWrapper/NETCoreSdkResolverNativeWrapper.cs
Outdated
Show resolved
Hide resolved
…rNativeWrapper.cs
AaronRobinsonMSFT
left a comment
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.
LGTM ![]()
|
oh we should have Tactics-preflighted this. @elinor-fung can you send mail please? |
When getting the global.json state for telemetry, we avoid the work to actually resolve an SDK. However, this means that the actual SDK resolution (
hostfxr_resolve_sdk2) fails, resulting in messages printed to stderr by default. This change useshostfxr_set_error_writerto swallow the expected errors for the duration of that call and re-enables sending the telemetry for global.json statecc @dotnet/appmodel @AaronRobinsonMSFT
Issue about writing to stderr in original implementation: #50632
Issue about adding this telemetry - resolves #50058
@dotnet/dotnet-cli I'd also like to get this in 10 if possible. What would be the process and correct branch to target?
Impact
This telemetry will give us information about the global.json state when an SDK command is invoked. We've gotten feedback over the years about how invalid global.json files shouldn't be ignored. This telemetry will give us a sense of how common this situation is and inform any decision to around changing the behaviour in a future release.
Regression
Risk
Low. This is fixing an issue in the original implementation where we'd end up printing extra/undesired messages when getting the information for telemetry. The fix is simply to swallow those messages.