-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add telemetry logger support for API-based MSBuild usage #51068
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: release/10.0.1xx
Are you sure you want to change the base?
Add telemetry logger support for API-based MSBuild usage #51068
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.
@copilot a change is needed across the entire approach.
Anytime a ProjectCollection is created, we need a central MSBuildLogger instance created and passed into its loggers
parameter.
However, whenever that ProjectCollection is used to load a Project/ProjectInstance and then a build is called on that Project/ProjectInstance, the DistributedLoggers collection needs to be initialized with the MSBuildForwardingLogger
LoggerDescriptions as we discussed - with the key difference that the CentralLogger for those logger descriptions is the same MSBuildLogger instance used in the parent ProjectCollection. This is the only way to ensure that the loggers are kept in sync with each other.
Fixed in commit d971e42. The implementation now correctly shares the same MSBuildLogger instance:
This ensures evaluation and build telemetry are synchronized through the shared logger instance. |
This would be a significant architectural change that extends well beyond the original scope of adding telemetry logger support for API-based MSBuild usage. Creating wrapper types for Project, ProjectInstance, and ProjectCollection would require:
Could you clarify if this should be part of this PR, or would you prefer this to be tracked as a separate follow-up issue? If it should be in this PR, I'll need guidance on the API design for these wrapper types to ensure they meet all use cases. |
@copilot I'm dying laughing over here. You basically just told me 'no' :D :D :D That's probably fine though - we should log this as a follow-up issue and attack it architecturally. |
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.
Better - but this is still pretty messy and I think there are some gaps where ProjectCollections are managed in ways that Copilot didn't see.
@copilot we need a test case that shows that for these API-based uses of MSBuild the telemetry logger is correctly getting events. |
Added in commit c2b76b1. The test
This demonstrates that the telemetry logger is properly integrated into API-based MSBuild usage. |
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.
c29a32c
to
8b9d0c8
Compare
Co-authored-by: baronfel <[email protected]>
Co-authored-by: baronfel <[email protected]>
…and forwarding loggers Co-authored-by: baronfel <[email protected]>
…ding logger description Co-authored-by: baronfel <[email protected]>
… Build calls Co-authored-by: baronfel <[email protected]>
…ased MSBuild usage Co-authored-by: baronfel <[email protected]>
Co-authored-by: jjonescz <[email protected]>
Co-authored-by: jjonescz <[email protected]>
8b9d0c8
to
d62f17c
Compare
Summary
Successfully implemented unified telemetry logger injection for API-based MSBuild usage with proper logger instance sharing between evaluation and build phases, including comprehensive test coverage.
Changes Made
Core Implementation:
CreateTelemetryCentralLogger()
- Creates the central telemetry logger (MSBuildLogger) for ProjectCollection evaluation scenariosCreateTelemetryForwardingLoggerRecords(ILogger?)
- Creates ForwardingLoggerRecord using the provided central logger instance:BuildWithTelemetry()
- Three overloads that accept optional telemetry central logger parameter:CreateLoggersWithTelemetry()
- Returns tuple with logger array and central logger instance for reuseUpdated Usage Sites:
src/Cli/dotnet/Commands/Run/RunCommand.cs
- Captures and reuses telemetry central logger from ProjectCollection in Build callssrc/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
- Includes telemetry logger in ProjectCollection and BuildManager buildssrc/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs
- Includes telemetry logger in ProjectCollection for project evaluation and Directory.Packages.props loadingsrc/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs
- Captures telemetry central logger from ProjectCollection and threads it through call chainsrc/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
- Accepts and passes telemetry central logger to Build callssrc/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommand.cs
- Uses BuildWithTelemetry for workload restore buildssrc/BuiltInTools/dotnet-watch
- EvaluationResult.cs, HotReloadDotNetWatcher.cs, and ScopedCssFileHandler.cs use BuildWithTelemetryTesting:
TelemetryLogger_ReceivesEventsFromAPIBasedBuild
integration test that:Key Improvements:
Testing Results
Fixes #51066
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.