Skip to content
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

Add telemetry for which error codes are suppressed at restore time #6290

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

jgonz120
Copy link
Contributor

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/2384

Description

Modified RestoreCollectorLogger to keep track of which warnings were suppressed. This is then added to telemetry.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@jgonz120 jgonz120 requested a review from a team as a code owner February 27, 2025 18:51
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request adds telemetry support for tracking suppressed warning codes during restore operations. It introduces new telemetry event reporting in the restore command, extends test coverage for collecting suppressed warnings, and updates the logging implementation to capture these warnings.

  • Introduces telemetry event for suppressed warning codes in RestoreCommand.
  • Adds new unit tests to verify correct telemetry recording and warning suppression.
  • Updates RestoreCollectorLogger to enqueue suppressed warnings.

Reviewed Changes

File Description
test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/RestoreCommandTests.cs Adds a test to verify telemetry population when warnings are suppressed.
test/NuGet.Core.Tests/NuGet.Commands.Test/CollectorLoggerTests.cs Adds tests ensuring correct tracking of suppressed warnings.
src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs Updates telemetry population logic to include suppressed warning codes.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/RestoreCollectorLogger.cs Modifies warning suppression logic and introduces a suppressed warnings queue.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

@@ -615,6 +616,7 @@ private async Task<IEnumerable<RestoreTargetGraph>> GenerateRestoreGraphsAsync(T

var errorCodes = ConcatAsString(new HashSet<NuGetLogCode>(logs.Where(l => l.Level == LogLevel.Error).Select(l => l.Code)));
var warningCodes = ConcatAsString(new HashSet<NuGetLogCode>(logs.Where(l => l.Level == LogLevel.Warning).Select(l => l.Code)));
var suppressedWarningCodes = ConcatAsString(new HashSet<NuGetLogCode>(_logger.SuppressedWarnings.Select(l => l.Code)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question for everyone: This allocates a string that may or may not be used depending on if the telemetry pipeline is available. Shouldn't all of those allocations only happen if telemetry is available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do collect quite a bit of data for telemetry, so I think it might be worth figuring out if we can gate it on NuGetTelemetryService being non-null.

My vote would be create an issue for this, since there are ways we can improve things.

@@ -615,6 +621,15 @@ private async Task<IEnumerable<RestoreTargetGraph>> GenerateRestoreGraphsAsync(T

var errorCodes = ConcatAsString(new HashSet<NuGetLogCode>(logs.Where(l => l.Level == LogLevel.Error).Select(l => l.Code)));
var warningCodes = ConcatAsString(new HashSet<NuGetLogCode>(logs.Where(l => l.Level == LogLevel.Warning).Select(l => l.Code)));
var suppressedWarningCodes = ConcatAsString(new HashSet<string>(_logger.SuppressedWarnings.Select(l =>
{
if (string.IsNullOrEmpty(l.LibraryId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tracking whether it was suppressed at the package id level vs the project level?
If we were gonna get anything, I think that's more valuable.

tbh, I feel like I'd rather just get the suppressed warnings, but that's just me.

Keep in mind we need to parse this when we "cook" the data. I'd rather have an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants