Skip to content

Commit

Permalink
Merge pull request #124 from owent/dev
Browse files Browse the repository at this point in the history
Update otel-cpp
  • Loading branch information
owent authored Oct 14, 2024
2 parents 16eabdc + 650e813 commit 5b8770a
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 4 deletions.
49 changes: 49 additions & 0 deletions ports/malloc/mimalloc-v2.1.7.patch
Original file line number Diff line number Diff line change
@@ -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 <stdatomic.h>
+#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 <new>
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(<crt_externs.h>)
+#if defined(__APPLE__) && defined(__has_include)
+# if __has_include(<crt_externs.h>)
+# define MI_HAVE_CRT_EXTERNS
+# endif
+#endif
+#if defined(MI_HAVE_CRT_EXTERNS)
#include <crt_externs.h>
static char** mi_get_environ(void) {
return (*_NSGetEnviron());
130 changes: 130 additions & 0 deletions ports/telemetry/opentelemetry-cpp-v1.17.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,133 @@ 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<T> &rhs) noexcept
{
return nullptr != rhs.get();
}
+
+template <class T, class... Args>
+unique_ptr<T> make_unique(Args &&...args) {
+ return unique_ptr<T>(new T(std::forward<Args>(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 <class... _Types>
using unique_ptr = std::unique_ptr<_Types...>;

+# if (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
+using std::make_unique;
+# else
+template <class T, class... Args>
+unique_ptr<T> make_unique(Args &&...args) {
+ return unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+# endif
+
} // 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<ResourceMetrics> 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<std::string, std::string>{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<std::string, std::string>{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
+++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc
@@ -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<ResourceMetrics>(data));
+ data_->Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{data}));
return ExportResult::kSuccess;
}

@@ -78,14 +79,14 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter
std::unique_ptr<PushMetricExporter> InMemoryMetricExporterFactory::Create(
const std::shared_ptr<InMemoryMetricData> &data)
{
- return Create(data, [](auto) { return AggregationTemporality::kCumulative; });
+ return Create(data, [](sdk::metrics::InstrumentType) { return AggregationTemporality::kCumulative; });
}

std::unique_ptr<PushMetricExporter> InMemoryMetricExporterFactory::Create(
const std::shared_ptr<InMemoryMetricData> &data,
const AggregationTemporalitySelector &temporality)
{
- return std::make_unique<InMemoryMetricExporter>(data, temporality);
+ return std::unique_ptr<InMemoryMetricExporter>(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..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 @@
// 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,8 +24,8 @@ TEST(InMemoryMetricDataTest, CircularBuffer)
{
CircularBufferInMemoryMetricData buf(10);
Resource resource = Resource::GetEmpty();
- buf.Add(std::make_unique<ResourceMetrics>(
- &resource, std::vector<ScopeMetrics>{{nullptr, std::vector<MetricData>{}}}));
+ buf.Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{
+ &resource, std::vector<ScopeMetrics>{{nullptr, std::vector<MetricData>{}}}}));
EXPECT_EQ((*buf.Get().begin())->resource_, &resource);
}

@@ -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<ResourceMetrics>(
- &resource, std::vector<ScopeMetrics>{{scope.get(), std::vector<MetricData>{md}}}));
+ agg.Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{
+ &resource, std::vector<ScopeMetrics>{{scope.get(), std::vector<MetricData>{md}}}}));
auto it = agg.Get("my-scope", "my-metric").begin();

auto saved_point = opentelemetry::nostd::get<SumPointData>(it->second);
2 changes: 1 addition & 1 deletion ports/telemetry/opentelemetry-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<opentelemetry::trace::TracerProvider>{provider.release()});
}

opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer() {
Expand Down

0 comments on commit 5b8770a

Please sign in to comment.