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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -282,25 +286,19 @@ 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)

# The synchronous gauge metric instrument is only defined in ABI version 2
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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -542,17 +541,10 @@ if(WIN32)
$<TARGET_FILE_DIR:OpenSSL::SSL>/../bin/${OPENSSL_DLL}
$<TARGET_FILE_DIR:OpenSSL::SSL>/../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} $<TARGET_FILE:ZLIB::ZLIB>
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
elseif(APPLE)
set(OTEL_CPP_RUNTIME $<TARGET_FILE:ZLIB::ZLIB>
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_MAJOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}
$<TARGET_FILE_DIR:ZLIB::ZLIB>/libz.${ZLIB_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(OPENTELEMETRY_PROXY_RUNTIME_LIBRARIES ${OTEL_CPP_RUNTIME})
endif()

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions examples/context_propagation/cpp/client.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions examples/webread/cpp/server.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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";
Expand Down Expand Up @@ -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<uint64_t>(request.content.length())},
{SemanticConventions::kClientAddress, request.client}},
{semconv::client::kClientAddress, request.client}},
options);

auto scope = get_tracer("http_server")->WithActiveSpan(span);
Expand Down
13 changes: 0 additions & 13 deletions patches/otel-cpp-mac.patch

This file was deleted.

8 changes: 4 additions & 4 deletions patches/otel-cpp-windows.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 The MathWorks, Inc.
// Copyright 2023-2026 The MathWorks, Inc.

#pragma once

Expand All @@ -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;

Expand Down Expand Up @@ -87,7 +84,7 @@ class ViewProxy : public libmexclass::proxy::Proxy {
std::string Description;
metrics_sdk::AggregationType Aggregation;
std::vector<double> HistogramBinEdges;
std::unordered_map<std::string, bool> AllowedAttributes;
metrics_sdk::FilterAttributeMap AllowedAttributes;
bool FilterAttributes;
};
}
12 changes: 8 additions & 4 deletions sdk/metrics/src/ViewProxy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2025 The MathWorks, Inc.
// Copyright 2023-2026 The MathWorks, Inc.

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

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

// HistogramAggregationConfig
auto aggregation_config = std::shared_ptr<metrics_sdk::HistogramAggregationConfig>(new metrics_sdk::HistogramAggregationConfig());
std::shared_ptr<metrics_sdk::AggregationConfig> 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<metrics_sdk::HistogramAggregationConfig>();
histogram_aggregation_config->boundaries_ = HistogramBinEdges;
aggregation_config = histogram_aggregation_config;
} else {
aggregation_config = std::make_shared<metrics_sdk::AggregationConfig>();
}

// 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<metrics_sdk::InstrumentSelector> ViewProxy::getInstrumentSelector(){
Expand Down
Loading