-
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
WriteEventCore with DateTime has changed behavior in .Net 6.0 #61563
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Area should be "area-System.Diagnostics.Tracing" |
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsDescriptionWhen updating to .NET 6.0, we encountered issues with DateTimes within events containing an incorrect year. It appears that the optimization in pull request #52092 changed the behavior so that it's no longer decoded from a FileTime and is instead decoded using the full tick value. Reproduction StepsWrite an event using WriteEventCore like the example below
Expected behaviorEventWrittenEventArgs payload from an EventTraceListener contains the DateTime matching the input. Actual behaviorEventWrittenEventArgs payload from an EventTraceListener contains the DateTime, but the year is off by 1600 as it appears to be decoding from ticks rather than file time ticks. Known WorkaroundsA workaround is to use Other informationThis appears to be a breaking change from NetCore3.1 and Net 5.0 so seeking guidance on whether this is an expected change in behavior or if this is a bug. Thanks!
|
Hi, any updates on this? |
@MJSanfelippo this issue is currently on our backlog and we have not yet had time to investigate. Is this workaround sufficient or is this a higher priority issue? A couple of quick questions:
|
@tommcdon it is a bug introduced by #52092 in .NET 6.0, but only affects in-process The difference is in how the serialized value (
Sadly this was not caught by tests since none of them uses The fix here would be to change runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Line 1844 in a25aa66
to decoded = DateTime.FromFileTimeUtc(*(long*)dataPointer); |
The workaround I proposed also only works for local listeners. If you're sending events to another process, in my experience they're still expecting them to be FileTime ticks. This creates a scenario where you want to keep the same write event behavior as pre-6.0, but then you have to jump through extra hoops to get the correct value if using a local trace listener. |
I updated ours to be ToBinary() for now, but I'd like to keep them the way they were. |
@MihaZupan Yeah, I agree, it's not really a workaround. As far as I can tell, it results in a completely different telemetry contract, since we're sending a different, not really related number for DateTimes. This workaround only fixes things to jive between the .NET EventSource publishing libraries and listening/decoding libraries, but most people are sending telemetry somewhere else, in which case this is totally breaking. |
Note that the serialized value of a External telemetry systems should not be impacted (unless they are being fed by data coming from |
Thanks, @MihaZupan, I was afraid some WriteEvent overloads but not others would be impacted to write ticks instead of FileTime, but if they encode the data the same way as before, we can just fix the EventListener usages (which we use in tests). Looking at the PR some more, it looks like this only affects data being sent to listeners? |
I've updated my original post to remove the known workaround since it's unlikely to result in the correct behavior in most cases. The workaround was that if you're only using a local listener then you can get the same behavior by updating to use |
Description
When updating to .NET 6.0, we encountered issues with DateTimes within events containing an incorrect year. It appears that the optimization in pull request #52092 changed the behavior so that it's no longer decoded from a FileTime and is instead decoded using the full tick value.
Reproduction Steps
Write an event using WriteEventCore like the example below
Expected behavior
EventWrittenEventArgs payload from an EventTraceListener contains the DateTime matching the input.
Actual behavior
EventWrittenEventArgs payload from an EventTraceListener contains the DateTime, but the year is off by 1600 as it appears to be decoding from ticks rather than file time ticks.
Other information
This appears to be a breaking change from NetCore3.1 and Net 5.0 so seeking guidance on whether this is an expected change in behavior or if this is a bug. Thanks!
The text was updated successfully, but these errors were encountered: