diff --git a/CMakeLists.txt b/CMakeLists.txt index abcd2e1..5003e9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,9 +98,6 @@ option(WITH_OTLP_FILE "Whether to include the OTLP file exporter" OFF) if(NOT WITH_OTLP_HTTP AND NOT WITH_OTLP_GRPC AND NOT WITH_OTLP_FILE) message(FATAL_ERROR "At least one of WITH_OTLP_HTTP, WITH_OTLP_GRPC, or WITH_OTLP_FILE must be ON") endif() -if(APPLE) - option(SKIP_OTEL_CPP_PATCH "Whether to skip patching OpenTelemetry-cpp" OFF) -endif() option(WITH_EXAMPLES "Whether to build examples" OFF) # set vcpkg features depending on specified options @@ -174,6 +171,19 @@ if(WITH_OTLP_GRPC) ${GRPC_INSTALL_LIB_DIR}/upb_message_lib.lib ${GRPC_INSTALL_LIB_DIR}/upb_textformat_lib.lib ${GRPC_INSTALL_LIB_DIR}/utf8_range_lib.lib) + elseif(APPLE) + set(GRPC_LINK_LIBRARIES ${GRPC_INSTALL_LIB_DIR}/libaddress_sorting.dylib + ${GRPC_INSTALL_LIB_DIR}/libgpr.dylib + ${GRPC_INSTALL_LIB_DIR}/libgrpc++.dylib + ${GRPC_INSTALL_LIB_DIR}/libgrpc++_unsecure.dylib + ${GRPC_INSTALL_LIB_DIR}/libgrpc.dylib + ${GRPC_INSTALL_LIB_DIR}/libgrpc_unsecure.dylib + ${GRPC_INSTALL_LIB_DIR}/libupb_base_lib.dylib + ${GRPC_INSTALL_LIB_DIR}/libupb_json_lib.dylib + ${GRPC_INSTALL_LIB_DIR}/libupb_mem_lib.dylib + ${GRPC_INSTALL_LIB_DIR}/libupb_message_lib.dylib + ${GRPC_INSTALL_LIB_DIR}/libupb_textformat_lib.dylib + ${GRPC_INSTALL_LIB_DIR}/libutf8_range_lib.dylib) else() set(GRPC_LINK_LIBRARIES ${GRPC_INSTALL_LIB_DIR}/libgrpc++${CMAKE_SHARED_LIBRARY_SUFFIX}) endif() @@ -242,15 +252,9 @@ else() set(OTEL_CPP_PREFIX ${CMAKE_BINARY_DIR}/otel-cpp) endif() -if(WIN32) - set(OTEL_PROTO_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) -else() - set(OTEL_PROTO_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) -endif() - set(OTEL_CPP_LIBRARIES ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_common${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_otlp_recordable${CMAKE_STATIC_LIBRARY_SUFFIX} - ${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto${OTEL_PROTO_LIBRARY_SUFFIX} + ${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_resources${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_trace${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_version${CMAKE_STATIC_LIBRARY_SUFFIX} @@ -268,7 +272,7 @@ if(WITH_OTLP_GRPC) ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_client${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_metrics${CMAKE_STATIC_LIBRARY_SUFFIX} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_log${CMAKE_STATIC_LIBRARY_SUFFIX} - ${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto_grpc${OTEL_PROTO_LIBRARY_SUFFIX}) + ${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto_grpc${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() if(WITH_OTLP_FILE) set(OTEL_CPP_LIBRARIES ${OTEL_CPP_LIBRARIES} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_file${CMAKE_STATIC_LIBRARY_SUFFIX} @@ -282,7 +286,7 @@ if(NOT DEFINED OTEL_CPP_INSTALLED_DIR) include(ExternalProject) set(OTEL_CPP_PROJECT_NAME opentelemetry-cpp) set(OTEL_CPP_GIT_REPOSITORY "https://github.com/open-telemetry/opentelemetry-cpp.git") - set(OTEL_CPP_GIT_TAG "955a807") + set(OTEL_CPP_GIT_TAG "a7b1008") set(OTEL_CPP_CXX_STANDARD 14) @@ -290,17 +294,11 @@ if(NOT DEFINED OTEL_CPP_INSTALLED_DIR) set(OTEL_CPP_ABI_VERSION OPENTELEMETRY_ABI_VERSION_NO=2) set(PATCHES_DIR ${CMAKE_SOURCE_DIR}/patches) - if(SKIP_OTEL_CPP_PATCH) - set(OTEL_CPP_PATCH_CMD "") - elseif(WIN32) + set(OTEL_CPP_PATCH_CMD "") + if(WIN32 AND NOT SKIP_OTEL_CPP_PATCH) # Windows patch to add a preprocessor definition _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR # See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130 set(OTEL_CPP_PATCH_CMD git apply ${PATCHES_DIR}/otel-cpp-windows.patch) - elseif(APPLE) - # Mac patch to fix a linker issue when including gRPC exporter - set(OTEL_CPP_PATCH_CMD git apply ${PATCHES_DIR}/otel-cpp-mac.patch) - else() - set(OTEL_CPP_PATCH_CMD "") endif() if(WITH_OTLP_GRPC) @@ -513,6 +511,7 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN) "${OTEL_CPP_PREFIX}/lib/libopentelemetry_logs.a" "${OTEL_CPP_PREFIX}/lib/libopentelemetry_common.a" "${OTEL_CPP_PREFIX}/lib/libopentelemetry_otlp_recordable.a" + "${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto.a" ${ABSL_LIBRARIES} -Wl,--no-whole-archive) target_link_options(${OPENTELEMETRY_PROXY_LIBRARY_NAME} PRIVATE ${OPENTELEMETRY_PROXY_LINK_OPTIONS}) endif() @@ -542,17 +541,10 @@ if(WIN32) $/../bin/${OPENSSL_DLL} $/../bin/${OPENSSL_CRYPTO_DLL}) endif() -else() - set(OTEL_CPP_RUNTIME ${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto${CMAKE_SHARED_LIBRARY_SUFFIX}) - if(WITH_OTLP_GRPC) - set(OTEL_CPP_RUNTIME ${OTEL_CPP_RUNTIME} - ${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto_grpc${CMAKE_SHARED_LIBRARY_SUFFIX}) - endif() - if(APPLE) - set(OTEL_CPP_RUNTIME ${OTEL_CPP_RUNTIME} $ - $/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX} - $/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}) - endif() +elseif(APPLE) + set(OTEL_CPP_RUNTIME $ + $/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX} + $/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}) set(OPENTELEMETRY_PROXY_RUNTIME_LIBRARIES ${OTEL_CPP_RUNTIME}) endif() @@ -682,6 +674,7 @@ else() # they won't get overwritten when packaged set(DEPENDENT_RUNTIME_INSTALLED_DIR lib/${PLATFORM_NAME}) endif() +install(CODE "file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEPENDENT_RUNTIME_INSTALLED_DIR})") install(FILES ${OPENTELEMETRY_PROXY_RUNTIME_LIBRARIES} DESTINATION ${DEPENDENT_RUNTIME_INSTALLED_DIR}) if(UNIX) if(WITH_OTLP_GRPC) diff --git a/examples/context_propagation/cpp/client.cc b/examples/context_propagation/cpp/client.cc index 2bcf6b8..e302b0a 100644 --- a/examples/context_propagation/cpp/client.cc +++ b/examples/context_propagation/cpp/client.cc @@ -1,8 +1,9 @@ -// Copyright 2023-2024 The MathWorks, Inc. +// Copyright 2023-2026 The MathWorks, Inc. #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/ext/http/common/url_parser.h" -#include "opentelemetry/trace/semantic_conventions.h" +#include "opentelemetry/semconv/url_attributes.h" +#include "opentelemetry/semconv/http_attributes.h" #include "HttpTextMapCarrier.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" @@ -26,6 +27,7 @@ using namespace opentelemetry::trace; namespace http_client = opentelemetry::ext::http::client; namespace context = opentelemetry::context; namespace nostd = opentelemetry::nostd; +namespace semconv = opentelemetry::semconv; void InitTracer() { @@ -71,9 +73,9 @@ void sendRequest(const std::string &url) std::string span_name = url_parser.path_; auto span = get_tracer("http-client") ->StartSpan(span_name, - {{SemanticConventions::kUrlFull, url_parser.url_}, - {SemanticConventions::kUrlScheme, url_parser.scheme_}, - {SemanticConventions::kHttpRequestMethod, "POST"}}, + {{semconv::url::kUrlFull, url_parser.url_}, + {semconv::url::kUrlScheme, url_parser.scheme_}, + {semconv::http::kHttpRequestMethod, "POST"}}, options); auto scope = get_tracer("http-client")->WithActiveSpan(span); @@ -89,7 +91,7 @@ void sendRequest(const std::string &url) { // set span attributes auto status_code = result.GetResponse().GetStatusCode(); - span->SetAttribute(SemanticConventions::kHttpResponseStatusCode, status_code); + span->SetAttribute(semconv::http::kHttpResponseStatusCode, status_code); result.GetResponse().ForEachHeader( [&span](nostd::string_view header_name, nostd::string_view header_value) { span->SetAttribute("http.header." + std::string(header_name.data()), header_value); diff --git a/examples/webread/cpp/server.cc b/examples/webread/cpp/server.cc index c41b896..3d4b3cf 100644 --- a/examples/webread/cpp/server.cc +++ b/examples/webread/cpp/server.cc @@ -1,8 +1,11 @@ -// Copyright 2023-2024 The MathWorks, Inc. +// Copyright 2023-2026 The MathWorks, Inc. #include "server.h" #include "opentelemetry/trace/context.h" -#include "opentelemetry/trace/semantic_conventions.h" +#include "opentelemetry/semconv/url_attributes.h" +#include "opentelemetry/semconv/server_attributes.h" +#include "opentelemetry/semconv/client_attributes.h" +#include "opentelemetry/semconv/incubating/http_attributes.h" #include "HttpTextMapCarrier.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" @@ -25,6 +28,7 @@ namespace using namespace opentelemetry::trace; namespace context = opentelemetry::context; namespace common = opentelemetry::common; +namespace semconv= opentelemetry::semconv; uint16_t server_port = 8800; constexpr const char *server_name = "localhost"; @@ -79,13 +83,13 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback // start span with parent context extracted from http header auto span = get_tracer("http_server") ->StartSpan(span_name, - {{SemanticConventions::kServerAddress, server_name}, - {SemanticConventions::kServerPort, server_port}, - {SemanticConventions::kHttpRequestMethod, request.method}, - {SemanticConventions::kUrlScheme, "http"}, - {SemanticConventions::kHttpRequestBodySize, + {{semconv::server::kServerAddress, server_name}, + {semconv::server::kServerPort, server_port}, + {semconv::http::kHttpRequestMethod, request.method}, + {semconv::url::kUrlScheme, "http"}, + {semconv::http::kHttpRequestBodySize, static_cast(request.content.length())}, - {SemanticConventions::kClientAddress, request.client}}, + {semconv::client::kClientAddress, request.client}}, options); auto scope = get_tracer("http_server")->WithActiveSpan(span); diff --git a/patches/otel-cpp-mac.patch b/patches/otel-cpp-mac.patch deleted file mode 100644 index a422ad0..0000000 --- a/patches/otel-cpp-mac.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake -index 62197068..150ce3fb 100644 ---- a/cmake/opentelemetry-proto.cmake -+++ b/cmake/opentelemetry-proto.cmake -@@ -346,7 +346,7 @@ if(WITH_OTLP_GRPC) - target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto) - - get_target_property(grpc_lib_type gRPC::grpc++ TYPE) -- if(grpc_lib_type STREQUAL "SHARED_LIBRARY") -+ if(grpc_lib_type STREQUAL "SHARED_LIBRARY" OR APPLE) - target_link_libraries(opentelemetry_proto_grpc PUBLIC gRPC::grpc++) - endif() - set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME diff --git a/patches/otel-cpp-windows.patch b/patches/otel-cpp-windows.patch index cc607a6..cc51575 100644 --- a/patches/otel-cpp-windows.patch +++ b/patches/otel-cpp-windows.patch @@ -1,10 +1,10 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index cc085b1a..6c4dc0ae 100644 +index 6da525dc..07592866 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -15,6 +15,12 @@ endif() - - project(opentelemetry-cpp) +@@ -21,6 +21,12 @@ project( + VERSION "${OPENTELEMETRY_VERSION_NUMBER}" + LANGUAGES CXX) +if(WIN32) + # Add a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue diff --git a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h b/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h index 8f928fe..08a4ed8 100644 --- a/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h +++ b/sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h @@ -1,4 +1,4 @@ -// Copyright 2023-2024 The MathWorks, Inc. +// Copyright 2023-2026 The MathWorks, Inc. #pragma once @@ -19,9 +19,6 @@ #include "opentelemetry/sdk/metrics/view/meter_selector.h" #include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" - -#include "opentelemetry-matlab/sdk/metrics/ViewProxy.h" - namespace metrics_sdk = opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; @@ -87,7 +84,7 @@ class ViewProxy : public libmexclass::proxy::Proxy { std::string Description; metrics_sdk::AggregationType Aggregation; std::vector HistogramBinEdges; - std::unordered_map AllowedAttributes; + metrics_sdk::FilterAttributeMap AllowedAttributes; bool FilterAttributes; }; } diff --git a/sdk/metrics/src/ViewProxy.cpp b/sdk/metrics/src/ViewProxy.cpp index 96c820e..a037f48 100644 --- a/sdk/metrics/src/ViewProxy.cpp +++ b/sdk/metrics/src/ViewProxy.cpp @@ -1,4 +1,4 @@ -// Copyright 2023-2025 The MathWorks, Inc. +// Copyright 2023-2026 The MathWorks, Inc. #include "opentelemetry-matlab/sdk/metrics/ViewProxy.h" @@ -117,14 +117,18 @@ std::unique_ptr ViewProxy::getView(){ } // HistogramAggregationConfig - auto aggregation_config = std::shared_ptr(new metrics_sdk::HistogramAggregationConfig()); + std::shared_ptr aggregation_config; if(Aggregation == metrics_sdk::AggregationType::kHistogram || (Aggregation == metrics_sdk::AggregationType::kDefault && InstrumentType == metrics_sdk::InstrumentType::kHistogram)){ - aggregation_config->boundaries_ = HistogramBinEdges; + auto histogram_aggregation_config = std::make_shared(); + histogram_aggregation_config->boundaries_ = HistogramBinEdges; + aggregation_config = histogram_aggregation_config; + } else { + aggregation_config = std::make_shared(); } // View - return metrics_sdk::ViewFactory::Create(Name, Description, "", Aggregation, aggregation_config, std::move(attributes_processor)); + return metrics_sdk::ViewFactory::Create(Name, Description, Aggregation, aggregation_config, std::move(attributes_processor)); } std::unique_ptr ViewProxy::getInstrumentSelector(){