microsoft / ApplicationInsights-Profiler-AspNetCore

Application Insights Profiler sample and documentation
MIT License
66 stars 22 forks source link

Allow additional EventPipe/ETW providers to be specified #183

Closed kalebpederson closed 1 year ago

kalebpederson commented 1 year ago

I ran a trace of our application and found that only contained events for some of the EventPipe/ETW providers my application consumes. In my case, I was looking for insight around the Microsoft.IdentityModel.Clients.ActiveDirectory provider, but I've worked with others in the past that would be equally useful.

Please allow additional ETW/EventPipe providers to be specified to enable capturing of other events from other providers.

NOTE: dotnet-trace isn't a suitable substitute because, although it's capable of capturing this information, we have requirements around executables present on our machines/images/containers.

xiaomi7732 commented 1 year ago

@kalebpederson, thanks for the request - I'll bring this to our team for triaging.

xiaomi7732 commented 1 year ago

@kalebpederson The feature is released in 2.5.0-beat1, please give it a try: https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.5.0-beta1

Instructions here, note: it is different than the private one shared with you. https://aka.ms/ep-sp/custom-providers

Again, thank you for bringing this up!

kalebpederson commented 1 year ago

Thanks @xiaomi7732! Your custom providers documentation says when talking about default providers:

You don't need to configure these providers.

In my mind, the word "need" implies I still have the ability to. I don't have a reason to do so right now, but does the above imply that if I ever wanted to change the keywords used on a default provider I could do so by adding something like the following to my configuration?:

{
  ...
  "ServiceProfiler": {
    "CustomEventPipeProviders": [
      { "name": "Microsoft-Windows-DotNETRuntime", "eventLevel": "Verbose", "keywords": "0xffffffff" }
    ]
  }
  ...
}
xiaomi7732 commented 1 year ago

Hey Kaleb, why do you have to ask tough questions? ( :-) kidding).

Yes, you read it correctly, technically, you could overwrite built-in providers.

That said, we chose not to state it explicitly because this is a new feature, and there could be changes. There might also be consequences on the trace validation that we use on the service side that you might stop seeing traces show up in the portal - and we need time to work on that story.

As of today, here's the related code:

⚠️Disclaimer: Implementation details might change without notice. Use it at your own risk.

// Appending custom providers when there are any.
EventPipeProviderItem[]? customProviders = configuration.CustomEventPipeProviders?.ToArray(); // Read from configurations you specified.
try
{
    if (customProviders is not null && customProviders.Length > 0)
    {
        foreach (EventPipeProviderItem providerInfo in customProviders)
        {
            if (providerHolder.ContainsKey(providerInfo.Name))
            {
                // Replace existing provider - as long as the key matches
                providerHolder[providerInfo.Name] = providerInfo.ToProvider();
            }
            else
            {
                // Append new provider
                providerHolder.Add(providerInfo.Name, providerInfo.ToProvider());
            }
        }
    }
}
catch (Exception ex)  // TODO: narrow down to specific exception types.
{
    _logger.LogError(ex, "Unexpected exception configuring custom EventPipe providers. Please refer to https://aka.ms/ep-sp/custom-providers for instructions.");
}
finally
{
    Providers = providerHolder.Values; // Finalize the provider list.
}

Keep us posted on whether this feature fits your needs or not. Let us know if there are any other questions.

kalebpederson commented 1 year ago

why do you have to ask tough questions? ( :-) kidding).

Haha! You haven't learned how much of troublemaker I am yet?! ;)

Keep us posted on whether this feature fits your needs or not. Let us know if there are any other questions.

This meets my current needs. Rather than guess and gold plate, I'll reach out if I discover a need later.

xiaomi7732 commented 1 year ago

I know you are a trouble seeker and resolver :-) I'll close this issue for now. Feel free to file new issues if you see anything.