-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
I ran into this while working on tests for #41670.
runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Lines 4544 to 4557 in abeadc2
| public Guid ActivityId | |
| { | |
| get | |
| { | |
| Guid activityId = m_activityId; | |
| if (activityId == Guid.Empty) | |
| { | |
| activityId = EventSource.CurrentThreadActivityId; | |
| } | |
| return activityId; | |
| } | |
| internal set => m_activityId = value; | |
| } |
The ActivityId property will return the m_activityId field if set (Start/Stop events).
If it wasn't set, it will fetch the current thread's activity id - but it won't save it.
This means that the behavior is correct when the EventArgs are analyzed in the event callback itself.
If the EventArgs are stored and looked at later, ActivityId info is lost (it'll always return Zero).
Considering that the property is described as Activity ID for the thread on which the event was written, this seems like a bug and not intentional behavior (which is also incredibly confusing to debug).
Is there a significant perf drawback to the approach of simply always fetching EventSource.CurrentThreadActivityId when creating the EventArgs and removing the getter logic?