Skip to content

Commit 52f7084

Browse files
authored
Merge pull request #237 from mathworks/otel_cpp_1_24
Update to OpenTelemetry-cpp 1.24
2 parents 721da05 + eda76bd commit 52f7084

7 files changed

Lines changed: 58 additions & 71 deletions

File tree

CMakeLists.txt

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ option(WITH_OTLP_FILE "Whether to include the OTLP file exporter" OFF)
9898
if(NOT WITH_OTLP_HTTP AND NOT WITH_OTLP_GRPC AND NOT WITH_OTLP_FILE)
9999
message(FATAL_ERROR "At least one of WITH_OTLP_HTTP, WITH_OTLP_GRPC, or WITH_OTLP_FILE must be ON")
100100
endif()
101-
if(APPLE)
102-
option(SKIP_OTEL_CPP_PATCH "Whether to skip patching OpenTelemetry-cpp" OFF)
103-
endif()
104101
option(WITH_EXAMPLES "Whether to build examples" OFF)
105102

106103
# set vcpkg features depending on specified options
@@ -174,6 +171,19 @@ if(WITH_OTLP_GRPC)
174171
${GRPC_INSTALL_LIB_DIR}/upb_message_lib.lib
175172
${GRPC_INSTALL_LIB_DIR}/upb_textformat_lib.lib
176173
${GRPC_INSTALL_LIB_DIR}/utf8_range_lib.lib)
174+
elseif(APPLE)
175+
set(GRPC_LINK_LIBRARIES ${GRPC_INSTALL_LIB_DIR}/libaddress_sorting.dylib
176+
${GRPC_INSTALL_LIB_DIR}/libgpr.dylib
177+
${GRPC_INSTALL_LIB_DIR}/libgrpc++.dylib
178+
${GRPC_INSTALL_LIB_DIR}/libgrpc++_unsecure.dylib
179+
${GRPC_INSTALL_LIB_DIR}/libgrpc.dylib
180+
${GRPC_INSTALL_LIB_DIR}/libgrpc_unsecure.dylib
181+
${GRPC_INSTALL_LIB_DIR}/libupb_base_lib.dylib
182+
${GRPC_INSTALL_LIB_DIR}/libupb_json_lib.dylib
183+
${GRPC_INSTALL_LIB_DIR}/libupb_mem_lib.dylib
184+
${GRPC_INSTALL_LIB_DIR}/libupb_message_lib.dylib
185+
${GRPC_INSTALL_LIB_DIR}/libupb_textformat_lib.dylib
186+
${GRPC_INSTALL_LIB_DIR}/libutf8_range_lib.dylib)
177187
else()
178188
set(GRPC_LINK_LIBRARIES ${GRPC_INSTALL_LIB_DIR}/libgrpc++${CMAKE_SHARED_LIBRARY_SUFFIX})
179189
endif()
@@ -242,15 +252,9 @@ else()
242252
set(OTEL_CPP_PREFIX ${CMAKE_BINARY_DIR}/otel-cpp)
243253
endif()
244254

245-
if(WIN32)
246-
set(OTEL_PROTO_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
247-
else()
248-
set(OTEL_PROTO_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
249-
endif()
250-
251255
set(OTEL_CPP_LIBRARIES ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_common${CMAKE_STATIC_LIBRARY_SUFFIX}
252256
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_otlp_recordable${CMAKE_STATIC_LIBRARY_SUFFIX}
253-
${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto${OTEL_PROTO_LIBRARY_SUFFIX}
257+
${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto${CMAKE_STATIC_LIBRARY_SUFFIX}
254258
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_resources${CMAKE_STATIC_LIBRARY_SUFFIX}
255259
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_trace${CMAKE_STATIC_LIBRARY_SUFFIX}
256260
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_version${CMAKE_STATIC_LIBRARY_SUFFIX}
@@ -268,7 +272,7 @@ if(WITH_OTLP_GRPC)
268272
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_client${CMAKE_STATIC_LIBRARY_SUFFIX}
269273
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_metrics${CMAKE_STATIC_LIBRARY_SUFFIX}
270274
${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_grpc_log${CMAKE_STATIC_LIBRARY_SUFFIX}
271-
${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto_grpc${OTEL_PROTO_LIBRARY_SUFFIX})
275+
${OTEL_CPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}opentelemetry_proto_grpc${CMAKE_STATIC_LIBRARY_SUFFIX})
272276
endif()
273277
if(WITH_OTLP_FILE)
274278
set(OTEL_CPP_LIBRARIES ${OTEL_CPP_LIBRARIES} ${OTEL_CPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}opentelemetry_exporter_otlp_file${CMAKE_STATIC_LIBRARY_SUFFIX}
@@ -282,25 +286,19 @@ if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
282286
include(ExternalProject)
283287
set(OTEL_CPP_PROJECT_NAME opentelemetry-cpp)
284288
set(OTEL_CPP_GIT_REPOSITORY "https://github.com/open-telemetry/opentelemetry-cpp.git")
285-
set(OTEL_CPP_GIT_TAG "955a807")
289+
set(OTEL_CPP_GIT_TAG "a7b1008")
286290

287291
set(OTEL_CPP_CXX_STANDARD 14)
288292

289293
# The synchronous gauge metric instrument is only defined in ABI version 2
290294
set(OTEL_CPP_ABI_VERSION OPENTELEMETRY_ABI_VERSION_NO=2)
291295

292296
set(PATCHES_DIR ${CMAKE_SOURCE_DIR}/patches)
293-
if(SKIP_OTEL_CPP_PATCH)
294-
set(OTEL_CPP_PATCH_CMD "")
295-
elseif(WIN32)
297+
set(OTEL_CPP_PATCH_CMD "")
298+
if(WIN32 AND NOT SKIP_OTEL_CPP_PATCH)
296299
# Windows patch to add a preprocessor definition _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
297300
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
298301
set(OTEL_CPP_PATCH_CMD git apply ${PATCHES_DIR}/otel-cpp-windows.patch)
299-
elseif(APPLE)
300-
# Mac patch to fix a linker issue when including gRPC exporter
301-
set(OTEL_CPP_PATCH_CMD git apply ${PATCHES_DIR}/otel-cpp-mac.patch)
302-
else()
303-
set(OTEL_CPP_PATCH_CMD "")
304302
endif()
305303

306304
if(WITH_OTLP_GRPC)
@@ -513,6 +511,7 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN)
513511
"${OTEL_CPP_PREFIX}/lib/libopentelemetry_logs.a"
514512
"${OTEL_CPP_PREFIX}/lib/libopentelemetry_common.a"
515513
"${OTEL_CPP_PREFIX}/lib/libopentelemetry_otlp_recordable.a"
514+
"${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto.a"
516515
${ABSL_LIBRARIES} -Wl,--no-whole-archive)
517516
target_link_options(${OPENTELEMETRY_PROXY_LIBRARY_NAME} PRIVATE ${OPENTELEMETRY_PROXY_LINK_OPTIONS})
518517
endif()
@@ -542,17 +541,10 @@ if(WIN32)
542541
$<TARGET_FILE_DIR:OpenSSL::SSL>/../bin/${OPENSSL_DLL}
543542
$<TARGET_FILE_DIR:OpenSSL::SSL>/../bin/${OPENSSL_CRYPTO_DLL})
544543
endif()
545-
else()
546-
set(OTEL_CPP_RUNTIME ${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto${CMAKE_SHARED_LIBRARY_SUFFIX})
547-
if(WITH_OTLP_GRPC)
548-
set(OTEL_CPP_RUNTIME ${OTEL_CPP_RUNTIME}
549-
${OTEL_CPP_PREFIX}/lib/libopentelemetry_proto_grpc${CMAKE_SHARED_LIBRARY_SUFFIX})
550-
endif()
551-
if(APPLE)
552-
set(OTEL_CPP_RUNTIME ${OTEL_CPP_RUNTIME} $<TARGET_FILE:ZLIB::ZLIB>
553-
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}
554-
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX})
555-
endif()
544+
elseif(APPLE)
545+
set(OTEL_CPP_RUNTIME $<TARGET_FILE:ZLIB::ZLIB>
546+
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}
547+
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX})
556548
set(OPENTELEMETRY_PROXY_RUNTIME_LIBRARIES ${OTEL_CPP_RUNTIME})
557549
endif()
558550

@@ -682,6 +674,7 @@ else()
682674
# they won't get overwritten when packaged
683675
set(DEPENDENT_RUNTIME_INSTALLED_DIR lib/${PLATFORM_NAME})
684676
endif()
677+
install(CODE "file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEPENDENT_RUNTIME_INSTALLED_DIR})")
685678
install(FILES ${OPENTELEMETRY_PROXY_RUNTIME_LIBRARIES} DESTINATION ${DEPENDENT_RUNTIME_INSTALLED_DIR})
686679
if(UNIX)
687680
if(WITH_OTLP_GRPC)

examples/context_propagation/cpp/client.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2026 The MathWorks, Inc.
22

33
#include "opentelemetry/ext/http/client/http_client_factory.h"
44
#include "opentelemetry/ext/http/common/url_parser.h"
5-
#include "opentelemetry/trace/semantic_conventions.h"
5+
#include "opentelemetry/semconv/url_attributes.h"
6+
#include "opentelemetry/semconv/http_attributes.h"
67
#include "HttpTextMapCarrier.h"
78

89
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
@@ -26,6 +27,7 @@ using namespace opentelemetry::trace;
2627
namespace http_client = opentelemetry::ext::http::client;
2728
namespace context = opentelemetry::context;
2829
namespace nostd = opentelemetry::nostd;
30+
namespace semconv = opentelemetry::semconv;
2931

3032
void InitTracer()
3133
{
@@ -71,9 +73,9 @@ void sendRequest(const std::string &url)
7173
std::string span_name = url_parser.path_;
7274
auto span = get_tracer("http-client")
7375
->StartSpan(span_name,
74-
{{SemanticConventions::kUrlFull, url_parser.url_},
75-
{SemanticConventions::kUrlScheme, url_parser.scheme_},
76-
{SemanticConventions::kHttpRequestMethod, "POST"}},
76+
{{semconv::url::kUrlFull, url_parser.url_},
77+
{semconv::url::kUrlScheme, url_parser.scheme_},
78+
{semconv::http::kHttpRequestMethod, "POST"}},
7779
options);
7880
auto scope = get_tracer("http-client")->WithActiveSpan(span);
7981

@@ -89,7 +91,7 @@ void sendRequest(const std::string &url)
8991
{
9092
// set span attributes
9193
auto status_code = result.GetResponse().GetStatusCode();
92-
span->SetAttribute(SemanticConventions::kHttpResponseStatusCode, status_code);
94+
span->SetAttribute(semconv::http::kHttpResponseStatusCode, status_code);
9395
result.GetResponse().ForEachHeader(
9496
[&span](nostd::string_view header_name, nostd::string_view header_value) {
9597
span->SetAttribute("http.header." + std::string(header_name.data()), header_value);

examples/webread/cpp/server.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2026 The MathWorks, Inc.
22

33
#include "server.h"
44
#include "opentelemetry/trace/context.h"
5-
#include "opentelemetry/trace/semantic_conventions.h"
5+
#include "opentelemetry/semconv/url_attributes.h"
6+
#include "opentelemetry/semconv/server_attributes.h"
7+
#include "opentelemetry/semconv/client_attributes.h"
8+
#include "opentelemetry/semconv/incubating/http_attributes.h"
69
#include "HttpTextMapCarrier.h"
710

811
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
@@ -25,6 +28,7 @@ namespace
2528
using namespace opentelemetry::trace;
2629
namespace context = opentelemetry::context;
2730
namespace common = opentelemetry::common;
31+
namespace semconv= opentelemetry::semconv;
2832

2933
uint16_t server_port = 8800;
3034
constexpr const char *server_name = "localhost";
@@ -79,13 +83,13 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback
7983
// start span with parent context extracted from http header
8084
auto span = get_tracer("http_server")
8185
->StartSpan(span_name,
82-
{{SemanticConventions::kServerAddress, server_name},
83-
{SemanticConventions::kServerPort, server_port},
84-
{SemanticConventions::kHttpRequestMethod, request.method},
85-
{SemanticConventions::kUrlScheme, "http"},
86-
{SemanticConventions::kHttpRequestBodySize,
86+
{{semconv::server::kServerAddress, server_name},
87+
{semconv::server::kServerPort, server_port},
88+
{semconv::http::kHttpRequestMethod, request.method},
89+
{semconv::url::kUrlScheme, "http"},
90+
{semconv::http::kHttpRequestBodySize,
8791
static_cast<uint64_t>(request.content.length())},
88-
{SemanticConventions::kClientAddress, request.client}},
92+
{semconv::client::kClientAddress, request.client}},
8993
options);
9094

9195
auto scope = get_tracer("http_server")->WithActiveSpan(span);

patches/otel-cpp-mac.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

patches/otel-cpp-windows.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index cc085b1a..6c4dc0ae 100644
2+
index 6da525dc..07592866 100644
33
--- a/CMakeLists.txt
44
+++ b/CMakeLists.txt
5-
@@ -15,6 +15,12 @@ endif()
6-
7-
project(opentelemetry-cpp)
5+
@@ -21,6 +21,12 @@ project(
6+
VERSION "${OPENTELEMETRY_VERSION_NUMBER}"
7+
LANGUAGES CXX)
88

99
+if(WIN32)
1010
+ # Add a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue

sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2026 The MathWorks, Inc.
22

33
#pragma once
44

@@ -19,9 +19,6 @@
1919
#include "opentelemetry/sdk/metrics/view/meter_selector.h"
2020
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h"
2121

22-
23-
#include "opentelemetry-matlab/sdk/metrics/ViewProxy.h"
24-
2522
namespace metrics_sdk = opentelemetry::sdk::metrics;
2623
namespace nostd = opentelemetry::nostd;
2724

@@ -87,7 +84,7 @@ class ViewProxy : public libmexclass::proxy::Proxy {
8784
std::string Description;
8885
metrics_sdk::AggregationType Aggregation;
8986
std::vector<double> HistogramBinEdges;
90-
std::unordered_map<std::string, bool> AllowedAttributes;
87+
metrics_sdk::FilterAttributeMap AllowedAttributes;
9188
bool FilterAttributes;
9289
};
9390
}

sdk/metrics/src/ViewProxy.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2025 The MathWorks, Inc.
1+
// Copyright 2023-2026 The MathWorks, Inc.
22

33
#include "opentelemetry-matlab/sdk/metrics/ViewProxy.h"
44

@@ -117,14 +117,18 @@ std::unique_ptr<metrics_sdk::View> ViewProxy::getView(){
117117
}
118118

119119
// HistogramAggregationConfig
120-
auto aggregation_config = std::shared_ptr<metrics_sdk::HistogramAggregationConfig>(new metrics_sdk::HistogramAggregationConfig());
120+
std::shared_ptr<metrics_sdk::AggregationConfig> aggregation_config;
121121
if(Aggregation == metrics_sdk::AggregationType::kHistogram ||
122122
(Aggregation == metrics_sdk::AggregationType::kDefault && InstrumentType == metrics_sdk::InstrumentType::kHistogram)){
123-
aggregation_config->boundaries_ = HistogramBinEdges;
123+
auto histogram_aggregation_config = std::make_shared<metrics_sdk::HistogramAggregationConfig>();
124+
histogram_aggregation_config->boundaries_ = HistogramBinEdges;
125+
aggregation_config = histogram_aggregation_config;
126+
} else {
127+
aggregation_config = std::make_shared<metrics_sdk::AggregationConfig>();
124128
}
125129

126130
// View
127-
return metrics_sdk::ViewFactory::Create(Name, Description, "", Aggregation, aggregation_config, std::move(attributes_processor));
131+
return metrics_sdk::ViewFactory::Create(Name, Description, Aggregation, aggregation_config, std::move(attributes_processor));
128132
}
129133

130134
std::unique_ptr<metrics_sdk::InstrumentSelector> ViewProxy::getInstrumentSelector(){

0 commit comments

Comments
 (0)