Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Adds ETW instrumentation to log when projects are created and added to the workspace in ProjectSystemProjectFactory.

Changes

  • CodeAnalysisEventSource.Common.cs: Added ProjectCreated event (ID 20) that logs projectSystemName and filePath
  • ProjectSystemProjectFactory.cs: Emit event after project is added to workspace in CreateAndAddToWorkspaceAsync
CodeAnalysisEventSource.Log.ProjectCreated(projectSystemName, creationInfo.FilePath);

The event follows the existing pattern used for analyzer reference logging and uses the next available event ID in the sequence. The event is defined in the shared CodeAnalysisEventSource.Common.cs layer to avoid ID conflicts and maintain consistency with the architecture.

Original prompt

On ProjectSystemProjectFactory.cs:178-178, Here in ProjectSystemProjectFactory we have code that creates a new project and adds it to the workspace. We should add an ETW event that logs when we create a project. The logging is done with the CodeAnalysisEventSource, and we already have other examples of how it's used in ProjectSystemProject.cs. You'll have to add a new event and parameters for what you want to capture. When you're capturing parameters, you'll want to include the ProjectSystemName and the file path that comes from the creationInfo.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added ProjectCreated event (ID 20) to CodeAnalysisEventSource.Workspaces.cs
- Event logs projectSystemName and filePath parameters
- Added event call in ProjectSystemProjectFactory.CreateAndAddToWorkspaceAsync after project is added to workspace
- Built and verified changes compile successfully

Co-authored-by: jasonmalinowski <[email protected]>
Copilot AI changed the title [WIP] Add ETW event logging for project creation Add ETW event for project creation in ProjectSystemProjectFactory Oct 31, 2025
Copilot AI requested a review from jasonmalinowski October 31, 2025 00:07
public static readonly CodeAnalysisEventSource Log = new();

[Event(20, Message = "Project '{0}' created with file path '{1}'", Level = EventLevel.Informational)]
internal void ProjectCreated(string projectSystemName, string? filePath) => WriteEvent(20, projectSystemName, filePath ?? string.Empty);
Copy link
Member

Choose a reason for hiding this comment

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

@chsienki Should this be defined in this file or in the other Common file? It looks like other workspace events are being defined there, but then I'm not entirely sure what this file is doing specifically or what the intent is for the different provider names.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC these got shared because the ALC events are shared across the compiler and workspaces code. @RikkiGibson would probably remember better.

There's nothing inherently wrong with having the events be declared only in the workspaces layer but means we have to not re-use the ID for something else in the shared layer.

We should probably refactor this to have a shared ALC event source and then separate ones for compiler and workspaces. For now I would suggest just putting it in the shared layer for simplicity though.

Copy link
Member

Choose a reason for hiding this comment

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

See #75613 for context

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Can you move this addition to CodeAnalysisEventSource.Common.cs then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved the ProjectCreated event to CodeAnalysisEventSource.Common.cs in commit 3a013db.

@jasonmalinowski jasonmalinowski marked this pull request as ready for review October 31, 2025 00:10
@jasonmalinowski jasonmalinowski requested a review from a team as a code owner October 31, 2025 00:10
Per feedback from @jasonmalinowski and @chsienki, moved the ProjectCreated event definition from CodeAnalysisEventSource.Workspaces.cs to CodeAnalysisEventSource.Common.cs to keep event definitions in the shared layer for simplicity and avoid ID conflicts.

Co-authored-by: jasonmalinowski <[email protected]>
Copilot AI requested a review from a team as a code owner October 31, 2025 18:45
Copilot AI requested a review from jasonmalinowski October 31, 2025 18:46
@jasonmalinowski jasonmalinowski merged commit 6ea3a66 into main Oct 31, 2025
28 checks passed
@jasonmalinowski jasonmalinowski deleted the copilot/add-etw-event-for-project-creation branch October 31, 2025 21:16
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 31, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
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.

5 participants