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

Developers can employ EventSource APIs when publishing for AOT targets to be able to use .NET tracing capabilities #43390

Open
mjsabby opened this issue Oct 14, 2020 · 10 comments
Assignees
Labels
area-Tracing-coreclr feature-request Priority:2 Work that is important, but not critical for the release Team:Runtime User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@mjsabby
Copy link
Contributor

mjsabby commented Oct 14, 2020

EventSource is a common logging abstraction in .NET but it uses reflection to generate the schema for an EventSource definition. The source generator would do this at build time and make using EventSources reflection free.

@MichalStrehovsky
Copy link
Member

EventSource used to have a hookup point for this that was used in .NET Native. It looked like this:

internal virtual void GetMetadata(out Guid eventSourceGuid, out string eventSourceName, out EventMetadata[] eventData, out byte[] manifestBytes)
{
//
// In ProjectN subclasses need to override this method, and return the data from their EventSourceAttribute and EventAttribute annotations.
// On other architectures it is a no-op.
//
// eventDescriptors needs to contain one EventDescriptor for each event; the event's ID should be the same as its index in this array.
// manifestBytes is a UTF-8 encoding of the ETW manifest for the type.
//
// This will be implemented by an IL rewriter, so we can't make this method abstract or the initial build of the subclass would fail.
//
eventSourceGuid = Guid.Empty;
eventSourceName = null;
eventData = null;
manifestBytes = null;
return;
}

It was nuked in the meantime (latest sources don't have it anymore).

@jeffschwMSFT jeffschwMSFT added area-Tracing-coreclr untriaged New issue has not been triaged by the area owner labels Oct 14, 2020
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Oct 14, 2020
@tommcdon tommcdon added this to the 6.0.0 milestone Oct 14, 2020
@samsp-msft samsp-msft added the User Story A single user-facing feature. Can be grouped under an epic. label Nov 9, 2020
@7sharp9
Copy link

7sharp9 commented Nov 17, 2020

How would this be consumed by non C# languages?

@samsp-msft samsp-msft added the Priority:0 Work that we can't release without label Nov 20, 2020
@danmoseley danmoseley assigned tommcdon and shirhatti and unassigned danmoseley Nov 25, 2020
@terrajobst terrajobst added this to Proposed in .NET 6.0 Nov 26, 2020
@marek-safar marek-safar changed the title Feature Proposal: Reflection-free EventSource* using Roslyn Source Generators Developers can leverage EventSource API when publishing for AOT targets Nov 27, 2020
@marek-safar marek-safar changed the title Developers can leverage EventSource API when publishing for AOT targets Developers can employ EventSource APIs when publishing for AOT targets to be able to use .NET tracing capabilities Nov 27, 2020
@tommcdon tommcdon added this to User Stories in .NET Core Diagnostics Dec 7, 2020
@benaadams
Copy link
Member

benaadams commented Dec 8, 2020

How would this be consumed by non C# languages?

It would affect all the EventSources in the runtime and aspnet so all languages would get benefits (reduced startup; increased trimability etc)

  • ConcurrencyLimiterEventSource
  • HostingEventSource
  • KestrelEventSource
  • CertificateManagerEventSource
  • HttpConnectionsEventSource
  • LoggingEventSource
  • System.Net.NetEventSource
  • DependencyInjectionEventSource
  • CDSCollectionETWBCLProvider
  • DataCommonEventSource
  • DiagnosticSourceEventSource
  • PLINQETWProvider
  • HttpTelemetry
  • NameResolutionTelemetry
  • NetSecurityTelemetry
  • SocketsTelemetry
  • ArrayPoolEventSource
  • TplEventSource
  • FrameworkEventSource
  • NativeRuntimeEventSource
  • RuntimeEventSource
  • PortableThreadPoolEventSource
  • XmlSerializationEventSource
  • DataflowEtwProvider
  • ParallelETWProvider
  • TransactionsEtwProvider

Whether or not you enable the EventSources they do a reflection based initialization step to see whether they are Enabled; which is expensive in startup.

It will also mean exposing runtime apis for EventSources that other languages can use if they also wish to implement similar source generators; or can manually use.

@vitek-karas
Copy link
Member

How would this be consumed by non C# languages?

On top of the benefits with framework event sources mentioned by @benaadams, this could be used for any other event source as well.

If the API is exposed as public any language could be used to implement it. For the C# source generator to actually work it would need to be public anyway.

The C# source generator would make it easier (do it automatically), but it would still be possible to implement the same functionality manually in any other language.

@samsp-msft samsp-msft added Priority:2 Work that is important, but not critical for the release and removed Priority:0 Work that we can't release without labels Mar 5, 2021
@samsp-msft
Copy link
Member

Dropping the priority as we don't have early AoT customers depending on it.

@benaadams
Copy link
Member

benaadams commented Mar 10, 2021

A whole lot of startup going into generating EventSource manifests and Guids etc for a standardish ASP.NET Core app with ApplicationInsights, e.g. this is https://themesof.net/

image

Couldn't fit it all on one screen, here's the rest

image

@benaadams
Copy link
Member

benaadams commented Mar 10, 2021

For https://themesof.net/ looks like 27 EventSources are created on startup, most of them probably just to check .Log.IsEnabled() and get false back... 😅

With any not in System.Private.CoreLib.dll doing reflection to get the Guid to use

image

@iSazonov
Copy link
Contributor

It is an issue for PowerShell startup too.

@tommcdon
Copy link
Member

@LakshanF @davmason do you know of any unresolved issues related to using EventSource on NativeAOT?

@LakshanF
Copy link
Member

Any payload that uses complex data types in EventSource, that in turn depends on unbound reflection for serialization, will be problematic for NativeAOT applications (primarily due to trimming). The long-term solution is to use a source generator for such cases. These scenarios would cause both Roslyn analyzer (when the application project file indicate intention to use NativeAOT) and ILCompiler to generate warnings, and developers should not ignore these warnings.

All Framework EventSource providers should work without problems, as well as payloads with primitive data types.

@tommcdon tommcdon modified the milestones: 8.0.0, 9.0.0 Jul 24, 2023
@tommcdon tommcdon assigned samsp-msft and unassigned shirhatti Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tracing-coreclr feature-request Priority:2 Work that is important, but not critical for the release Team:Runtime User Story A single user-facing feature. Can be grouped under an epic.
Projects
.NET 6.0
  
Cut
.NET Core Diagnostics
  
User Stories
Development

No branches or pull requests