Skip to content

EventSource EventWrittenEventArgs.ActivityId isn't always set #42128

@MihaZupan

Description

@MihaZupan

I ran into this while working on tests for #41670.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions