diff --git a/.devcontainer/Dockerfile.conan b/.devcontainer/Dockerfile.conan new file mode 100644 index 0000000000..44b0dfdff4 --- /dev/null +++ b/.devcontainer/Dockerfile.conan @@ -0,0 +1,55 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 +FROM ubuntu:24.04 + +RUN apt update && apt install -y \ + build-essential \ + ca-certificates \ + wget \ + cmake \ + git \ + sudo \ + nano \ + pkg-config \ + ninja-build \ + clang-format \ + clang-tidy \ + autoconf \ + automake \ + libtool \ + python3-pip + +RUN pip install conan --break-system-packages + +ARG USER_UID=1000 +ARG USER_GID=1000 +ARG USER_NAME=devuser +ENV USER_NAME=devuser +ENV USER_UID=${USER_UID} +ENV USER_GID=${USER_GID} +ENV INSTALL_PACKAGES= +ENV IS_CONTAINER_BUILD=true + +COPY ./.devcontainer/customize_container.sh /tmp/opentelemetry_cpp/devcontainer/customize_container.sh +RUN /tmp/opentelemetry_cpp/devcontainer/customize_container.sh +USER devuser + +RUN conan profile detect --force + +ARG CONAN_FILE=conanfile_stable.txt +ARG CONAN_BUILD_TYPE=Debug +ARG CXX_STANDARD=17 +WORKDIR /home/devuser/conan +COPY ./install/conan/ . + +RUN conan install ./${CONAN_FILE} --build=missing -s build_type=${CONAN_BUILD_TYPE} +ENV CMAKE_TOOLCHAIN_FILE=/home/devuser/conan/build/${CONAN_BUILD_TYPE}/generators/conan_toolchain.cmake +ENV CXX_STANDARD=${CXX_STANDARD} +ENV BUILD_TYPE=${CONAN_BUILD_TYPE} +ENV CONAN_FILE=${CONAN_FILE} + +WORKDIR /workspaces/opentelemetry-cpp + +ENTRYPOINT [] + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61f7a97db5..05d10e3213 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -302,24 +302,6 @@ jobs: run: | ./ci/do_ci.sh cmake.with_async_export.test -# cmake_abseil_stl_test: -# name: CMake test (with abseil) -# runs-on: ubuntu-20.04 -# steps: -# - uses: actions/checkout@v4 -# with: -# submodules: 'recursive' -# - name: setup -# run: | - -# sudo -E ./ci/setup_ci_environment.sh -# sudo -E ./ci/setup_cmake.sh -# sudo -E ./ci/setup_googletest.sh -# - name: run cmake tests (enable abseil-cpp) -# run: | -# sudo ./ci/install_abseil.sh -# ./ci/do_ci.sh cmake.abseil.test - cmake_opentracing_shim_test: name: CMake test (with opentracing-shim) runs-on: ubuntu-latest @@ -558,26 +540,6 @@ jobs: sudo ./ci/setup_grpc.sh -T ./ci/do_ci.sh cmake.exporter.otprotocol.shared_libs.with_static_grpc.test -# cmake_install_test: -# name: CMake install test (with abseil) -# runs-on: ubuntu-20.04 -# steps: -# - uses: actions/checkout@v4 -# with: -# submodules: 'recursive' -# - name: setup -# run: | -# sudo -E ./ci/setup_ci_environment.sh -# sudo -E ./ci/setup_cmake.sh -# sudo -E ./ci/setup_googletest.sh -# - name: run cmake install (with abseil) -# run: | -# sudo ./ci/install_abseil.sh -# ./ci/do_ci.sh cmake.install.test -# - name: verify packages -# run: | -# ./ci/verify_packages.sh - plugin_test: name: Plugin -> CMake runs-on: ubuntu-latest diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml new file mode 100644 index 0000000000..15075bb90b --- /dev/null +++ b/.github/workflows/cmake_install.yml @@ -0,0 +1,287 @@ +name: CMake Install Tests + +on: + workflow_dispatch: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + windows_2022_vcpkg: + name: Windows 2022 vcpkg cxx17 (static libs - dll) + runs-on: windows-2022 + env: + CXX_STANDARD: '17' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Build dependencies with vcpkg submodule + run: | + ./ci/setup_cmake.ps1 + ./ci/setup_windows_ci_environment.ps1 + - name: Run Tests + run: ./ci/do_ci.ps1 cmake.install.test + - name: Run DLL Tests + run: ./ci/do_ci.ps1 cmake.dll.install.test + + windows_2019_vcpkg: + name: Windows 2019 vcpkg cxx14 (static libs) + runs-on: windows-2019 + env: + CXX_STANDARD: '14' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Build dependencies with vcpkg submodule + run: | + ./ci/setup_cmake.ps1 + ./ci/setup_windows_ci_environment.ps1 + - name: Run Tests + run: ./ci/do_ci.ps1 cmake.install.test + + ubuntu_2404_system_packages: + name: Ubuntu 24.04 apt packages cxx17 (static libs - shared libs) + runs-on: ubuntu-24.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '17' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install libcurl, zlib, nlohmann-json with apt + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_googletest.sh + - name: Install abseil, protobuf, and grpc with apt + run: | + sudo -E apt-get update + sudo -E apt-get install -y libabsl-dev libprotobuf-dev libgrpc++-dev protobuf-compiler protobuf-compiler-grpc + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + - name: Run Tests (shared libs) + env: + BUILD_SHARED_LIBS: 'ON' + run: ./ci/do_ci.sh cmake.install.test + + ubuntu_2404_script_build_grpc_1_71_0: + name: Ubuntu 24.04 script grpc 1.71.0 cxx17 (static libs) + runs-on: ubuntu-24.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '20' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install gtest, libcurl, zlib, nlohmann-json with apt + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_googletest.sh + - name: Build abseil, protobuf, and grpc with ci scripts + env: + ABSEIL_CPP_VERSION: '20240722.1' + PROTOBUF_VERSION: '29.0' + GRPC_VERSION: 'v1.71.0' + run: | + sudo -E ./ci/install_abseil.sh + sudo -E ./ci/install_protobuf.sh + sudo -E ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil-cpp + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + + ubuntu_2204_script_build_grpc_1_55_0: + name: Ubuntu 22.04 script grpc 1.55.0 cxx17 (static libs - shared libs) + runs-on: ubuntu-22.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '17' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install gtest, libcurl, zlib, nlohmann-json with apt + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_googletest.sh + - name: Build abseil, protobuf, and grpc with ci scripts + env: + ABSEIL_CPP_VERSION: '20230125.3' + PROTOBUF_VERSION: '23.3' + GRPC_VERSION: 'v1.55.0' + run: | + sudo -E ./ci/install_abseil.sh + sudo -E ./ci/install_protobuf.sh + sudo -E ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil-cpp + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + - name: Run Tests (shared libs) + env: + BUILD_SHARED_LIBS: 'ON' + run: ./ci/do_ci.sh cmake.install.test + + ubuntu_2204_script_build_grpc_1_49_2: + name: Ubuntu 22.04 script grpc 1.49.2 cxx14 (static libs - shared libs) + runs-on: ubuntu-22.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '14' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install gtest, libcurl, zlib, nlohmann-json with apt + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_googletest.sh + - name: Build abseil, protobuf, and grpc with ci scripts + env: + ABSEIL_CPP_VERSION: '20220623.2' + PROTOBUF_VERSION: '21.12' + GRPC_VERSION: 'v1.49.2' + run: | + sudo -E ./ci/install_abseil.sh + sudo -E ./ci/install_protobuf.sh + sudo -E ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil-cpp + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + - name: Run Tests (shared libs) + env: + BUILD_SHARED_LIBS: 'ON' + run: ./ci/do_ci.sh cmake.install.test + + ubuntu_2404_conan_stable: + name: Ubuntu 24.04 conan stable cxx17 (static libs - shared libs - opentracing shim) + runs-on: ubuntu-24.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '17' + CMAKE_TOOLCHAIN_FILE: /home/runner/conan/build/Debug/generators/conan_toolchain.cmake + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install Conan + run: | + python3 -m pip install --upgrade pip + pip install "conan>=2.0,<3" + conan profile detect --force + - name: Install or build all dependencies with Conan + run: | + sudo -E ./ci/setup_cmake.sh + conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=Debug + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + - name: Run Tests (shared libs) + env: + BUILD_SHARED_LIBS: 'ON' + run: ./ci/do_ci.sh cmake.install.test + - name: verify pkgconfig packages + 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 + + ubuntu_2404_conan_latest: + name: Ubuntu 24.04 conan latest cxx17 (static libs) + runs-on: ubuntu-24.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '17' + CMAKE_TOOLCHAIN_FILE: /home/runner/conan/build/Debug/generators/conan_toolchain.cmake + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install Conan + run: | + python3 -m pip install --upgrade pip + pip install "conan>=2.0,<3" + conan profile detect --force + - name: Install or build all dependencies with Conan + run: | + sudo -E ./ci/setup_cmake.sh + conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=Debug + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + - name: verify pkgconfig packages + run: | + export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH + ./ci/verify_packages.sh + + macos_14_conan_stable: + name: macOS 14 conan stable cxx17 (static libs) + runs-on: macos-14 + env: + INSTALL_TEST_DIR: '/Users/runner/install_test' + CXX_STANDARD: '17' + CMAKE_TOOLCHAIN_FILE: '/Users/runner/conan/build/Debug/generators/conan_toolchain.cmake' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install Conan and tools + run: | + brew install conan autoconf automake libtool coreutils + sudo -E ./ci/setup_cmake_macos.sh + conan profile detect --force + - name: Install or build all dependencies with Conan + run: conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=Debug + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test + + macos_14_brew_packages: + name: macOS 14 brew packages cxx17 (static libs) + runs-on: macos-14 + env: + CXX_STANDARD: '17' + BUILD_TYPE: 'Debug' + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Install Dependencies with Homebrew + run: | + sudo -E ./ci/setup_cmake_macos.sh + brew install coreutils + brew install googletest + brew install google-benchmark + brew install zlib + brew install abseil + brew install protobuf + brew install grpc + brew install nlohmann-json + brew install prometheus-cpp + - name: Run Tests (static libs) + env: + BUILD_SHARED_LIBS: 'OFF' + run: ./ci/do_ci.sh cmake.install.test \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bee414678..4414f38002 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,8 @@ project(opentelemetry-cpp) # Mark variables as used so cmake doesn't complain about them mark_as_advanced(CMAKE_TOOLCHAIN_FILE) -# Prefer cmake CONFIG to auto resolve dependencies. +# Prefer cmake CONFIG to auto resolve dependencies. This is important to +# properly find protobuf versions 3.22.0 and above set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) # Don't use customized cmake modules if vcpkg is used to resolve dependence. @@ -386,6 +387,23 @@ if(WITH_PROMETHEUS) set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY}) set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}) + + # Get the version of the prometheus-cpp submodule + find_package(Git QUIET) + if(Git_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/prometheus-cpp + OUTPUT_VARIABLE prometheus-cpp_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "^v" "" prometheus-cpp_VERSION + "${prometheus-cpp_VERSION}") + endif() + + message( + STATUS + "Using local prometheus-cpp from submodule. Version = ${prometheus-cpp_VERSION}" + ) else() message( FATAL_ERROR @@ -398,19 +416,16 @@ if(WITH_PROMETHEUS) endif() endif() -if(WITH_OTLP_GRPC) - find_package(absl CONFIG REQUIRED) -endif() - if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP OR WITH_OTLP_FILE) + find_package(Protobuf) # Protobuf 3.22 or upper require abseil-cpp, we can find it in # opentelemetry-cpp-config.cmake if(WITH_OTLP_GRPC) - find_package(gRPC) + find_package(gRPC CONFIG) endif() if((NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) OR (WITH_OTLP_GRPC AND NOT gRPC_FOUND)) @@ -429,7 +444,7 @@ if(WITH_OTLP_GRPC find_package(Protobuf REQUIRED) endif() if(NOT gRPC_FOUND AND WITH_OTLP_GRPC) - find_package(gRPC) + find_package(gRPC CONFIG) endif() if(WIN32) # Always use x64 protoc.exe @@ -487,7 +502,6 @@ endif() if((NOT WITH_API_ONLY) AND WITH_HTTP_CLIENT_CURL) # No specific version required. find_package(CURL REQUIRED) - message(STATUS "Found CURL: ${CURL_LIBRARIES}, version ${CURL_VERSION}") endif() # @@ -499,7 +513,6 @@ if((NOT WITH_API_ONLY) AND WITH_OTLP_HTTP_COMPRESSION) # No specific version required. find_package(ZLIB REQUIRED) - message(STATUS "Found ZLIB: ${ZLIB_LIBRARIES}, version ${ZLIB_VERSION}") endif() # @@ -698,6 +711,108 @@ if(BUILD_TESTING) endif() endif() +# Record build config and versions +message(STATUS "---------------------------------------------") +message(STATUS "build settings") +message(STATUS "---------------------------------------------") +message(STATUS "OpenTelemetry: ${OPENTELEMETRY_VERSION}") +message(STATUS "OpenTelemetry ABI: ${OPENTELEMETRY_ABI_VERSION_NO}") +message(STATUS "ARCH: ${ARCH}") +message(STATUS "CXX: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "CXXFLAGS: ${CMAKE_CXX_FLAGS}") +message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}") +message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") +message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") + +message(STATUS "---------------------------------------------") +message(STATUS "opentelemetry-cpp build options") +message(STATUS "---------------------------------------------") +message(STATUS "WITH_API_ONLY: ${WITH_API_ONLY}") +message(STATUS "WITH_NO_DEPRECATED_CODE: ${WITH_NO_DEPRECATED_CODE}") +message(STATUS "WITH_ABI_VERSION_1: ${WITH_ABI_VERSION_1}") +message(STATUS "WITH_ABI_VERSION_2: ${WITH_ABI_VERSION_2}") +message(STATUS "OTELCPP_VERSIONED_LIBS: ${OTELCPP_VERSIONED_LIBS}") +message(STATUS "OTELCPP_MAINTAINER_MODE: ${OTELCPP_MAINTAINER_MODE}") +message(STATUS "WITH_STL: ${WITH_STL}") +message(STATUS "WITH_GSL: ${WITH_GSL}") +message(STATUS "WITH_NO_GETENV: ${WITH_NO_GETENV}") + +message(STATUS "---------------------------------------------") +message(STATUS "opentelemetry-cpp cmake component options") +message(STATUS "---------------------------------------------") +message(STATUS "WITH_OTLP_GRPC: ${WITH_OTLP_GRPC}") +message(STATUS "WITH_OTLP_HTTP: ${WITH_OTLP_HTTP}") +message(STATUS "WITH_OTLP_FILE: ${WITH_OTLP_FILE}") +message(STATUS "WITH_HTTP_CLIENT_CURL: ${WITH_HTTP_CLIENT_CURL}") +message(STATUS "WITH_ZIPKIN: ${WITH_ZIPKIN}") +message(STATUS "WITH_PROMETHEUS: ${WITH_PROMETHEUS}") +message(STATUS "WITH_ELASTICSEARCH: ${WITH_ELASTICSEARCH}") +message(STATUS "WITH_OPENTRACING: ${WITH_OPENTRACING}") +message(STATUS "WITH_ETW: ${WITH_ETW}") +message(STATUS "OPENTELEMETRY_BUILD_DLL: ${OPENTELEMETRY_BUILD_DLL}") + +message(STATUS "---------------------------------------------") +message(STATUS "feature preview options") +message(STATUS "---------------------------------------------") +message(STATUS "WITH_ASYNC_EXPORT_PREVIEW: ${WITH_ASYNC_EXPORT_PREVIEW}") +message( + STATUS + "WITH_THREAD_INSTRUMENTATION_PREVIEW: ${WITH_THREAD_INSTRUMENTATION_PREVIEW}" +) +message( + STATUS "WITH_METRICS_EXEMPLAR_PREVIEW: ${WITH_METRICS_EXEMPLAR_PREVIEW}") +message(STATUS "WITH_REMOVE_METER_PREVIEW: ${WITH_REMOVE_METER_PREVIEW}") +message( + STATUS "WITH_OTLP_GRPC_SSL_MTLS_PREVIEW: ${WITH_OTLP_GRPC_SSL_MTLS_PREVIEW}") +message(STATUS "WITH_OTLP_RETRY_PREVIEW: ${WITH_OTLP_RETRY_PREVIEW}") +message(STATUS "---------------------------------------------") +message(STATUS "third-party options") +message(STATUS "---------------------------------------------") +message(STATUS "WITH_NLOHMANN_JSON: ${USE_NLOHMANN_JSON}") +message(STATUS "WITH_CURL_LOGGING: ${WITH_CURL_LOGGING}") +message(STATUS "WITH_OTLP_HTTP_COMPRESSION: ${WITH_OTLP_HTTP_COMPRESSION}") +message(STATUS "---------------------------------------------") +message(STATUS "examples and test options") +message(STATUS "---------------------------------------------") +message(STATUS "WITH_BENCHMARK: ${WITH_BENCHMARK}") +message(STATUS "WITH_EXAMPLES: ${WITH_EXAMPLES}") +message(STATUS "WITH_EXAMPLES_HTTP: ${WITH_EXAMPLES_HTTP}") +message(STATUS "WITH_FUNC_TESTS: ${WITH_FUNC_TESTS}") +message(STATUS "BUILD_W3CTRACECONTEXT_TEST: ${BUILD_W3CTRACECONTEXT_TEST}") +message(STATUS "BUILD_TESTING: ${BUILD_TESTING}") +message(STATUS "---------------------------------------------") +message(STATUS "versions") +message(STATUS "---------------------------------------------") +message(STATUS "CMake: ${CMAKE_VERSION}") +message(STATUS "GTest: ${GTest_VERSION}") +message(STATUS "benchmark: ${benchmark_VERSION}") +if(WITH_GSL) + message(STATUS "GSL: ${GSL_VERSION}") +endif() +if(absl_FOUND) + message(STATUS "Abseil: ${absl_VERSION}") +endif() +if(Protobuf_FOUND) + message(STATUS "Protobuf: ${Protobuf_VERSION}") +endif() +if(gRPC_FOUND) + message(STATUS "gRPC: ${gRPC_VERSION}") +endif() +if(CURL_FOUND) + message(STATUS "CURL: ${CURL_VERSION}") +endif() +if(ZLIB_FOUND) + message(STATUS "ZLIB: ${ZLIB_VERSION}") +endif() +if(USE_NLOHMANN_JSON) + message(STATUS "nlohmann-json: ${nlohmann_json_VERSION}") +endif() +if(prometheus-cpp_FOUND) + message(STATUS "prometheus-cpp: ${prometheus-cpp_VERSION}") +endif() +message(STATUS "---------------------------------------------") + include(CMakePackageConfigHelpers) if(DEFINED OPENTELEMETRY_BUILD_DLL) @@ -775,12 +890,11 @@ if(OPENTELEMETRY_INSTALL) # Write config file for find_packages(opentelemetry-cpp CONFIG) set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") configure_package_config_file( - "${CMAKE_CURRENT_LIST_DIR}/cmake/opentelemetry-cpp-config.cmake.in" + "${CMAKE_CURRENT_LIST_DIR}/cmake/templates/opentelemetry-cpp-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME - INCLUDE_INSTALL_DIR CMAKE_INSTALL_LIBDIR - NO_CHECK_REQUIRED_COMPONENTS_MACRO) + INCLUDE_INSTALL_DIR CMAKE_INSTALL_LIBDIR) # Write version file for find_packages(opentelemetry-cpp CONFIG) write_basic_package_version_file( @@ -788,22 +902,23 @@ if(OPENTELEMETRY_INSTALL) VERSION ${OPENTELEMETRY_VERSION} COMPATIBILITY ExactVersion) + # Write the "BUILT_WITH_ **Note:** `opentelemetry-cpp` CMake package components were introduced in `v1.21.0` + +The `opentelemetry-cpp` package supports using the `COMPONENTS` argument to +`find_package`. The following example illustrates using this feature to include +and link the `api` header only target to an instrumented `foo_lib` while only including +and linking the `sdk` and `otlp_grpc_exporter` targets to the `foo_app`. + +```cmake +# foo_lib/CMakeLists.txt +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api) +add_library(foo_lib foo.cpp) +target_link_libraries(foo_lib PRIVATE opentelemetry-cpp::api) +``` + +```cmake +# foo_app/CMakeLists.txt +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api sdk exporters_otlp_grpc) +add_executable(foo_app main.cpp) +target_link_libraries(foo_app PRIVATE foo_lib opentelemetry-cpp::api opentelemetry-cpp::sdk opentelemetry-cpp::otlp_grpc_exporter ) +``` + +The following table provides the mapping between components and targets. Components +and targets available in the installation depends on the opentelemetry-cpp package +build configuration. + +| Component | Targets | +|----------------------------|--------------------------------------------------------------------------------------------------| +| **api** | opentelemetry-cpp::api | +| **sdk** | opentelemetry-cpp::sdk | +| | opentelemetry-cpp::version | +| | opentelemetry-cpp::common | +| | opentelemetry-cpp::resources | +| | opentelemetry-cpp::trace | +| | opentelemetry-cpp::metrics | +| | opentelemetry-cpp::logs | +| **ext_common** | opentelemetry-cpp::ext | +| **ext_http_curl** | opentelemetry-cpp::http_client_curl | +| **ext_dll** | opentelemetry-cpp::opentelemetry_cpp | +| **exporters_in_memory** | opentelemetry-cpp::in_memory_span_exporter | +| | opentelemetry-cpp::in_memory_metric_exporter | +| **exporters_ostream** | opentelemetry-cpp::ostream_log_record_exporter | +| | opentelemetry-cpp::ostream_metrics_exporter | +| | opentelemetry-cpp::ostream_span_exporter | +| **exporters_otlp_common** | opentelemetry-cpp::proto | +| | opentelemetry-cpp::otlp_recordable | +| **exporters_otlp_file** | opentelemetry-cpp::otlp_file_client | +| | opentelemetry-cpp::otlp_file_exporter | +| | opentelemetry-cpp::otlp_file_log_record_exporter | +| | opentelemetry-cpp::otlp_file_metric_exporter | +| **exporters_otlp_grpc** | opentelemetry-cpp::proto_grpc | +| | opentelemetry-cpp::otlp_grpc_client | +| | opentelemetry-cpp::otlp_grpc_exporter | +| | opentelemetry-cpp::otlp_grpc_log_record_exporter | +| | opentelemetry-cpp::otlp_grpc_metrics_exporter | +| **exporters_otlp_http** | opentelemetry-cpp::otlp_http_client | +| | opentelemetry-cpp::otlp_http_exporter | +| | opentelemetry-cpp::otlp_http_log_record_exporter | +| | opentelemetry-cpp::otlp_http_metric_exporter | +| **exporters_prometheus** | opentelemetry-cpp::prometheus_exporter | +| **exporters_elasticsearch**| opentelemetry-cpp::elasticsearch_log_record_exporter | +| **exporters_etw** | opentelemetry-cpp::etw_exporter | +| **exporters_zipkin** | opentelemetry-cpp::zipkin_trace_exporter | +| **shims_opentracing** | opentelemetry-cpp::opentracing_shim | + ## Build instructions using Bazel NOTE: Experimental, and not supported for all the components. Make sure the diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 4d7e4542b0..518b1e04d5 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -12,17 +12,25 @@ set_target_properties(opentelemetry_api PROPERTIES EXPORT_NAME api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_api - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-api-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT api) install( DIRECTORY include/opentelemetry DESTINATION include + COMPONENT api FILES_MATCHING PATTERN "*.h") + install( + EXPORT "${PROJECT_NAME}-api-target" + FILE "${PROJECT_NAME}-api-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT api) + unset(TARGET_DEPS) endif() diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 66f983065f..e34d72d5e4 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -20,6 +20,11 @@ if (!(test-path build)) { } $BUILD_DIR = Join-Path "$SRC_DIR" "build" +if (!(test-path install_test)) { + mkdir install_test +} +$INSTALL_TEST_DIR = Join-Path "$SRC_DIR" "install_test" + if (!(test-path plugin)) { mkdir plugin } @@ -340,6 +345,210 @@ switch ($action) { exit $exit } } + "cmake.install.test" { + Remove-Item -Recurse -Force "$BUILD_DIR\*" + Remove-Item -Recurse -Force "$INSTALL_TEST_DIR\*" + cd "$BUILD_DIR" + + if (Test-Path Env:\CXX_STANDARD) { + $CXX_STANDARD = [int](Get-Item Env:\CXX_STANDARD).Value + } else { + $CXX_STANDARD = 14 + } + if (-not $CXX_STANDARD) { + $CXX_STANDARD = 14 + } + Write-Host "Using CXX_STANDARD: $CXX_STANDARD" + + $CMAKE_OPTIONS = @( + "-DCMAKE_CXX_STANDARD=$CXX_STANDARD", + "-DCMAKE_CXX_STANDARD_REQUIRED=ON", + "-DCMAKE_CXX_EXTENSIONS=OFF", + "-DVCPKG_TARGET_TRIPLET=x64-windows", + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + ) + + cmake $SRC_DIR ` + $CMAKE_OPTIONS ` + "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` + -DWITH_ABI_VERSION_1=OFF ` + -DWITH_ABI_VERSION_2=ON ` + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` + -DWITH_ASYNC_EXPORT_PREVIEW=ON ` + -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON ` + -DWITH_OTLP_RETRY_PREVIEW=ON ` + -DWITH_OTLP_GRPC=ON ` + -DWITH_OTLP_HTTP=ON ` + -DWITH_OTLP_FILE=ON ` + -DWITH_OTLP_HTTP_COMPRESSION=ON ` + -DWITH_HTTP_CLIENT_CURL=ON ` + -DWITH_PROMETHEUS=ON ` + -DWITH_ZIPKIN=ON ` + -DWITH_ELASTICSEARCH=ON ` + -DWITH_ETW=ON ` + -DWITH_EXAMPLES=ON ` + -DOPENTELEMETRY_INSTALL=ON + + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . -j $nproc + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . --target install + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + $env:PATH = "$INSTALL_TEST_DIR\bin;$env:PATH" + + $CMAKE_OPTIONS_STRING = $CMAKE_OPTIONS -join " " + + $EXPECTED_COMPONENTS = @( + "api", + "sdk", + "ext_common", + "ext_http_curl", + "exporters_in_memory", + "exporters_ostream", + "exporters_otlp_common", + "exporters_otlp_file", + "exporters_otlp_grpc", + "exporters_otlp_http", + "exporters_prometheus", + "exporters_elasticsearch", + "exporters_zipkin", + "exporters_etw" + ) + $EXPECTED_COMPONENTS_STRING = $EXPECTED_COMPONENTS -join ";" + + cmake -S "$SRC_DIR\install\test\cmake" ` + -B "$BUILD_DIR\install_test" ` + $CMAKE_OPTIONS ` + "-DCMAKE_PREFIX_PATH=$INSTALL_TEST_DIR" ` + "-DINSTALL_TEST_CMAKE_OPTIONS=$CMAKE_OPTIONS_STRING" ` + "-DINSTALL_TEST_COMPONENTS=$EXPECTED_COMPONENTS_STRING" + + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + ctest -C Debug --test-dir "$BUILD_DIR\install_test" --output-on-failure + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + exit 0 + } + "cmake.dll.install.test" { + cd "$BUILD_DIR" + Remove-Item -Recurse -Force "$BUILD_DIR\*" + Remove-Item -Recurse -Force "$INSTALL_TEST_DIR\*" + + $CMAKE_OPTIONS = @( + "-DCMAKE_CXX_STANDARD=17", + "-DVCPKG_TARGET_TRIPLET=x64-windows", + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + ) + + cmake $SRC_DIR ` + $CMAKE_OPTIONS ` + "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` + -DOPENTELEMETRY_BUILD_DLL=1 ` + -DWITH_ABI_VERSION_1=ON ` + -DWITH_ABI_VERSION_2=OFF ` + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` + -DWITH_ASYNC_EXPORT_PREVIEW=ON ` + -DWITH_ETW=ON ` + -DOPENTELEMETRY_INSTALL=ON ` + -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=OFF ` + -DWITH_OTLP_RETRY_PREVIEW=OFF ` + -DWITH_OTLP_GRPC=OFF ` + -DWITH_OTLP_HTTP=OFF ` + -DWITH_OTLP_FILE=OFF ` + -DWITH_OTLP_HTTP_COMPRESSION=OFF ` + -DWITH_HTTP_CLIENT_CURL=OFF ` + -DWITH_PROMETHEUS=OFF ` + -DWITH_ZIPKIN=OFF ` + -DWITH_ELASTICSEARCH=OFF ` + -DWITH_EXAMPLES=OFF ` + + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . -j $nproc + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . --target install + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + $env:PATH = "$INSTALL_TEST_DIR\bin;$env:PATH" + + echo "$env:PATH" + + $CMAKE_OPTIONS_STRING = $CMAKE_OPTIONS -join " " + + $EXPECTED_COMPONENTS = @( + "api", + "sdk", + "ext_common", + "exporters_in_memory", + "exporters_ostream", + "exporters_etw", + "ext_dll" + ) + $EXPECTED_COMPONENTS_STRING = $EXPECTED_COMPONENTS -join ";" + + cmake -S "$SRC_DIR\install\test\cmake" ` + -B "$BUILD_DIR\install_test" ` + $CMAKE_OPTIONS ` + "-DCMAKE_PREFIX_PATH=$INSTALL_TEST_DIR" ` + "-DINSTALL_TEST_CMAKE_OPTIONS=$CMAKE_OPTIONS_STRING" ` + "-DINSTALL_TEST_COMPONENTS=$EXPECTED_COMPONENTS_STRING" + + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + ctest -C Debug --test-dir "$BUILD_DIR\install_test" --output-on-failure + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + exit 0 + } default { echo "unknown action: $action" exit 1 diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 0275f820a0..f81e96469d 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -62,6 +62,8 @@ function run_benchmarks mkdir -p "${BUILD_DIR}" [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin mkdir -p "${PLUGIN_DIR}" +[ -z "${INSTALL_TEST_DIR}" ] && export INSTALL_TEST_DIR=$HOME/install_test +mkdir -p "${INSTALL_TEST_DIR}" MAKE_COMMAND="make -k -j \$(nproc)" @@ -81,13 +83,28 @@ BAZEL_MACOS_TEST_OPTIONS="$BAZEL_MACOS_OPTIONS --test_output=errors" BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel" -CMAKE_OPTIONS=(-DCMAKE_BUILD_TYPE=Debug) -if [ ! -z "${CXX_STANDARD}" ]; then - CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +if [[ "${BUILD_TYPE}" =~ ^(Debug|Release|RelWithDebInfo|MinSizeRel)$ ]]; then + CMAKE_OPTIONS=(-DCMAKE_BUILD_TYPE=${BUILD_TYPE}) else - CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=14") + CMAKE_OPTIONS=(-DCMAKE_BUILD_TYPE=Debug) fi +if [ -n "${CXX_STANDARD}" ]; then + CMAKE_OPTIONS+=("-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +else + CMAKE_OPTIONS+=("-DCMAKE_CXX_STANDARD=14") +fi + +CMAKE_OPTIONS+=("-DCMAKE_CXX_STANDARD_REQUIRED=ON") +CMAKE_OPTIONS+=("-DCMAKE_CXX_EXTENSIONS=OFF") + +if [ -n "$CMAKE_TOOLCHAIN_FILE" ]; then + echo "CMAKE_TOOLCHAIN_FILE is set to: $CMAKE_TOOLCHAIN_FILE" + CMAKE_OPTIONS+=("-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE") +fi + +echo "CMAKE_OPTIONS:" "${CMAKE_OPTIONS[@]}" + export CTEST_OUTPUT_ON_FAILURE=1 if [[ "$1" == "cmake.test" ]]; then @@ -215,27 +232,46 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then make -j $(nproc) make test exit 0 -elif [[ "$1" == "cmake.abseil.test" ]]; then +elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake "${CMAKE_OPTIONS[@]}" \ - -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ - -DWITH_ASYNC_EXPORT_PREVIEW=ON \ - -DWITH_ABSEIL=ON \ + cmake "${CMAKE_OPTIONS[@]}" \ + -DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \ + -DWITH_OPENTRACING=ON \ "${SRC_DIR}" make -j $(nproc) make test exit 0 -elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then +elif [[ "$1" == "cmake.opentracing_shim.install.test" ]]; then cd "${BUILD_DIR}" rm -rf * + rm -rf ${INSTALL_TEST_DIR}/* cmake "${CMAKE_OPTIONS[@]}" \ -DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \ -DWITH_OPENTRACING=ON \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ "${SRC_DIR}" make -j $(nproc) make test + make install + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + CMAKE_OPTIONS_STRING=$(IFS=" "; echo "${CMAKE_OPTIONS[*]}") + EXPECTED_COMPONENTS=( + "api" + "sdk" + "ext_common" + "exporters_in_memory" + "exporters_ostream" + "shims_opentracing" + ) + EXPECTED_COMPONENTS_STRING=$(IFS=\;; echo "${EXPECTED_COMPONENTS[*]}") + cmake -S "${SRC_DIR}/install/test/cmake" \ + -B "${BUILD_DIR}/install_test" \ + "${CMAKE_OPTIONS[@]}" \ + "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ + "-DINSTALL_TEST_CMAKE_OPTIONS=${CMAKE_OPTIONS_STRING}" \ + "-DINSTALL_TEST_COMPONENTS=${EXPECTED_COMPONENTS_STRING}" + ctest --test-dir "${BUILD_DIR}/install_test" --output-on-failure exit 0 elif [[ "$1" == "cmake.c++20.test" ]]; then cd "${BUILD_DIR}" @@ -339,9 +375,6 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * - if [[ ! -z "${WITH_ABSEIL}" ]]; then - CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DWITH_ABSEIL=${WITH_ABSEIL}") - fi cmake "${CMAKE_OPTIONS[@]}" \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ @@ -412,16 +445,71 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then cd exporters/otlp && make test exit 0 elif [[ "$1" == "cmake.install.test" ]]; then + if [[ -n "${BUILD_SHARED_LIBS}" && "${BUILD_SHARED_LIBS}" == "ON" ]]; then + CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=ON") + echo "BUILD_SHARED_LIBS is set to: ON" + else + CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=OFF") + echo "BUILD_SHARED_LIBS is set to: OFF" + fi + CMAKE_OPTIONS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON") + cd "${BUILD_DIR}" rm -rf * + rm -rf ${INSTALL_TEST_DIR}/* + cmake "${CMAKE_OPTIONS[@]}" \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ + -DWITH_ABI_VERSION_1=OFF \ + -DWITH_ABI_VERSION_2=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ - -DWITH_ABSEIL=ON \ + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ + -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \ + -DWITH_OTLP_RETRY_PREVIEW=ON \ + -DWITH_OTLP_GRPC=ON \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_FILE=ON \ + -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_HTTP_CLIENT_CURL=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_ZIPKIN=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_EXAMPLES=ON \ + -DOPENTELEMETRY_INSTALL=ON \ "${SRC_DIR}" + make -j $(nproc) - sudo make install + make test + make install + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + + CMAKE_OPTIONS_STRING=$(IFS=" "; echo "${CMAKE_OPTIONS[*]}") + + EXPECTED_COMPONENTS=( + "api" + "sdk" + "ext_common" + "ext_http_curl" + "exporters_in_memory" + "exporters_ostream" + "exporters_otlp_common" + "exporters_otlp_file" + "exporters_otlp_grpc" + "exporters_otlp_http" + "exporters_prometheus" + "exporters_elasticsearch" + "exporters_zipkin" + ) + EXPECTED_COMPONENTS_STRING=$(IFS=\;; echo "${EXPECTED_COMPONENTS[*]}") + + cmake -S "${SRC_DIR}/install/test/cmake" \ + -B "${BUILD_DIR}/install_test" \ + "${CMAKE_OPTIONS[@]}" \ + "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ + "-DINSTALL_TEST_CMAKE_OPTIONS=${CMAKE_OPTIONS_STRING}" \ + "-DINSTALL_TEST_COMPONENTS=${EXPECTED_COMPONENTS_STRING}" + ctest --test-dir "${BUILD_DIR}/install_test" --output-on-failure exit 0 elif [[ "$1" == "cmake.test_example_plugin" ]]; then # Build the plugin diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh index 01270b84f1..e6e297e338 100755 --- a/ci/setup_cmake.sh +++ b/ci/setup_cmake.sh @@ -5,7 +5,6 @@ set -e -# Use CMAKE_VERSION env var if set, else default to 3.31.6 CMAKE_VERSION=${CMAKE_VERSION:-3.31.6} CMAKE_DIR="cmake-$CMAKE_VERSION-linux-x86_64" CMAKE_TAR="$CMAKE_DIR.tar.gz" @@ -25,7 +24,7 @@ mkdir -p /opt/cmake mv "$CMAKE_DIR" /opt/cmake/cmake for file in /opt/cmake/cmake/bin/*; do - ln -sf "$file" /usr/local/bin/$(basename "$file") + ln -sf "$file" "/usr/local/bin/$(basename "$file")" done rm -f "$CMAKE_TAR" diff --git a/ci/setup_cmake_macos.sh b/ci/setup_cmake_macos.sh new file mode 100755 index 0000000000..5208c9cd24 --- /dev/null +++ b/ci/setup_cmake_macos.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -e + +CMAKE_VERSION="${CMAKE_VERSION:-3.31.6}" +CMAKE_PKG="cmake-${CMAKE_VERSION}-macos-universal" +CMAKE_TAR="${CMAKE_PKG}.tar.gz" +CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TAR}" + +INSTALL_DIR="/opt/cmake" +BIN_DIR="${INSTALL_DIR}/cmake/CMake.app/Contents/bin" + +echo "Installing CMake version ${CMAKE_VERSION}..." + +if brew list cmake >/dev/null 2>&1; then + echo "Removing existing Homebrew-installed CMake..." + brew uninstall cmake +fi + +if ! command -v wget >/dev/null 2>&1; then + echo "wget not found. Installing wget via Homebrew..." + brew install wget +fi + +wget -q "${CMAKE_URL}" +tar -xzf "${CMAKE_TAR}" + +sudo mkdir -p "${INSTALL_DIR}" +sudo mv "${CMAKE_PKG}" "${INSTALL_DIR}/cmake" + +for file in "${BIN_DIR}"/*; do + sudo ln -sf "${file}" "/usr/local/bin/$(basename "${file}")" +done + +rm -f "${CMAKE_TAR}" + +cmake --version diff --git a/ci/setup_windows_ci_environment.ps1 b/ci/setup_windows_ci_environment.ps1 index ff2c2f9f60..f5c761edb9 100755 --- a/ci/setup_windows_ci_environment.ps1 +++ b/ci/setup_windows_ci_environment.ps1 @@ -25,4 +25,7 @@ $VCPKG_DIR = (Get-Item -Path ".\").FullName # curl ./vcpkg "--vcpkg-root=$VCPKG_DIR" install curl:x64-windows +# prometheus-cpp +./vcpkg "--vcpkg-root=$VCPKG_DIR" install prometheus-cpp:x64-windows + Pop-Location diff --git a/cmake/component-definitions.cmake b/cmake/component-definitions.cmake new file mode 100644 index 0000000000..74087beff4 --- /dev/null +++ b/cmake/component-definitions.cmake @@ -0,0 +1,221 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# ---------------------------------------------------------------------- +# opentelmetry-cpp COMPONENT list +# ---------------------------------------------------------------------- +set(opentelemetry-cpp_COMPONENTS + api + sdk + ext_common + ext_http_curl + exporters_in_memory + exporters_ostream + exporters_otlp_common + exporters_otlp_file + exporters_otlp_grpc + exporters_otlp_http + exporters_prometheus + exporters_elasticsearch + exporters_etw + exporters_zipkin + shims_opentracing + ext_dll +) + +# ---------------------------------------------------------------------- +# COMPONENT to TARGET lists +# ---------------------------------------------------------------------- + +# COMPONENT api +set(COMPONENT_opentelemetry-cpp_api_TARGETS + opentelemetry-cpp::api +) + +# COMPONENT sdk +set(COMPONENT_opentelemetry-cpp_sdk_TARGETS + opentelemetry-cpp::sdk + opentelemetry-cpp::version + opentelemetry-cpp::common + opentelemetry-cpp::resources + opentelemetry-cpp::trace + opentelemetry-cpp::metrics + opentelemetry-cpp::logs +) + +# COMPONENT ext_common +set(COMPONENT_opentelemetry-cpp_ext_common_TARGETS + opentelemetry-cpp::ext +) + +# COMPONENT ext_http_curl +set(COMPONENT_opentelemetry-cpp_ext_http_curl_TARGETS + opentelemetry-cpp::http_client_curl +) + +# COMPONENT ext_dll +set(COMPONENT_opentelemetry-cpp_ext_dll_TARGETS + opentelemetry-cpp::opentelemetry_cpp +) + +# COMPONENT exporters_in_memory +set(COMPONENT_opentelemetry-cpp_exporters_in_memory_TARGETS + opentelemetry-cpp::in_memory_span_exporter + opentelemetry-cpp::in_memory_metric_exporter +) + +# COMPONENT exporters_ostream +set(COMPONENT_opentelemetry-cpp_exporters_ostream_TARGETS + opentelemetry-cpp::ostream_log_record_exporter + opentelemetry-cpp::ostream_metrics_exporter + opentelemetry-cpp::ostream_span_exporter +) + +# COMPONENT exporters_otlp_common +set(COMPONENT_opentelemetry-cpp_exporters_otlp_common_TARGETS + opentelemetry-cpp::proto + opentelemetry-cpp::otlp_recordable +) + +# COMPONENT exporters_otlp_file +set(COMPONENT_opentelemetry-cpp_exporters_otlp_file_TARGETS + opentelemetry-cpp::otlp_file_client + opentelemetry-cpp::otlp_file_exporter + opentelemetry-cpp::otlp_file_log_record_exporter + opentelemetry-cpp::otlp_file_metric_exporter +) + +# COMPONENT exporters_otlp_grpc +set(COMPONENT_opentelemetry-cpp_exporters_otlp_grpc_TARGETS + opentelemetry-cpp::proto_grpc + opentelemetry-cpp::otlp_grpc_client + opentelemetry-cpp::otlp_grpc_exporter + opentelemetry-cpp::otlp_grpc_log_record_exporter + opentelemetry-cpp::otlp_grpc_metrics_exporter +) + +# COMPONENT exporters_otlp_http +set(COMPONENT_opentelemetry-cpp_exporters_otlp_http_TARGETS + opentelemetry-cpp::otlp_http_client + opentelemetry-cpp::otlp_http_exporter + opentelemetry-cpp::otlp_http_log_record_exporter + opentelemetry-cpp::otlp_http_metric_exporter +) + +# COMPONENT exporters_prometheus +set(COMPONENT_opentelemetry-cpp_exporters_prometheus_TARGETS + opentelemetry-cpp::prometheus_exporter +) + +# COMPONENT exporters_elasticsearch +set(COMPONENT_opentelemetry-cpp_exporters_elasticsearch_TARGETS + opentelemetry-cpp::elasticsearch_log_record_exporter +) + +# COMPONENT exporters_etw +set(COMPONENT_opentelemetry-cpp_exporters_etw_TARGETS + opentelemetry-cpp::etw_exporter +) + +# COMPONENT exporters_zipkin +set(COMPONENT_opentelemetry-cpp_exporters_zipkin_TARGETS + opentelemetry-cpp::zipkin_trace_exporter +) + +# COMPONENT shims_opentracing +set(COMPONENT_opentelemetry-cpp_shims_opentracing_TARGETS + opentelemetry-cpp::opentracing_shim +) + + +#----------------------------------------------------------------------- +# COMPONENT to COMPONENT dependencies +#----------------------------------------------------------------------- + +# COMPONENT sdk depends on COMPONENT api +set(COMPONENT_sdk_COMPONENT_DEPENDS + api +) + +set(COMPONENT_ext_common_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_ext_http_curl_COMPONENT_DEPENDS + api + sdk + ext_common +) + +set(COMPONENT_ext_dll_COMPONENT_DEPENDS + api + sdk + ext_common + exporters_in_memory + exporters_ostream +) + +set(COMPONENT_exporters_in_memory_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_exporters_ostream_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_exporters_otlp_common_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_exporters_otlp_file_COMPONENT_DEPENDS + api + sdk + exporters_otlp_common +) + +set(COMPONENT_exporters_otlp_grpc_COMPONENT_DEPENDS + api + sdk + ext_common + exporters_otlp_common +) + +set(COMPONENT_exporters_otlp_http_COMPONENT_DEPENDS + api + sdk + ext_common + ext_http_curl + exporters_otlp_common +) + +set(COMPONENT_exporters_prometheus_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_exporters_elasticsearch_COMPONENT_DEPENDS + api + sdk + ext_common + ext_http_curl +) + +set(COMPONENT_exporters_etw_COMPONENT_DEPENDS + api + sdk +) + +set(COMPONENT_exporters_zipkin_COMPONENT_DEPENDS + api + sdk + ext_common + ext_http_curl +) + +set(COMPONENT_shims_opentracing_COMPONENT_DEPENDS + api +) \ No newline at end of file diff --git a/cmake/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake new file mode 100644 index 0000000000..5cb9f99443 --- /dev/null +++ b/cmake/find-package-support-functions.cmake @@ -0,0 +1,214 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include("${CMAKE_CURRENT_LIST_DIR}/component-definitions.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/thirdparty-dependency-definitions.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/thirdparty-built-with-flags.cmake") + +#------------------------------------------------------------------------- +# Functions to get supported, installed, and requested components. +#------------------------------------------------------------------------- +function(get_supported_components components_out) + set(${components_out} ${opentelemetry-cpp_COMPONENTS} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Function to get installed components. +#------------------------------------------------------------------------- +function(get_installed_components installed_components_out) + set(result "") + foreach(_COMPONENT IN LISTS opentelemetry-cpp_COMPONENTS) + set(_COMPONENT_TARGET_FILE "${CMAKE_CURRENT_LIST_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake") + if(EXISTS "${_COMPONENT_TARGET_FILE}") + list(APPEND result ${_COMPONENT}) + message(DEBUG "get_installed_components: component = ${_COMPONENT}, installed = TRUE") + else() + message(DEBUG "get_installed_components: component = ${_COMPONENT}, installed = FALSE") + endif() + endforeach() + set(${installed_components_out} ${result} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Function to get dependent components. +#------------------------------------------------------------------------- +function(get_dependent_components component_in dependent_components_out) + set(result "") + set(depends_var "COMPONENT_${component_in}_COMPONENT_DEPENDS") + if(DEFINED ${depends_var}) + set(result ${${depends_var}}) + endif() + set(${dependent_components_out} ${result} PARENT_SCOPE) +endfunction() + + +#------------------------------------------------------------------------- +# Function to get requested components. +#------------------------------------------------------------------------- +function(get_requested_components installed_components_in requested_components_out) + set(result "") + if (NOT opentelemetry-cpp_FIND_COMPONENTS) + set(result ${${installed_components_in}}) + message(DEBUG "get_requested_components: No components explicitly requested. Importing all installed components including: ${result}") + set(${requested_components_out} ${result} PARENT_SCOPE) + else() + message(DEBUG "get_requested_components: Components requested: ${opentelemetry-cpp_FIND_COMPONENTS}") + foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) + if(NOT ${_COMPONENT} IN_LIST opentelemetry-cpp_COMPONENTS) + message(ERROR " get_requested_components: Component `${_COMPONENT}` is not a supported component of the opentelemetry-cpp package. Supported components include: ${opentelemetry-cpp_COMPONENTS}") + return() + endif() + if(NOT ${_COMPONENT} IN_LIST ${installed_components_in}) + message(FATAL_ERROR " get_requested_components: Component `${_COMPONENT}` is supported by opentelemetry-cpp but not installed. Installed components include: ${${installed_components_in}}") + endif() + get_dependent_components(${_COMPONENT} _DEPENDENT_COMPONENTS) + foreach(_DEPENDENT_COMPONENT IN LISTS _DEPENDENT_COMPONENTS) + if(NOT ${_DEPENDENT_COMPONENT} IN_LIST result) + list(APPEND result ${_DEPENDENT_COMPONENT}) + endif() + endforeach(_DEPENDENT_COMPONENT IN LISTS _DEPENDENT_COMPONENTS) + if(NOT ${_COMPONENT} IN_LIST result) + list(APPEND result ${_COMPONENT}) + endif() + endforeach() + set(${requested_components_out} ${result} PARENT_SCOPE) + endif() +endfunction() + + +#------------------------------------------------------------------------- +# Function to get the targets for a component. +#------------------------------------------------------------------------- +function(get_component_targets component_in targets_out) + set(result "") + if(NOT ${comp} IN_LIST opentelemetry-cpp_COMPONENTS) + message(ERROR " get_component_targets: Component `${comp}` component is not a supported component of the opentelemetry-cpp package.") + else() + set(targets_var "COMPONENT_opentelemetry-cpp_${comp}_TARGETS") + if(DEFINED ${targets_var}) + set(result ${${targets_var}}) + else() + message(FATAL_ERROR " get_component_targets: ${targets_var} is not defined. Please add it to component-definitions.cmake to define the exported targets for this component.") + endif() + endif() + set(${targets_out} ${result} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Get targets for a list of components. +#------------------------------------------------------------------------- +function(get_targets components_in targets_out) + set(result "") + foreach(comp IN LISTS ${components_in}) + get_component_targets(${comp} comp_targets) + foreach(target IN LISTS comp_targets) + list(APPEND result ${target}) + endforeach() + endforeach() + set(${targets_out} ${result} PARENT_SCOPE) + message(DEBUG "get_targets: found the following installed and requested targets. ${result}") +endfunction() + + +#------------------------------------------------------------------------- +# Check if a target is imported for a list of targets. +#------------------------------------------------------------------------- +function(check_targets_imported targets_in) + set(result TRUE) + foreach(target IN LISTS ${targets_in}) + if(TARGET ${target}) + message(DEBUG "check_targets_imported: imported target `${target}`") + else() + message(FATAL_ERROR " check_targets_imported: failed to import target `${target}`") + set(result FALSE) + endif() + endforeach() + set(${result_bool_out} ${result} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Function to get all supported third party dependencies +#------------------------------------------------------------------------- +function(get_supported_third_party_dependencies dependencies_out) + set(${dependencies_out} ${THIRD_PARTY_DEPNDENCIES_SUPPORTED} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Function to check if a third-party dependency is required for a component. +#------------------------------------------------------------------------- +function(is_dependency_required_by_component component_in dependency_in is_required_out) + set(result FALSE) + set(depends_var "THIRD_PARTY_${dependency_in}_DEPENDENT_COMPONENTS") + if(NOT DEFINED ${depends_var}) + message(FATAL_ERROR " is_dependency_required_by_component: ${depends_var} is not defined. + Please add ${depends_var} + in the 'thirdparty-dependency-definitions.cmake' file") + return() + endif() + + if(${component_in} IN_LIST ${depends_var}) + set(result TRUE) + message(DEBUG "is_dependency_required_by_component: ${dependency_in} is required by component ${component_in}.") + endif() + set(${is_required_out} ${result} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Check if a dependency is expected and required +#------------------------------------------------------------------------- +function (is_dependency_required dependency_in components_in is_required_out) + if(NOT DEFINED BUILT_WITH_${dependency_in}) + message(FATAL_ERROR " is_dependency_required: The BUILT_WITH_${dependency_in} flag is required but not defined in the 'thirdparty-built-with-flags.cmake' file") + elseif(NOT BUILT_WITH_${dependency_in}) + set(${is_required_out} FALSE PARENT_SCOPE) + else() + foreach(component IN LISTS ${components_in}) + set(is_required_by_component FALSE) + is_dependency_required_by_component(${component} ${dependency} is_required_by_component) + if(is_required_by_component) + set(${is_required_out} TRUE PARENT_SCOPE) + return() + endif() + endforeach() + endif() +endfunction() + +#------------------------------------------------------------------------- +# Check if a dependency should be found using CONFIG search mode +#------------------------------------------------------------------------- +function (is_config_mode_required dependency_in use_config_out) + if(NOT FIND_DEPENDENCY_${dependency}_USE_CONFIG OR NOT FIND_DEPENDENCY_${dependency}_USE_CONFIG) + set(${use_config_out} FALSE PARENT_SCOPE) + else() + set(${use_config_out} TRUE PARENT_SCOPE) + endif() +endfunction() + +#------------------------------------------------------------------------- +# Find all required and expected dependencies +#------------------------------------------------------------------------- +include(CMakeFindDependencyMacro) + +function(find_required_dependencies components_in) + foreach(dependency IN LISTS THIRD_PARTY_DEPENDENCIES_SUPPORTED) + set(is_required FALSE) + is_dependency_required(${dependency} ${components_in} is_required) + message(DEBUG "find_required_dependencies: dependency = ${dependency}, is_required = ${is_required}") + if(is_required) + set(use_config FALSE) + is_config_mode_required(${dependency} use_config) + if(${use_config}) + message(DEBUG "find_required_dependencies: calling find_dependency(${dependency} CONFIG)...") + find_dependency(${dependency} CONFIG) + else() + message(DEBUG "find_required_dependencies: calling find_dependency(${dependency})...") + find_dependency(${dependency}) + endif() + if(${dependency}_FOUND AND DEFINED BUILT_WITH_${dependency}_VERSION AND DEFINED ${dependency}_VERSION) + if(NOT ${dependency}_VERSION VERSION_EQUAL ${BUILT_WITH_${dependency}_VERSION}) + message(WARNING "find_required_dependencies: found ${dependency} version ${${dependency}_VERSION} which does not match the opentelemetry-cpp built with version ${BUILT_WITH_${dependency}_VERSION}.") + endif() + endif() + endif() + endforeach() +endfunction() \ No newline at end of file diff --git a/cmake/nlohmann-json.cmake b/cmake/nlohmann-json.cmake index d56a6cbb6d..eb952cb81b 100644 --- a/cmake/nlohmann-json.cmake +++ b/cmake/nlohmann-json.cmake @@ -85,9 +85,10 @@ else() if(OPENTELEMETRY_INSTALL) install( TARGETS nlohmann_json_ - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-third_party_nlohmann_json_target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT third_party_nlohmann_json) endif() endif() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in deleted file mode 100644 index db801b7499..0000000000 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -#[[ -#.rst: -# opentelemetry-cpp-config.cmake -# -------- -# -# Find the native opentelemetry-cpp includes and library. -# -# :: -# -# OPENTELEMETRY_CPP_INCLUDE_DIRS - Include directories of opentelemetry-cpp. -# OPENTELEMETRY_CPP_LIBRARY_DIRS - Link directories of opentelemetry-cpp. -# OPENTELEMETRY_CPP_LIBRARIES - List of libraries when using opentelemetry-cpp. -# OPENTELEMETRY_CPP_FOUND - True if opentelemetry-cpp found. -# OPENTELEMETRY_ABI_VERSION_NO - ABI version of opentelemetry-cpp. -# OPENTELEMETRY_VERSION - Version of opentelemetry-cpp. -# -# :: -# opentelemetry-cpp::api - Imported target of opentelemetry-cpp::api -# opentelemetry-cpp::sdk - Imported target of opentelemetry-cpp::sdk -# opentelemetry-cpp::ext - Imported target of opentelemetry-cpp::ext -# opentelemetry-cpp::version - Imported target of opentelemetry-cpp::version -# opentelemetry-cpp::common - Imported target of opentelemetry-cpp::common -# opentelemetry-cpp::trace - Imported target of opentelemetry-cpp::trace -# opentelemetry-cpp::metrics - Imported target of opentelemetry-cpp::metrics -# opentelemetry-cpp::logs - Imported target of opentelemetry-cpp::logs -# opentelemetry-cpp::in_memory_span_exporter - Imported target of opentelemetry-cpp::in_memory_span_exporter -# opentelemetry-cpp::otlp_grpc_client - Imported target of opentelemetry-cpp::otlp_grpc_client -# opentelemetry-cpp::otlp_recordable - Imported target of opentelemetry-cpp::otlp_recordable -# opentelemetry-cpp::otlp_grpc_exporter - Imported target of opentelemetry-cpp::otlp_grpc_exporter -# opentelemetry-cpp::otlp_grpc_log_record_exporter - Imported target of opentelemetry-cpp::otlp_grpc_log_record_exporter -# opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of opentelemetry-cpp::otlp_grpc_metrics_exporter -# opentelemetry-cpp::otlp_http_client - Imported target of opentelemetry-cpp::otlp_http_client -# opentelemetry-cpp::otlp_http_exporter - Imported target of opentelemetry-cpp::otlp_http_exporter -# opentelemetry-cpp::otlp_http_log_record_exporter - Imported target of opentelemetry-cpp::otlp_http_log_record_exporter -# opentelemetry-cpp::otlp_http_metric_exporter - Imported target of opentelemetry-cpp::otlp_http_metric_exporter -# opentelemetry-cpp::otlp_file_client - Imported target of opentelemetry-cpp::otlp_file_client -# opentelemetry-cpp::otlp_file_exporter - Imported target of opentelemetry-cpp::otlp_file_exporter -# opentelemetry-cpp::otlp_file_log_record_exporter - Imported target of opentelemetry-cpp::otlp_file_log_record_exporter -# opentelemetry-cpp::otlp_file_metric_exporter - Imported target of opentelemetry-cpp::otlp_file_metric_exporter -# opentelemetry-cpp::ostream_log_record_exporter - Imported target of opentelemetry-cpp::ostream_log_record_exporter -# opentelemetry-cpp::ostream_metrics_exporter - Imported target of opentelemetry-cpp::ostream_metrics_exporter -# opentelemetry-cpp::ostream_span_exporter - Imported target of opentelemetry-cpp::ostream_span_exporter -# opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of opentelemetry-cpp::elasticsearch_log_record_exporter -# opentelemetry-cpp::etw_exporter - Imported target of opentelemetry-cpp::etw_exporter -# opentelemetry-cpp::http_client_curl - Imported target of opentelemetry-cpp::http_client_curl -# opentelemetry-cpp::opentracing_shim - Imported target of opentelemetry-cpp::opentracing_shim -# -]] -# ============================================================================= -# Copyright The OpenTelemetry Authors SPDX-License-Identifier: Apache-2.0 -# ============================================================================= - -set(OPENTELEMETRY_ABI_VERSION_NO - "@OPENTELEMETRY_ABI_VERSION_NO@" - CACHE STRING "opentelemetry-cpp ABI version" FORCE) -set(OPENTELEMETRY_VERSION - "@OPENTELEMETRY_VERSION@" - CACHE STRING "opentelemetry-cpp version" FORCE) - -@PACKAGE_INIT@ - -# ############################################################################## - -include(CMakeFindDependencyMacro) - -find_dependency(Threads) - -if(@WITH_OTLP_GRPC@) - find_dependency(gRPC) -endif() - -if("@OpenTracing_FOUND@") - find_dependency(OpenTracing) -endif() - -if("@prometheus-cpp_FOUND@") - find_dependency(prometheus-cpp) -endif() - -if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") - find_dependency(Protobuf) -endif() - -if(@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) - if("@CURL_FOUND@") - find_dependency(CURL) - endif() - - if("@ZLIB_FOUND@") - find_dependency(ZLIB) - endif() -endif() - -if(@WITH_OTLP_GRPC@) - find_package(absl CONFIG) -elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@) - if("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0") - find_package(absl CONFIG) - endif() -endif() - -set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") -set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@") - -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-target.cmake") - -set(OPENTELEMETRY_CPP_LIBRARIES) -set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS - api - sdk - ext - version - common - trace - metrics - logs - in_memory_span_exporter - otlp_recordable - otlp_grpc_client - otlp_grpc_exporter - otlp_grpc_log_record_exporter - otlp_grpc_metrics_exporter - otlp_http_client - otlp_http_exporter - otlp_http_log_record_exporter - otlp_http_metric_exporter - otlp_file_client - otlp_file_exporter - otlp_file_log_record_exporter - otlp_file_metric_exporter - ostream_log_record_exporter - ostream_metrics_exporter - ostream_span_exporter - prometheus_exporter - elasticsearch_log_record_exporter - etw_exporter - http_client_curl - opentracing_shim) -foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS) - if(TARGET opentelemetry-cpp::${_TEST_TARGET}) - list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET}) - endif() -endforeach() - -# handle the QUIETLY and REQUIRED arguments and set opentelemetry-cpp_FOUND to -# TRUE if all variables listed contain valid results, e.g. valid file paths. -include("FindPackageHandleStandardArgs") -find_package_handle_standard_args( - ${CMAKE_FIND_PACKAGE_NAME} - FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND - REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES) - -if(${CMAKE_FIND_PACKAGE_NAME}_FOUND) - set(OPENTELEMETRY_CPP_FOUND - ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} - CACHE BOOL "whether opentelemetry-cpp is found" FORCE) -else() - unset(OPENTELEMETRY_CPP_FOUND) - unset(OPENTELEMETRY_CPP_FOUND CACHE) -endif() diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index d30e8d2293..d88f66966e 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -318,11 +318,6 @@ set_target_version(opentelemetry_proto) # Disable include-what-you-use on generated code. set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "") - -if(TARGET absl::bad_variant_access) - target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access) -endif() - if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf) get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) @@ -371,15 +366,27 @@ patch_protobuf_targets(opentelemetry_proto) if(OPENTELEMETRY_INSTALL) install( - TARGETS ${OPENTELEMETRY_PROTO_TARGETS} - EXPORT "${PROJECT_NAME}-target" + TARGETS opentelemetry_proto + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT exporters_otlp_common) + + if(WITH_OTLP_GRPC) + install( + TARGETS opentelemetry_proto_grpc + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT exporters_otlp_grpc) + endif() install( DIRECTORY ${GENERATED_PROTOBUF_PATH}/opentelemetry DESTINATION include + COMPONENT exporters_otlp_common FILES_MATCHING PATTERN "*.h") endif() @@ -390,10 +397,11 @@ else() # cmake 3.8 or lower target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES}) endif() +# this is needed on some older grcp versions specifically conan recipe for grpc/1.54.3 if(WITH_OTLP_GRPC) if(TARGET absl::synchronization) target_link_libraries(opentelemetry_proto_grpc - PRIVATE absl::synchronization) + PUBLIC "$") endif() endif() diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in new file mode 100644 index 0000000000..46655f8ff6 --- /dev/null +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -0,0 +1,228 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +#.rst: +# opentelemetry-cpp-config.cmake +# -------- +# Finding opentelemetry-cpp in CMake projects +# ======================================== +# +# - find_package(opentelemetry-cpp CONFIG REQUIRED) to import all installed targets and dependencies +# - find_package(opentelemetry-cpp CONFIG COMPONENTS ...) to import specific components' targets and dependencies +# +# Example usage +# ------------------- +# +# 1. **No Components Specified** +# +# When no components are provided, all components and their targets are imported. +# +# .. code-block:: cmake +# +# find_package(opentelemetry-cpp CONFIG REQUIRED) +# +# +# 2. **Components Specified** +# +# When a component is specified, its third-party dependencies are found; +# then, targets from that component, along with the components on which it depends, are imported. +# +# .. code-block:: cmake +# +# find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_otlp_grpc) +# +# +#.. note:: +# To troubleshoot issues with ``find_package(opentelemetry-cpp CONFIG REQUIRED)``, run CMake with debug logging enabled: +# +# .. code-block:: bash +# +# cmake --log-level=DEBUG -S -B +# +# To get more verbose output from CMake’s package search, run CMake with the following flag: +# +# .. code-block:: bash +# +# cmake -DCMAKE_FIND_DEBUG_MODE=ON -S -B +# +# +# CMake Variables Defined +# -------------------- +# +# This module defines the following variables: +# +# :: +# +# OPENTELEMETRY_CPP_INCLUDE_DIRS - Include directories of opentelemetry-cpp. +# OPENTELEMETRY_CPP_LIBRARY_DIRS - Link directories of opentelemetry-cpp. +# OPENTELEMETRY_CPP_LIBRARIES - List of libraries when using opentelemetry-cpp. +# OPENTELEMETRY_CPP_FOUND - True if opentelemetry-cpp found. +# OPENTELEMETRY_ABI_VERSION_NO - ABI version of opentelemetry-cpp. +# OPENTELEMETRY_VERSION - Version of opentelemetry-cpp. +# OPENTELEMETRY_CPP_COMPONENTS_INSTALLED - List of components installed. +# opentelemetry-cpp_FOUND - True if opentelemetry-cpp found. +# opentelemetry-cpp__FOUND - True if the requested component is found. +# :: +# +# +# CMake Components and Targets Supported +# -------------------- +# opentelemetry-cpp supports the following components and targets. This install may include a subset. +# +# COMPONENTS +# api +# sdk +# ext_common +# ext_http_curl +# ext_dll +# exporters_in_memory +# exporters_ostream +# exporters_otlp_common +# exporters_otlp_file +# exporters_otlp_grpc +# exporters_otlp_http +# exporters_prometheus +# exporters_elasticsearch +# exporters_etw +# exporters_zipkin +# shims_opentracing +# +# :: +# +# TARGETS +# opentelemetry-cpp::api - Imported target of COMPONENT api +# opentelemetry-cpp::sdk - Imported target of COMPONENT sdk +# opentelemetry-cpp::version - Imported target of COMPONENT sdk +# opentelemetry-cpp::common - Imported target of COMPONENT sdk +# opentelemetry-cpp::resources - Imported target of COMPONENT sdk +# opentelemetry-cpp::trace - Imported target of COMPONENT sdk +# opentelemetry-cpp::metrics - Imported target of COMPONENT sdk +# opentelemetry-cpp::logs - Imported target of COMPONENT sdk +# opentelemetry-cpp::ext - Imported target of COMPONENT ext_common +# opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext_http_curl +# opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext_dll +# opentelemetry-cpp::in_memory_span_exporter - Imported target of COMPONENT exporters_in_memory +# opentelemetry-cpp::in_memory_metric_exporter - Imported target of COMPONENT exporters_in_memory +# opentelemetry-cpp::ostream_log_record_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::ostream_metrics_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::ostream_span_exporter - Imported target of COMPONENT exporters_ostream +# opentelemetry-cpp::proto - Imported target of COMPONENT exporters_otlp_common +# opentelemetry-cpp::otlp_recordable - Imported target of COMPONENT exporters_otlp_common +# opentelemetry-cpp::otlp_file_client - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_log_record_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::otlp_file_metric_exporter - Imported target of COMPONENT exporters_otlp_file +# opentelemetry-cpp::proto_grpc - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_client - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_log_record_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of COMPONENT exporters_otlp_grpc +# opentelemetry-cpp::otlp_http_client - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_log_record_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::otlp_http_metric_exporter - Imported target of COMPONENT exporters_otlp_http +# opentelemetry-cpp::prometheus_exporter - Imported target of COMPONENT exporters_prometheus +# opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of COMPONENT exporters_elasticsearch +# opentelemetry-cpp::etw_exporter - Imported target of COMPONENT exporters_etw +# opentelemetry-cpp::zipkin_trace_exporter - Imported target of COMPONENT exporters_zipkin +# opentelemetry-cpp::opentracing_shim - Imported target of COMPONENT shims_opentracing +# +# Additional Files Used in Component to Component and Third-Party Dependency Resolution +# -------------------------------------------------------- +# +# - **thirdparty-dependency-definitions.cmake** +# This file lists the third-party dependencies supported by opentelemetry-cpp and components that may require them. +# Dependencies are found in the order defined in this file when find_package(opentelemetry-cpp …) is invoked. +# +# **Found using CMake CONFIG search mode:** +# +# - **absl** +# - **nlohmann_json** +# - **Protobuf** +# - **gRPC** +# - **prometheus-cpp** +# - **OpenTracing** +# +# **Found using the CMake MODULE search mode:** +# +# - **Threads** +# - **ZLIB** +# - **CURL** +# +# - **component-definitions.cmake** +# This file defines the available opentelemetry-cpp components, the targets associated with each +# component, and the inter-component dependencies. +# + + +# ============================================================================= +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 +# ============================================================================= + +set(OPENTELEMETRY_ABI_VERSION_NO + "@OPENTELEMETRY_ABI_VERSION_NO@" + CACHE STRING "opentelemetry-cpp ABI version" FORCE) +set(OPENTELEMETRY_VERSION + "@OPENTELEMETRY_VERSION@" + CACHE STRING "opentelemetry-cpp version" FORCE) + +@PACKAGE_INIT@ + +# Include the opentelemetry-cpp file that includes component defintions, thirdparty definitons and functions to support finding this package and dependencies. +include("${CMAKE_CURRENT_LIST_DIR}/find-package-support-functions.cmake") + +set(_INSTALLED_COMPONENTS "") +get_installed_components(_INSTALLED_COMPONENTS) + +set(OPENTELEMETRY_CPP_COMPONENTS_INSTALLED ${_INSTALLED_COMPONENTS} CACHE STRING "opentelemetry-cpp components installed" FORCE) + +set(_REQUESTED_COMPONENTS "") +get_requested_components(_INSTALLED_COMPONENTS _REQUESTED_COMPONENTS) + +find_required_dependencies(_REQUESTED_COMPONENTS) + +set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@") + +# include the target files selected and set the component found flag +foreach(_COMPONENT IN LISTS _REQUESTED_COMPONENTS) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-${_COMPONENT}-target.cmake") + set(${CMAKE_FIND_PACKAGE_NAME}_${_COMPONENT}_FOUND TRUE + CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} component ${_COMPONENT} is found" FORCE) +endforeach() + +# get installed and requested targets +set(_OPENTELEMETRY_CPP_TARGETS "") +get_targets(_REQUESTED_COMPONENTS _OPENTELEMETRY_CPP_TARGETS) +check_targets_imported(_OPENTELEMETRY_CPP_TARGETS) + +# Set OPENTELEMETRY_CPP_* variables +set(OPENTELEMETRY_CPP_LIBRARIES) + +set(DLL_TARGET "opentelemetry-cpp::opentelemetry_cpp") + +foreach(_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) + if(TARGET "${_TARGET}" AND NOT "${_TARGET}" STREQUAL "${DLL_TARGET}") + list(APPEND OPENTELEMETRY_CPP_LIBRARIES "${_TARGET}") + endif() +endforeach() + +# handle the QUIETLY and REQUIRED arguments and set opentelemetry-cpp_FOUND to +# TRUE if all variables listed contain valid results, e.g. valid file paths. +include("FindPackageHandleStandardArgs") +find_package_handle_standard_args( + ${CMAKE_FIND_PACKAGE_NAME} + FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND + REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES) + +if(${CMAKE_FIND_PACKAGE_NAME}_FOUND) + set(OPENTELEMETRY_CPP_FOUND + ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} + CACHE BOOL "whether opentelemetry-cpp is found" FORCE) +else() + unset(OPENTELEMETRY_CPP_FOUND) + unset(OPENTELEMETRY_CPP_FOUND CACHE) +endif() + +check_required_components(${CMAKE_FIND_PACKAGE_NAME}) \ No newline at end of file diff --git a/cmake/templates/thirdparty-built-with-flags.cmake.in b/cmake/templates/thirdparty-built-with-flags.cmake.in new file mode 100644 index 0000000000..c893332ad4 --- /dev/null +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -0,0 +1,103 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +#------------------------------------------------------------------------- +# CMAKE flags to capture the build configuration for the insalled package +# BUILT_WITH_ is set to true if the installed package requires that dependency +# See the thirdparty-dependency-deinfitions.cmake for the supported dependency list and +# mapping to opentelemetry-cpp components. +#------------------------------------------------------------------------- + +# Initialize dependency expected flags +set(BUILT_WITH_Threads TRUE) +set(BUILT_WITH_CURL FALSE) +set(BUILT_WITH_ZLIB FALSE) +set(BUILT_WITH_nlohmann_json FALSE) +set(BUILT_WITH_Protobuf FALSE) +set(BUILT_WITH_gRPC FALSE) +set(BUILT_WITH_prometheus-cpp FALSE) +set(BUILT_WITH_OpenTracing FALSE) + +# CURL and ZLIB: +if(@WITH_HTTP_CLIENT_CURL@) + if("@CURL_FOUND@") + set(BUILT_WITH_CURL TRUE) + endif() + if("@ZLIB_FOUND@") + set(BUILT_WITH_ZLIB TRUE) + endif() +endif() + +# nlohmann_json: +if("@USE_NLOHMANN_JSON@") + set(BUILT_WITH_nlohmann_json TRUE) +endif() + +# Protobuf: +# Expected TRUE if protobuf was found during the build +if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") + set(BUILT_WITH_Protobuf TRUE) +endif() + +# gRPC: +if(@WITH_OTLP_GRPC@) + set(BUILT_WITH_gRPC TRUE) +endif() + +# prometheus-cpp: +if(@WITH_PROMETHEUS@) + set(BUILT_WITH_prometheus-cpp TRUE) +endif() + +# OpenTracing: +if(@WITH_OPENTRACING@) + set(BUILT_WITH_OpenTracing TRUE) +endif() + +#----------------------------------------------------------------------- +# Third party dependency versions +#----------------------------------------------------------------------- +if(BUILT_WITH_CURL) + set(BUILT_WITH_CURL_VERSION @CURL_VERSION_STRING@) +endif() + +if(BUILT_WITH_ZLIB) + set(BUILT_WITH_ZLIB_VERSION @ZLIB_VERSION@) +endif() + +if(BUILT_WITH_nlohmann_json) + set(BUILT_WITH_nlohmann_json_VERSION @nlohmann_json_VERSION@) +endif() + +if(BUILT_WITH_Protobuf) + set(BUILT_WITH_Protobuf_VERSION @Protobuf_VERSION@) +endif() + +if(BUILT_WITH_gRPC) + set(BUILT_WITH_gRPC_VERSION @gRPC_VERSION@) +endif() + +if(BUILT_WITH_prometheus-cpp) + set(BUILT_WITH_prometheus-cpp_VERSION @prometheus-cpp_VERSION@) +endif() + +if(BUILT_WITH_OpenTracing) + set(BUILT_WITH_OpenTracing_VERSION @OpenTracing_VERSION@) +endif() + +#----------------------------------------------------------------------- +# Flags to determine if CONFIG search mode should be used in find_dependency(...) +#----------------------------------------------------------------------- +set(FIND_DEPENDENCY_Threads_USE_CONFIG FALSE) +set(FIND_DEPENDENCY_ZLIB_USE_CONFIG FALSE) +set(FIND_DEPENDENCY_CURL_USE_CONFIG FALSE) +set(FIND_DEPENDENCY_nlohmann_json_USE_CONFIG TRUE) +set(FIND_DEPENDENCY_gRPC_USE_CONFIG TRUE) +set(FIND_DEPENDENCY_prometheus-cpp_USE_CONFIG TRUE) +set(FIND_DEPENDENCY_OpenTracing_USE_CONFIG TRUE) + +if(DEFINED BUILT_WITH_Protobuf_VERSION AND BUILT_WITH_Protobuf_VERSION VERSION_GREATER_EQUAL 3.22.0) + set(FIND_DEPENDENCY_Protobuf_USE_CONFIG TRUE) +else() + set(FIND_DEPENDENCY_Protobuf_USE_CONFIG FALSE) +endif() diff --git a/cmake/thirdparty-dependency-definitions.cmake b/cmake/thirdparty-dependency-definitions.cmake new file mode 100644 index 0000000000..33de84f027 --- /dev/null +++ b/cmake/thirdparty-dependency-definitions.cmake @@ -0,0 +1,64 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +#----------------------------------------------------------------------- +# Third party dependencies supported by opentelemetry-cpp +# Dependencies will be found in this order when find_package(opentelemetry-cpp ...) is called. +#----------------------------------------------------------------------- +set(THIRD_PARTY_DEPENDENCIES_SUPPORTED + Threads + ZLIB + CURL + nlohmann_json + Protobuf + gRPC + prometheus-cpp + OpenTracing +) + +#----------------------------------------------------------------------- +# THIRD_PARTY to COMPONENT dependencies +# These are the components that may require the third party dependency +#----------------------------------------------------------------------- + +# Components that require Threads +set(THIRD_PARTY_Threads_DEPENDENT_COMPONENTS + sdk +) + +# Components that may require ZLIB +set(THIRD_PARTY_ZLIB_DEPENDENT_COMPONENTS + ext_http_curl +) + +# Components that may require CURL +set(THIRD_PARTY_CURL_DEPENDENT_COMPONENTS + ext_http_curl +) + +# Components that require nlohmann_json +set(THIRD_PARTY_nlohmann_json_DEPENDENT_COMPONENTS + exporters_zipkin + exporters_elasticsearch + exporters_etw +) + +# Components that require Protobuf +set(THIRD_PARTY_Protobuf_DEPENDENT_COMPONENTS + exporters_otlp_common +) + +# Components that require gRPC +set(THIRD_PARTY_gRPC_DEPENDENT_COMPONENTS + exporters_otlp_grpc +) + +# Components that require prometheus-cpp +set(THIRD_PARTY_prometheus-cpp_DEPENDENT_COMPONENTS + exporters_prometheus +) + +# Components that require OpenTracing +set(THIRD_PARTY_OpenTracing_DEPENDENT_COMPONENTS + shims_opentracing +) diff --git a/examples/grpc/CMakeLists.txt b/examples/grpc/CMakeLists.txt index ea34e58364..ff833edfde 100644 --- a/examples/grpc/CMakeLists.txt +++ b/examples/grpc/CMakeLists.txt @@ -42,9 +42,6 @@ else() target_link_libraries(example_grpc_proto PUBLIC gRPC::grpc++ ${Protobuf_LIBRARIES}) endif() -if(WITH_OTLP_GRPC) - target_link_libraries(example_grpc_proto PUBLIC absl::bad_variant_access) -endif() foreach(_target client server) add_executable(${_target} "${_target}.cc") diff --git a/examples/otlp/README.md b/examples/otlp/README.md index d1846a88a2..dab6a5048d 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -67,19 +67,3 @@ Once you have the Collector running, see [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. -## Additional notes regarding Abseil library - -gRPC internally uses a different version of Abseil than OpenTelemetry C++ SDK. - -One option to optimize your code is to build the SDK with system-provided -Abseil library. If you are using CMake, then `-DWITH_ABSEIL=ON` may be passed -during the build of SDK to reuse the same Abseil library as gRPC. If you are -using Bazel, then `--@io_opentelemetry_cpp/api:with_abseil=true` may be passed -to reuse your Abseil library in your project. - -If you do not want to pursue the above option, and in case if you run into -conflict between Abseil library and OpenTelemetry C++ `absl::variant` -implementation, please include either `grpcpp/grpcpp.h` or -`opentelemetry/exporters/otlp/otlp_grpc_exporter.h` BEFORE any other API -headers. This approach efficiently avoids the conflict between the two different -versions of Abseil. diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index e91b53f1c6..a5d0c31e99 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -21,17 +21,27 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_elasticsearch_logs - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_elasticsearch-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT exporters_elasticsearch) install( DIRECTORY include/opentelemetry/exporters/elasticsearch DESTINATION include/opentelemetry/exporters + COMPONENT exporters_elasticsearch FILES_MATCHING PATTERN "*.h" PATTERN "es_log_recordable.h" EXCLUDE) + + install( + EXPORT "${PROJECT_NAME}-exporters_elasticsearch-target" + FILE "${PROJECT_NAME}-exporters_elasticsearch-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_elasticsearch) + endif() if(BUILD_TESTING) diff --git a/exporters/etw/CMakeLists.txt b/exporters/etw/CMakeLists.txt index 947e390dd9..fa98992509 100644 --- a/exporters/etw/CMakeLists.txt +++ b/exporters/etw/CMakeLists.txt @@ -22,16 +22,24 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_etw - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_etw-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_etw) install( DIRECTORY include/opentelemetry/exporters/etw DESTINATION include/opentelemetry/exporters + COMPONENT exporters_etw FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_etw-target" + FILE "${PROJECT_NAME}-exporters_etw-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_etw) endif() if(BUILD_TESTING) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 0738759a96..79ec4b08c5 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -36,16 +36,25 @@ if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_in_memory opentelemetry_exporter_in_memory_metric - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_in_memory-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_in_memory) install( DIRECTORY include/opentelemetry/exporters/memory DESTINATION include/opentelemetry/exporters + COMPONENT exporters_in_memory FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_in_memory-target" + FILE "${PROJECT_NAME}-exporters_in_memory-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_in_memory) + endif() if(BUILD_TESTING) diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index e08d6592a3..7515093e1b 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -15,20 +15,7 @@ target_include_directories( target_link_libraries(opentelemetry_exporter_ostream_span PUBLIC opentelemetry_trace) -if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_ostream_span - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - - install( - DIRECTORY include/opentelemetry/exporters/ostream - DESTINATION include/opentelemetry/exporters - PATTERN "*.h" - PATTERN "log_record_exporter.h" EXCLUDE) -endif() +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS opentelemetry_exporter_ostream_span) if(BUILD_TESTING) add_executable(ostream_span_test test/ostream_span_test.cc) @@ -52,18 +39,8 @@ target_include_directories( target_link_libraries(opentelemetry_exporter_ostream_metrics PUBLIC opentelemetry_metrics) -if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_ostream_metrics - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install( - DIRECTORY include/opentelemetry/exporters/ostream - DESTINATION include/opentelemetry/exporters - PATTERN "metric_exporter.h") -endif() +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS + opentelemetry_exporter_ostream_metrics) if(BUILD_TESTING) add_executable(ostream_metric_test test/ostream_metric_test.cc) @@ -87,19 +64,27 @@ target_include_directories( PUBLIC "$") target_link_libraries(opentelemetry_exporter_ostream_logs PUBLIC opentelemetry_logs) +list(APPEND OPENTELEMETRY_OSTREAM_TARGETS opentelemetry_exporter_ostream_logs) if(OPENTELEMETRY_INSTALL) install( - TARGETS opentelemetry_exporter_ostream_logs - EXPORT "${PROJECT_NAME}-target" + TARGETS ${OPENTELEMETRY_OSTREAM_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_ostream-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_ostream) + install( + DIRECTORY include/opentelemetry/exporters/ostream + DESTINATION include/opentelemetry/exporters + COMPONENT exporters_ostream + PATTERN "*.h") + install( - FILES - "include/opentelemetry/exporters/ostream/log_record_exporter.h" - "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" - DESTINATION include/opentelemetry/exporters/ostream) + EXPORT "${PROJECT_NAME}-exporters_ostream-target" + FILE "${PROJECT_NAME}-exporters_ostream-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_ostream) endif() if(BUILD_TESTING) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 126a62310c..d30341b7ab 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -38,11 +38,10 @@ if(WITH_OTLP_GRPC) # targets that depend on opentelemetry_proto_grpc. target_link_libraries( opentelemetry_exporter_otlp_grpc_client - PUBLIC opentelemetry_sdk opentelemetry_common opentelemetry_ext + PUBLIC opentelemetry_sdk opentelemetry_common # gRPC::grpc++ must be linked before opentelemetry_proto_grpc. opentelemetry_proto_grpc - PRIVATE gRPC::grpc++ absl::bad_variant_access absl::any absl::base - absl::bits absl::city) + PRIVATE gRPC::grpc++ opentelemetry_ext) get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++ INTERFACE_INCLUDE_DIRECTORIES) @@ -56,7 +55,7 @@ if(WITH_OTLP_GRPC) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc_client) add_library( @@ -73,7 +72,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc) add_library( opentelemetry_exporter_otlp_grpc_log @@ -90,7 +89,8 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_log) + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS + opentelemetry_exporter_otlp_grpc_log) add_library( opentelemetry_exporter_otlp_grpc_metrics @@ -106,7 +106,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_grpc_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_GRPC_TARGETS opentelemetry_exporter_otlp_grpc_metrics) endif() @@ -124,12 +124,9 @@ if(WITH_OTLP_HTTP) # building internal components PRIVATE opentelemetry_proto "$" - nlohmann_json::nlohmann_json + "$" "$") - if(TARGET absl::strings) - target_link_libraries(opentelemetry_exporter_otlp_http_client - PUBLIC absl::strings) - endif() + if(nlohmann_json_clone) add_dependencies(opentelemetry_exporter_otlp_http_client nlohmann_json::nlohmann_json) @@ -139,7 +136,7 @@ if(WITH_OTLP_HTTP) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http_client) add_library( @@ -156,7 +153,7 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http) + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http) add_library( opentelemetry_exporter_otlp_http_log @@ -173,7 +170,8 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log) + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS + opentelemetry_exporter_otlp_http_log) add_library( opentelemetry_exporter_otlp_http_metric @@ -189,7 +187,7 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http_metric) endif() @@ -202,11 +200,8 @@ if(WITH_OTLP_FILE) target_link_libraries( opentelemetry_exporter_otlp_file_client PUBLIC opentelemetry_sdk opentelemetry_common - PRIVATE opentelemetry_proto nlohmann_json::nlohmann_json) - if(TARGET absl::strings) - target_link_libraries(opentelemetry_exporter_otlp_file_client - PUBLIC absl::strings) - endif() + PRIVATE opentelemetry_proto $) + if(nlohmann_json_clone) add_dependencies(opentelemetry_exporter_otlp_file_client nlohmann_json::nlohmann_json) @@ -216,7 +211,7 @@ if(WITH_OTLP_FILE) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file_client) add_library( @@ -233,7 +228,7 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_file) + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file) add_library( opentelemetry_exporter_otlp_file_log @@ -250,7 +245,8 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_file_log) + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS + opentelemetry_exporter_otlp_file_log) add_library( opentelemetry_exporter_otlp_file_metric @@ -266,7 +262,7 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_otlp_recordable opentelemetry_exporter_otlp_file_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file_metric) endif() @@ -276,17 +272,73 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( - TARGETS ${OPENTELEMETRY_OTLP_TARGETS} - EXPORT "${PROJECT_NAME}-target" + TARGETS opentelemetry_otlp_recordable + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_otlp_common) install( DIRECTORY include/opentelemetry/exporters/otlp DESTINATION include/opentelemetry/exporters + COMPONENT exporters_otlp_common FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_common-target" + FILE "${PROJECT_NAME}-exporters_otlp_common-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_common) + + if(WITH_OTLP_GRPC) + install( + TARGETS ${OPENTELEMETRY_OTLP_GRPC_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_otlp_grpc) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" + FILE "${PROJECT_NAME}-exporters_otlp_grpc-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_grpc) + endif() + + if(WITH_OTLP_FILE) + install( + TARGETS ${OPENTELEMETRY_OTLP_FILE_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_file-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_otlp_file) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_file-target" + FILE "${PROJECT_NAME}-exporters_otlp_file-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_file) + endif() + + if(WITH_OTLP_HTTP) + install( + TARGETS ${OPENTELEMETRY_OTLP_HTTP_TARGETS} + EXPORT "${PROJECT_NAME}-exporters_otlp_http-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_otlp_http) + + install( + EXPORT "${PROJECT_NAME}-exporters_otlp_http-target" + FILE "${PROJECT_NAME}-exporters_otlp_http-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_http) + endif() endif() if(BUILD_TESTING) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 6c872be3ab..13fdfd1006 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -40,16 +40,24 @@ target_link_libraries(opentelemetry_exporter_prometheus if(OPENTELEMETRY_INSTALL) install( TARGETS ${PROMETHEUS_EXPORTER_TARGETS} - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_prometheus-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_prometheus) install( DIRECTORY include/opentelemetry/exporters/prometheus DESTINATION include/opentelemetry/exporters/ + COMPONENT exporters_prometheus FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_prometheus-target" + FILE "${PROJECT_NAME}-exporters_prometheus-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_prometheus) endif() if(BUILD_TESTING) diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 5944258ca3..52b7af913e 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -12,6 +12,9 @@ target_include_directories( PUBLIC "$" "$") +set_target_properties(opentelemetry_exporter_zipkin_trace + PROPERTIES EXPORT_NAME zipkin_trace_exporter) + set_target_version(opentelemetry_exporter_zipkin_trace) target_link_libraries( @@ -22,17 +25,26 @@ target_link_libraries( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_zipkin_trace - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-exporters_zipkin-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT exporters_zipkin) install( DIRECTORY include/opentelemetry/exporters/zipkin DESTINATION include/opentelemetry/exporters + COMPONENT exporters_zipkin FILES_MATCHING PATTERN "*.h" PATTERN "recordable.h" EXCLUDE) + + install( + EXPORT "${PROJECT_NAME}-exporters_zipkin-target" + FILE "${PROJECT_NAME}-exporters_zipkin-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_zipkin) + endif() if(BUILD_TESTING) @@ -52,8 +64,13 @@ if(BUILD_TESTING) add_executable(zipkin_exporter_test test/zipkin_exporter_test.cc) target_link_libraries( - zipkin_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIB} opentelemetry_exporter_zipkin_trace opentelemetry_resources) + zipkin_exporter_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIB} + opentelemetry_exporter_zipkin_trace + opentelemetry_resources + ${CURL_LIBRARIES}) gtest_add_tests( TARGET zipkin_exporter_test diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index bae59e3040..8569658591 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -13,16 +13,25 @@ target_link_libraries(opentelemetry_ext INTERFACE opentelemetry_api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_ext - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext_common-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ext_common) install( DIRECTORY include/opentelemetry/ext DESTINATION include/opentelemetry/ + COMPONENT ext_common FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-ext_common-target" + FILE "${PROJECT_NAME}-ext_common-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT ext_common) + endif() add_subdirectory(src) diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index 2fd55d5db0..17323bc2a4 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -119,8 +119,15 @@ add_custom_command( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_cpp - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext_dll-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ext_dll) + + install( + EXPORT "${PROJECT_NAME}-ext_dll-target" + FILE "${PROJECT_NAME}-ext_dll-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT ext_dll) endif() diff --git a/ext/src/http/client/curl/CMakeLists.txt b/ext/src/http/client/curl/CMakeLists.txt index ead02699b0..4c86bc74b3 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -70,8 +70,15 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_http_client_curl - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext_http_curl-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ext_http_curl) + + install( + EXPORT "${PROJECT_NAME}-ext_http_curl-target" + FILE "${PROJECT_NAME}-ext_http_curl-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT ext_http_curl) endif() diff --git a/install/conan/conanfile_latest.txt b/install/conan/conanfile_latest.txt new file mode 100644 index 0000000000..90a832eb1d --- /dev/null +++ b/install/conan/conanfile_latest.txt @@ -0,0 +1,39 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +[requires] +zlib/1.3.1 +libcurl/8.12.1 +abseil/20240116.2 +protobuf/5.27.0 +grpc/1.67.1 +nlohmann_json/3.11.3 +prometheus-cpp/1.3.0 +opentracing-cpp/1.6.0 + +[options] +grpc/*:fPIC=True +grpc/*:shared=False +grpc/*:csharp_plugin=False +grpc/*:node_plugin=False +grpc/*:objective_c_plugin=False +grpc/*:php_plugin=False +grpc/*:python_plugin=False +grpc/*:ruby_plugin=False +protobuf/*:fPIC=True +protobuf/*:shared=False +abseil/*:fPIC=True +abseil/*:shared=False +opentracing-cpp/*:fPIC=True +opentracing-cpp/*:shared=True + +[test_requires] +gtest/1.16.0 +benchmark/1.9.1 + +[generators] +CMakeToolchain +CMakeDeps + +[layout] +cmake_layout \ No newline at end of file diff --git a/install/conan/conanfile_stable.txt b/install/conan/conanfile_stable.txt new file mode 100644 index 0000000000..796fdaa412 --- /dev/null +++ b/install/conan/conanfile_stable.txt @@ -0,0 +1,39 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +[requires] +zlib/1.2.13 +libcurl/8.5.0 +abseil/20230125.3 +protobuf/3.21.12 +grpc/1.54.3 +nlohmann_json/3.10.5 +prometheus-cpp/1.3.0 +opentracing-cpp/1.6.0 + +[options] +grpc/*:fPIC=True +grpc/*:shared=False +grpc/*:csharp_plugin=False +grpc/*:node_plugin=False +grpc/*:objective_c_plugin=False +grpc/*:php_plugin=False +grpc/*:python_plugin=False +grpc/*:ruby_plugin=False +protobuf/*:fPIC=True +protobuf/*:shared=False +abseil/*:fPIC=True +abseil/*:shared=False +opentracing-cpp/*:fPIC=True +opentracing-cpp/*:shared=True + +[test_requires] +gtest/1.14.0 +benchmark/1.9.1 + +[generators] +CMakeToolchain +CMakeDeps + +[layout] +cmake_layout \ No newline at end of file diff --git a/install/test/cmake/CMakeLists.txt b/install/test/cmake/CMakeLists.txt new file mode 100644 index 0000000000..1c8b69fc07 --- /dev/null +++ b/install/test/cmake/CMakeLists.txt @@ -0,0 +1,141 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-component-install-tests LANGUAGES CXX) + +if(NOT INSTALL_TEST_CMAKE_OPTIONS) + set(INSTALL_TEST_CMAKE_OPTIONS + "-DCMAKE_CXX_STANDARD=14 -DCMAKE_BUILD_TYPE=Debug") +endif() + +separate_arguments(INSTALL_TEST_CMAKE_OPTIONS) + +message( + STATUS "INSTALL_TEST_CMAKE_OPTIONS is set to ${INSTALL_TEST_CMAKE_OPTIONS}") + +find_package(opentelemetry-cpp CONFIG REQUIRED) + +message( + STATUS + "OPENTELEMETRY_CPP_COMPONENTS_INSTALLED = ${OPENTELEMETRY_CPP_COMPONENTS_INSTALLED}" +) + +# Check that INSTALL_TEST_COMPONENTS is set and contains installed components +if(NOT INSTALL_TEST_COMPONENTS) + message( + STATUS + "INSTALL_TEST_COMPONENTS is not set. Setting to OPENTELEMETRY_CPP_COMPONENTS_INSTALLED" + ) + set(INSTALL_TEST_COMPONENTS ${OPENTELEMETRY_CPP_COMPONENTS_INSTALLED}) +else() + set(COMPONENTS_ARE_VALID TRUE) + foreach(component ${INSTALL_TEST_COMPONENTS}) + if(NOT component IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) + message( + ERROR + " Component ${component} is not an installed opentelemetry-cpp component" + ) + set(COMPONENTS_ARE_VALID FALSE) + endif() + endforeach() + if(NOT COMPONENTS_ARE_VALID) + message(FATAL_ERROR "INSTALL_TEST_COMPONENTS contains invalid components") + endif() +endif() + +message(STATUS "INSTALL_TEST_COMPONENTS = ${INSTALL_TEST_COMPONENTS}") + +set(INSTALL_TEST_SRC_DIR "${CMAKE_SOURCE_DIR}/../src") + +enable_testing() + +# ----------------------------------------------------------- +# CMake Usage tests for find_package(opentelemetry-cpp ...) +# +# 1. Test find_package with no components specified +# 2. Test find_package with components specified but not sorted in dependency +# order +# 3. Test find_package with components specified but missing dependent components +# 4. Test find_package with components specified but including +# unsupported/unknown components + +add_test( + NAME cmake-usage-no-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/usage_tests/no_components -B + build-cmake-usage-no-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) + +add_test( + NAME cmake-usage-unsorted-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/usage_tests/unsorted_components -B + build-cmake-usage-unsorted-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) + +add_test( + NAME cmake-usage-missing-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/usage_tests/missing_components -B + build-cmake-usage-missing-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) + +add_test( + NAME cmake-usage-unsupported-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/usage_tests/unsupported_components -B + build-cmake-usage-unsupported-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) + +# ----------------------------------------------------------- +# Test the full package install using legacy cmake build instructions +# find_package(opentelemetry-cpp CONFIG REQUIRED) + +# Test cmake configuration +add_test( + NAME full-package-cmake-config-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S ${CMAKE_SOURCE_DIR}/package_test -B + build-full-package-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ${INSTALL_TEST_CMAKE_OPTIONS} + "-DINSTALL_TEST_COMPONENTS=${INSTALL_TEST_COMPONENTS}" + "-DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}") + +# Build the full package test executable +add_test(NAME full-package-build-test + COMMAND ${CMAKE_COMMAND} --build + ${CMAKE_BINARY_DIR}/build-full-package-test --parallel) + +# Run the full package test executable +add_test(NAME full-package-run-test + COMMAND ${CMAKE_BINARY_DIR}/build-full-package-test/full_test) +# ----------------------------------------------------------- + +# ----------------------------------------------------------- +# Loop over all the components to test +foreach(component ${INSTALL_TEST_COMPONENTS}) + # Test cmake configuration + add_test( + NAME component-${component}-cmake-config-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/component_tests/${component} -B + build-${component}-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ${INSTALL_TEST_CMAKE_OPTIONS} + "-DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}") + + # Build the component test executable + add_test(NAME component-${component}-build-test + COMMAND ${CMAKE_COMMAND} --build + ${CMAKE_BINARY_DIR}/build-${component}-test --parallel) + + # Run the component test executable + add_test( + NAME component-${component}-run-test + COMMAND ${CMAKE_BINARY_DIR}/build-${component}-test/${component}_test) +endforeach() diff --git a/install/test/cmake/component_tests/api/CMakeLists.txt b/install/test/cmake/component_tests/api/CMakeLists.txt new file mode 100644 index 0000000000..e4a963ab81 --- /dev/null +++ b/install/test/cmake/component_tests/api/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-api-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS api) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(api_test ${INSTALL_TEST_SRC_DIR}/test_api.cc) +target_link_libraries(api_test PRIVATE opentelemetry-cpp::api GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(api_test) diff --git a/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt new file mode 100644 index 0000000000..3019aa1d2a --- /dev/null +++ b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-elasticsearch-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_elasticsearch) + +if(NOT TARGET nlohmann_json::nlohmann_json) + message(FATAL_ERROR "nlohmann_json::nlohmann_json target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_elasticsearch_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_elasticsearch.cc) +target_link_libraries( + exporters_elasticsearch_test + PRIVATE opentelemetry-cpp::elasticsearch_log_record_exporter GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_elasticsearch_test) diff --git a/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt new file mode 100644 index 0000000000..4860a2f1f5 --- /dev/null +++ b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters_etw-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_etw) + +if(NOT TARGET nlohmann_json::nlohmann_json) + message(FATAL_ERROR "nlohmann_json::nlohmann_json target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_etw_test ${INSTALL_TEST_SRC_DIR}/test_exporters_etw.cc) +target_link_libraries(exporters_etw_test PRIVATE opentelemetry-cpp::etw_exporter + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(exporters_etw_test) diff --git a/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt b/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt new file mode 100644 index 0000000000..e24b7761fa --- /dev/null +++ b/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-in-memory-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_in_memory) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_in_memory_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_in_memory.cc) +target_link_libraries( + exporters_in_memory_test + PRIVATE opentelemetry-cpp::in_memory_span_exporter + opentelemetry-cpp::in_memory_metric_exporter GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_in_memory_test) diff --git a/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt b/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt new file mode 100644 index 0000000000..eec0f26a7e --- /dev/null +++ b/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-ostream-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_ostream) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_ostream_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_ostream.cc) +target_link_libraries( + exporters_ostream_test + PRIVATE opentelemetry-cpp::ostream_log_record_exporter + opentelemetry-cpp::ostream_metrics_exporter + opentelemetry-cpp::ostream_span_exporter + GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_ostream_test) diff --git a/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt new file mode 100644 index 0000000000..e7bd38fe1f --- /dev/null +++ b/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-otlp-common-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_common) + +if(NOT TARGET protobuf::libprotobuf) + message(FATAL_ERROR "protobuf::libprotobuf target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_otlp_common_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_otlp_common.cc) +target_link_libraries( + exporters_otlp_common_test + PRIVATE opentelemetry-cpp::proto opentelemetry-cpp::otlp_recordable + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(exporters_otlp_common_test) diff --git a/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt new file mode 100644 index 0000000000..e625a73bb3 --- /dev/null +++ b/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-otlp-file-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_file) + +if(NOT TARGET protobuf::libprotobuf) + message(FATAL_ERROR "protobuf::libprotobuf target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_otlp_file_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_otlp_file.cc) +target_link_libraries( + exporters_otlp_file_test + PRIVATE opentelemetry-cpp::otlp_file_client + opentelemetry-cpp::otlp_file_exporter + opentelemetry-cpp::otlp_file_log_record_exporter + opentelemetry-cpp::otlp_file_metric_exporter + GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_otlp_file_test) diff --git a/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt new file mode 100644 index 0000000000..62665d10c8 --- /dev/null +++ b/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-otlp-grpc-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_grpc) + +if(NOT TARGET protobuf::libprotobuf) + message(FATAL_ERROR "protobuf::libprotobuf target not found") +endif() + +if(NOT TARGET gRPC::grpc++) + message(FATAL_ERROR "gRPC::grpc++ target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_otlp_grpc_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_otlp_grpc.cc) +target_link_libraries( + exporters_otlp_grpc_test + PRIVATE opentelemetry-cpp::otlp_grpc_exporter + opentelemetry-cpp::otlp_grpc_log_record_exporter + opentelemetry-cpp::otlp_grpc_metrics_exporter + GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_otlp_grpc_test) diff --git a/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt new file mode 100644 index 0000000000..ca555c05cc --- /dev/null +++ b/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-otlp-http-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_http) + +if(NOT TARGET protobuf::libprotobuf) + message(FATAL_ERROR "protobuf::libprotobuf target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_otlp_http_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_otlp_http.cc) +target_link_libraries( + exporters_otlp_http_test + PRIVATE opentelemetry-cpp::otlp_http_client + opentelemetry-cpp::otlp_http_exporter + opentelemetry-cpp::otlp_http_log_record_exporter + opentelemetry-cpp::otlp_http_metric_exporter + GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(exporters_otlp_http_test) diff --git a/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt b/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt new file mode 100644 index 0000000000..78eaa26136 --- /dev/null +++ b/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-prometheus-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_prometheus) + +if(NOT TARGET prometheus-cpp::core) + message(FATAL_ERROR "prometheus-cpp::core target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_prometheus_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_prometheus.cc) +target_link_libraries( + exporters_prometheus_test PRIVATE opentelemetry-cpp::prometheus_exporter + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(exporters_prometheus_test) diff --git a/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt new file mode 100644 index 0000000000..cbbb7ba887 --- /dev/null +++ b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-exporters-zipkin-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_zipkin) + +if(NOT TARGET nlohmann_json::nlohmann_json) + message(FATAL_ERROR "nlohmann_json::nlohmann_json target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(exporters_zipkin_test + ${INSTALL_TEST_SRC_DIR}/test_exporters_zipkin.cc) +target_link_libraries( + exporters_zipkin_test PRIVATE opentelemetry-cpp::zipkin_trace_exporter + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(exporters_zipkin_test) diff --git a/install/test/cmake/component_tests/ext_common/CMakeLists.txt b/install/test/cmake/component_tests/ext_common/CMakeLists.txt new file mode 100644 index 0000000000..0d6abde19f --- /dev/null +++ b/install/test/cmake/component_tests/ext_common/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-ext_common-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_common) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(ext_common_test ${INSTALL_TEST_SRC_DIR}/test_ext_common.cc) +target_link_libraries(ext_common_test PRIVATE opentelemetry-cpp::ext + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(ext_common_test) diff --git a/install/test/cmake/component_tests/ext_dll/CMakeLists.txt b/install/test/cmake/component_tests/ext_dll/CMakeLists.txt new file mode 100644 index 0000000000..bfff138544 --- /dev/null +++ b/install/test/cmake/component_tests/ext_dll/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-ext_dll-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_dll) + +add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(ext_dll_test ${INSTALL_TEST_SRC_DIR}/test_ext_dll.cc) + +target_include_directories(ext_dll_test + PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) + +target_link_libraries(ext_dll_test PRIVATE opentelemetry-cpp::opentelemetry_cpp + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(ext_dll_test) diff --git a/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt b/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt new file mode 100644 index 0000000000..caafd3e766 --- /dev/null +++ b/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-ext_http_curl-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_http_curl) + +if(NOT TARGET CURL::libcurl) + message(FATAL_ERROR "CURL::libcurl target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(ext_http_curl_test ${INSTALL_TEST_SRC_DIR}/test_ext_http_curl.cc) +target_link_libraries( + ext_http_curl_test PRIVATE opentelemetry-cpp::http_client_curl GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(ext_http_curl_test) diff --git a/install/test/cmake/component_tests/sdk/CMakeLists.txt b/install/test/cmake/component_tests/sdk/CMakeLists.txt new file mode 100644 index 0000000000..9dd828b65c --- /dev/null +++ b/install/test/cmake/component_tests/sdk/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +project(opentelemetry-cpp-sdk-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS sdk) + +if(NOT TARGET Threads::Threads) + message(FATAL_ERROR "Threads::Threads target not found") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(sdk_test ${INSTALL_TEST_SRC_DIR}/test_sdk.cc) +target_link_libraries( + sdk_test + PRIVATE opentelemetry-cpp::api + opentelemetry-cpp::sdk + opentelemetry-cpp::version + opentelemetry-cpp::common + opentelemetry-cpp::resources + opentelemetry-cpp::trace + opentelemetry-cpp::metrics + opentelemetry-cpp::logs + GTest::gtest + GTest::gtest_main) + +gtest_discover_tests(sdk_test) diff --git a/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt b/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt new file mode 100644 index 0000000000..34187da294 --- /dev/null +++ b/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) +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") +endif() + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(shims_opentracing_test + ${INSTALL_TEST_SRC_DIR}/test_shims_opentracing.cc) +target_link_libraries( + shims_opentracing_test PRIVATE opentelemetry-cpp::opentracing_shim + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(shims_opentracing_test) diff --git a/install/test/cmake/package_test/CMakeLists.txt b/install/test/cmake/package_test/CMakeLists.txt new file mode 100644 index 0000000000..b14c91bffb --- /dev/null +++ b/install/test/cmake/package_test/CMakeLists.txt @@ -0,0 +1,78 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-full-package-install-test LANGUAGES CXX) + +if(NOT DEFINED INSTALL_TEST_SRC_DIR) + message( + FATAL_ERROR + "INSTALL_TEST_SRC_DIR must be defined when running cmake on this test project" + ) +endif() + +find_package(opentelemetry-cpp CONFIG REQUIRED) + +# Test that the required OPENTELEMETRY_CPP_* variables are set + +if(NOT OPENTELEMETRY_CPP_INCLUDE_DIRS) + message(FATAL_ERROR "OPENTELEMETRY_CPP_INCLUDE_DIRS is empty") +endif() + +if(NOT OPENTELEMETRY_CPP_LIBRARY_DIRS) + message(FATAL_ERROR "OPENTELEMETRY_CPP_LIBRARY_DIRS is empty") +endif() + +if(NOT OPENTELEMETRY_CPP_LIBRARIES) + message(FATAL_ERROR "OPENTELEMETRY_CPP_LIBRARIES is empty") +endif() + +if(NOT OPENTELEMETRY_CPP_FOUND) + message(FATAL_ERROR "OPENTELEMETRY_CPP_FOUND is not set") +endif() + +if(NOT OPENTELEMETRY_ABI_VERSION_NO) + message(FATAL_ERROR "OPENTELEMETRY_ABI_VERSION_NO is empty") +endif() + +if(NOT OPENTELEMETRY_VERSION) + message(FATAL_ERROR "OPENTELEMETRY_VERSION is empty") +endif() + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "calling find_package must import the components and set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) + message(FATAL_ERROR "OPENTELEMETRY_CPP_COMPONENTS_INSTALLED is empty") +endif() + +if(NOT INSTALL_TEST_COMPONENTS) + message(FATAL_ERROR "INSTALL_TEST_COMPONENTS is empty") +endif() + +message( + STATUS + "Testing the full package install on components = ${INSTALL_TEST_COMPONENTS}" +) + +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(full_test) + +foreach(component IN LISTS INSTALL_TEST_COMPONENTS) + message(STATUS "Adding test source for component ${component}") + target_sources(full_test + PRIVATE "${INSTALL_TEST_SRC_DIR}/test_${component}.cc") +endforeach() + +target_include_directories(full_test PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) +target_link_libraries(full_test PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES} + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(full_test) diff --git a/install/test/cmake/usage_tests/missing_components/CMakeLists.txt b/install/test/cmake/usage_tests/missing_components/CMakeLists.txt new file mode 100644 index 0000000000..c93d558c8a --- /dev/null +++ b/install/test/cmake/usage_tests/missing_components/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) + +# Any missing component dependencies must be implicitly resolved. This tests +# implicitly resolves the sdk component dependency +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api + exporters_in_memory) + +if(NOT OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_exporters_in_memory_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_in_memory_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::api) + message(FATAL_ERROR "opentelemetry-cpp::api target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::sdk) + message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::in_memory_span_exporter) + message( + FATAL_ERROR "opentelemetry-cpp::in_memory_span_exporter target not found") +endif() diff --git a/install/test/cmake/usage_tests/no_components/CMakeLists.txt b/install/test/cmake/usage_tests/no_components/CMakeLists.txt new file mode 100644 index 0000000000..9d9521ad79 --- /dev/null +++ b/install/test/cmake/usage_tests/no_components/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) + +# specifying no components must import all installed components +find_package(opentelemetry-cpp CONFIG REQUIRED) + +if(NOT OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::api) + message(FATAL_ERROR "opentelemetry-cpp::api target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::sdk) + message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::ostream_log_record_exporter) + message( + FATAL_ERROR + "opentelemetry-cpp::ostream_log_record_exporter target not found") +endif() diff --git a/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt new file mode 100644 index 0000000000..0331e97046 --- /dev/null +++ b/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) + +# components not provided in order of dependency must be imported in the correct +# order without error +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_ostream api + sdk) + +if(NOT OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_exporters_ostream_FOUND) + message( + FATAL_ERROR + "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_ostream_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::api) + message(FATAL_ERROR "opentelemetry-cpp::api target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::sdk) + message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") +endif() + +if(NOT TARGET opentelemetry-cpp::ostream_log_record_exporter) + message( + FATAL_ERROR + "opentelemetry-cpp::ostream_log_record_exporter target not found") +endif() diff --git a/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt new file mode 100644 index 0000000000..6c9bea709c --- /dev/null +++ b/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.10) + +project(opentelemetry-cpp-unsupported-components-install-test LANGUAGES CXX) + +# request an unsupported/unknown component (without the REQUIRED arg) +find_package(opentelemetry-cpp CONFIG COMPONENTS api an_unknown_component) + +if(OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "calling find_package with an unsuported component should not set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "calling find_package with an unsupported component should not set opentelemetry-cpp_FOUND" + ) +endif() diff --git a/install/test/src/test_api.cc b/install/test/src/test_api.cc new file mode 100644 index 0000000000..6fc88663f5 --- /dev/null +++ b/install/test/src/test_api.cc @@ -0,0 +1,91 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +TEST(ApiInstallTest, VersionCheck) +{ + EXPECT_GE(OPENTELEMETRY_VERSION_MAJOR, 0); + EXPECT_GE(OPENTELEMETRY_VERSION_MINOR, 0); + EXPECT_GE(OPENTELEMETRY_VERSION_PATCH, 0); + EXPECT_NE(OPENTELEMETRY_VERSION, "not a version"); +} + +TEST(ApiInstallTest, TraceApiCheck) +{ + auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + ASSERT_TRUE(provider != nullptr); + + auto tracer = provider->GetTracer("test-tracer"); + ASSERT_TRUE(tracer != nullptr); + + auto span = tracer->StartSpan("test-span"); + ASSERT_TRUE(span != nullptr); + + auto scope = opentelemetry::trace::Tracer::WithActiveSpan(span); + span->AddEvent("test-event"); + span->SetAttribute("test-attribute", "test-value"); + span->SetStatus(opentelemetry::trace::StatusCode::kOk, "test-status"); + span->End(); +} + +TEST(ApiInstallTest, LogsApiCheck) +{ + auto provider = opentelemetry::logs::Provider::GetLoggerProvider(); + ASSERT_TRUE(provider != nullptr); + + auto logger = provider->GetLogger("test-logger"); + ASSERT_TRUE(logger != nullptr); + + auto record = logger->CreateLogRecord(); + ASSERT_TRUE(record != nullptr); + record->SetSeverity(opentelemetry::logs::Severity::kInfo); + record->SetBody("test-body"); + record->SetAttribute("test-attribute", "test-value"); + logger->EmitLogRecord(std::move(record)); +} + +TEST(ApiInstallTest, MetricsApiCheck) +{ + auto provider = opentelemetry::metrics::Provider::GetMeterProvider(); + ASSERT_TRUE(provider != nullptr); + + auto meter = provider->GetMeter("test-meter"); + ASSERT_TRUE(meter != nullptr); + + auto counter = meter->CreateUInt64Counter("test-counter"); + ASSERT_TRUE(counter != nullptr); + counter->Add(1, {{"test-attribute", "test-value"}}); + + auto histogram = meter->CreateDoubleHistogram("test-histogram"); + ASSERT_TRUE(histogram != nullptr); + histogram->Record(1, {{"test-attribute", "test-value"}}, + opentelemetry::context::RuntimeContext::GetCurrent()); + + auto async_gauge = meter->CreateDoubleObservableGauge("test-gauge"); + ASSERT_TRUE(async_gauge != nullptr); + + auto async_counter = meter->CreateDoubleObservableCounter("test-async-counter"); + ASSERT_TRUE(async_counter != nullptr); + + auto async_updown_counter = + meter->CreateInt64ObservableUpDownCounter("test-async-updown-counter"); + ASSERT_TRUE(async_updown_counter != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_exporters_elasticsearch.cc b/install/test/src/test_exporters_elasticsearch.cc new file mode 100644 index 0000000000..f18d59cf1e --- /dev/null +++ b/install/test/src/test_exporters_elasticsearch.cc @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include + +namespace logs_exporter = opentelemetry::exporter::logs; +namespace sdklogs = opentelemetry::sdk::logs; + +TEST(ExportersElasticSearchInstall, ElasticsearchLogRecordExporter) +{ + logs_exporter::ElasticsearchExporterOptions options; + + auto exporter = std::unique_ptr( + new logs_exporter::ElasticsearchLogRecordExporter(options)); + + ASSERT_TRUE(exporter != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_exporters_etw.cc b/install/test/src/test_exporters_etw.cc new file mode 100644 index 0000000000..12a5d292c7 --- /dev/null +++ b/install/test/src/test_exporters_etw.cc @@ -0,0 +1,65 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef _WIN32 + +# include +# include +# include + +# include "opentelemetry/exporters/etw/etw_logger_exporter.h" +# include "opentelemetry/exporters/etw/etw_tracer_exporter.h" +# include "opentelemetry/sdk/trace/sampler.h" +# include "opentelemetry/sdk/trace/simple_processor.h" + +using namespace OPENTELEMETRY_NAMESPACE; + +using namespace opentelemetry::exporter::etw; + +TEST(ExportersEtwInstall, LoggerProvider) +{ + std::string providerName = "OpenTelemetry-ETW-TLD"; + exporter::etw::LoggerProvider lp; + + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp.GetLogger(providerName, schema_url); + ASSERT_TRUE(logger != nullptr); + + // Log attributes + Properties attribs = {{"attrib1", 1}, {"attrib2", 2}}; + EXPECT_NO_THROW(logger->EmitLogRecord(opentelemetry::logs::Severity::kDebug, + opentelemetry::common::MakeAttributes(attribs))); +} + +TEST(ExportersEtwInstall, TracerProvider) +{ + std::string providerName = "OpenTelemetry-ETW-TLD"; + exporter::etw::TracerProvider tp({{"enableTraceId", false}, + {"enableSpanId", false}, + {"enableActivityId", false}, + {"enableActivityTracking", true}, + {"enableRelatedActivityId", false}, + {"enableAutoParent", false}}); + auto tracer = tp.GetTracer(providerName); + ASSERT_TRUE(tracer != nullptr); + { + auto aSpan = tracer->StartSpan("A.min"); + auto aScope = tracer->WithActiveSpan(aSpan); + { + auto bSpan = tracer->StartSpan("B.min"); + auto bScope = tracer->WithActiveSpan(bSpan); + { + auto cSpan = tracer->StartSpan("C.min"); + auto cScope = tracer->WithActiveSpan(cSpan); + EXPECT_NO_THROW(cSpan->End()); + } + EXPECT_NO_THROW(bSpan->End()); + } + EXPECT_NO_THROW(aSpan->End()); + } +# if OPENTELEMETRY_ABI_VERSION_NO == 1 + EXPECT_NO_THROW(tracer->CloseWithMicroseconds(0)); +# endif +} + +#endif // _WIN32 \ No newline at end of file diff --git a/install/test/src/test_exporters_in_memory.cc b/install/test/src/test_exporters_in_memory.cc new file mode 100644 index 0000000000..660dbd6f45 --- /dev/null +++ b/install/test/src/test_exporters_in_memory.cc @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include +#include + +using namespace opentelemetry::exporter::memory; + +TEST(ExportersInMemoryInstall, InMemorySpanExporter) +{ + auto data = std::shared_ptr{new InMemorySpanData(10)}; + auto exporter = InMemorySpanExporterFactory::Create(data); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOstreamInstall, InMemoryMetricExporter) +{ + auto data = std::shared_ptr{new SimpleAggregateInMemoryMetricData()}; + auto exporter = InMemoryMetricExporterFactory::Create(data); + ASSERT_TRUE(exporter != nullptr); +} diff --git a/install/test/src/test_exporters_ostream.cc b/install/test/src/test_exporters_ostream.cc new file mode 100644 index 0000000000..ef59856727 --- /dev/null +++ b/install/test/src/test_exporters_ostream.cc @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include + +TEST(ExportersOstreamInstall, OStreamSpanExporter) +{ + auto exporter = opentelemetry::exporter::trace::OStreamSpanExporterFactory::Create(); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOstreamInstall, OStreamMetricExporter) +{ + auto exporter = opentelemetry::exporter::metrics::OStreamMetricExporterFactory::Create(); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOstreamInstall, OStreamLogRecordExporter) +{ + auto exporter = opentelemetry::exporter::logs::OStreamLogRecordExporterFactory::Create(); + ASSERT_TRUE(exporter != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_exporters_otlp_common.cc b/install/test/src/test_exporters_otlp_common.cc new file mode 100644 index 0000000000..da4e2550d9 --- /dev/null +++ b/install/test/src/test_exporters_otlp_common.cc @@ -0,0 +1,161 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/proto/metrics/v1/metrics.pb.h" +#include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +#include + +#include +#include +#include +#include + +namespace nostd = opentelemetry::nostd; +namespace resource_sdk = opentelemetry::sdk::resource; +namespace proto = opentelemetry::proto; +namespace metrics_sdk = opentelemetry::sdk::metrics; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace logs_sdk = opentelemetry::sdk::logs; +namespace otlp_exporter = opentelemetry::exporter::otlp; + +static metrics_sdk::MetricData CreateSumAggregationData() +{ + metrics_sdk::MetricData data; + data.start_ts = opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()); + metrics_sdk::InstrumentDescriptor inst_desc = {"Counter", "desc", "unit", + metrics_sdk::InstrumentType::kCounter, + metrics_sdk::InstrumentValueType::kDouble}; + metrics_sdk::SumPointData s_data_1, s_data_2; + s_data_1.value_ = 10.2; + s_data_2.value_ = 20.2; + + data.aggregation_temporality = metrics_sdk::AggregationTemporality::kCumulative; + data.end_ts = opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()); + data.instrument_descriptor = inst_desc; + metrics_sdk::PointDataAttributes point_data_attr_1, point_data_attr_2; + point_data_attr_1.attributes = {{"k1", "v1"}}; + point_data_attr_1.point_data = s_data_1; + + point_data_attr_2.attributes = {{"k2", "v2"}}; + point_data_attr_2.point_data = s_data_2; + std::vector point_data_attr; + point_data_attr.push_back(point_data_attr_1); + point_data_attr.push_back(point_data_attr_2); + data.point_data_attr_ = std::move(point_data_attr); + return data; +} + +TEST(ExportersOtlpCommon, OtlpSpanRecordable) +{ + auto resource = resource_sdk::Resource::Create({{"service.name", "one"}}); + auto scope = trace_sdk::InstrumentationScope::Create("one", "1", "scope_schema", + {{"scope_key", "scope_value"}}); + ASSERT_TRUE(scope != nullptr); + + auto span_recordable = std::unique_ptr(new otlp_exporter::OtlpRecordable); + ASSERT_TRUE(span_recordable != nullptr); + span_recordable->SetResource(resource); + span_recordable->SetInstrumentationScope(*scope); + span_recordable->SetAttribute("test", "test"); + span_recordable->SetName("test-name"); + + proto::collector::trace::v1::ExportTraceServiceRequest request; + std::vector> spans; + spans.push_back(std::move(span_recordable)); + const nostd::span, 1> spans_span(spans.data(), 1); + otlp_exporter::OtlpRecordableUtils::PopulateRequest(spans_span, &request); + + ASSERT_EQ(request.resource_spans().size(), 1); + + auto resource_spans = request.resource_spans().at(0); + + ASSERT_EQ(resource_spans.scope_spans().size(), 1); + + auto spans_proto = resource_spans.scope_spans().at(0).spans(); + auto &span = spans_proto.at(0); + + EXPECT_EQ(span.name(), "test-name"); +} + +TEST(ExportersOtlpCommon, OtlpLogRecordable) +{ + auto resource = resource_sdk::Resource::Create({{"service.name", "one"}}); + auto scope = trace_sdk::InstrumentationScope::Create("one", "1", "scope_schema", + {{"scope_key", "scope_value"}}); + ASSERT_TRUE(scope != nullptr); + + auto logs_recordable = + std::unique_ptr(new otlp_exporter::OtlpLogRecordable); + ASSERT_TRUE(logs_recordable != nullptr); + + logs_recordable->SetResource(resource); + logs_recordable->SetInstrumentationScope(*scope); + logs_recordable->SetAttribute("test", "test"); + logs_recordable->SetBody("testing 123"); + logs_recordable->SetSeverity(opentelemetry::logs::Severity::kInfo); + + std::vector> logs; + logs.push_back(std::move(logs_recordable)); + + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request; + const opentelemetry::nostd::span> logs_span( + logs.data(), 1); + + otlp_exporter::OtlpRecordableUtils::PopulateRequest(logs_span, &request); + ASSERT_EQ(request.resource_logs().size(), 1); + auto logs_proto = request.resource_logs().at(0).scope_logs(); + auto log_records_proto = logs_proto.at(0).log_records(); + + ASSERT_EQ(log_records_proto.size(), 1); + auto &log = log_records_proto.at(0); + EXPECT_EQ(log.body().string_value(), "testing 123"); +} + +TEST(ExportersOtlpCommon, ExportMetricsServiceRequest) +{ + const auto resource = resource_sdk::Resource::Create({{"service.name", "test_service_name"}}, + "resource_schema_url"); + const auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( + "scope_name", "scope_version", "scope_schema_url", {{"scope_key", "scope_value"}}); + + metrics_sdk::ScopeMetrics scope_metrics{scope.get(), CreateSumAggregationData()}; + metrics_sdk::ResourceMetrics resource_metrics{&resource, scope_metrics}; + + proto::collector::metrics::v1::ExportMetricsServiceRequest request_proto; + otlp_exporter::OtlpMetricUtils::PopulateRequest(resource_metrics, &request_proto); + + ASSERT_EQ(1, request_proto.resource_metrics_size()); + const auto &resource_metrics_proto = request_proto.resource_metrics(0); + EXPECT_EQ("resource_schema_url", resource_metrics_proto.schema_url()); + + ASSERT_EQ(1, resource_metrics_proto.scope_metrics_size()); + const auto &scope_metrics_proto = resource_metrics_proto.scope_metrics(0); + EXPECT_EQ("scope_schema_url", scope_metrics_proto.schema_url()); + + ASSERT_EQ(1, scope_metrics_proto.metrics_size()); + const auto &metric_proto = scope_metrics_proto.metrics(0); + EXPECT_EQ("Counter", metric_proto.name()); + + const auto &scope_proto = scope_metrics_proto.scope(); + EXPECT_EQ("scope_name", scope_proto.name()); + EXPECT_EQ("scope_version", scope_proto.version()); + + ASSERT_EQ(1, scope_proto.attributes_size()); + const auto &scope_attributes_proto = scope_proto.attributes(0); + EXPECT_EQ("scope_key", scope_attributes_proto.key()); + EXPECT_EQ("scope_value", scope_attributes_proto.value().string_value()); +} \ No newline at end of file diff --git a/install/test/src/test_exporters_otlp_file.cc b/install/test/src/test_exporters_otlp_file.cc new file mode 100644 index 0000000000..11627f5503 --- /dev/null +++ b/install/test/src/test_exporters_otlp_file.cc @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include + +#include +#include +#include +#include + +TEST(ExportersOtlpFileInstall, OtlpFileExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpFileExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpFileExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpFileInstall, OtlpFileLogRecordExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpFileLogRecordExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpFileLogRecordExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpFileInstall, OtlpFileMetricExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpFileMetricExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpFileMetricExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} diff --git a/install/test/src/test_exporters_otlp_grpc.cc b/install/test/src/test_exporters_otlp_grpc.cc new file mode 100644 index 0000000000..6e32c68a23 --- /dev/null +++ b/install/test/src/test_exporters_otlp_grpc.cc @@ -0,0 +1,42 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +TEST(ExportersOtlpGrpcInstall, OtlpGrpcClient) +{ + auto options = opentelemetry::exporter::otlp::OtlpGrpcExporterOptions(); + auto client = opentelemetry::exporter::otlp::OtlpGrpcClientFactory::Create(options); + ASSERT_TRUE(client != nullptr); +} + +TEST(ExportersOtlpGrpcInstall, OtlpGrpcExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpGrpcExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpGrpcExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpGrpcInstall, OtlpGrpcLogRecordExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpGrpcInstall, OtlpGrpcMetricExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpGrpcMetricExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpGrpcMetricExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} diff --git a/install/test/src/test_exporters_otlp_http.cc b/install/test/src/test_exporters_otlp_http.cc new file mode 100644 index 0000000000..441df255cc --- /dev/null +++ b/install/test/src/test_exporters_otlp_http.cc @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include + +#include +#include +#include +#include + +TEST(ExportersOtlpHttpInstall, OtlpHttpExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpHttpExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpHttpExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpHttpInstall, OtlpHttpLogRecordExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} + +TEST(ExportersOtlpHttpInstall, OtlpHttpMetricExporter) +{ + auto options = opentelemetry::exporter::otlp::OtlpHttpMetricExporterOptions(); + auto exporter = opentelemetry::exporter::otlp::OtlpHttpMetricExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} diff --git a/install/test/src/test_exporters_prometheus.cc b/install/test/src/test_exporters_prometheus.cc new file mode 100644 index 0000000000..1def1417f9 --- /dev/null +++ b/install/test/src/test_exporters_prometheus.cc @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include + +TEST(ExportersPrometheusInstall, PrometheusExporter) +{ + auto options = opentelemetry::exporter::metrics::PrometheusExporterOptions(); + auto exporter = opentelemetry::exporter::metrics::PrometheusExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_exporters_zipkin.cc b/install/test/src/test_exporters_zipkin.cc new file mode 100644 index 0000000000..1a09fe6143 --- /dev/null +++ b/install/test/src/test_exporters_zipkin.cc @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include + +TEST(ExportersZipkinInstall, ZipkinExporter) +{ + auto options = opentelemetry::exporter::zipkin::ZipkinExporterOptions(); + auto exporter = opentelemetry::exporter::zipkin::ZipkinExporterFactory::Create(options); + ASSERT_TRUE(exporter != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_ext_common.cc b/install/test/src/test_ext_common.cc new file mode 100644 index 0000000000..cd4b83dfaf --- /dev/null +++ b/install/test/src/test_ext_common.cc @@ -0,0 +1,12 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include + +TEST(ExtCommonInstall, UrlParser) +{ + auto url_parser = opentelemetry::ext::http::common::UrlParser("www.opentelemetry.io"); + ASSERT_TRUE(url_parser.success_); +} \ No newline at end of file diff --git a/install/test/src/test_ext_dll.cc b/install/test/src/test_ext_dll.cc new file mode 100644 index 0000000000..ed8c1b9941 --- /dev/null +++ b/install/test/src/test_ext_dll.cc @@ -0,0 +1,116 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace nostd = opentelemetry::nostd; +namespace version_sdk = opentelemetry::sdk::version; +namespace common = opentelemetry::common; +namespace common_sdk = opentelemetry::sdk::common; +namespace scope_sdk = opentelemetry::sdk::instrumentationscope; +namespace resource_sdk = opentelemetry::sdk::resource; +namespace metrics_sdk = opentelemetry::sdk::metrics; +namespace metrics = opentelemetry::metrics; +namespace logs_sdk = opentelemetry::sdk::logs; +namespace logs = opentelemetry::logs; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace trace = opentelemetry::trace; + +TEST(ExtDllInstallTest, LoggerProviderCheck) +{ + { + auto exporter = std::unique_ptr( + new opentelemetry::exporter::logs::OStreamLogRecordExporter()); + auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); + auto sdk_provider = logs_sdk::LoggerProviderFactory::Create(std::move(processor)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + logs::Provider::SetLoggerProvider(new_provider); + } + + auto provider = opentelemetry::logs::Provider::GetLoggerProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto logger = provider->GetLogger("test-logger"); + ASSERT_TRUE(logger != nullptr); + logger->Info("test-message"); + } +} + +TEST(ExtDllInstallTest, TracerProviderCheck) +{ + { + auto exporter = opentelemetry::exporter::trace::OStreamSpanExporterFactory::Create(); + auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); + auto sdk_provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + trace::Provider::SetTracerProvider(new_provider); + } + + auto provider = trace::Provider::GetTracerProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto tracer = provider->GetTracer("test-tracer"); + ASSERT_TRUE(tracer != nullptr); + auto span = tracer->StartSpan("test-span"); + ASSERT_TRUE(span != nullptr); + span->End(); + } +} + +TEST(ExtDllInstallTest, MeterProviderCheck) +{ + { + auto exporter = opentelemetry::exporter::metrics::OStreamMetricExporterFactory::Create(); + auto reader = metrics_sdk::PeriodicExportingMetricReaderFactory::Create( + std::move(exporter), metrics_sdk::PeriodicExportingMetricReaderOptions{}); + auto context = metrics_sdk::MeterContextFactory::Create(); + auto sdk_provider = metrics_sdk::MeterProviderFactory::Create(std::move(context)); + sdk_provider->AddMetricReader(std::move(reader)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + metrics::Provider::SetMeterProvider(new_provider); + } + + auto provider = metrics::Provider::GetMeterProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto meter = provider->GetMeter("test-meter"); + ASSERT_TRUE(meter != nullptr); + auto counter = meter->CreateUInt64Counter("test-counter"); + ASSERT_TRUE(counter != nullptr); + counter->Add(1); + } +} \ No newline at end of file diff --git a/install/test/src/test_ext_http_curl.cc b/install/test/src/test_ext_http_curl.cc new file mode 100644 index 0000000000..799ee4732a --- /dev/null +++ b/install/test/src/test_ext_http_curl.cc @@ -0,0 +1,13 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include + +TEST(ExtHttpCurlInstall, HttpClient) +{ + auto client = opentelemetry::ext::http::client::HttpClientFactory::Create(); + ASSERT_TRUE(client != nullptr); +} \ No newline at end of file diff --git a/install/test/src/test_sdk.cc b/install/test/src/test_sdk.cc new file mode 100644 index 0000000000..13c4d19245 --- /dev/null +++ b/install/test/src/test_sdk.cc @@ -0,0 +1,262 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace nostd = opentelemetry::nostd; +namespace version_sdk = opentelemetry::sdk::version; +namespace common = opentelemetry::common; +namespace common_sdk = opentelemetry::sdk::common; +namespace scope_sdk = opentelemetry::sdk::instrumentationscope; +namespace resource_sdk = opentelemetry::sdk::resource; +namespace metrics_sdk = opentelemetry::sdk::metrics; +namespace metrics = opentelemetry::metrics; +namespace logs_sdk = opentelemetry::sdk::logs; +namespace logs = opentelemetry::logs; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace trace = opentelemetry::trace; + +class NoopLogRecordable : public logs_sdk::Recordable +{ +public: + ~NoopLogRecordable() override = default; + void SetTimestamp(common::SystemTimestamp timestamp) noexcept override {} + void SetObservedTimestamp(common::SystemTimestamp timestamp) noexcept override {} + void SetSeverity(logs::Severity severity) noexcept override {} + void SetBody(const common::AttributeValue &message) noexcept override {} + void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept override + {} + void SetEventId(int64_t id, nostd::string_view name = {}) noexcept override {} + void SetTraceId(const trace::TraceId &trace_id) noexcept override {} + void SetSpanId(const trace::SpanId &span_id) noexcept override {} + void SetTraceFlags(const trace::TraceFlags &trace_flags) noexcept override {} + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override {} + void SetInstrumentationScope( + const scope_sdk::InstrumentationScope &instrumentation_scope) noexcept override + {} +}; + +class NoopLogRecordExporter : public logs_sdk::LogRecordExporter +{ +public: + ~NoopLogRecordExporter() override = default; + std::unique_ptr MakeRecordable() noexcept override + { + return std::move(std::unique_ptr{new NoopLogRecordable()}); + } + common_sdk::ExportResult Export( + const nostd::span> &records) noexcept override + { + return common_sdk::ExportResult::kSuccess; + } + bool ForceFlush( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } + bool Shutdown( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } +}; + +class NoopSpanRecordable : public trace_sdk::Recordable +{ +public: + ~NoopSpanRecordable() override = default; + void SetIdentity(const trace::SpanContext &span_context, + trace::SpanId parent_span_id) noexcept override + {} + void SetAttribute(nostd::string_view key, + const opentelemetry::common::AttributeValue &value) noexcept override + {} + void AddEvent(nostd::string_view name, + opentelemetry::common::SystemTimestamp timestamp, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override + {} + void AddLink(const trace::SpanContext &span_context, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override + {} + void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override {} + void SetName(nostd::string_view name) noexcept override {} + void SetSpanKind(trace::SpanKind span_kind) noexcept override {} + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override {} + void SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept override {} + void SetDuration(std::chrono::nanoseconds duration) noexcept override {} + void SetInstrumentationScope( + const scope_sdk::InstrumentationScope &instrumentation_scope) noexcept override + {} +}; + +class NoopSpanExporter : public trace_sdk::SpanExporter +{ +public: + ~NoopSpanExporter() override = default; + std::unique_ptr MakeRecordable() noexcept override + { + return std::move(std::unique_ptr{new NoopSpanRecordable()}); + } + common_sdk::ExportResult Export( + const nostd::span> &spans) noexcept override + { + return common_sdk::ExportResult::kSuccess; + } + bool ForceFlush( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } + bool Shutdown( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } +}; + +class NoopPushMetricExporter : public metrics_sdk::PushMetricExporter +{ +public: + ~NoopPushMetricExporter() override = default; + common_sdk::ExportResult Export( + const metrics_sdk::ResourceMetrics &resource_metrics) noexcept override + { + return common_sdk::ExportResult::kSuccess; + } + + metrics_sdk::AggregationTemporality GetAggregationTemporality( + metrics_sdk::InstrumentType instrument_type) const noexcept override + { + return metrics_sdk::AggregationTemporality::kCumulative; + } + + bool ForceFlush( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } + bool Shutdown( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override + { + return true; + } +}; + +TEST(SdkInstallTest, SdkVersionCheck) +{ + EXPECT_NE(OPENTELEMETRY_SDK_VERSION, "not a version"); + EXPECT_GE(version_sdk::major_version, 0); + EXPECT_GE(version_sdk::minor_version, 0); + EXPECT_GE(version_sdk::patch_version, 0); + EXPECT_NE(version_sdk::full_version, ""); + EXPECT_NE(version_sdk::short_version, ""); +} + +TEST(SdkInstallTest, ResourceDetectorCheck) +{ + auto resource = resource_sdk::Resource::GetDefault(); + resource_sdk::OTELResourceDetector detector; + resource.Merge(detector.Detect()); + resource_sdk::ResourceAttributes attributes = resource.GetAttributes(); + EXPECT_NE(attributes.size(), 0); +} + +TEST(SdkInstallTest, LoggerProviderCheck) +{ + { + auto exporter = nostd::unique_ptr(new NoopLogRecordExporter()); + auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); + auto sdk_provider = logs_sdk::LoggerProviderFactory::Create(std::move(processor)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + logs::Provider::SetLoggerProvider(new_provider); + } + + auto provider = opentelemetry::logs::Provider::GetLoggerProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto logger = provider->GetLogger("test-logger"); + ASSERT_TRUE(logger != nullptr); + logger->Info("test-message"); + } + auto sdk_provider = static_cast(provider.get()); + sdk_provider->ForceFlush(); +} + +TEST(SdkInstallTest, TracerProviderCheck) +{ + { + auto exporter = nostd::unique_ptr(new NoopSpanExporter()); + auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); + auto sdk_provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + trace::Provider::SetTracerProvider(new_provider); + } + + auto provider = trace::Provider::GetTracerProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto tracer = provider->GetTracer("test-tracer"); + ASSERT_TRUE(tracer != nullptr); + auto span = tracer->StartSpan("test-span"); + ASSERT_TRUE(span != nullptr); + span->End(); + } + auto sdk_provider = static_cast(provider.get()); + sdk_provider->ForceFlush(); +} + +TEST(SdkInstallTest, MeterProviderCheck) +{ + { + auto exporter = + nostd::unique_ptr(new NoopPushMetricExporter()); + auto reader = metrics_sdk::PeriodicExportingMetricReaderFactory::Create( + std::move(exporter), metrics_sdk::PeriodicExportingMetricReaderOptions{}); + auto context = metrics_sdk::MeterContextFactory::Create(); + auto sdk_provider = metrics_sdk::MeterProviderFactory::Create(std::move(context)); + sdk_provider->AddMetricReader(std::move(reader)); + nostd::shared_ptr new_provider{sdk_provider.release()}; + metrics::Provider::SetMeterProvider(new_provider); + } + + auto provider = metrics::Provider::GetMeterProvider(); + ASSERT_TRUE(provider != nullptr); + { + auto meter = provider->GetMeter("test-meter"); + ASSERT_TRUE(meter != nullptr); + auto counter = meter->CreateUInt64Counter("test-counter"); + ASSERT_TRUE(counter != nullptr); + counter->Add(1); + } + auto sdk_provider = static_cast(provider.get()); + sdk_provider->ForceFlush(); +} \ No newline at end of file diff --git a/install/test/src/test_shims_opentracing.cc b/install/test/src/test_shims_opentracing.cc new file mode 100644 index 0000000000..ddf037a308 --- /dev/null +++ b/install/test/src/test_shims_opentracing.cc @@ -0,0 +1,23 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include +#include +#include +#include +#include + +TEST(ShimsOpenTracingInstall, TracerShim) +{ + auto tracer_shim = opentelemetry::opentracingshim::TracerShim::createTracerShim(); + ASSERT_TRUE(tracer_shim != nullptr); + auto span_shim = tracer_shim->StartSpan("test"); + ASSERT_TRUE(span_shim != nullptr); + span_shim->Log({{"event", "test"}}); + span_shim->SetTag("test", "test"); + span_shim->SetBaggageItem("test", "test"); + span_shim->Finish(); + tracer_shim->Close(); +} \ No newline at end of file diff --git a/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index b77b9c1985..e1130b8fd7 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -30,16 +30,24 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS ${this_target} - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-shims_opentracing-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shims_opentracing) install( DIRECTORY include/opentelemetry/opentracingshim DESTINATION include/opentelemetry + COMPONENT shims_opentracing FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-shims_opentracing-target" + FILE "${PROJECT_NAME}-shims_opentracing-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT shims_opentracing) endif() if(BUILD_TESTING) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 90d07a984a..66b9b2544d 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -12,22 +12,32 @@ set_target_properties(opentelemetry_sdk PROPERTIES EXPORT_NAME sdk) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_sdk - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) install( DIRECTORY include/opentelemetry/ DESTINATION include/opentelemetry + COMPONENT sdk FILES_MATCHING PATTERN "*config.h") install( DIRECTORY include/opentelemetry/sdk DESTINATION include/opentelemetry + COMPONENT sdk FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-sdk-target" + FILE "${PROJECT_NAME}-sdk-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT sdk) + endif() add_subdirectory(src) diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index db36266a4f..c27e9ca483 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -18,17 +18,13 @@ target_link_libraries( opentelemetry_common PUBLIC opentelemetry_api opentelemetry_sdk Threads::Threads) -if(WITH_OTLP_GRPC) - target_link_libraries(opentelemetry_common PUBLIC absl::strings) -endif() - if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_common - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( common diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 178b28f830..ff7bd49344 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -37,10 +37,10 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_logs - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( logs "OpenTelemetry SDK - Logs" diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index f1ba16a116..8a7b801b77 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -45,10 +45,10 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_metrics - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( metrics "OpenTelemetry SDK - Metrics" diff --git a/sdk/src/resource/CMakeLists.txt b/sdk/src/resource/CMakeLists.txt index 7ccb9b491e..1dbfd1a993 100644 --- a/sdk/src/resource/CMakeLists.txt +++ b/sdk/src/resource/CMakeLists.txt @@ -15,10 +15,10 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_resources - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( resources "OpenTelemetry SDK - Resources" diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index b39663b419..4543521eda 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -37,10 +37,10 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_trace - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( trace "OpenTelemetry SDK - Trace" diff --git a/sdk/src/version/CMakeLists.txt b/sdk/src/version/CMakeLists.txt index 4818a4ec63..bbfd9a53b8 100644 --- a/sdk/src/version/CMakeLists.txt +++ b/sdk/src/version/CMakeLists.txt @@ -16,10 +16,10 @@ target_include_directories( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_version - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-sdk-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sdk) opentelemetry_add_pkgconfig( version "OpenTelemetry SDK - Version"