Skip to content

Minimal work to make System.Diagnostics.Activity usable by the dotnet CLI application and codebase #49749

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

baronfel
Copy link
Member

I'm breaking out the monolithic set of changes from #49409 into a more digestible series of changesets.

This first one adds the ability to use System.Diagnostic.Activity at all in our codebase - creating an ActivitySource for us to use, and hooking the existing telemetry publishing up to it in a zero-cost way if no Activity Listeners are configured (which is the case today).

This is part of #49668.

@Copilot Copilot AI review requested due to automatic review settings July 12, 2025 14:35
Copy link
Contributor

@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.

Pull Request Overview

This PR makes System.Diagnostics.Activity usable in the .NET CLI by creating a central ActivitySource, freezing common telemetry data for zero-cost scenarios, and updating environment-variable APIs for nullability.

  • Introduce Activities.Source and emit ActivityEvents in Telemetry.TrackEvent
  • Convert common properties/measurements to FrozenDictionary and update nullability in Telemetry
  • Update forwarding-app environment‐variable methods to accept nullable values and add the DiagnosticSource package

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Cli/dotnet/Telemetry/TelemetryCommonProperties.cs Return FrozenDictionary<string, string> instead of Dictionary for common props
src/Cli/dotnet/Telemetry/Telemetry.cs Hook into Activity.Current.AddEvent, implement CreateActivityEvent/MakeTags, use frozen collections and nullables
src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs Add Activities.Source static ActivitySource for the CLI
src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs Accept string? for environment‐variable values
src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs Change internal dictionaries to store string? values for env vars
src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs Update WithEnvironmentVariable to accept string?
src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj Add System.Diagnostics.DiagnosticSource package reference
eng/Versions.props Bump SystemDiagnosticsDiagnosticSourcePackageVersion
Directory.Packages.props Pin System.Diagnostics.DiagnosticSource version
Comments suppressed due to low confidence (2)

src/Cli/dotnet/Telemetry/Telemetry.cs:184

  • [nitpick] The property key "event id" uses a space and lowercase naming. Consider using a consistent identifier like "EventId" or "eventId" without spaces for clarity.
            eventProperties.Add("event id", Guid.NewGuid().ToString());

src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs:19

  • This new public API for Activities.Source and its integration into telemetry warrants added tests to verify that Activities are created correctly and events propagate as expected. Please add tests and use the Skip parameter on the Fact attribute to reference the related SDK issue when necessary.
    public static ActivitySource Source { get; } = new("dotnet-cli", Product.Version);

}

private Dictionary<string, double> GetEventMeasures(IDictionary<string, double> measurements)
private static ActivityTagsCollection? MakeTags(
Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The branching in MakeTags is repetitive. Consider consolidating the four branches into a single enumeration of properties and measurements to simplify the logic.

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

1 participant