Skip to content
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

impl(otel): set Recordable identity and timestamps #11286

Merged

Conversation

dbolduc
Copy link
Member

@dbolduc dbolduc commented Apr 14, 2023

Part of the work for #11156

Implement the identity and timestamp setters for a Recordable. This change should make the class usable with Cloud Trace.

@devbww might be interested in the absl::Time business.


This change is Reviewable

@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (bc8ab44) 93.77% compared to head (38e2ef1) 93.77%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11286   +/-   ##
=======================================
  Coverage   93.77%   93.77%           
=======================================
  Files        1767     1767           
  Lines      159222   159222           
=======================================
+ Hits       149316   149317    +1     
+ Misses       9906     9905    -1     

see 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dbolduc dbolduc marked this pull request as ready for review April 14, 2023 05:19
@dbolduc dbolduc requested a review from a team as a code owner April 14, 2023 05:19
opentelemetry::trace::SpanContext const& /*span_context*/,
opentelemetry::trace::SpanId /*parent_span_id*/) noexcept {}
opentelemetry::trace::SpanContext const& span_context,
opentelemetry::trace::SpanId parent_span_id) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how you can assert noexcept when you do things like construct strings.

Copy link
Contributor

@coryan coryan Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't. These are virtual functions and we need to respect the specification.

I tried (and failed) to convince these folks to drop the noexcept.

It seems that we will need to capture all exceptions. Maybe something like this (

// in some header...
bool NoExceptAction(absl::FunctionRef<void()> action) noexcept;

// in some cc
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
bool NoExceptAction(absl::FunctionRef<void()> action) noexcept try {
  action();
  return true;
} catch(...) {
  return false;
}
#else
bool NoExceptAction(absl::FunctionRef<void()> action) noexcept {
  action(); // Will crash, would have crashed anyway.
  return true;
}
#endif

// In Recordable.cc
void Recordable::SetIdentity(...) {
  usable_ = usable_ & NoExceptAction([&]() { SetIdentityImpl(...); });
}

Then we will drop (not send to Cloud Trace) any Recordables where usable_ is false.

This is all for a TODO bug and future PRs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #11288

std::array<char, 2 * opentelemetry::trace::TraceId::kSize> hex_trace_buf;
span_context.trace_id().ToLowerBase16(hex_trace_buf);
std::string const hex_trace(hex_trace_buf.data(),
2 * opentelemetry::trace::TraceId::kSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hex_trace_buf.size() perhaps, to avoid repeating the template parameter, and to perpetuate the "data/size" pairing convention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Fixed.

@dbolduc dbolduc force-pushed the otel-recordable-identity-and-timestamps branch from c6e046a to 26875f5 Compare April 14, 2023 15:42
Comment on lines +208 to +210
// std::chrono::system_clock may not have nanosecond resolution on some
// platforms, so we avoid using it for conversions between OpenTelemetry
// time and Protobuf time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It seems like opentelemetry::common::SystemTimestamp's implicit conversion to std::chrono::system_clock::time_point is a rounding accident waiting to happen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks for the warning.

// platforms, so we avoid using it for conversions between OpenTelemetry
// time and Protobuf time.
auto t = absl::FromUnixNanos(start_time.time_since_epoch().count());
*span_.mutable_start_time() = internal::ToProtoTimestamp(std::move(t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absl::Time is one of those always-pass-by-value exceptions, so drop the move().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dbolduc dbolduc enabled auto-merge (squash) April 14, 2023 17:03
@dbolduc dbolduc merged commit c21f9eb into googleapis:main Apr 14, 2023
@dbolduc dbolduc deleted the otel-recordable-identity-and-timestamps branch April 15, 2023 09:45
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