Fails to build with Protobuf v22+ · Issue #16 · nginxinc/nginx-otel (original) (raw)

Describe the bug

Protobuf v22 has a breaking change in logging that breaks how nginx-otel uses it.
https://github.com/protocolbuffers/protobuf/releases/tag/v22.0

protobuf-dev no longer includes a logging.h, and no longer provides google::protobuf::LogLevel or google::protobuf::SetLogHandler.

Error when building with protobuf v23.4:

/opt/nginx-otel-main/src/http_module.cpp:510:6: error: variable or field 'protobufLogHandler' declared void
  510 | void protobufLogHandler(google::protobuf::LogLevel logLevel,
      |      ^~~~~~~~~~~~~~~~~~
/opt/nginx-otel-main/src/http_module.cpp:510:43: error: 'LogLevel' is not a member of 'google::protobuf'
  510 | void protobufLogHandler(google::protobuf::LogLevel logLevel,
      |                                           ^~~~~~~~
/opt/nginx-otel-main/src/http_module.cpp:511:5: error: expected primary-expression before 'const'
  511 |     const char* filename, int line, const std::string& msg)
      |     ^~~~~
/opt/nginx-otel-main/src/http_module.cpp:511:27: error: expected primary-expression before 'int'
  511 |     const char* filename, int line, const std::string& msg)
      |                           ^~~
/opt/nginx-otel-main/src/http_module.cpp:511:37: error: expected primary-expression before 'const'
  511 |     const char* filename, int line, const std::string& msg)
      |                                     ^~~~~
/opt/nginx-otel-main/src/http_module.cpp: In function 'ngx_int_t {anonymous}::initModule(ngx_conf_t*)':
/opt/nginx-otel-main/src/http_module.cpp:545:23: error: 'SetLogHandler' is not a member of 'google::protobuf'
  545 |     google::protobuf::SetLogHandler(protobufLogHandler);
      |                       ^~~~~~~~~~~~~
/opt/nginx-otel-main/src/http_module.cpp:545:37: error: 'protobufLogHandler' was not declared in this scope
  545 |     google::protobuf::SetLogHandler(protobufLogHandler);
      |                                     ^~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/ngx_otel_module.dir/build.make:76: CMakeFiles/ngx_otel_module.dir/src/http_module.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/ngx_otel_module.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Your environment

Building from source with Alpine edge in docker.

FROM docker.io/library/alpine:20230901 as otel-module-builder

Build nginx OpenTelemetry module

https://github.com/nginxinc/nginx-otel

WORKDIR /opt

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && apk update RUN apk add
cmake build-base openssl-dev zlib-dev pcre-dev
pkgconfig c-ares-dev re2-dev
opentelemetry-cpp-dev grpc-dev protobuf-dev
unzip

RUN wget https://github.com/nginx/nginx/archive/refs/tags/release-1.25.2.zip; unzip release-1.25.2.zip; mv nginx-release-1.25.2 nginx WORKDIR /opt/nginx RUN auto/configure --with-compat

WORKDIR /opt RUN wget https://github.com/nginxinc/nginx-otel/archive/refs/heads/main.zip; unzip main.zip COPY configs/nginx-otel-CMakeLists.txt /opt/nginx-otel-main/CMakeLists.txt RUN sed -i
's!#include <google/protobuf/stubs/logging.h>!#include <google/protobuf/stubs/common.h>!'
/opt/nginx-otel-main/src/http_module.cpp # Fix link to old version of protobuf? WORKDIR /opt/nginx-otel-main/build RUN cmake -DNGX_OTEL_NGINX_BUILD_DIR=/opt/nginx/objs .. RUN make -j 8

I overrode CMakeLists manually because building opentelemetry-cpp from source was slow.

# nginx-otel-CMakeLists.txt
cmake_minimum_required(VERSION 3.24.0)
project(nginx-otel)

set(NGX_OTEL_NGINX_BUILD_DIR ""
    CACHE PATH "Nginx build (objs) dir")
set(NGX_OTEL_NGINX_DIR "${NGX_OTEL_NGINX_BUILD_DIR}/.."
    CACHE PATH "Nginx source dir")

set(NGX_OTEL_FETCH_DEPS ON CACHE BOOL "Download dependencies")
set(NGX_OTEL_PROTO_DIR  "" CACHE PATH "OTel proto files root")

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)

find_package(opentelemetry-cpp REQUIRED)
find_package(protobuf REQUIRED)
find_package(gRPC REQUIRED)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)

add_compile_options(-Wall -Wtype-limits -Werror)

add_library(ngx_otel_module MODULE
    src/http_module.cpp
    src/modules.c)

# avoid 'lib' prefix in binary name
set_target_properties(ngx_otel_module PROPERTIES PREFIX "")

target_include_directories(ngx_otel_module PRIVATE
    ${NGX_OTEL_NGINX_BUILD_DIR}
    ${NGX_OTEL_NGINX_DIR}/src/core
    ${NGX_OTEL_NGINX_DIR}/src/event
    ${NGX_OTEL_NGINX_DIR}/src/event/modules
    ${NGX_OTEL_NGINX_DIR}/src/event/quic
    ${NGX_OTEL_NGINX_DIR}/src/os/unix
    ${NGX_OTEL_NGINX_DIR}/src/http
    ${NGX_OTEL_NGINX_DIR}/src/http/modules
    ${NGX_OTEL_NGINX_DIR}/src/http/v2
    ${NGX_OTEL_NGINX_DIR}/src/http/v3
    /usr/include/opentelemetry/proto/)

target_link_libraries(ngx_otel_module
    opentelemetry-cpp::trace
    gRPC::grpc++)