Skip to content

Commit

Permalink
fix(otel): support abseil <= 20210324
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc committed Oct 27, 2023
1 parent 6a3b9ae commit 1bf8901
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions google/cloud/internal/trace_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ class CloudTraceContext
using opentelemetry::trace::TraceId;
std::array<char, 2 * TraceId::kSize> trace_id;
span_context.trace_id().ToLowerBase16(trace_id);
std::array<char, 2 * SpanId::kSize> span_id;
span_context.span_id().ToLowerBase16(span_id);
std::uint64_t span_id_dec;
if (!absl::SimpleHexAtoi(absl::string_view{span_id.data(), span_id.size()},
&span_id_dec)) {
return;
}
// We would prefer to use `absl::SimpleHexAtoi`, but it is not available in
// the oldest version of Abseil we support. So we use `std::strtoull`, which
// requires the input to be null-terminated.
std::array<char, 2 * SpanId::kSize + 1> span_id;
span_context.span_id().ToLowerBase16({span_id.data(), span_id.size() - 1});
span_id[2 * SpanId::kSize] = '\0';
char* end = nullptr;
std::uint64_t span_id_dec = std::strtoull(span_id.data(), &end, 16);
carrier.Set(
"x-cloud-trace-context",
absl::StrCat(absl::string_view{trace_id.data(), trace_id.size()}, "/",
Expand Down

0 comments on commit 1bf8901

Please sign in to comment.