From 0fa41f9e261163ebdc7eb95a7fe85a094622aa0d Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Mon, 24 Mar 2025 17:09:19 -0400 Subject: [PATCH 1/2] [SDK] Use OPENTELEMETRY_EXPORT and static local variables (#3314) --- .../opentelemetry/sdk/metrics/meter_config.h | 4 +--- .../opentelemetry/sdk/trace/tracer_config.h | 4 +--- sdk/src/metrics/meter_config.cc | 17 ++++++++--------- sdk/src/trace/tracer_config.cc | 17 ++++++++--------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_config.h b/sdk/include/opentelemetry/sdk/metrics/meter_config.h index abb22154d2..3523230e1c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_config.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_config.h @@ -16,7 +16,7 @@ namespace metrics * ScopeConfigurator should be used to compute the desired MeterConfig which can then be used to * configure a Meter. */ -class MeterConfig +class OPENTELEMETRY_EXPORT MeterConfig { public: bool operator==(const MeterConfig &other) const noexcept; @@ -51,8 +51,6 @@ class MeterConfig private: explicit MeterConfig(const bool disabled = false) : disabled_(disabled) {} bool disabled_; - static const MeterConfig kDefaultConfig; - static const MeterConfig kDisabledConfig; }; } // namespace metrics } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_config.h b/sdk/include/opentelemetry/sdk/trace/tracer_config.h index 708d05b5e8..3fa5a144d3 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_config.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_config.h @@ -16,7 +16,7 @@ namespace trace * ScopeConfigurator should be used to compute the desired TracerConfig which can then be used to * configure a Tracer. */ -class TracerConfig +class OPENTELEMETRY_EXPORT TracerConfig { public: bool operator==(const TracerConfig &other) const noexcept; @@ -51,8 +51,6 @@ class TracerConfig private: explicit TracerConfig(const bool disabled = false) : disabled_(disabled) {} bool disabled_; - static const TracerConfig kDefaultConfig; - static const TracerConfig kDisabledConfig; }; } // namespace trace } // namespace sdk diff --git a/sdk/src/metrics/meter_config.cc b/sdk/src/metrics/meter_config.cc index cef0d60da1..85f7d4caf7 100644 --- a/sdk/src/metrics/meter_config.cc +++ b/sdk/src/metrics/meter_config.cc @@ -8,31 +8,30 @@ namespace sdk namespace metrics { -const MeterConfig MeterConfig::kDefaultConfig = MeterConfig(); -const MeterConfig MeterConfig::kDisabledConfig = MeterConfig(true); - -bool MeterConfig::operator==(const MeterConfig &other) const noexcept +OPENTELEMETRY_EXPORT bool MeterConfig::operator==(const MeterConfig &other) const noexcept { return disabled_ == other.disabled_; } -bool MeterConfig::IsEnabled() const noexcept +OPENTELEMETRY_EXPORT bool MeterConfig::IsEnabled() const noexcept { return !disabled_; } -MeterConfig MeterConfig::Disabled() +OPENTELEMETRY_EXPORT MeterConfig MeterConfig::Disabled() { + static const auto kDisabledConfig = MeterConfig(true); return kDisabledConfig; } -MeterConfig MeterConfig::Enabled() +OPENTELEMETRY_EXPORT MeterConfig MeterConfig::Enabled() { - return kDefaultConfig; + return Default(); } -MeterConfig MeterConfig::Default() +OPENTELEMETRY_EXPORT MeterConfig MeterConfig::Default() { + static const auto kDefaultConfig = MeterConfig(); return kDefaultConfig; } diff --git a/sdk/src/trace/tracer_config.cc b/sdk/src/trace/tracer_config.cc index 8c9dd93652..f32c2d78e1 100644 --- a/sdk/src/trace/tracer_config.cc +++ b/sdk/src/trace/tracer_config.cc @@ -9,30 +9,29 @@ namespace sdk namespace trace { -const TracerConfig TracerConfig::kDefaultConfig = TracerConfig(); -const TracerConfig TracerConfig::kDisabledConfig = TracerConfig(true); - -TracerConfig TracerConfig::Disabled() +OPENTELEMETRY_EXPORT TracerConfig TracerConfig::Disabled() { + static const auto kDisabledConfig = TracerConfig(true); return kDisabledConfig; } -TracerConfig TracerConfig::Enabled() +OPENTELEMETRY_EXPORT TracerConfig TracerConfig::Enabled() { - return kDefaultConfig; + return Default(); } -TracerConfig TracerConfig::Default() +OPENTELEMETRY_EXPORT TracerConfig TracerConfig::Default() { + static const auto kDefaultConfig = TracerConfig(); return kDefaultConfig; } -bool TracerConfig::IsEnabled() const noexcept +OPENTELEMETRY_EXPORT bool TracerConfig::IsEnabled() const noexcept { return !disabled_; } -bool TracerConfig::operator==(const TracerConfig &other) const noexcept +OPENTELEMETRY_EXPORT bool TracerConfig::operator==(const TracerConfig &other) const noexcept { return disabled_ == other.disabled_; } From 216f3f739978ef03876805a3d941b359b79df489 Mon Sep 17 00:00:00 2001 From: Doug Barker Date: Mon, 24 Mar 2025 23:07:49 -0600 Subject: [PATCH 2/2] [BUILD] Fix elasticsearch exporter json compatibility (#3313) * fix build issue with elasticsearch exporter and older versions of nlohmann-json * run the cmake.test on 22.04 to verify compatibility with the older json package * use class instead of typename in template args --------- --- .github/workflows/ci.yml | 14 +++++--------- exporters/elasticsearch/src/es_log_recordable.cc | 10 ++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d17ae2ca2..99f6ec22c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,23 +41,19 @@ jobs: # ./ci/do_ci.sh cmake.exporter.otprotocol.test cmake_test: - name: CMake test (without otlp-exporter) - runs-on: ubuntu-latest + name: CMake test (prometheus, elasticsearch, zipkin) + runs-on: ubuntu-22.04 + env: + CXX_STANDARD: '17' steps: - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup - env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 run: | sudo -E ./ci/setup_googletest.sh sudo -E ./ci/setup_ci_environment.sh - - name: run cmake tests (without otlp-exporter) - env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 + - name: run cmake tests run: | ./ci/do_ci.sh cmake.test diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 7376a9c78a..1b6fe3f0e3 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -34,6 +34,16 @@ struct json_assign_visitor { *j_ = u; } + + template + void operator()(const opentelemetry::nostd::span &span) + { + *j_ = nlohmann::json::array(); + for (const auto &elem : span) + { + j_->push_back(elem); + } + } }; template <>