-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
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 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 emitActivityEvent
s inTelemetry.TrackEvent
- Convert common properties/measurements to
FrozenDictionary
and update nullability inTelemetry
- 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( |
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.
[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.
… CLI application and codebase
f0d6f8a
to
c173b9e
Compare
if (_commonMeasurements == null) | ||
{ | ||
return measurements; | ||
} |
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.
_commonMeasurements
is more likely to be FrozenDictionary<string, double>.Empty than null. This might be able to return measurements
in that case too.
if (properties is null) | ||
{ | ||
return _commonProperties; | ||
} |
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.
Returning _commonProperties
as-is from here is wrong because the caller TrackEventTask would attempt to add "event id", causing the FrozenDictionary to throw NotSupportedException.
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.