Add per-source telemetry for package IDs containing non-ASCII characters#7213
Open
Add per-source telemetry for package IDs containing non-ASCII characters#7213
Conversation
Copilot
AI
changed the title
[WIP] Add telemetry for non-standard package ID tracking
Add per-source telemetry for non-standard package ID characters
Mar 13, 2026
jeffkl
reviewed
Mar 16, 2026
src/NuGet.Clients/NuGet.VisualStudio.Common/Telemetry/PackageSourceTelemetry.cs
Outdated
Show resolved
Hide resolved
jeffkl
reviewed
Mar 16, 2026
src/NuGet.Clients/NuGet.VisualStudio.Common/Telemetry/PackageSourceTelemetry.cs
Outdated
Show resolved
Hide resolved
… per feed source Co-authored-by: jeffkl <17556515+jeffkl@users.noreply.github.com>
Co-authored-by: jeffkl <17556515+jeffkl@users.noreply.github.com>
Co-authored-by: jeffkl <17556515+jeffkl@users.noreply.github.com>
7e34992 to
79664c2
Compare
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.
Adds a boolean property
nupkgs.idcontainsnonasciicharacterto thePackageSourceDiagnosticstelemetry event, indicating whether any package installed from that source had an ID containing characters outside[A-Za-z0-9.\-]. Since the event is already scoped per-source, this automatically correlates non-standard ID usage to specific feed providers.Protocol layer
PackageIdproperty toProtocolDiagnosticNupkgCopiedEvent(nullable; new 3-param constructor, old 2-param delegates to it)FindPackagesByIdNupkgDownloader→identity.IdLocalPackageArchiveDownloader→_packageIdentity.IdLocalV3FindPackageByIdResource/LocalV2FindPackageByIdResource→idparameterPublicAPI.Unshipped.txtfilesTelemetry layer (
PackageSourceTelemetry)Dataclass: newIdContainsNonAsciiCharacterbool, set totrueon first non-standard ID seen per source (staystrueonce set)ReadOnlySpan<char>character loop checking each char against the allowed ranges (A-Z,a-z,0-9,.,-) — faster than a compiledRegexand produces no heap allocationsAddNupkgCopiedData: skips check whenPackageIdis null (events raised by old constructor)ToTelemetryAsync: emitsnupkgs.idcontainsnonasciicharacteralongside the existingnupkgs.copied/nupkgs.bytesPropertyNames.Nupkgs.IdContainsNonAsciiCharacter = "nupkgs.idcontainsnonasciicharacter"addedTests
New
AddNupkgCopiedData_*test cases covering: all-standard IDs →false; non-standard IDs (underscore, Unicode, space,@,+) →true; mixed batch with one non-standard →true; nullPackageId→false. ExistingToTelemetry_WithData_CreatesTelemetryPropertiesextended to assert the new property is emitted.Original prompt
Summary
Add telemetry to track whether a package ID contains characters other than
A-Z,a-z,0-9,., or-. This will help correlate non-standard package ID usage to specific feed providers (e.g., nuget.org vs myget.org vs others).Background
The existing telemetry infrastructure in
PackageSourceTelemetry.csalready:PackageSourceDiagnosticsevent per source that was used during restore/searchGetMsFeed()(nuget.org, Azure DevOps, GitHub, VS Offline)source.url)ProtocolDiagnostics.NupkgCopiedEventRequirements
Add a new boolean telemetry property to the
PackageSourceDiagnosticsevent that indicates whether any package installed from that source during the operation had a package ID containing characters outside of the set[A-Za-z0-9.\-](i.e., anything but ASCII letters, digits,., or-).boolnamed something likenupkgs.hasnonstandard_id(following the existing naming convention inPropertyNames)DataclassProtocolDiagnostics.NupkgCopiedEvent)ProtocolDiagnosticNupkgCopiedEventalready has access to the package identity/ID — check if it includes the package ID, and if not, determine the best way to get it (e.g., parse from the file path, or add it to the event)ToTelemetryAsyncviaAddSourcePropertiesor a new helper methodsource.msfeedorsource.urlproperties already in the event), no additional feed correlation logic is needed — the existing per-source event structure already provides that correlationRelevant Files
Primary file to modify:
src/NuGet.Clients/NuGet.VisualStudio.Common/Telemetry/PackageSourceTelemetry.csHasNonStandardId(or similar) bool field to theDatainner classPropertyNames.NupkgsAddNupkgCopiedDatato detect non-standard characters in the package ID and set the flag onDataToTelemetryAsync(in the nupkgs section)AddSourcePropertiesor create a new helper to emit the new propertyCheck the event type:
ProtocolDiagnosticNupkgCopiedEvent(inNuGet.Protocol) — verify if it carries the package ID. If not, determine how to obtain the package ID at the point the event fires.Tests: Add unit tests in
test/NuGet.Clients.Tests/NuGet.VisualStudio.Common.Test/Telemetry/PackageSourceTelemetryTests.cscovering:falsetruetrueNon-Standard Character Definition
A package ID is considered to have a non-standard ID if it contains any character that does NOT match
[A-Za-z0-9.\-]. Use aRegexor simple character-by-character check.Coding Standards
Follow the NuGet coding guidelines and match the style of the existing code in
PackageSourceTelemetry.cs.Pull Request Requirements
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: where is the code that logs telemetry of packages used during restore?
Assistant: The restore telemetry code is spread across a few key files. Here's a breakdown of where it all lives:
1. Core Telemetry Initialization & Package Counts —
RestoreCommand.csThis is the heart of the per-project restore telemetry. There are two main areas:
InitializeTelemetry()— Populates general restore metadata at the start of a restore: