Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 4 commits into from
Feb 22, 2025

Conversation

ThomsonTan
Copy link
Contributor

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
  • Unit tests have been added
  • Changes in public API reviewed

@ThomsonTan ThomsonTan requested a review from a team as a code owner February 21, 2025 21:35
Copy link

netlify bot commented Feb 21, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 70d0366
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/67b92320a122980007301f86

@lalitb lalitb self-assigned this Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.41%. Comparing base (3212b0f) to head (70d0366).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3286   +/-   ##
=======================================
  Coverage   89.41%   89.41%           
=======================================
  Files         207      207           
  Lines        6457     6457           
=======================================
  Hits         5773     5773           
  Misses        684      684           

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;
Copy link
Member

@lalitb lalitb Feb 21, 2025

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.

Copy link
Contributor Author

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.

Copy link
Member

@lalitb lalitb Feb 22, 2025

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.

@marcalff marcalff merged commit 021eb99 into open-telemetry:main Feb 22, 2025
58 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Feb 23, 2025
[ETW] Add configuration to export 64-bit integer as timestamp (open-telemetry#3286)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants