diff --git a/CMakeLists.txt b/CMakeLists.txt index fb18701a99..515c48895e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,12 @@ endif(WIN32) option(WITH_EXAMPLES "Whether to build examples" ON) +option(WITH_METRICS_PREVIEW "Whether to build metrics preview" OFF) + +if(WITH_METRICS_PREVIEW) + add_definitions(-DENABLE_METRICS_PREVIEW) +endif() + find_package(Threads) function(install_windows_deps) diff --git a/api/include/opentelemetry/metrics/async_instruments.h b/api/include/opentelemetry/metrics/async_instruments.h index 24eab3467e..430618157c 100644 --- a/api/include/opentelemetry/metrics/async_instruments.h +++ b/api/include/opentelemetry/metrics/async_instruments.h @@ -1,7 +1,8 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "instrument.h" -#include "observer_result.h" +# include "instrument.h" +# include "observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -81,3 +82,4 @@ class UpDownSumObserver : virtual public AsynchronousInstrument } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/instrument.h b/api/include/opentelemetry/metrics/instrument.h index 5d1c07a5d5..c763c61085 100644 --- a/api/include/opentelemetry/metrics/instrument.h +++ b/api/include/opentelemetry/metrics/instrument.h @@ -1,10 +1,11 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/string_view.h" +# include +# include "opentelemetry/common/attribute_value.h" +# include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -202,3 +203,4 @@ class AsynchronousInstrument : virtual public Instrument } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 3d8c2e037d..c4f812ee6c 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -1,12 +1,13 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/async_instruments.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/metrics/sync_instruments.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/version.h" +# include "opentelemetry/metrics/async_instruments.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/metrics/sync_instruments.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/span.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -281,3 +282,4 @@ class Meter }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index aa57715632..eb1c5084c9 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -1,8 +1,9 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -25,3 +26,4 @@ class MeterProvider }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 552e125dd0..51322c1504 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,19 +1,20 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW // Please refer to provider.h for documentation on how to obtain a Meter object. // // This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be // used directly. Please refer to meter.h for documentation on these interfaces. -#include "opentelemetry/metrics/async_instruments.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/metrics/meter_provider.h" -#include "opentelemetry/metrics/sync_instruments.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" -#include "opentelemetry/version.h" +# include "opentelemetry/metrics/async_instruments.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/metrics/sync_instruments.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/nostd/unique_ptr.h" +# include "opentelemetry/version.h" -#include +# include // TODO: Create generic short pattern for opentelemetry::common and opentelemetry::trace and others // as necessary @@ -647,3 +648,4 @@ class NoopMeterProvider final : public opentelemetry::metrics::MeterProvider }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h index c7733c75e4..5f804f9265 100644 --- a/api/include/opentelemetry/metrics/observer_result.h +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -1,7 +1,8 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "instrument.h" -#include "opentelemetry/nostd/shared_ptr.h" +# include "instrument.h" +# include "opentelemetry/nostd/shared_ptr.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -34,3 +35,4 @@ class ObserverResult } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/provider.h b/api/include/opentelemetry/metrics/provider.h index 88b97fdf5f..eee1ba6405 100644 --- a/api/include/opentelemetry/metrics/provider.h +++ b/api/include/opentelemetry/metrics/provider.h @@ -1,11 +1,11 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW +# include -#include - -#include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/metrics/meter_provider.h" -#include "opentelemetry/metrics/noop.h" -#include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/common/spin_lock_mutex.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/metrics/noop.h" +# include "opentelemetry/nostd/shared_ptr.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -53,3 +53,4 @@ class Provider } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index c5ab128074..05bc16a862 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -1,6 +1,7 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "instrument.h" +# include "instrument.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -174,3 +175,4 @@ class ValueRecorder : virtual public SynchronousInstrument } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index eaf09e44e0..63f9369a1a 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -3,7 +3,9 @@ add_subdirectory(context) add_subdirectory(plugin) add_subdirectory(nostd) add_subdirectory(trace) -add_subdirectory(metrics) +if(WITH_METRICS_PREVIEW) + add_subdirectory(metrics) +endif() add_subdirectory(logs) add_subdirectory(common) add_subdirectory(baggage) diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index 252cead516..3ecc7e2c7c 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -1,7 +1,7 @@ -#include "opentelemetry/metrics/provider.h" -#include "opentelemetry/nostd/shared_ptr.h" - -#include +#ifdef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/metrics/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" using opentelemetry::metrics::Meter; using opentelemetry::metrics::MeterProvider; @@ -39,3 +39,4 @@ TEST(Provider, MultipleMeterProviders) ASSERT_NE(Provider::GetMeterProvider(), tf); } +#endif diff --git a/api/test/metrics/noop_instrument_test.cc b/api/test/metrics/noop_instrument_test.cc index c6bb8c7b81..b29ea05de8 100644 --- a/api/test/metrics/noop_instrument_test.cc +++ b/api/test/metrics/noop_instrument_test.cc @@ -1,8 +1,10 @@ -#include -#include -#include -#include -#include "opentelemetry/metrics/noop.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include + +# include "opentelemetry/metrics/noop.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -183,3 +185,4 @@ TEST(ValueRecorder, Record) } // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 8e43f78180..fc740cf282 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -1,11 +1,12 @@ -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/metrics/noop.h" -#include "opentelemetry/metrics/observer_result.h" -#include "opentelemetry/metrics/sync_instruments.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/metrics/noop.h" +# include "opentelemetry/metrics/observer_result.h" +# include "opentelemetry/metrics/sync_instruments.h" -#include -#include +# include +# include OPENTELEMETRY_BEGIN_NAMESPACE @@ -76,3 +77,4 @@ TEST(NoopMeter, RecordBatch) m->RecordDoubleBatch(labelkv, dsp, dval); } OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 04dadac177..ba19f94269 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -32,6 +32,7 @@ if [[ "$1" == "cmake.test" ]]; then -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ + -DWITH_METRICS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror" \ "${SRC_DIR}" make @@ -107,7 +108,7 @@ EOF examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null exit 0 elif [[ "$1" == "bazel.test" ]]; then - bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //... + bazel $BAZEL_STARTUP_OPTIONS build --copt=-DENABLE_METRICS_PREVIEW $BAZEL_OPTIONS //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //... exit 0 elif [[ "$1" == "bazel.legacy.test" ]]; then diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 56dc51b2d6..e0689f9a78 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,7 +7,9 @@ endif() add_subdirectory(plugin) add_subdirectory(simple) add_subdirectory(batch) -add_subdirectory(metrics_simple) +if(WITH_METRICS_PREVIEW) + add_subdirectory(metrics_simple) +endif() add_subdirectory(multithreaded) add_subdirectory(multi_processor) add_subdirectory(http) diff --git a/examples/metrics_simple/main.cc b/examples/metrics_simple/main.cc index ca8bb2bda3..57fe7390bc 100644 --- a/examples/metrics_simple/main.cc +++ b/examples/metrics_simple/main.cc @@ -1,9 +1,10 @@ -#include "opentelemetry/exporters/ostream/metrics_exporter.h" -#include "opentelemetry/metrics/provider.h" -#include "opentelemetry/sdk/metrics/controller.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_provider.h" -#include "opentelemetry/sdk/metrics/ungrouped_processor.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/exporters/ostream/metrics_exporter.h" +# include "opentelemetry/metrics/provider.h" +# include "opentelemetry/sdk/metrics/controller.h" +# include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/sdk/metrics/meter_provider.h" +# include "opentelemetry/sdk/metrics/ungrouped_processor.h" namespace sdkmetrics = opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; @@ -105,3 +106,9 @@ int main() } ControllerStateful.stop(); } +#else +int main() +{ + // empty +} +#endif diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt index 4ab469b7c2..f48b3bedb7 100644 --- a/exporters/CMakeLists.txt +++ b/exporters/CMakeLists.txt @@ -19,7 +19,7 @@ endif() add_subdirectory(ostream) add_subdirectory(memory) -if(WITH_PROMETHEUS) +if(WITH_PROMETHEUS AND WITH_METRICS_PREVIEW) add_subdirectory(prometheus) endif() diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index b9797b2974..9fff15d288 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -1,13 +1,9 @@ add_library(opentelemetry_exporter_ostream_logs src/log_exporter.cc) -add_library(opentelemetry_exporter_ostream_metrics src/metrics_exporter.cc) add_library(opentelemetry_exporter_ostream_span src/span_exporter.cc) set_target_properties(opentelemetry_exporter_ostream_logs PROPERTIES EXPORT_NAME ostream_log_exporter) -set_target_properties(opentelemetry_exporter_ostream_metrics - PROPERTIES EXPORT_NAME ostream_metrics_exporter) - set_target_properties(opentelemetry_exporter_ostream_span PROPERTIES EXPORT_NAME ostream_span_exporter) @@ -15,10 +11,6 @@ target_include_directories( opentelemetry_exporter_ostream_logs PUBLIC "$") -target_include_directories( - opentelemetry_exporter_ostream_metrics - PUBLIC "$") - target_include_directories( opentelemetry_exporter_ostream_span PUBLIC "$") @@ -26,15 +18,11 @@ target_include_directories( target_link_libraries(opentelemetry_exporter_ostream_logs PUBLIC opentelemetry_logs) -target_link_libraries(opentelemetry_exporter_ostream_metrics - PUBLIC opentelemetry_metrics) - target_link_libraries(opentelemetry_exporter_ostream_span PUBLIC opentelemetry_trace) install( TARGETS opentelemetry_exporter_ostream_logs - opentelemetry_exporter_ostream_metrics opentelemetry_exporter_ostream_span EXPORT "${PROJECT_NAME}-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -45,19 +33,15 @@ install( DIRECTORY include/opentelemetry/exporters/ostream DESTINATION include/opentelemetry/exporters/ FILES_MATCHING - PATTERN "*.h") + PATTERN "metrics_exporter.h" EXCLUDE) if(BUILD_TESTING) - add_executable(ostream_metrics_test test/ostream_metrics_test.cc) add_executable(ostream_span_test test/ostream_span_test.cc) add_executable(ostream_log_test test/ostream_log_test.cc) target_link_libraries(ostream_span_test ${GTEST_BOTH_LIBRARIES} opentelemetry_exporter_ostream_span) - target_link_libraries(ostream_metrics_test ${GTEST_BOTH_LIBRARIES} - opentelemetry_exporter_ostream_metrics) - target_link_libraries(ostream_log_test ${GTEST_BOTH_LIBRARIES} opentelemetry_exporter_ostream_logs) @@ -66,14 +50,40 @@ if(BUILD_TESTING) TEST_PREFIX exporter. TEST_LIST ostream_log_test) - gtest_add_tests( - TARGET ostream_metrics_test - TEST_PREFIX exporter. - TEST_LIST ostream_metrics_test) - gtest_add_tests( TARGET ostream_span_test TEST_PREFIX exporter. TEST_LIST ostream_span_test) endif() # BUILD_TESTING + +if(WITH_METRICS_PREVIEW) + add_library(opentelemetry_exporter_ostream_metrics src/metrics_exporter.cc) + set_target_properties(opentelemetry_exporter_ostream_metrics + PROPERTIES EXPORT_NAME ostream_metrics_exporter) + target_include_directories( + opentelemetry_exporter_ostream_metrics + PUBLIC "$") + target_link_libraries(opentelemetry_exporter_ostream_metrics + PUBLIC opentelemetry_metrics) + install( + TARGETS opentelemetry_exporter_ostream_metrics + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install( + DIRECTORY include/opentelemetry/exporters/ostream + DESTINATION include/opentelemetry/exporters/ + FILES_MATCHING + PATTERN "metrics_exporter.h") + if(BUILD_TESTING) + add_executable(ostream_metrics_test test/ostream_metrics_test.cc) + target_link_libraries(ostream_metrics_test ${GTEST_BOTH_LIBRARIES} + opentelemetry_exporter_ostream_metrics) + gtest_add_tests( + TARGET ostream_metrics_test + TEST_PREFIX exporter. + TEST_LIST ostream_metrics_test) + endif() +endif() diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h index 1a97682dfe..630ab4268b 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h @@ -1,12 +1,13 @@ -#pragma once +#ifdef ENABLE_METRICS_PREVIEW +# pragma once -#include -#include -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" -#include "opentelemetry/sdk/metrics/exporter.h" -#include "opentelemetry/sdk/metrics/record.h" +# include +# include +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" +# include "opentelemetry/sdk/metrics/exporter.h" +# include "opentelemetry/sdk/metrics/record.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdkmetrics = opentelemetry::sdk::metrics; @@ -161,3 +162,4 @@ class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter } // namespace metrics } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/ostream/src/metrics_exporter.cc b/exporters/ostream/src/metrics_exporter.cc index 7ebaa7e386..943ec3c98f 100644 --- a/exporters/ostream/src/metrics_exporter.cc +++ b/exporters/ostream/src/metrics_exporter.cc @@ -1,4 +1,5 @@ -#include "opentelemetry/exporters/ostream/metrics_exporter.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/exporters/ostream/metrics_exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -48,3 +49,4 @@ sdk::common::ExportResult OStreamMetricsExporter::Export( } // namespace metrics } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/ostream/test/ostream_metrics_test.cc b/exporters/ostream/test/ostream_metrics_test.cc index 07313ae2d1..53b58401a6 100644 --- a/exporters/ostream/test/ostream_metrics_test.cc +++ b/exporters/ostream/test/ostream_metrics_test.cc @@ -1,14 +1,16 @@ -#include "opentelemetry/exporters/ostream/metrics_exporter.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" -#include "opentelemetry/sdk/metrics/exporter.h" -#include "opentelemetry/sdk/metrics/record.h" - #include -#include +#ifdef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/ostream/metrics_exporter.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" +# include "opentelemetry/sdk/metrics/exporter.h" +# include "opentelemetry/sdk/metrics/record.h" + +# include namespace sdkmetrics = opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; @@ -288,3 +290,9 @@ TEST(OStreamMetricsExporter, PrintSketch) ASSERT_EQ(stdoutOutput.str(), expectedOutput); } +#else +TEST(OStreamMetricsExporter, DummyTest) +{ + // empty +} +#endif diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h index 93184edc02..ebf1e2d548 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include +# include +# include +# include -#include "opentelemetry/sdk/metrics/record.h" -#include "prometheus/collectable.h" -#include "prometheus/metric_family.h" -#include "prometheus_exporter_utils.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "prometheus/collectable.h" +# include "prometheus/metric_family.h" +# include "prometheus_exporter_utils.h" namespace prometheus_client = ::prometheus; namespace metric_sdk = opentelemetry::sdk::metrics; @@ -98,3 +98,4 @@ class PrometheusCollector : public prometheus_client::Collectable } // namespace prometheus } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h index de63b4d88e..cf7636d431 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include +# include +# include -#include "opentelemetry/sdk/metrics/record.h" -#include "prometheus/metric_family.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "prometheus/metric_family.h" namespace metric_sdk = opentelemetry::sdk::metrics; @@ -180,3 +180,4 @@ class PrometheusExporterUtils } // namespace prometheus } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/prometheus/src/prometheus_collector.cc b/exporters/prometheus/src/prometheus_collector.cc index b0c8330135..23e727f2ab 100644 --- a/exporters/prometheus/src/prometheus_collector.cc +++ b/exporters/prometheus/src/prometheus_collector.cc @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifdef ENABLE_METRICS_PREVIEW +# include -#include - -#include "opentelemetry/exporters/prometheus/prometheus_collector.h" +# include "opentelemetry/exporters/prometheus/prometheus_collector.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -173,3 +173,4 @@ int PrometheusCollector::GetMaxCollectionSize() const } // namespace prometheus } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/prometheus/src/prometheus_exporter_utils.cc b/exporters/prometheus/src/prometheus_exporter_utils.cc index 1a887b302d..303153499c 100644 --- a/exporters/prometheus/src/prometheus_exporter_utils.cc +++ b/exporters/prometheus/src/prometheus_exporter_utils.cc @@ -14,14 +14,15 @@ * limitations under the License. */ -#include -#include -#include -#include +#ifdef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include -#include "opentelemetry/exporters/prometheus/prometheus_exporter_utils.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "prometheus/metric_type.h" +# include "opentelemetry/exporters/prometheus/prometheus_exporter_utils.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "prometheus/metric_type.h" namespace prometheus_client = ::prometheus; @@ -454,3 +455,4 @@ void PrometheusExporterUtils::SetValue(std::vector values, } // namespace prometheus } // namespace exporter OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/prometheus/test/prometheus_collector_test.cc b/exporters/prometheus/test/prometheus_collector_test.cc index e80852eb41..8270bb3a2d 100644 --- a/exporters/prometheus/test/prometheus_collector_test.cc +++ b/exporters/prometheus/test/prometheus_collector_test.cc @@ -14,22 +14,23 @@ * limitations under the License. */ -#include -#include -#include -#include - -#include "opentelemetry/exporters/prometheus/prometheus_collector.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/version.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include + +# include "opentelemetry/exporters/prometheus/prometheus_collector.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/version.h" using opentelemetry::exporter::prometheus::PrometheusCollector; @@ -765,3 +766,4 @@ TEST(PrometheusCollector, ConcurrentlyAddingAndConcurrentlyCollecting) } OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/prometheus/test/prometheus_exporter_utils_test.cc b/exporters/prometheus/test/prometheus_exporter_utils_test.cc index 5bf9664b2d..e6725d81cd 100644 --- a/exporters/prometheus/test/prometheus_exporter_utils_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_utils_test.cc @@ -14,20 +14,21 @@ * limitations under the License. */ -#include -#include -#include -#include - -#include -#include -#include "opentelemetry/exporters/prometheus/prometheus_exporter_utils.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include +# include + +# include +# include "opentelemetry/exporters/prometheus/prometheus_exporter_utils.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" using opentelemetry::exporter::prometheus::PrometheusExporterUtils; namespace metric_sdk = opentelemetry::sdk::metrics; @@ -469,3 +470,4 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusMultipleAggregators) prometheus_client::MetricType::Gauge, 1, vals); } OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h index d3e878d785..7a950fe44c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h @@ -1,10 +1,11 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include "opentelemetry/common/timestamp.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/version.h" +# include +# include +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -151,3 +152,4 @@ class Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h index e744d9b150..f53a5d600f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h @@ -1,10 +1,11 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -75,11 +76,11 @@ class CounterAggregator final : public Aggregator } else { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Aggregators of different types cannot be merged."); -#else +# else std::terminate(); -#endif +# endif } } @@ -103,3 +104,4 @@ class CounterAggregator final : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/exact_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/exact_aggregator.h index b34bfd0643..2e2d36d23a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/exact_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/exact_aggregator.h @@ -1,13 +1,14 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" -#include -#include -#include -#include +# include +# include +# include +# include namespace metrics_api = opentelemetry::metrics; @@ -120,20 +121,20 @@ class ExactAggregator : public Aggregator if (!quant_estimation_) { // Log error -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::domain_error("Exact aggregator is not in quantile estimation mode!"); -#else +# else std::terminate(); -#endif +# endif } if (this->checkpoint_.size() == 0 || q < 0 || q > 1) { // Log error -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Arg 'q' must be between 0 and 1, inclusive"); -#else +# else std::terminate(); -#endif +# endif } else if (q == 0 || this->checkpoint_.size() == 1) { @@ -164,3 +165,4 @@ class ExactAggregator : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h index fa36f07981..403c2ec1db 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h @@ -1,13 +1,14 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/common/timestamp.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" -#include -#include -#include +# include +# include +# include namespace metrics_api = opentelemetry::metrics; @@ -141,3 +142,4 @@ class GaugeAggregator : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h index 6cd417f650..191cbf60e6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h @@ -1,12 +1,13 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include +# include +# include +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -32,11 +33,11 @@ class HistogramAggregator final : public Aggregator { if (!std::is_sorted(boundaries.begin(), boundaries.end())) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Histogram boundaries must be monotonic."); -#else +# else std::terminate(); -#endif +# endif } this->kind_ = kind; this->agg_kind_ = AggregatorKind::Histogram; @@ -119,20 +120,20 @@ class HistogramAggregator final : public Aggregator // Ensure that incorrect types are not merged if (this->agg_kind_ != other.agg_kind_) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Aggregators of different types cannot be merged."); -#else +# else std::terminate(); -#endif +# endif // Reject histogram merges with differing boundary vectors } else if (other.boundaries_ != this->boundaries_) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Histogram boundaries do not match."); -#else +# else std::terminate(); -#endif +# endif } this->values_[0] += other.values_[0]; @@ -202,3 +203,4 @@ class HistogramAggregator final : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h index 08c57c998d..db3a8b5e53 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h @@ -1,12 +1,13 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" -#include -#include -#include +# include +# include +# include namespace metrics_api = opentelemetry::metrics; @@ -154,3 +155,4 @@ class MinMaxSumCountAggregator : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h index 4de4174df2..4956e9a7b0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h @@ -1,15 +1,16 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include -#include -#include -#include -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/version.h" +# include +# include +# include +# include +# include +# include +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -102,11 +103,11 @@ class SketchAggregator final : public Aggregator { if (q < 0 || q > 1) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Quantile values must fall between 0 and 1"); -#else +# else std::terminate(); -#endif +# endif } auto iter = checkpoint_raw_.begin(); int idx = iter->first; @@ -152,19 +153,19 @@ class SketchAggregator final : public Aggregator { if (gamma != other.gamma) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Aggregators must have identical error tolerance"); -#else +# else std::terminate(); -#endif +# endif } else if (max_buckets_ != other.max_buckets_) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Aggregators must have the same maximum bucket allowance"); -#else +# else std::terminate(); -#endif +# endif } this->mu_.lock(); @@ -275,3 +276,4 @@ class SketchAggregator final : public Aggregator } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index 850d798ac5..644ccb937c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -1,15 +1,16 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include -#include -#include -#include "opentelemetry/metrics/async_instruments.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/instrument.h" -#include "opentelemetry/version.h" +# include +# include +# include +# include +# include +# include "opentelemetry/metrics/async_instruments.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/instrument.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -19,10 +20,10 @@ namespace sdk namespace metrics { -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4250) // inheriting methods via dominance -#endif +# if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable : 4250) // inheriting methods via dominance +# endif template class ValueObserver : public AsynchronousInstrument, virtual public metrics_api::ValueObserver @@ -136,11 +137,11 @@ class SumObserver : public AsynchronousInstrument, virtual public metrics_api boundAggregators_.insert(std::make_pair(labelset, sp1)); if (value < 0) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); -#else +# else std::terminate(); -#endif +# endif } else { @@ -151,11 +152,11 @@ class SumObserver : public AsynchronousInstrument, virtual public metrics_api { if (value < 0) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); -#else +# else std::terminate(); -#endif +# endif } else { @@ -272,10 +273,11 @@ class UpDownSumObserver : public AsynchronousInstrument, std::unordered_map>> boundAggregators_; }; -#if defined(_MSC_VER) -# pragma warning(pop) -#endif +# if defined(_MSC_VER) +# pragma warning(pop) +# endif } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/controller.h b/sdk/include/opentelemetry/sdk/metrics/controller.h index c36d789e72..fc90ce9dd2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/controller.h +++ b/sdk/include/opentelemetry/sdk/metrics/controller.h @@ -1,17 +1,18 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include -#include -#include -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/nostd/unique_ptr.h" -#include "opentelemetry/sdk/metrics/exporter.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/processor.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/version.h" +# include +# include +# include +# include +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/nostd/unique_ptr.h" +# include "opentelemetry/sdk/metrics/exporter.h" +# include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/sdk/metrics/processor.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -140,3 +141,4 @@ class PushController } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exporter.h b/sdk/include/opentelemetry/sdk/metrics/exporter.h index 55d5221ac8..1888eb27ac 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exporter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exporter.h @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include "opentelemetry/sdk/common/exporter_utils.h" -#include "opentelemetry/sdk/metrics/record.h" +# include +# include "opentelemetry/sdk/common/exporter_utils.h" +# include "opentelemetry/sdk/metrics/record.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -44,3 +44,4 @@ class MetricsExporter } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/instrument.h b/sdk/include/opentelemetry/sdk/metrics/instrument.h index aa54909339..754abfd941 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instrument.h +++ b/sdk/include/opentelemetry/sdk/metrics/instrument.h @@ -1,16 +1,17 @@ #pragma once - -#include -#include -#include -#include -#include -#include -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/version.h" +#ifdef ENABLE_METRICS_PREVIEW + +# include +# include +# include +# include +# include +# include +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/version.h" namespace metrics_api = opentelemetry::metrics; @@ -20,10 +21,10 @@ namespace sdk namespace metrics { -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4250) // inheriting methods via dominance -#endif +# if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable : 4250) // inheriting methods via dominance +# endif class Instrument : virtual public metrics_api::Instrument { @@ -253,11 +254,11 @@ inline void print_value(std::stringstream &ss, break; default: -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Labels must be strings"); -#else +# else std::terminate(); -#endif +# endif break; } }; @@ -299,10 +300,11 @@ inline std::string KvToString(const opentelemetry::common::KeyValueIterable &kv) return ss.str(); } -#if defined(_MSC_VER) -# pragma warning(pop) -#endif +# if defined(_MSC_VER) +# pragma warning(pop) +# endif } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 860d89eeea..591b6ef0c8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -1,14 +1,15 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/metrics/async_instruments.h" -#include "opentelemetry/sdk/metrics/instrument.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/sdk/metrics/sync_instruments.h" +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/metrics/async_instruments.h" +# include "opentelemetry/sdk/metrics/instrument.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/sdk/metrics/sync_instruments.h" -#include -#include +# include +# include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -373,3 +374,4 @@ class Meter : public metrics_api::Meter } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index 4112d14b8f..9d75613077 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -1,11 +1,12 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics/meter_provider.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/metrics/meter.h" -#include -#include +# include +# include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -30,3 +31,4 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/processor.h b/sdk/include/opentelemetry/sdk/metrics/processor.h index 38324aadba..f60831944c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/processor.h @@ -1,12 +1,13 @@ #pragma once -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/version.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/version.h" -#include -#include -#include +# include +# include +# include namespace sdkmetrics = opentelemetry::sdk::metrics; @@ -33,3 +34,4 @@ class MetricsProcessor } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/record.h b/sdk/include/opentelemetry/sdk/metrics/record.h index 1c646faf2e..bc868169b2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/record.h +++ b/sdk/include/opentelemetry/sdk/metrics/record.h @@ -1,9 +1,10 @@ #pragma once +#ifdef ENABLE_METRICS_PREVIEW -#include -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/nostd/variant.h" -#include "opentelemetry/sdk/metrics/aggregator/aggregator.h" +# include +# include "opentelemetry/metrics/instrument.h" +# include "opentelemetry/nostd/variant.h" +# include "opentelemetry/sdk/metrics/aggregator/aggregator.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -45,3 +46,4 @@ class Record } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 3893680cbe..6a774e3a5f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -1,14 +1,15 @@ #pragma once - -#include -#include -#include -#include -#include -#include "opentelemetry/metrics/sync_instruments.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/instrument.h" +#ifdef ENABLE_METRICS_PREVIEW + +# include +# include +# include +# include +# include +# include "opentelemetry/metrics/sync_instruments.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/instrument.h" namespace metrics_api = opentelemetry::metrics; @@ -18,10 +19,10 @@ namespace sdk namespace metrics { -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4250) // inheriting methods via dominance -#endif +# if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable : 4250) // inheriting methods via dominance +# endif template class BoundCounter final : public BoundSynchronousInstrument, public metrics_api::BoundCounter @@ -55,11 +56,11 @@ class BoundCounter final : public BoundSynchronousInstrument, public metrics_ { if (value < 0) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); -#else +# else std::terminate(); -#endif +# endif } else { @@ -128,11 +129,11 @@ class Counter final : public SynchronousInstrument, public metrics_api::Count { if (value < 0) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); -#else +# else std::terminate(); -#endif +# endif } else { @@ -436,10 +437,11 @@ class ValueRecorder final : public SynchronousInstrument, public metrics_api: boundInstruments_; }; -#if defined(_MSC_VER) -# pragma warning(pop) -#endif +# if defined(_MSC_VER) +# pragma warning(pop) +# endif } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/ungrouped_processor.h b/sdk/include/opentelemetry/sdk/metrics/ungrouped_processor.h index f0449be0ba..a1bf68d57e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/ungrouped_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/ungrouped_processor.h @@ -1,15 +1,16 @@ #pragma once - -#include -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" -#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" -#include "opentelemetry/sdk/metrics/processor.h" -#include "opentelemetry/sdk/metrics/record.h" -#include "opentelemetry/version.h" +#ifdef ENABLE_METRICS_PREVIEW + +# include +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" +# include "opentelemetry/sdk/metrics/processor.h" +# include "opentelemetry/sdk/metrics/record.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -283,3 +284,4 @@ class UngroupedMetricsProcessor : public MetricsProcessor } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 56adec57d5..47f76ac170 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(common) add_subdirectory(trace) -add_subdirectory(metrics) +if(WITH_METRICS_PREVIEW) + add_subdirectory(metrics) +endif() add_subdirectory(logs) add_subdirectory(version) add_subdirectory(resource) diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 29a769628f..636a0880ef 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -1,4 +1,5 @@ -#include "opentelemetry/sdk/metrics/meter.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/meter.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -12,11 +13,11 @@ nostd::shared_ptr> Meter::NewShortCounter( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto counter = new Counter(name, description, unit, enabled); auto ptr = std::shared_ptr>(counter); @@ -33,11 +34,11 @@ nostd::shared_ptr> Meter::NewIntCounter(nostd::string_ { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto counter = new Counter(name, description, unit, enabled); auto ptr = std::shared_ptr>(counter); @@ -55,11 +56,11 @@ nostd::shared_ptr> Meter::NewFloatCounter( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto counter = new Counter(name, description, unit, enabled); auto ptr = std::shared_ptr>(counter); @@ -77,11 +78,11 @@ nostd::shared_ptr> Meter::NewDoubleCounter( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto counter = new Counter(name, description, unit, enabled); auto ptr = std::shared_ptr>(counter); @@ -99,11 +100,11 @@ nostd::shared_ptr> Meter::NewShortUpDownCounte { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto udcounter = new UpDownCounter(name, description, unit, enabled); auto ptr = std::shared_ptr>(udcounter); @@ -121,11 +122,11 @@ nostd::shared_ptr> Meter::NewIntUpDownCounter( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto udcounter = new UpDownCounter(name, description, unit, enabled); auto ptr = std::shared_ptr>(udcounter); @@ -143,11 +144,11 @@ nostd::shared_ptr> Meter::NewFloatUpDownCounte { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto udcounter = new UpDownCounter(name, description, unit, enabled); auto ptr = std::shared_ptr>(udcounter); @@ -165,11 +166,11 @@ nostd::shared_ptr> Meter::NewDoubleUpDownCoun { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto udcounter = new UpDownCounter(name, description, unit, enabled); auto ptr = std::shared_ptr>(udcounter); @@ -187,11 +188,11 @@ nostd::shared_ptr> Meter::NewShortValueRecorde { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto recorder = new ValueRecorder(name, description, unit, enabled); auto ptr = std::shared_ptr>(recorder); @@ -209,11 +210,11 @@ nostd::shared_ptr> Meter::NewIntValueRecorder( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto recorder = new ValueRecorder(name, description, unit, enabled); auto ptr = std::shared_ptr>(recorder); @@ -231,11 +232,11 @@ nostd::shared_ptr> Meter::NewFloatValueRecorde { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto recorder = new ValueRecorder(name, description, unit, enabled); auto ptr = std::shared_ptr>(recorder); @@ -253,11 +254,11 @@ nostd::shared_ptr> Meter::NewDoubleValueRecor { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto recorder = new ValueRecorder(name, description, unit, enabled); auto ptr = std::shared_ptr>(recorder); @@ -276,11 +277,11 @@ nostd::shared_ptr> Meter::NewShortSumObserver( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new SumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -299,11 +300,11 @@ nostd::shared_ptr> Meter::NewIntSumObserver( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new SumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -322,11 +323,11 @@ nostd::shared_ptr> Meter::NewFloatSumObserver( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new SumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -345,11 +346,11 @@ nostd::shared_ptr> Meter::NewDoubleSumObserver( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new SumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -368,11 +369,11 @@ nostd::shared_ptr> Meter::NewShortUpDownSu { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new UpDownSumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -391,11 +392,11 @@ nostd::shared_ptr> Meter::NewIntUpDownSumObs { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new UpDownSumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -414,11 +415,11 @@ nostd::shared_ptr> Meter::NewFloatUpDownSu { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new UpDownSumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -437,11 +438,11 @@ nostd::shared_ptr> Meter::NewDoubleUpDown { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new UpDownSumObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -460,11 +461,11 @@ nostd::shared_ptr> Meter::NewShortValueObserve { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new ValueObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -483,11 +484,11 @@ nostd::shared_ptr> Meter::NewIntValueObserver( { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new ValueObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -506,11 +507,11 @@ nostd::shared_ptr> Meter::NewFloatValueObserve { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new ValueObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -529,11 +530,11 @@ nostd::shared_ptr> Meter::NewDoubleValueObser { if (!IsValidName(name) || NameAlreadyUsed(name)) { -#if __EXCEPTIONS +# if __EXCEPTIONS throw std::invalid_argument("Invalid Name"); -#else +# else std::terminate(); -#endif +# endif } auto sumobs = new ValueObserver(name, description, unit, enabled, callback); auto ptr = std::shared_ptr>(sumobs); @@ -762,3 +763,4 @@ bool Meter::NameAlreadyUsed(nostd::string_view name) } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 7c009a7bab..7da48c36b1 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -1,4 +1,5 @@ -#include "opentelemetry/sdk/metrics/meter_provider.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/meter_provider.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -19,3 +20,4 @@ opentelemetry::nostd::shared_ptr MeterProvider::G } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/metrics/ungrouped_processor.cc b/sdk/src/metrics/ungrouped_processor.cc index 4c5be0e220..414ed28cdb 100644 --- a/sdk/src/metrics/ungrouped_processor.cc +++ b/sdk/src/metrics/ungrouped_processor.cc @@ -1,4 +1,5 @@ -#include "opentelemetry/sdk/metrics/ungrouped_processor.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/ungrouped_processor.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -161,3 +162,4 @@ void UngroupedMetricsProcessor::process(sdkmetrics::Record record) noexcept } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/CMakeLists.txt b/sdk/test/CMakeLists.txt index 77047165d9..f574b688fb 100644 --- a/sdk/test/CMakeLists.txt +++ b/sdk/test/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(common) add_subdirectory(trace) -add_subdirectory(metrics) +if(WITH_METRICS_PREVIEW) + add_subdirectory(metrics) +endif() add_subdirectory(logs) add_subdirectory(resource) add_subdirectory(instrumentationlibrary) diff --git a/sdk/test/metrics/controller_test.cc b/sdk/test/metrics/controller_test.cc index 078d4330c5..51749bb7df 100644 --- a/sdk/test/metrics/controller_test.cc +++ b/sdk/test/metrics/controller_test.cc @@ -1,10 +1,11 @@ -#include "opentelemetry/sdk/metrics/controller.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/ungrouped_processor.h" - -#include -#include -#include +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/controller.h" +# include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/sdk/metrics/ungrouped_processor.h" + +# include +# include +# include // #include namespace metrics_api = opentelemetry::metrics; @@ -49,3 +50,4 @@ TEST(Controller, Constructor) } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/counter_aggregator_test.cc b/sdk/test/metrics/counter_aggregator_test.cc index 09d146b15f..188faa2843 100644 --- a/sdk/test/metrics/counter_aggregator_test.cc +++ b/sdk/test/metrics/counter_aggregator_test.cc @@ -1,8 +1,9 @@ -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" -#include -#include -#include +# include +# include +# include namespace metrics_api = opentelemetry::metrics; @@ -113,3 +114,4 @@ TEST(CounterAggregator, Merge) } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/exact_aggregator_test.cc b/sdk/test/metrics/exact_aggregator_test.cc index be32b87704..ee31fda1a3 100644 --- a/sdk/test/metrics/exact_aggregator_test.cc +++ b/sdk/test/metrics/exact_aggregator_test.cc @@ -1,7 +1,9 @@ #include -#include -#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include + +# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" using namespace opentelemetry::sdk::metrics; @@ -179,10 +181,10 @@ TEST(ExactAggregatorInOrder, Quantile) agg.update(i); } agg.checkpoint(); -#if __EXCEPTIONS +# if __EXCEPTIONS ASSERT_THROW(agg.get_quantiles(0.5), std::domain_error); -#else -#endif +# else +# endif } void callback(ExactAggregator &agg) @@ -214,4 +216,10 @@ TEST(ExactAggregatorQuant, Concurrency) agg.checkpoint(); ASSERT_EQ(agg.get_checkpoint(), correct); -} \ No newline at end of file +} +#else +TEST(ExactAggregatorQuant, DummyTest) +{ + // empty +} +#endif diff --git a/sdk/test/metrics/gauge_aggregator_test.cc b/sdk/test/metrics/gauge_aggregator_test.cc index 7370d78f70..7d0438cbe7 100644 --- a/sdk/test/metrics/gauge_aggregator_test.cc +++ b/sdk/test/metrics/gauge_aggregator_test.cc @@ -1,7 +1,9 @@ -#include -#include -#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include + +# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" using namespace opentelemetry::sdk::metrics; @@ -124,4 +126,5 @@ TEST(GaugeAggregator, Concurrency) second.join(); ASSERT_EQ(agg.get_values()[0], 10000); -} \ No newline at end of file +} +#endif diff --git a/sdk/test/metrics/histogram_aggregator_test.cc b/sdk/test/metrics/histogram_aggregator_test.cc index 146c552bb0..74961d9890 100644 --- a/sdk/test/metrics/histogram_aggregator_test.cc +++ b/sdk/test/metrics/histogram_aggregator_test.cc @@ -1,9 +1,11 @@ -#include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h" + +# include +# include +# include +# include -#include -#include -#include -#include // #include namespace metrics_api = opentelemetry::metrics; @@ -144,7 +146,7 @@ TEST(Histogram, Concurrency) EXPECT_EQ(alpha.get_counts(), beta.get_counts()); } -#if __EXCEPTIONS +# if __EXCEPTIONS TEST(Histogram, Errors) { @@ -160,8 +162,9 @@ TEST(Histogram, Errors) EXPECT_ANY_THROW(beta.merge(gamma)); } -#endif +# endif } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index 52a00d6c58..54a545a96a 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -1,7 +1,8 @@ -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_provider.h" +#ifdef ENABLE_METRICS_PREVIEW +# include -#include +# include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/sdk/metrics/meter_provider.h" using namespace opentelemetry::sdk::metrics; @@ -19,3 +20,4 @@ TEST(MeterProvider, GetMeter) ASSERT_EQ(t1, t2); ASSERT_EQ(t1, t3); } +#endif diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index b47b0d418a..d980050afa 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -1,6 +1,8 @@ -#include "opentelemetry/sdk/metrics/meter.h" -#include -#include +#ifdef ENABLE_METRICS_PREVIEW +# include +# include + +# include "opentelemetry/sdk/metrics/meter.h" using namespace opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; @@ -264,7 +266,7 @@ TEST(Meter, DisableCollectAsync) TEST(MeterStringUtil, IsValid) { -#if __EXCEPTIONS +# if __EXCEPTIONS Meter m("Test"); ASSERT_ANY_THROW(m.NewShortCounter("", "Empty name is invalid", " ", true)); ASSERT_ANY_THROW(m.NewShortCounter("1a", "Can't begin with a number", " ", true)); @@ -272,18 +274,19 @@ TEST(MeterStringUtil, IsValid) ASSERT_ANY_THROW(m.NewShortCounter(" a", "Can't begin with space", " ", true)); ASSERT_ANY_THROW(m.NewShortCounter( "te^ s=%t", "Only alphanumeric ., -, and _ characters are allowed", " ", true)); -#endif +# endif } TEST(MeterStringUtil, AlreadyExists) { -#if __EXCEPTIONS +# if __EXCEPTIONS Meter m("Test"); m.NewShortCounter("a", "First instance of instrument named 'a'", "", true); ASSERT_ANY_THROW(m.NewShortCounter("a", "Second (illegal) instrument named 'a'", "", true)); ASSERT_ANY_THROW(m.NewShortSumObserver("a", "Still illegal even though it is not a short counter", "", true, &ShortCallback)); -#endif +# endif } OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/metric_instrument_test.cc b/sdk/test/metrics/metric_instrument_test.cc index 9fd1c5c5a7..741a3d819d 100644 --- a/sdk/test/metrics/metric_instrument_test.cc +++ b/sdk/test/metrics/metric_instrument_test.cc @@ -1,13 +1,13 @@ - -#include -#include -#include -#include -#include -#include -#include -#include "opentelemetry/sdk/metrics/async_instruments.h" -#include "opentelemetry/sdk/metrics/sync_instruments.h" +#ifdef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include +# include +# include +# include +# include "opentelemetry/sdk/metrics/async_instruments.h" +# include "opentelemetry/sdk/metrics/sync_instruments.h" namespace metrics_api = opentelemetry::metrics; @@ -467,3 +467,4 @@ TEST(Instruments, NoUpdateNoRecord) } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/min_max_sum_count_aggregator_test.cc b/sdk/test/metrics/min_max_sum_count_aggregator_test.cc index 21d06ddcea..638147e856 100644 --- a/sdk/test/metrics/min_max_sum_count_aggregator_test.cc +++ b/sdk/test/metrics/min_max_sum_count_aggregator_test.cc @@ -1,7 +1,8 @@ -#include -#include +#ifdef ENABLE_METRICS_PREVIEW +# include +# include -#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" +# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" using namespace opentelemetry::sdk::metrics; @@ -200,4 +201,5 @@ TEST(MinMaxSumCountAggregator, Concurrency) ASSERT_EQ(value_set[1], 10000); ASSERT_EQ(value_set[2], 2 * 50005000); ASSERT_EQ(value_set[3], 2 * 10000); -} \ No newline at end of file +} +#endif diff --git a/sdk/test/metrics/sketch_aggregator_test.cc b/sdk/test/metrics/sketch_aggregator_test.cc index 7045fe393a..47c080236c 100644 --- a/sdk/test/metrics/sketch_aggregator_test.cc +++ b/sdk/test/metrics/sketch_aggregator_test.cc @@ -1,9 +1,10 @@ -#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h" -#include -#include -#include -#include +# include +# include +# include +# include namespace metrics_api = opentelemetry::metrics; @@ -226,7 +227,7 @@ TEST(Sketch, Concurrency) EXPECT_EQ(alpha.get_boundaries(), beta.get_boundaries()); } -#if __EXCEPTIONS +# if __EXCEPTIONS TEST(Sketch, Errors) { @@ -242,8 +243,9 @@ TEST(Sketch, Errors) EXPECT_ANY_THROW(tol1.get_quantiles(1.000001)); } -#endif +# endif } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/ungrouped_processor_test.cc b/sdk/test/metrics/ungrouped_processor_test.cc index 0ecff02659..2c8a368b91 100644 --- a/sdk/test/metrics/ungrouped_processor_test.cc +++ b/sdk/test/metrics/ungrouped_processor_test.cc @@ -1,8 +1,8 @@ -#include "opentelemetry/sdk/metrics/ungrouped_processor.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" - -#include +#ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/ungrouped_processor.h" +# include +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" namespace sdkmetrics = opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; @@ -620,3 +620,4 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful ->get_checkpoint(), test_aggregator->get_checkpoint()); } +#endif