Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 3 additions & 1 deletion .github/workflows/cmake_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test

ubuntu_2404_conan_latest:
name: Ubuntu 24.04 conan latest versions cxx17 (static libs)
name: Ubuntu 24.04 conan latest versions cxx17 (static libs - opentracing shim)
runs-on: ubuntu-24.04
env:
INSTALL_TEST_DIR: '/home/runner/install_test'
Expand Down Expand Up @@ -248,6 +248,8 @@ jobs:
run: |
export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
./ci/verify_packages.sh
- name: Run OpenTracing Shim Test
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test

macos_14_conan_stable:
name: macOS 14 conan stable versions cxx17 (static libs)
Expand Down
45 changes: 12 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ project(opentelemetry-cpp)
# Mark variables as used so cmake doesn't complain about them
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)

# Note: CMAKE_FIND_PACKAGE_PREFER_CONFIG requires cmake 3.15. Prefer cmake
# CONFIG search mode to find dependencies. This is important to properly find
# protobuf versions 3.22.0 and above due to the abseil-cpp dependency.
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this now that GTest, Protobuf, and gRPC are found with the CONFIG search mode explicitly.


# Don't use customized cmake modules if vcpkg is used to resolve dependence.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
Expand Down Expand Up @@ -79,10 +74,6 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
CACHE STRING "")
endif()

if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
endif()

option(WITH_ABI_VERSION_1 "ABI version 1" ON)
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)

Expand Down Expand Up @@ -497,6 +488,14 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/nlohmann-json.cmake")
endif()

#
# Do we need OpenTracing ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official vcpkg port still supports it as opentelemetry-cpp[opentracing], but I think we could deprecate it, or plan on that.

#

if(WITH_OPENTRACING)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentracing-cpp.cmake")
endif()

if(OTELCPP_MAINTAINER_MODE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Building with gcc in maintainer mode.")
Expand Down Expand Up @@ -701,6 +700,10 @@ endif()
if(prometheus-cpp_FOUND)
message(STATUS "prometheus-cpp: ${prometheus-cpp_VERSION}")
endif()
if(WITH_OPENTRACING)
message(
STATUS "opentracing-cpp: ${OpenTracing_VERSION} (${OpenTracing_PROVIDER})")
endif()
message(STATUS "---------------------------------------------")

include("${opentelemetry-cpp_SOURCE_DIR}/cmake/otel-install-functions.cmake")
Expand All @@ -724,30 +727,6 @@ endif()
add_subdirectory(api)

if(WITH_OPENTRACING)
find_package(OpenTracing CONFIG QUIET)
if(NOT OpenTracing_FOUND)
set(OPENTRACING_DIR "third_party/opentracing-cpp")
message(STATUS "Trying to use local ${OPENTRACING_DIR} from submodule")
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
add_subdirectory(${OPENTRACING_DIR})
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
else()
message(
FATAL_ERROR
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. "
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
"git submodule update --init --recursive")
endif()
else()
message(STATUS "Using external opentracing-cpp")
endif()
add_subdirectory(opentracing-shim)
endif()

Expand Down
68 changes: 68 additions & 0 deletions cmake/opentracing-cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

find_package(OpenTracing CONFIG QUIET)
set(OpenTracing_PROVIDER "find_package")

if(NOT OpenTracing_FOUND)
set(_OPENTRACING_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentracing-cpp")
if(EXISTS "${_OPENTRACING_SUBMODULE_DIR}/.git")
FetchContent_Declare(
"opentracing"
SOURCE_DIR "${_OPENTRACING_SUBMODULE_DIR}"
)
set(OpenTracing_PROVIDER "fetch_source")
else()
FetchContent_Declare(
"opentracing"
GIT_REPOSITORY "https://github.com/opentracing/opentracing-cpp.git"
GIT_TAG "${opentracing-cpp_GIT_TAG}"
)
set(OpenTracing_PROVIDER "fetch_repository")
endif()

# OpenTracing uses the BUILD_TESTING variable directly and we must force the cached value to OFF.
# save the current state of BUILD_TESTING
if(DEFINED BUILD_TESTING)
set(_SAVED_BUILD_TESTING ${BUILD_TESTING})
endif()

# Set the cache variables for the opentracing build
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(opentracing)

# Restore the saved state of BUILD_TESTING
if(DEFINED _SAVED_BUILD_TESTING)
set(BUILD_TESTING ${_SAVED_BUILD_TESTING} CACHE BOOL "" FORCE)
else()
unset(BUILD_TESTING CACHE)
endif()

# Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy.
foreach(_target opentracing opentracing-static)
if(TARGET ${_target})
# Add missing include directories
target_include_directories(${_target} PUBLIC
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/3rd_party/include>"
"$<BUILD_INTERFACE:${opentracing_BINARY_DIR}/include>"
)
# Disable CXX_INCLUDE_WHAT_YOU_USE and CXX_CLANG_TIDY
set_target_properties(${_target}
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "")
# Create alias targets
if(NOT TARGET OpenTracing::${_target})
add_library(OpenTracing::${_target} ALIAS ${_target})
endif()
endif()
endforeach()

# Set the OpenTracing_VERSION variable from the git tag.
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" OpenTracing_VERSION "${opentracing-cpp_GIT_TAG}")
endif(NOT OpenTracing_FOUND)

if(NOT TARGET OpenTracing::opentracing AND NOT TARGET OpenTracing::opentracing-static)
message(FATAL_ERROR "No OpenTracing targets (OpenTracing::opentracing or OpenTracing::opentracing-static) were imported")
endif()
2 changes: 1 addition & 1 deletion install/conan/conanfile_latest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protobuf/*:shared=False
abseil/*:fPIC=True
abseil/*:shared=False
opentracing-cpp/*:fPIC=True
opentracing-cpp/*:shared=True
opentracing-cpp/*:shared=False
pcre2/*:with_bzip2=False

[test_requires]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ project(opentelemetry-cpp-shims_opentracing-install-test LANGUAGES CXX)

find_package(opentelemetry-cpp REQUIRED COMPONENTS shims_opentracing)

if(NOT TARGET OpenTracing::opentracing)
message(FATAL_ERROR "OpenTracing::opentracing target not found")
if(NOT TARGET OpenTracing::opentracing AND NOT TARGET
OpenTracing::opentracing-static)
message(
FATAL_ERROR
"A required OpenTracing target (OpenTracing::opentracing or OpenTracing::opentracing-static) was not imported"
)
endif()

find_package(GTest CONFIG REQUIRED)
Expand Down
55 changes: 22 additions & 33 deletions opentracing-shim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

set(this_target opentelemetry_opentracing_shim)
add_library(
opentelemetry_opentracing_shim src/shim_utils.cc src/span_shim.cc
src/span_context_shim.cc src/tracer_shim.cc)

add_library(${this_target} src/shim_utils.cc src/span_shim.cc
src/span_context_shim.cc src/tracer_shim.cc)

set_target_properties(${this_target} PROPERTIES EXPORT_NAME opentracing_shim)
set_target_version(${this_target})
set_target_properties(opentelemetry_opentracing_shim
PROPERTIES EXPORT_NAME opentracing_shim)
set_target_version(opentelemetry_opentracing_shim)

target_include_directories(
${this_target} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
opentelemetry_opentracing_shim
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

target_link_libraries(opentelemetry_opentracing_shim PUBLIC opentelemetry_api)

if(OPENTRACING_DIR)
target_include_directories(
${this_target}
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${OPENTRACING_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/3rd_party/include>"
)
target_link_libraries(${this_target} opentelemetry_api opentracing)
# link to the shared library target (OpenTracing::opentracing) if it exists
# otherwise use the static library target.
if(TARGET OpenTracing::opentracing)
target_link_libraries(opentelemetry_opentracing_shim
PUBLIC OpenTracing::opentracing)
else()
target_link_libraries(${this_target} opentelemetry_api
OpenTracing::opentracing)
target_link_libraries(opentelemetry_opentracing_shim
PUBLIC OpenTracing::opentracing-static)
endif()

otel_add_component(
COMPONENT
shims_opentracing
TARGETS
${this_target}
opentelemetry_opentracing_shim
FILES_DIRECTORY
"include/opentelemetry/opentracingshim"
FILES_DESTINATION
Expand All @@ -43,20 +42,10 @@ otel_add_component(
if(BUILD_TESTING)
foreach(testname propagation_test shim_utils_test span_shim_test
span_context_shim_test tracer_shim_test)

add_executable(${testname} "test/${testname}.cc")

if(OPENTRACING_DIR)
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api opentelemetry_opentracing_shim opentracing)
else()
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api opentelemetry_opentracing_shim
OpenTracing::opentracing)
endif()

target_link_libraries(
${testname} PRIVATE ${GTEST_BOTH_LIBRARIES} Threads::Threads
opentelemetry_opentracing_shim)
gtest_add_tests(
TARGET ${testname}
TEST_PREFIX opentracing_shim.
Expand Down
Loading