Skip to content

Commit

Permalink
Update to otel-cpp 1.16.1, closes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Aug 29, 2024
1 parent 69a6093 commit 9546b11
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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 "054b0dc")
set(OTEL_CPP_GIT_TAG "baecbb9")

set(OTEL_CPP_CXX_STANDARD 14)

Expand All @@ -209,14 +209,15 @@ if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
set(patch_command "")
endif()

# WITH_DEPRECATED_SDK_FACTORY flag is only needed for versions 1.16.0 and 1.16.1, and will be removed in 1.17.0
ExternalProject_Add(
${OTEL_CPP_PROJECT_NAME}
GIT_REPOSITORY ${OTEL_CPP_GIT_REPOSITORY}
GIT_TAG ${OTEL_CPP_GIT_TAG}
PREFIX ${OTEL_CPP_PREFIX}
UPDATE_DISCONNECTED 1
PATCH_COMMAND ${patch_command}
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DWITH_OTLP_HTTP=${WITH_OTLP_HTTP} -DWITH_OTLP_GRPC=${WITH_OTLP_GRPC} -DWITH_OTLP_FILE=${WITH_OTLP_FILE} -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DOPENTELEMETRY_INSTALL=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_CXX_STANDARD=${OTEL_CPP_CXX_STANDARD} -DVCPKG_INSTALLED_DIR=${VCPKG_INSTALLED_DIR} ${TRIPLET_DEFINITIONS}
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DWITH_OTLP_HTTP=${WITH_OTLP_HTTP} -DWITH_OTLP_GRPC=${WITH_OTLP_GRPC} -DWITH_OTLP_FILE=${WITH_OTLP_FILE} -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DWITH_DEPRECATED_SDK_FACTORY=OFF -DOPENTELEMETRY_INSTALL=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_CXX_STANDARD=${OTEL_CPP_CXX_STANDARD} -DVCPKG_INSTALLED_DIR=${VCPKG_INSTALLED_DIR} ${TRIPLET_DEFINITIONS}
BUILD_BYPRODUCTS ${OTEL_CPP_LIBRARIES}
INSTALL_DIR ${OTEL_CPP_PREFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} --install . --prefix ${OTEL_CPP_PREFIX} --config $<CONFIG>
Expand Down
14 changes: 7 additions & 7 deletions patches/otel-cpp-mac.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake
index 22082356..e25a89a2 100644
index 62197068..150ce3fb 100644
--- a/cmake/opentelemetry-proto.cmake
+++ b/cmake/opentelemetry-proto.cmake
@@ -276,7 +276,7 @@ if(WITH_OTLP_GRPC)
PUBLIC opentelemetry_proto)
@@ -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++)
- 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
7 changes: 5 additions & 2 deletions sdk/logs/src/LoggerProviderProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ libmexclass::proxy::MakeResult LoggerProviderProxy::make(const libmexclass::prox

auto resource_custom = createResource(resourcenames_mda, resourcevalues_mda);

out = std::make_shared<LoggerProviderProxy>(nostd::shared_ptr<logs_api::LoggerProvider>(
std::move(logs_sdk::LoggerProviderFactory::Create(std::move(processor), resource_custom))));
std::unique_ptr<logs_sdk::LoggerProvider> p_sdk = logs_sdk::LoggerProviderFactory::Create(
std::move(processor), resource_custom);
nostd::shared_ptr<logs_sdk::LoggerProvider> p_sdk_shared(std::move(p_sdk));
nostd::shared_ptr<logs_api::LoggerProvider> p_api_shared(std::move(p_sdk_shared));
out = std::make_shared<LoggerProviderProxy>(p_api_shared);
}
return out;
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/metrics/src/MeterProviderProxy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The MathWorks, Inc.
// Copyright 2023-2024 The MathWorks, Inc.

#include "opentelemetry-matlab/sdk/metrics/MeterProviderProxy.h"
#include "opentelemetry-matlab/sdk/metrics/PeriodicExportingMetricReaderProxy.h"
Expand Down Expand Up @@ -39,8 +39,7 @@ libmexclass::proxy::MakeResult MeterProviderProxy::make(const libmexclass::proxy
libmexclass::proxy::ProxyManager::getProxy(readerid))->getInstance();

