-
Notifications
You must be signed in to change notification settings - Fork 483
[ETW] Add configuration to export 64-bit integer as timestamp #3286
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
[ETW] Add configuration to export 64-bit integer as timestamp #3286
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
constexpr int64_t FILETIME_EPOCH_DIFF = 11644473600LL; // Seconds from 1601 to 1970 | ||
constexpr int64_t HUNDRED_NANOSECONDS_PER_SECOND = 10000000LL; | ||
int64_t unix_time_seconds = (filetime / HUNDRED_NANOSECONDS_PER_SECOND) - FILETIME_EPOCH_DIFF; | ||
int64_t unix_time_nanos = unix_time_seconds * 1'000'000'000 + (filetime % HUNDRED_NANOSECONDS_PER_SECOND) * 100; |
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.
Do we need to check for the overflow, as unix_time_seconds
can be large value in uint64_t, and we are multiplying with 1'000'000'000 , followed by addition.
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.
I am not sure how should overflow be handled here, but it seems it is converted into time64_t
which doesn't take the signing of int64_t
into account (see here, probably passing overflowed value is fine here, which will just be treated as sort of invalid timestamp and returns some new or old timestamp.
Please feel free to correct me.
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.
I did some test here - https://godbolt.org/z/dGoen89bh, and can see the overflow happening for the filetime > year 2280. The existing code is used for conversion of the current timestamp (span start time, log timestamp etc), which should be fine as it won't overflow. However, with timestamp coming as attribute can have any value past year 2280, and this can overflow.
This should be fine for now, but good to add some code comment so it can be revisited.
[ETW] Add configuration to export 64-bit integer as timestamp (open-telemetry#3286)
Changes
Add macro
OPENTELEMETRY_ATTRIBUTE_TIMESTAMP_PREVIEW
to ETW exporter to support exporting a given 64-bit integer as timestamp type, because timestamp is not supported in the attribute type.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes