Skip to content
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

Add event tracing to NuGet.Common and write events for the NuGet-based MSBuid project SDK resolver #5409

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

jeffkl
Copy link
Contributor

@jeffkl jeffkl commented Sep 7, 2023

Bug

Fixes: NuGet/Home#11445

Regression? Last working version:

Description

This adds a new EventSource to NuGet.Common and writes events for the NuGet-based MSBuild project SDK resolver.

I also implemented the following Keywords:

Keyword Purpose
Common Any event coming from a component in the NuGet.Common namespace
Configuration Any event coming from a component in the NuGet.Configuration namespace
Logging Any event that is logging a message
Performance Any event related to measuring performance
SdkResolver Any event coming from a component in the NuGet-based MSBuild project SDK resolver

This will allow users to filter out potential components that aren't necessary for a particular trace.

Users will be able to enable the tracing with tools like PerfView:

PerfView /OnlyProviders=*Microsoft-NuGet run dotnet restore

The resulting Event Trace Log (.etl) will be useful when diagnosing issues with it. The above command also includes traces from MSBuild and there are additional sources like Visual Studio which include more information.

Here is a sample trace log you can view in tools like PerfView:
PerfViewData.etl.zip

image
image
image

Its also possible to create these traces with Visual Studio and dotnet trace

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@jeffkl jeffkl self-assigned this Sep 7, 2023
@jeffkl jeffkl requested a review from a team as a code owner September 7, 2023 20:35
@jeffkl
Copy link
Contributor Author

jeffkl commented Sep 7, 2023

FYI @ladipro and @lifengl

@jeffkl
Copy link
Contributor Author

jeffkl commented Sep 11, 2023

@zivkan and @nkolev92 so if I update this and move the event provider to NuGet.Common, make it public, update the event names, then fire the events where needed, you'll approve?

@nkolev92
Copy link
Member

I like that idea.

@zivkan has some experience with the events and he did a lot of work on the VS side with, so he's probably the best person to review it.

@zivkan
Copy link
Member

zivkan commented Sep 12, 2023

Yes, I'd approve without hesitation. I've been thinking about how we can monitor NuGet better since mid to late 2020, but there's always higher priority work. But adding an EventSource so we can start using it more is very much needed. It probably would have been nice to add some instrumentation into NuGetAudit to get detailed perf & diagnostic data in case someone ends up reporting a difficult to reproduce bug.

The only thing I haven't thought about is naming conventions for events. If we're going to have all NuGet assemblies using one provider, we need event names to include the assembly name, or feature area, so we don't end up with dumb event names like NuGet/ReadFile/Start and we don't know if it's reading a config file, or http cache file, or global.json, or something else. While we can put the filename being read as an event property, if I'm trying to investigate slow or failing nuget.config load errors, I don't want global.json and http cache reads spamming the event list, so I think it's better to have more events. From memory, ETW has a max of 32k events allowed per provider. We're not going to reach that limit.

Since the EventSource will unfortunately need to be in NuGet.Common's public API, my advice is to have a public EventSource instance, which we will call .Write( on. Similar to what I already added in our VS code:

public static EventSource ExtensibilityEventSource { get; } = new EventSource(ExtensibilityEventSourceName);

While this PR's first iteration uses a class that extends EventSource, and adds methods to make emiting the events nicer, since we need to make our common provider part of our client SDK's public API, I don't think we should need to change public APIs every time someone adds/removes/modifies some EventSource event. Not only will it reduce PR workload, but it also makes NuGet much less fragile to mismatched dll versions. While we could argue that anyone using the CLient SDK should use the same package version for all the packages, I'd rather not introduce this as potential failure.

@jeffkl jeffkl changed the title Add event tracing to the NuGet-based MSBuid project SDK resolver Add event tracing to NuGet.Common and write events for the NuGet-based MSBuid project SDK resolver Sep 12, 2023
@jeffkl
Copy link
Contributor Author

jeffkl commented Sep 12, 2023

This has now been moved to NuGet.Common.

@jeffkl jeffkl force-pushed the dev-jeffkl-nugetsdkresolver-tracing branch from 84cfb1a to 0bafeab Compare September 12, 2023 18:09
nkolev92
nkolev92 previously approved these changes Sep 12, 2023
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

LGTM.

The only thing I could think of is whether the EventKeywords need to be defined in common instead maybe in the assemblies themselves.

@jeffkl
Copy link
Contributor Author

jeffkl commented Sep 12, 2023

The only thing I could think of is whether the EventKeywords need to be defined in common instead maybe in the assemblies themselves.

Keywords have to be a flags so I was worried that if they weren't declared in one place then we could end up with collisions. I can move them but their just constants that we'll never change so I wasn't as worried about them being part of the public API

zivkan
zivkan previously approved these changes Sep 13, 2023
@jeffkl jeffkl dismissed stale reviews from zivkan and nkolev92 via d6e4d28 September 13, 2023 17:00
zivkan
zivkan previously approved these changes Sep 13, 2023
nkolev92
nkolev92 previously approved these changes Sep 13, 2023
@jeffkl jeffkl merged commit 4ea106d into dev Sep 21, 2023
15 checks passed
@jeffkl jeffkl deleted the dev-jeffkl-nugetsdkresolver-tracing branch September 21, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add more logging to NuGetSdkResolver
5 participants