From af81dddb1bef50ca11c48453283862725ec09c2b Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 13:31:22 -0700 Subject: [PATCH 01/28] add cmake components to group targets --- CMakeLists.txt | 11 -- INSTALL.md | 63 +++++++ api/CMakeLists.txt | 8 +- cmake/opentelemetry-cpp-config.cmake.in | 241 +++++++++++++++++------- cmake/opentelemetry-proto.cmake | 13 +- exporters/elasticsearch/CMakeLists.txt | 9 +- exporters/etw/CMakeLists.txt | 8 +- exporters/memory/CMakeLists.txt | 9 +- exporters/ostream/CMakeLists.txt | 47 ++--- exporters/otlp/CMakeLists.txt | 82 ++++++-- exporters/prometheus/CMakeLists.txt | 8 +- exporters/zipkin/CMakeLists.txt | 12 +- ext/CMakeLists.txt | 9 +- ext/src/dll/CMakeLists.txt | 3 +- ext/src/http/client/curl/CMakeLists.txt | 3 +- opentracing-shim/CMakeLists.txt | 8 +- sdk/CMakeLists.txt | 9 +- sdk/src/common/CMakeLists.txt | 2 +- sdk/src/logs/CMakeLists.txt | 2 +- sdk/src/metrics/CMakeLists.txt | 2 +- sdk/src/resource/CMakeLists.txt | 2 +- sdk/src/trace/CMakeLists.txt | 2 +- sdk/src/version/CMakeLists.txt | 2 +- 23 files changed, 411 insertions(+), 144 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 408ee43046..2fe237916d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -774,17 +774,6 @@ if(OPENTELEMETRY_INSTALL) "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - # Export all components - export( - EXPORT "${PROJECT_NAME}-target" - NAMESPACE "${PROJECT_NAME}::" - FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-target.cmake" - ) - install( - EXPORT "${PROJECT_NAME}-target" - NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - if(BUILD_PACKAGE) include(cmake/package.cmake) include(CPack) diff --git a/INSTALL.md b/INSTALL.md index b528181aa2..89fc8e0661 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -145,6 +145,69 @@ target_include_directories(foo PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) ``` +#### Using opentelemetry-cpp package components + +> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) + +The `opentelemetry-cpp` package includes components to enable selective inclusion of its CMake targets and their dependencies 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** | opentelemetry-cpp::ext | +| | opentelemetry-cpp::http_client_curl | +| | 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 78e97ad029..74c91c0eac 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -12,7 +12,7 @@ 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}) @@ -23,6 +23,12 @@ if(OPENTELEMETRY_INSTALL) 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}") + unset(TARGET_DEPS) endif() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 254bcc662b..d0fe97e0d4 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -22,35 +22,64 @@ # 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 +# +# This module includes the following components for use with `find_package(opentelemetry-cpp COMPONENTS ...)` +# +# COMPONENTS +# api +# sdk +# ext +# 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 +# opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext +# opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext (from 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 # # ============================================================================= @@ -68,6 +97,89 @@ set(OPENTELEMETRY_VERSION @PACKAGE_INIT@ # ############################################################################## +# List all possible opentelemetry-cpp component targets. Some may not be supported by this install + + +set(_OPENTELEMETRY_CPP_COMPONENTS + api + sdk + ext + 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) + +set(_OPENTELEMETRY_CPP_TARGETS + api + sdk + version + common + resources + trace + metrics + logs + ext + http_client_curl + in_memory_span_exporter + in_memory_metric_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 + zipkin_trace_exporter + opentracing_shim) + + +# ############################################################################## + +# Create the list of requested components. Either all installed or a set passed to find_package( opentelemetry-cpp COMPONENTS ...) + +set(_FIND_ALL_COMPONENTS TRUE) + +if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") + # if no components are requested then find all installed components + set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_OPENTELEMETRY_CPP_COMPONENTS}) +else() + set(_FIND_ALL_COMPONENTS FALSE) + # check that the requested components are valid and installed + + foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) + if(NOT ${_COMPONENT} IN_LIST _OPENTELEMETRY_CPP_COMPONENTS) + message(FATAL_ERROR "The `${_COMPONENT}` component is not a supported component of the opentelemetry-cpp package. Supported components include: ${_OPENTELEMETRY_CPP_COMPONENTS}") + endif() + endforeach() + + foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) + if(${_COMPONENT} IN_LIST opentelemetry-cpp_FIND_COMPONENTS) + list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) + endif() + endforeach() +endif() + +# _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS only contains valid components. However they may not all be installed in this package +# Find dependencies based on the requested components list. include(CMakeFindDependencyMacro) @@ -78,28 +190,45 @@ if(@WITH_ABSEIL@) endif() if(@WITH_OTLP_GRPC@) - find_dependency(gRPC) + if("exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(gRPC) + endif() endif() if("@OpenTracing_FOUND@") - find_dependency(OpenTracing) + if("shims_opentracing" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(OpenTracing) + endif() endif() if("@prometheus-cpp_FOUND@") - find_dependency(prometheus-cpp) + if("exporters_prometheus" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(prometheus-cpp) + endif() endif() if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") - find_dependency(Protobuf) + if( + "exporters_otlp_common" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_file" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR + "exporters_otlp_http" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS + ) + find_dependency(Protobuf) + endif() endif() if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) if("@CURL_FOUND@") - find_dependency(CURL) + if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(CURL) + endif() endif() if("@ZLIB_FOUND@") - find_dependency(ZLIB) + if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + find_dependency(ZLIB) + endif() endif() endif() @@ -114,41 +243,17 @@ 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") +# include the target files selected. + +foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-${_COMPONENT}-target.cmake") +endforeach() + +# Set OPENTELEMETRY_CPP_* variables to preserve legacy CMake style 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) + +foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) if(TARGET opentelemetry-cpp::${_TEST_TARGET}) list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET}) endif() diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 0ff346d249..d57a2a0c4c 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -369,12 +369,21 @@ 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}) + 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}) + endif() + install( DIRECTORY ${GENERATED_PROTOBUF_PATH}/opentelemetry DESTINATION include diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index e91b53f1c6..4ca61476b6 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -21,7 +21,7 @@ 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}) @@ -32,6 +32,13 @@ if(OPENTELEMETRY_INSTALL) 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}") + endif() if(BUILD_TESTING) diff --git a/exporters/etw/CMakeLists.txt b/exporters/etw/CMakeLists.txt index 947e390dd9..837b9f46a3 100644 --- a/exporters/etw/CMakeLists.txt +++ b/exporters/etw/CMakeLists.txt @@ -22,7 +22,7 @@ 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}) @@ -32,6 +32,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters 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}") endif() if(BUILD_TESTING) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 0738759a96..f15d58f514 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -36,7 +36,7 @@ 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}) @@ -46,6 +46,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters 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}") + endif() if(BUILD_TESTING) diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index e08d6592a3..b566a4f322 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,25 @@ 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}) install( - FILES - "include/opentelemetry/exporters/ostream/log_record_exporter.h" - "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" - DESTINATION include/opentelemetry/exporters/ostream) + DIRECTORY include/opentelemetry/exporters/ostream + DESTINATION include/opentelemetry/exporters + PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-exporters_ostream-target" + FILE "${PROJECT_NAME}-exporters_ostream-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif() if(BUILD_TESTING) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index cd4e1b62fa..512876aaec 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -55,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( @@ -72,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 @@ -89,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 @@ -105,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() @@ -134,7 +135,7 @@ if(WITH_OTLP_HTTP) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_HTTP_TARGETS opentelemetry_exporter_otlp_http_client) add_library( @@ -151,7 +152,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 @@ -168,7 +169,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 @@ -184,7 +186,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() @@ -211,7 +213,7 @@ if(WITH_OTLP_FILE) PUBLIC "$" "$") - list(APPEND OPENTELEMETRY_OTLP_TARGETS + list(APPEND OPENTELEMETRY_OTLP_FILE_TARGETS opentelemetry_exporter_otlp_file_client) add_library( @@ -228,7 +230,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 @@ -245,7 +247,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 @@ -261,7 +264,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() @@ -271,8 +274,8 @@ 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}) @@ -282,6 +285,57 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters 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}") + + 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}) + + 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}") + 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}) + + 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}") + 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}) + + 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}") + endif() endif() if(BUILD_TESTING) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 6c872be3ab..6dc392e42a 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -40,7 +40,7 @@ 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}) @@ -50,6 +50,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/exporters/ 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}") endif() if(BUILD_TESTING) diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 5944258ca3..6c2d635793 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,7 +25,7 @@ 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}) @@ -33,6 +36,13 @@ if(OPENTELEMETRY_INSTALL) 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}") + endif() if(BUILD_TESTING) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index bae59e3040..cfd298ea9d 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -13,7 +13,7 @@ target_link_libraries(opentelemetry_ext INTERFACE opentelemetry_api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_ext - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -23,6 +23,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry/ FILES_MATCHING PATTERN "*.h") + + install( + EXPORT "${PROJECT_NAME}-ext-target" + FILE "${PROJECT_NAME}-ext-target.cmake" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() add_subdirectory(src) diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index e6772b839f..653bc2b180 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -103,8 +103,9 @@ add_custom_command( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_cpp - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() diff --git a/ext/src/http/client/curl/CMakeLists.txt b/ext/src/http/client/curl/CMakeLists.txt index c812fcefbf..e1ed24a44f 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -48,8 +48,9 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_http_client_curl - EXPORT "${PROJECT_NAME}-target" + EXPORT "${PROJECT_NAME}-ext-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() diff --git a/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index b77b9c1985..494fd67267 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -30,7 +30,7 @@ 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}) @@ -40,6 +40,12 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry 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}") endif() if(BUILD_TESTING) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 90d07a984a..b063cf6548 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -12,7 +12,7 @@ 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}) @@ -28,6 +28,13 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include/opentelemetry 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}") + endif() add_subdirectory(src) diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index 16229e0820..500eb8e0bc 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -24,7 +24,7 @@ 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}) diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 71679a9a48..47fc1dd09c 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -35,7 +35,7 @@ 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}) diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index 15611d1cab..c0235bf622 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -43,7 +43,7 @@ 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}) diff --git a/sdk/src/resource/CMakeLists.txt b/sdk/src/resource/CMakeLists.txt index 7ccb9b491e..ac28033fcf 100644 --- a/sdk/src/resource/CMakeLists.txt +++ b/sdk/src/resource/CMakeLists.txt @@ -15,7 +15,7 @@ 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}) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index 939a6ed2bc..590ec78885 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -35,7 +35,7 @@ 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}) diff --git a/sdk/src/version/CMakeLists.txt b/sdk/src/version/CMakeLists.txt index 4818a4ec63..53ffdea436 100644 --- a/sdk/src/version/CMakeLists.txt +++ b/sdk/src/version/CMakeLists.txt @@ -16,7 +16,7 @@ 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}) From bd6685df00e694ff282e9185ed4801b6aedcc228 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 14:40:26 -0700 Subject: [PATCH 02/28] fix markdown lint errors --- INSTALL.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 89fc8e0661..9fc095e1f2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -147,9 +147,14 @@ target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) #### Using opentelemetry-cpp package components -> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) +> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. +> **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) -The `opentelemetry-cpp` package includes components to enable selective inclusion of its CMake targets and their dependencies 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`. +The `opentelemetry-cpp` package includes components to enable selective inclusion +of its CMake targets and their dependencies 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 @@ -164,7 +169,10 @@ find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api sdk exporters_otlp 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. + +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 | |----------------------------|---------------------------------------------------------------------------------------------------| @@ -205,9 +213,6 @@ The following table provides the mapping between components and targets. Compone | **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 From 4cef852ad75e72f267660faf1bada1203e165fa7 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 16:54:02 -0700 Subject: [PATCH 03/28] fix default case to include all components in the package --- cmake/opentelemetry-cpp-config.cmake.in | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index d0fe97e0d4..2b4c655f67 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -158,9 +158,20 @@ set(_OPENTELEMETRY_CPP_TARGETS set(_FIND_ALL_COMPONENTS TRUE) +set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") # if no components are requested then find all installed components - set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_OPENTELEMETRY_CPP_COMPONENTS}) + + set(_TARGET_FILES_DIR "${CMAKE_CURRENT_LIST_DIR}") + + foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) + set(_COMPONENT_TARGET_FILE "${_TARGET_FILES_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake") + if(EXISTS "${_COMPONENT_TARGET_FILE}") + list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) + endif() + endforeach() + else() set(_FIND_ALL_COMPONENTS FALSE) # check that the requested components are valid and installed From 80a3cb385db9e85ba13690229b112fb759ded56d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 23 Dec 2024 17:33:57 -0700 Subject: [PATCH 04/28] remove unused opentelemetry_ext dependency from the otlp grpc client --- exporters/otlp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 512876aaec..918feaeb97 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -38,7 +38,7 @@ 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++) From 6d6c2c935376a95a12d4b577dd2f34046837657d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 8 Jan 2025 12:37:31 -0700 Subject: [PATCH 05/28] the ext target is used by the grpc client but can be private --- exporters/otlp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 918feaeb97..d8ec497e2b 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -41,7 +41,7 @@ if(WITH_OTLP_GRPC) PUBLIC opentelemetry_sdk opentelemetry_common # gRPC::grpc++ must be linked before opentelemetry_proto_grpc. opentelemetry_proto_grpc - PRIVATE gRPC::grpc++) + PRIVATE gRPC::grpc++ opentelemetry_ext) get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++ INTERFACE_INCLUDE_DIRECTORIES) From 74d5f743db9ed77b89b9b6db1e33c712b2444f28 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 16 Feb 2025 20:36:37 -0700 Subject: [PATCH 06/28] adds the COMPONENT name to export sets, file sets, and installs. Breaks up the ext component into three (dll, http_curl, and common) so there are no optional targets in components. Adds a suite of install tests, run them with do_ci.sh cmake.install.test command. Updates the github ci cmake_install_test to run the new suite --- .github/workflows/ci.yml | 15 +- CMakeLists.txt | 19 +- INSTALL.md | 6 +- api/CMakeLists.txt | 6 +- ci/do_ci.sh | 30 +- cmake/install/component-definitions.cmake | 228 +++++++++++++++ .../find-package-support-functions.cmake | 207 +++++++++++++ cmake/install/test/CMakeLists.txt | 124 ++++++++ .../missing_components/CMakeLists.txt | 42 +++ .../no_components/CMakeLists.txt | 34 +++ .../unsorted_components/CMakeLists.txt | 43 +++ .../unsupported_components/CMakeLists.txt | 20 ++ .../component_tests/api/CMakeLists.txt | 14 + .../exporters_elasticsearch/CMakeLists.txt | 16 + .../exporters_etw/CMakeLists.txt | 13 + .../exporters_in_memory/CMakeLists.txt | 16 + .../exporters_ostream/CMakeLists.txt | 17 ++ .../exporters_otlp_common/CMakeLists.txt | 20 ++ .../exporters_otlp_file/CMakeLists.txt | 24 ++ .../exporters_otlp_grpc/CMakeLists.txt | 29 ++ .../exporters_otlp_http/CMakeLists.txt | 24 ++ .../exporters_prometheus/CMakeLists.txt | 19 ++ .../exporters_zipkin/CMakeLists.txt | 15 + .../component_tests/ext_common/CMakeLists.txt | 13 + .../ext_http_curl/CMakeLists.txt | 18 ++ .../component_tests/sdk/CMakeLists.txt | 23 ++ .../shims_opentracing/CMakeLists.txt | 19 ++ .../test/projects/package_test/CMakeLists.txt | 86 ++++++ cmake/install/test/src/test_api.cc | 91 ++++++ .../test/src/test_exporters_elasticsearch.cc | 12 + cmake/install/test/src/test_exporters_etw.cc | 60 ++++ .../test/src/test_exporters_in_memory.cc | 25 ++ .../test/src/test_exporters_ostream.cc | 26 ++ .../test/src/test_exporters_otlp_common.cc | 161 ++++++++++ .../test/src/test_exporters_otlp_file.cc | 34 +++ .../test/src/test_exporters_otlp_grpc.cc | 42 +++ .../test/src/test_exporters_otlp_http.cc | 34 +++ .../test/src/test_exporters_prometheus.cc | 14 + .../install/test/src/test_exporters_zipkin.cc | 14 + cmake/install/test/src/test_ext_common.cc | 12 + cmake/install/test/src/test_ext_http_curl.cc | 13 + cmake/install/test/src/test_sdk.cc | 240 +++++++++++++++ .../test/src/test_shims_opentracing.cc | 23 ++ .../thirdparty-dependency-definitions.cmake | 97 ++++++ cmake/nlohmann-json.cmake | 5 +- cmake/opentelemetry-proto.cmake | 7 +- .../opentelemetry-cpp-config.cmake.in | 276 +++++++----------- .../thirdparty-built-with-flags.cmake.in | 72 +++++ exporters/elasticsearch/CMakeLists.txt | 7 +- exporters/etw/CMakeLists.txt | 6 +- exporters/memory/CMakeLists.txt | 6 +- exporters/ostream/CMakeLists.txt | 6 +- exporters/otlp/CMakeLists.txt | 21 +- exporters/prometheus/CMakeLists.txt | 6 +- exporters/zipkin/CMakeLists.txt | 6 +- ext/CMakeLists.txt | 12 +- ext/src/dll/CMakeLists.txt | 10 +- ext/src/http/client/curl/CMakeLists.txt | 10 +- opentracing-shim/CMakeLists.txt | 6 +- sdk/CMakeLists.txt | 7 +- sdk/src/common/CMakeLists.txt | 2 +- sdk/src/logs/CMakeLists.txt | 2 +- sdk/src/metrics/CMakeLists.txt | 2 +- sdk/src/resource/CMakeLists.txt | 2 +- sdk/src/trace/CMakeLists.txt | 2 +- sdk/src/version/CMakeLists.txt | 2 +- 66 files changed, 2290 insertions(+), 223 deletions(-) create mode 100644 cmake/install/component-definitions.cmake create mode 100644 cmake/install/find-package-support-functions.cmake create mode 100644 cmake/install/test/CMakeLists.txt create mode 100644 cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt create mode 100644 cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt create mode 100644 cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt create mode 100644 cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/api/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/sdk/CMakeLists.txt create mode 100644 cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt create mode 100644 cmake/install/test/projects/package_test/CMakeLists.txt create mode 100644 cmake/install/test/src/test_api.cc create mode 100644 cmake/install/test/src/test_exporters_elasticsearch.cc create mode 100644 cmake/install/test/src/test_exporters_etw.cc create mode 100644 cmake/install/test/src/test_exporters_in_memory.cc create mode 100644 cmake/install/test/src/test_exporters_ostream.cc create mode 100644 cmake/install/test/src/test_exporters_otlp_common.cc create mode 100644 cmake/install/test/src/test_exporters_otlp_file.cc create mode 100644 cmake/install/test/src/test_exporters_otlp_grpc.cc create mode 100644 cmake/install/test/src/test_exporters_otlp_http.cc create mode 100644 cmake/install/test/src/test_exporters_prometheus.cc create mode 100644 cmake/install/test/src/test_exporters_zipkin.cc create mode 100644 cmake/install/test/src/test_ext_common.cc create mode 100644 cmake/install/test/src/test_ext_http_curl.cc create mode 100644 cmake/install/test/src/test_sdk.cc create mode 100644 cmake/install/test/src/test_shims_opentracing.cc create mode 100644 cmake/install/thirdparty-dependency-definitions.cmake rename cmake/{ => templates}/opentelemetry-cpp-config.cmake.in (55%) create mode 100644 cmake/templates/thirdparty-built-with-flags.cmake.in diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86cba0c767..ccd10f171d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -535,19 +535,28 @@ jobs: ./ci/do_ci.sh cmake.exporter.otprotocol.shared_libs.with_static_grpc.test cmake_install_test: - name: CMake install test (with abseil) + name: CMake install test runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup + env: + CXX_STANDARD: '14' + PROTOBUF_VERSION: '21.3' + GRPC_VERSION: 'v1.49.2' + OTEL_CPP_TEST_INSTALL_DIR: "$HOME/test-install" + PKG_CONFIG_PATH: "${OTEL_CPP_TEST_INSTALL_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" run: | sudo -E ./ci/setup_googletest.sh sudo -E ./ci/setup_ci_environment.sh - - name: run cmake install (with abseil) + - name: run cmake install + run: | + sudo ./ci/install_protobuf.sh + sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf + - name: build and run tests run: | - sudo ./ci/install_abseil.sh ./ci/do_ci.sh cmake.install.test - name: verify packages run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index c98bc664aa..0d7a38969f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -772,12 +772,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( @@ -785,11 +784,23 @@ if(OPENTELEMETRY_INSTALL) VERSION ${OPENTELEMETRY_VERSION} COMPATIBILITY ExactVersion) + # Write the "BUILT_WITH_ + +#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/cmake/install/test/src/test_exporters_elasticsearch.cc b/cmake/install/test/src/test_exporters_elasticsearch.cc new file mode 100644 index 0000000000..a2884fc714 --- /dev/null +++ b/cmake/install/test/src/test_exporters_elasticsearch.cc @@ -0,0 +1,12 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include + +TEST(ExportersElasticSearchInstall, ElasticsearchLogRecordExporter) +{ + auto options = opentelemetry::exporter::logs::ElasticsearchExporterOptions(); + auto exporter = opentelemetry::exporter::logs::ElasticsearchLogRecordExporter(options); +} \ No newline at end of file diff --git a/cmake/install/test/src/test_exporters_etw.cc b/cmake/install/test/src/test_exporters_etw.cc new file mode 100644 index 0000000000..cd8016dfa0 --- /dev/null +++ b/cmake/install/test/src/test_exporters_etw.cc @@ -0,0 +1,60 @@ +// 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); + // 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); + { + 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()); + } + tracer->CloseWithMicroseconds(0); +} + +#endif // _WIN32 \ No newline at end of file diff --git a/cmake/install/test/src/test_exporters_in_memory.cc b/cmake/install/test/src/test_exporters_in_memory.cc new file mode 100644 index 0000000000..660dbd6f45 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_ostream.cc b/cmake/install/test/src/test_exporters_ostream.cc new file mode 100644 index 0000000000..ef59856727 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_otlp_common.cc b/cmake/install/test/src/test_exporters_otlp_common.cc new file mode 100644 index 0000000000..da4e2550d9 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_otlp_file.cc b/cmake/install/test/src/test_exporters_otlp_file.cc new file mode 100644 index 0000000000..11627f5503 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_otlp_grpc.cc b/cmake/install/test/src/test_exporters_otlp_grpc.cc new file mode 100644 index 0000000000..6e32c68a23 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_otlp_http.cc b/cmake/install/test/src/test_exporters_otlp_http.cc new file mode 100644 index 0000000000..441df255cc --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_prometheus.cc b/cmake/install/test/src/test_exporters_prometheus.cc new file mode 100644 index 0000000000..1def1417f9 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_exporters_zipkin.cc b/cmake/install/test/src/test_exporters_zipkin.cc new file mode 100644 index 0000000000..1a09fe6143 --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_ext_common.cc b/cmake/install/test/src/test_ext_common.cc new file mode 100644 index 0000000000..cd4b83dfaf --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_ext_http_curl.cc b/cmake/install/test/src/test_ext_http_curl.cc new file mode 100644 index 0000000000..799ee4732a --- /dev/null +++ b/cmake/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/cmake/install/test/src/test_sdk.cc b/cmake/install/test/src/test_sdk.cc new file mode 100644 index 0000000000..ee16888e5b --- /dev/null +++ b/cmake/install/test/src/test_sdk.cc @@ -0,0 +1,240 @@ +// 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: + 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: + 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: + 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_sdk::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"); + static_cast(provider.get())->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(); + static_cast(provider.get())->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); + static_cast(provider.get())->ForceFlush(); +} \ No newline at end of file diff --git a/cmake/install/test/src/test_shims_opentracing.cc b/cmake/install/test/src/test_shims_opentracing.cc new file mode 100644 index 0000000000..ddf037a308 --- /dev/null +++ b/cmake/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/cmake/install/thirdparty-dependency-definitions.cmake b/cmake/install/thirdparty-dependency-definitions.cmake new file mode 100644 index 0000000000..38e7825090 --- /dev/null +++ b/cmake/install/thirdparty-dependency-definitions.cmake @@ -0,0 +1,97 @@ +#----------------------------------------------------------------------- +# 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 + absl + Threads + ZLIB + CURL + nlohmann_json + Protobuf + gRPC + prometheus-cpp + OpenTracing +) + +#----------------------------------------------------------------------- +# Flags to determine if find_dependency(dep) or find_dependency(dep CONFIG) should be used +#----------------------------------------------------------------------- + +# absl +set(FIND_DEPENDENCY_absl_USE_CONFIG TRUE) +# Threads +set(FIND_DEPENDENCY_Threads_USE_CONFIG FALSE) +# ZLIB +set(FIND_DEPENDENCY_ZLIB_USE_CONFIG FALSE) +# CURL +set(FIND_DEPENDENCY_CURL_USE_CONFIG FALSE) +# nlohmann_json +set(FIND_DEPENDENCY_nlohmann_json_USE_CONFIG TRUE) +# Protobuf +set(FIND_DEPENDENCY_Protobuf_USE_CONFIG TRUE) +# gRPC +set(FIND_DEPENDENCY_gRPC_USE_CONFIG TRUE) +# prometheus-cpp +set(FIND_DEPENDENCY_prometheus-cpp_USE_CONFIG TRUE) +# OpenTracing +set(FIND_DEPENDENCY_OpenTracing_USE_CONFIG TRUE) + +#----------------------------------------------------------------------- +# THIRD_PARTY to COMPONENT dependencies +# These are the components that may require the third party dependency +#----------------------------------------------------------------------- + +# Components that may require absl +set(THIRD_PARTY_absl_DEPENDENT_COMPONENTS + api + sdk + exporters_otlp_common + exporters_otlp_grpc +) + +# 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_otlp_file + exporters_otlp_http + exporters_zipkin + exporters_elasticsearch +) + +# Components that require Protobuf +set(THIRD_PARTY_Protobuf_DEPENDENT_COMPONENTS + exporters_otlp_common + exporters_otlp_file + exporters_otlp_http + exporters_otlp_grpc +) + +# 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/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-proto.cmake b/cmake/opentelemetry-proto.cmake index 0d7cc36236..e9a0c878dd 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -376,7 +376,8 @@ if(OPENTELEMETRY_INSTALL) 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( @@ -384,12 +385,14 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE 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() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in similarity index 55% rename from cmake/opentelemetry-cpp-config.cmake.in rename to cmake/templates/opentelemetry-cpp-config.cmake.in index 2b4c655f67..28bac45649 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -4,11 +4,60 @@ #.rst: # opentelemetry-cpp-config.cmake # -------- +# Finding opentelemetry-cpp in CMake projects +# ======================================== # -# Find the native opentelemetry-cpp includes and library. +# - find_package(opentelemetry-cpp CONFIG) to import all installed targets and dependencies +# - find_package(opentelemetry-cpp CONFIG COMPONENTS ...) to import specific components' targets and dependencies # -# Result Variables -# ^^^^^^^^^^^^^^^^ +# Supported use cases +# ------------------- +# +# 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. **Subset of Required Components Specified** +# +# If you request only a subset (e.g. one component), the package will import the +# requested component and resolve additional dependencies as needed. +# +# .. code-block:: cmake +# +# find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_otlp_grpc) +# +# 3. **Components Specified Out-of-Order** +# +# The package automatically sorts components based on their inter-dependencies. +# For instance, even if the components are listed out-of-order: +# +# .. code-block:: cmake +# +# find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_ostream sdk api) +# +# the correct dependency order is applied internally. +# +#.. note:: +# To troubleshoot issues with ``find_package(opentelemetry-cpp)``, 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: # @@ -20,7 +69,9 @@ # 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. # :: # # This module includes the following components for use with `find_package(opentelemetry-cpp COMPONENTS ...)` @@ -28,7 +79,9 @@ # COMPONENTS # api # sdk -# ext +# ext_common +# ext_http_curl +# ext_dll # exporters_in_memory # exporters_ostream # exporters_otlp_common @@ -52,9 +105,9 @@ # 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 -# opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext -# opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext (from ext/dll) +# 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 @@ -81,6 +134,34 @@ # 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 dependency relationships. It ensures that, regardless of the +# order in which components are specified, all necessary dependencies and targets are imported correctly. +# + # ============================================================================= # Copyright The OpenTelemetry Authors @@ -96,177 +177,40 @@ set(OPENTELEMETRY_VERSION @PACKAGE_INIT@ -# ############################################################################## -# List all possible opentelemetry-cpp component targets. Some may not be supported by this install - - -set(_OPENTELEMETRY_CPP_COMPONENTS - api - sdk - ext - 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) - -set(_OPENTELEMETRY_CPP_TARGETS - api - sdk - version - common - resources - trace - metrics - logs - ext - http_client_curl - in_memory_span_exporter - in_memory_metric_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 - zipkin_trace_exporter - opentracing_shim) - - -# ############################################################################## +# 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") -# Create the list of requested components. Either all installed or a set passed to find_package( opentelemetry-cpp COMPONENTS ...) +set(_INSTALLED_COMPONENTS "") +get_installed_components(_INSTALLED_COMPONENTS) -set(_FIND_ALL_COMPONENTS TRUE) +set(OPENTELEMETRY_CPP_COMPONENTS_INSTALLED ${_INSTALLED_COMPONENTS} CACHE STRING "opentelemetry-cpp components installed" FORCE) -set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) +set(_REQUESTED_COMPONENTS "") +get_requested_components(_INSTALLED_COMPONENTS _REQUESTED_COMPONENTS) -if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") - # if no components are requested then find all installed components - - set(_TARGET_FILES_DIR "${CMAKE_CURRENT_LIST_DIR}") - - foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) - set(_COMPONENT_TARGET_FILE "${_TARGET_FILES_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake") - if(EXISTS "${_COMPONENT_TARGET_FILE}") - list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) - endif() - endforeach() - -else() - set(_FIND_ALL_COMPONENTS FALSE) - # check that the requested components are valid and installed - - foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) - if(NOT ${_COMPONENT} IN_LIST _OPENTELEMETRY_CPP_COMPONENTS) - message(FATAL_ERROR "The `${_COMPONENT}` component is not a supported component of the opentelemetry-cpp package. Supported components include: ${_OPENTELEMETRY_CPP_COMPONENTS}") - endif() - endforeach() - - foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) - if(${_COMPONENT} IN_LIST opentelemetry-cpp_FIND_COMPONENTS) - list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) - endif() - endforeach() -endif() - -# _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS only contains valid components. However they may not all be installed in this package -# Find dependencies based on the requested components list. - -include(CMakeFindDependencyMacro) - -find_dependency(Threads) - -if(@WITH_ABSEIL@) - find_dependency(absl) -endif() - -if(@WITH_OTLP_GRPC@) - if("exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) - find_dependency(gRPC) - endif() -endif() - -if("@OpenTracing_FOUND@") - if("shims_opentracing" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) - find_dependency(OpenTracing) - endif() -endif() - -if("@prometheus-cpp_FOUND@") - if("exporters_prometheus" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) - find_dependency(prometheus-cpp) - endif() -endif() - -if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") - if( - "exporters_otlp_common" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR - "exporters_otlp_grpc" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR - "exporters_otlp_file" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS OR - "exporters_otlp_http" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS - ) - find_dependency(Protobuf) - endif() -endif() - -if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) - if("@CURL_FOUND@") - if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) - find_dependency(CURL) - endif() - endif() - - if("@ZLIB_FOUND@") - if("ext" IN_LIST _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) - find_dependency(ZLIB) - endif() - endif() -endif() - -if(@WITH_ABSEIL@ OR @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() +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. - -foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) +# 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() -# Set OPENTELEMETRY_CPP_* variables to preserve legacy CMake style +# 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 to preserve legacy CMake style set(OPENTELEMETRY_CPP_LIBRARIES) -foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) - if(TARGET opentelemetry-cpp::${_TEST_TARGET}) - list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET}) +foreach(_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) + if(TARGET ${_TARGET}) + list(APPEND OPENTELEMETRY_CPP_LIBRARIES ${_TARGET}) endif() endforeach() @@ -286,3 +230,5 @@ 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..dc6069c2b3 --- /dev/null +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -0,0 +1,72 @@ +#------------------------------------------------------------------------- +# 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 that may require them. +#------------------------------------------------------------------------- + +# Initialize dependency expected flags +set(BUILT_WITH_Threads TRUE) +set(BUILT_WITH_absl FALSE) +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) + +# absl: +# Expected TRUE if either: +# - WITH_ABSEIL is enabled, OR +# - WITH_OTLP_GRPC is enabled, OR +# - WITH_OTLP_HTTP or WITH_OTLP_FILE is enabled and Protobuf version is at least 3.22.0. +if(@WITH_ABSEIL@) + set(BUILT_WITH_absl TRUE) +elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@ OR @WITH_OTLP_GRPC@) + if( @WITH_OTLP_GRPC@ ) + set(BUILT_WITH_absl TRUE) + elseif("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0") + set(BUILT_WITH_absl TRUE) + endif() +endif() + +# CURL and ZLIB: +# Expected TRUE if WITH_HTTP_CLIENT_CURL is enabled and we're building static libraries. +if(@WITH_HTTP_CLIENT_CURL@ AND NOT "@BUILD_SHARED_LIBS@") + if("@CURL_FOUND@") + set(BUILT_WITH_CURL TRUE) + endif() + if("@ZLIB_FOUND@") + set(BUILT_WITH_ZLIB TRUE) + endif() +endif() + +# nlohmann_json: +# Expected TRUE if both USE_NLOHMANN_JSON is true and the package was found during build. +if("@USE_NLOHMANN_JSON@" AND "@nlohmann_json_FOUND@") + 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() + + diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index 4ca61476b6..a5d0c31e99 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -24,11 +24,13 @@ if(OPENTELEMETRY_INSTALL) 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) @@ -37,7 +39,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_elasticsearch-target" FILE "${PROJECT_NAME}-exporters_elasticsearch-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_elasticsearch) endif() diff --git a/exporters/etw/CMakeLists.txt b/exporters/etw/CMakeLists.txt index 837b9f46a3..fa98992509 100644 --- a/exporters/etw/CMakeLists.txt +++ b/exporters/etw/CMakeLists.txt @@ -25,11 +25,12 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -37,7 +38,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_etw-target" FILE "${PROJECT_NAME}-exporters_etw-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${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 f15d58f514..79ec4b08c5 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -39,11 +39,12 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -51,7 +52,8 @@ if(OPENTELEMETRY_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}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_in_memory) endif() diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index b566a4f322..7515093e1b 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -72,17 +72,19 @@ if(OPENTELEMETRY_INSTALL) 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( EXPORT "${PROJECT_NAME}-exporters_ostream-target" FILE "${PROJECT_NAME}-exporters_ostream-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${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 2355e68f6b..a596298c5a 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -278,11 +278,12 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -290,7 +291,8 @@ if(OPENTELEMETRY_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}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_common) if(WITH_OTLP_GRPC) install( @@ -298,13 +300,14 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_otlp_grpc-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE 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}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_grpc) endif() if(WITH_OTLP_FILE) @@ -313,13 +316,14 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_otlp_file-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE 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}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_file) endif() if(WITH_OTLP_HTTP) @@ -328,13 +332,14 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_otlp_http-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE 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}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_otlp_http) endif() endif() diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 6dc392e42a..13fdfd1006 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -43,11 +43,12 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -55,7 +56,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_prometheus-target" FILE "${PROJECT_NAME}-exporters_prometheus-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${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 6c2d635793..af91c496dd 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -28,11 +28,12 @@ if(OPENTELEMETRY_INSTALL) 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) @@ -41,7 +42,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-exporters_zipkin-target" FILE "${PROJECT_NAME}-exporters_zipkin-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT exporters_zipkin) endif() diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index cfd298ea9d..8569658591 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -13,22 +13,24 @@ target_link_libraries(opentelemetry_ext INTERFACE opentelemetry_api) if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_ext - EXPORT "${PROJECT_NAME}-ext-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-target" - FILE "${PROJECT_NAME}-ext-target.cmake" + EXPORT "${PROJECT_NAME}-ext_common-target" + FILE "${PROJECT_NAME}-ext_common-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT ext_common) endif() diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index d8fd107822..17323bc2a4 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -119,9 +119,15 @@ add_custom_command( if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_cpp - EXPORT "${PROJECT_NAME}-ext-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 e1ed24a44f..95a07e0d3e 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -48,9 +48,15 @@ endif() if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_http_client_curl - EXPORT "${PROJECT_NAME}-ext-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/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index 494fd67267..e1130b8fd7 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -33,11 +33,12 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -45,7 +46,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-shims_opentracing-target" FILE "${PROJECT_NAME}-shims_opentracing-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${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 b063cf6548..66b9b2544d 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -15,17 +15,19 @@ if(OPENTELEMETRY_INSTALL) 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") @@ -33,7 +35,8 @@ if(OPENTELEMETRY_INSTALL) EXPORT "${PROJECT_NAME}-sdk-target" FILE "${PROJECT_NAME}-sdk-target.cmake" NAMESPACE "${PROJECT_NAME}::" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT sdk) endif() diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index b4a4163222..69a63dd282 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -28,7 +28,7 @@ if(OPENTELEMETRY_INSTALL) 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 11fa400998..2929dca7d7 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -39,7 +39,7 @@ if(OPENTELEMETRY_INSTALL) 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 aa54940519..0c87dbf69c 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -47,7 +47,7 @@ if(OPENTELEMETRY_INSTALL) 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 ac28033fcf..1dbfd1a993 100644 --- a/sdk/src/resource/CMakeLists.txt +++ b/sdk/src/resource/CMakeLists.txt @@ -18,7 +18,7 @@ if(OPENTELEMETRY_INSTALL) 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 f8253c182b..4543521eda 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -40,7 +40,7 @@ if(OPENTELEMETRY_INSTALL) 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 53ffdea436..bbfd9a53b8 100644 --- a/sdk/src/version/CMakeLists.txt +++ b/sdk/src/version/CMakeLists.txt @@ -19,7 +19,7 @@ if(OPENTELEMETRY_INSTALL) 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" From 96e2e96ff9668a2e01a0e38c9c3e3bdca45183f1 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 16 Feb 2025 21:35:24 -0700 Subject: [PATCH 07/28] add missing copyright and license statements. Set LD_LIBRARY path to the install directory. Update ci scripts to set environment variables properly --- .github/workflows/ci.yml | 14 ++++++++------ ci/do_ci.sh | 2 ++ cmake/install/component-definitions.cmake | 3 +++ cmake/install/find-package-support-functions.cmake | 3 +++ cmake/install/test/CMakeLists.txt | 10 +++++++--- .../missing_components/CMakeLists.txt | 3 +++ .../cmake_usage_tests/no_components/CMakeLists.txt | 3 +++ .../unsorted_components/CMakeLists.txt | 3 +++ .../unsupported_components/CMakeLists.txt | 3 +++ .../projects/component_tests/api/CMakeLists.txt | 3 +++ .../exporters_elasticsearch/CMakeLists.txt | 5 ++++- .../component_tests/exporters_etw/CMakeLists.txt | 5 ++++- .../exporters_in_memory/CMakeLists.txt | 5 ++++- .../exporters_ostream/CMakeLists.txt | 5 ++++- .../exporters_otlp_common/CMakeLists.txt | 5 ++++- .../exporters_otlp_file/CMakeLists.txt | 5 ++++- .../exporters_otlp_grpc/CMakeLists.txt | 5 ++++- .../exporters_otlp_http/CMakeLists.txt | 5 ++++- .../exporters_prometheus/CMakeLists.txt | 5 ++++- .../exporters_zipkin/CMakeLists.txt | 5 ++++- .../component_tests/ext_common/CMakeLists.txt | 5 ++++- .../component_tests/ext_http_curl/CMakeLists.txt | 5 ++++- .../projects/component_tests/sdk/CMakeLists.txt | 5 ++++- .../shims_opentracing/CMakeLists.txt | 5 ++++- .../test/projects/package_test/CMakeLists.txt | 12 ++++-------- .../thirdparty-dependency-definitions.cmake | 3 +++ .../templates/thirdparty-built-with-flags.cmake.in | 3 +++ 27 files changed, 104 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccd10f171d..ea65bff027 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -542,23 +542,25 @@ jobs: with: submodules: 'recursive' - name: setup - env: - CXX_STANDARD: '14' - PROTOBUF_VERSION: '21.3' - GRPC_VERSION: 'v1.49.2' - OTEL_CPP_TEST_INSTALL_DIR: "$HOME/test-install" - PKG_CONFIG_PATH: "${OTEL_CPP_TEST_INSTALL_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" run: | sudo -E ./ci/setup_googletest.sh sudo -E ./ci/setup_ci_environment.sh - name: run cmake install + env: + CXX_STANDARD: '14' + PROTOBUF_VERSION: '21.3' + GRPC_VERSION: 'v1.49.2' run: | sudo ./ci/install_protobuf.sh sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf - name: build and run tests + env: + OTEL_CPP_TEST_INSTALL_DIR: "$HOME/test-install" run: | ./ci/do_ci.sh cmake.install.test - name: verify packages + env: + PKG_CONFIG_PATH: "$HOME/test-install/lib/pkgconfig:${PKG_CONFIG_PATH:-}" run: | ./ci/verify_packages.sh diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f1863b1ea2..b528b46e22 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -241,6 +241,7 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then make -j $(nproc) make test make install + export LD_LIBRARY_PATH="${OTEL_CPP_TEST_INSTALL_DIR}/lib:$LD_LIBRARY_PATH" cmake -S "${SRC_DIR}/cmake/install/test" \ -B "${BUILD_DIR}/install_test" \ "-DCMAKE_PREFIX_PATH=${OTEL_CPP_TEST_INSTALL_DIR}" \ @@ -441,6 +442,7 @@ elif [[ "$1" == "cmake.install.test" ]]; then "${SRC_DIR}" make -j $(nproc) make install + export LD_LIBRARY_PATH="${OTEL_CPP_TEST_INSTALL_DIR}/lib:$LD_LIBRARY_PATH" cmake -S "${SRC_DIR}/cmake/install/test" \ -B "${BUILD_DIR}/install_test" \ "-DCMAKE_PREFIX_PATH=${OTEL_CPP_TEST_INSTALL_DIR}" \ diff --git a/cmake/install/component-definitions.cmake b/cmake/install/component-definitions.cmake index 5180c49b58..0135438b9f 100644 --- a/cmake/install/component-definitions.cmake +++ b/cmake/install/component-definitions.cmake @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + # ---------------------------------------------------------------------- # opentelmetry-cpp COMPONENT list # ---------------------------------------------------------------------- diff --git a/cmake/install/find-package-support-functions.cmake b/cmake/install/find-package-support-functions.cmake index c6945bd083..29097cf461 100644 --- a/cmake/install/find-package-support-functions.cmake +++ b/cmake/install/find-package-support-functions.cmake @@ -1,3 +1,6 @@ +# 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") diff --git a/cmake/install/test/CMakeLists.txt b/cmake/install/test/CMakeLists.txt index dc4875b2c6..76d1a579d4 100644 --- a/cmake/install/test/CMakeLists.txt +++ b/cmake/install/test/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + cmake_minimum_required(VERSION 3.10) project(opentelemetry-cpp-component-install-tests LANGUAGES CXX) @@ -12,6 +15,7 @@ endif() include(${CMAKE_SOURCE_DIR}/../../install/component-definitions.cmake) +# If COMPONENTS_TO_TEST is not set, then test all components if(NOT COMPONENTS_TO_TEST) set(COMPONENTS_TO_TEST ${opentelemetry-cpp_COMPONENTS}) else() @@ -41,6 +45,8 @@ message(STATUS "Testing cmake usage for find_package(opentelemetry ...)") # 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 @@ -76,9 +82,7 @@ add_test( # ----------------------------------------------------------- # Test the full package install using legacy cmake build instructions -# find_package(opentelemetry-cpp CONFIG REQUIRED) target_include_directories(foo -# PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) target_link_libraries(foo PRIVATE -# ${OPENTELEMETRY_CPP_LIBRARIES}) +# find_package(opentelemetry-cpp CONFIG REQUIRED) message(STATUS "Testing the full package install") # Test cmake configuration add_test( diff --git a/cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt b/cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt index 81fb37526e..c93d558c8a 100644 --- a/cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt +++ b/cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt @@ -1,3 +1,6 @@ +# 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) diff --git a/cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt b/cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt index b02410dc7f..9d9521ad79 100644 --- a/cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt +++ b/cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt @@ -1,3 +1,6 @@ +# 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) diff --git a/cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt b/cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt index 933dd28563..0331e97046 100644 --- a/cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt +++ b/cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt @@ -1,3 +1,6 @@ +# 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) diff --git a/cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt b/cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt index 27f31ca747..6c9bea709c 100644 --- a/cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt +++ b/cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt @@ -1,3 +1,6 @@ +# 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) diff --git a/cmake/install/test/projects/component_tests/api/CMakeLists.txt b/cmake/install/test/projects/component_tests/api/CMakeLists.txt index 3feb551eed..0721e37797 100644 --- a/cmake/install/test/projects/component_tests/api/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/api/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + cmake_minimum_required(VERSION 3.10) project(opentelemetry-cpp-api-install-test LANGUAGES CXX) diff --git a/cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt index 4f98ca1d65..ede48beb17 100644 --- a/cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_elasticsearch_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_elasticsearch) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt index 30e3f3d30c..6cb9ecaa7e 100644 --- a/cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_etw_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_etw) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt index fb6fb2275e..6c05935e81 100644 --- a/cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_in_memory_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_in_memory) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt index 09bee9a7f1..42226d6492 100644 --- a/cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_ostream_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_ostream) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt index 13135d6417..5a78f56789 100644 --- a/cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_otlp_common_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_common) if(NOT TARGET protobuf::libprotobuf) diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt index 69a6f335dd..14d4898bbb 100644 --- a/cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_otlp_file_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_file) if(NOT TARGET protobuf::libprotobuf) diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt index 15c0a01520..aa3047a684 100644 --- a/cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_otlp_grpc_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_grpc) if(NOT TARGET protobuf::libprotobuf) diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt index e70d900372..7cab341374 100644 --- a/cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_otlp_http_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_otlp_http) if(NOT TARGET protobuf::libprotobuf) diff --git a/cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt index e9a9c82516..776cff300b 100644 --- a/cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_prometheus_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_prometheus) if(NOT TARGET prometheus-cpp::core) diff --git a/cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt b/cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt index c6019e9635..40c0fda0b3 100644 --- a/cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the exporters_zipkin_test component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_zipkin) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt b/cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt index bd114f0890..51cbb908d0 100644 --- a/cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the ext_common component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_common) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt b/cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt index 704c090027..5fb9fff695 100644 --- a/cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the ext_http_curl component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_http_curl) if(NOT TARGET CURL::libcurl) diff --git a/cmake/install/test/projects/component_tests/sdk/CMakeLists.txt b/cmake/install/test/projects/component_tests/sdk/CMakeLists.txt index 55ecd3fcc0..3f3d6d277b 100644 --- a/cmake/install/test/projects/component_tests/sdk/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/sdk/CMakeLists.txt @@ -1,6 +1,9 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + cmake_minimum_required(VERSION 3.10) project(opentelemetry-cpp-sdk-install-test LANGUAGES CXX) -message(STATUS "Testing the sdk component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS sdk) find_package(GTest REQUIRED) diff --git a/cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt b/cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt index a32a1798d4..fbe3fbaa4e 100644 --- a/cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt +++ b/cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt @@ -1,6 +1,9 @@ +# 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) -message(STATUS "Testing the shims_opentracing component install") + find_package(opentelemetry-cpp REQUIRED COMPONENTS shims_opentracing) if(NOT TARGET OpenTracing::opentracing) diff --git a/cmake/install/test/projects/package_test/CMakeLists.txt b/cmake/install/test/projects/package_test/CMakeLists.txt index 946b581f67..5066b7abaf 100644 --- a/cmake/install/test/projects/package_test/CMakeLists.txt +++ b/cmake/install/test/projects/package_test/CMakeLists.txt @@ -1,3 +1,6 @@ +# 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) @@ -11,14 +14,7 @@ endif() find_package(opentelemetry-cpp CONFIG REQUIRED) -# Test that the following variables are set: 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. +# Test that the required OPENTELEMETRY_CPP_* variables are set if(NOT OPENTELEMETRY_CPP_INCLUDE_DIRS) message(FATAL_ERROR "OPENTELEMETRY_CPP_INCLUDE_DIRS is empty") diff --git a/cmake/install/thirdparty-dependency-definitions.cmake b/cmake/install/thirdparty-dependency-definitions.cmake index 38e7825090..c03bb9cd49 100644 --- a/cmake/install/thirdparty-dependency-definitions.cmake +++ b/cmake/install/thirdparty-dependency-definitions.cmake @@ -1,3 +1,6 @@ +# 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. diff --git a/cmake/templates/thirdparty-built-with-flags.cmake.in b/cmake/templates/thirdparty-built-with-flags.cmake.in index dc6069c2b3..2e1ee2da09 100644 --- a/cmake/templates/thirdparty-built-with-flags.cmake.in +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -1,3 +1,6 @@ +# 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 From d3d171c2f53d70922616c21631dbea1cd6309763 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 16 Feb 2025 22:03:19 -0700 Subject: [PATCH 08/28] update the cmake_install_test runner image to ubuntu 24.04 to pull in the latest nlohmann-json package for the es exporter --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea65bff027..191538318c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -536,7 +536,7 @@ jobs: cmake_install_test: name: CMake install test - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: From 5dadf7af728a707fde205b753b774432775951e7 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 16 Feb 2025 22:43:29 -0700 Subject: [PATCH 09/28] fix gihub workflow yaml to use correct syntacx for accessing env vars --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 191538318c..3b732a9728 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -555,12 +555,12 @@ jobs: sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf - name: build and run tests env: - OTEL_CPP_TEST_INSTALL_DIR: "$HOME/test-install" + OTEL_CPP_TEST_INSTALL_DIR: "${{ env.HOME }}/test-install" run: | ./ci/do_ci.sh cmake.install.test - name: verify packages env: - PKG_CONFIG_PATH: "$HOME/test-install/lib/pkgconfig:${PKG_CONFIG_PATH:-}" + PKG_CONFIG_PATH: "${{ env.HOME }}/test-install/lib/pkgconfig:${{ env.PKG_CONFIG_PATH }}" run: | ./ci/verify_packages.sh From d3d0db769426441074a898d0a1c2a503146a05b1 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 16 Feb 2025 23:10:09 -0700 Subject: [PATCH 10/28] set the install path in the run statement --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b732a9728..4c079e58d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -554,14 +554,12 @@ jobs: sudo ./ci/install_protobuf.sh sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf - name: build and run tests - env: - OTEL_CPP_TEST_INSTALL_DIR: "${{ env.HOME }}/test-install" run: | + export OTEL_CPP_TEST_INSTALL_DIR=$HOME/test-install ./ci/do_ci.sh cmake.install.test - name: verify packages - env: - PKG_CONFIG_PATH: "${{ env.HOME }}/test-install/lib/pkgconfig:${{ env.PKG_CONFIG_PATH }}" run: | + export PKG_CONFIG_PATH=$HOME/test-install/lib/pkgconfig:$PKG_CONFIG_PATH ./ci/verify_packages.sh plugin_test: From ca4a507579372e8415fa1bde5a4f5dc5b2edff6c Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 18 Feb 2025 15:48:47 -0700 Subject: [PATCH 11/28] move cmake install tests to a top level install dir. Clean up comments and cmake messages. Run the ci install test on the more modern grpc version and with abseil --- .github/workflows/ci.yml | 19 ++-- CMakeLists.txt | 8 +- ci/do_ci.sh | 25 +++--- .../{install => }/component-definitions.cmake | 0 .../find-package-support-functions.cmake | 0 .../opentelemetry-cpp-config.cmake.in | 32 +++---- .../thirdparty-built-with-flags.cmake.in | 8 +- .../thirdparty-dependency-definitions.cmake | 2 +- .../test/cmake}/CMakeLists.txt | 27 +++--- .../cmake}/component_tests/api/CMakeLists.txt | 0 .../exporters_elasticsearch/CMakeLists.txt | 0 .../exporters_etw/CMakeLists.txt | 0 .../exporters_in_memory/CMakeLists.txt | 0 .../exporters_ostream/CMakeLists.txt | 0 .../exporters_otlp_common/CMakeLists.txt | 0 .../exporters_otlp_file/CMakeLists.txt | 0 .../exporters_otlp_grpc/CMakeLists.txt | 0 .../exporters_otlp_http/CMakeLists.txt | 0 .../exporters_prometheus/CMakeLists.txt | 0 .../exporters_zipkin/CMakeLists.txt | 0 .../component_tests/ext_common/CMakeLists.txt | 0 .../ext_http_curl/CMakeLists.txt | 0 .../cmake}/component_tests/sdk/CMakeLists.txt | 0 .../shims_opentracing/CMakeLists.txt | 0 .../test/cmake}/package_test/CMakeLists.txt | 0 .../missing_components/CMakeLists.txt | 0 .../usage_tests}/no_components/CMakeLists.txt | 0 .../unsorted_components/CMakeLists.txt | 0 .../unsupported_components/CMakeLists.txt | 0 .../install => install}/test/src/test_api.cc | 0 .../test/src/test_exporters_elasticsearch.cc | 0 .../test/src/test_exporters_etw.cc | 0 .../test/src/test_exporters_in_memory.cc | 0 .../test/src/test_exporters_ostream.cc | 0 .../test/src/test_exporters_otlp_common.cc | 0 .../test/src/test_exporters_otlp_file.cc | 0 .../test/src/test_exporters_otlp_grpc.cc | 0 .../test/src/test_exporters_otlp_http.cc | 0 .../test/src/test_exporters_prometheus.cc | 0 .../test/src/test_exporters_zipkin.cc | 0 .../test/src/test_ext_common.cc | 0 .../test/src/test_ext_http_curl.cc | 0 .../install => install}/test/src/test_sdk.cc | 90 ++++++++++++------- .../test/src/test_shims_opentracing.cc | 0 44 files changed, 111 insertions(+), 100 deletions(-) rename cmake/{install => }/component-definitions.cmake (100%) rename cmake/{install => }/find-package-support-functions.cmake (100%) rename cmake/{install => }/thirdparty-dependency-definitions.cmake (96%) rename {cmake/install/test => install/test/cmake}/CMakeLists.txt (79%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/api/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_elasticsearch/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_etw/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_in_memory/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_ostream/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_otlp_common/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_otlp_file/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_otlp_grpc/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_otlp_http/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_prometheus/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/exporters_zipkin/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/ext_common/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/ext_http_curl/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/sdk/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/component_tests/shims_opentracing/CMakeLists.txt (100%) rename {cmake/install/test/projects => install/test/cmake}/package_test/CMakeLists.txt (100%) rename {cmake/install/test/projects/cmake_usage_tests => install/test/cmake/usage_tests}/missing_components/CMakeLists.txt (100%) rename {cmake/install/test/projects/cmake_usage_tests => install/test/cmake/usage_tests}/no_components/CMakeLists.txt (100%) rename {cmake/install/test/projects/cmake_usage_tests => install/test/cmake/usage_tests}/unsorted_components/CMakeLists.txt (100%) rename {cmake/install/test/projects/cmake_usage_tests => install/test/cmake/usage_tests}/unsupported_components/CMakeLists.txt (100%) rename {cmake/install => install}/test/src/test_api.cc (100%) rename {cmake/install => install}/test/src/test_exporters_elasticsearch.cc (100%) rename {cmake/install => install}/test/src/test_exporters_etw.cc (100%) rename {cmake/install => install}/test/src/test_exporters_in_memory.cc (100%) rename {cmake/install => install}/test/src/test_exporters_ostream.cc (100%) rename {cmake/install => install}/test/src/test_exporters_otlp_common.cc (100%) rename {cmake/install => install}/test/src/test_exporters_otlp_file.cc (100%) rename {cmake/install => install}/test/src/test_exporters_otlp_grpc.cc (100%) rename {cmake/install => install}/test/src/test_exporters_otlp_http.cc (100%) rename {cmake/install => install}/test/src/test_exporters_prometheus.cc (100%) rename {cmake/install => install}/test/src/test_exporters_zipkin.cc (100%) rename {cmake/install => install}/test/src/test_ext_common.cc (100%) rename {cmake/install => install}/test/src/test_ext_http_curl.cc (100%) rename {cmake/install => install}/test/src/test_sdk.cc (75%) rename {cmake/install => install}/test/src/test_shims_opentracing.cc (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c079e58d0..299b294972 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -537,6 +537,9 @@ jobs: cmake_install_test: name: CMake install test runs-on: ubuntu-24.04 + env: + INSTALL_TEST_DIR: '/home/runner/install_test' + CXX_STANDARD: '17' steps: - uses: actions/checkout@v4 with: @@ -545,21 +548,21 @@ jobs: run: | sudo -E ./ci/setup_googletest.sh sudo -E ./ci/setup_ci_environment.sh - - name: run cmake install + - name: install dependencies env: - CXX_STANDARD: '14' - PROTOBUF_VERSION: '21.3' - GRPC_VERSION: 'v1.49.2' + ABSEIL_CPP_VERSION: '20230125.3' + PROTOBUF_VERSION: '23.3' + GRPC_VERSION: 'v1.55.0' run: | + sudo ./ci/install_abseil.sh sudo ./ci/install_protobuf.sh - sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf - - name: build and run tests + sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil + - name: build and test run: | - export OTEL_CPP_TEST_INSTALL_DIR=$HOME/test-install ./ci/do_ci.sh cmake.install.test - name: verify packages run: | - export PKG_CONFIG_PATH=$HOME/test-install/lib/pkgconfig:$PKG_CONFIG_PATH + export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH ./ci/verify_packages.sh plugin_test: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d7a38969f..cd0f3abcda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -394,6 +394,8 @@ if(WITH_PROMETHEUS) endif() endif() +message(STATUS "Building WITH_ABSEIL=${WITH_ABSEIL}") + if(WITH_ABSEIL) if(NOT TARGET absl::strings) find_package(absl CONFIG REQUIRED) @@ -796,9 +798,9 @@ if(OPENTELEMETRY_INSTALL) "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake" "${CMAKE_CURRENT_BINARY_DIR}/thirdparty-built-with-flags.cmake" - "${CMAKE_CURRENT_LIST_DIR}/cmake/install/component-definitions.cmake" - "${CMAKE_CURRENT_LIST_DIR}/cmake/install/thirdparty-dependency-definitions.cmake" - "${CMAKE_CURRENT_LIST_DIR}/cmake/install/find-package-support-functions.cmake" + "${CMAKE_CURRENT_LIST_DIR}/cmake/component-definitions.cmake" + "${CMAKE_CURRENT_LIST_DIR}/cmake/thirdparty-dependency-definitions.cmake" + "${CMAKE_CURRENT_LIST_DIR}/cmake/find-package-support-functions.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" COMPONENT cmake-config) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index b528b46e22..4dd150e03d 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -62,8 +62,8 @@ function run_benchmarks mkdir -p "${BUILD_DIR}" [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin mkdir -p "${PLUGIN_DIR}" -[ -z "${OTEL_CPP_TEST_INSTALL_DIR}" ] && export OTEL_CPP_TEST_INSTALL_DIR=$HOME/otel_cpp_test_install -mkdir -p "${OTEL_CPP_TEST_INSTALL_DIR}" +[ -z "${INSTALL_TEST_DIR}" ] && export INSTALL_TEST_DIR=$HOME/install_test +mkdir -p "${INSTALL_TEST_DIR}" MAKE_COMMAND="make -k -j \$(nproc)" @@ -232,19 +232,19 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then cd "${BUILD_DIR}" rm -rf * - rm -rf ${OTEL_CPP_TEST_INSTALL_DIR}/* + rm -rf ${INSTALL_TEST_DIR}/* cmake "${CMAKE_OPTIONS[@]}" \ -DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \ -DWITH_OPENTRACING=ON \ - -DCMAKE_INSTALL_PREFIX=${OTEL_CPP_TEST_INSTALL_DIR} \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ "${SRC_DIR}" make -j $(nproc) make test make install - export LD_LIBRARY_PATH="${OTEL_CPP_TEST_INSTALL_DIR}/lib:$LD_LIBRARY_PATH" - cmake -S "${SRC_DIR}/cmake/install/test" \ + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + cmake -S "${SRC_DIR}/install/test/cmake" \ -B "${BUILD_DIR}/install_test" \ - "-DCMAKE_PREFIX_PATH=${OTEL_CPP_TEST_INSTALL_DIR}" \ + "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ "-DCOMPONENTS_TO_TEST=shims_opentracing" ctest --test-dir "${BUILD_DIR}/install_test" --output-on-failure exit 0 @@ -425,9 +425,10 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then elif [[ "$1" == "cmake.install.test" ]]; then cd "${BUILD_DIR}" rm -rf * - rm -rf ${OTEL_CPP_TEST_INSTALL_DIR}/* + rm -rf ${INSTALL_TEST_DIR}/* cmake "${CMAKE_OPTIONS[@]}" \ - -DCMAKE_INSTALL_PREFIX=${OTEL_CPP_TEST_INSTALL_DIR} \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ + -DWITH_ABSEIL=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_OTLP_GRPC=ON \ @@ -442,10 +443,10 @@ elif [[ "$1" == "cmake.install.test" ]]; then "${SRC_DIR}" make -j $(nproc) make install - export LD_LIBRARY_PATH="${OTEL_CPP_TEST_INSTALL_DIR}/lib:$LD_LIBRARY_PATH" - cmake -S "${SRC_DIR}/cmake/install/test" \ + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + cmake -S "${SRC_DIR}/install/test/cmake" \ -B "${BUILD_DIR}/install_test" \ - "-DCMAKE_PREFIX_PATH=${OTEL_CPP_TEST_INSTALL_DIR}" \ + "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ "-DCOMPONENTS_TO_TEST=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" ctest --test-dir "${BUILD_DIR}/install_test" --output-on-failure exit 0 diff --git a/cmake/install/component-definitions.cmake b/cmake/component-definitions.cmake similarity index 100% rename from cmake/install/component-definitions.cmake rename to cmake/component-definitions.cmake diff --git a/cmake/install/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake similarity index 100% rename from cmake/install/find-package-support-functions.cmake rename to cmake/find-package-support-functions.cmake diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in index 28bac45649..3f43bb1f2f 100644 --- a/cmake/templates/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -7,10 +7,10 @@ # Finding opentelemetry-cpp in CMake projects # ======================================== # -# - find_package(opentelemetry-cpp CONFIG) to import all installed targets and dependencies +# - 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 # -# Supported use cases +# Example usage # ------------------- # # 1. **No Components Specified** @@ -22,28 +22,18 @@ # find_package(opentelemetry-cpp CONFIG REQUIRED) # # -# 2. **Subset of Required Components Specified** +# 2. **Components Specified** # -# If you request only a subset (e.g. one component), the package will import the -# requested component and resolve additional dependencies as needed. +# 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) # -# 3. **Components Specified Out-of-Order** -# -# The package automatically sorts components based on their inter-dependencies. -# For instance, even if the components are listed out-of-order: -# -# .. code-block:: cmake -# -# find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_ostream sdk api) -# -# the correct dependency order is applied internally. # #.. note:: -# To troubleshoot issues with ``find_package(opentelemetry-cpp)``, run CMake with debug logging enabled: +# To troubleshoot issues with ``find_package(opentelemetry-cpp CONFIG REQUIRED)``, run CMake with debug logging enabled: # # .. code-block:: bash # @@ -74,7 +64,10 @@ # opentelemetry-cpp__FOUND - True if the requested component is found. # :: # -# This module includes the following components for use with `find_package(opentelemetry-cpp COMPONENTS ...)` +# +# CMake Components and Targets Supported +# -------------------- +# opentelemetry-cpp supports the following components and targets. This install may include a subset. # # COMPONENTS # api @@ -158,8 +151,7 @@ # # - **component-definitions.cmake** # This file defines the available opentelemetry-cpp components, the targets associated with each -# component, and the inter-component dependency relationships. It ensures that, regardless of the -# order in which components are specified, all necessary dependencies and targets are imported correctly. +# component, and the inter-component dependencies. # @@ -205,7 +197,7 @@ set(_OPENTELEMETRY_CPP_TARGETS "") get_targets(_REQUESTED_COMPONENTS _OPENTELEMETRY_CPP_TARGETS) check_targets_imported(_OPENTELEMETRY_CPP_TARGETS) -# Set OPENTELEMETRY_CPP_* variables to preserve legacy CMake style +# Set OPENTELEMETRY_CPP_* variables set(OPENTELEMETRY_CPP_LIBRARIES) foreach(_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS) diff --git a/cmake/templates/thirdparty-built-with-flags.cmake.in b/cmake/templates/thirdparty-built-with-flags.cmake.in index 2e1ee2da09..ddbd155612 100644 --- a/cmake/templates/thirdparty-built-with-flags.cmake.in +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -5,7 +5,7 @@ # 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 that may require them. +# mapping to opentelemetry-cpp components. #------------------------------------------------------------------------- # Initialize dependency expected flags @@ -20,10 +20,6 @@ set(BUILT_WITH_prometheus-cpp FALSE) set(BUILT_WITH_OpenTracing FALSE) # absl: -# Expected TRUE if either: -# - WITH_ABSEIL is enabled, OR -# - WITH_OTLP_GRPC is enabled, OR -# - WITH_OTLP_HTTP or WITH_OTLP_FILE is enabled and Protobuf version is at least 3.22.0. if(@WITH_ABSEIL@) set(BUILT_WITH_absl TRUE) elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@ OR @WITH_OTLP_GRPC@) @@ -35,7 +31,6 @@ elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@ OR @WITH_OTLP_GRPC@) endif() # CURL and ZLIB: -# Expected TRUE if WITH_HTTP_CLIENT_CURL is enabled and we're building static libraries. if(@WITH_HTTP_CLIENT_CURL@ AND NOT "@BUILD_SHARED_LIBS@") if("@CURL_FOUND@") set(BUILT_WITH_CURL TRUE) @@ -46,7 +41,6 @@ if(@WITH_HTTP_CLIENT_CURL@ AND NOT "@BUILD_SHARED_LIBS@") endif() # nlohmann_json: -# Expected TRUE if both USE_NLOHMANN_JSON is true and the package was found during build. if("@USE_NLOHMANN_JSON@" AND "@nlohmann_json_FOUND@") set(BUILT_WITH_nlohmann_json TRUE) endif() diff --git a/cmake/install/thirdparty-dependency-definitions.cmake b/cmake/thirdparty-dependency-definitions.cmake similarity index 96% rename from cmake/install/thirdparty-dependency-definitions.cmake rename to cmake/thirdparty-dependency-definitions.cmake index c03bb9cd49..77ece1c0a4 100644 --- a/cmake/install/thirdparty-dependency-definitions.cmake +++ b/cmake/thirdparty-dependency-definitions.cmake @@ -18,7 +18,7 @@ set(THIRD_PARTY_DEPENDENCIES_SUPPORTED ) #----------------------------------------------------------------------- -# Flags to determine if find_dependency(dep) or find_dependency(dep CONFIG) should be used +# Flags to determine if CONFIG search mode should be used in find_dependency(...) #----------------------------------------------------------------------- # absl diff --git a/cmake/install/test/CMakeLists.txt b/install/test/cmake/CMakeLists.txt similarity index 79% rename from cmake/install/test/CMakeLists.txt rename to install/test/cmake/CMakeLists.txt index 76d1a579d4..5798246871 100644 --- a/cmake/install/test/CMakeLists.txt +++ b/install/test/cmake/CMakeLists.txt @@ -13,11 +13,11 @@ else() STATUS "CMAKE_CXX_STANDARD is set to default of ${CMAKE_CXX_STANDARD}") endif() -include(${CMAKE_SOURCE_DIR}/../../install/component-definitions.cmake) +include(${CMAKE_SOURCE_DIR}/../../../cmake/component-definitions.cmake) -# If COMPONENTS_TO_TEST is not set, then test all components +# Check that COMPONENTS_TO_TEST is set and contains valid components if(NOT COMPONENTS_TO_TEST) - set(COMPONENTS_TO_TEST ${opentelemetry-cpp_COMPONENTS}) + message(FATAL_ERROR "COMPONENTS_TO_TEST is not set") else() set(COMPONENTS_ARE_VALID TRUE) foreach(component ${COMPONENTS_TO_TEST}) @@ -33,11 +33,10 @@ else() endif() endif() -set(INSTALL_TEST_SRC_DIR "${CMAKE_SOURCE_DIR}/src") +set(INSTALL_TEST_SRC_DIR "${CMAKE_SOURCE_DIR}/../src") enable_testing() -message(STATUS "Testing cmake usage for find_package(opentelemetry ...)") # ----------------------------------------------------------- # CMake Usage tests for find_package(opentelemetry-cpp ...) # @@ -52,7 +51,7 @@ add_test( NAME cmake-usage-no-components-test COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/cmake_usage_tests/no_components -B + ${CMAKE_SOURCE_DIR}/usage_tests/no_components -B build-cmake-usage-no-components-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}) @@ -60,7 +59,7 @@ add_test( NAME cmake-usage-unsorted-components-test COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/cmake_usage_tests/unsorted_components -B + ${CMAKE_SOURCE_DIR}/usage_tests/unsorted_components -B build-cmake-usage-unsorted-components-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}) @@ -68,7 +67,7 @@ add_test( NAME cmake-usage-missing-components-test COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/cmake_usage_tests/missing_components -B + ${CMAKE_SOURCE_DIR}/usage_tests/missing_components -B build-cmake-usage-missing-components-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}) @@ -76,21 +75,20 @@ add_test( NAME cmake-usage-unsupported-components-test COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/cmake_usage_tests/unsupported_components -B + ${CMAKE_SOURCE_DIR}/usage_tests/unsupported_components -B build-cmake-usage-unsupported-components-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}) # ----------------------------------------------------------- # Test the full package install using legacy cmake build instructions # find_package(opentelemetry-cpp CONFIG REQUIRED) -message(STATUS "Testing the full package install") + # Test cmake configuration add_test( NAME full-package-cmake-config-test COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/package_test -B build-full-package-test - -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} + ${CMAKE_COMMAND} --log-level=DEBUG -S ${CMAKE_SOURCE_DIR}/package_test -B + build-full-package-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}) # Build the full package test executable @@ -106,13 +104,12 @@ add_test(NAME full-package-run-test # ----------------------------------------------------------- # Loop over all the components to test foreach(component ${COMPONENTS_TO_TEST}) - message(STATUS "Testing the ${component} component install") # Test cmake configuration add_test( NAME component-${component}-cmake-config-test COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/projects/component_tests/${component} -B + ${CMAKE_SOURCE_DIR}/component_tests/${component} -B build-${component}-test -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}) diff --git a/cmake/install/test/projects/component_tests/api/CMakeLists.txt b/install/test/cmake/component_tests/api/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/api/CMakeLists.txt rename to install/test/cmake/component_tests/api/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_elasticsearch/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_etw/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_etw/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt b/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_in_memory/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt b/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_ostream/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_otlp_common/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_otlp_file/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_otlp_grpc/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt b/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_otlp_http/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt b/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_prometheus/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/exporters_zipkin/CMakeLists.txt rename to install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt b/install/test/cmake/component_tests/ext_common/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/ext_common/CMakeLists.txt rename to install/test/cmake/component_tests/ext_common/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt b/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/ext_http_curl/CMakeLists.txt rename to install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/sdk/CMakeLists.txt b/install/test/cmake/component_tests/sdk/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/sdk/CMakeLists.txt rename to install/test/cmake/component_tests/sdk/CMakeLists.txt diff --git a/cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt b/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/component_tests/shims_opentracing/CMakeLists.txt rename to install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt diff --git a/cmake/install/test/projects/package_test/CMakeLists.txt b/install/test/cmake/package_test/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/package_test/CMakeLists.txt rename to install/test/cmake/package_test/CMakeLists.txt diff --git a/cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt b/install/test/cmake/usage_tests/missing_components/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/cmake_usage_tests/missing_components/CMakeLists.txt rename to install/test/cmake/usage_tests/missing_components/CMakeLists.txt diff --git a/cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt b/install/test/cmake/usage_tests/no_components/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/cmake_usage_tests/no_components/CMakeLists.txt rename to install/test/cmake/usage_tests/no_components/CMakeLists.txt diff --git a/cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/cmake_usage_tests/unsorted_components/CMakeLists.txt rename to install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt diff --git a/cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt similarity index 100% rename from cmake/install/test/projects/cmake_usage_tests/unsupported_components/CMakeLists.txt rename to install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt diff --git a/cmake/install/test/src/test_api.cc b/install/test/src/test_api.cc similarity index 100% rename from cmake/install/test/src/test_api.cc rename to install/test/src/test_api.cc diff --git a/cmake/install/test/src/test_exporters_elasticsearch.cc b/install/test/src/test_exporters_elasticsearch.cc similarity index 100% rename from cmake/install/test/src/test_exporters_elasticsearch.cc rename to install/test/src/test_exporters_elasticsearch.cc diff --git a/cmake/install/test/src/test_exporters_etw.cc b/install/test/src/test_exporters_etw.cc similarity index 100% rename from cmake/install/test/src/test_exporters_etw.cc rename to install/test/src/test_exporters_etw.cc diff --git a/cmake/install/test/src/test_exporters_in_memory.cc b/install/test/src/test_exporters_in_memory.cc similarity index 100% rename from cmake/install/test/src/test_exporters_in_memory.cc rename to install/test/src/test_exporters_in_memory.cc diff --git a/cmake/install/test/src/test_exporters_ostream.cc b/install/test/src/test_exporters_ostream.cc similarity index 100% rename from cmake/install/test/src/test_exporters_ostream.cc rename to install/test/src/test_exporters_ostream.cc diff --git a/cmake/install/test/src/test_exporters_otlp_common.cc b/install/test/src/test_exporters_otlp_common.cc similarity index 100% rename from cmake/install/test/src/test_exporters_otlp_common.cc rename to install/test/src/test_exporters_otlp_common.cc diff --git a/cmake/install/test/src/test_exporters_otlp_file.cc b/install/test/src/test_exporters_otlp_file.cc similarity index 100% rename from cmake/install/test/src/test_exporters_otlp_file.cc rename to install/test/src/test_exporters_otlp_file.cc diff --git a/cmake/install/test/src/test_exporters_otlp_grpc.cc b/install/test/src/test_exporters_otlp_grpc.cc similarity index 100% rename from cmake/install/test/src/test_exporters_otlp_grpc.cc rename to install/test/src/test_exporters_otlp_grpc.cc diff --git a/cmake/install/test/src/test_exporters_otlp_http.cc b/install/test/src/test_exporters_otlp_http.cc similarity index 100% rename from cmake/install/test/src/test_exporters_otlp_http.cc rename to install/test/src/test_exporters_otlp_http.cc diff --git a/cmake/install/test/src/test_exporters_prometheus.cc b/install/test/src/test_exporters_prometheus.cc similarity index 100% rename from cmake/install/test/src/test_exporters_prometheus.cc rename to install/test/src/test_exporters_prometheus.cc diff --git a/cmake/install/test/src/test_exporters_zipkin.cc b/install/test/src/test_exporters_zipkin.cc similarity index 100% rename from cmake/install/test/src/test_exporters_zipkin.cc rename to install/test/src/test_exporters_zipkin.cc diff --git a/cmake/install/test/src/test_ext_common.cc b/install/test/src/test_ext_common.cc similarity index 100% rename from cmake/install/test/src/test_ext_common.cc rename to install/test/src/test_ext_common.cc diff --git a/cmake/install/test/src/test_ext_http_curl.cc b/install/test/src/test_ext_http_curl.cc similarity index 100% rename from cmake/install/test/src/test_ext_http_curl.cc rename to install/test/src/test_ext_http_curl.cc diff --git a/cmake/install/test/src/test_sdk.cc b/install/test/src/test_sdk.cc similarity index 75% rename from cmake/install/test/src/test_sdk.cc rename to install/test/src/test_sdk.cc index ee16888e5b..13c4d19245 100644 --- a/cmake/install/test/src/test_sdk.cc +++ b/install/test/src/test_sdk.cc @@ -68,6 +68,7 @@ class NoopLogRecordable : public logs_sdk::Recordable class NoopLogRecordExporter : public logs_sdk::LogRecordExporter { public: + ~NoopLogRecordExporter() override = default; std::unique_ptr MakeRecordable() noexcept override { return std::move(std::unique_ptr{new NoopLogRecordable()}); @@ -120,6 +121,7 @@ class NoopSpanRecordable : public trace_sdk::Recordable class NoopSpanExporter : public trace_sdk::SpanExporter { public: + ~NoopSpanExporter() override = default; std::unique_ptr MakeRecordable() noexcept override { return std::move(std::unique_ptr{new NoopSpanRecordable()}); @@ -144,6 +146,7 @@ class NoopSpanExporter : public trace_sdk::SpanExporter class NoopPushMetricExporter : public metrics_sdk::PushMetricExporter { public: + ~NoopPushMetricExporter() override = default; common_sdk::ExportResult Export( const metrics_sdk::ResourceMetrics &resource_metrics) noexcept override { @@ -189,52 +192,71 @@ TEST(SdkInstallTest, ResourceDetectorCheck) 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_sdk::Provider::SetLoggerProvider(new_provider); + { + 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"); - static_cast(provider.get())->ForceFlush(); + { + 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 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(); - static_cast(provider.get())->ForceFlush(); + { + 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 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); - static_cast(provider.get())->ForceFlush(); + { + 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/cmake/install/test/src/test_shims_opentracing.cc b/install/test/src/test_shims_opentracing.cc similarity index 100% rename from cmake/install/test/src/test_shims_opentracing.cc rename to install/test/src/test_shims_opentracing.cc From e239be72d137801ae7ac81214dcbb6a6b978159e Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 18 Feb 2025 16:10:12 -0700 Subject: [PATCH 12/28] set -E when calling the install scripts --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 299b294972..0f8058e3f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -554,9 +554,9 @@ jobs: PROTOBUF_VERSION: '23.3' GRPC_VERSION: 'v1.55.0' run: | - sudo ./ci/install_abseil.sh - sudo ./ci/install_protobuf.sh - sudo ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil + 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 - name: build and test run: | ./ci/do_ci.sh cmake.install.test From 60a21afaf2125d54085569fa1f20e1ef8d081bac Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Thu, 6 Mar 2025 06:01:44 -0700 Subject: [PATCH 13/28] make nlohmann_json a build time dependency only for otlp file and otlp http. Add json dependecy to the etw exporter. Add checks for the json target in install tests --- cmake/thirdparty-dependency-definitions.cmake | 3 +-- exporters/otlp/CMakeLists.txt | 13 ++++++++++--- .../exporters_elasticsearch/CMakeLists.txt | 4 ++++ .../component_tests/exporters_etw/CMakeLists.txt | 4 ++++ .../component_tests/exporters_zipkin/CMakeLists.txt | 4 ++++ .../test/cmake/component_tests/sdk/CMakeLists.txt | 4 ++++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmake/thirdparty-dependency-definitions.cmake b/cmake/thirdparty-dependency-definitions.cmake index 77ece1c0a4..f2b45f097e 100644 --- a/cmake/thirdparty-dependency-definitions.cmake +++ b/cmake/thirdparty-dependency-definitions.cmake @@ -70,10 +70,9 @@ set(THIRD_PARTY_CURL_DEPENDENT_COMPONENTS # Components that require nlohmann_json set(THIRD_PARTY_nlohmann_json_DEPENDENT_COMPONENTS - exporters_otlp_file - exporters_otlp_http exporters_zipkin exporters_elasticsearch + exporters_etw ) # Components that require Protobuf diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index a596298c5a..64537c7644 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -120,8 +120,11 @@ if(WITH_OTLP_HTTP) target_link_libraries( opentelemetry_exporter_otlp_http_client PUBLIC opentelemetry_sdk opentelemetry_ext - PRIVATE opentelemetry_proto opentelemetry_http_client_curl - nlohmann_json::nlohmann_json) + PRIVATE opentelemetry_proto opentelemetry_http_client_curl) + + target_link_libraries(opentelemetry_exporter_otlp_http_client + PRIVATE $) + if(TARGET absl::strings) target_link_libraries(opentelemetry_exporter_otlp_http_client PUBLIC absl::strings) @@ -199,7 +202,11 @@ if(WITH_OTLP_FILE) target_link_libraries( opentelemetry_exporter_otlp_file_client PUBLIC opentelemetry_sdk opentelemetry_common - PRIVATE opentelemetry_proto nlohmann_json::nlohmann_json) + PRIVATE opentelemetry_proto) + + target_link_libraries(opentelemetry_exporter_otlp_file_client + PRIVATE $) + if(TARGET absl::strings) target_link_libraries(opentelemetry_exporter_otlp_file_client PUBLIC absl::strings) diff --git a/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt index ede48beb17..dce7700ec7 100644 --- a/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt @@ -6,6 +6,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) diff --git a/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt index 6cb9ecaa7e..1e164bc0cc 100644 --- a/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt @@ -6,6 +6,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) diff --git a/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt index 40c0fda0b3..9bbff6f05a 100644 --- a/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt @@ -6,6 +6,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) diff --git a/install/test/cmake/component_tests/sdk/CMakeLists.txt b/install/test/cmake/component_tests/sdk/CMakeLists.txt index 3f3d6d277b..0170be056c 100644 --- a/install/test/cmake/component_tests/sdk/CMakeLists.txt +++ b/install/test/cmake/component_tests/sdk/CMakeLists.txt @@ -6,6 +6,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) From 66088b1f36c33bfd526e80891adbb10753808d1d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Thu, 6 Mar 2025 06:23:52 -0700 Subject: [PATCH 14/28] format fix --- exporters/otlp/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 5fadf54672..c2215f3057 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -204,8 +204,7 @@ if(WITH_OTLP_FILE) target_link_libraries( opentelemetry_exporter_otlp_file_client PUBLIC opentelemetry_sdk opentelemetry_common - PRIVATE opentelemetry_proto - $) + PRIVATE opentelemetry_proto $) if(TARGET absl::strings) target_link_libraries(opentelemetry_exporter_otlp_file_client From 50aee213db98fde9adb178d48cc0670701f9a42f Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Mar 2025 04:43:37 -0700 Subject: [PATCH 15/28] fix markdown table alignment. Add changelog entry --- CHANGELOG.md | 3 +++ INSTALL.md | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7028d53118..95247a372b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ Increment the: * [DEVCONTAINER] Support customization and run as non-root user [#3270](https://github.com/open-telemetry/opentelemetry-cpp/pull/3270) +* [INSTALL] Add support for cmake components to the package + [#3270](https://github.com/open-telemetry/opentelemetry-cpp/pull/3220) + Important changes: * [SDK] Support OTEL_SDK_DISABLED environment variable diff --git a/INSTALL.md b/INSTALL.md index 296dd6de4b..0c415cbcdc 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -174,8 +174,8 @@ The following table provides the mapping between components and targets. Compone and targets available in the installation depends on the opentelemetry-cpp package build configuration. -| Component | Targets | -|----------------------------|---------------------------------------------------------------------------------------------------| +| Component | Targets | +|----------------------------|--------------------------------------------------------------------------------------------------| | **api** | opentelemetry-cpp::api | | **sdk** | opentelemetry-cpp::sdk | | | opentelemetry-cpp::version | @@ -188,25 +188,25 @@ build configuration. | **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 | +| | opentelemetry-cpp::in_memory_metric_exporter | | **exporters_ostream** | opentelemetry-cpp::ostream_log_record_exporter | -| | opentelemetry-cpp::ostream_metrics_exporter | -| | opentelemetry-cpp::ostream_span_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 | +| | 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 | +| | 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 | +| | 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 | From 28be5f9ee35265368a32c604cd8e297d0d025afd Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 23 Mar 2025 21:26:25 -0600 Subject: [PATCH 16/28] windows components install tests --- .devcontainer/Dockerfile.dev | 2 +- .github/workflows/ci.yml | 16 +- ci/do_ci.ps1 | 198 ++++++++++++++++++ ci/setup_windows_ci_environment.ps1 | 3 + cmake/component-definitions.cmake | 10 - .../opentelemetry-cpp-config.cmake.in | 6 +- install/test/cmake/CMakeLists.txt | 64 +++--- .../cmake/component_tests/api/CMakeLists.txt | 4 +- .../exporters_elasticsearch/CMakeLists.txt | 4 +- .../exporters_etw/CMakeLists.txt | 2 +- .../exporters_in_memory/CMakeLists.txt | 3 +- .../exporters_ostream/CMakeLists.txt | 4 +- .../exporters_otlp_common/CMakeLists.txt | 2 +- .../exporters_otlp_file/CMakeLists.txt | 4 +- .../exporters_otlp_grpc/CMakeLists.txt | 8 +- .../exporters_otlp_http/CMakeLists.txt | 4 +- .../exporters_prometheus/CMakeLists.txt | 2 +- .../exporters_zipkin/CMakeLists.txt | 2 +- .../component_tests/ext_common/CMakeLists.txt | 2 +- .../component_tests/ext_dll/CMakeLists.txt | 22 ++ .../ext_http_curl/CMakeLists.txt | 4 +- .../cmake/component_tests/sdk/CMakeLists.txt | 4 +- .../shims_opentracing/CMakeLists.txt | 2 +- .../test/cmake/package_test/CMakeLists.txt | 16 +- .../test/src/test_exporters_elasticsearch.cc | 12 +- install/test/src/test_exporters_etw.cc | 7 +- install/test/src/test_ext_dll.cc | 116 ++++++++++ 27 files changed, 447 insertions(+), 76 deletions(-) create mode 100644 install/test/cmake/component_tests/ext_dll/CMakeLists.txt create mode 100644 install/test/src/test_ext_dll.cc diff --git a/.devcontainer/Dockerfile.dev b/.devcontainer/Dockerfile.dev index 8902aa181a..6e19e32f8e 100644 --- a/.devcontainer/Dockerfile.dev +++ b/.devcontainer/Dockerfile.dev @@ -30,7 +30,7 @@ RUN cd /opt/ci && bash setup_ci_environment.sh RUN cd /opt && bash ci/setup_googletest.sh \ && bash ci/install_abseil.sh \ && bash ci/install_protobuf.sh \ - && bash ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil + && bash ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil-cpp ADD https://github.com/bazelbuild/bazelisk/releases/download/v1.22.1/bazelisk-linux-amd64 /usr/local/bin diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8437e2d02..d880678e8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -567,7 +567,7 @@ jobs: 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 + sudo -E ./ci/setup_grpc.sh -r $GRPC_VERSION -s $CXX_STANDARD -p protobuf -p abseil-cpp - name: build and test run: | ./ci/do_ci.sh cmake.install.test @@ -860,6 +860,8 @@ jobs: run: ./ci/do_ci.ps1 cmake.dll.cxx20.test - name: run otprotocol test (DLL build) run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test + - name: run cmake install test + run: ./ci/do_ci.ps1 cmake.dll.install.test windows_with_async_export: name: CMake (With async export) -> exporter proto @@ -903,6 +905,18 @@ jobs: - name: run tests run: ./ci/do_ci.ps1 cmake.test_example_plugin + windows_cmake_install_test: + name: Windows CMake install test + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Setup Windows CI Environment + run: ./ci/setup_windows_ci_environment.ps1 + - name: Run Tests + run: ./ci/do_ci.ps1 cmake.install.test + code_coverage: name: Code coverage runs-on: ubuntu-22.04 diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 66f983065f..6b9b41cda3 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,199 @@ 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_ABSEIL=OFF ` + -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" + rm -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_ABSEIL=OFF ` + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` + -DWITH_ETW=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" + + 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/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 index 0135438b9f..74087beff4 100644 --- a/cmake/component-definitions.cmake +++ b/cmake/component-definitions.cmake @@ -152,18 +152,8 @@ set(COMPONENT_ext_dll_COMPONENT_DEPENDS 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 ) set(COMPONENT_exporters_in_memory_COMPONENT_DEPENDS diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in index 3f43bb1f2f..46655f8ff6 100644 --- a/cmake/templates/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -200,9 +200,11 @@ 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}) - list(APPEND OPENTELEMETRY_CPP_LIBRARIES ${_TARGET}) + if(TARGET "${_TARGET}" AND NOT "${_TARGET}" STREQUAL "${DLL_TARGET}") + list(APPEND OPENTELEMETRY_CPP_LIBRARIES "${_TARGET}") endif() endforeach() diff --git a/install/test/cmake/CMakeLists.txt b/install/test/cmake/CMakeLists.txt index 5798246871..1c8b69fc07 100644 --- a/install/test/cmake/CMakeLists.txt +++ b/install/test/cmake/CMakeLists.txt @@ -4,35 +4,48 @@ cmake_minimum_required(VERSION 3.10) project(opentelemetry-cpp-component-install-tests LANGUAGES CXX) -if(CXX_STANDARD) - message(STATUS "CMAKE_CXX_STANDARD is set from CXX_STANDARD=${CXX_STANDARD}") - set(CMAKE_CXX_STANDARD $CXX_STANDARD) -else() - set(CMAKE_CXX_STANDARD 14) - message( - STATUS "CMAKE_CXX_STANDARD is set to default of ${CMAKE_CXX_STANDARD}") +if(NOT INSTALL_TEST_CMAKE_OPTIONS) + set(INSTALL_TEST_CMAKE_OPTIONS + "-DCMAKE_CXX_STANDARD=14 -DCMAKE_BUILD_TYPE=Debug") endif() -include(${CMAKE_SOURCE_DIR}/../../../cmake/component-definitions.cmake) +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) -# Check that COMPONENTS_TO_TEST is set and contains valid components -if(NOT COMPONENTS_TO_TEST) - message(FATAL_ERROR "COMPONENTS_TO_TEST is not set") +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 ${COMPONENTS_TO_TEST}) - if(NOT component IN_LIST opentelemetry-cpp_COMPONENTS) + foreach(component ${INSTALL_TEST_COMPONENTS}) + if(NOT component IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) message( ERROR - " Component ${component} is not a valid opentelemetry-cpp component") + " Component ${component} is not an installed opentelemetry-cpp component" + ) set(COMPONENTS_ARE_VALID FALSE) endif() endforeach() if(NOT COMPONENTS_ARE_VALID) - message(FATAL_ERROR "COMPONENTS_TO_TEST contains invalid components") + 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() @@ -53,7 +66,7 @@ add_test( ${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}) + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) add_test( NAME cmake-usage-unsorted-components-test @@ -61,7 +74,7 @@ add_test( ${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}) + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) add_test( NAME cmake-usage-missing-components-test @@ -69,7 +82,7 @@ add_test( ${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}) + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) add_test( NAME cmake-usage-unsupported-components-test @@ -77,7 +90,7 @@ add_test( ${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}) + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) # ----------------------------------------------------------- # Test the full package install using legacy cmake build instructions @@ -88,8 +101,10 @@ 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} - -DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}) + 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 @@ -103,15 +118,16 @@ add_test(NAME full-package-run-test # ----------------------------------------------------------- # Loop over all the components to test -foreach(component ${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} - -DINSTALL_TEST_SRC_DIR=${INSTALL_TEST_SRC_DIR}) + 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 diff --git a/install/test/cmake/component_tests/api/CMakeLists.txt b/install/test/cmake/component_tests/api/CMakeLists.txt index 0721e37797..e4a963ab81 100644 --- a/install/test/cmake/component_tests/api/CMakeLists.txt +++ b/install/test/cmake/component_tests/api/CMakeLists.txt @@ -11,7 +11,7 @@ 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::Main) +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 index dce7700ec7..3019aa1d2a 100644 --- a/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt @@ -17,7 +17,7 @@ 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::Main) + 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 index 1e164bc0cc..4860a2f1f5 100644 --- a/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_etw/CMakeLists.txt @@ -15,6 +15,6 @@ 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::Main) + 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 index 6c05935e81..e24b7761fa 100644 --- a/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_in_memory/CMakeLists.txt @@ -14,6 +14,7 @@ add_executable(exporters_in_memory_test target_link_libraries( exporters_in_memory_test PRIVATE opentelemetry-cpp::in_memory_span_exporter - opentelemetry-cpp::in_memory_metric_exporter GTest::GTest GTest::Main) + 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 index 42226d6492..eec0f26a7e 100644 --- a/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_ostream/CMakeLists.txt @@ -15,6 +15,8 @@ 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::Main) + 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 index 5a78f56789..e7bd38fe1f 100644 --- a/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt @@ -18,6 +18,6 @@ add_executable(exporters_otlp_common_test target_link_libraries( exporters_otlp_common_test PRIVATE opentelemetry-cpp::proto opentelemetry-cpp::otlp_recordable - GTest::GTest GTest::Main) + 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 index 14d4898bbb..e625a73bb3 100644 --- a/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries( opentelemetry-cpp::otlp_file_exporter opentelemetry-cpp::otlp_file_log_record_exporter opentelemetry-cpp::otlp_file_metric_exporter - GTest::GTest - GTest::Main) + 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 index aa3047a684..62665d10c8 100644 --- a/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_otlp_grpc/CMakeLists.txt @@ -21,12 +21,10 @@ 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::proto_grpc - opentelemetry-cpp::otlp_grpc_client - opentelemetry-cpp::otlp_grpc_exporter + PRIVATE opentelemetry-cpp::otlp_grpc_exporter opentelemetry-cpp::otlp_grpc_log_record_exporter opentelemetry-cpp::otlp_grpc_metrics_exporter - GTest::GTest - GTest::Main) + 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 index 7cab341374..ca555c05cc 100644 --- a/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_otlp_http/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries( opentelemetry-cpp::otlp_http_exporter opentelemetry-cpp::otlp_http_log_record_exporter opentelemetry-cpp::otlp_http_metric_exporter - GTest::GTest - GTest::Main) + 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 index 776cff300b..78eaa26136 100644 --- a/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_prometheus/CMakeLists.txt @@ -17,6 +17,6 @@ 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::Main) + 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 index 9bbff6f05a..cbbb7ba887 100644 --- a/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt +++ b/install/test/cmake/component_tests/exporters_zipkin/CMakeLists.txt @@ -17,6 +17,6 @@ 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::Main) + 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 index 51cbb908d0..0d6abde19f 100644 --- a/install/test/cmake/component_tests/ext_common/CMakeLists.txt +++ b/install/test/cmake/component_tests/ext_common/CMakeLists.txt @@ -11,6 +11,6 @@ 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::Main) + 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 index 5fb9fff695..caafd3e766 100644 --- a/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt +++ b/install/test/cmake/component_tests/ext_http_curl/CMakeLists.txt @@ -15,7 +15,7 @@ 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::Main) + 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 index 0170be056c..9dd828b65c 100644 --- a/install/test/cmake/component_tests/sdk/CMakeLists.txt +++ b/install/test/cmake/component_tests/sdk/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries( opentelemetry-cpp::trace opentelemetry-cpp::metrics opentelemetry-cpp::logs - GTest::GTest - GTest::Main) + 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 index fbe3fbaa4e..34187da294 100644 --- a/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt +++ b/install/test/cmake/component_tests/shims_opentracing/CMakeLists.txt @@ -17,6 +17,6 @@ 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::Main) + 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 index 5066b7abaf..b14c91bffb 100644 --- a/install/test/cmake/package_test/CMakeLists.txt +++ b/install/test/cmake/package_test/CMakeLists.txt @@ -51,25 +51,21 @@ if(NOT OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) message(FATAL_ERROR "OPENTELEMETRY_CPP_COMPONENTS_INSTALLED is empty") endif() -# Set the components to test. If not set, use all installed components. -if(NOT COMPONENTS_TO_TEST) - message( - STATUS - "COMPONENTS_TO_TEST is empty. Setting to OPENTELEMETRY_CPP_COMPONENTS_INSTALLED" - ) - set(COMPONENTS_TO_TEST ${OPENTELEMETRY_CPP_COMPONENTS_INSTALLED}) +if(NOT INSTALL_TEST_COMPONENTS) + message(FATAL_ERROR "INSTALL_TEST_COMPONENTS is empty") endif() message( STATUS - "Testing the full package install on components = ${COMPONENTS_TO_TEST}") + "Testing the full package install on components = ${INSTALL_TEST_COMPONENTS}" +) find_package(GTest REQUIRED) include(GoogleTest) add_executable(full_test) -foreach(component IN LISTS COMPONENTS_TO_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") @@ -77,6 +73,6 @@ endforeach() target_include_directories(full_test PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) target_link_libraries(full_test PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES} - GTest::GTest GTest::Main) + GTest::gtest GTest::gtest_main) gtest_discover_tests(full_test) diff --git a/install/test/src/test_exporters_elasticsearch.cc b/install/test/src/test_exporters_elasticsearch.cc index a2884fc714..f18d59cf1e 100644 --- a/install/test/src/test_exporters_elasticsearch.cc +++ b/install/test/src/test_exporters_elasticsearch.cc @@ -4,9 +4,17 @@ #include #include +#include + +namespace logs_exporter = opentelemetry::exporter::logs; +namespace sdklogs = opentelemetry::sdk::logs; TEST(ExportersElasticSearchInstall, ElasticsearchLogRecordExporter) { - auto options = opentelemetry::exporter::logs::ElasticsearchExporterOptions(); - auto exporter = opentelemetry::exporter::logs::ElasticsearchLogRecordExporter(options); + 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 index cd8016dfa0..12a5d292c7 100644 --- a/install/test/src/test_exporters_etw.cc +++ b/install/test/src/test_exporters_etw.cc @@ -23,6 +23,8 @@ TEST(ExportersEtwInstall, LoggerProvider) 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, @@ -39,6 +41,7 @@ TEST(ExportersEtwInstall, TracerProvider) {"enableRelatedActivityId", false}, {"enableAutoParent", false}}); auto tracer = tp.GetTracer(providerName); + ASSERT_TRUE(tracer != nullptr); { auto aSpan = tracer->StartSpan("A.min"); auto aScope = tracer->WithActiveSpan(aSpan); @@ -54,7 +57,9 @@ TEST(ExportersEtwInstall, TracerProvider) } EXPECT_NO_THROW(aSpan->End()); } - tracer->CloseWithMicroseconds(0); +# 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_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 From b189f7e527886d3aa7f74252f46969ec772f46d2 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 23 Mar 2025 21:30:20 -0600 Subject: [PATCH 17/28] record thirdparty dependency versions on install. Use module search mode for older versions of protobuf. Fix curl and nlohmann-json flags --- CMakeLists.txt | 17 ++++++ cmake/find-package-support-functions.cmake | 6 +- .../thirdparty-built-with-flags.cmake.in | 57 ++++++++++++++++++- cmake/thirdparty-dependency-definitions.cmake | 23 -------- 4 files changed, 76 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b419bf434c..cb7bebae26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,6 +388,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 diff --git a/cmake/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake index 29097cf461..5cb9f99443 100644 --- a/cmake/find-package-support-functions.cmake +++ b/cmake/find-package-support-functions.cmake @@ -161,7 +161,6 @@ function (is_dependency_required dependency_in components_in is_required_out) 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) - message(DEBUG "is_dependency_required: ${dependency_in} is not required because that package was not built with it.") else() foreach(component IN LISTS ${components_in}) set(is_required_by_component FALSE) @@ -205,6 +204,11 @@ function(find_required_dependencies components_in) 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/templates/thirdparty-built-with-flags.cmake.in b/cmake/templates/thirdparty-built-with-flags.cmake.in index ddbd155612..84d7e130ed 100644 --- a/cmake/templates/thirdparty-built-with-flags.cmake.in +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -25,13 +25,13 @@ if(@WITH_ABSEIL@) elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@ OR @WITH_OTLP_GRPC@) if( @WITH_OTLP_GRPC@ ) set(BUILT_WITH_absl TRUE) - elseif("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0") + elseif(@Protobuf_VERSION@ VERSION_GREATER_EQUAL 3.22.0) set(BUILT_WITH_absl TRUE) endif() endif() # CURL and ZLIB: -if(@WITH_HTTP_CLIENT_CURL@ AND NOT "@BUILD_SHARED_LIBS@") +if(@WITH_HTTP_CLIENT_CURL@) if("@CURL_FOUND@") set(BUILT_WITH_CURL TRUE) endif() @@ -41,7 +41,7 @@ if(@WITH_HTTP_CLIENT_CURL@ AND NOT "@BUILD_SHARED_LIBS@") endif() # nlohmann_json: -if("@USE_NLOHMANN_JSON@" AND "@nlohmann_json_FOUND@") +if("@USE_NLOHMANN_JSON@") set(BUILT_WITH_nlohmann_json TRUE) endif() @@ -66,4 +66,55 @@ if(@WITH_OPENTRACING@) set(BUILT_WITH_OpenTracing TRUE) endif() +#----------------------------------------------------------------------- +# Third party dependency versions +#----------------------------------------------------------------------- +if(BUILT_WITH_absl) + set(BUILT_WITH_absl_VERSION @absl_VERSION@) +endif() + +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_absl_USE_CONFIG TRUE) +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 index f2b45f097e..fca76ea31c 100644 --- a/cmake/thirdparty-dependency-definitions.cmake +++ b/cmake/thirdparty-dependency-definitions.cmake @@ -17,29 +17,6 @@ set(THIRD_PARTY_DEPENDENCIES_SUPPORTED OpenTracing ) -#----------------------------------------------------------------------- -# Flags to determine if CONFIG search mode should be used in find_dependency(...) -#----------------------------------------------------------------------- - -# absl -set(FIND_DEPENDENCY_absl_USE_CONFIG TRUE) -# Threads -set(FIND_DEPENDENCY_Threads_USE_CONFIG FALSE) -# ZLIB -set(FIND_DEPENDENCY_ZLIB_USE_CONFIG FALSE) -# CURL -set(FIND_DEPENDENCY_CURL_USE_CONFIG FALSE) -# nlohmann_json -set(FIND_DEPENDENCY_nlohmann_json_USE_CONFIG TRUE) -# Protobuf -set(FIND_DEPENDENCY_Protobuf_USE_CONFIG TRUE) -# gRPC -set(FIND_DEPENDENCY_gRPC_USE_CONFIG TRUE) -# prometheus-cpp -set(FIND_DEPENDENCY_prometheus-cpp_USE_CONFIG TRUE) -# OpenTracing -set(FIND_DEPENDENCY_OpenTracing_USE_CONFIG TRUE) - #----------------------------------------------------------------------- # THIRD_PARTY to COMPONENT dependencies # These are the components that may require the third party dependency From 218e8f7a5ad36dabeba0a42277f54dbda865bc39 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 23 Mar 2025 21:35:10 -0600 Subject: [PATCH 18/28] conan package install support. DockerFile that uses conan to install all dependencies --- .devcontainer/Dockerfile.conan | 52 +++++++++++++++++++ ci/do_ci.sh | 82 +++++++++++++++++++++++++++--- ci/setup_grpc.sh | 9 ++++ install/conan/conanfile_latest.txt | 33 ++++++++++++ install/conan/conanfile_stable.txt | 33 ++++++++++++ 5 files changed, 202 insertions(+), 7 deletions(-) create mode 100644 .devcontainer/Dockerfile.conan create mode 100644 install/conan/conanfile_latest.txt create mode 100644 install/conan/conanfile_stable.txt diff --git a/.devcontainer/Dockerfile.conan b/.devcontainer/Dockerfile.conan new file mode 100644 index 0000000000..c85e68a7ca --- /dev/null +++ b/.devcontainer/Dockerfile.conan @@ -0,0 +1,52 @@ +# 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 \ + 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/ci/do_ci.sh b/ci/do_ci.sh index 4dd150e03d..2d4aa5e69b 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -83,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 @@ -242,10 +257,23 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then 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" + "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}" \ - "-DCOMPONENTS_TO_TEST=shims_opentracing" + "-DINSTALL_TEST_CMAKE_OPTIONS=${CMAKE_OPTIONS_STRING}" \ + "-DINSTALL_TEST_COMPONENTS=${EXPECTED_COMPONENTS}" ctest --test-dir "${BUILD_DIR}/install_test" --output-on-failure exit 0 elif [[ "$1" == "cmake.c++20.test" ]]; then @@ -423,14 +451,29 @@ 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_ABSEIL=ON \ + -DWITH_ABI_VERSION_1=OFF \ + -DWITH_ABI_VERSION_2=ON \ + -DWITH_ABSEIL=OFF \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=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 \ @@ -439,15 +482,40 @@ elif [[ "$1" == "cmake.install.test" ]]; then -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ + -DWITH_EXAMPLES=ON \ -DOPENTELEMETRY_INSTALL=ON \ "${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" + "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}" \ - "-DCOMPONENTS_TO_TEST=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" + "-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 diff --git a/ci/setup_grpc.sh b/ci/setup_grpc.sh index dc78c172a8..62f06aafe9 100755 --- a/ci/setup_grpc.sh +++ b/ci/setup_grpc.sh @@ -101,6 +101,7 @@ if [[ $build_internal_abseil_cpp -ne 0 ]]; then ABSEIL_CPP_BUILD_OPTIONS=( -DCMAKE_BUILD_TYPE=Release + -DCMAKE_CXX_STANDARD=${std_version} -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ) @@ -117,6 +118,14 @@ GRPC_BUILD_OPTIONS=( -DgRPC_INSTALL=ON -DCMAKE_CXX_STANDARD=${std_version} -DgRPC_BUILD_TESTS=OFF + -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF + -DgRPC_BUILD_GRPC_JAVA_PLUGIN=OFF + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF + -DgRPC_BUILD_GRPCPP_OTEL_PLUGIN=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR ) diff --git a/install/conan/conanfile_latest.txt b/install/conan/conanfile_latest.txt new file mode 100644 index 0000000000..1d62ddddcd --- /dev/null +++ b/install/conan/conanfile_latest.txt @@ -0,0 +1,33 @@ +[requires] +zlib/1.3.1 +libcurl/8.5.0 +abseil/20240116.2 +protobuf/5.27.0 +grpc/1.69.0 +nlohmann_json/3.11.3 +prometheus-cpp/1.3.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 + +[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/conan/conanfile_stable.txt b/install/conan/conanfile_stable.txt new file mode 100644 index 0000000000..5351b601c7 --- /dev/null +++ b/install/conan/conanfile_stable.txt @@ -0,0 +1,33 @@ +[requires] +zlib/1.2.13 +libcurl/8.5.0 +abseil/20230125.3 +protobuf/3.21.12 +grpc/1.54.3 +nlohmann_json/3.11.3 +prometheus-cpp/1.3.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 + +[test_requires] +gtest/1.14.0 +benchmark/1.9.1 + +[generators] +CMakeToolchain +CMakeDeps + +[layout] +cmake_layout \ No newline at end of file From 72999956668fdee319d5bd9e66150b4e89afd85a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 24 Mar 2025 23:03:23 -0600 Subject: [PATCH 19/28] update install.md with the version --- INSTALL.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 0c415cbcdc..a009f00434 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -147,11 +147,9 @@ target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) #### Using opentelemetry-cpp package components -> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v.TODO`. -> **Status:** [`Development`](https://opentelemetry.io/docs/specs/otel/document-status/) +> **Note:** `opentelemetry-cpp` CMake package components were introduced in `v1.21.0` -The `opentelemetry-cpp` package includes components to enable selective inclusion -of its CMake targets and their dependencies using the `COMPONENTS` argument to +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`. From b028914c8545b436ffc608d6f5caab6ef95dc458 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 24 Mar 2025 23:03:43 -0600 Subject: [PATCH 20/28] add curl link to zipkin test --- exporters/zipkin/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index af91c496dd..52b7af913e 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -64,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 From d2a423ea98c9c8821e6363be4c5f4286748c7d07 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 25 Mar 2025 13:04:03 -0600 Subject: [PATCH 21/28] fix opentracing and dll test in ci scripts. add opentracing to the conan files. update versions in conan files --- .devcontainer/Dockerfile.conan | 3 +++ ci/do_ci.ps1 | 17 +++++++++++++++-- ci/do_ci.sh | 13 +++++++++++-- install/conan/conanfile_latest.txt | 12 +++++++++--- install/conan/conanfile_stable.txt | 8 +++++++- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/.devcontainer/Dockerfile.conan b/.devcontainer/Dockerfile.conan index c85e68a7ca..44b0dfdff4 100644 --- a/.devcontainer/Dockerfile.conan +++ b/.devcontainer/Dockerfile.conan @@ -14,6 +14,9 @@ RUN apt update && apt install -y \ ninja-build \ clang-format \ clang-tidy \ + autoconf \ + automake \ + libtool \ python3-pip RUN pip install conan --break-system-packages diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 6b9b41cda3..bbc4f4d765 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -458,7 +458,8 @@ switch ($action) { } "cmake.dll.install.test" { cd "$BUILD_DIR" - rm -Recurse -Force "$INSTALL_TEST_DIR\*" + Remove-Item -Recurse -Force "$BUILD_DIR\*" + Remove-Item -Recurse -Force "$INSTALL_TEST_DIR\*" $CMAKE_OPTIONS = @( "-DCMAKE_CXX_STANDARD=17", @@ -475,8 +476,20 @@ switch ($action) { -DWITH_ABSEIL=OFF ` -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` + -DWITH_ASYNC_EXPORT_PREVIEW=ON ` -DWITH_ETW=ON ` - -DOPENTELEMETRY_INSTALL=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) { diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 2d4aa5e69b..4b72331b92 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -245,6 +245,16 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then make test exit 0 elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + 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.install.test" ]]; then cd "${BUILD_DIR}" rm -rf * rm -rf ${INSTALL_TEST_DIR}/* @@ -262,7 +272,6 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then "api" "sdk" "ext_common" - "ext_http_curl" "exporters_in_memory" "exporters_ostream" "shims_opentracing" @@ -273,7 +282,7 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then "${CMAKE_OPTIONS[@]}" \ "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ "-DINSTALL_TEST_CMAKE_OPTIONS=${CMAKE_OPTIONS_STRING}" \ - "-DINSTALL_TEST_COMPONENTS=${EXPECTED_COMPONENTS}" + "-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 diff --git a/install/conan/conanfile_latest.txt b/install/conan/conanfile_latest.txt index 1d62ddddcd..90a832eb1d 100644 --- a/install/conan/conanfile_latest.txt +++ b/install/conan/conanfile_latest.txt @@ -1,11 +1,15 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + [requires] zlib/1.3.1 -libcurl/8.5.0 +libcurl/8.12.1 abseil/20240116.2 protobuf/5.27.0 -grpc/1.69.0 +grpc/1.67.1 nlohmann_json/3.11.3 prometheus-cpp/1.3.0 +opentracing-cpp/1.6.0 [options] grpc/*:fPIC=True @@ -20,9 +24,11 @@ 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 +gtest/1.16.0 benchmark/1.9.1 [generators] diff --git a/install/conan/conanfile_stable.txt b/install/conan/conanfile_stable.txt index 5351b601c7..796fdaa412 100644 --- a/install/conan/conanfile_stable.txt +++ b/install/conan/conanfile_stable.txt @@ -1,11 +1,15 @@ +# 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.11.3 +nlohmann_json/3.10.5 prometheus-cpp/1.3.0 +opentracing-cpp/1.6.0 [options] grpc/*:fPIC=True @@ -20,6 +24,8 @@ 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 From 0591dbaaea419706d0760de0a43182d848fd0122 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 25 Mar 2025 13:04:20 -0600 Subject: [PATCH 22/28] add build config messages to the main cmake file --- CMakeLists.txt | 107 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb7bebae26..fb270baede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,8 +417,6 @@ if(WITH_PROMETHEUS) endif() endif() -message(STATUS "Building WITH_ABSEIL=${WITH_ABSEIL}") - if(WITH_ABSEIL) if(NOT TARGET absl::strings) find_package(absl CONFIG REQUIRED) @@ -510,7 +508,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() # @@ -522,7 +519,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() # @@ -721,6 +717,109 @@ 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_ABSEIL: ${WITH_ABSEIL}") +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) From 89c2acb2f372471b23298fc4bc1c240d87699dd8 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 25 Mar 2025 13:12:55 -0600 Subject: [PATCH 23/28] move cmake install test to a separate gitlab workflow --- .github/workflows/ci.yml | 45 ----- .github/workflows/cmake_install.yml | 273 ++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/cmake_install.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d880678e8e..b643e6f419 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -545,37 +545,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 - runs-on: ubuntu-24.04 - env: - INSTALL_TEST_DIR: '/home/runner/install_test' - CXX_STANDARD: '17' - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: setup - run: | - sudo -E ./ci/setup_googletest.sh - sudo -E ./ci/setup_ci_environment.sh - - name: install dependencies - 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: build and test - run: | - ./ci/do_ci.sh cmake.install.test - - name: verify packages - run: | - export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH - ./ci/verify_packages.sh - plugin_test: name: Plugin -> CMake runs-on: ubuntu-latest @@ -860,8 +829,6 @@ jobs: run: ./ci/do_ci.ps1 cmake.dll.cxx20.test - name: run otprotocol test (DLL build) run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test - - name: run cmake install test - run: ./ci/do_ci.ps1 cmake.dll.install.test windows_with_async_export: name: CMake (With async export) -> exporter proto @@ -905,18 +872,6 @@ jobs: - name: run tests run: ./ci/do_ci.ps1 cmake.test_example_plugin - windows_cmake_install_test: - name: Windows CMake install test - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: Setup Windows CI Environment - run: ./ci/setup_windows_ci_environment.ps1 - - name: Run Tests - run: ./ci/do_ci.ps1 cmake.install.test - code_coverage: name: Code coverage runs-on: ubuntu-22.04 diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml new file mode 100644 index 0000000000..799b3f02e8 --- /dev/null +++ b/.github/workflows/cmake_install.yml @@ -0,0 +1,273 @@ +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_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_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_googletest.sh + sudo -E ./ci/setup_ci_environment.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_googletest.sh + sudo -E ./ci/setup_ci_environment.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_googletest.sh + sudo -E ./ci/setup_ci_environment.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_2004_script_build_grpc_1_49_2: + name: Ubuntu 20.04 script grpc 1.49.2 cxx14 (static libs - shared libs) + runs-on: ubuntu-20.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_googletest.sh + sudo -E ./ci/setup_ci_environment.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: 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: 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 + 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: | + 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 From 70c323290324faba0a9f59a4f3f21ea6a739d6d3 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 25 Mar 2025 14:58:50 -0600 Subject: [PATCH 24/28] fix shellcheck error --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 4b72331b92..f7bfaa2e41 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -103,7 +103,7 @@ if [ -n "$CMAKE_TOOLCHAIN_FILE" ]; then CMAKE_OPTIONS+=("-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE") fi -echo "CMAKE_OPTIONS: ${CMAKE_OPTIONS[@]}" +echo "CMAKE_OPTIONS:" "${CMAKE_OPTIONS[@]}" export CTEST_OUTPUT_ON_FAILURE=1 From 286332170e9b1ee835034611029fd9939cb02920 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 31 Mar 2025 11:32:24 -0600 Subject: [PATCH 25/28] upgrade 20.04 cmake install test runner to 22.04 --- .github/workflows/cmake_install.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml index 799b3f02e8..1cc6b04c89 100644 --- a/.github/workflows/cmake_install.yml +++ b/.github/workflows/cmake_install.yml @@ -128,9 +128,9 @@ jobs: BUILD_SHARED_LIBS: 'ON' run: ./ci/do_ci.sh cmake.install.test - ubuntu_2004_script_build_grpc_1_49_2: - name: Ubuntu 20.04 script grpc 1.49.2 cxx14 (static libs - shared libs) - runs-on: ubuntu-20.04 + 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' From 560a374cad5f09f21260a9cc4af1794f7403f45f Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 1 Apr 2025 23:54:34 -0600 Subject: [PATCH 26/28] pin cmake version in the cmake install test workflow --- .github/workflows/cmake_install.yml | 30 ++++++++++++++++------ ci/setup_cmake.sh | 3 +-- ci/setup_cmake_macos.sh | 40 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) create mode 100755 ci/setup_cmake_macos.sh diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml index 1cc6b04c89..15075bb90b 100644 --- a/.github/workflows/cmake_install.yml +++ b/.github/workflows/cmake_install.yml @@ -18,7 +18,9 @@ jobs: with: submodules: 'recursive' - name: Build dependencies with vcpkg submodule - run: ./ci/setup_windows_ci_environment.ps1 + 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 @@ -34,7 +36,9 @@ jobs: with: submodules: 'recursive' - name: Build dependencies with vcpkg submodule - run: ./ci/setup_windows_ci_environment.ps1 + run: | + ./ci/setup_cmake.ps1 + ./ci/setup_windows_ci_environment.ps1 - name: Run Tests run: ./ci/do_ci.ps1 cmake.install.test @@ -51,8 +55,9 @@ jobs: submodules: 'recursive' - name: Install libcurl, zlib, nlohmann-json with apt run: | - sudo -E ./ci/setup_googletest.sh 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 @@ -79,8 +84,9 @@ jobs: submodules: 'recursive' - name: Install gtest, libcurl, zlib, nlohmann-json with apt run: | - sudo -E ./ci/setup_googletest.sh 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' @@ -108,8 +114,9 @@ jobs: submodules: 'recursive' - name: Install gtest, libcurl, zlib, nlohmann-json with apt run: | - sudo -E ./ci/setup_googletest.sh 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' @@ -141,8 +148,9 @@ jobs: submodules: 'recursive' - name: Install gtest, libcurl, zlib, nlohmann-json with apt run: | - sudo -E ./ci/setup_googletest.sh 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' @@ -179,7 +187,9 @@ jobs: pip install "conan>=2.0,<3" conan profile detect --force - name: Install or build all dependencies with Conan - run: conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=Debug + 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' @@ -213,7 +223,9 @@ jobs: pip install "conan>=2.0,<3" conan profile detect --force - name: Install or build all dependencies with Conan - run: conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=Debug + 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' @@ -238,6 +250,7 @@ jobs: - 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 @@ -258,6 +271,7 @@ jobs: 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 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 From 3c1f8e76fdac17b0de0600992978d36906501b6a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 1 Apr 2025 23:54:57 -0600 Subject: [PATCH 27/28] remove abseil as a public dependency. update install notes on how to install abseil, protobuf, and grpc so the transitive abseil depenedency is found implicitly --- .github/workflows/ci.yml | 18 ------------------ CMakeLists.txt | 11 ++++------- INSTALL.md | 18 ++++++++++++++---- ci/do_ci.ps1 | 2 -- ci/do_ci.sh | 16 ---------------- cmake/opentelemetry-proto.cmake | 8 ++------ .../thirdparty-built-with-flags.cmake.in | 17 ----------------- cmake/thirdparty-dependency-definitions.cmake | 12 ------------ examples/grpc/CMakeLists.txt | 3 --- examples/otlp/README.md | 16 ---------------- exporters/otlp/CMakeLists.txt | 8 -------- sdk/src/common/CMakeLists.txt | 4 ---- 12 files changed, 20 insertions(+), 113 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d87833ed1..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 diff --git a/CMakeLists.txt b/CMakeLists.txt index b5cefac9ec..329c021295 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ project(opentelemetry-cpp) mark_as_advanced(CMAKE_TOOLCHAIN_FILE) # 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. @@ -415,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)) @@ -446,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 @@ -738,7 +736,6 @@ 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_ABSEIL: ${WITH_ABSEIL}") message(STATUS "WITH_NO_GETENV: ${WITH_NO_GETENV}") message(STATUS "---------------------------------------------") diff --git a/INSTALL.md b/INSTALL.md index a009f00434..07acf4388a 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -38,10 +38,20 @@ You can link OpenTelemetry C++ SDK with libraries provided in [GoogleBenchmark Build Instructions](https://github.com/google/benchmark#installation). - Apart from above core requirements, the Exporters and Propagators have their - build dependencies which are not covered here. E.g, the OTLP Exporter needs - grpc/protobuf library, the Zipkin exporter needs nlohmann-json and libcurl, - the ETW exporter needs nlohmann-json to build. This is covered in the build - instructions for each of these components. + build dependencies. + +### Building dependencies for the OTLP exporters + +The opentelemetry-cpp OTLP exporters depend on Protobuf and gRPC (in the case of the otlp grpc exporters). Protobuf (since version 3.22.0) and gRPC depend on Abseil. +For cmake builds, it is best practice to build and install Abseil, Protobuf, and gPRC as independent packages - configuring cmake for Protobuf and gRPC to build against the installed packages instead of using their submodule option. + +If building and installing Protobuf and gRPC manually with cmake the recommended approach is: +1. Choose the desired tag version of grpc. Find the compatible versions of abseil and protobuf by inspecting the submodules of grpc at that tag. +2. Build and install the required version of abseil +3. Build and install the required version of protobuf + - Set the cmake option of Protobuf to build against the installed package of Abseil (`protobuf_ABSL_PROVIDER=package`) +4. Build and install the required version of grpc + - Set the cmake option of grpc to build against the installed packages of Abseil and Protobuf (cmake options - `gRPC_ABSL_PROVIDER=package` and `gRPC_PROTOBUF_PROVIDER=package`) ### Building as standalone CMake Project diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index bbc4f4d765..e34d72d5e4 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -373,7 +373,6 @@ switch ($action) { "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` -DWITH_ABI_VERSION_1=OFF ` -DWITH_ABI_VERSION_2=ON ` - -DWITH_ABSEIL=OFF ` -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` @@ -473,7 +472,6 @@ switch ($action) { -DOPENTELEMETRY_BUILD_DLL=1 ` -DWITH_ABI_VERSION_1=ON ` -DWITH_ABI_VERSION_2=OFF ` - -DWITH_ABSEIL=OFF ` -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f7bfaa2e41..f81e96469d 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -232,18 +232,6 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then make -j $(nproc) make test exit 0 -elif [[ "$1" == "cmake.abseil.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 \ - "${SRC_DIR}" - make -j $(nproc) - make test - exit 0 elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then cd "${BUILD_DIR}" rm -rf * @@ -387,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 \ @@ -477,7 +462,6 @@ elif [[ "$1" == "cmake.install.test" ]]; then -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ -DWITH_ABI_VERSION_1=OFF \ -DWITH_ABI_VERSION_2=ON \ - -DWITH_ABSEIL=OFF \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 0655ebc346..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) @@ -402,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/thirdparty-built-with-flags.cmake.in b/cmake/templates/thirdparty-built-with-flags.cmake.in index 84d7e130ed..c893332ad4 100644 --- a/cmake/templates/thirdparty-built-with-flags.cmake.in +++ b/cmake/templates/thirdparty-built-with-flags.cmake.in @@ -10,7 +10,6 @@ # Initialize dependency expected flags set(BUILT_WITH_Threads TRUE) -set(BUILT_WITH_absl FALSE) set(BUILT_WITH_CURL FALSE) set(BUILT_WITH_ZLIB FALSE) set(BUILT_WITH_nlohmann_json FALSE) @@ -19,17 +18,6 @@ set(BUILT_WITH_gRPC FALSE) set(BUILT_WITH_prometheus-cpp FALSE) set(BUILT_WITH_OpenTracing FALSE) -# absl: -if(@WITH_ABSEIL@) - set(BUILT_WITH_absl TRUE) -elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@ OR @WITH_OTLP_GRPC@) - if( @WITH_OTLP_GRPC@ ) - set(BUILT_WITH_absl TRUE) - elseif(@Protobuf_VERSION@ VERSION_GREATER_EQUAL 3.22.0) - set(BUILT_WITH_absl TRUE) - endif() -endif() - # CURL and ZLIB: if(@WITH_HTTP_CLIENT_CURL@) if("@CURL_FOUND@") @@ -69,10 +57,6 @@ endif() #----------------------------------------------------------------------- # Third party dependency versions #----------------------------------------------------------------------- -if(BUILT_WITH_absl) - set(BUILT_WITH_absl_VERSION @absl_VERSION@) -endif() - if(BUILT_WITH_CURL) set(BUILT_WITH_CURL_VERSION @CURL_VERSION_STRING@) endif() @@ -104,7 +88,6 @@ endif() #----------------------------------------------------------------------- # Flags to determine if CONFIG search mode should be used in find_dependency(...) #----------------------------------------------------------------------- -set(FIND_DEPENDENCY_absl_USE_CONFIG TRUE) set(FIND_DEPENDENCY_Threads_USE_CONFIG FALSE) set(FIND_DEPENDENCY_ZLIB_USE_CONFIG FALSE) set(FIND_DEPENDENCY_CURL_USE_CONFIG FALSE) diff --git a/cmake/thirdparty-dependency-definitions.cmake b/cmake/thirdparty-dependency-definitions.cmake index fca76ea31c..33de84f027 100644 --- a/cmake/thirdparty-dependency-definitions.cmake +++ b/cmake/thirdparty-dependency-definitions.cmake @@ -6,7 +6,6 @@ # Dependencies will be found in this order when find_package(opentelemetry-cpp ...) is called. #----------------------------------------------------------------------- set(THIRD_PARTY_DEPENDENCIES_SUPPORTED - absl Threads ZLIB CURL @@ -22,14 +21,6 @@ set(THIRD_PARTY_DEPENDENCIES_SUPPORTED # These are the components that may require the third party dependency #----------------------------------------------------------------------- -# Components that may require absl -set(THIRD_PARTY_absl_DEPENDENT_COMPONENTS - api - sdk - exporters_otlp_common - exporters_otlp_grpc -) - # Components that require Threads set(THIRD_PARTY_Threads_DEPENDENT_COMPONENTS sdk @@ -55,9 +46,6 @@ set(THIRD_PARTY_nlohmann_json_DEPENDENT_COMPONENTS # Components that require Protobuf set(THIRD_PARTY_Protobuf_DEPENDENT_COMPONENTS exporters_otlp_common - exporters_otlp_file - exporters_otlp_http - exporters_otlp_grpc ) # Components that require gRPC 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/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index c2215f3057..d30341b7ab 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -127,10 +127,6 @@ if(WITH_OTLP_HTTP) "$" "$") - 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) @@ -206,10 +202,6 @@ if(WITH_OTLP_FILE) PUBLIC opentelemetry_sdk opentelemetry_common PRIVATE opentelemetry_proto $) - if(TARGET absl::strings) - target_link_libraries(opentelemetry_exporter_otlp_file_client - PUBLIC absl::strings) - endif() if(nlohmann_json_clone) add_dependencies(opentelemetry_exporter_otlp_file_client nlohmann_json::nlohmann_json) diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index 4707813831..c27e9ca483 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -18,10 +18,6 @@ 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 From 98cc8cf79087dac06e79415d800e8fc9260ebe66 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 2 Apr 2025 00:12:06 -0600 Subject: [PATCH 28/28] fix format issues --- CMakeLists.txt | 6 +++--- INSTALL.md | 34 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 329c021295..4414f38002 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +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. -# This is important to properly find protobuf versions 3.22.0 and above +# 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. @@ -419,7 +419,7 @@ 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 diff --git a/INSTALL.md b/INSTALL.md index 07acf4388a..3e12db5a1e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -40,18 +40,28 @@ You can link OpenTelemetry C++ SDK with libraries provided in - Apart from above core requirements, the Exporters and Propagators have their build dependencies. -### Building dependencies for the OTLP exporters - -The opentelemetry-cpp OTLP exporters depend on Protobuf and gRPC (in the case of the otlp grpc exporters). Protobuf (since version 3.22.0) and gRPC depend on Abseil. -For cmake builds, it is best practice to build and install Abseil, Protobuf, and gPRC as independent packages - configuring cmake for Protobuf and gRPC to build against the installed packages instead of using their submodule option. - -If building and installing Protobuf and gRPC manually with cmake the recommended approach is: -1. Choose the desired tag version of grpc. Find the compatible versions of abseil and protobuf by inspecting the submodules of grpc at that tag. -2. Build and install the required version of abseil -3. Build and install the required version of protobuf - - Set the cmake option of Protobuf to build against the installed package of Abseil (`protobuf_ABSL_PROVIDER=package`) -4. Build and install the required version of grpc - - Set the cmake option of grpc to build against the installed packages of Abseil and Protobuf (cmake options - `gRPC_ABSL_PROVIDER=package` and `gRPC_PROTOBUF_PROVIDER=package`) +### Building dependencies for the OTLP exporters + +The opentelemetry-cpp OTLP exporters depend on Protobuf and gRPC + (in the case of the otlp grpc exporters). +Protobuf (since version 3.22.0) and gRPC depend on Abseil. +For cmake builds, it is best practice to build and install Abseil +, Protobuf, and gPRC as independent packages - +configuring cmake for Protobuf and gRPC to build against + the installed packages instead of using their submodule option. + +If building and installing Protobuf and gRPC manually with cmake the + recommended approach is: + +1. Choose the desired tag version of grpc. Find the compatible versions of abseil + and protobuf by inspecting the submodules of grpc at that tag. +2. Build and install the required version of abseil +3. Build and install the required version of protobuf + - Set the cmake option of Protobuf to build against the installed + package of Abseil (`protobuf_ABSL_PROVIDER=package`) +4. Build and install the required version of grpc + - Set the cmake option of grpc to build against the installed packages + of Abseil and Protobuf (cmake options - `gRPC_ABSL_PROVIDER=package` and `gRPC_PROTOBUF_PROVIDER=package`) ### Building as standalone CMake Project