Skip to content

Commit e3b6c98

Browse files
bavshin-f5p-pautov
authored andcommitted
Fix build with C++20.
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.
1 parent 6b90050 commit e3b6c98

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/http_module.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ template <class Id>
859859
ngx_int_t hexIdVar(ngx_http_request_t* r, ngx_http_variable_value_t* v,
860860
uintptr_t data)
861861
{
862+
namespace nostd = opentelemetry::nostd;
863+
862864
auto ctx = ensureOtelCtx(r);
863865
if (!ctx) {
864866
return NGX_ERROR;
@@ -867,13 +869,13 @@ ngx_int_t hexIdVar(ngx_http_request_t* r, ngx_http_variable_value_t* v,
867869
auto id = (Id*)((char*)ctx + data);
868870

869871
if (id->IsValid()) {
870-
auto size = id->Id().size() * 2;
872+
constexpr auto size = 2 * Id::kSize;
871873
auto buf = (char*)ngx_pnalloc(r->pool, size);
872874
if (buf == NULL) {
873875
return NGX_ERROR;
874876
}
875877

876-
id->ToLowerBase16({buf, size});
878+
id->ToLowerBase16(nostd::span<char, size>{buf, size});
877879

878880
v->len = size;
879881
v->valid = 1;

src/trace_context.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ struct TraceContext {
6767
static void serialize(const TraceContext& tc, char* out)
6868
{
6969
using namespace opentelemetry::trace::propagation;
70+
namespace nostd = opentelemetry::nostd;
7071

7172
*out++ = '0';
7273
*out++ = '0';
7374
*out++ = '-';
7475

75-
tc.traceId.ToLowerBase16({out, kTraceIdSize});
76+
tc.traceId.ToLowerBase16(
77+
nostd::span<char, kTraceIdSize>{out, kTraceIdSize});
7678
out += kTraceIdSize;
7779
*out++ = '-';
7880

79-
tc.spanId.ToLowerBase16({out, kSpanIdSize});
81+
tc.spanId.ToLowerBase16(
82+
nostd::span<char, kSpanIdSize>{out, kSpanIdSize});
8083
out += kSpanIdSize;
8184
*out++ = '-';
8285

0 commit comments

Comments
 (0)