From bb5f91a028eeabab5e92f4353934c9d36e54507f Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Tue, 5 Nov 2024 22:03:48 +0000 Subject: [PATCH] Remove one-liner functions with inline code --- .../trace/propagation/http_trace_context.h | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/api/include/opentelemetry/trace/propagation/http_trace_context.h b/api/include/opentelemetry/trace/propagation/http_trace_context.h index e6a436d110..81d4c308ec 100644 --- a/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -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) { @@ -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);