This repository was archived by the owner on Jul 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
opencensus/trace/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,17 +75,23 @@ SpanContext FromB3Headers(absl::string_view b3_trace_id,
7575 std::string trace_id_binary = absl::HexStringToBytes (b3_trace_id);
7676 std::string span_id_binary = absl::HexStringToBytes (b3_span_id);
7777
78- // Extend 64-bit trace_id to 128-bit.
7978 uint8_t extended_trace_id[16 ];
80- if (b3_trace_id.length () == 16 ) {
79+
80+ // trace_id_ptr must point to a 128-bit trace_id.
81+ const uint8_t * trace_id_ptr;
82+ if (trace_id_binary.length () == 16 ) {
83+ trace_id_ptr = reinterpret_cast <const uint8_t *>(trace_id_binary.data ());
84+ } else if (trace_id_binary.length () == 8 ) {
85+ // Extend 64-bit trace_id to 128-bit using the buffer.
8186 memset (extended_trace_id, 0 , 8 );
8287 memcpy (extended_trace_id + 8 , trace_id_binary.data (), 8 );
88+ trace_id_ptr = extended_trace_id;
89+ } else {
90+ return invalid;
8391 }
8492
8593 return SpanContext (
86- TraceId ((b3_trace_id.length () == 16 )
87- ? extended_trace_id
88- : reinterpret_cast <const uint8_t *>(trace_id_binary.data ())),
94+ TraceId (trace_id_ptr),
8995 SpanId (reinterpret_cast <const uint8_t *>(span_id_binary.data ())),
9096 TraceOptions (&sampled));
9197}
You can’t perform that action at this time.
0 commit comments