From 21576b26d7848c92d60470b74259d56b7cd1c608 Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 11:26:08 +0800 Subject: [PATCH 1/8] Update otel-cpp --- ports/telemetry/opentelemetry-cpp.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/telemetry/opentelemetry-cpp.cmake b/ports/telemetry/opentelemetry-cpp.cmake index 43323c3..9ab2ed1 100644 --- a/ports/telemetry/opentelemetry-cpp.cmake +++ b/ports/telemetry/opentelemetry-cpp.cmake @@ -37,7 +37,7 @@ if(NOT TARGET opentelemetry-cpp::api AND NOT TARGET opentelemetry-cpp::sdk) if(NOT TARGET opentelemetry-cpp::api AND NOT TARGET opentelemetry-cpp::sdk) unset(ATFRAMEWORK_CMAKE_TOOLSET_THIRD_PARTY_OPENTELEMETRY_CPP_INCLUDE_DIRECTORIES) - project_third_party_port_declare(opentelemetry_cpp VERSION "v1.15.0" GIT_URL + project_third_party_port_declare(opentelemetry_cpp VERSION "v1.17.0" GIT_URL "https://github.com/open-telemetry/opentelemetry-cpp.git") project_third_party_try_patch_file( From 81c3c027c30ed413537d725c9bad89e6b8d17abc Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 12:09:18 +0800 Subject: [PATCH 2/8] Fix test --- test/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 39fcd2a..1159069 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -5,12 +5,13 @@ #if defined(HAVE_OPENTELEMETRY_CPP) && HAVE_OPENTELEMETRY_CPP # include "opentelemetry/exporters/ostream/span_exporter_factory.h" +# include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/batch_span_processor_factory.h" # include "opentelemetry/sdk/trace/batch_span_processor_options.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/exporter.h" +# include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" + #endif #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF @@ -86,7 +87,8 @@ static void OpentelemetryInitTracer() { auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider. - opentelemetry::trace::Provider::SetTracerProvider(std::move(provider)); + opentelemetry::trace::Provider::SetTracerProvider( + opentelemetry::nostd::shared_ptr{provider.release()}); } opentelemetry::nostd::shared_ptr GetTracer() { From 257056d1c383a71be71784dbfa679aef750d5db2 Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 13:28:08 +0800 Subject: [PATCH 3/8] Fix mimalloc patch. fix otel test --- ports/malloc/mimalloc-v2.1.7.patch | 49 ++++++++++++++++++++++++++++++ test/main.cpp | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ports/malloc/mimalloc-v2.1.7.patch diff --git a/ports/malloc/mimalloc-v2.1.7.patch b/ports/malloc/mimalloc-v2.1.7.patch new file mode 100644 index 0000000..f9f8e62 --- /dev/null +++ b/ports/malloc/mimalloc-v2.1.7.patch @@ -0,0 +1,49 @@ +diff --git a/include/mimalloc/atomic.h b/include/mimalloc/atomic.h +index d5333dd..ae31bf3 100644 +--- a/include/mimalloc/atomic.h ++++ b/include/mimalloc/atomic.h +@@ -30,6 +30,9 @@ terms of the MIT license. A copy of the license can be found in the file + #else + #define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x) + #endif ++#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L ++#include ++#endif + #elif defined(_MSC_VER) + // Use MSVC C wrapper for C11 atomics + #define _Atomic(tp) tp +diff --git a/src/alloc.c b/src/alloc.c +index 86aaae7..c95a8a3 100644 +--- a/src/alloc.c ++++ b/src/alloc.c +@@ -439,10 +439,10 @@ but we call `exit` instead (i.e. not returning). + #ifdef __cplusplus + #include + static bool mi_try_new_handler(bool nothrow) { +- #if defined(_MSC_VER) || (__cplusplus >= 201103L) ++ #if (defined(_MSC_VER) || (__cplusplus >= 201103L)) && !(defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)) + std::new_handler h = std::get_new_handler(); + #else +- std::new_handler h = std::set_new_handler(); ++ std::new_handler h = std::set_new_handler(nullptr); + std::set_new_handler(h); + #endif + if (h==NULL) { +diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c +index dd665d3..d413ad0 100644 +--- a/src/prim/unix/prim.c ++++ b/src/prim/unix/prim.c +@@ -700,7 +700,12 @@ void _mi_prim_out_stderr( const char* msg ) { + #if !defined(MI_USE_ENVIRON) || (MI_USE_ENVIRON!=0) + // On Posix systemsr use `environ` to access environment variables + // even before the C runtime is initialized. +-#if defined(__APPLE__) && defined(__has_include) && __has_include() ++#if defined(__APPLE__) && defined(__has_include) ++# if __has_include() ++# define MI_HAVE_CRT_EXTERNS ++# endif ++#endif ++#if defined(MI_HAVE_CRT_EXTERNS) + #include + static char** mi_get_environ(void) { + return (*_NSGetEnviron()); diff --git a/test/main.cpp b/test/main.cpp index 1159069..548a150 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -88,7 +88,7 @@ static void OpentelemetryInitTracer() { auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider. opentelemetry::trace::Provider::SetTracerProvider( - opentelemetry::nostd::shared_ptr{provider.release()}); + opentelemetry::nostd::shared_ptr{provider.release()}); } opentelemetry::nostd::shared_ptr GetTracer() { From 9834b75d106be6f07f784312142c2a88a3ef74a2 Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 14:26:06 +0800 Subject: [PATCH 4/8] Fix std::make_unique --- ports/telemetry/opentelemetry-cpp-v1.17.patch | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/ports/telemetry/opentelemetry-cpp-v1.17.patch b/ports/telemetry/opentelemetry-cpp-v1.17.patch index ab76d9c..2e8e495 100644 --- a/ports/telemetry/opentelemetry-cpp-v1.17.patch +++ b/ports/telemetry/opentelemetry-cpp-v1.17.patch @@ -17,3 +17,83 @@ index fd41fa7..9edd3a0 100644 function(install_windows_deps) # Bootstrap vcpkg from CMake and auto-install deps in case if we are missing +diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h +index b3f5e61..0b5bd55 100644 +--- a/api/include/opentelemetry/nostd/unique_ptr.h ++++ b/api/include/opentelemetry/nostd/unique_ptr.h +@@ -175,6 +175,12 @@ bool operator!=(std::nullptr_t, const unique_ptr &rhs) noexcept + { + return nullptr != rhs.get(); + } ++ ++template ++unique_ptr make_unique(Args &&...args) { ++ return unique_ptr(new T(std::forward(args)...)); ++} ++ + } // namespace nostd + OPENTELEMETRY_END_NAMESPACE + #endif /* OPENTELEMETRY_HAVE_STD_UNIQUE_PTR */ +diff --git a/api/include/opentelemetry/std/unique_ptr.h b/api/include/opentelemetry/std/unique_ptr.h +index 4b25b7c..0c2f1b1 100644 +--- a/api/include/opentelemetry/std/unique_ptr.h ++++ b/api/include/opentelemetry/std/unique_ptr.h +@@ -18,5 +18,14 @@ namespace nostd + template + using unique_ptr = std::unique_ptr<_Types...>; + ++# if (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) ++using std::make_unique; ++# else ++template ++unique_ptr make_unique(Args &&...args) { ++ return unique_ptr(new T(std::forward(args)...)); ++} ++# endif ++ + } // namespace nostd + OPENTELEMETRY_END_NAMESPACE +diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc +index f2577c4..40d96ca 100644 +--- a/exporters/memory/src/in_memory_metric_exporter_factory.cc ++++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc +@@ -49,7 +49,7 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter + OTEL_INTERNAL_LOG_ERROR("[In Memory Metric Exporter] Exporting failed, exporter is shutdown"); + return ExportResult::kFailure; + } +- data_->Add(std::make_unique(data)); ++ data_->Add(nostd::make_unique(data)); + return ExportResult::kSuccess; + } + +@@ -85,7 +85,7 @@ std::unique_ptr InMemoryMetricExporterFactory::Create( + const std::shared_ptr &data, + const AggregationTemporalitySelector &temporality) + { +- return std::make_unique(data, temporality); ++ return nostd::make_unique(data, temporality); + } + + } // namespace memory +diff --git a/exporters/memory/test/in_memory_metric_data_test.cc b/exporters/memory/test/in_memory_metric_data_test.cc +index ffaba2c..fabc240 100644 +--- a/exporters/memory/test/in_memory_metric_data_test.cc ++++ b/exporters/memory/test/in_memory_metric_data_test.cc +@@ -23,7 +23,7 @@ TEST(InMemoryMetricDataTest, CircularBuffer) + { + CircularBufferInMemoryMetricData buf(10); + Resource resource = Resource::GetEmpty(); +- buf.Add(std::make_unique( ++ buf.Add(nostd::make_unique( + &resource, std::vector{{nullptr, std::vector{}}})); + EXPECT_EQ((*buf.Get().begin())->resource_, &resource); + } +@@ -45,7 +45,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) + md.instrument_descriptor.name_ = "my-metric"; + md.point_data_attr_.push_back(pda); + +- agg.Add(std::make_unique( ++ agg.Add(nostd::make_unique( + &resource, std::vector{{scope.get(), std::vector{md}}})); + auto it = agg.Get("my-scope", "my-metric").begin(); + From caacd62ed8ae6a23a98c7959fce2f114eca258af Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 15:00:38 +0800 Subject: [PATCH 5/8] Fix nostd::make_unique again --- ports/telemetry/opentelemetry-cpp-v1.17.patch | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ports/telemetry/opentelemetry-cpp-v1.17.patch b/ports/telemetry/opentelemetry-cpp-v1.17.patch index 2e8e495..b8529aa 100644 --- a/ports/telemetry/opentelemetry-cpp-v1.17.patch +++ b/ports/telemetry/opentelemetry-cpp-v1.17.patch @@ -54,46 +54,62 @@ index 4b25b7c..0c2f1b1 100644 } // namespace nostd OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc -index f2577c4..40d96ca 100644 +index f2577c4..aca2cce 100644 --- a/exporters/memory/src/in_memory_metric_exporter_factory.cc +++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc -@@ -49,7 +49,7 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter +@@ -3,6 +3,7 @@ + + #include "opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h" + #include "opentelemetry/exporters/memory/in_memory_metric_data.h" ++#include "opentelemetry/nostd/unique_ptr.h" + #include "opentelemetry/sdk/common/global_log_handler.h" + #include "opentelemetry/sdk/metrics/export/metric_producer.h" + #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +@@ -49,7 +50,7 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter OTEL_INTERNAL_LOG_ERROR("[In Memory Metric Exporter] Exporting failed, exporter is shutdown"); return ExportResult::kFailure; } - data_->Add(std::make_unique(data)); -+ data_->Add(nostd::make_unique(data)); ++ data_->Add(opentelemetry::nostd::make_unique(data)); return ExportResult::kSuccess; } -@@ -85,7 +85,7 @@ std::unique_ptr InMemoryMetricExporterFactory::Create( +@@ -85,7 +86,7 @@ std::unique_ptr InMemoryMetricExporterFactory::Create( const std::shared_ptr &data, const AggregationTemporalitySelector &temporality) { - return std::make_unique(data, temporality); -+ return nostd::make_unique(data, temporality); ++ return opentelemetry::nostd::make_unique(data, temporality); } } // namespace memory diff --git a/exporters/memory/test/in_memory_metric_data_test.cc b/exporters/memory/test/in_memory_metric_data_test.cc -index ffaba2c..fabc240 100644 +index ffaba2c..c2df832 100644 --- a/exporters/memory/test/in_memory_metric_data_test.cc +++ b/exporters/memory/test/in_memory_metric_data_test.cc -@@ -23,7 +23,7 @@ TEST(InMemoryMetricDataTest, CircularBuffer) +@@ -2,6 +2,7 @@ + // SPDX-License-Identifier: Apache-2.0 + + #include "opentelemetry/exporters/memory/in_memory_metric_data.h" ++#include "opentelemetry/nostd/unique_ptr.h" + #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" + #include "opentelemetry/sdk/metrics/export/metric_producer.h" + #include "opentelemetry/sdk/resource/resource.h" +@@ -23,7 +24,7 @@ TEST(InMemoryMetricDataTest, CircularBuffer) { CircularBufferInMemoryMetricData buf(10); Resource resource = Resource::GetEmpty(); - buf.Add(std::make_unique( -+ buf.Add(nostd::make_unique( ++ buf.Add(opentelemetry::nostd::make_unique( &resource, std::vector{{nullptr, std::vector{}}})); EXPECT_EQ((*buf.Get().begin())->resource_, &resource); } -@@ -45,7 +45,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) +@@ -45,7 +46,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) md.instrument_descriptor.name_ = "my-metric"; md.point_data_attr_.push_back(pda); - agg.Add(std::make_unique( -+ agg.Add(nostd::make_unique( ++ agg.Add(opentelemetry::nostd::make_unique( &resource, std::vector{{scope.get(), std::vector{md}}})); auto it = agg.Get("my-scope", "my-metric").begin(); From 4631b1d8d1af8832e02dbe21deeed92ed2187015 Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 15:27:35 +0800 Subject: [PATCH 6/8] Fix `std::unique_ptr` in otel-cpp --- ports/telemetry/opentelemetry-cpp-v1.17.patch | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ports/telemetry/opentelemetry-cpp-v1.17.patch b/ports/telemetry/opentelemetry-cpp-v1.17.patch index b8529aa..f95e99a 100644 --- a/ports/telemetry/opentelemetry-cpp-v1.17.patch +++ b/ports/telemetry/opentelemetry-cpp-v1.17.patch @@ -54,7 +54,7 @@ index 4b25b7c..0c2f1b1 100644 } // namespace nostd OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc -index f2577c4..aca2cce 100644 +index f2577c4..5f1f716 100644 --- a/exporters/memory/src/in_memory_metric_exporter_factory.cc +++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc @@ -3,6 +3,7 @@ @@ -70,7 +70,7 @@ index f2577c4..aca2cce 100644 return ExportResult::kFailure; } - data_->Add(std::make_unique(data)); -+ data_->Add(opentelemetry::nostd::make_unique(data)); ++ data_->Add(std::unique_ptr(new ResourceMetrics{data})); return ExportResult::kSuccess; } @@ -79,12 +79,12 @@ index f2577c4..aca2cce 100644 const AggregationTemporalitySelector &temporality) { - return std::make_unique(data, temporality); -+ return opentelemetry::nostd::make_unique(data, temporality); ++ return std::unique_ptr(new InMemoryMetricExporter{data, temporality}); } } // namespace memory diff --git a/exporters/memory/test/in_memory_metric_data_test.cc b/exporters/memory/test/in_memory_metric_data_test.cc -index ffaba2c..c2df832 100644 +index ffaba2c..342c201 100644 --- a/exporters/memory/test/in_memory_metric_data_test.cc +++ b/exporters/memory/test/in_memory_metric_data_test.cc @@ -2,6 +2,7 @@ @@ -95,21 +95,25 @@ index ffaba2c..c2df832 100644 #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/resource/resource.h" -@@ -23,7 +24,7 @@ TEST(InMemoryMetricDataTest, CircularBuffer) +@@ -23,8 +24,8 @@ TEST(InMemoryMetricDataTest, CircularBuffer) { CircularBufferInMemoryMetricData buf(10); Resource resource = Resource::GetEmpty(); - buf.Add(std::make_unique( -+ buf.Add(opentelemetry::nostd::make_unique( - &resource, std::vector{{nullptr, std::vector{}}})); +- &resource, std::vector{{nullptr, std::vector{}}})); ++ buf.Add(std::unique_ptr(new ResourceMetrics{ ++ &resource, std::vector{{nullptr, std::vector{}}}})); EXPECT_EQ((*buf.Get().begin())->resource_, &resource); } -@@ -45,7 +46,7 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) + +@@ -45,8 +46,8 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) md.instrument_descriptor.name_ = "my-metric"; md.point_data_attr_.push_back(pda); - agg.Add(std::make_unique( -+ agg.Add(opentelemetry::nostd::make_unique( - &resource, std::vector{{scope.get(), std::vector{md}}})); +- &resource, std::vector{{scope.get(), std::vector{md}}})); ++ agg.Add(std::unique_ptr(new ResourceMetrics{ ++ &resource, std::vector{{scope.get(), std::vector{md}}}})); auto it = agg.Get("my-scope", "my-metric").begin(); + auto saved_point = opentelemetry::nostd::get(it->second); From 52bf6d0c984cf3ff0c1ce114dc708d669c45849e Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 16:28:23 +0800 Subject: [PATCH 7/8] Fix callback parameter in `InMemoryMetricExporterFactory::Create` when using C++11 mode --- ports/telemetry/opentelemetry-cpp-v1.17.patch | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ports/telemetry/opentelemetry-cpp-v1.17.patch b/ports/telemetry/opentelemetry-cpp-v1.17.patch index f95e99a..3a38aa5 100644 --- a/ports/telemetry/opentelemetry-cpp-v1.17.patch +++ b/ports/telemetry/opentelemetry-cpp-v1.17.patch @@ -54,7 +54,7 @@ index 4b25b7c..0c2f1b1 100644 } // namespace nostd OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc -index f2577c4..5f1f716 100644 +index f2577c4..9d36047 100644 --- a/exporters/memory/src/in_memory_metric_exporter_factory.cc +++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc @@ -3,6 +3,7 @@ @@ -74,7 +74,15 @@ index f2577c4..5f1f716 100644 return ExportResult::kSuccess; } -@@ -85,7 +86,7 @@ std::unique_ptr InMemoryMetricExporterFactory::Create( +@@ -78,14 +79,14 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter + std::unique_ptr InMemoryMetricExporterFactory::Create( + const std::shared_ptr &data) + { +- return Create(data, [](auto) { return AggregationTemporality::kCumulative; }); ++ return Create(data, [](sdk::metrics::InstrumentType) { return AggregationTemporality::kCumulative; }); + } + + std::unique_ptr InMemoryMetricExporterFactory::Create( const std::shared_ptr &data, const AggregationTemporalitySelector &temporality) { From 650e813971abcebe2007ac5de67e4d3596540929 Mon Sep 17 00:00:00 2001 From: owent Date: Mon, 14 Oct 2024 17:15:39 +0800 Subject: [PATCH 8/8] Fix compatibility --- ports/telemetry/opentelemetry-cpp-v1.17.patch | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ports/telemetry/opentelemetry-cpp-v1.17.patch b/ports/telemetry/opentelemetry-cpp-v1.17.patch index 3a38aa5..fe3b5f0 100644 --- a/ports/telemetry/opentelemetry-cpp-v1.17.patch +++ b/ports/telemetry/opentelemetry-cpp-v1.17.patch @@ -53,6 +53,28 @@ index 4b25b7c..0c2f1b1 100644 + } // namespace nostd OPENTELEMETRY_END_NAMESPACE +diff --git a/exporters/memory/src/in_memory_metric_data.cc b/exporters/memory/src/in_memory_metric_data.cc +index 2a77e0b..87015cc 100644 +--- a/exporters/memory/src/in_memory_metric_data.cc ++++ b/exporters/memory/src/in_memory_metric_data.cc +@@ -31,7 +31,7 @@ void SimpleAggregateInMemoryMetricData::Add(std::unique_ptr res + const auto &metric = m.instrument_descriptor.name_; + for (const auto &pda : m.point_data_attr_) + { +- data_[{scope, metric}].insert({pda.attributes, pda.point_data}); ++ data_[std::tuple{scope, metric}].insert({pda.attributes, pda.point_data}); + } + } + } +@@ -41,7 +41,7 @@ const SimpleAggregateInMemoryMetricData::AttributeToPoint &SimpleAggregateInMemo + const std::string &scope, + const std::string &metric) + { +- return data_[{scope, metric}]; ++ return data_[std::tuple{scope, metric}]; + } + + void SimpleAggregateInMemoryMetricData::Clear() diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc index f2577c4..9d36047 100644 --- a/exporters/memory/src/in_memory_metric_exporter_factory.cc