ceph/cmake/modules/BuildOpentelemetry.cmake
Omri Zeneva 320a2179a3 tracer/osd/librados/build/rgw: rgw and osd end2end tracing using opentelemetry
* build: add opentelemetry to cmake system
crimson targets that uses Message.cc/h are built before opentelemetry (o-tel), so we need to build o-tel eralier so we also add the library to the include path earlier
this shoud work for WITH_JAEGER flag both the ON/OFF cases, and for librados where the compilation flag is ignored

* msg/tracer: add o-tel trace to Messages with decode/encode function in tracer.h
some files that uses Message.cc/h just need the encode/decode functions  and not all others functions.
some crimson targets does not link with ceph_context (common) which is required for tracer.cc file. so we just need to include that functions

* librados: Add opentelemtry trace param for aio_operate and operate methods
in order to propagate the trace info I added the otel-trace as an extra param.
in some places, there already was a blkin trace info, and since it is not used in other places we can safely change it to o-tel trace info.
this will be done in another commit, so the cleanup of blkin trace will be in a dedicated commit

* osd: use the o-tel trace of the msg as a parent span of the osd trace
if there is a valid span in the msg, we will add this op to the request
trace, otherwise it will start a new trace for the OSD op

* rgw: pass put obj trace info to librados
in order to make it possible, I saved the trace info inside the sal::Object, so we can use it later when writing the object to rados
it could be used also later for read ops.
note the trace field of req_state is initalized only in rgw_process, so it's also required in librgw request flow

* prevent breaking channges to kSize. make sure that changes between components built with
different versions of OTEL do not break message compatibility

Signed-off-by: Omri Zeneva <ozeneva@redhat.com>
2024-02-06 08:01:42 +00:00

87 lines
3.9 KiB
CMake

function(target_create _target _lib)
add_library(${_target} STATIC IMPORTED)
set_target_properties(
${_target} PROPERTIES IMPORTED_LOCATION
"${opentelemetry_BINARY_DIR}/${_lib}")
endfunction()
function(build_opentelemetry)
set(opentelemetry_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src/jaegertracing/opentelemetry-cpp")
set(opentelemetry_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/opentelemetry-cpp")
set(opentelemetry_cpp_targets opentelemetry_trace opentelemetry_exporter_jaeger_trace)
set(opentelemetry_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DWITH_JAEGER=ON
-DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=Release
-DWITH_EXAMPLES=OFF)
set(opentelemetry_libs
${opentelemetry_BINARY_DIR}/sdk/src/trace/libopentelemetry_trace.a
${opentelemetry_BINARY_DIR}/sdk/src/resource/libopentelemetry_resources.a
${opentelemetry_BINARY_DIR}/sdk/src/common/libopentelemetry_common.a
${opentelemetry_BINARY_DIR}/exporters/jaeger/libopentelemetry_exporter_jaeger_trace.a
${opentelemetry_BINARY_DIR}/ext/src/http/client/curl/libopentelemetry_http_client_curl.a
${CURL_LIBRARIES}
)
set(opentelemetry_include_dir ${opentelemetry_SOURCE_DIR}/api/include/
${opentelemetry_SOURCE_DIR}/exporters/jaeger/include/
${opentelemetry_SOURCE_DIR}/ext/include/
${opentelemetry_SOURCE_DIR}/sdk/include/)
# TODO: add target based propogation
set(opentelemetry_deps opentelemetry_trace opentelemetry_resources opentelemetry_common
opentelemetry_exporter_jaeger_trace http_client_curl
${CURL_LIBRARIES})
if(CMAKE_MAKE_PROGRAM MATCHES "make")
# try to inherit command line arguments passed by parent "make" job
set(make_cmd $(MAKE) ${opentelemetry_cpp_targets})
else()
set(make_cmd ${CMAKE_COMMAND} --build <BINARY_DIR> --target
${opentelemetry_cpp_targets})
endif()
if(WITH_SYSTEM_BOOST)
list(APPEND opentelemetry_CMAKE_ARGS -DBOOST_ROOT=${BOOST_ROOT})
else()
list(APPEND dependencies Boost)
list(APPEND opentelemetry_CMAKE_ARGS -DBoost_INCLUDE_DIR=${CMAKE_BINARY_DIR}/boost/include)
endif()
include(ExternalProject)
ExternalProject_Add(opentelemetry-cpp
SOURCE_DIR ${opentelemetry_SOURCE_DIR}
PREFIX "opentelemetry-cpp"
CMAKE_ARGS ${opentelemetry_CMAKE_ARGS}
BUILD_COMMAND ${make_cmd}
BINARY_DIR ${opentelemetry_BINARY_DIR}
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${opentelemetry_libs}
DEPENDS ${dependencies}
LOG_BUILD ON)
# CMake doesn't allow to add a list of libraries to the import property, hence
# we create individual targets and link their libraries which finally
# interfaces to opentelemetry target
target_create("opentelemetry_trace" "sdk/src/trace/libopentelemetry_trace.a")
target_create("opentelemetry_resources"
"sdk/src/resource/libopentelemetry_resources.a")
target_create("opentelemetry_common"
"sdk/src/common/libopentelemetry_common.a")
target_create("opentelemetry_exporter_jaeger_trace"
"exporters/jaeger/libopentelemetry_exporter_jaeger_trace.a")
target_create("http_client_curl"
"ext/src/http/client/curl/libopentelemetry_http_client_curl.a")
# will do all linking and path setting fake include path for
# interface_include_directories since this happens at build time
file(MAKE_DIRECTORY ${opentelemetry_include_dir})
add_library(opentelemetry::libopentelemetry INTERFACE IMPORTED)
add_dependencies(opentelemetry::libopentelemetry opentelemetry-cpp)
set_target_properties(
opentelemetry::libopentelemetry
PROPERTIES
INTERFACE_LINK_LIBRARIES "${opentelemetry_deps}"
INTERFACE_INCLUDE_DIRECTORIES "${opentelemetry_include_dir}")
include_directories(SYSTEM "${opentelemetry_include_dir}")
endfunction()