Skip to content

Commit b0fc083

Browse files
authored
[CONFIGURATION] File configuration - cmake build (#3655)
1 parent 0875ca1 commit b0fc083

28 files changed

+878
-46
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,45 @@ jobs:
182182
run: |
183183
(cd ./functional/otlp; ./run_test.sh)
184184
185+
cmake_clang_yaml_config:
186+
name: CMake clang 18 (maintainer mode, yaml config)
187+
runs-on: ubuntu-24.04
188+
env:
189+
CC: /usr/bin/clang-18
190+
CXX: /usr/bin/clang++-18
191+
CXX_STANDARD: '14'
192+
steps:
193+
- name: Harden the runner (Audit all outbound calls)
194+
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
195+
with:
196+
egress-policy: audit
197+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
198+
with:
199+
submodules: 'recursive'
200+
- name: setup
201+
run: |
202+
sudo -E ./ci/setup_ci_environment.sh
203+
- name: install dependencies
204+
run: |
205+
sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release
206+
- name: run cmake clang (maintainer mode, sync)
207+
run: |
208+
./ci/do_ci.sh cmake.maintainer.yaml.test
209+
- name: install shelltest
210+
run: sudo apt update && sudo apt-get install -y shelltestrunner
211+
- name: generate test cert
212+
env:
213+
CFSSL_VERSION: 1.6.3
214+
run: |
215+
sudo -E ./tools/setup-cfssl.sh
216+
(cd ./functional/cert; ./generate_cert.sh)
217+
- name: run otlp func test
218+
run: |
219+
(cd ./functional/otlp; ./run_test.sh)
220+
- name: run configuration func test
221+
run: |
222+
(cd ./functional/configuration; ./run_test.sh)
223+
185224
cmake_clang_maintainer_async_test:
186225
name: CMake clang 18 (maintainer mode, async)
187226
runs-on: ubuntu-24.04

.github/workflows/clang-tidy.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
matrix:
1818
include:
1919
- cmake_options: all-options-abiv1-preview
20-
warning_limit: 61
20+
warning_limit: 63
2121
- cmake_options: all-options-abiv2-preview
22-
warning_limit: 61
22+
warning_limit: 63
2323
steps:
2424
- name: Harden the runner (Audit all outbound calls)
2525
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
@@ -49,6 +49,12 @@ jobs:
4949
libgtest-dev \
5050
libbenchmark-dev
5151
52+
- name: Install rapidyaml
53+
run: |
54+
sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release --packages "ryml"
55+
56+
- name: Check clang-tidy
57+
run: |
5258
if ! command -v clang-tidy &> /dev/null; then
5359
echo "clang-tidy could not be found"
5460
exit 1

.github/workflows/iwyu.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ jobs:
5353
llvm-dev \
5454
libclang-dev \
5555
cmake
56+
57+
- name: Install rapidyaml
58+
run: |
59+
sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release --packages "ryml"
60+
5661
- name: Install include-what-you-use
5762
run: |
5863
sudo ./ci/install_iwyu.sh
64+
5965
- name: Prepare CMake
6066
env:
6167
CC: clang

.iwyu.imp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
{ "include": ["<bits/types/struct_tm.h>", "private", "<time.h>", "public"] },
1212
{ "include": ["<bits/types/struct_FILE.h>", "private", "<stdio.h>", "public"] },
1313

14+
# Work around for ryml
15+
{ "include": ["<c4/std/string.hpp>", "private", "<ryml_std.hpp>", "public"] },
16+
17+
{ "include": ["<c4/yml/node.hpp>", "private", "<ryml.hpp>", "public"] },
18+
{ "include": ["<c4/yml/parse.hpp>", "private", "<ryml.hpp>", "public"] },
19+
{ "include": ["<c4/yml/parse_engine.hpp>", "private", "<ryml.hpp>", "public"] },
20+
{ "include": ["<c4/yml/tree.hpp>", "private", "<ryml.hpp>", "public"] },
21+
{ "include": ["<c4/yml/event_handler_tree.hpp>", "private", "<ryml.hpp>", "public"] },
22+
{ "include": ["<c4/substr.hpp>", "private", "<ryml.hpp>", "public"] },
23+
{ "include": ["<c4/substr_fwd.hpp>", "private", "<ryml.hpp>", "public"] },
24+
1425
# Local opentelemetry-cpp style
1526

1627
# We prefer to include <gtest/gtest.h> for simplicity

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ endif()
6666
option(WITH_ABI_VERSION_1 "ABI version 1" ON)
6767
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)
6868

69+
option(WITH_CONFIGURATION "EXPERIMENTAL: YAML configuration file" OFF)
70+
6971
#
7072
# We do not want to have WITH_ABI_VERSION = "1" or "2", and instead prefer two
7173
# distinct flags, WITH_ABI_VERSION_1 and WITH_ABI_VERSION_2.
@@ -349,6 +351,14 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
349351
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/nlohmann-json.cmake")
350352
endif()
351353

