You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using System.Linq;using System.Diagnostics.Tracing;using Microsoft.ApplicationInsights;using Microsoft.ApplicationInsights.Extensibility;namespaceConsoleApp1{internalsealedclassMyEventListener:EventListener{publicEventSourceRichPayloadEventSource;protectedoverridevoidOnEventSourceCreated(EventSourceeventSource){if(eventSource.Name =="Microsoft-ApplicationInsights-Data"){RichPayloadEventSource=eventSource;}base.OnEventSourceCreated(eventSource);}}classProgram{privatestaticstringGetEnabledLevels(EventSourceeventSource)=>string.Join('|',fromEventLevellevelin Enum.GetValues(typeof(EventLevel))where eventSource.IsEnabled(level, EventKeywords.All)selectlevel);staticvoidMain(string[]args){using(varmyListener=new MyEventListener()){// This has the effect of creating the RichPayloadEventSource.// Use an unconfigured TelemetryConfiguration so we don't get the// DiagnosticsTelemetryModule added. Note that when config is Disposed,// TelemetryConfiguration.Active is reset to null.using(varconfig=new TelemetryConfiguration()){new TelemetryClient(config).TrackEvent("Startup");}// This has the side-effect of creating TelemetryConfiguration.Active with// DiagnosticsTelemetryModule added. It hooks up an EventListener for all// Microsoft-ApplicationInsights-* event sources, including the// RichPayloadEventSource. It's supposed to use EventLevel.Error.new TelemetryClient().TrackEvent("Hello!");// This prints: LogAlways|Critical|Error|Warning|Informational|Verbose// It's supposed to print LogAlways|Critical|Error
Console.WriteLine(GetEnabledLevels(myListener.RichPayloadEventSource));}}}}
The comments explain what's going on. The problem is that RichPayloadEventSource has been enabled with all events at all levels which makes it slow and inefficient. The events don't actually get logged because the DiagnosticListener.WriteEvent has an additional check for the level, so they get stopped there; but getting there involved allocating and serializing big payloads.
While this repro looks contrived, I don't believe this is purely hypothetical. I think we've had customers run into this.
Also note that RichPayloadEventSource is just one of the EventSources affected by this bug. Any other sources with names starting with "Microsoft-ApplicationInsights-" are affected; that includes the CoreEventSource and the Snapshot Debugger (which has an EventSource called "Microsoft-ApplicationInsights-Profiler-Session"). We've had reports of the latter getting "stuck" on.
SDK Version : 2.9.1
.NET Version : .NET Core 2.2, but it'll reproduce on all frameworks.
How Application was onboarded with SDK: Visual Studio
OS : Windows 10
Hosting Info (IIS/Azure WebApps/ etc) : N/A
The text was updated successfully, but these errors were encountered:
pharring
changed the title
RichPayloadEventSource can get enabled at LogAlways level
RichPayloadEventSource can get enabled at Verbose level
Mar 30, 2019
pharring
added a commit
to pharring/ApplicationInsights-dotnet
that referenced
this issue
Mar 30, 2019
Repro Steps
Compile and run:
The comments explain what's going on. The problem is that RichPayloadEventSource has been enabled with all events at all levels which makes it slow and inefficient. The events don't actually get logged because the DiagnosticListener.WriteEvent has an additional check for the level, so they get stopped there; but getting there involved allocating and serializing big payloads.
While this repro looks contrived, I don't believe this is purely hypothetical. I think we've had customers run into this.
Also note that RichPayloadEventSource is just one of the EventSources affected by this bug. Any other sources with names starting with "Microsoft-ApplicationInsights-" are affected; that includes the CoreEventSource and the Snapshot Debugger (which has an EventSource called "Microsoft-ApplicationInsights-Profiler-Session"). We've had reports of the latter getting "stuck" on.
Actual Behavior
LogAlways|Critical|Error|Warning|Informational|Verbose
Expected Behavior
LogAlways|Critical|Error
Version Info
SDK Version : 2.9.1
.NET Version : .NET Core 2.2, but it'll reproduce on all frameworks.
How Application was onboarded with SDK: Visual Studio
OS : Windows 10
Hosting Info (IIS/Azure WebApps/ etc) : N/A
The text was updated successfully, but these errors were encountered: