This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 756c49ff52 Static link opentelemetry-cpp libraries to otel_tracer
plugin (#12026)
756c49ff52 is described below
commit 756c49ff52219e376bd60420e6081f64f8b5d3c7
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Sun Mar 30 21:36:02 2025 +0900
Static link opentelemetry-cpp libraries to otel_tracer plugin (#12026)
* Static link opentelemetry-cpp libraries to otel_tracer plugin
Without this, `cmake --build build --target test` causes an error
that failes to load otel_tracer.so because of undefined symbol
`_ZN6google8protobuf7Message19CopyWithSourceCheckERS1_RKS1_`.
Also update instructions for building and installing dependency
libraries using CMake.
Also update opentelemetry-cpp version to v1.19.0.
* Make otel_tracer to be built on macOS successfully again
Also remove unused opentelemetry libraries on OSes other than macOS.
---
cmake/Findopentelemetry.cmake | 62 +++++++++++++++++++++----
doc/admin-guide/plugins/otel_tracer.en.rst | 32 ++++++++-----
plugins/experimental/otel_tracer/CMakeLists.txt | 14 +++++-
3 files changed, 87 insertions(+), 21 deletions(-)
diff --git a/cmake/Findopentelemetry.cmake b/cmake/Findopentelemetry.cmake
index ca48cd8444..9bfcb5f945 100644
--- a/cmake/Findopentelemetry.cmake
+++ b/cmake/Findopentelemetry.cmake
@@ -20,13 +20,45 @@
# This will define the following variables
#
# opentelemetry_FOUND
-# opentelemetry_LIBRARY
+# opentelemetry_exporter_ostream_span_LIBRARY
+# opentelemetry_exporter_otlp_http_LIBRARY
+# opentelemetry_exporter_otlp_http_client_LIBRARY
+# opentelemetry_exporter_otlp_http_log_LIBRARY
+# opentelemetry_exporter_otlp_http_metric_LIBRARY
+# opentelemetry_http_client_curl_LIBRARY
+# opentelemetry_metrics_LIBRARY
+# opentelemetry_otlp_recordable_LIBRARY
+# opentelemetry_proto_LIBRARY
+# opentelemetry_resources_LIBRARY
+# opentelemetry_trace_LIBRARY
+# opentelemetry_version_LIBRARY
+# opentelemetry_common_LIBRARY
+# opentelemetry_metrics_LIBRARY
+# opentelemetry_logs_LIBRARY
# opentelemetry_INCLUDE_DIRS
#
# and the following imported targets
#
+# on macOS
# opentelemetry::opentelemetry
#
+# on other OSes
+# opentelemetry::opentelemetry_exporter_ostream_span
+# opentelemetry::opentelemetry_exporter_otlp_http
+# opentelemetry::opentelemetry_exporter_otlp_http_client
+# opentelemetry::opentelemetry_exporter_otlp_http_log
+# opentelemetry::opentelemetry_exporter_otlp_http_metric
+# opentelemetry::opentelemetry_http_client_curl
+# opentelemetry::opentelemetry_metrics
+# opentelemetry::opentelemetry_otlp_recordable
+# opentelemetry::opentelemetry_proto
+# opentelemetry::opentelemetry_resources
+# opentelemetry::opentelemetry_trace
+# opentelemetry::opentelemetry_version
+# opentelemetry::opentelemetry_common
+# opentelemetry::opentelemetry_metrics
+# opentelemetry::opentelemetry_logs
+#
#opentelemetry has a lot of libraries
set(OTEL_LIBS
@@ -59,18 +91,32 @@ include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(opentelemetry REQUIRED_VARS
opentelemetry_INCLUDE_DIR ${OTEL_LIBRARIES})
if(opentelemetry_FOUND)
- mark_as_advanced(opentelemetry_FOUND ${OTEL_LIBRARIES})
set(opentelemetry_INCLUDE_DIRS "${opentelemetry_INCLUDE_DIR}")
+ mark_as_advanced(opentelemetry_FOUND opentelemetry_INCLUDE_DIR
${OTEL_LIBRARIES})
foreach(OTELLIB ${OTEL_LIBRARIES})
- list(APPEND opentelemetry_LIBRARIES ${${OTELLIB}})
+ list(APPEND opentelemetry_found_LIBRARIES ${${OTELLIB}})
endforeach()
- message(STATUS "Opentelemetry found: ${opentelemetry_LIBRARIES}")
+ message(STATUS "Opentelemetry found: ${opentelemetry_found_LIBRARIES}")
message(STATUS "Opentelemetry include: ${opentelemetry_INCLUDE_DIRS}")
- if(NOT TARGET opentelemetry::opentelemetry)
- add_library(opentelemetry::opentelemetry INTERFACE IMPORTED)
- target_include_directories(opentelemetry::opentelemetry INTERFACE
${opentelemetry_INCLUDE_DIRS})
- target_link_libraries(opentelemetry::opentelemetry INTERFACE
${opentelemetry_LIBRARIES})
+ if(APPLE)
+ if(NOT TARGET opentelemetry::opentelemetry)
+ add_library(opentelemetry::opentelemetry INTERFACE IMPORTED)
+ target_include_directories(opentelemetry::opentelemetry INTERFACE
${opentelemetry_INCLUDE_DIRS})
+ target_link_libraries(opentelemetry::opentelemetry INTERFACE
${opentelemetry_found_LIBRARIES})
+ list(APPEND opentelemetry_LIBRARIES opentelemetry::opentelemetry)
+ endif()
+ else()
+ foreach(OTLIB ${OTEL_LIBS})
+ if(NOT TARGET opentelemetry::${OTLIB})
+ add_library(opentelemetry::${OTLIB} STATIC IMPORTED)
+ set_target_properties(
+ opentelemetry::${OTLIB} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${opentelemetry_INCLUDE_DIR}"
+ IMPORTED_LOCATION
"${${OTLIB}_LIBRARY}"
+ )
+ list(APPEND opentelemetry_LIBRARIES opentelemetry::${OTLIB})
+ endif()
+ endforeach()
endif()
endif()
diff --git a/doc/admin-guide/plugins/otel_tracer.en.rst
b/doc/admin-guide/plugins/otel_tracer.en.rst
index 84ceb55aeb..504875ff28 100644
--- a/doc/admin-guide/plugins/otel_tracer.en.rst
+++ b/doc/admin-guide/plugins/otel_tracer.en.rst
@@ -50,6 +50,17 @@ Compiling the Plugin
To compile this plugin, we need nlohmann-json, protobuf and opentelemetry-cpp
+nlohmann-json:
+
+::
+
+ wget https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.tar.gz
+ tar zxvf v3.11.3.tar.gz
+ cd json-3.11.3
+ cmake -B build -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=ON
+ cmake --build build --config Release --parallel --verbose
+ sudo cmake --install build --prefix /usr/local/
+
protobuf:
::
@@ -58,24 +69,21 @@ protobuf:
wget
https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.tar.gz
tar zxvf v3.21.12.tar.gz
cd protobuf-3.21.12
- ./autogen.sh
- ./configure --enable-shared=no --enable-static=yes CXXFLAGS="-std=c++17
-fPIC" CFLAGS="-fPIC"
- make
- make install
+ cmake -B build -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
+ cmake --build build --config Release --parallel --verbose
+ sudo cmake --install build --prefix /usr/local/
opentelemetry-cpp
::
cd
- wget
https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.11.0.tar.gz
- tar zxvf v1.11.0.tar.gz
- cd opentelemetry-cpp-1.11.0
- mkdir build
- cd build
- cmake .. -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DWITH_JAEGER=OFF
-DWITH_OTLP_GRPC=OFF -DWITH_OTLP_HTTP=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_ABSEIL=OFF
- cmake --build . --target all
- cmake --install . --config Debug --prefix /usr/local/
+ wget
https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.19.0.tar.gz
+ tar zxvf v1.19.0.tar.gz
+ cd opentelemetry-cpp-1.19.0
+ cmake -B build -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF
-DWITH_EXAMPLES=OFF -DWITH_OTLP_GRPC=OFF -DWITH_OTLP_HTTP=ON
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_ABSEIL=OFF
+ cmake --build build --config Release --parallel --verbose
+ sudo cmake --install build --prefix /usr/local/
Installation
============
diff --git a/plugins/experimental/otel_tracer/CMakeLists.txt
b/plugins/experimental/otel_tracer/CMakeLists.txt
index 8b9ab00579..5b0a478719 100644
--- a/plugins/experimental/otel_tracer/CMakeLists.txt
+++ b/plugins/experimental/otel_tracer/CMakeLists.txt
@@ -16,5 +16,17 @@
#######################
add_atsplugin(otel_tracer otel_tracer.cc)
-target_link_libraries(otel_tracer PRIVATE opentelemetry::opentelemetry
protobuf::libprotobuf CURL::libcurl)
+if(CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED OR
CMAKE_CXX_LINK_GROUP_USING_RESCAN_SUPPORTED)
+ string(JOIN "," opentelemetry_LIBRARIES_CSV ${opentelemetry_LIBRARIES})
+ target_link_libraries(
+ otel_tracer PRIVATE
"$<LINK_GROUP:RESCAN,${opentelemetry_LIBRARIES_CSV},protobuf::libprotobuf,CURL::libcurl>"
+ )
+elseif(APPLE)
+ target_link_libraries(otel_tracer PRIVATE ${opentelemetry_LIBRARIES}
protobuf::libprotobuf CURL::libcurl)
+else()
+ target_link_libraries(
+ otel_tracer PRIVATE -Wl,--start-group ${opentelemetry_LIBRARIES}
protobuf::libprotobuf CURL::libcurl
+ -Wl,--end-group
+ )
+endif()
verify_global_plugin(otel_tracer)