auto view_registry = metrics_sdk::ViewRegistryFactory::Create();
auto p = metrics_sdk::MeterProviderFactory::Create(std::move(view_registry), resource_custom);
auto *p_sdk = static_cast<metrics_sdk::MeterProvider *>(p.get());
auto p_sdk = metrics_sdk::MeterProviderFactory::Create(std::move(view_registry), resource_custom);
p_sdk->AddMetricReader(std::move(reader));

// View
Expand All @@ -52,8 +51,9 @@ libmexclass::proxy::MakeResult MeterProviderProxy::make(const libmexclass::proxy
p_sdk->AddView(view->getInstrumentSelector(), view->getMeterSelector(), view->getView());
}

auto p_out = nostd::shared_ptr<metrics_api::MeterProvider>(std::move(p));
out = std::make_shared<MeterProviderProxy>(p_out);
nostd::shared_ptr<metrics_sdk::MeterProvider> p_sdk_shared(std::move(p_sdk));
nostd::shared_ptr<metrics_api::MeterProvider> p_api_shared(std::move(p_sdk_shared));
out = std::make_shared<MeterProviderProxy>(p_api_shared);
}
return out;
}
Expand Down
11 changes: 7 additions & 4 deletions sdk/trace/src/TracerProviderProxy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The MathWorks, Inc.
// Copyright 2023-2024 The MathWorks, Inc.

#include "opentelemetry-matlab/sdk/trace/TracerProviderProxy.h"
#include "opentelemetry-matlab/sdk/trace/SpanProcessorProxy.h"
Expand All @@ -14,6 +14,7 @@
#include "opentelemetry/trace/tracer_provider.h"
#include "opentelemetry/trace/noop.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/nostd/shared_ptr.h"

namespace trace_api = opentelemetry::trace;
namespace trace_sdk = opentelemetry::sdk::trace;
Expand Down Expand Up @@ -53,9 +54,11 @@ libmexclass::proxy::MakeResult TracerProviderProxy::make(const libmexclass::prox

auto resource_custom = createResource(resourcenames_mda, resourcevalues_mda);

out = std::make_shared<TracerProviderProxy>(nostd::shared_ptr<trace_api::TracerProvider>(
std::move(trace_sdk::TracerProviderFactory::Create(std::move(processor), resource_custom,
std::move(sampler)))));
std::unique_ptr<trace_sdk::TracerProvider> p_sdk = trace_sdk::TracerProviderFactory::Create(std::move(processor),
resource_custom, std::move(sampler));
nostd::shared_ptr<trace_sdk::TracerProvider> p_sdk_shared(std::move(p_sdk));
nostd::shared_ptr<trace_api::TracerProvider> p_api_shared(std::move(p_sdk_shared));
out = std::make_shared<TracerProviderProxy>(p_api_shared);
}
return out;
}
Expand Down
1 change: 1 addition & 0 deletions test/tlogs_sdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function testOtlpFileExporter(testCase)

% perform test comparisons
forceFlush(lp, testCase.ForceFlushTimeout);
clear("lg", "lp");
results = jsondecode(fileread(alias));

% check logger name, log body and severity
Expand Down
2 changes: 1 addition & 1 deletion test/tmetrics_sdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function testOtlpFileExporter(testCase)
ct.add(val);

% fetch result
clear p;
clear("ct", "mt", "p");
results = jsondecode(fileread(alias));

% verify meter and counter names
Expand Down
4 changes: 2 additions & 2 deletions test/ttrace_sdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ function testOtlpFileExporter(testCase)
tracername = "foo";
spanname = "bar";
tr = getTracer(tp, tracername);
sp = startSpan(tr, spanname);
sp = startSpan(tr, spanname); %#ok<NASGU>
pause(1);
endSpan(sp);
clear("sp", "tr", "tp");

% perform test comparisons
results = jsondecode(fileread(alias));
Expand Down

0 comments on commit 9546b11

Please sign in to comment.