Skip to content
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

timestamp for dotnet counters in JSON Formatted Incorrectly #3905

Closed
kkeirstead opened this issue May 23, 2023 · 2 comments · Fixed by #4389
Closed

timestamp for dotnet counters in JSON Formatted Incorrectly #3905

kkeirstead opened this issue May 23, 2023 · 2 comments · Fixed by #4389
Labels
bug Something isn't working dotnet-counters
Milestone

Comments

@kkeirstead
Copy link
Member

Description

When outputting using the JSON format, I get a StartTime that looks like this: 5/23/2023 10:34:49 AM.

However, each individual timestamp looks like this: 2023-05-23 10:34:59Z.

My understanding is that the "Z" at the end of the time indicates that this is supposed to be UTC; however, this is still local time (as seen in StartTime). I'm not sure if this time is supposed to be in UTC, but if so, I believe .ToUniversalTime() should be used here.

This became apparent while I was working on automated testing for dotnet counters; when deserializing a JSONCounterTrace, I believe the trailing "Z" is indicating that the timestamp should be treated as UTC, causing the timestamp to be incorrect (e.g. {5/23/2023 3:34:49 AM} local time). When I made the change listed above (using .ToUniversalTime()), this fixed the issue with the test reporting the incorrect time (note that this causes dotnet-counters to actually print in UTC though).

Configuration

Debugging locally on Windows using main:

collect --format json --output "C:\\artifacts\\collect.json" --counters "HatCo.HatStore" --name CustomMetricsTest --refresh-interval 5

Regression?

This appears to have originated in this change.

Other information

@kkeirstead kkeirstead added the bug Something isn't working label May 23, 2023
@gfoidl
Copy link
Member

gfoidl commented May 24, 2023

Should the timestamps be formatted according ISO 8601, so they're universal readable?
E.g. via ToString("O").

The default implementation of the JSON-serializer (in .NET) uses that format too. See e.g. sharplab example.

Relevant code lines here are

.Append("\"StartTime\": \"").Append(DateTime.Now.ToString()).Append("\", ")
and
.Append("{ \"timestamp\": \"").Append(DateTime.Now.ToString("u")).Append("\", ")

@tommcdon tommcdon added this to the 8.0.0 milestone May 30, 2023
@tommcdon
Copy link
Member

@kkeirstead please feel free to submit a PR addressing this issue

mikelle-rogers added a commit that referenced this issue Nov 14, 2023
In dotnet-counters JSON Exporter, change time formatting to universal
time formatting. Fixes #3905
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working dotnet-counters
Projects
None yet
3 participants