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

EventCounters event is written to an EventListener that never subscribed to it #31500

Closed
pakrym opened this issue Nov 14, 2019 · 6 comments
Closed
Assignees
Labels
area-System.Diagnostics.Tracing bug tracking This issue is tracking the completion of other related issues.
Milestone

Comments

@pakrym
Copy link
Contributor

pakrym commented Nov 14, 2019

We have an EventListener listener where the subscription is guarded by a trait that System.Runtime event source doesn't have (TraitName = "AzureEventSource")

  protected sealed override void OnEventSourceCreated(EventSource eventSource)
        {
            base.OnEventSourceCreated(eventSource);

            if (eventSource.GetTrait(TraitName) == TraitValue)
            {
                EnableEvents(eventSource, _level);
            }
        }

Somehow without subscribing to System.Runtime event source we get EventCounters events with the following stack:

>	Azure.Core.dll!Azure.Core.Diagnostics.AzureEventSourceListener.OnEventWritten(System.Diagnostics.Tracing.EventWrittenEventArgs eventData) Line 70	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.DispatchToAllListeners(int eventId, System.Guid* childActivityID, System.Diagnostics.Tracing.EventWrittenEventArgs eventCallbackArgs) Line 2166	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.WriteToAllListeners(string eventName, ref System.Diagnostics.Tracing.EventDescriptor eventDescriptor, System.Diagnostics.Tracing.EventTags tags, System.Guid* pActivityId, System.Guid* pChildActivityId, System.Diagnostics.Tracing.EventPayload payload) Line 747	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.EventSource.WriteImpl(string eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, object data, System.Guid* pActivityId, System.Guid* pRelatedActivityId, System.Diagnostics.Tracing.TraceLoggingEventTypes eventTypes) Line 695	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.PollingCounter.WritePayload(float intervalSec, int pollingIntervalMillisec) Line 76	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.CounterGroup.OnTimer() Line 224	C#
 	System.Private.CoreLib.dll!System.Diagnostics.Tracing.CounterGroup.PollForValues() Line 251	C#
 	System.Private.CoreLib.dll!System.Threading.ThreadHelper.ThreadStart() Line 100	C#

EventData:


  | Name | Value | Type
-- | -- | -- | --
◢ | eventData | {System.Diagnostics.Tracing.EventWrittenEventArgs} | System.Diagnostics.Tracing.EventWrittenEventArgs
  | ▶ ActivityId | {00000000-0000-0000-0000-000000000000} | System.Guid
  | Channel | None | System.Diagnostics.Tracing.EventChannel
  | EventId | -1 | int
  | EventName | "EventCounters" | string
  | ▶ EventSource | {EventSource(System.Runtime, 49592c0f-5a05-516d-aa4b-a64e02026c89)} | System.Diagnostics.Tracing.EventSource {System.Diagnostics.Tracing.RuntimeEventSource}
  | Keywords | None | System.Diagnostics.Tracing.EventKeywords
  | Level | LogAlways | System.Diagnostics.Tracing.EventLevel
  | Message | null | string
  | OSThreadId | 36244 | long
  | Opcode | Info | System.Diagnostics.Tracing.EventOpcode
  | ▶ Payload | Count = 1 | System.Collections.ObjectModel.ReadOnlyCollection<object>
  | ▶ PayloadNames | Count = 1 | System.Collections.ObjectModel.ReadOnlyCollection<string>
  | ▶ RelatedActivityId | {00000000-0000-0000-0000-000000000000} | System.Guid
  | Tags | None | System.Diagnostics.Tracing.EventTags
  | Task | None | System.Diagnostics.Tracing.EventTask
  | ▶ TimeStamp | {11/14/2019 7:38:14 PM} | System.DateTime
  | Version | 0 | byte


Runtime version: 3.0.0

cc @noahfalk

@sywhang
Copy link
Contributor

sywhang commented Nov 14, 2019

Do you know if there any EventPipe/ETW session that subscribed to System.Runtime? EventCounters are not session-aware so if an out-of-proc session has been started it is possible for EventListeners to start receiving payloads from EventSource that another session started.

@pakrym
Copy link
Contributor Author

pakrym commented Nov 14, 2019

I'm using ApplicationInsights in the same app so maybe.

@sywhang
Copy link
Contributor

sywhang commented Nov 14, 2019

AFAIK AppInsights does have an EventListener that turns on System.Runtime, so this is working as it was designed. I'll close this issue since it is a dup of https://github.com/dotnet/coreclr/issues/25262.

@sywhang sywhang closed this as completed Nov 14, 2019
@pakrym pakrym reopened this Nov 14, 2019
@pakrym
Copy link
Contributor Author

pakrym commented Nov 14, 2019

That issue seems to be about refresh rates of event counters and subscibing to the same event source with different set of parameters. I don't see how it correlates with event being sent to the wrong eventlistener.

@sywhang
Copy link
Contributor

sywhang commented Nov 14, 2019

Ah, sorry I should've clarified myself. To be more precise your issue is related to filtering on EventListener side - EventListener doesn't have the ability to filter on EventSource.Write. You can actually repro this same behavior happening with just a plain EventSource without any EventCounters.

For example, this EventSource will start spewing events out to any EventListener instance if there is a session that enables it:

    [EventSource(Name = "MyCompany")]
    class MyCompanyEventSource : EventSource
    {
        public void Failure(string message)
        {
            this.Write("MyCompany", new EventSourceOptions() { Level = EventLevel.LogAlways }, new CompanyPayloadType("Failure: " + message));
        }

        public void Startup()
        {
            this.Write("MyCompany", new EventSourceOptions() { Level = EventLevel.LogAlways }, new CompanyPayloadType("Startup"));
        }

        public void PageStart(int ID, string url)
        {
            if (IsEnabled())
            {
                this.Write("MyCompany", new EventSourceOptions() { Level = EventLevel.LogAlways }, new CompanyPayloadType("Page Started"));
            }
        }

        public void PageStop(int ID)
        {
            if (IsEnabled())
            {
                this.Write("MyCompany", new EventSourceOptions() { Level = EventLevel.LogAlways }, new CompanyPayloadType("Page Stopped"));
             }
         }

        public static MyCompanyEventSource Log = new MyCompanyEventSource();
    }

The culprit is here: https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs#L684

I thought we had an issue tracking this but I couldn't find any, so I'll use this issue as tracking this work item. Thanks!

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Mar 7, 2020
@tommcdon tommcdon added the tracking This issue is tracking the completion of other related issues. label Jul 8, 2020
@tommcdon tommcdon modified the milestones: 5.0.0, 6.0.0 Jul 8, 2020
@sywhang sywhang modified the milestones: 6.0.0, 5.0.0 Jul 9, 2020
@sywhang sywhang self-assigned this Jul 9, 2020
@tommcdon
Copy link
Member

Duplicate to #31927

@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Tracing bug tracking This issue is tracking the completion of other related issues.
Projects
None yet
Development

No branches or pull requests

5 participants