-
Notifications
You must be signed in to change notification settings - Fork 500
[SDK] Ensure TraceId is portable on big-endian architectures #3543
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
[SDK] Ensure TraceId is portable on big-endian architectures #3543
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Thanks for the fix. Please fix the clang-format failure, patch below from the CI logs:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3543 +/- ##
==========================================
+ Coverage 89.98% 89.99% +0.01%
==========================================
Files 219 219
Lines 7044 7048 +4
==========================================
+ Hits 6338 6342 +4
Misses 706 706
🚀 New features to boost your workflow:
|
0f78911
to
9377a5d
Compare
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, thanks for the fix.
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.
Pull Request Overview
This PR ensures consistent big-endian interpretation of TraceId values for sampling on all architectures and updates the unit test to match the new behavior.
- CalculateThresholdFromBuffer now manually constructs the uint64_t from the first 8 bytes in big-endian order.
- The test buffer in
trace_id_ratio_sampler_test.cc
was reordered to big-endian format.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
sdk/src/trace/samplers/trace_id_ratio.cc | Replaces memcpy with a byte-by-byte shift loop to always interpret the first 8 bytes as big-endian |
sdk/test/trace/trace_id_ratio_sampler_test.cc | Updates the hardcoded buffer so its significant byte appears first, matching big-endian ordering |
Comments suppressed due to low confidence (1)
sdk/test/trace/trace_id_ratio_sampler_test.cc:102
- Add complementary test cases for boundary values (e.g., all zeros and all 0xFF) to verify behavior at the lower and upper extremes of the TraceId range.
constexpr uint8_t buf[] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
include-what-you-use failure in CI:
Patch to fix it:
|
include-what-you-use
Fixes #1221
Changes
While trying to enable opentelemetry-cpp for s390x on Alpine Linux, the following test was failing:
This PR fixes architecture-dependent behavior in TraceIdRatioBasedSampler by ensuring the trace ID is always interpreted as a big-endian integer for sampling decisions, as required for cross-platform and cross-language consistency in OpenTelemetry. The previous implementation used memcpy, which resulted in host-endian interpretation and inconsistent sampling results on big-endian architectures (e.g., s390x).
The test case is also updated to construct the trace ID buffer in big-endian order, matching the intended numeric value for sampling.
With this change, the build and all tests pass on native (no Docker) s390x and ppc64le, so #1221 can probably be closed.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes