Skip to content

Commit 2e3d1e4

Browse files
authored
Merge pull request #395 from open-telemetry/main
merged from upstream
2 parents 2272817 + 1ad6674 commit 2e3d1e4

File tree

8 files changed

+180
-135
lines changed

8 files changed

+180
-135
lines changed

.github/workflows/cmake_install.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ jobs:
215215
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test
216216

217217
ubuntu_2404_conan_latest:
218-
name: Ubuntu 24.04 conan latest versions cxx17 (static libs)
218+
name: Ubuntu 24.04 conan latest versions cxx17 (static libs - opentracing shim)
219219
runs-on: ubuntu-24.04
220220
env:
221221
INSTALL_TEST_DIR: '/home/runner/install_test'
@@ -248,6 +248,8 @@ jobs:
248248
run: |
249249
export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
250250
./ci/verify_packages.sh
251+
- name: Run OpenTracing Shim Test
252+
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test
251253

252254
macos_14_conan_stable:
253255
name: macOS 14 conan stable versions cxx17 (static libs)

CMakeLists.txt

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ project(opentelemetry-cpp)
3636
# Mark variables as used so cmake doesn't complain about them
3737
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)
3838

39-
# Note: CMAKE_FIND_PACKAGE_PREFER_CONFIG requires cmake 3.15. Prefer cmake
40-
# CONFIG search mode to find dependencies. This is important to properly find
41-
# protobuf versions 3.22.0 and above due to the abseil-cpp dependency.
42-
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
43-
4439
# Don't use customized cmake modules if vcpkg is used to resolve dependence.
4540
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
4641
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
@@ -79,10 +74,6 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
7974
CACHE STRING "")
8075
endif()
8176

82-
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
83-
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
84-
endif()
85-
8677
option(WITH_ABI_VERSION_1 "ABI version 1" ON)
8778
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)
8879

@@ -310,49 +301,7 @@ endif()
310301
include(GNUInstallDirs)
311302

312303
if(WITH_PROMETHEUS)
313-
find_package(prometheus-cpp CONFIG QUIET)
314-
if(NOT prometheus-cpp_FOUND)
315-
message(STATUS "Trying to use local prometheus-cpp from submodule")
316-
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
317-
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
318-
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
319-
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
320-
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
321-
set(ENABLE_TESTING OFF)
322-
set(CMAKE_CXX_CLANG_TIDY "")
323-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
324-
add_subdirectory(third_party/prometheus-cpp)
325-
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
326-
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
327-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
328-
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
329-
330-
# Get the version of the prometheus-cpp submodule
331-
find_package(Git QUIET)
332-
if(Git_FOUND)
333-
execute_process(
334-
COMMAND ${GIT_EXECUTABLE} describe --tags --always
335-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/prometheus-cpp
336-
OUTPUT_VARIABLE prometheus-cpp_VERSION
337-
OUTPUT_STRIP_TRAILING_WHITESPACE)
338-
string(REGEX REPLACE "^v" "" prometheus-cpp_VERSION
339-
"${prometheus-cpp_VERSION}")
340-
endif()
341-
342-
message(
343-
STATUS
344-
"Using local prometheus-cpp from submodule. Version = ${prometheus-cpp_VERSION}"
345-
)
346-
else()
347-
message(
348-
FATAL_ERROR
349-
"\nprometheus-cpp package was not found. Please either provide it manually or clone with submodules. "
350-
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
351-
"git submodule update --init --recursive")
352-
endif()
353-
else()
354-
message(STATUS "Using external prometheus-cpp")
355-
endif()
304+
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/prometheus-cpp.cmake")
356305
endif()
357306

358307
if(WITH_OTLP_GRPC
@@ -497,6 +446,14 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
497446
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/nlohmann-json.cmake")
498447
endif()
499448

449+
#
450+
# Do we need OpenTracing ?
451+
#
452+
453+
if(WITH_OPENTRACING)
454+
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentracing-cpp.cmake")
455+
endif()
456+
500457
if(OTELCPP_MAINTAINER_MODE)
501458
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
502459
message(STATUS "Building with gcc in maintainer mode.")
@@ -700,8 +657,14 @@ if(USE_NLOHMANN_JSON)
700657
STATUS "nlohmann-json: ${nlohmann_json_VERSION} (${nlohmann_json_PROVIDER})"
701658
)
702659
endif()
703-
if(prometheus-cpp_FOUND)
704-
message(STATUS "prometheus-cpp: ${prometheus-cpp_VERSION}")
660+
if(WITH_PROMETHEUS)
661+
message(
662+
STATUS
663+
"prometheus-cpp: ${prometheus-cpp_VERSION} (${prometheus-cpp_PROVIDER})")
664+
endif()
665+
if(WITH_OPENTRACING)
666+
message(
667+
STATUS "opentracing-cpp: ${OpenTracing_VERSION} (${OpenTracing_PROVIDER})")
705668
endif()
706669
message(STATUS "---------------------------------------------")
707670

@@ -731,30 +694,6 @@ include_directories(api/include)
731694
add_subdirectory(api)
732695

733696
if(WITH_OPENTRACING)
734-
find_package(OpenTracing CONFIG QUIET)
735-
if(NOT OpenTracing_FOUND)
736-
set(OPENTRACING_DIR "third_party/opentracing-cpp")
737-
message(STATUS "Trying to use local ${OPENTRACING_DIR} from submodule")
738-
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
739-
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
740-
set(BUILD_TESTING OFF)
741-
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
742-
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
743-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
744-
add_subdirectory(${OPENTRACING_DIR})
745-
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
746-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
747-
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
748-
else()
749-
message(
750-
FATAL_ERROR
751-
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. "
752-
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
753-
"git submodule update --init --recursive")
754-
endif()
755-
else()
756-
message(STATUS "Using external opentracing-cpp")
757-
endif()
758697
add_subdirectory(opentracing-shim)
759698
endif()
760699

cmake/opentracing-cpp.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
find_package(OpenTracing CONFIG QUIET)
5+
set(OpenTracing_PROVIDER "find_package")
6+
7+
if(NOT OpenTracing_FOUND)
8+
set(_OPENTRACING_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentracing-cpp")
9+
if(EXISTS "${_OPENTRACING_SUBMODULE_DIR}/.git")
10+
FetchContent_Declare(
11+
"opentracing"
12+
SOURCE_DIR "${_OPENTRACING_SUBMODULE_DIR}"
13+
)
14+
set(OpenTracing_PROVIDER "fetch_source")
15+
else()
16+
FetchContent_Declare(
17+
"opentracing"
18+
GIT_REPOSITORY "https://github.com/opentracing/opentracing-cpp.git"
19+
GIT_TAG "${opentracing-cpp_GIT_TAG}"
20+
)
21+
set(OpenTracing_PROVIDER "fetch_repository")
22+
endif()
23+
24+
# OpenTracing uses the BUILD_TESTING variable directly and we must force the cached value to OFF.
25+
# save the current state of BUILD_TESTING
26+
if(DEFINED BUILD_TESTING)
27+
set(_SAVED_BUILD_TESTING ${BUILD_TESTING})
28+
endif()
29+
30+
# Set the cache variables for the opentracing build
31+
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
32+
set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE)
33+
34+
FetchContent_MakeAvailable(opentracing)
35+
36+
# Restore the saved state of BUILD_TESTING
37+
if(DEFINED _SAVED_BUILD_TESTING)
38+
set(BUILD_TESTING ${_SAVED_BUILD_TESTING} CACHE BOOL "" FORCE)
39+
else()
40+
unset(BUILD_TESTING CACHE)
41+
endif()
42+
43+
# Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy.
44+
foreach(_target opentracing opentracing-static)
45+
if(TARGET ${_target})
46+
# Add missing include directories
47+
target_include_directories(${_target} PUBLIC
48+
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/include>"
49+
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/3rd_party/include>"
50+
"$<BUILD_INTERFACE:${opentracing_BINARY_DIR}/include>"
51+
)
52+
# Disable CXX_INCLUDE_WHAT_YOU_USE and CXX_CLANG_TIDY
53+
set_target_properties(${_target}
54+
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "")
55+
# Create alias targets
56+
if(NOT TARGET OpenTracing::${_target})
57+
add_library(OpenTracing::${_target} ALIAS ${_target})
58+
endif()
59+
endif()
60+
endforeach()
61+
62+
# Set the OpenTracing_VERSION variable from the git tag.
63+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" OpenTracing_VERSION "${opentracing-cpp_GIT_TAG}")
64+
endif(NOT OpenTracing_FOUND)
65+
66+
if(NOT TARGET OpenTracing::opentracing AND NOT TARGET OpenTracing::opentracing-static)
67+
message(FATAL_ERROR "No OpenTracing targets (OpenTracing::opentracing or OpenTracing::opentracing-static) were imported")
68+
endif()

cmake/prometheus-cpp.cmake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Import prometheus-cpp targets (prometheus-cpp::core and prometheus-cpp::pull)
5+
# 1. Find an installed prometheus-cpp package
6+
# 2. Use FetchContent to build prometheus-cpp from a git submodule
7+
# 3. Use FetchContent to fetch and build prometheus-cpp from GitHub
8+
9+
find_package(prometheus-cpp CONFIG QUIET)
10+
set(prometheus-cpp_PROVIDER "find_package")
11+
12+
if(NOT prometheus-cpp_FOUND)
13+
set(_PROMETHEUS_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/prometheus-cpp")
14+
if(EXISTS "${_PROMETHEUS_SUBMODULE_DIR}/.git")
15+
FetchContent_Declare(
16+
"prometheus-cpp"
17+
SOURCE_DIR "${_PROMETHEUS_SUBMODULE_DIR}"
18+
)
19+
set(prometheus-cpp_PROVIDER "fetch_source")
20+
else()
21+
FetchContent_Declare(
22+
"prometheus-cpp"
23+
GIT_REPOSITORY "https://github.com/jupp0r/prometheus-cpp.git"
24+
GIT_TAG "${prometheus-cpp_GIT_TAG}"
25+
GIT_SUBMODULES "3rdparty/civetweb"
26+
)
27+
set(prometheus-cpp_PROVIDER "fetch_repository")
28+
endif()
29+
30+
if(DEFINED ENABLE_TESTING)
31+
set(_SAVED_ENABLE_TESTING ${ENABLE_TESTING})
32+
endif()
33+
34+
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
35+
set(ENABLE_PUSH OFF CACHE BOOL "" FORCE)
36+
set(USE_THIRDPARTY_LIBRARIES ON CACHE BOOL "" FORCE)
37+
38+
FetchContent_MakeAvailable(prometheus-cpp)
39+
40+
if(DEFINED _SAVED_ENABLE_TESTING)
41+
set(ENABLE_TESTING ${_SAVED_ENABLE_TESTING} CACHE BOOL "" FORCE)
42+
else()
43+
unset(ENABLE_TESTING CACHE)
44+
endif()
45+
46+
# Set the prometheus-cpp_VERSION variable from the git tag.
47+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" prometheus-cpp_VERSION "${prometheus-cpp_GIT_TAG}")
48+
49+
# Disable iwyu and clang-tidy
50+
foreach(_prometheus_target core pull civetweb)
51+
set_target_properties(${_prometheus_target} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
52+
CXX_CLANG_TIDY "")
53+
endforeach()
54+
endif()
55+
56+
if(NOT TARGET prometheus-cpp::core OR
57+
NOT TARGET prometheus-cpp::pull)
58+
message(FATAL_ERROR "A required prometheus-cpp target (prometheus-cpp::core or prometheus-cpp::pull) was not imported")
59+
endif()

exporters/prometheus/CMakeLists.txt

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if(NOT TARGET prometheus-cpp::core)
5-
find_package(prometheus-cpp CONFIG REQUIRED)
6-
endif()
7-
84
add_library(
95
opentelemetry_exporter_prometheus
106
src/exporter.cc src/exporter_options.cc src/exporter_factory.cc
@@ -19,22 +15,10 @@ target_include_directories(
1915
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
2016
"$<INSTALL_INTERFACE:include>")
2117

22-
set(PROMETHEUS_EXPORTER_TARGETS opentelemetry_exporter_prometheus)
23-
if(TARGET pull)
24-
list(APPEND PROMETHEUS_EXPORTER_TARGETS pull)
25-
endif()
26-
if(TARGET core)
27-
list(APPEND PROMETHEUS_EXPORTER_TARGETS core)
28-
endif()
29-
if(TARGET util)
30-
list(APPEND PROMETHEUS_EXPORTER_TARGETS util)
31-
endif()
32-
set(PROMETHEUS_CPP_TARGETS prometheus-cpp::pull prometheus-cpp::core)
33-
if(TARGET prometheus-cpp::util)
34-
list(APPEND PROMETHEUS_CPP_TARGETS prometheus-cpp::util)
35-
endif()
36-
target_link_libraries(opentelemetry_exporter_prometheus
37-
PUBLIC opentelemetry_metrics ${PROMETHEUS_CPP_TARGETS})
18+
target_link_libraries(
19+
opentelemetry_exporter_prometheus
20+
PUBLIC opentelemetry_metrics prometheus-cpp::core
21+
PRIVATE prometheus-cpp::pull)
3822

3923
otel_add_component(
4024
COMPONENT

install/conan/conanfile_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protobuf/*:shared=False
2525
abseil/*:fPIC=True
2626
abseil/*:shared=False
2727
opentracing-cpp/*:fPIC=True
28-
opentracing-cpp/*:shared=True
28+
opentracing-cpp/*:shared=False
2929
pcre2/*:with_bzip2=False
3030

3131
[test_requires]

install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ project(opentelemetry-cpp-shims_opentracing-install-test LANGUAGES CXX)
66

77
find_package(opentelemetry-cpp REQUIRED COMPONENTS shims_opentracing)
88

9-
if(NOT TARGET OpenTracing::opentracing)
10-
message(FATAL_ERROR "OpenTracing::opentracing target not found")
9+
if(NOT TARGET OpenTracing::opentracing AND NOT TARGET
10+
OpenTracing::opentracing-static)
11+
message(
12+
FATAL_ERROR
13+
"A required OpenTracing target (OpenTracing::opentracing or OpenTracing::opentracing-static) was not imported"
14+
)
1115
endif()
1216

1317
find_package(GTest CONFIG REQUIRED)

0 commit comments

Comments
 (0)