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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/cmake_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ jobs:
run: |
sudo -E ./ci/setup_cmake.sh
conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
conan cache clean --source --build
- name: Run Tests (static libs)
env:
BUILD_SHARED_LIBS: 'OFF'
Expand Down Expand Up @@ -297,6 +298,7 @@ jobs:
run: |
sudo -E ./ci/setup_cmake.sh
conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
conan cache clean --source --build
- name: Run Tests (static libs)
env:
BUILD_SHARED_LIBS: 'OFF'
Expand Down Expand Up @@ -330,7 +332,9 @@ jobs:
./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=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
run: |
conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
conan cache clean --source --build
- name: Run Tests (static libs)
env:
BUILD_SHARED_LIBS: 'OFF'
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Increment the:

## [Unreleased]

* [TEST] Test examples in CI with CMake Part 1
[#3449](https://github.com/open-telemetry/opentelemetry-cpp/pull/3449)

## [1.21 2025-05-28]

* [BUILD] Remove WITH_ABSEIL
Expand Down
39 changes: 5 additions & 34 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,8 @@ switch ($action) {
if ($exit -ne 0) {
exit $exit
}
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
examples\simple\Debug\example_simple.exe
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
examples\metrics_simple\Debug\metrics_ostream_example.exe
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
examples\logs_simple\Debug\example_logs_simple.exe
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
Expand All @@ -115,23 +100,8 @@ switch ($action) {
if ($exit -ne 0) {
exit $exit
}
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
examples\simple\Debug\example_simple.exe
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
examples\metrics_simple\Debug\metrics_ostream_example.exe
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
examples\logs_simple\Debug\example_logs_simple.exe
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
Expand Down Expand Up @@ -277,6 +247,7 @@ switch ($action) {
if ($exit -ne 0) {
exit $exit
}
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
Expand Down Expand Up @@ -467,13 +438,13 @@ switch ($action) {
$CMAKE_OPTIONS = @(
"-DCMAKE_CXX_STANDARD=17",
"-DVCPKG_TARGET_TRIPLET=x64-windows",
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake",
"-DOPENTELEMETRY_BUILD_DLL=1"
)

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 `
Expand Down
5 changes: 5 additions & 0 deletions examples/batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ add_executable(batch_span_processor_example main.cc)
target_link_libraries(
batch_span_processor_example PRIVATE opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::trace)

if(BUILD_TESTING)
add_test(NAME examples.batch
COMMAND "$<TARGET_FILE:batch_span_processor_example>")
endif()
2 changes: 0 additions & 2 deletions examples/common/foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

add_library(common_foo_library foo_library.h foo_library.cc)

set_target_version(common_foo_library)

if(DEFINED OPENTELEMETRY_BUILD_DLL)
target_compile_definitions(common_foo_library
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
Expand Down
2 changes: 0 additions & 2 deletions examples/common/logs_foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

add_library(common_logs_foo_library foo_library.h foo_library.cc)

set_target_version(common_logs_foo_library)

if(DEFINED OPENTELEMETRY_BUILD_DLL)
target_compile_definitions(common_logs_foo_library
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
Expand Down
2 changes: 0 additions & 2 deletions examples/common/metrics_foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

add_library(common_metrics_foo_library foo_library.h foo_library.cc)

set_target_version(common_metrics_foo_library)

if(DEFINED OPENTELEMETRY_BUILD_DLL)
target_compile_definitions(common_metrics_foo_library
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
Expand Down
4 changes: 4 additions & 0 deletions examples/etw_threads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ add_executable(etw_threadpool main.cc)
target_link_libraries(
etw_threadpool PRIVATE Threads::Threads opentelemetry-cpp::api
opentelemetry-cpp::etw_exporter)

if(BUILD_TESTING)
add_test(NAME examples.etw_threads COMMAND "$<TARGET_FILE:etw_threadpool>")
endif()
23 changes: 19 additions & 4 deletions examples/grpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,35 @@ set(example_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/messages.pb.h")
set(example_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/messages.grpc.pb.cc")
set(example_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/messages.grpc.pb.h")

if(NOT TARGET gRPC::grpc_cpp_plugin)
message(
FATAL_ERROR
"gRPC::grpc_cpp_plugin target not found. Please ensure that gRPC is installed and found with find_package."
)
endif()

if(NOT DEFINED PROTOBUF_PROTOC_EXECUTABLE)
if(NOT TARGET protobuf::protoc)
message(
FATAL_ERROR
"protobuf::protoc target not found. Please ensure that Protobuf is installed and found with find_package."
)
endif()
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
endif()

add_custom_command(
OUTPUT "${example_proto_srcs}" "${example_proto_hdrs}" "${example_grpc_srcs}"
"${example_grpc_hdrs}"
COMMAND
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "--proto_path=${proto_file_path}"
"--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN_EXECUTABLE}" "${proto_file}")
"--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
"${proto_file}")

add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
${example_proto_srcs} ${example_proto_hdrs})

patch_protobuf_targets(example_grpc_proto)

# Disable include-what-you-use on generated code.
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")

Expand All @@ -45,5 +61,4 @@ foreach(_target client server)
target_link_libraries(
${_target} PRIVATE example_grpc_proto
opentelemetry-cpp::ostream_span_exporter)
patch_protobuf_targets(${_target})
endforeach()
2 changes: 1 addition & 1 deletion examples/grpc/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int argc, char **argv)
uint16_t port;
if (argc > 1)
{
port = atoi(argv[1]);
port = static_cast<uint16_t>(atoi(argv[1]));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int argc, char **argv)
uint16_t port;
if (argc > 1)
{
port = atoi(argv[1]);
port = static_cast<uint16_t>(atoi(argv[1]));
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions examples/logs_simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ else()
opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::ostream_log_record_exporter)
endif()

if(BUILD_TESTING)
add_test(NAME examples.logs_simple
COMMAND "$<TARGET_FILE:example_logs_simple>")
endif()
8 changes: 8 additions & 0 deletions examples/metrics_simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ else()
metrics_ostream_example PRIVATE opentelemetry-cpp::metrics
opentelemetry-cpp::ostream_metrics_exporter)
endif()

if(BUILD_TESTING)
add_test(NAME examples.metrics_simple
COMMAND "$<TARGET_FILE:metrics_ostream_example>")
# Disable the metrics_simple example test due to sporadic segfaults on Windows
# See https://github.com/open-telemetry/opentelemetry-cpp/issues/3458
set_tests_properties(examples.metrics_simple PROPERTIES DISABLED TRUE)
endif()
5 changes: 5 additions & 0 deletions examples/multi_processor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ target_link_libraries(
PRIVATE common_foo_library opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::in_memory_span_exporter)

if(BUILD_TESTING)
add_test(NAME examples.multi_processor
COMMAND "$<TARGET_FILE:example_multi_processor>")
endif()
5 changes: 5 additions & 0 deletions examples/multithreaded/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ add_executable(example_multithreaded main.cc)
target_link_libraries(
example_multithreaded PRIVATE opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter)

if(BUILD_TESTING)
add_test(NAME examples.multithreaded
COMMAND "$<TARGET_FILE:example_multithreaded>")
endif()
4 changes: 1 addition & 3 deletions examples/otlp/grpc_metric_main.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "grpcpp/grpcpp.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"

#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
Expand All @@ -18,6 +15,7 @@
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h"
#include "opentelemetry/sdk/metrics/view/view_factory.h"

#include <iostream>
#include <memory>
#include <thread>

Expand Down
9 changes: 9 additions & 0 deletions examples/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ add_subdirectory(load)
if(NOT OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS)
add_subdirectory(plugin)
endif()

if(BUILD_TESTING)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/load/empty_config.txt" "")
add_test(
NAME examples.plugin
COMMAND
"$<TARGET_FILE:load_plugin_example>" "$<TARGET_FILE:example_plugin>"
"${CMAKE_CURRENT_BINARY_DIR}/load/empty_config.txt")
endif()
4 changes: 4 additions & 0 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ else()
example_simple PRIVATE opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter)
endif()

if(BUILD_TESTING)
add_test(NAME examples.simple COMMAND "$<TARGET_FILE:example_simple>")
endif()
5 changes: 3 additions & 2 deletions ext/src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ set_target_properties(opentelemetry_cpp PROPERTIES EXPORT_NAME
opentelemetry_cpp)

target_link_libraries(
opentelemetry_cpp PRIVATE opentelemetry_trace
opentelemetry_exporter_ostream_span)
opentelemetry_cpp
PUBLIC opentelemetry_api
PRIVATE opentelemetry_trace opentelemetry_exporter_ostream_span)

target_include_directories(
opentelemetry_cpp
Expand Down
22 changes: 22 additions & 0 deletions install/test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,25 @@ foreach(component ${INSTALL_TEST_COMPONENTS})
NAME component-${component}-run-test
COMMAND ${CMAKE_BINARY_DIR}/build-${component}-test/${component}_test)
endforeach()

set(OPENTELEMETRY_CPP_EXAMPLES_SRC_DIR "${CMAKE_SOURCE_DIR}/../../../examples")

# Configure the examples with the installed package
add_test(
NAME examples-config-test
COMMAND
${CMAKE_COMMAND} --log-level=DEBUG -S ${CMAKE_SOURCE_DIR}/examples_test -B
examples-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
${INSTALL_TEST_CMAKE_OPTIONS}
"-DOPENTELEMETRY_CPP_EXAMPLES_SRC_DIR=${OPENTELEMETRY_CPP_EXAMPLES_SRC_DIR}"
)

# Build the examples with the installed package
add_test(NAME examples-build-test
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/examples-test
--parallel)

# Run the examples
add_test(NAME examples-run-test
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/examples-test
${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
59 changes: 59 additions & 0 deletions install/test/cmake/examples_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.14)

project(opentelemetry-cpp-examples-test LANGUAGES CXX)

if(NOT DEFINED OPENTELEMETRY_CPP_EXAMPLES_SRC_DIR)
message(
FATAL_ERROR
"OPENTELEMETRY_CPP_SRC_DIR must be defined when running cmake on this test project"
)
endif()

find_package(GTest CONFIG REQUIRED)
find_package(opentelemetry-cpp CONFIG REQUIRED)

if(NOT OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
message(
FATAL_ERROR
"OPENTELEMETRY_CPP_COMPONENTS_INSTALLED must be set when running cmake on this test project"
)
endif()

if("exporters_otlp_file" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_OTLP_FILE ON)
endif()

if("exporters_otlp_grpc" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_OTLP_GRPC ON)
endif()

if("exporters_otlp_http" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_OTLP_HTTP ON)
endif()

if("exporters_prometheus" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_PROMETHEUS ON)
endif()

if("exporters_zipkin" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_ZIPKIN ON)
endif()

if("exporters_etw" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_ETW ON)
endif()

if("ext_http_curl" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
set(WITH_EXAMPLES_HTTP ON)
endif()

set(BUILD_TESTING ON)

include(CTest)
include(GoogleTest)

add_subdirectory(${OPENTELEMETRY_CPP_EXAMPLES_SRC_DIR}
${CMAKE_CURRENT_BINARY_DIR}/examples)
Loading