dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.42k stars 4.76k forks source link

Log details of app being launched by dotnet(.exe) to ETW/LTTng #3156

Open DamianEdwards opened 6 years ago

DamianEdwards commented 6 years ago

There is a desire in certain environments to get details about .NET Core apps being launched in order to aid in analysis of issues, distribution of frameworks and dependencies being loaded, etc. (similar to the way that .NET apps log to the Windows Event log when they crash to capture details of failure). This can be particularly useful to discover how many apps are using a given shared framework version (to aid in planning to uninstall that version), or which apps are using a particular dependency (in case there is a security or compliance issue of some kind).

To this end, the host layer should log details about the app being launched to the appropriate sink for the OS (e.g. ETW on Windows, LTTng on Linux). The following details would be helpful:

It might be good to enable configuring which of these details is logged, e.g. via ETW event names or keywords.

Petermarcu commented 6 years ago

@brianrob

DamianEdwards commented 6 years ago

Would like this to be considered for next minor release, or even better, a servicing release šŸ˜„

brianrob commented 6 years ago

CoreCLR has the concept of the RuntimeInformation event which does a stripped-down version of this for things that the runtime knows, and it is quite valuable. This is what is logged in the RuntimeInformation event:

It can be quite useful and I can imagine that the information requested here would also be quite valuable. One thing to note is that amost all of the information requested here is information that the host has but the runtime does not. This complicates things just a bit because the component that knows how to log to the platform-dependent and platform-independent loggers is the runtime. I would recommend designing a mechanism to pass this information from the host to the runtime and let the runtime log it. This will guarantee that the information is exposed in all the right logging mechanisms on each platform (both platform-independent and platform-dependent).

I can help with details on exactly what to do here.

DamianEdwards commented 6 years ago

Sounds great.

Where is the RuntimeInformation event logged today?

brianrob commented 6 years ago

It's logged in a few places:

The code that does the actual logging is here: https://github.com/dotnet/coreclr/blob/86f418f0bd196ba84ab702410500271a4f8b0c33/src/vm/eventtrace.cpp#L4926.

It is called from a few different places.

DamianEdwards commented 6 years ago

@blowdart

blowdart commented 6 years ago

Oh yes, I want this for security scanning, including fingerprinting of assemblies (SHA and signer would be great) loaded during startup, and even better, runtime, for dynamic loaded.

DamianEdwards commented 6 years ago

Curious where this has landed? Are we getting this for 3.0?

jeffschwMSFT commented 5 years ago

We are still gathering details on what should be logged. We should put this on the potential list for .NET Core 3.1

DamianEdwards commented 5 years ago

ping ?

jeffschwMSFT commented 5 years ago

It is on our backlog. @DamianEdwards are you the right person to get the specifics on what is needed? We explored this in late .NET Core 3, but the requirements were not solid enough for us to build something.

cc @vitek-karas @elinor-fung @lpereira

DamianEdwards commented 5 years ago

Right owner would be someone on @glennc's team I think, and I know for sure @blowdart is interested too. I provided a strawman summary up front on this issue and I think it's probably still a good place to start.

swaroop-sridhar commented 5 years ago

@vitek-karas, @shirhatti, and @noahfalk talked about this issue. Here are some notes.

Here is the work we agreed to perform in 3.1:

This will be achieved by:

vitek-karas commented 5 years ago

Based on recent offline discussion with @blowdart the security scanning aspect is a somewhat different ask. In addition it might already be sort of "resolved" by existing assembly loader tracing.

swaroop-sridhar commented 5 years ago

For the work agreed upon here, I'm in the process of making the following changes:

A sample output of the event is here:


TRUSTED_PLATFORM_ASSEMBLIES = C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Connections.Abstractions.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.Extensions.Identity.Stores.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Authentication.dll;webapi\bin\Debug\netcoreapp3.0\publish\asp.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Http.Connections.Common.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.0.0\System.Runtime.Serialization.Formatters.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Antiforgery.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.0.0\System.IO.IsolatedStorage.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Mvc.Localization.dll;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\
NATIVE_DLL_SEARCH_DIRECTORIES = C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\;C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.0.0\;
PLATFORM_RESOURCE_ROOTS = 
FX_DEPS_FILE = webapi\bin\Debug\netcoreapp3.0\publish\asp.deps.json
FX_PRODUCT_VERSION = 3.0.0
APP_CONTEXT_BASE_DIRECTORY = webapi\bin\Debug\netcoreapp3.0\publish\
APP_CONTEXT_DEPS_FILES = webapi\bin\Debug\netcoreapp3.0\publish\asp.deps.json;C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.App.deps.json;C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.0.0\Microsoft.NETCore.App.deps.json
PROBING_DIRECTORIES = 
JIT_PATH = C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\3.0.0\clrjit.dll
FX_RESOLUTION=Framework:'Microsoft.AspNetCore.App', Min:'3.0.0', Resolved:'3.0.0'; Framework:'Microsoft.NETCore.App', Min:'3.0.0', Resolved:'3.0.0'
Othes = System.GC.Server = true

@shirhatti can you please verify if the output is what'd you'd like to have? @noahfalk, @vitek: Please let me know if you have any additional comments about the implementation. Thanks.

swaroop-sridhar commented 5 years ago

@noahfalk recommended structuring the schema for some items (like TPA, FX_RESOLUTION) as arrays of structured items, rather than strings. I'll update it.

vitek-karas commented 5 years ago

I would change the name of the property in FX_RESOLUTION from Min to Requested, that better describes the intent of the message.

swaroop-sridhar commented 4 years ago

I discussed the logging format issue with @shirhatti, who preferred publishing the runtime properties as simple strings (that are also human readable) rather than binary blobs. So, we'll try implementing the event with data-definitions as individual strings, as described above

agocke commented 4 years ago

@vitek-karas @swaroop-sridhar I'm thinking that this is a 6.0 item now, any objections?

vitek-karas commented 4 years ago

agreed šŸ˜¢

swaroop-sridhar commented 4 years ago

Me too.

swaroop-sridhar commented 4 years ago

In order to make the event extensible, we'd agreed that the event's payload will contain two arrays -- for property names and values -- similar to what's passed in to the runtime. Initially, we only report the following properties: FX_PRODUCT_VERSION and FX_RESOLUTION, and this can be expanded based on use-cases.

brianrob commented 4 years ago

@swaroop-sridhar do you have a plan for how this data will ultimately get logged? If it gets logged from the runtime, or managed code, we have the ability to use the runtime support for tracing. Is the idea here to extend the interface between the host and the runtime to pass this data, and then the runtime is responsible for logging it?

swaroop-sridhar commented 4 years ago

The FX_RESOLUTION property will be computed by the host, and passed on to the runtime, as an additional property. The input properties will be logged by the runtime at startup (ex: in CreateAppDomain). Please see: https://github.com/dotnet/runtime/pull/644 and https://github.com/dotnet/runtime/pull/690

brianrob commented 4 years ago

Sounds good. Thanks much @swaroop-sridhar.

agocke commented 3 years ago

I believe this work has been completed in #690

vitek-karas commented 3 years ago

690 was never merged - as far as I know this functionality doesn't exist in the runtime yet. The only even which is there is Runtime Start - which logs version of CoreCLR and BCL, but nothing else.