354+
#
355+
# Do we need RapidYaml ?
356+
#
357+
358+
if((NOT WITH_API_ONLY) AND WITH_CONFIGURATION)
359+
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/ryml.cmake")
360+
endif()
361+
352362
#
353363
# Do we need OpenTracing ?
354364
#
@@ -499,6 +509,7 @@ message(STATUS "WITH_ELASTICSEARCH: ${WITH_ELASTICSEARCH}")
499509
message(STATUS "WITH_OPENTRACING: ${WITH_OPENTRACING}")
500510
message(STATUS "WITH_ETW: ${WITH_ETW}")
501511
message(STATUS "OPENTELEMETRY_BUILD_DLL: ${OPENTELEMETRY_BUILD_DLL}")
512+
message(STATUS "WITH_CONFIGURATION: ${WITH_CONFIGURATION}")
502513

503514
message(STATUS "---------------------------------------------")
504515
message(STATUS "feature preview options")
@@ -580,6 +591,9 @@ if(WITH_OPENTRACING)
580591
message(
581592
STATUS "opentracing-cpp: ${OpenTracing_VERSION} (${OpenTracing_PROVIDER})")
582593
endif()
594+
if(ryml_VERSION)
595+
message(STATUS "ryml: ${ryml_VERSION} (${ryml_PROVIDER})")
596+
endif()
583597
message(STATUS "---------------------------------------------")
584598

585599
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/otel-install-functions.cmake")

ci/do_ci.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,31 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
171171
eval "$MAKE_COMMAND"
172172
make test
173173
exit 0
174+
elif [[ "$1" == "cmake.maintainer.yaml.test" ]]; then
175+
cd "${BUILD_DIR}"
176+
rm -rf *
177+
cmake "${CMAKE_OPTIONS[@]}" \
178+
-DWITH_OTLP_HTTP=ON \
179+
-DWITH_OTLP_GRPC=ON \
180+
-DWITH_OTLP_FILE=ON \
181+
-DWITH_PROMETHEUS=ON \
182+
-DWITH_EXAMPLES=ON \
183+
-DWITH_EXAMPLES_HTTP=ON \
184+
-DWITH_ZIPKIN=ON \
185+
-DBUILD_W3CTRACECONTEXT_TEST=ON \
186+
-DWITH_ELASTICSEARCH=ON \
187+
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
188+
-DWITH_ASYNC_EXPORT_PREVIEW=OFF \
189+
-DOTELCPP_MAINTAINER_MODE=ON \
190+
-DWITH_NO_DEPRECATED_CODE=ON \
191+
-DWITH_OTLP_HTTP_COMPRESSION=ON \
192+
-DWITH_OTLP_RETRY_PREVIEW=ON \
193+
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
194+
-DWITH_CONFIGURATION=ON \
195+
"${SRC_DIR}"
196+
eval "$MAKE_COMMAND"
197+
make test
198+
exit 0
174199
elif [[ "$1" == "cmake.with_async_export.test" ]]; then
175200
cd "${BUILD_DIR}"
176201
rm -rf *

