Skip to content

Commit

Permalink
Remove one-liner functions with inline code
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Nov 5, 2024
1 parent 35e6ec0 commit bb5f91a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions api/include/opentelemetry/trace/propagation/http_trace_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
static constexpr uint8_t kInvalidVersion = 0xFF;
static constexpr uint8_t kDefaultAssumedVersion = 0x00;

static bool IsValidVersion(uint8_t version_binary)
{
return version_binary != kInvalidVersion;
}

static bool IsHigherVersion(uint8_t version_binary)
{
return version_binary > kDefaultAssumedVersion;
}

static void InjectImpl(context::propagation::TextMapCarrier &carrier,
const SpanContext &span_context)
{
Expand Down Expand Up @@ -152,19 +142,28 @@ class HttpTraceContext : public context::propagation::TextMapPropagator
// hex is valid, convert it to binary
uint8_t version_binary;
detail::HexToBinary(version_hex, &version_binary, sizeof(version_binary));
if (!IsValidVersion(version_binary))
if (version_binary == kInvalidVersion)
{
// invalid version encountered
return SpanContext::GetInvalid();
}

if (IsHigherVersion(version_binary) && trace_parent.size() < kTraceParentSize)
// See https://www.w3.org/TR/trace-context/#versioning-of-traceparent
if (version_binary > kDefaultAssumedVersion)
{
return SpanContext::GetInvalid();
// higher than default version detected
if (trace_parent.size() < kTraceParentSize)
{
return SpanContext::GetInvalid();
}
}

if (!IsHigherVersion(version_binary) && trace_parent.size() != kTraceParentSize)
else
{
return SpanContext::GetInvalid();
// version is either lower or same as the default version
if (trace_parent.size() != kTraceParentSize)
{
return SpanContext::GetInvalid();
}
}

TraceId trace_id = TraceIdFromHex(trace_id_hex);
Expand Down

0 comments on commit bb5f91a

Please sign in to comment.