-
Notifications
You must be signed in to change notification settings - Fork 423
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
Add SpanId class. #10
Conversation
class SpanId { | ||
public: | ||
// The size in bytes of the SpanId. | ||
static constexpr size_t kSize = 8; |
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.
Curious:
- Do we need this to be public?
- Which naming style are we following?
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.
IMO it doesn't have to be public, but my reasoning is that span_id is a rigidly defined part of the otel data model and having a size constant is useful.
There would be e.g. SpanId::kSize
and also TraceId::kSize
@@ -0,0 +1,29 @@ | |||
// Copyright 2019, OpenTelemetry Authors |
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.
Re. file naming convention - if the only class in that module is SpanId , should we name the file SpanId[.cpp|.hpp] or SpanId[.cc|.hh] ? .cpp looks a bit better to my eye, others may have a different opinion :)
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 think we should keep it as-is (api/include/opentelemetry/trace/span_id.h
) to match e.g. api/include/opentelemetry/nostd/string_view.h
std::string ToHex() const; | ||
|
||
private: | ||
uint8_t rep_[kSize]; |
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.
Any reason we're using an array of 8-bit numbers to represent this type instead of a uint64_t?
A char array like this will have a byte-level alignment (e.g. alignof(SpanId) == 1)) and will be less performant for doing basic operations like equality check, assignment, etc.
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 wanted to avoid implying that this is an integer, and thereby avoid endianness issues. SpanId is an opaque 8-byte binary blob.
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.
This has been discussed in the protocol repository, fwiw: open-telemetry/opentelemetry-proto#52
(It looks like we'll end up on using a byte array in the protocol, which doesn't preclude using 64-bit integers here.)
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.
Can we defer this as an implementation detail, or do we treat alignment as part of the ABI, and therefore have to set it in stone?
std::string ToHex() const; | ||
|
||
private: | ||
uint8_t rep_[kSize]; |
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.
This has been discussed in the protocol repository, fwiw: open-telemetry/opentelemetry-proto#52
(It looks like we'll end up on using a byte array in the protocol, which doesn't preclude using 64-bit integers here.)
Folks, I've respun this PR on top of #13 which added the start of the bazel build system. This has the start of a span_id class, and an example program that shows how to consume the Please take a fresh look at the changes, especially the BUILD parts and the directory structures. |
@@ -1,3 +1,17 @@ | |||
# Copyright 2019, OpenTelemetry Authors |
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.
Someone please remind me: do we need the license comment on basically every file?
{ | ||
constexpr char kHex[] = "0123456789ABCDEF"; | ||
std::string s(kSize * 2, ' '); | ||
for (int i = 0; i < kSize; ++i) |
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'm not comfortable with non-trivial implementations in headers. Is this okay?
I don't know what the alternative is, if we stick to the requirement that the api is strictly header-only.
opentelemetry::trace::SpanId* id = GetGlobalTracer::MakeSpanId(args...);
seems a bit extreme.
Can we make basic parts of the data model (eg SpanId, TraceId, Attribute) have concrete implementations in the API that can't be overridden by e.g. a dynamically loaded tracer at runtime.
Friendly ping. |
FYI: void f(const opentelemetry::trace::SpanId& span, opentelemetry::nostd::span<uint8_t, 8> out) {
span.CopyBytesTo(out);
}
|
If you pass SpanId by value does it still use a register? |
No:
Maybe we should add a comment encouraging users to pass span ids as values. |
If you keep the same approach but use an int64 (you can still cast it back to a char[]), it should pass in a register like a regular integer argument. |
Sorry, I miscommunicated. When passing spanid by value, |
Ok, so %rdi is storing the TraceId value and %rsi is storing the pointer from the span -- yeah that looks good. |
This is my understanding, yes. :) |
Also in #10 (comment) I was trying to show that the |
…tors Origin/propagators
Merge from upstream
No description provided.