-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix Activity Start Time Precision #45175
Conversation
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsThe In .NET 5.0 we have introduced a new type The fix here is, instead of having
|
/backport to release/5.0 |
Started backporting to release/5.0: https://github.com/dotnet/runtime/actions/runs/382236457 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The CI failure is unrelated and tracked by the issue #44306 |
#45111
#44354
The
Activity
class has a property calledStartTimeUtc
which report the starting time of the activity.Activity
class existed for long time and users used to create it through the constructornew Activity(...)
. When running on .NET Core, we useDateTime.UtcNow
to get the starting time. We do that because in .NET Core theDateTime.UtcNow
is returned with high precision. When running on .NET Framework, we don't useDateTime.UtcNow
because its accuracy is ~16ms which is not that precise. Instead we use a combination ofStopwatch
andDateTime
to calculate more precise time. Activity has internal method calledGetUtcNow()
which implemented for .NET Core by just callingDateTime.UtcNow
and implemented for .NET Framework by using theStopwatch
andDateTime
.Activity.StartTimeUtc
just useGetUtcNow()
to get the starting time.In .NET 5.0 we have introduced a new type
ActivitySource
which allow creating and startingActivity
objects through the public methodStartActivity(...)
. But the implementation of this method always useDateTime.UtcNow
for getting the starting time. That made the reported starting time on the .NET Framework not precise and users of theSystem.Diagnostics.DiagnosticSource
package that shipped with .NET 5.0 started to notice that and caused problems in their trace reporting.The fix here is, instead of having
ActivitySource.StartActivity(...)
callingDateTime.UtcNow
, we are changing it to callActivity.GetUtcNow()
which will make the reported time on .NET Framework more precise. This change has no real effect on .NET Core asActivity.GetUtcNow()
there just callingDateTime.UtcNow
.