-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
EventSource EventWrittenEventArgs.ActivityId isn't always set #42128
Comments
CC @noahfalk who can address this issue. |
How are you consuming these events? Are you listening to these events live via an |
The use case here is using I modified the using var listener = new TestEventListener("System.Net.Sockets", EventLevel.Verbose, 0.1);
listener.AddActivityTracking(); // Doesn't exist on current TestEventListener
var events = new ConcurrentQueue<EventWrittenEventArgs>();
await listener.RunWithCallbackAsync(events.Enqueue, async () =>
{
// Stuff that triggers events
}
EventWrittenEventArgs start = Assert.Single(events, e => e.EventName == "FooStart");
EventWrittenEventArgs something = Assert.Single(events, e => e.EventName == "FooSomething");
EventWrittenEventArgs stop = Assert.Single(events, e => e.EventName == "FooStop");
Assert.NotEqual(Guid.Empty, start.ActivityId);
Assert.Equal(start.ActivityId, something.ActivityId); // Fail
Assert.Equal(start.ActivityId, stop.ActivityId); Here, ActivityId would be set correctly for FooStart/FooStop, but If instead you look at the EventArgs inside the listener.RunWithCallbackAsync(e => { Console.WriteLine(e.ActivityId); events.Enqueue(e); }, ... |
I'm not sure if there is an explicit reason for this behavior (the code hasn't changed in ~1 year), but I agree with Tom on how we should handle this (document now; address/change in 6.0). For now, would it be sufficient for the test to store a tuple |
Yes a temporary fix would be changing the test / adding 2 lines of reflection into TestEventListener to set the private field. |
* Correct NameResolutionTelemetry logic Taken from c4c9a2f99b7e339388199086d3014041abccc21e * Enable listening to multiple sources with TestEventListener * Workaround EventWrittenEventArgs bug when the EventArgs are stored Workaround #42128 * Correct System.Net.Sockets Telemetry * Avoid using value tuple in TestEventListener * Remove unnecessary argument to OnCompletedInternal * Remove redundant Telemetry.IsEnabled check * Log Connect/Accept start before the initial context capture * Use SocketHelperBase in Accept tests * Avoid duplicate events for BeginConnect without ConnextEx support * Enable Sync Socket tests * Revert unrelated SocketPal change * Log the correct ErrorCode in case of socket disposal * Add more info on TelemetryTest timeout * Add PlatformSpecific attribute to ConnectFailure test * Add missing BeginConnect AfterConnect call on sync failure * Add comment around GetHelperBase * Correct WaitForEventCountersAsync helper * Assert against SocketError.TimedOut in ConnectFailed test * Add EndConnect comment * Log Failure around sync SocketPal exceptions * Don't assert that the exception message is empty * Dispose socket in a different Thread * Disable Telemetry failure tests for Sync on RedHat7 * Use more descriptive names in MemberData generation * Avoid using reflection for #42128 workaround * Remove ConnectCanceled event
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
The
ActivityId
property will return them_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?The text was updated successfully, but these errors were encountered: