-
Notifications
You must be signed in to change notification settings - Fork 446
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 endianness of Jaeger IDs for transmission #832
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,25 @@ void Recordable::PopulateAttribute(nostd::string_view key, const common::Attribu | |
void Recordable::SetIdentity(const trace::SpanContext &span_context, | ||
trace::SpanId parent_span_id) noexcept | ||
{ | ||
// IDs should be converted to big endian before transmission. | ||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#ids | ||
#if JAEGER_IS_LITTLE_ENDIAN == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if this is something that should be handled by https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-htons There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, to be more precise, something like this? #define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nicely done. this will check the endianness too before performing conversion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I considered There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could change the function name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second thought, leave the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if it's something you can move into a separate static inline utility function, then it can be reused elsewhere? I think it might be common requirement, to transmit the buffer in big endian, not unique to Jaeger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far I only saw the requirement in Jaeger. I'd be happen to move this to common utility if it is used in other places. |
||
span_->__set_traceIdHigh( | ||
bswap_64(*(reinterpret_cast<const int64_t *>(span_context.trace_id().Id().data())))); | ||
span_->__set_traceIdLow( | ||
bswap_64(*(reinterpret_cast<const int64_t *>(span_context.trace_id().Id().data()) + 1))); | ||
span_->__set_spanId( | ||
bswap_64(*(reinterpret_cast<const int64_t *>(span_context.span_id().Id().data())))); | ||
span_->__set_parentSpanId( | ||
bswap_64(*(reinterpret_cast<const int64_t *>(parent_span_id.Id().data())))); | ||
#else | ||
span_->__set_traceIdLow( | ||
*(reinterpret_cast<const int64_t *>(span_context.trace_id().Id().data()))); | ||
span_->__set_traceIdHigh( | ||
*(reinterpret_cast<const int64_t *>(span_context.trace_id().Id().data()) + 1)); | ||
span_->__set_spanId(*(reinterpret_cast<const int64_t *>(span_context.span_id().Id().data()))); | ||
span_->__set_parentSpanId(*(reinterpret_cast<const int64_t *>(parent_span_id.Id().data()))); | ||
#endif | ||
|
||
// TODO: set trace_state. | ||
} | ||
|
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.
how about using run-time determination if it's not set by compiler, something like:
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'd like to avoid the runtime check as it is a static property known at compile time. I think our current definition should cover most real cases if not all.
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.
For a reference implementation see https://github.com/abseil/abseil-cpp/blob/master/absl/base/internal/endian.h I think you can use that code (not directly if avoiding dependency is needed) but is a good implementation.