cmake/ryml.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Import the rapidyaml target (ryml::ryml).
5+
# 1. Find an installed ryml package
6+
# 2. Use FetchContent to fetch and build ryml from GitHub
7+
8+
find_package(ryml QUIET)
9+
set(ryml_PROVIDER "find_package")
10+
11+
if(NOT ryml_FOUND)
12+
FetchContent_Declare(
13+
"ryml"
14+
GIT_REPOSITORY "https://github.com/biojppm/rapidyaml.git"
15+
GIT_TAG "${ryml_GIT_TAG}"
16+
)
17+
set(ryml_PROVIDER "fetch_repository")
18+
19+
set(RYML_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
20+
set(RYML_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
21+
22+
FetchContent_MakeAvailable(ryml)
23+
24+
# Set the ryml_VERSION variable from the git tag.
25+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" ryml_VERSION "${ryml_GIT_TAG}")
26+
endif()
27+
28+
if(NOT TARGET ryml::ryml)
29+
message(FATAL_ERROR "The required ryml::ryml target was not imported")
30+
endif()

cmake/thirdparty-dependency-config.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(OTEL_THIRDPARTY_DEPENDENCIES_SUPPORTED
1616
gRPC
1717
prometheus-cpp
1818
OpenTracing
19+
ryml
1920
)
2021

2122
#-----------------------------------------------------------------------
@@ -26,7 +27,7 @@ set(OTEL_THIRDPARTY_DEPENDENCIES_SUPPORTED
2627
set(OTEL_Protobuf_TARGET_NAMESPACE "protobuf")
2728

2829
#-----------------------------------------------------------------------
29-
# Set the find_dependecy search mode - empty is default. Options: cmake default (empty string ""), "MODULE", or "CONFIG"
30+
# Set the find_dependency search mode - empty is default. Options: cmake default (empty string ""), "MODULE", or "CONFIG"
3031
# # set(OTEL_<dependency>_SEARCH_MODE "<search mode>")
3132
#-----------------------------------------------------------------------
3233
set(OTEL_Threads_SEARCH_MODE "")
@@ -37,6 +38,7 @@ set(OTEL_nlohmann_json_SEARCH_MODE "CONFIG")
3738
set(OTEL_gRPC_SEARCH_MODE "CONFIG")
3839
set(OTEL_prometheus-cpp_SEARCH_MODE "CONFIG")
3940
set(OTEL_OpenTracing_SEARCH_MODE "CONFIG")
41+
set(OTEL_ryml_SEARCH_MODE "")
4042

4143
# The search mode is set to "CONFIG" for Protobuf versions >= 3.22.0
4244
# to find Protobuf's abseil dependency properly until the FindProtobuf module is updated support the upstream protobuf-config.cmake.
@@ -45,4 +47,4 @@ if(DEFINED Protobuf_VERSION AND Protobuf_VERSION VERSION_GREATER_EQUAL 3.22.0)
4547
set(OTEL_Protobuf_SEARCH_MODE "CONFIG")
4648
else()
4749
set(OTEL_Protobuf_SEARCH_MODE "")
48-
endif()
50+
endif()

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ add_subdirectory(multi_processor)
3131
if(WITH_EXAMPLES_HTTP)
3232
add_subdirectory(http)
3333
endif()
34+
35+
if(WITH_CONFIGURATION)
36+
add_subdirectory(configuration)
37+
endif()
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5+
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
6+
endif()
7+
8+
add_executable(
9+
example_yaml
10+
main.cc
11+
custom_sampler.cc
12+
custom_sampler_builder.cc
13+
custom_span_exporter.cc
14+
custom_span_exporter_builder.cc
15+
custom_span_processor.cc
16+
custom_span_processor_builder.cc
17+
custom_push_metric_exporter.cc
18+
custom_push_metric_exporter_builder.cc
19+
custom_pull_metric_exporter.cc
20+
custom_pull_metric_exporter_builder.cc
21+
custom_log_record_exporter.cc
22+
custom_log_record_exporter_builder.cc
23+
custom_log_record_processor.cc
24+
custom_log_record_processor_builder.cc)
25+
26+
target_link_libraries(
27+
example_yaml ${CMAKE_THREAD_LIBS_INIT}
28+
PRIVATE common_metrics_foo_library
29+
common_logs_foo_library
30+
opentelemetry-cpp::ostream_span_exporter_builder
31+
opentelemetry-cpp::ostream_metrics_exporter_builder
32+
opentelemetry-cpp::ostream_log_record_exporter_builder)
33+
34+
if(WITH_OTLP_HTTP)
35+
add_definitions(-DOTEL_HAVE_OTLP_HTTP)
36+
target_link_libraries(
37+
example_yaml
38+
PRIVATE opentelemetry-cpp::otlp_http_exporter_builder
39+
opentelemetry-cpp::otlp_http_log_record_exporter_builder
40+
opentelemetry-cpp::otlp_http_metric_exporter_builder)
41+
endif()
42+
43+
if(WITH_OTLP_GRPC)
44+
add_definitions(-DOTEL_HAVE_OTLP_GRPC)
45+
target_link_libraries(
46+
example_yaml
47+
PRIVATE opentelemetry-cpp::otlp_grpc_exporter_builder
48+
opentelemetry-cpp::otlp_grpc_log_record_exporter_builder
49+
opentelemetry-cpp::otlp_grpc_metrics_exporter_builder)
50+
endif()
51+
52+
if(WITH_OTLP_FILE)
53+
add_definitions(-DOTEL_HAVE_OTLP_FILE)
54+
target_link_libraries(
55+
example_yaml
56+
PRIVATE opentelemetry-cpp::otlp_file_exporter_builder
57+
opentelemetry-cpp::otlp_file_log_record_exporter_builder
58+
opentelemetry-cpp::otlp_file_metric_exporter_builder)
59+
endif()
60+
61+
if(WITH_ZIPKIN)
62+
add_definitions(-DOTEL_HAVE_ZIPKIN)
63+
target_link_libraries(
64+
example_yaml PRIVATE opentelemetry-cpp::zipkin_trace_exporter_builder)
65+
endif()
66+
67+
if(WITH_PROMETHEUS)
68+
add_definitions(-DOTEL_HAVE_PROMETHEUS)
69+
target_link_libraries(example_yaml
70+
PRIVATE opentelemetry-cpp::prometheus_exporter_builder)
71+
endif()
72+
73+
if(DEFINED OPENTELEMETRY_BUILD_DLL)
74+
target_link_libraries(example_yaml
75+
PRIVATE opentelemetry-cpp::opentelemetry_cpp)
76+
else()
77+
target_link_libraries(
78+
example_yaml
79+
PRIVATE opentelemetry-cpp::configuration opentelemetry-cpp::common
80+
opentelemetry-cpp::trace opentelemetry-cpp::logs)
81+
endif()

0 commit comments

Comments
 (0)