From 4968d0a4284f1e0002f23352b6891efc92058eba Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 30 Mar 2026 14:59:33 -0700 Subject: [PATCH] Fix build with C++20. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenTelemetry SDK built with C++20 uses std::span in the API, and we want to match the standard to avoid type changes at the API boundary. However, std::span constructor is explicit for non-default Extent, requiring us to use a more verbose specification instead of an initializer list. ``` src/trace_context.hpp:75:33: error: converting to ‘opentelemetry::v1::nostd::span’ {aka ‘std::span’} from initializer list would use explicit constructor ‘constexpr std::span<_Type, _Extent>::span(_It, size_type) [with _It = char*; _Type = char; long unsigned int _Extent = 32; size_type = long unsigned int]’ 75 | tc.traceId.ToLowerBase16({out, kTraceIdSize}); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ ``` --- src/http_module.cpp | 6 ++++-- src/trace_context.hpp | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/http_module.cpp b/src/http_module.cpp index 78a5e896..1ccfece9 100644 --- a/src/http_module.cpp +++ b/src/http_module.cpp @@ -859,6 +859,8 @@ template ngx_int_t hexIdVar(ngx_http_request_t* r, ngx_http_variable_value_t* v, uintptr_t data) { + namespace nostd = opentelemetry::nostd; + auto ctx = ensureOtelCtx(r); if (!ctx) { return NGX_ERROR; @@ -867,13 +869,13 @@ ngx_int_t hexIdVar(ngx_http_request_t* r, ngx_http_variable_value_t* v, auto id = (Id*)((char*)ctx + data); if (id->IsValid()) { - auto size = id->Id().size() * 2; + constexpr auto size = 2 * Id::kSize; auto buf = (char*)ngx_pnalloc(r->pool, size); if (buf == NULL) { return NGX_ERROR; } - id->ToLowerBase16({buf, size}); + id->ToLowerBase16(nostd::span{buf, size}); v->len = size; v->valid = 1; diff --git a/src/trace_context.hpp b/src/trace_context.hpp index 2d9c266d..4a27a7d4 100644 --- a/src/trace_context.hpp +++ b/src/trace_context.hpp @@ -67,16 +67,17 @@ struct TraceContext { static void serialize(const TraceContext& tc, char* out) { using namespace opentelemetry::trace::propagation; + namespace nostd = opentelemetry::nostd; *out++ = '0'; *out++ = '0'; *out++ = '-'; - tc.traceId.ToLowerBase16({out, kTraceIdSize}); + tc.traceId.ToLowerBase16(nostd::span{out, kTraceIdSize}); out += kTraceIdSize; *out++ = '-'; - tc.spanId.ToLowerBase16({out, kSpanIdSize}); + tc.spanId.ToLowerBase16(nostd::span{out, kSpanIdSize}); out += kSpanIdSize; *out++ = '-';