Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Static link opentelemetry-cpp libraries to otel_tracer plugin #12026

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions cmake/Findopentelemetry.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
32 changes: 20 additions & 12 deletions doc/admin-guide/plugins/otel_tracer.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

::
Expand All @@ -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
============
Expand Down
14 changes: 13 additions & 1 deletion plugins/experimental/otel_tracer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)