Skip to content

Commit

Permalink
Support 64 bit B3 traceIDs in OTel exporter
Browse files Browse the repository at this point in the history
Summary:
OTel wants all trace ids to be 128bit.
However b3 trace ids can be 64 bit. See https://github.com/openzipkin/b3-propagation#traceid-1

So we should also support propagating 64 bit trace IDs. To ensure compatibility
with other OTel tooling, we left pad the trace IDs with zeroes and make it a
128 bit ID before passing it to the OTel endpoint. This mirrors the approach
taken by open-telemetry/opentelemetry-go#698

Test Plan:
Updated a test to use 64 bit trace ids and ensured that they get
left padded with zeroes as expexted.

Reviewers: nserrino, michelle, philkuz

Reviewed By: philkuz

JIRA Issues: PP-3407

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11450

GitOrigin-RevId: 9f09a7e
  • Loading branch information
vihangm authored and orishuss committed Jul 14, 2022
1 parent 164e093 commit f86c078
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/carnot/exec/otel_export_sink_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ using table_store::schema::RowDescriptor;
const int64_t kOTelSpanIDLength = 8;
const int64_t kOTelTraceIDLength = 16;

const int64_t kB3ShortTraceIDLength = 8;

std::string OTelExportSinkNode::DebugStringImpl() {
return absl::Substitute("Exec::OTelExportSinkNode: $0", plan_node_->DebugString());
}
Expand Down Expand Up @@ -354,6 +356,11 @@ Status OTelExportSinkNode::ConsumeSpans(const RowBatch& rb) {
// 2. The ID value in the column is not valid hex or not valid length.
if (span_pb.trace_id_column_index() >= 0) {
auto id = ParseID(rb, span_pb.trace_id_column_index(), row_idx);
if (id.length() == kB3ShortTraceIDLength) {
std::string padded_id = std::string(kOTelSpanIDLength, '\0');
padded_id.replace(kOTelTraceIDLength - kB3ShortTraceIDLength, kB3ShortTraceIDLength, id);
id = padded_id;
}
if (id.length() != kOTelTraceIDLength) {
id = GenerateID(kOTelTraceIDLength);
}
Expand Down
17 changes: 10 additions & 7 deletions src/carnot/exec/otel_export_sink_node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1443,20 +1443,23 @@ spans {
parent_span_id_column_index: -1
})pb",
R"pb(
cols { time64ns_data { data: 10 data: 20 } }
cols { time64ns_data { data: 12 data: 22 } }
cols { string_data { data: "00112233445566778899aabbccddeeff" data: "invalid_hex" } }
cols { string_data { data: "invalid_hex" data: "0123456789abcdef" } }
num_rows: 2
cols { time64ns_data { data: 10 data: 20 data: 30 } }
cols { time64ns_data { data: 12 data: 22 data: 32 } }
cols { string_data { data: "00112233445566778899aabbccddeeff" data: "445566778899aabb" data: "invalid_hex" } }
cols { string_data { data: "invalid_hex" data: "012345678" data: "0123456789abcdef" } }
num_rows: 3
eow: true
eos: true)pb",
{SpecificID({'\x00', '\x11', '\x22', '\x33', '\x44', '\x55', '\x66', '\x77', '\x88',
'\x99', '\xaa', '\xbb', '\xcc', '\xdd', '\xee', '\xff'},
16),
SpecificID({'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x44',
'\x55', '\x66', '\x77', '\x88', '\x99', '\xaa', '\xbb'},
16),
GeneratedID(16)},
{GeneratedID(8),
{GeneratedID(8), GeneratedID(8),
SpecificID({'\x01', '\x23', '\x45', '\x67', '\x89', '\xab', '\xcd', '\xef'}, 8)},
{SpecificID("", 8), SpecificID("", 8)},
{SpecificID("", 8), SpecificID("", 8), SpecificID("", 8)},
},
{
"parent_span_id_only_set_when_exact",
Expand Down

0 comments on commit f86c078

Please sign in to comment.