From 716c5faebf99aca006e0ece5ca285b47ebd7bed8 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 | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 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..3283e655b6 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,23 @@ 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) - { - return SpanContext::GetInvalid(); - } - - if (!IsHigherVersion(version_binary) && trace_parent.size() != kTraceParentSize) - { - return SpanContext::GetInvalid(); + // See https://www.w3.org/TR/trace-context/#versioning-of-traceparent + if (version_binary > kDefaultAssumedVersion) { + // higher than default version detected + if (trace_parent.size() < kTraceParentSize) { + return SpanContext::GetInvalid(); + } + } else { + // 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);