From a22bbd3877d443a2a18049f1c65d9d1cd77c4dbe Mon Sep 17 00:00:00 2001 From: Yutong Zhang Date: Tue, 28 Apr 2026 15:14:55 +0800 Subject: [PATCH] Add --enable-otlp configure flag and 'otlp' debian build profile Wire the build system to optionally pull in opentelemetry-cpp so a follow-up PR can add an OTLP sink to ComponentStats. The default build is unchanged: * configure.ac gains a new --enable-otlp option (default: disabled). When enabled, the build probes for opentelemetry-cpp via pkg-config and falls back to a header check + a hard-coded -l list for SDKs that are not packaged with .pc files. HAVE_OTLP is defined and OTLP is exposed as an automake conditional, plus OPENTELEMETRY_CFLAGS / OPENTELEMETRY_LIBS substitutions for use by Makefile.am in later PRs. * debian/rules gains a new 'otlp' build profile. When the profile is active, --enable-otlp is passed to configure; otherwise --disable-otlp is passed, which is the current behaviour. This is the build-system half of Phase 2 in the Component Statistics HLD (sonic-net/SONiC#2312). It does not add any source files, does not change the public API, and does not affect any default build path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Yutong Zhang --- configure.ac | 30 ++++++++++++++++++++++++++++++ debian/rules | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/configure.ac b/configure.ac index 287ff2722..13c973178 100644 --- a/configure.ac +++ b/configure.ac @@ -44,9 +44,39 @@ AC_ARG_ENABLE(yangmodules, no) yangmodules=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-yangmodules) ;; esac],[yangmodules=true]) +AC_ARG_ENABLE(otlp, +[ --enable-otlp Build the OTLP sink (requires opentelemetry-cpp)], +[case "${enableval}" in + yes) otlp=true ;; + no) otlp=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-otlp) ;; +esac],[otlp=false]) AM_CONDITIONAL(DEBUG, test x$debug = xtrue) AM_CONDITIONAL(PYTHON2, test x$python2 = xtrue) AM_CONDITIONAL(YANGMODS, test x$yangmodules = xtrue) +AM_CONDITIONAL(OTLP, test x$otlp = xtrue) + +if test x$otlp = xtrue; then + PKG_CHECK_MODULES([OPENTELEMETRY], + [opentelemetry_api opentelemetry_sdk opentelemetry_exporter_otlp_grpc], + [have_otlp_pkgconfig=yes], + [have_otlp_pkgconfig=no]) + if test x$have_otlp_pkgconfig = xno; then + # opentelemetry-cpp does not ship pkg-config files in all distributions. + # Fall back to header + library probes so the build still succeeds when + # the SDK is installed under a standard prefix. + AC_LANG_PUSH([C++]) + AC_CHECK_HEADER([opentelemetry/version.h], [], + [AC_MSG_ERROR([--enable-otlp requested but opentelemetry-cpp headers were not found. Install opentelemetry-cpp or pass CPPFLAGS=-I/include.])]) + AC_LANG_POP([C++]) + OPENTELEMETRY_CFLAGS="" + OPENTELEMETRY_LIBS="-lopentelemetry_exporter_otlp_grpc -lopentelemetry_otlp_recordable -lopentelemetry_proto -lopentelemetry_resources -lopentelemetry_trace -lopentelemetry_metrics -lopentelemetry_common -lgrpc++ -lgrpc -lprotobuf" + fi + AC_DEFINE([HAVE_OTLP], [1], [Define to 1 if the OTLP sink is built]) +fi +AC_SUBST([OPENTELEMETRY_CFLAGS]) +AC_SUBST([OPENTELEMETRY_LIBS]) + if test x$CONFIGURED_ARCH = xarmhf && test x$CROSS_BUILD_ENVIRON = xy; then AM_CONDITIONAL(ARCH64, false) else diff --git a/debian/rules b/debian/rules index 928253b00..f2cf172a3 100755 --- a/debian/rules +++ b/debian/rules @@ -35,6 +35,16 @@ else CONFIGURE_ARGS += --enable-yangmodules endif +# Build the OTLP sink only when the 'otlp' build profile is active. The +# OTLP sink depends on opentelemetry-cpp, which is not yet packaged in +# every distribution; the default build keeps OTLP off so behaviour is +# unchanged. +ifneq (,$(filter otlp,$(DEB_BUILD_PROFILES))) +CONFIGURE_ARGS += --enable-otlp +else +CONFIGURE_ARGS += --disable-otlp +endif + # main packaging script %: dh $@