Skip to content

Commit

Permalink
Improve invalid span Id check (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Jan 28, 2021
1 parent ee79464 commit d94a368
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/include/opentelemetry/trace/span_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class SpanId final
bool operator!=(const SpanId &that) const noexcept { return !(*this == that); }

// Returns false if the SpanId is all zeros.
bool IsValid() const noexcept { return *this != SpanId(); }
bool IsValid() const noexcept
{
static_assert(kSize == 8, "update is needed if kSize is not 8");
return *reinterpret_cast<const uint64_t *>(&rep_) != 0ull;
}

// Copies the opaque SpanId data to dest.
void CopyBytesTo(nostd::span<uint8_t, kSize> dest) const noexcept
Expand Down

0 comments on commit d94a368

Please sign in to comment.