From 025f42f1eacc3b656cedb8465ec2f2574fcc9e51 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 14 Jun 2024 13:43:37 -0700 Subject: [PATCH 01/71] [BUILD] Add support for bzlmod (#2608) * Add support for bzlmod This adds support for bzlmod, which is bazel's new dependency resolution system. Theoretically we could now remove the previous dependency management configuration which required flattening all the dependencies, but I left it here for now for users using old versions of bazel. --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ .gitignore | 1 + MODULE.bazel | 25 +++++++++++++++++++++++++ WORKSPACE.bzlmod | 4 ++++ ci/do_ci.sh | 4 ++++ 5 files changed, 55 insertions(+) create mode 100644 MODULE.bazel create mode 100644 WORKSPACE.bzlmod diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5834ca2fd4..26c692953c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -537,6 +537,27 @@ jobs: - name: run tests run: ./ci/do_ci.sh bazel.test + bazel_no_bzlmod_test: + name: Bazel without bzlmod + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Mount Bazel Cache + uses: actions/cache@v4 + env: + cache-name: bazel_cache + with: + path: /home/runner/.cache/bazel + key: bazel_test + - name: setup + run: | + sudo ./ci/setup_ci_environment.sh + sudo ./ci/install_bazelisk.sh + - name: run tests + run: ./ci/do_ci.sh bazel.no_bzlmod.test + bazel_test_async: name: Bazel with async export runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index dc26aa2f82..cafefd636d 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ *.app # Bazel files +MODULE.bazel.lock /bazel-* # Mac diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000000..7b84c2b719 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,25 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +module( + name = "opentelemetry-cpp", + version = "0", + compatibility_level = 0, + repo_name = "io_opentelemetry_cpp", +) + +bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "com_google_absl") +bazel_dep(name = "bazel_skylib", version = "1.5.0") +bazel_dep(name = "curl", version = "8.4.0") +bazel_dep(name = "grpc", version = "1.62.1", repo_name = "com_github_grpc_grpc") +bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohmann_json") +bazel_dep(name = "opentelemetry-proto", version = "1.3.1", repo_name = "com_github_opentelemetry_proto") +bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing") +bazel_dep(name = "platforms", version = "0.0.8") +bazel_dep(name = "prometheus-cpp", version = "1.2.4", repo_name = "com_github_jupp0r_prometheus_cpp") +bazel_dep(name = "protobuf", version = "26.0", repo_name = "com_google_protobuf") +bazel_dep(name = "rules_proto", version = "5.3.0-21.7") +bazel_dep(name = "zlib", version = "1.3.1.bcr.1") + +bazel_dep(name = "google_benchmark", version = "1.8.3", dev_dependency = True, repo_name = "com_github_google_benchmark") +bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True, repo_name = "com_google_googletest") diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000000..0db1b04622 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,4 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Disables the default WORKSPACE when using bzlmod diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 7855ed4175..efdac9e87e 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -459,6 +459,10 @@ EOF make load_plugin_example examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null exit 0 +elif [[ "$1" == "bazel.no_bzlmod.test" ]]; then + bazel $BAZEL_STARTUP_OPTIONS build --enable_bzlmod=false $BAZEL_OPTIONS //... + bazel $BAZEL_STARTUP_OPTIONS test --enable_bzlmod=false $BAZEL_TEST_OPTIONS //... + exit 0 elif [[ "$1" == "bazel.test" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //... From fad93f0727a44df5d2f88be2ab11e4e533ce349c Mon Sep 17 00:00:00 2001 From: zhanglei <357733652@qq.com> Date: Sat, 15 Jun 2024 19:50:04 +0800 Subject: [PATCH 02/71] [BUILD] Fix Import Abseil-cpp (#2701) --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e61faed35..3d7831b2a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,7 +377,9 @@ if(WITH_PROMETHEUS) endif() if(WITH_ABSEIL) - find_package(absl CONFIG REQUIRED) + if(NOT TARGET absl::strings) + find_package(absl CONFIG REQUIRED) + endif() endif() if(WITH_OTLP_GRPC From f97dc061bc96cd090f8af8493db4467494147da9 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 15 Jun 2024 17:10:05 +0200 Subject: [PATCH 03/71] [Code health] include-what-you-use cleanup (#2692) --- .github/workflows/iwyu.yml | 1 + CHANGELOG.md | 3 + api/include/opentelemetry/nostd/type_traits.h | 2 +- api/include/opentelemetry/nostd/utility.h | 4 +- .../plugin/detail/dynamic_load_unix.h | 3 +- .../opentelemetry/plugin/dynamic_load.h | 4 +- api/include/opentelemetry/plugin/factory.h | 2 +- api/include/opentelemetry/plugin/tracer.h | 2 +- examples/batch/main.cc | 20 +- examples/common/foo_library/foo_library.cc | 6 + .../common/logs_foo_library/foo_library.cc | 11 +- .../common/metrics_foo_library/foo_library.cc | 14 +- examples/logs_simple/main.cc | 11 +- examples/metrics_simple/metrics_ostream.cc | 17 +- examples/multi_processor/main.cc | 18 +- examples/multithreaded/main.cc | 18 +- examples/plugin/load/main.cc | 8 +- examples/plugin/plugin/factory_impl.cc | 7 + examples/plugin/plugin/tracer.cc | 14 +- examples/plugin/plugin/tracer.h | 7 + examples/simple/main.cc | 7 +- .../memory/in_memory_span_exporter_factory.h | 4 + .../exporters/ostream/log_record_exporter.h | 14 +- .../ostream/log_record_exporter_factory.h | 11 +- .../exporters/ostream/metric_exporter.h | 13 +- .../ostream/metric_exporter_factory.h | 9 +- .../exporters/ostream/span_exporter.h | 19 +- .../exporters/ostream/span_exporter_factory.h | 11 +- exporters/ostream/src/log_record_exporter.cc | 34 +++- .../src/log_record_exporter_factory.cc | 2 + exporters/ostream/src/metric_exporter.cc | 32 +++- exporters/ostream/src/span_exporter.cc | 36 +++- .../ostream/src/span_exporter_factory.cc | 2 + .../sdk/logs/batch_log_record_processor.h | 16 +- .../logs/batch_log_record_processor_factory.h | 7 +- .../opentelemetry/sdk/logs/event_logger.h | 5 +- .../sdk/logs/event_logger_provider.h | 5 +- sdk/include/opentelemetry/sdk/logs/exporter.h | 3 +- sdk/include/opentelemetry/sdk/logs/logger.h | 3 +- .../sdk/logs/logger_context_factory.h | 10 +- .../opentelemetry/sdk/logs/logger_provider.h | 10 +- .../sdk/logs/multi_log_record_processor.h | 3 +- .../logs/multi_log_record_processor_factory.h | 2 +- .../opentelemetry/sdk/logs/multi_recordable.h | 8 +- .../sdk/logs/readable_log_record.h | 4 + .../sdk/logs/simple_log_record_processor.h | 5 +- .../simple_log_record_processor_factory.h | 2 +- .../aggregation/histogram_aggregation.h | 6 + .../aggregation/lastvalue_aggregation.h | 2 + .../sdk/metrics/aggregation/sum_aggregation.h | 2 + .../sdk/metrics/data/circular_buffer.h | 6 +- .../export/periodic_exporting_metric_reader.h | 4 +- ...periodic_exporting_metric_reader_factory.h | 6 +- .../metrics/instrument_metadata_validator.h | 3 - .../opentelemetry/sdk/metrics/meter_context.h | 13 +- .../opentelemetry/sdk/metrics/metric_reader.h | 6 +- .../state/filtered_ordered_attribute_map.h | 13 +- .../sdk/metrics/state/metric_collector.h | 2 + .../sdk/metrics/state/sync_metric_storage.h | 24 ++- .../metrics/state/temporal_metric_storage.h | 7 +- .../sdk/metrics/sync_instruments.h | 7 +- .../view/instrument_selector_factory.h | 5 +- .../sdk/metrics/view/meter_selector_factory.h | 3 +- .../sdk/metrics/view/view_factory.h | 10 +- .../sdk/metrics/view/view_registry_factory.h | 4 +- .../opentelemetry/sdk/version/version.h | 2 - sdk/src/logs/batch_log_record_processor.cc | 25 ++- .../batch_log_record_processor_factory.cc | 9 +- sdk/src/logs/event_logger.cc | 27 ++- sdk/src/logs/event_logger_provider.cc | 18 +- sdk/src/logs/logger.cc | 51 +++-- sdk/src/logs/logger_context.cc | 11 +- sdk/src/logs/logger_context_factory.cc | 10 +- sdk/src/logs/logger_provider.cc | 33 ++-- sdk/src/logs/logger_provider_factory.cc | 4 + sdk/src/logs/multi_log_record_processor.cc | 9 + .../multi_log_record_processor_factory.cc | 10 +- sdk/src/logs/multi_recordable.cc | 14 +- sdk/src/logs/read_write_log_record.cc | 19 +- sdk/src/logs/readable_log_record.cc | 13 +- sdk/src/logs/simple_log_record_processor.cc | 13 +- .../simple_log_record_processor_factory.cc | 8 +- .../aggregation/histogram_aggregation.cc | 18 +- .../aggregation/lastvalue_aggregation.cc | 15 +- .../metrics/aggregation/sum_aggregation.cc | 14 +- sdk/src/metrics/async_instruments.cc | 3 + sdk/src/metrics/data/circular_buffer.cc | 8 + sdk/src/metrics/exemplar/reservoir.cc | 4 +- .../periodic_exporting_metric_reader.cc | 21 ++- ...eriodic_exporting_metric_reader_factory.cc | 7 +- .../metrics/instrument_metadata_validator.cc | 12 +- sdk/src/metrics/meter.cc | 174 ++++++++++-------- sdk/src/metrics/meter_context.cc | 27 ++- sdk/src/metrics/meter_context_factory.cc | 8 +- sdk/src/metrics/meter_provider.cc | 11 ++ sdk/src/metrics/metric_reader.cc | 3 +- sdk/src/metrics/state/metric_collector.cc | 14 +- sdk/src/metrics/state/observable_registry.cc | 22 ++- sdk/src/metrics/state/sync_metric_storage.cc | 13 ++ .../metrics/state/temporal_metric_storage.cc | 26 ++- sdk/src/metrics/sync_instruments.cc | 14 +- sdk/src/metrics/view/view_factory.cc | 9 +- sdk/src/trace/batch_span_processor.cc | 2 +- 103 files changed, 879 insertions(+), 394 deletions(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index de60502794..29b8274fbd 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -38,6 +38,7 @@ jobs: CC="clang" CXX="clang++" cmake \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ -DBUILD_TESTING=OFF \ + -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=OFF \ .. diff --git a/CHANGELOG.md b/CHANGELOG.md index cd92d15ba4..f2c08c6065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ Increment the: * [API/SDK] Provider cleanup [#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664) +* [Code health] include-what-you-use cleanup + [#2692](https://github.com/open-telemetry/opentelemetry-cpp/pull/2692) + Important changes: * [API/SDK] Provider cleanup diff --git a/api/include/opentelemetry/nostd/type_traits.h b/api/include/opentelemetry/nostd/type_traits.h index 46d11c89cb..5a087075bf 100644 --- a/api/include/opentelemetry/nostd/type_traits.h +++ b/api/include/opentelemetry/nostd/type_traits.h @@ -15,7 +15,7 @@ # include # include "opentelemetry/config.h" -# include "opentelemetry/nostd/detail/void.h" +# include "opentelemetry/nostd/detail/void.h" // IWYU pragma: export # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/nostd/utility.h b/api/include/opentelemetry/nostd/utility.h index 3238b0328d..de4f47e4cf 100644 --- a/api/include/opentelemetry/nostd/utility.h +++ b/api/include/opentelemetry/nostd/utility.h @@ -15,8 +15,8 @@ # include # include -# include "opentelemetry/nostd/detail/decay.h" -# include "opentelemetry/nostd/detail/invoke.h" +# include "opentelemetry/nostd/detail/decay.h" // IWYU pragma: export +# include "opentelemetry/nostd/detail/invoke.h" // IWYU pragma: export # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h b/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h index 1d249317a0..83522c56eb 100644 --- a/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h +++ b/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h @@ -3,11 +3,10 @@ #pragma once +#include #include #include -#include - #include "opentelemetry/plugin/detail/dynamic_library_handle.h" #include "opentelemetry/plugin/detail/loader_info.h" #include "opentelemetry/plugin/detail/utility.h" diff --git a/api/include/opentelemetry/plugin/dynamic_load.h b/api/include/opentelemetry/plugin/dynamic_load.h index 58a69ad5c8..10b4a34af4 100644 --- a/api/include/opentelemetry/plugin/dynamic_load.h +++ b/api/include/opentelemetry/plugin/dynamic_load.h @@ -7,9 +7,9 @@ #include #ifdef _WIN32 -# include "opentelemetry/plugin/detail/dynamic_load_windows.h" +# include "opentelemetry/plugin/detail/dynamic_load_windows.h" // IWYU pragma: export #else -# include "opentelemetry/plugin/detail/dynamic_load_unix.h" +# include "opentelemetry/plugin/detail/dynamic_load_unix.h" // IWYU pragma: export #endif #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/plugin/factory.h b/api/include/opentelemetry/plugin/factory.h index 6b484d8f2f..d9df30e480 100644 --- a/api/include/opentelemetry/plugin/factory.h +++ b/api/include/opentelemetry/plugin/factory.h @@ -6,7 +6,7 @@ #include #include -#include "opentelemetry/plugin/detail/utility.h" +#include "opentelemetry/plugin/detail/utility.h" // IWYU pragma: export #include "opentelemetry/plugin/tracer.h" #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index 9f3c7c76d1..ae78109dab 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -6,7 +6,7 @@ #include #include "opentelemetry/common/key_value_iterable.h" -#include "opentelemetry/plugin/detail/tracer_handle.h" +#include "opentelemetry/plugin/detail/tracer_handle.h" // IWYU pragma: export #include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" diff --git a/examples/batch/main.cc b/examples/batch/main.cc index ece864001a..2a7fba4630 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -1,17 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/nostd/detail/decay.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/batch_span_processor_factory.h" #include "opentelemetry/sdk/trace/batch_span_processor_options.h" -#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" constexpr int kNumSpans = 10; namespace trace_api = opentelemetry::trace; diff --git a/examples/common/foo_library/foo_library.cc b/examples/common/foo_library/foo_library.cc index a0dec3c766..e336bc5e4c 100644 --- a/examples/common/foo_library/foo_library.cc +++ b/examples/common/foo_library/foo_library.cc @@ -1,8 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/version/version.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; diff --git a/examples/common/logs_foo_library/foo_library.cc b/examples/common/logs_foo_library/foo_library.cc index d77cd058dc..23402563c6 100644 --- a/examples/common/logs_foo_library/foo_library.cc +++ b/examples/common/logs_foo_library/foo_library.cc @@ -1,11 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/version/version.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace logs = opentelemetry::logs; namespace trace = opentelemetry::trace; diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index 79427d195b..dd5f23297b 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -1,15 +1,25 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "foo_library.h" +#include +#include #include #include -#include #include +#include #include + +#include "foo_library.h" +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/meter_provider.h" +#include "opentelemetry/metrics/observer_result.h" #include "opentelemetry/metrics/provider.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/variant.h" namespace nostd = opentelemetry::nostd; namespace metrics_api = opentelemetry::metrics; diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index e104724e2a..35827b6502 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -1,19 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include + #include "opentelemetry/exporters/ostream/log_record_exporter.h" #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" -#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" -#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/logs_foo_library/foo_library.h" diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 770b2db81a..5871b5e6a3 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -1,20 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include +#include #include +#include +#include +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/exporters/ostream/metric_exporter_factory.h" +#include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/provider.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" -#include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/meter_provider_factory.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" #include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" #include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/view.h" #include "opentelemetry/sdk/metrics/view/view_factory.h" #ifdef BAZEL_BUILD diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index 10fe606b30..ceb7cdfcf9 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -1,13 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/exporters/memory/in_memory_span_data.h" #include "opentelemetry/exporters/memory/in_memory_span_exporter_factory.h" #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" -#include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/foo_library/foo_library.h" diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 6071e2597a..9dd76647c5 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -1,17 +1,27 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/nostd/detail/decay.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" #include "opentelemetry/trace/scope.h" - -#include -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; diff --git a/examples/plugin/load/main.cc b/examples/plugin/load/main.cc index 41a04baa48..589f70c2af 100644 --- a/examples/plugin/load/main.cc +++ b/examples/plugin/load/main.cc @@ -1,15 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/plugin/dynamic_load.h" - -#include +#include #include #include #include #include #include +#include "opentelemetry/plugin/dynamic_load.h" +#include "opentelemetry/plugin/factory.h" +#include "opentelemetry/trace/tracer.h" + int main(int argc, char *argv[]) { if (argc != 3) diff --git a/examples/plugin/plugin/factory_impl.cc b/examples/plugin/plugin/factory_impl.cc index b262facfb8..4d74bd6062 100644 --- a/examples/plugin/plugin/factory_impl.cc +++ b/examples/plugin/plugin/factory_impl.cc @@ -1,8 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/plugin/factory.h" #include "opentelemetry/plugin/hook.h" +#include "opentelemetry/plugin/tracer.h" #include "tracer.h" namespace nostd = opentelemetry::nostd; diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 14d1a746df..faf3f036e5 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -1,11 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "tracer.h" -#include "opentelemetry/nostd/unique_ptr.h" - #include #include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_metadata.h" +#include "tracer.h" namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; diff --git a/examples/plugin/plugin/tracer.h b/examples/plugin/plugin/tracer.h index 1480b44541..bb933d3d9b 100644 --- a/examples/plugin/plugin/tracer.h +++ b/examples/plugin/plugin/tracer.h @@ -3,8 +3,15 @@ #pragma once +#include #include +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_startoptions.h" #include "opentelemetry/trace/tracer.h" class Tracer final : public opentelemetry::trace::Tracer, diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 284ec2f693..a872816ba1 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -1,13 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include + #include "opentelemetry/exporters/ostream/span_exporter_factory.h" -#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/foo_library/foo_library.h" diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter_factory.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter_factory.h index c55f6a0802..549ff13c71 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter_factory.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter_factory.h @@ -3,8 +3,12 @@ #pragma once +#include +#include + #include "opentelemetry/exporters/memory/in_memory_span_data.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h index 3c11c53aee..24bc8e5be7 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -3,17 +3,21 @@ #pragma once +#include +#include +#include +#include +#include +#include + #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/version.h" -#include -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h index 143a481801..36c09a9f74 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h @@ -6,17 +6,10 @@ #include #include -#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace logs -{ -class LogRecordExporter; -} // namespace logs -} // namespace sdk - namespace exporter { namespace logs diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h index 0dd22203e5..1ad124a9ab 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h @@ -4,25 +4,22 @@ #pragma once #include +#include #include +#include #include #include +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace resource -{ -class Resource; -} // namespace resource -} // namespace sdk - namespace exporter { namespace metrics diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h index 0526165026..3451769747 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h @@ -7,17 +7,10 @@ #include #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace metrics -{ -class PushMetricExporter; -} // namespace metrics -} // namespace sdk - namespace exporter { namespace metrics diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index 153aa4701e..a7de9a5eb4 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -3,16 +3,25 @@ #pragma once +#include +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/span_data.h" #include "opentelemetry/version.h" -#include -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h index 79ba3b06d4..4797473bbb 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h @@ -6,17 +6,10 @@ #include #include -#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -class SpanExporter; -} // namespace trace -} // namespace sdk - namespace exporter { namespace trace diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 88b8ba5ba2..7f661276c8 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -1,20 +1,38 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/exporters/ostream/common_utils.h" +#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" -#include -#include -#include - -namespace nostd = opentelemetry::nostd; namespace sdklogs = opentelemetry::sdk::logs; namespace sdkcommon = opentelemetry::sdk::common; + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -33,7 +51,7 @@ std::unique_ptr OStreamLogRecordExporter::MakeRecordable() } sdk::common::ExportResult OStreamLogRecordExporter::Export( - const nostd::span> &records) noexcept + const opentelemetry::nostd::span> &records) noexcept { if (isShutdown()) { diff --git a/exporters/ostream/src/log_record_exporter_factory.cc b/exporters/ostream/src/log_record_exporter_factory.cc index 66ea1a0232..31539c5182 100644 --- a/exporters/ostream/src/log_record_exporter_factory.cc +++ b/exporters/ostream/src/log_record_exporter_factory.cc @@ -3,6 +3,8 @@ #include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" #include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" namespace logs_sdk = opentelemetry::sdk::logs; diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 4871a28b3d..08bfe340c7 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -1,19 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/ostream/metric_exporter.h" -#include "opentelemetry/exporters/ostream/common_utils.h" -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk_config.h" - +#include #include +#include #include #include +#include #include #include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/exporters/ostream/common_utils.h" +#include "opentelemetry/exporters/ostream/metric_exporter.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" namespace { diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index 4faa6854be..d3f5093b40 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -1,14 +1,36 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/ostream/span_exporter.h" -#include "opentelemetry/exporters/ostream/common_utils.h" - +#include +#include #include -#include -#include "opentelemetry/sdk_config.h" +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/exporters/ostream/common_utils.h" +#include "opentelemetry/exporters/ostream/span_exporter.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" +#include "opentelemetry/version.h" -namespace nostd = opentelemetry::nostd; namespace trace_sdk = opentelemetry::sdk::trace; namespace trace_api = opentelemetry::trace; namespace sdkcommon = opentelemetry::sdk::common; @@ -45,7 +67,7 @@ std::unique_ptr OStreamSpanExporter::MakeRecordable() noe } sdk::common::ExportResult OStreamSpanExporter::Export( - const nostd::span> &spans) noexcept + const opentelemetry::nostd::span> &spans) noexcept { if (isShutdown()) { diff --git a/exporters/ostream/src/span_exporter_factory.cc b/exporters/ostream/src/span_exporter_factory.cc index 5b3061ac3c..fdb08f150f 100644 --- a/exporters/ostream/src/span_exporter_factory.cc +++ b/exporters/ostream/src/span_exporter_factory.cc @@ -3,6 +3,8 @@ #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/exporters/ostream/span_exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" namespace trace_sdk = opentelemetry::sdk::trace; diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h index 01a39348e2..b52476071a 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h @@ -3,18 +3,22 @@ #pragma once -#include "opentelemetry/sdk/common/circular_buffer.h" -#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" -#include "opentelemetry/sdk/logs/exporter.h" -#include "opentelemetry/sdk/logs/processor.h" -#include "opentelemetry/version.h" - +#include #include +#include #include #include #include +#include #include +#include "opentelemetry/sdk/common/circular_buffer.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h index 74e0efbb59..983f2e7508 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h @@ -5,6 +5,9 @@ #include +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -14,10 +17,6 @@ namespace sdk namespace logs { -struct BatchLogRecordProcessorOptions; -class LogRecordExporter; -class LogRecordProcessor; - /** * Factory class for BatchLogRecordProcessor. */ diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger.h b/sdk/include/opentelemetry/sdk/logs/event_logger.h index 8230beeb32..d9e83b9998 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger.h @@ -6,6 +6,8 @@ #include #include "opentelemetry/logs/event_logger.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" @@ -16,9 +18,6 @@ namespace sdk { namespace logs { -class Logger; -class LogRecord; - class EventLogger final : public opentelemetry::logs::EventLogger { public: diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h index 4572647356..9e7ff4d866 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h @@ -3,7 +3,9 @@ #pragma once +#include "opentelemetry/logs/event_logger.h" #include "opentelemetry/logs/event_logger_provider.h" +#include "opentelemetry/logs/logger.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" @@ -17,9 +19,6 @@ namespace sdk { namespace logs { -class EventLogger; -class Logger; - class OPENTELEMETRY_EXPORT EventLoggerProvider final : public opentelemetry::logs::EventLoggerProvider { diff --git a/sdk/include/opentelemetry/sdk/logs/exporter.h b/sdk/include/opentelemetry/sdk/logs/exporter.h index 68c61603fa..15e848f351 100644 --- a/sdk/include/opentelemetry/sdk/logs/exporter.h +++ b/sdk/include/opentelemetry/sdk/logs/exporter.h @@ -8,6 +8,7 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -15,8 +16,6 @@ namespace sdk { namespace logs { -class Recordable; - /** * LogRecordExporter defines the interface that log exporters must implement. */ diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index fbbf4f28a5..ed43d1ce55 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -6,7 +6,7 @@ #include #include -#include "opentelemetry/common/macros.h" +#include "opentelemetry/logs/log_record.h" #include "opentelemetry/logs/logger.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" @@ -19,7 +19,6 @@ namespace sdk { namespace logs { -class LoggerProvider; class Logger final : public opentelemetry::logs::Logger { diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h index 9f8a8a54ba..5565be8a62 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -6,20 +6,16 @@ #include #include +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { -namespace resource -{ -class Resource; -} // namespace resource - namespace logs { -class LoggerContext; -class LogRecordProcessor; /** * Factory class for LoggerContext. diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index bced6061f5..bf116b4272 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -3,13 +3,19 @@ #pragma once +#include #include #include #include +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/logs/logger.h" #include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/logs/logger.h" +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" @@ -22,10 +28,6 @@ namespace sdk { namespace logs { -class Logger; -class LoggerContext; -class LogRecordProcessor; - class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::LoggerProvider { public: diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h index 8ca5cffcca..46432ef22e 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h @@ -8,6 +8,7 @@ #include #include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -15,8 +16,6 @@ namespace sdk { namespace logs { -class Recordable; - /** * Log processor allow hooks for receive method invocations. * diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h index 26bd9152ce..351b9c0f7f 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h @@ -6,6 +6,7 @@ #include #include +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -13,7 +14,6 @@ namespace sdk { namespace logs { -class LogRecordProcessor; /** * Factory class for MultiLogRecordProcessor. diff --git a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h index 1eb4b1a221..40a9c92e3b 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h @@ -3,11 +3,17 @@ #pragma once +#include #include #include #include +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/macros.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" @@ -17,8 +23,6 @@ namespace sdk { namespace logs { -class LogRecordProcessor; - class MultiRecordable final : public Recordable { public: diff --git a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h index a8f366b5b7..2222def9d2 100644 --- a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h @@ -3,14 +3,18 @@ #pragma once +#include #include #include #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" #include "opentelemetry/logs/severity.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h index a65c0eb7a9..23b6efa46f 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h @@ -8,7 +8,9 @@ #include #include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -16,9 +18,6 @@ namespace sdk { namespace logs { -class LogRecordExporter; -class Recordable; - /** * The simple log processor passes all log records * in a batch of 1 to the configured diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h index 295addce11..0b9df81c1e 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h @@ -5,6 +5,7 @@ #include +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -13,7 +14,6 @@ namespace sdk namespace logs { class LogRecordExporter; -class LogRecordProcessor; /** * Factory class for SimpleLogRecordProcessor. diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h index 04293e696f..c5cfcfd897 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h @@ -3,11 +3,17 @@ #pragma once +#include +#include #include #include +#include #include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h index 859fe26d6b..e8e6c40a30 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h @@ -3,10 +3,12 @@ #pragma once +#include #include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h index a098d86b72..035a8df84d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h @@ -3,10 +3,12 @@ #pragma once +#include #include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h index 32605dfd68..db4de054f4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h @@ -3,12 +3,14 @@ #pragma once -#include "opentelemetry/nostd/variant.h" - +#include #include #include #include +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h index 9fb0fbf5a0..d72ec08839 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h @@ -12,7 +12,9 @@ #include #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -21,8 +23,6 @@ namespace sdk namespace metrics { -class PushMetricExporter; - class PeriodicExportingMetricReader : public MetricReader { diff --git a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h index 1c5c1a0d7b..8cb439599e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h @@ -3,8 +3,11 @@ #pragma once +#include + #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -13,9 +16,6 @@ namespace sdk namespace metrics { -class MetricReader; -class PushMetricExporter; - class OPENTELEMETRY_EXPORT PeriodicExportingMetricReaderFactory { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h b/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h index fec1027746..a24d6db734 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h +++ b/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h @@ -3,9 +3,6 @@ #pragma once -#include - -#include "opentelemetry/common/macros.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index 2dfa2db56e..40a57a6f88 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -12,15 +12,20 @@ #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/filter_type.h" #endif -#include "opentelemetry/sdk/metrics/view/view_registry.h" -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/version.h" - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h index 126ad92282..30d5e60823 100644 --- a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h +++ b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h @@ -5,10 +5,9 @@ #include #include -#include #include "opentelemetry/nostd/function_ref.h" -#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/version.h" @@ -17,9 +16,6 @@ namespace sdk { namespace metrics { -class MetricProducer; -struct ResourceMetrics; - /** * MetricReader defines the interface to collect metrics from SDK */ diff --git a/sdk/include/opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h b/sdk/include/opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h index f9880b5073..329e75bfa7 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h @@ -3,9 +3,13 @@ #pragma once -#include -#include -#include "opentelemetry/sdk/common/attributemap_hash.h" +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -13,7 +17,8 @@ namespace sdk { namespace metrics { -class AttributesProcessor; +class AttributesProcessor; // IWYU pragma: keep + class FilteredOrderedAttributeMap : public opentelemetry::sdk::common::OrderedAttributeMap { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index bf0a9ba86b..e652ba12a9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -6,8 +6,10 @@ #include #include +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h index 031bab2f61..0e4d288d6e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -3,26 +3,25 @@ #pragma once +#include +#include #include -#include #include #include -#include -#include +#include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context.h" #include "opentelemetry/nostd/function_ref.h" -#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" - -#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" -# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" -#endif - +#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" @@ -30,6 +29,11 @@ #include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/version.h" +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +#endif + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h index 0a08e7d100..2d01710e47 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -11,7 +11,10 @@ #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -19,10 +22,6 @@ namespace sdk { namespace metrics { -class AggregationConfig; -class AttributesHashMap; -class CollectorHandle; -class MetricData; struct LastReportedMetrics { diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index f08b629fe2..1d2c5bf25f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -3,8 +3,12 @@ #pragma once +#include #include +#include +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/context/context.h" #include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" @@ -17,9 +21,6 @@ namespace sdk namespace metrics { -// forward declaration -class SyncWritableMetricStorage; - class Synchronous { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h index 3c221f123b..a2db241e98 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h @@ -3,9 +3,12 @@ #pragma once +#include #include #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -13,8 +16,6 @@ namespace sdk namespace metrics { -class InstrumentSelector; - class OPENTELEMETRY_EXPORT InstrumentSelectorFactory { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h index 47aa77b772..19cee41629 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h @@ -6,6 +6,7 @@ #include #include +#include "opentelemetry/sdk/metrics/view/meter_selector.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -14,8 +15,6 @@ namespace sdk namespace metrics { -class MeterSelector; - class OPENTELEMETRY_EXPORT MeterSelectorFactory { public: diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h index 22d34bf506..2fa1733f92 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h @@ -3,12 +3,14 @@ #pragma once -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/string_view.h" +#include +#include + #include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -16,8 +18,6 @@ namespace sdk namespace metrics { -class View; - /** * Factory class for View. */ diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h index f8f83c21ad..3592e95512 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h @@ -5,6 +5,7 @@ #include +#include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,9 +13,6 @@ namespace sdk { namespace metrics { - -class ViewRegistry; - class ViewRegistryFactory { public: diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index f7f6f4f0fd..f98c5c433f 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -3,8 +3,6 @@ #pragma once -#include "opentelemetry/detail/preprocessor.h" - #define OPENTELEMETRY_SDK_VERSION "1.15.0" #include "opentelemetry/version.h" diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index c29e27bdd3..c85d56739e 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -1,12 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/batch_log_record_processor.h" -#include "opentelemetry/common/spin_lock_mutex.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include "opentelemetry/sdk/common/circular_buffer.h" +#include "opentelemetry/sdk/common/circular_buffer_range.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/recordable.h" - -#include +#include "opentelemetry/version.h" using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBufferRange; diff --git a/sdk/src/logs/batch_log_record_processor_factory.cc b/sdk/src/logs/batch_log_record_processor_factory.cc index dabd0f4ff8..a6e29e4967 100644 --- a/sdk/src/logs/batch_log_record_processor_factory.cc +++ b/sdk/src/logs/batch_log_record_processor_factory.cc @@ -1,8 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" +#include +#include + #include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/event_logger.cc b/sdk/src/logs/event_logger.cc index c9dd5c35b5..6b0afacfaf 100644 --- a/sdk/src/logs/event_logger.cc +++ b/sdk/src/logs/event_logger.cc @@ -1,23 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include + +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/logs/event_logger.h" -#include "opentelemetry/sdk_config.h" -#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { -namespace nostd = opentelemetry::nostd; -EventLogger::EventLogger(nostd::shared_ptr delegate_logger, - nostd::string_view event_domain) noexcept +EventLogger::EventLogger( + opentelemetry::nostd::shared_ptr delegate_logger, + opentelemetry::nostd::string_view event_domain) noexcept : delegate_logger_(delegate_logger), event_domain_(event_domain) {} -const nostd::string_view EventLogger::GetName() noexcept +const opentelemetry::nostd::string_view EventLogger::GetName() noexcept { if (delegate_logger_) { @@ -27,13 +34,15 @@ const nostd::string_view EventLogger::GetName() noexcept return {}; } -nostd::shared_ptr EventLogger::GetDelegateLogger() noexcept +opentelemetry::nostd::shared_ptr +EventLogger::GetDelegateLogger() noexcept { return delegate_logger_; } -void EventLogger::EmitEvent(nostd::string_view event_name, - nostd::unique_ptr &&log_record) noexcept +void EventLogger::EmitEvent( + opentelemetry::nostd::string_view event_name, + opentelemetry::nostd::unique_ptr &&log_record) noexcept { if (!delegate_logger_ || !log_record) { diff --git a/sdk/src/logs/event_logger_provider.cc b/sdk/src/logs/event_logger_provider.cc index 28a88d82e2..570a64f82d 100644 --- a/sdk/src/logs/event_logger_provider.cc +++ b/sdk/src/logs/event_logger_provider.cc @@ -2,21 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/logs/event_logger_provider.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/logs/event_logger.h" - -#include -#include -#include -#include -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { -namespace nostd = opentelemetry::nostd; EventLoggerProvider::EventLoggerProvider() noexcept { @@ -25,11 +20,12 @@ EventLoggerProvider::EventLoggerProvider() noexcept EventLoggerProvider::~EventLoggerProvider() {} -nostd::shared_ptr EventLoggerProvider::CreateEventLogger( - nostd::shared_ptr delegate_logger, - nostd::string_view event_domain) noexcept +opentelemetry::nostd::shared_ptr +EventLoggerProvider::CreateEventLogger( + opentelemetry::nostd::shared_ptr delegate_logger, + opentelemetry::nostd::string_view event_domain) noexcept { - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new EventLogger(delegate_logger, event_domain)}; } diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 972b380efc..d3555ba4ec 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -1,12 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/logger.h" +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/logger.h" +#include "opentelemetry/sdk/logs/logger_context.h" #include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/recordable.h" -#include "opentelemetry/sdk_config.h" -#include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -14,11 +31,10 @@ namespace sdk namespace logs { namespace trace_api = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; Logger::Logger( - nostd::string_view name, + opentelemetry::nostd::string_view name, std::shared_ptr context, std::unique_ptr instrumentation_scope) noexcept : logger_name_(std::string(name)), @@ -26,12 +42,12 @@ Logger::Logger( context_(context) {} -const nostd::string_view Logger::GetName() noexcept +const opentelemetry::nostd::string_view Logger::GetName() noexcept { return logger_name_; } -nostd::unique_ptr Logger::CreateLogRecord() noexcept +opentelemetry::nostd::unique_ptr Logger::CreateLogRecord() noexcept { auto recordable = context_->GetProcessor().MakeRecordable(); @@ -42,10 +58,12 @@ nostd::unique_ptr Logger::CreateLogRecord() noex opentelemetry::context::ContextValue context_value = opentelemetry::context::RuntimeContext::GetCurrent().GetValue( opentelemetry::trace::kSpanKey); - if (nostd::holds_alternative>(context_value)) + if (opentelemetry::nostd::holds_alternative< + opentelemetry::nostd::shared_ptr>(context_value)) { - nostd::shared_ptr &data = - nostd::get>(context_value); + opentelemetry::nostd::shared_ptr &data = + opentelemetry::nostd::get>( + context_value); if (data) { recordable->SetTraceId(data->GetContext().trace_id()); @@ -53,10 +71,12 @@ nostd::unique_ptr Logger::CreateLogRecord() noex recordable->SetSpanId(data->GetContext().span_id()); } } - else if (nostd::holds_alternative>(context_value)) + else if (opentelemetry::nostd::holds_alternative< + opentelemetry::nostd::shared_ptr>(context_value)) { - nostd::shared_ptr &data = - nostd::get>(context_value); + opentelemetry::nostd::shared_ptr &data = + opentelemetry::nostd::get>( + context_value); if (data) { recordable->SetTraceId(data->trace_id()); @@ -66,10 +86,11 @@ nostd::unique_ptr Logger::CreateLogRecord() noex } } - return nostd::unique_ptr(recordable.release()); + return opentelemetry::nostd::unique_ptr(recordable.release()); } -void Logger::EmitLogRecord(nostd::unique_ptr &&log_record) noexcept +void Logger::EmitLogRecord( + opentelemetry::nostd::unique_ptr &&log_record) noexcept { if (!log_record) { diff --git a/sdk/src/logs/logger_context.cc b/sdk/src/logs/logger_context.cc index 357d13193d..2bfb89161e 100644 --- a/sdk/src/logs/logger_context.cc +++ b/sdk/src/logs/logger_context.cc @@ -1,12 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/logger_context.h" -#include "opentelemetry/sdk/logs/multi_log_record_processor.h" - +#include #include +#include #include +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/multi_log_record_processor.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/logs/logger_context_factory.cc b/sdk/src/logs/logger_context_factory.cc index ff57747f80..f11852be7f 100644 --- a/sdk/src/logs/logger_context_factory.cc +++ b/sdk/src/logs/logger_context_factory.cc @@ -1,13 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/logger_context_factory.h" +#include +#include +#include + #include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/logger_context_factory.h" #include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/resource/resource.h" - -#include -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 46eaa01054..c3b1fb7dd4 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -1,12 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/logger_provider.h" +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/logger.h" #include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -14,9 +28,6 @@ namespace sdk namespace logs { -namespace nostd = opentelemetry::nostd; -namespace logs_api = opentelemetry::logs; - LoggerProvider::LoggerProvider(std::unique_ptr &&processor, opentelemetry::sdk::resource::Resource resource) noexcept { @@ -50,11 +61,11 @@ LoggerProvider::~LoggerProvider() } } -nostd::shared_ptr LoggerProvider::GetLogger( - nostd::string_view logger_name, - nostd::string_view library_name, - nostd::string_view library_version, - nostd::string_view schema_url, +opentelemetry::nostd::shared_ptr LoggerProvider::GetLogger( + opentelemetry::nostd::string_view logger_name, + opentelemetry::nostd::string_view library_name, + opentelemetry::nostd::string_view library_version, + opentelemetry::nostd::string_view schema_url, const opentelemetry::common::KeyValueIterable &attributes) noexcept { // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-instrumentationscope @@ -73,7 +84,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( if (logger->GetName() == logger_name && logger_lib.equal(library_name, library_version, schema_url)) { - return nostd::shared_ptr{logger}; + return opentelemetry::nostd::shared_ptr{logger}; } } @@ -96,7 +107,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( loggers_.push_back(std::shared_ptr( new Logger(logger_name, context_, std::move(lib)))); - return nostd::shared_ptr{loggers_.back()}; + return opentelemetry::nostd::shared_ptr{loggers_.back()}; } void LoggerProvider::AddProcessor(std::unique_ptr processor) noexcept diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc index 8c169866ff..08567c65d9 100644 --- a/sdk/src/logs/logger_provider_factory.cc +++ b/sdk/src/logs/logger_provider_factory.cc @@ -1,12 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include +#include #include "opentelemetry/sdk/logs/logger_context.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/multi_log_record_processor.cc b/sdk/src/logs/multi_log_record_processor.cc index c0b3eb1ec6..efc1cbd1b4 100644 --- a/sdk/src/logs/multi_log_record_processor.cc +++ b/sdk/src/logs/multi_log_record_processor.cc @@ -1,9 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + #include "opentelemetry/sdk/logs/multi_log_record_processor.h" #include "opentelemetry/sdk/logs/multi_recordable.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/multi_log_record_processor_factory.cc b/sdk/src/logs/multi_log_record_processor_factory.cc index ab49689ca0..f51c851a28 100644 --- a/sdk/src/logs/multi_log_record_processor_factory.cc +++ b/sdk/src/logs/multi_log_record_processor_factory.cc @@ -1,13 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/multi_log_record_processor_factory.h" -#include "opentelemetry/sdk/logs/multi_log_record_processor.h" - -#include #include +#include #include +#include "opentelemetry/sdk/logs/multi_log_record_processor.h" +#include "opentelemetry/sdk/logs/multi_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/logs/multi_recordable.cc b/sdk/src/logs/multi_recordable.cc index 7d80259f27..53c2b25e33 100644 --- a/sdk/src/logs/multi_recordable.cc +++ b/sdk/src/logs/multi_recordable.cc @@ -1,11 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/multi_recordable.h" - +#include #include #include #include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/logs/multi_recordable.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/read_write_log_record.cc b/sdk/src/logs/read_write_log_record.cc index 27dd8f7d5f..48c9a2699d 100644 --- a/sdk/src/logs/read_write_log_record.cc +++ b/sdk/src/logs/read_write_log_record.cc @@ -1,10 +1,23 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include - +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/readable_log_record.cc b/sdk/src/logs/readable_log_record.cc index 80493354e3..4c8d119347 100644 --- a/sdk/src/logs/readable_log_record.cc +++ b/sdk/src/logs/readable_log_record.cc @@ -1,13 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/readable_log_record.h" +#include +#include +#include + +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/readable_log_record.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/version/version.h" - -#include -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/simple_log_record_processor.cc b/sdk/src/logs/simple_log_record_processor.cc index 68f90e83ab..7e65f31ca4 100644 --- a/sdk/src/logs/simple_log_record_processor.cc +++ b/sdk/src/logs/simple_log_record_processor.cc @@ -1,12 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include +#include +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/recordable.h" - -#include +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/simple_log_record_processor_factory.cc b/sdk/src/logs/simple_log_record_processor_factory.cc index 6146efc174..88e1b4b1ee 100644 --- a/sdk/src/logs/simple_log_record_processor_factory.cc +++ b/sdk/src/logs/simple_log_record_processor_factory.cc @@ -1,8 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include +#include + +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index 8e14ddec7a..da725cf09c 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -1,15 +1,23 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" -#include "opentelemetry/version.h" - +#include #include -#include +#include #include #include #include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc index 50904f8184..0380015234 100644 --- a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc +++ b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc @@ -1,12 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" +#include +#include +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index 0901a7bbdd..1e0442e92c 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -1,14 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +#include +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/version.h" -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 88f818dad9..311efc1e7e 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include +#include "opentelemetry/metrics/async_instruments.h" #include "opentelemetry/sdk/metrics/async_instruments.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk/metrics/state/observable_registry.h" #include "opentelemetry/version.h" diff --git a/sdk/src/metrics/data/circular_buffer.cc b/sdk/src/metrics/data/circular_buffer.cc index e2bd6e8ec0..007bedef6d 100644 --- a/sdk/src/metrics/data/circular_buffer.cc +++ b/sdk/src/metrics/data/circular_buffer.cc @@ -1,7 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/metrics/data/circular_buffer.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/exemplar/reservoir.cc b/sdk/src/metrics/exemplar/reservoir.cc index d695587a91..4e7501799e 100644 --- a/sdk/src/metrics/exemplar/reservoir.cc +++ b/sdk/src/metrics/exemplar/reservoir.cc @@ -1,13 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include - #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" -# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" # include "opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.h" diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 1de1ea71c8..f6ae47977d 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -1,12 +1,27 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" -#include "opentelemetry/common/spin_lock_mutex.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" -#include #if defined(_MSC_VER) # pragma warning(suppress : 5204) # include diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc index c4f0b8348a..6c85caaa2a 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc @@ -1,8 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" +#include +#include + #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/version.h" diff --git a/sdk/src/metrics/instrument_metadata_validator.cc b/sdk/src/metrics/instrument_metadata_validator.cc index 0b00404447..a63050985e 100644 --- a/sdk/src/metrics/instrument_metadata_validator.cc +++ b/sdk/src/metrics/instrument_metadata_validator.cc @@ -1,12 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/instrument_metadata_validator.h" -#include "opentelemetry/common/macros.h" -#include "opentelemetry/nostd/string_view.h" +#include +#include +#include +#include -#include -#include +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/metrics/instrument_metadata_validator.h" +#include "opentelemetry/version.h" #if OPENTELEMETRY_HAVE_WORKING_REGEX # include diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 763cdcbe02..f472ac726e 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -1,27 +1,46 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include - +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/metrics/async_instruments.h" #include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/metrics/async_instruments.h" - -#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/reservoir_utils.h" -#endif - +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/state/async_metric_storage.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" #include "opentelemetry/sdk/metrics/state/observable_registry.h" #include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/sync_instruments.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/version.h" -#include +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/reservoir_utils.h" +#endif OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -30,7 +49,6 @@ namespace metrics { namespace metrics = opentelemetry::metrics; -namespace nostd = opentelemetry::nostd; Meter::Meter( std::weak_ptr meter_context, @@ -40,38 +58,38 @@ Meter::Meter( observable_registry_(new ObservableRegistry()) {} -nostd::unique_ptr> Meter::CreateUInt64Counter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateUInt64Counter( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateUInt64Counter - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopCounter(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new LongCounter(instrument_descriptor, std::move(storage))); } -nostd::unique_ptr> Meter::CreateDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateDoubleCounter( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateDoubleCounter - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopCounter(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { @@ -79,14 +97,14 @@ nostd::unique_ptr> Meter::CreateDoubleCounter( std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>{ + return opentelemetry::nostd::unique_ptr>{ new DoubleCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr Meter::CreateInt64ObservableCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateInt64ObservableCounter(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -100,14 +118,14 @@ nostd::shared_ptr Meter::CreateInt std::string{unit.data(), unit.size()}, InstrumentType::kObservableCounter, InstrumentValueType::kLong}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr -Meter::CreateDoubleObservableCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateDoubleObservableCounter(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -121,21 +139,21 @@ Meter::CreateDoubleObservableCounter(nostd::string_view name, std::string{unit.data(), unit.size()}, InstrumentType::kObservableCounter, InstrumentValueType::kDouble}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::unique_ptr> Meter::CreateUInt64Histogram( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateUInt64Histogram( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateUInt64Histogram - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopHistogram(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { @@ -143,21 +161,21 @@ nostd::unique_ptr> Meter::CreateUInt64Histogram( std::string{unit.data(), unit.size()}, InstrumentType::kHistogram, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>{ + return opentelemetry::nostd::unique_ptr>{ new LongHistogram(instrument_descriptor, std::move(storage))}; } -nostd::unique_ptr> Meter::CreateDoubleHistogram( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateDoubleHistogram( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateDoubleHistogram - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopHistogram(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { @@ -165,14 +183,14 @@ nostd::unique_ptr> Meter::CreateDoubleHistogram( std::string{unit.data(), unit.size()}, InstrumentType::kHistogram, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>{ + return opentelemetry::nostd::unique_ptr>{ new DoubleHistogram(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr Meter::CreateInt64ObservableGauge( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateInt64ObservableGauge(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -186,14 +204,14 @@ nostd::shared_ptr Meter::CreateInt std::string{unit.data(), unit.size()}, InstrumentType::kObservableGauge, InstrumentValueType::kLong}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr Meter::CreateDoubleObservableGauge( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateDoubleObservableGauge(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -207,21 +225,21 @@ nostd::shared_ptr Meter::CreateDou std::string{unit.data(), unit.size()}, InstrumentType::kObservableGauge, InstrumentValueType::kDouble}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::unique_ptr> Meter::CreateInt64UpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateInt64UpDownCounter( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateInt64UpDownCounter - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopUpDownCounter(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { @@ -229,21 +247,21 @@ nostd::unique_ptr> Meter::CreateInt64UpDownCount std::string{unit.data(), unit.size()}, InstrumentType::kUpDownCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>{ + return opentelemetry::nostd::unique_ptr>{ new LongUpDownCounter(instrument_descriptor, std::move(storage))}; } -nostd::unique_ptr> Meter::CreateDoubleUpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::unique_ptr> Meter::CreateDoubleUpDownCounter( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { OTEL_INTERNAL_LOG_ERROR("Meter::CreateDoubleUpDownCounter - failed. Invalid parameters." << name << " " << description << " " << unit << ". Measurements won't be recorded."); - return nostd::unique_ptr>( + return opentelemetry::nostd::unique_ptr>( new metrics::NoopUpDownCounter(name, description, unit)); } InstrumentDescriptor instrument_descriptor = { @@ -251,14 +269,14 @@ nostd::unique_ptr> Meter::CreateDoubleUpDownCount std::string{unit.data(), unit.size()}, InstrumentType::kUpDownCounter, InstrumentValueType::kDouble}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::unique_ptr>{ + return opentelemetry::nostd::unique_ptr>{ new DoubleUpDownCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr -Meter::CreateInt64ObservableUpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateInt64ObservableUpDownCounter(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -272,14 +290,14 @@ Meter::CreateInt64ObservableUpDownCounter(nostd::string_view name, std::string{unit.data(), unit.size()}, InstrumentType::kObservableUpDownCounter, InstrumentValueType::kLong}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr -Meter::CreateDoubleObservableUpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +opentelemetry::nostd::shared_ptr +Meter::CreateDoubleObservableUpDownCounter(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view description, + opentelemetry::nostd::string_view unit) noexcept { if (!ValidateInstrument(name, description, unit)) { @@ -293,7 +311,7 @@ Meter::CreateDoubleObservableUpDownCounter(nostd::string_view name, std::string{unit.data(), unit.size()}, InstrumentType::kObservableUpDownCounter, InstrumentValueType::kDouble}; auto storage = RegisterAsyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr{ + return opentelemetry::nostd::shared_ptr{ new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index 2b5ef3148c..de32c469d8 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -1,14 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/meter_context.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" -#include "opentelemetry/sdk_config.h" - -#include +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/meter_context_factory.cc b/sdk/src/metrics/meter_context_factory.cc index d41bb6a193..59e97ce264 100644 --- a/sdk/src/metrics/meter_context_factory.cc +++ b/sdk/src/metrics/meter_context_factory.cc @@ -1,10 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/meter_context_factory.h" +#include +#include + #include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/meter_context_factory.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/sdk/metrics/view/view_registry_factory.h" - +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 84a0f56bf4..959ff32800 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -1,18 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include #include #include #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/metrics/meter.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/metrics/metric_reader.cc b/sdk/src/metrics/metric_reader.cc index 8046b1c148..e2f5bc1f1c 100644 --- a/sdk/src/metrics/metric_reader.cc +++ b/sdk/src/metrics/metric_reader.cc @@ -4,8 +4,7 @@ #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/state/metric_collector.cc b/sdk/src/metrics/state/metric_collector.cc index f0535a905d..5ecf41cecf 100644 --- a/sdk/src/metrics/state/metric_collector.cc +++ b/sdk/src/metrics/state/metric_collector.cc @@ -1,12 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 86a6d17abd..4da46ddfe3 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -1,11 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/observable_registry.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/async_instruments.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/observer_result.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/sdk/metrics/state/observable_registry.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/state/sync_metric_storage.cc b/sdk/src/metrics/state/sync_metric_storage.cc index 72bee72ea5..fe736e64f3 100644 --- a/sdk/src/metrics/state/sync_metric_storage.cc +++ b/sdk/src/metrics/state/sync_metric_storage.cc @@ -1,7 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" +#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index f988551108..2ba74d9213 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -1,16 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +#include +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" - -#include -#include -#include +#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index bdeff150ae..a99fa80868 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -1,9 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk/metrics/sync_instruments.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/view/view_factory.cc b/sdk/src/metrics/view/view_factory.cc index 24d87769f9..36496f62d6 100644 --- a/sdk/src/metrics/view/view_factory.cc +++ b/sdk/src/metrics/view/view_factory.cc @@ -1,8 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/view/view_factory.h" +#include +#include +#include + +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_factory.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 7759949490..c5e72f8176 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #include -#include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/atomic_unique_ptr.h" From 9af3c99cf03765b64279d2df654772fd53d79490 Mon Sep 17 00:00:00 2001 From: Darren Bolduc Date: Sat, 15 Jun 2024 12:20:57 -0400 Subject: [PATCH 04/71] [BUILD] Restore Bazel flag removed from public API (#2702) --- api/BUILD | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/BUILD b/api/BUILD index 2eca1de986..fdfe3ca146 100644 --- a/api/BUILD +++ b/api/BUILD @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") package(default_visibility = ["//visibility:public"]) @@ -55,3 +55,9 @@ config_setting( constraint_values = ["@bazel_tools//tools/cpp:msvc"], flag_values = {":with_cxx_stdlib": "best"}, ) + +bool_flag( + name = "with_abseil", + build_setting_default = False, + deprecation = "The value of this flag is ignored. Bazel builds always depend on Abseil for its pre-adopted `std::` types. You should remove this flag from your build command.", +) From 05bfb8a2578aa7af8145b0bb0e3fd9e87b60dd71 Mon Sep 17 00:00:00 2001 From: Yijie Ma Date: Sun, 16 Jun 2024 23:51:42 -0700 Subject: [PATCH 05/71] [DOC] Fix typo tace_id -> trace_id in logger.h (#2703) --- api/include/opentelemetry/logs/logger.h | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/api/include/opentelemetry/logs/logger.h b/api/include/opentelemetry/logs/logger.h index 46fd8bca72..dc09a0c2b4 100644 --- a/api/include/opentelemetry/logs/logger.h +++ b/api/include/opentelemetry/logs/logger.h @@ -54,9 +54,9 @@ class Logger * Severity -> severity, severity_text * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -86,9 +86,9 @@ class Logger * Severity -> severity, severity_text * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -109,9 +109,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -133,9 +133,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -157,9 +157,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -181,9 +181,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -205,9 +205,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp @@ -229,9 +229,9 @@ class Logger * @tparam args Arguments which can be used to set data of log record by type. * string_view -> body * AttributeValue -> body - * SpanContext -> span_id,tace_id and trace_flags + * SpanContext -> span_id,trace_id and trace_flags * SpanId -> span_id - * TraceId -> tace_id + * TraceId -> trace_id * TraceFlags -> trace_flags * SystemTimestamp -> timestamp * system_clock::time_point -> timestamp From 595801bab9ace8b0930b97183a2d9a28adb5d1fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:11:37 +0200 Subject: [PATCH 06/71] Bump docker/build-push-action from 5 to 6 (#2705) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 5 to 6. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v5...v6) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependencies_image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependencies_image.yml b/.github/workflows/dependencies_image.yml index 723fd1256b..0c7bad843f 100644 --- a/.github/workflows/dependencies_image.yml +++ b/.github/workflows/dependencies_image.yml @@ -21,7 +21,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build Image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: builder: ${{ steps.buildx.outputs.name }} context: ci/ From aff26ac503b1cd7e0b038cd9bb627c332fdd7036 Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:25:08 +0200 Subject: [PATCH 07/71] [CI] Enable ARM64 build in CI (#2699) --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ ci/setup_cmake.sh | 9 +++++++++ ci/setup_gcc10.sh | 10 ++++++++++ 3 files changed, 50 insertions(+) create mode 100755 ci/setup_cmake.sh create mode 100755 ci/setup_gcc10.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26c692953c..8c17bbece0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,37 @@ on: branches: [ main ] jobs: + arm64_test: + name: CMake test arm64 (with modern protobuf,grpc and abseil) + runs-on: actuated-arm64-4cpu-16gb + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + PROTOBUF_VERSION: '23.3' + ABSEIL_CPP_VERSION: '20230125.3' + CXX_STANDARD: '14' + CC: /usr/bin/gcc-10 + CXX: /usr/bin/g++-10 + run: | + sudo -E ./ci/setup_gcc10.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_googletest.sh + sudo -E ./ci/install_abseil.sh + sudo -E ./ci/install_protobuf.sh + - name: run otlp exporter tests + env: + CC: /usr/bin/gcc-10 + CXX: /usr/bin/g++-10 + WITH_ABSEIL: 'ON' + CXX_STANDARD: '14' + run: | + sudo -E ./ci/setup_grpc.sh -m -p protobuf -p abseil-cpp + ./ci/do_ci.sh cmake.exporter.otprotocol.test + cmake_test: name: CMake test (without otlp-exporter) runs-on: ubuntu-latest diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh new file mode 100755 index 0000000000..0cb5d7eb79 --- /dev/null +++ b/ci/setup_cmake.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -e +apt-get update +apt-get install --no-install-recommends --no-install-suggests -y \ + cmake diff --git a/ci/setup_gcc10.sh b/ci/setup_gcc10.sh new file mode 100755 index 0000000000..119d361cbf --- /dev/null +++ b/ci/setup_gcc10.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -e +apt-get update +apt-get install --no-install-recommends --no-install-suggests -y \ + g++-10 \ + gcc-10 From e1d96901fc9f41d79244e35c4209649d22b9fe9d Mon Sep 17 00:00:00 2001 From: Harish <140232061+perhapsmaple@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:50:57 +0530 Subject: [PATCH 08/71] [Code health] Remove Unicode Text from Source files (#2707) Signed-off-by: perhapsmaple <140232061+perhapsmaple@users.noreply.github.com> --- api/include/opentelemetry/baggage/baggage.h | 2 +- api/include/opentelemetry/context/context.h | 2 +- api/include/opentelemetry/context/runtime_context.h | 2 +- ext/test/http/url_parser_test.cc | 3 ++- opentracing-shim/src/span_shim.cc | 2 +- sdk/test/metrics/instrument_metadata_validator_test.cc | 10 +++++----- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index 66eb9d9833..6c799cda27 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 #pragma once diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index d0b53c3ea8..cf5c9cd319 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 #pragma once diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h index 2cd5b0ff90..cccc71e32f 100644 --- a/api/include/opentelemetry/context/runtime_context.h +++ b/api/include/opentelemetry/context/runtime_context.h @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 #pragma once diff --git a/ext/test/http/url_parser_test.cc b/ext/test/http/url_parser_test.cc index 212c5655a7..7b28d763e6 100644 --- a/ext/test/http/url_parser_test.cc +++ b/ext/test/http/url_parser_test.cc @@ -140,7 +140,8 @@ TEST(UrlDecoderTests, BasicTests) std::map testdata{ {"Authentication=Basic xxx", "Authentication=Basic xxx"}, {"Authentication=Basic%20xxx", "Authentication=Basic xxx"}, - {"%C3%B6%C3%A0%C2%A7%C3%96abcd%C3%84", "öà§ÖabcdÄ"}, + {"%C3%B6%C3%A0%C2%A7%C3%96abcd%C3%84", + "\xc3\xb6\xc3\xa0\xc2\xa7\xc3\x96\x61\x62\x63\x64\xc3\x84"}, {"%2x", "%2x"}, {"%20", " "}, {"text%2", "text%2"}, diff --git a/opentracing-shim/src/span_shim.cc b/opentracing-shim/src/span_shim.cc index 808b6b9e74..7911277f78 100644 --- a/opentracing-shim/src/span_shim.cc +++ b/opentracing-shim/src/span_shim.cc @@ -111,7 +111,7 @@ void SpanShim::Log(opentracing::SystemTime timestamp, void SpanShim::logImpl(nostd::span fields, const opentracing::SystemTime *const timestamp) noexcept { - // The Add Event’s name parameter MUST be the value with the event key + // The Add Event's name parameter MUST be the value with the event key // in the pair set, or else fallback to use the log literal string. const auto &event = std::find_if(fields.begin(), fields.end(), [](const EventEntry &item) { return item.first == "event"; }); diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 17b76a9419..172df1af3c 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -19,14 +19,14 @@ TEST(InstrumentMetadataValidator, TestName) { opentelemetry::sdk::metrics::InstrumentMetaDataValidator validator; std::vector invalid_names = { - "", // empty string - "1sdf", // string starting with number - "123€AAA€BBB", // unicode characters + "", // empty string + "1sdf", // string starting with number + "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42" // unicode characters "/\\sdsd", // string starting with special character "***sSSs", // string starting with special character "a\\broken\\path", // contains backward slash CreateVeryLargeString(25) + "X", // total 256 characters - CreateVeryLargeString(26), // string much bigger than 255 characters + CreateVeryLargeString(26), // string much bigger than 255 character }; for (auto const &str : invalid_names) { @@ -56,7 +56,7 @@ TEST(InstrumentMetadataValidator, TestUnit) std::vector invalid_units = { CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 charactes CreateVeryLargeString(7), // string bigger than 63 chars - "123€AAA€BBB", // unicode string + "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42", // unicode string }; for (auto const &str : invalid_units) { From 086e94cdbd10c742b07ca3b351157e253c9152eb Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 21 Jun 2024 15:35:34 +0800 Subject: [PATCH 09/71] [BUILD] Add option `WITH_OTLP_GRPC_SSL_MTLS_PREVIEW` (#2714) --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d7831b2a4..711ac14c4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,9 @@ if(DEFINED WITH_OTLP) ) endif() +option(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW + "Whether to enable mTLS support fro gRPC" OFF) + option(WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" OFF) From 4e86a86a5fbb5b72c0adb4ded18c49400fc8685f Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 21 Jun 2024 17:14:09 +0800 Subject: [PATCH 10/71] [EXPORTER] All 2xx return codes should be considered successful. (#2712) --- exporters/elasticsearch/src/es_log_record_exporter.cc | 2 +- exporters/otlp/src/otlp_http_client.cc | 2 +- exporters/zipkin/src/zipkin_exporter.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index e58fb1dda4..3b3e8c4aeb 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -59,7 +59,7 @@ class ResponseHandler : public http_client::EventHandler // Store the body of the request body_ = std::string(response.GetBody().begin(), response.GetBody().end()); - if (response.GetStatusCode() != 200 && response.GetStatusCode() != 202) + if (!(response.GetStatusCode() >= 200 && response.GetStatusCode() <= 299)) { log_message = BuildResponseLogMessage(response, body_); diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 6a1b89164e..8bada1e0e0 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -100,7 +100,7 @@ class ResponseHandler : public http_client::EventHandler // Store the body of the request body_ = std::string(response.GetBody().begin(), response.GetBody().end()); - if (response.GetStatusCode() != 200 && response.GetStatusCode() != 202) + if (!(response.GetStatusCode() >= 200 && response.GetStatusCode() <= 299)) { log_message = BuildResponseLogMessage(response, body_); diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index 97fdf4e63a..a8a97b58af 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -78,7 +78,7 @@ sdk::common::ExportResult ZipkinExporter::Export( http_client::Body body_v(body_s.begin(), body_s.end()); auto result = http_client_->PostNoSsl(url_parser_.url_, body_v, options_.headers); if (result && - (result.GetResponse().GetStatusCode() == 200 || result.GetResponse().GetStatusCode() == 202)) + (result.GetResponse().GetStatusCode() >= 200 && result.GetResponse().GetStatusCode() <= 299)) { return sdk::common::ExportResult::kSuccess; } From fd57e7aa23ffc352f62e504f34fd1c6b7b2ecac3 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 21 Jun 2024 19:13:20 +0200 Subject: [PATCH 11/71] [RELEASE] Release opentelemetry-cpp version 1.16.0 (#2711) --- CHANGELOG.md | 69 +++++++++++++++++-- api/include/opentelemetry/version.h | 4 +- docs/public/conf.py | 2 +- .../opentelemetry/sdk/version/version.h | 2 +- sdk/src/version/version.cc | 8 +-- 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c08c6065..6edb724131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,17 +15,78 @@ Increment the: ## [Unreleased] -* [SDK] Update ExemplarFilter and ExemplarReservoir for spec - [#2372](https://github.com/open-telemetry/opentelemetry-cpp/pull/2372) +## [1.16.0] 2024-06-21 +* [BUILD] Upgrade bazel abseil from 20220623.1 to 20230802.2 + [#2650](https://github.com/open-telemetry/opentelemetry-cpp/pull/2650) +* [BUILD] Use nostd::enable_if_t instead of std::enable_if_t + [#2648](https://github.com/open-telemetry/opentelemetry-cpp/pull/2648) +* [EXEMPLAR] Update ExemplarFilter and ExemplarReservoir for spec + [#2372](https://github.com/open-telemetry/opentelemetry-cpp/pull/2372) +* [BUILD] Link CoreFoundation on apple systems + [#2655](https://github.com/open-telemetry/opentelemetry-cpp/pull/2655) +* [SDK] Avoid missing conditional variable update and simplify atomic bool + [#2553](https://github.com/open-telemetry/opentelemetry-cpp/pull/2553) +* [BUILD] Build break in OLTP_FILE tests + [#2659](https://github.com/open-telemetry/opentelemetry-cpp/pull/2659) +* [EXPORTER] General cleanup for is_shutdown flags in exporters. + [#2663](https://github.com/open-telemetry/opentelemetry-cpp/pull/2663) +* [CI] Upgrade Maintainers CI to ubuntu-24.04 + [#2670](https://github.com/open-telemetry/opentelemetry-cpp/pull/2670) +* [BUILD] Upgrade to opentelemetry-proto 1.3.1 + [#2669](https://github.com/open-telemetry/opentelemetry-cpp/pull/2669) +* [API] Return NoopLogRecord from NoopLogger + [#2668](https://github.com/open-telemetry/opentelemetry-cpp/pull/2668) +* [BUILD] Remove the hard-coded separator in tracestate + [#2672](https://github.com/open-telemetry/opentelemetry-cpp/pull/2672) +* [SDK] Fix forceflush may wait for ever + [#2584](https://github.com/open-telemetry/opentelemetry-cpp/pull/2584) +* [API] DO not allow unsafe Logger::EmitLogRecord + [#2673](https://github.com/open-telemetry/opentelemetry-cpp/pull/2673) +* [BUILD] Read default proto version from third_party_release + [#2677](https://github.com/open-telemetry/opentelemetry-cpp/pull/2677) +* [CI] include-what-you-use + [#2629](https://github.com/open-telemetry/opentelemetry-cpp/pull/2629) * [CI] Upgrade to clang-format 18 [#2684](https://github.com/open-telemetry/opentelemetry-cpp/pull/2684) - +* [CI] Fix CI failures on Ubuntu 24.04 + [#2686](https://github.com/open-telemetry/opentelemetry-cpp/pull/2686) +* [SEMANTIC CONVENTIONS] Upgrade to version 1.26.0 + [#2687](https://github.com/open-telemetry/opentelemetry-cpp/pull/2687) * [API/SDK] Provider cleanup [#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664) - +* [ETW] Add table name mapping for Logs other than the default Log table + [#2691](https://github.com/open-telemetry/opentelemetry-cpp/pull/2691) +* [CI] Remove benchmark overlay for vcpkg + [#2695](https://github.com/open-telemetry/opentelemetry-cpp/pull/2695) +* [BUILD] Remove the incorrect set of CMAKE_MSVC_RUNTIME_LIBRARY for vcpkg + [#2696](https://github.com/open-telemetry/opentelemetry-cpp/pull/2696) +* [BUILD] CMakeLists.txt: Enable CMAKE_MSVC_RUNTIME_LIBRARY support + [#2652](https://github.com/open-telemetry/opentelemetry-cpp/pull/2652) +* [EXPORTER] OTLP file: use thread-safe file/io + [#2675](https://github.com/open-telemetry/opentelemetry-cpp/pull/2675) +* [bazel] Bump version and deps + [#2679](https://github.com/open-telemetry/opentelemetry-cpp/pull/2679) +* [BUILD] Add support for bzlmod + [#2608](https://github.com/open-telemetry/opentelemetry-cpp/pull/2608) +* [BUILD] Fix Import Abseil-cpp + [#2701](https://github.com/open-telemetry/opentelemetry-cpp/pull/2701) * [Code health] include-what-you-use cleanup [#2692](https://github.com/open-telemetry/opentelemetry-cpp/pull/2692) +* [BUILD] Restore Bazel flag removed from public API + [#2702](https://github.com/open-telemetry/opentelemetry-cpp/pull/2702) +* [DOC] Fix typo tace_id -> trace_id in logger.h + [#2703](https://github.com/open-telemetry/opentelemetry-cpp/pull/2703) +* Bump docker/build-push-action from 5 to 6 + [#2705](https://github.com/open-telemetry/opentelemetry-cpp/pull/2705) +* [CI] Enable ARM64 build in CI + [#2699](https://github.com/open-telemetry/opentelemetry-cpp/pull/2699) +* [Code health] Remove Unicode Text from Source files + [#2707](https://github.com/open-telemetry/opentelemetry-cpp/pull/2707) +* [BUILD] Add option WITH_OTLP_GRPC_SSL_MTLS_PREVIEW + [#2714](https://github.com/open-telemetry/opentelemetry-cpp/pull/2714) +* [EXPORTER] All 2xx return codes should be considered successful. + [#2712](https://github.com/open-telemetry/opentelemetry-cpp/pull/2712) Important changes: diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 6e8a24a2d4..e09c193659 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -10,9 +10,9 @@ # define OPENTELEMETRY_ABI_VERSION_NO 1 #endif -#define OPENTELEMETRY_VERSION "1.15.0" +#define OPENTELEMETRY_VERSION "1.16.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 15 +#define OPENTELEMETRY_VERSION_MINOR 16 #define OPENTELEMETRY_VERSION_PATCH 0 #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) diff --git a/docs/public/conf.py b/docs/public/conf.py index 1747696a30..927e07751a 100644 --- a/docs/public/conf.py +++ b/docs/public/conf.py @@ -24,7 +24,7 @@ author = 'OpenTelemetry authors' # The full version, including alpha/beta/rc tags -release = "1.15.0" +release = "1.16.0" # Run sphinx on subprojects and copy output # ----------------------------------------- diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index f98c5c433f..bfc93238b4 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -3,7 +3,7 @@ #pragma once -#define OPENTELEMETRY_SDK_VERSION "1.15.0" +#define OPENTELEMETRY_SDK_VERSION "1.16.0" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index 71d8db16e2..e5fdbda99d 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -12,13 +12,13 @@ namespace sdk namespace version { const int major_version = 1; -const int minor_version = 15; +const int minor_version = 16; const int patch_version = 0; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.15.0"; -const char *full_version = "1.15.0-NONE-NONE"; -const char *build_date = "Sun Apr 21 19:31:02 UTC 2024"; +const char *short_version = "1.16.0"; +const char *full_version = "1.16.0-NONE-NONE"; +const char *build_date = "Fri Jun 21 16:41:17 UTC 2024"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 77012391b272c016b15611092626dec4c21c54bb Mon Sep 17 00:00:00 2001 From: Dat Le <4686348+tdat00@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:01:41 +0700 Subject: [PATCH 12/71] [BUILD] Add bazel missing BUILD file (#2720) --- examples/etw_threads/BUILD | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/etw_threads/BUILD diff --git a/examples/etw_threads/BUILD b/examples/etw_threads/BUILD new file mode 100644 index 0000000000..edb60080eb --- /dev/null +++ b/examples/etw_threads/BUILD @@ -0,0 +1,18 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cc_binary( + name = "example_etw_threads", + srcs = [ + "main.cc", + ], + tags = [ + "etw", + "examples", + ], + target_compatible_with = ["@platforms//os:windows"], + deps = [ + "//api", + "//exporters/etw:etw_exporter", + ], +) From f0e0ef0bf3e769b609de3fd1d79a5b615b8bc881 Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Thu, 27 Jun 2024 18:14:31 -0400 Subject: [PATCH 13/71] [SDK] Added reserve for spans array in BatchSpanProcessor. (#2724) * Added reserve for spans array in BatchSpanProcessor. Added reserve for spans array in BatchSpanProcessor. Helps to allocate the amount of memory needed for number of records so that dynamic memory allocation doesn't happen in the consume method. .push_back() reallocates memory each time the method is called. Using .reserve() would avoid memory reallocation as already the memory is allocated. References: https://cplusplus.com/reference/vector/vector/push_back/ https://cplusplus.com/reference/vector/vector/reserve/ * Added reserve for spans array in BatchLogProcessor. Added reserve for spans array in BatchLogProcessor. Same as previously done for BatchSpanProcessor * Update batch_log_record_processor.cc * Update batch_span_processor.cc * Update sdk/src/logs/batch_log_record_processor.cc --- sdk/src/logs/batch_log_record_processor.cc | 2 ++ sdk/src/trace/batch_span_processor.cc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index c85d56739e..f5c35ad339 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -208,6 +208,8 @@ void BatchLogRecordProcessor::Export() break; } + // Reserve space for the number of records + records_arr.reserve(num_records_to_export); buffer_.Consume(num_records_to_export, [&](CircularBufferRange> range) noexcept { range.ForEach([&](AtomicUniquePtr &ptr) { diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index c5e72f8176..03b79f6ebb 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -206,6 +206,10 @@ void BatchSpanProcessor::Export() NotifyCompletion(notify_force_flush, exporter_, synchronization_data_); break; } + + // Reserve space for the number of records + spans_arr.reserve(num_records_to_export); + buffer_.Consume(num_records_to_export, [&](CircularBufferRange> range) noexcept { range.ForEach([&](AtomicUniquePtr &ptr) { From ead2d1b6062473c354a9ca91f65e322170acb001 Mon Sep 17 00:00:00 2001 From: Pravila Date: Sun, 30 Jun 2024 13:47:06 +0100 Subject: [PATCH 14/71] [DOC] Update "Using triplets" section in building-with-vcpkg documentation. (#2726) * Update triplet links in building-with-vcpkg documentation. * Update docs/building-with-vcpkg.md Co-authored-by: Tom Tan --------- Co-authored-by: Marc Alff Co-authored-by: Tom Tan --- docs/building-with-vcpkg.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/building-with-vcpkg.md b/docs/building-with-vcpkg.md index aace95460c..70d794d5cf 100644 --- a/docs/building-with-vcpkg.md +++ b/docs/building-with-vcpkg.md @@ -67,12 +67,12 @@ logs in case if you encounter package installation failures. In order to enable custom build flags - vcpkg triplets and custom environment variables may be used. Please see [triplets instruction -here](https://vcpkg.readthedocs.io/en/latest/users/triplets/). Response file for +here](https://learn.microsoft.com/en-us/vcpkg/users/triplets). Response file for a custom build, e.g. `response_file_linux_PRODUCTNAME.txt` may specify a custom triplet. For example, custom triplet controls if the library is built as static -or dynamic. Default triplets may also be overridden with [custom -triplets](https://vcpkg.readthedocs.io/en/latest/examples/overlay-triplets-linux-dynamic/#overlay-triplets-example). -Custom triplets specific to various products must be maintained by product +or dynamic. Default triplets may also be overridden with [overlay +triplets](https://learn.microsoft.com/en-us/vcpkg/users/examples/overlay-triplets-linux-dynamic). +Overlay triplets specific to various products must be maintained by product teams. Product teams may optionally decide to integrate their triplets in the mainline OpenTelemetry C++ SDK repo as-needed. From 5e21b8ac2dec059d89f515e67600a0c11d15d19f Mon Sep 17 00:00:00 2001 From: Dylan Herman Date: Sun, 30 Jun 2024 14:42:19 -0700 Subject: [PATCH 15/71] [DOC] Remove comment for unused LoggerProvider initialization params (#2972) --- sdk/include/opentelemetry/sdk/logs/logger_provider.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index bf116b4272..6c035ad5e9 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -36,10 +36,6 @@ class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::Lo * @param processor The span processor for this logger provider. This must * not be a nullptr. * @param resource The resources for this logger provider. - * @param sampler The sampler for this logger provider. This must - * not be a nullptr. - * @param id_generator The custom id generator for this logger provider. This must - * not be a nullptr */ explicit LoggerProvider(std::unique_ptr &&processor, opentelemetry::sdk::resource::Resource resource = From 42563e41602bd29fba7ea00082a4df4a4f8c7676 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 2 Jul 2024 20:42:54 +0200 Subject: [PATCH 16/71] [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1, require TLS 1.2 (#2722) --- CHANGELOG.md | 19 ++++++ .../exporters/otlp/otlp_environment.h | 2 +- .../ext/http/client/http_client.h | 8 +-- .../http/client/curl/http_operation_curl.cc | 40 +++++------- functional/otlp/func_http_main.cc | 62 +++++++++++++++---- 5 files changed, 86 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6edb724131..92e234a77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,25 @@ Increment the: ## [Unreleased] +* [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1, + require TLS 1.2 or better + [#2721](https://github.com/open-telemetry/opentelemetry-cpp/pull/2721) + +Breaking changes: + +* [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1, + require TLS 1.2 or better + [#2721](https://github.com/open-telemetry/opentelemetry-cpp/pull/2721) + * The OTLP HTTP exporter no longer accept options like: + * min_TLS = 1.0 + * min_TLS = 1.1 + * max_TLS = 1.0 + * max_TLS = 1.1 + * When connecting to an OTLP HTTP endpoint, using `https`, + the connection will require TLS 1.2 by default, + unless min_TLS is set to 1.3 + * Plain `http` connections (insecure) are not affected. + ## [1.16.0] 2024-06-21 * [BUILD] Upgrade bazel abseil from 20220623.1 to 20230802.2 diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h index c2e0afb7bc..8b486a548f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h @@ -111,7 +111,7 @@ std::string GetOtlpDefaultTracesSslTlsMaxVersion(); std::string GetOtlpDefaultMetricsSslTlsMaxVersion(); std::string GetOtlpDefaultLogsSslTlsMaxVersion(); -// For TLS 1.0, 1.1, 1.2 +// For TLS 1.2 std::string GetOtlpDefaultTracesSslTlsCipher(); std::string GetOtlpDefaultMetricsSslTlsCipher(); std::string GetOtlpDefaultLogsSslTlsCipher(); diff --git a/ext/include/opentelemetry/ext/http/client/http_client.h b/ext/include/opentelemetry/ext/http/client/http_client.h index b3cf7365eb..1089402e28 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client.h +++ b/ext/include/opentelemetry/ext/http/client/http_client.h @@ -192,9 +192,7 @@ struct HttpSslOptions /** Minimum SSL version to use. Valid values are: - - empty (no minimum version required) - - "1.0" (TLSv1.0) - - "1.1" (TLSv1.1) + - empty (defaults to TLSv1.2) - "1.2" (TLSv1.2) - "1.3" (TLSv1.3) */ @@ -204,8 +202,6 @@ struct HttpSslOptions Maximum SSL version to use. Valid values are: - empty (no maximum version required) - - "1.0" (TLSv1.0) - - "1.1" (TLSv1.1) - "1.2" (TLSv1.2) - "1.3" (TLSv1.3) */ @@ -213,7 +209,7 @@ struct HttpSslOptions /** TLS Cipher. - This is for TLS 1.0, 1.1 and 1.2. + This is for TLS 1.2. The list is delimited by colons (":"). Cipher names depends on the underlying CURL implementation. */ diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index 25f43fcb2f..fe06384414 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -414,16 +414,16 @@ void HttpOperation::Cleanup() To represent versions, the following symbols are needed: Added in CURL 7.34.0: - - CURL_SSLVERSION_TLSv1_0 - - CURL_SSLVERSION_TLSv1_1 + - CURL_SSLVERSION_TLSv1_0 (do not use) + - CURL_SSLVERSION_TLSv1_1 (do not use) - CURL_SSLVERSION_TLSv1_2 Added in CURL 7.52.0: - CURL_SSLVERSION_TLSv1_3 Added in CURL 7.54.0: - - CURL_SSLVERSION_MAX_TLSv1_0 - - CURL_SSLVERSION_MAX_TLSv1_1 + - CURL_SSLVERSION_MAX_TLSv1_0 (do not use) + - CURL_SSLVERSION_MAX_TLSv1_1 (do not use) - CURL_SSLVERSION_MAX_TLSv1_2 - CURL_SSLVERSION_MAX_TLSv1_3 @@ -439,16 +439,6 @@ void HttpOperation::Cleanup() static long parse_min_ssl_version(std::string version) { #ifdef HAVE_TLS_VERSION - if (version == "1.0") - { - return CURL_SSLVERSION_TLSv1_0; - } - - if (version == "1.1") - { - return CURL_SSLVERSION_TLSv1_1; - } - if (version == "1.2") { return CURL_SSLVERSION_TLSv1_2; @@ -466,16 +456,6 @@ static long parse_min_ssl_version(std::string version) static long parse_max_ssl_version(std::string version) { #ifdef HAVE_TLS_VERSION - if (version == "1.0") - { - return CURL_SSLVERSION_MAX_TLSv1_0; - } - - if (version == "1.1") - { - return CURL_SSLVERSION_MAX_TLSv1_1; - } - if (version == "1.2") { return CURL_SSLVERSION_MAX_TLSv1_2; @@ -730,7 +710,12 @@ CURLcode HttpOperation::Setup() /* 4 - TLS */ +#ifdef HAVE_TLS_VERSION + /* By default, TLSv1.2 or better is required (if we have TLS). */ + long min_ssl_version = CURL_SSLVERSION_TLSv1_2; +#else long min_ssl_version = 0; +#endif if (!ssl_options_.ssl_min_tls.empty()) { @@ -748,6 +733,11 @@ CURLcode HttpOperation::Setup() #endif } + /* + * Do not set a max TLS version by default. + * The CURL + openssl library may be more recent than this code, + * and support a version we do not know about. + */ long max_ssl_version = 0; if (!ssl_options_.ssl_max_tls.empty()) @@ -780,7 +770,7 @@ CURLcode HttpOperation::Setup() if (!ssl_options_.ssl_cipher.empty()) { - /* TLS 1.0, 1.1, 1.2 */ + /* TLS 1.2 */ const char *cipher_list = ssl_options_.ssl_cipher.c_str(); rc = SetCurlStrOption(CURLOPT_SSL_CIPHER_LIST, cipher_list); diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 9cd3585668..08b7807998 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -54,6 +54,8 @@ struct TestResult bool found_request_send_failure = false; bool found_export_error = false; bool found_export_success = false; + bool found_unknown_min_tls = false; + bool found_unknown_max_tls = false; void reset() { @@ -62,6 +64,8 @@ struct TestResult found_request_send_failure = false; found_export_error = false; found_export_success = false; + found_unknown_min_tls = false; + found_unknown_max_tls = false; } }; @@ -96,6 +100,20 @@ void parse_error_msg(TestResult *result, std::string msg) { result->found_export_error = true; } + + static std::string unknown_min_tls("Unknown min TLS version"); + + if (msg.find(unknown_min_tls) != std::string::npos) + { + result->found_unknown_min_tls = true; + } + + static std::string unknown_max_tls("Unknown max TLS version"); + + if (msg.find(unknown_max_tls) != std::string::npos) + { + result->found_unknown_max_tls = true; + } } void parse_warning_msg(TestResult * /* result */, std::string /* msg */) {} @@ -507,6 +525,24 @@ int expect_request_send_failed() return TEST_FAILED; } +int expect_unknown_min_tls() +{ + if (g_test_result.found_export_error && g_test_result.found_unknown_min_tls) + { + return TEST_PASSED; + } + return TEST_FAILED; +} + +int expect_unknown_max_tls() +{ + if (g_test_result.found_export_error && g_test_result.found_unknown_max_tls) + { + return TEST_PASSED; + } + return TEST_FAILED; +} + int expect_export_failed() { /* @@ -928,7 +964,7 @@ int test_min_tls_unknown() return expect_export_failed(); } - return expect_connection_failed(); + return expect_unknown_min_tls(); } int test_min_tls_10() @@ -963,7 +999,7 @@ int test_min_tls_10() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_min_tls_11() @@ -998,7 +1034,7 @@ int test_min_tls_11() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_min_tls_12() @@ -1098,7 +1134,7 @@ int test_max_tls_unknown() return expect_export_failed(); } - return expect_connection_failed(); + return expect_unknown_max_tls(); } int test_max_tls_10() @@ -1134,7 +1170,7 @@ int test_max_tls_10() } // No support for TLS 1.0 - return expect_connection_failed(); + return expect_unknown_max_tls(); } int test_max_tls_11() @@ -1170,7 +1206,7 @@ int test_max_tls_11() } // No support for TLS 1.1 - return expect_connection_failed(); + return expect_unknown_max_tls(); } int test_max_tls_12() @@ -1277,7 +1313,7 @@ int test_range_tls_10() } // No support for TLS 1.0 - return expect_connection_failed(); + return expect_unknown_min_tls(); } int test_range_tls_11() @@ -1314,7 +1350,7 @@ int test_range_tls_11() } // No support for TLS 1.0 - return expect_connection_failed(); + return expect_unknown_min_tls(); } int test_range_tls_12() @@ -1423,7 +1459,7 @@ int test_range_tls_10_11() } // No support for TLS 1.0, TLS 1.1 - return expect_connection_failed(); + return expect_unknown_min_tls(); } int test_range_tls_10_12() @@ -1459,7 +1495,7 @@ int test_range_tls_10_12() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_range_tls_10_13() @@ -1495,7 +1531,7 @@ int test_range_tls_10_13() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_range_tls_11_10() @@ -1563,7 +1599,7 @@ int test_range_tls_11_12() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_range_tls_11_13() @@ -1599,7 +1635,7 @@ int test_range_tls_11_13() return expect_connection_failed(); } - return expect_success(); + return expect_unknown_min_tls(); } int test_range_tls_12_10() From f6dca999b5ec011af07fb2e86cc7e9c1eaa6e80a Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 3 Jul 2024 18:04:05 +0200 Subject: [PATCH 17/71] [TEST] Fix opentelemetry-collector bind address (#2989) --- functional/otlp/otel-config-http.yaml | 1 + functional/otlp/otel-config-https.yaml | 1 + functional/otlp/otel-docker-config-http.yaml | 1 + functional/otlp/otel-docker-config-https.yaml | 1 + 4 files changed, 4 insertions(+) diff --git a/functional/otlp/otel-config-http.yaml b/functional/otlp/otel-config-http.yaml index 39c264c747..da68e6f96c 100644 --- a/functional/otlp/otel-config-http.yaml +++ b/functional/otlp/otel-config-http.yaml @@ -10,6 +10,7 @@ receivers: otlp: protocols: http: + endpoint: 0.0.0.0:4318 processors: batch: diff --git a/functional/otlp/otel-config-https.yaml b/functional/otlp/otel-config-https.yaml index 611bba828f..f106baf8b6 100644 --- a/functional/otlp/otel-config-https.yaml +++ b/functional/otlp/otel-config-https.yaml @@ -10,6 +10,7 @@ receivers: otlp: protocols: http: + endpoint: 0.0.0.0:4318 tls: ca_file: ../cert/ca.pem cert_file: ../cert/server_cert.pem diff --git a/functional/otlp/otel-docker-config-http.yaml b/functional/otlp/otel-docker-config-http.yaml index f8e5ad45d3..c18f0e54a4 100644 --- a/functional/otlp/otel-docker-config-http.yaml +++ b/functional/otlp/otel-docker-config-http.yaml @@ -9,6 +9,7 @@ receivers: otlp: protocols: http: + endpoint: 0.0.0.0:4318 processors: batch: diff --git a/functional/otlp/otel-docker-config-https.yaml b/functional/otlp/otel-docker-config-https.yaml index 9b3422bf5e..db8f2b3756 100644 --- a/functional/otlp/otel-docker-config-https.yaml +++ b/functional/otlp/otel-docker-config-https.yaml @@ -9,6 +9,7 @@ receivers: otlp: protocols: http: + endpoint: 0.0.0.0:4318 tls: ca_file: /otel-cpp/ca.pem cert_file: /otel-cpp/server_cert.pem From 0ff58e8334dc9c5b7cbf0f8088f174dd5ddbd538 Mon Sep 17 00:00:00 2001 From: Mats Taraldsvik Date: Fri, 5 Jul 2024 19:16:32 +0200 Subject: [PATCH 18/71] [EXPORTER] Fix references in AttributeValueVisitor (#2985) --- .../include/opentelemetry/exporters/ostream/common_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index ec1ee2d367..ec860794f0 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -87,7 +87,7 @@ class AttributeValueVisitor print_value(arg, sout_); } - void operator()(const nostd::string_view &&arg) { sout_.write(arg.data(), arg.size()); } + void operator()(nostd::string_view &&arg) { sout_.write(arg.data(), arg.size()); } private: std::ostream &sout_; From 6dbfdb52ebca82d8705392fe88dadd9c133374e4 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 6 Jul 2024 17:16:02 +0200 Subject: [PATCH 19/71] [Code health] include-what-you-use cleanup, part 2 (#2704) --- .github/workflows/iwyu.yml | 8 +++ api/include/opentelemetry/std/shared_ptr.h | 4 +- api/include/opentelemetry/std/span.h | 2 + api/include/opentelemetry/std/string_view.h | 2 + api/include/opentelemetry/std/type_traits.h | 2 + api/include/opentelemetry/std/unique_ptr.h | 4 +- api/include/opentelemetry/std/utility.h | 2 + api/include/opentelemetry/std/variant.h | 2 + cmake/opentelemetry-proto.cmake | 6 ++ examples/batch/main.cc | 5 +- examples/common/foo_library/foo_library.cc | 1 - .../common/logs_foo_library/foo_library.cc | 5 +- .../common/metrics_foo_library/foo_library.cc | 36 ++++++------ examples/multithreaded/main.cc | 5 +- examples/otlp/file_log_main.cc | 19 +++--- examples/otlp/file_main.cc | 13 +++-- examples/otlp/file_metric_main.cc | 25 ++++---- examples/otlp/http_log_main.cc | 18 ++++-- examples/otlp/http_main.cc | 11 +++- examples/otlp/http_metric_main.cc | 22 ++++--- examples/plugin/load/main.cc | 2 +- examples/plugin/plugin/factory_impl.cc | 1 - examples/plugin/plugin/tracer.cc | 2 - examples/plugin/plugin/tracer.h | 1 - examples/zipkin/main.cc | 9 +++ exporters/ostream/src/span_exporter.cc | 1 - .../exporters/otlp/otlp_environment.h | 12 ++-- .../exporters/otlp/otlp_file_client.h | 9 +-- .../exporters/otlp/otlp_file_exporter.h | 13 +++-- .../otlp/otlp_file_exporter_factory.h | 1 + .../otlp/otlp_file_log_record_exporter.h | 14 ++--- .../otlp_file_log_record_exporter_factory.h | 1 + .../otlp/otlp_file_metric_exporter.h | 14 ++--- .../otlp/otlp_file_metric_exporter_factory.h | 1 + .../opentelemetry/exporters/otlp/otlp_http.h | 3 +- .../exporters/otlp/otlp_http_client.h | 16 ++--- .../exporters/otlp/otlp_http_exporter.h | 17 +++--- .../otlp/otlp_http_exporter_factory.h | 1 + .../otlp/otlp_http_exporter_options.h | 8 +-- .../otlp/otlp_http_log_record_exporter.h | 15 +++-- .../otlp_http_log_record_exporter_factory.h | 5 +- .../otlp_http_log_record_exporter_options.h | 8 +-- .../otlp/otlp_http_metric_exporter.h | 14 ++--- .../otlp/otlp_http_metric_exporter_factory.h | 5 +- .../otlp/otlp_http_metric_exporter_options.h | 8 +-- .../exporters/otlp/otlp_metric_utils.h | 32 +++++++--- .../otlp/otlp_populate_attribute_utils.h | 31 ++++++++-- .../exporters/otlp/otlp_recordable.h | 22 +++++-- .../exporters/otlp/otlp_recordable_utils.h | 36 +++++++++--- exporters/otlp/src/otlp_environment.cc | 17 ++++-- exporters/otlp/src/otlp_file_client.cc | 7 +-- exporters/otlp/src/otlp_file_exporter.cc | 25 +++++--- .../otlp/src/otlp_file_log_record_exporter.cc | 24 ++++++-- .../otlp/src/otlp_file_metric_exporter.cc | 25 ++++++-- exporters/otlp/src/otlp_http_client.cc | 58 ++++++++++--------- exporters/otlp/src/otlp_http_exporter.cc | 32 +++++++--- .../otlp/src/otlp_http_exporter_options.cc | 9 +-- .../otlp/src/otlp_http_log_record_exporter.cc | 32 +++++++--- .../otlp_http_log_record_exporter_options.cc | 9 +-- .../otlp/src/otlp_http_metric_exporter.cc | 30 +++++++--- .../src/otlp_http_metric_exporter_options.cc | 10 ++-- exporters/otlp/src/otlp_log_recordable.cc | 19 ++++-- exporters/otlp/src/otlp_metric_utils.cc | 23 ++++++++ .../otlp/src/otlp_populate_attribute_utils.cc | 22 +++++++ exporters/otlp/src/otlp_recordable.cc | 30 +++++++++- exporters/otlp/src/otlp_recordable_utils.cc | 43 +++++++++----- exporters/otlp/test/otlp_recordable_test.cc | 6 ++ .../exporters/zipkin/recordable.h | 14 +++++ .../exporters/zipkin/zipkin_exporter.h | 18 +++--- .../zipkin/zipkin_exporter_factory.h | 1 + exporters/zipkin/src/recordable.cc | 27 ++++++++- exporters/zipkin/src/zipkin_exporter.cc | 21 ++++++- .../zipkin/src/zipkin_exporter_factory.cc | 2 + .../ext/http/client/curl/http_client_curl.h | 21 ++++--- ext/src/http/client/curl/http_client_curl.cc | 26 ++++++++- .../client/curl/http_client_factory_curl.cc | 2 + .../http/client/curl/http_operation_curl.cc | 21 ++++++- functional/otlp/func_http_main.cc | 19 +++++- sdk/src/logs/logger.cc | 1 - sdk/src/logs/logger_provider.cc | 2 - sdk/src/logs/readable_log_record.cc | 1 - sdk/src/metrics/meter.cc | 1 - sdk/src/metrics/meter_provider.cc | 2 - sdk/src/metrics/state/observable_registry.cc | 1 - sdk/src/trace/tracer.cc | 2 - sdk/src/trace/tracer_provider.cc | 2 - 86 files changed, 761 insertions(+), 338 deletions(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 29b8274fbd..598f57e97e 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -36,10 +36,18 @@ jobs: TOPDIR=`pwd` mkdir build && cd build CC="clang" CXX="clang++" cmake \ + -DCMAKE_CXX_STANDARD=14 \ + -DWITH_STL=CXX14 \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ -DBUILD_TESTING=OFF \ -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=OFF \ + -DWITH_OTLP_GRPC=OFF \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_FILE=ON \ + -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_ZIPKIN=ON \ + -DWITH_PROMETHEUS=OFF \ .. - name: iwyu_tool diff --git a/api/include/opentelemetry/std/shared_ptr.h b/api/include/opentelemetry/std/shared_ptr.h index b1b99bd36c..8b855b08c6 100644 --- a/api/include/opentelemetry/std/shared_ptr.h +++ b/api/include/opentelemetry/std/shared_ptr.h @@ -3,7 +3,9 @@ #pragma once -#include +// IWYU pragma: private, include "opentelemetry/nostd/shared_ptr.h" + +#include // IWYU pragma: export #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/std/span.h b/api/include/opentelemetry/std/span.h index 1160d54fbe..5d20e0227f 100644 --- a/api/include/opentelemetry/std/span.h +++ b/api/include/opentelemetry/std/span.h @@ -3,6 +3,8 @@ #pragma once +// IWYU pragma: private, include "opentelemetry/nostd/span.h" + #include "opentelemetry/version.h" // Standard library implementation requires at least C++17 compiler. diff --git a/api/include/opentelemetry/std/string_view.h b/api/include/opentelemetry/std/string_view.h index 5295eb4544..d0f0c08125 100644 --- a/api/include/opentelemetry/std/string_view.h +++ b/api/include/opentelemetry/std/string_view.h @@ -3,6 +3,8 @@ #pragma once +// IWYU pragma: private, include "opentelemetry/nostd/string_view.h" + #include #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/std/type_traits.h b/api/include/opentelemetry/std/type_traits.h index f26af95b94..074f796798 100644 --- a/api/include/opentelemetry/std/type_traits.h +++ b/api/include/opentelemetry/std/type_traits.h @@ -3,6 +3,8 @@ #pragma once +// IWYU pragma: private, include "opentelemetry/nostd/type_traits.h" + #include #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/std/unique_ptr.h b/api/include/opentelemetry/std/unique_ptr.h index 1d7d9b1fc7..4b25b7c381 100644 --- a/api/include/opentelemetry/std/unique_ptr.h +++ b/api/include/opentelemetry/std/unique_ptr.h @@ -3,7 +3,9 @@ #pragma once -#include +// IWYU pragma: private, include "opentelemetry/nostd/unique_ptr.h" + +#include // IWYU pragma: export #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/std/utility.h b/api/include/opentelemetry/std/utility.h index be0f1e5f46..d1f5614d7c 100644 --- a/api/include/opentelemetry/std/utility.h +++ b/api/include/opentelemetry/std/utility.h @@ -3,6 +3,8 @@ #pragma once +// IWYU pragma: private, include "opentelemetry/nostd/utility.h" + #include #include diff --git a/api/include/opentelemetry/std/variant.h b/api/include/opentelemetry/std/variant.h index 6acdb81e9a..58bc510c5f 100644 --- a/api/include/opentelemetry/std/variant.h +++ b/api/include/opentelemetry/std/variant.h @@ -3,6 +3,8 @@ #pragma once +// IWYU pragma: private, include "opentelemetry/nostd/variant.h" + #include "opentelemetry/version.h" #include diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 19516c3b71..62197068e2 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -326,6 +326,12 @@ add_library( ${LOGS_SERVICE_PB_CPP_FILE} ${METRICS_SERVICE_PB_CPP_FILE}) +# Disable include-what-you-use on generated code. +set_target_properties( + opentelemetry_proto + PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" +) + if(WITH_ABSEIL) target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access) endif() diff --git a/examples/batch/main.cc b/examples/batch/main.cc index 2a7fba4630..677feca424 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -5,13 +5,11 @@ #include #include #include -#include #include #include #include #include "opentelemetry/exporters/ostream/span_exporter_factory.h" -#include "opentelemetry/nostd/detail/decay.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/batch_span_processor_factory.h" @@ -30,7 +28,6 @@ namespace trace_api = opentelemetry::trace; namespace resource = opentelemetry::sdk::resource; namespace trace_sdk = opentelemetry::sdk::trace; namespace trace_exporter = opentelemetry::exporter::trace; -namespace nostd = opentelemetry::nostd; namespace { @@ -69,7 +66,7 @@ void CleanupTracer() trace_api::Provider::SetTracerProvider(none); } -nostd::shared_ptr get_tracer() +opentelemetry::nostd::shared_ptr get_tracer() { auto provider = trace_api::Provider::GetTracerProvider(); return provider->GetTracer("foo_library"); diff --git a/examples/common/foo_library/foo_library.cc b/examples/common/foo_library/foo_library.cc index e336bc5e4c..6dd7792e48 100644 --- a/examples/common/foo_library/foo_library.cc +++ b/examples/common/foo_library/foo_library.cc @@ -3,7 +3,6 @@ #include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/version/version.h" #include "opentelemetry/trace/provider.h" #include "opentelemetry/trace/scope.h" diff --git a/examples/common/logs_foo_library/foo_library.cc b/examples/common/logs_foo_library/foo_library.cc index 23402563c6..510c3956d4 100644 --- a/examples/common/logs_foo_library/foo_library.cc +++ b/examples/common/logs_foo_library/foo_library.cc @@ -16,17 +16,16 @@ namespace logs = opentelemetry::logs; namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; namespace { -nostd::shared_ptr get_tracer() +opentelemetry::nostd::shared_ptr get_tracer() { auto provider = trace::Provider::GetTracerProvider(); return provider->GetTracer("foo_library", OPENTELEMETRY_SDK_VERSION); } -nostd::shared_ptr get_logger() +opentelemetry::nostd::shared_ptr get_logger() { auto provider = logs::Provider::GetLoggerProvider(); return provider->GetLogger("foo_library_logger", "foo_library"); diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index dd5f23297b..c4be2b530f 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -17,17 +17,17 @@ #include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/observer_result.h" #include "opentelemetry/metrics/provider.h" +#include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/nostd/variant.h" -namespace nostd = opentelemetry::nostd; namespace metrics_api = opentelemetry::metrics; namespace { -static nostd::shared_ptr double_observable_counter; +static opentelemetry::nostd::shared_ptr + double_observable_counter; std::map get_random_attr() { @@ -45,13 +45,15 @@ class MeasurementFetcher public: static void Fetcher(opentelemetry::metrics::ObserverResult observer_result, void * /* state */) { - if (nostd::holds_alternative< - nostd::shared_ptr>>(observer_result)) + if (opentelemetry::nostd::holds_alternative< + opentelemetry::nostd::shared_ptr>>( + observer_result)) { double random_incr = (rand() % 5) + 1.1; value_ += random_incr; std::map labels = get_random_attr(); - nostd::get>>( + opentelemetry::nostd::get< + opentelemetry::nostd::shared_ptr>>( observer_result) ->Observe(value_, labels); } @@ -63,10 +65,10 @@ double MeasurementFetcher::value_ = 0.0; void foo_library::counter_example(const std::string &name) { - std::string counter_name = name + "_counter"; - auto provider = metrics_api::Provider::GetMeterProvider(); - nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); - auto double_counter = meter->CreateDoubleCounter(counter_name); + std::string counter_name = name + "_counter"; + auto provider = metrics_api::Provider::GetMeterProvider(); + opentelemetry::nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); + auto double_counter = meter->CreateDoubleCounter(counter_name); for (uint32_t i = 0; i < 20; ++i) { @@ -78,10 +80,10 @@ void foo_library::counter_example(const std::string &name) void foo_library::observable_counter_example(const std::string &name) { - std::string counter_name = name + "_observable_counter"; - auto provider = metrics_api::Provider::GetMeterProvider(); - nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); - double_observable_counter = meter->CreateDoubleObservableCounter(counter_name); + std::string counter_name = name + "_observable_counter"; + auto provider = metrics_api::Provider::GetMeterProvider(); + opentelemetry::nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); + double_observable_counter = meter->CreateDoubleObservableCounter(counter_name); double_observable_counter->AddCallback(MeasurementFetcher::Fetcher, nullptr); for (uint32_t i = 0; i < 20; ++i) { @@ -91,9 +93,9 @@ void foo_library::observable_counter_example(const std::string &name) void foo_library::histogram_example(const std::string &name) { - std::string histogram_name = name + "_histogram"; - auto provider = metrics_api::Provider::GetMeterProvider(); - nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); + std::string histogram_name = name + "_histogram"; + auto provider = metrics_api::Provider::GetMeterProvider(); + opentelemetry::nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); auto histogram_counter = meter->CreateDoubleHistogram(histogram_name, "des", "unit"); auto context = opentelemetry::context::Context{}; for (uint32_t i = 0; i < 20; ++i) diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 9dd76647c5..d92a4ab2ac 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include #include #include "opentelemetry/exporters/ostream/span_exporter_factory.h" -#include "opentelemetry/nostd/detail/decay.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/processor.h" @@ -25,7 +23,6 @@ namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; -namespace nostd = opentelemetry::nostd; namespace { @@ -46,7 +43,7 @@ void CleanupTracer() trace_api::Provider::SetTracerProvider(none); } -nostd::shared_ptr get_tracer() +opentelemetry::nostd::shared_ptr get_tracer() { auto provider = trace_api::Provider::GetTracerProvider(); return provider->GetTracer("foo_library"); diff --git a/examples/otlp/file_log_main.cc b/examples/otlp/file_log_main.cc index 9254c9947f..30eb71cc2b 100644 --- a/examples/otlp/file_log_main.cc +++ b/examples/otlp/file_log_main.cc @@ -1,27 +1,32 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + #include "opentelemetry/exporters/otlp/otlp_file_client_options.h" #include "opentelemetry/exporters/otlp/otlp_file_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" -#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" -#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" -#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include -#include -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/logs_foo_library/foo_library.h" diff --git a/examples/otlp/file_main.cc b/examples/otlp/file_main.cc index 13db0e4ad1..243ad44428 100644 --- a/examples/otlp/file_main.cc +++ b/examples/otlp/file_main.cc @@ -1,16 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_file_client_options.h" #include "opentelemetry/exporters/otlp/otlp_file_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include -#include -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/foo_library/foo_library.h" diff --git a/examples/otlp/file_metric_main.cc b/examples/otlp/file_metric_main.cc index b99d77a609..ce259005be 100644 --- a/examples/otlp/file_metric_main.cc +++ b/examples/otlp/file_metric_main.cc @@ -1,21 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/exporters/otlp/otlp_file_client_options.h" #include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h" +#include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/provider.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" -#include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/meter_context_factory.h" -#include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/meter_provider_factory.h" - -#include -#include -#include -#include -#include +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" #ifdef BAZEL_BUILD # include "examples/common/metrics_foo_library/foo_library.h" diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index e2b219de1c..38aa009d04 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -1,23 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" -#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/logs_foo_library/foo_library.h" diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index 9ad476bd47..6217bdcb34 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -1,16 +1,23 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/foo_library/foo_library.h" diff --git a/examples/otlp/http_metric_main.cc b/examples/otlp/http_metric_main.cc index f33d57772f..53f5fe38bc 100644 --- a/examples/otlp/http_metric_main.cc +++ b/examples/otlp/http_metric_main.cc @@ -1,20 +1,28 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" +#include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/provider.h" #include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" #include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" -#include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/meter_context_factory.h" -#include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/meter_provider_factory.h" - -#include -#include +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" #ifdef BAZEL_BUILD # include "examples/common/metrics_foo_library/foo_library.h" diff --git a/examples/plugin/load/main.cc b/examples/plugin/load/main.cc index 589f70c2af..81d5221372 100644 --- a/examples/plugin/load/main.cc +++ b/examples/plugin/load/main.cc @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/examples/plugin/plugin/factory_impl.cc b/examples/plugin/plugin/factory_impl.cc index 4d74bd6062..6eaa4aa4f1 100644 --- a/examples/plugin/plugin/factory_impl.cc +++ b/examples/plugin/plugin/factory_impl.cc @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include #include #include diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index faf3f036e5..5361197584 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -10,7 +9,6 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/context/context_value.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" #include "tracer.h" diff --git a/examples/plugin/plugin/tracer.h b/examples/plugin/plugin/tracer.h index bb933d3d9b..92012fa4a5 100644 --- a/examples/plugin/plugin/tracer.h +++ b/examples/plugin/plugin/tracer.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/shared_ptr.h" diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 0052cd430e..ac9e454580 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -1,12 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include + #include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer_provider.h" #ifdef BAZEL_BUILD # include "examples/common/foo_library/foo_library.h" diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index d3f5093b40..9437ae561a 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h index 8b486a548f..74a222a9d0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h @@ -3,18 +3,14 @@ #pragma once -#include "opentelemetry/common/kv_properties.h" -#include "opentelemetry/nostd/string_view.h" - -#include "opentelemetry/sdk/common/attribute_utils.h" -#include "opentelemetry/sdk/common/env_variables.h" -#include "opentelemetry/sdk/version/version.h" - +#include #include #include #include #include -#include + +#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client.h index bedbe77e52..e377b140b6 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client.h @@ -3,12 +3,13 @@ #pragma once -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/exporter_utils.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_file_client_options.h" - -#include +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/version.h" // forward declare google::protobuf::Message namespace google diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter.h index b5b87f9f88..b49dcef77f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter.h @@ -3,15 +3,16 @@ #pragma once -// We need include exporter.h first, which will include Windows.h with NOMINMAX on Windows -#include "opentelemetry/sdk/trace/exporter.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_file_client.h" - #include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h" - -#include -#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter_factory.h index dc68609729..bf4ba3288f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_exporter_factory.h @@ -7,6 +7,7 @@ #include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h index 79d816ae53..6fb9f6d844 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h @@ -3,16 +3,16 @@ #pragma once -#include "opentelemetry/sdk/logs/exporter.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_file_client.h" - #include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h" - -#include -#include -#include -#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h index 0e6c0143b9..663eeb189a 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h @@ -7,6 +7,7 @@ #include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter.h index 165c7de99a..e03e544de9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter.h @@ -3,16 +3,16 @@ #pragma once -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_file_client.h" - #include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h" - -#include -#include -#include -#include +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h index 483e4aa5aa..a34c057fad 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h @@ -7,6 +7,7 @@ #include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http.h index 7d1e7bac55..6899c6f544 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http.h @@ -3,9 +3,8 @@ #pragma once -#include "opentelemetry/common/macros.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h index 9d79b5d99b..6806f1cdf9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h @@ -3,14 +3,6 @@ #pragma once -#include "opentelemetry/ext/http/client/http_client.h" -#include "opentelemetry/nostd/variant.h" -#include "opentelemetry/sdk/common/exporter_utils.h" - -#include "opentelemetry/exporters/otlp/otlp_environment.h" -#include "opentelemetry/exporters/otlp/otlp_http.h" - -#include #include #include #include @@ -21,6 +13,14 @@ #include #include +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/version.h" + // forward declare google::protobuf::Message namespace google { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h index b5faf1a9b8..38f1d9e306 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -3,19 +3,16 @@ #pragma once -// We need include exporter.h first, which will include Windows.h with NOMINMAX on Windows -#include "opentelemetry/sdk/trace/exporter.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_http_client.h" - -#include "opentelemetry/exporters/otlp/otlp_environment.h" - #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" - -#include -#include -#include -#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h index 5316528365..9e072a0534 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h @@ -7,6 +7,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h index 1be4bd8d95..7f6d5a1b35 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h @@ -3,15 +3,13 @@ #pragma once +#include +#include + #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/version.h" -#include -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h index f481fdab0b..9439e5725b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h @@ -3,17 +3,16 @@ #pragma once -#include "opentelemetry/sdk/logs/exporter.h" +#include +#include #include "opentelemetry/exporters/otlp/otlp_http_client.h" - -#include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" - -#include -#include -#include -#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h index f4c90d5b0c..c1e9de9ae1 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h @@ -3,10 +3,11 @@ #pragma once +#include + #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h index 7d60a28cf0..60f674a3a7 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h @@ -3,15 +3,13 @@ #pragma once +#include +#include + #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/version.h" -#include -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h index 0aebf79760..d74177e5c9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h @@ -3,16 +3,16 @@ #pragma once -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include +#include -#include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" - -#include -#include -#include -#include +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h index 7fa7980470..a290d91fd0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h @@ -3,10 +3,11 @@ #pragma once +#include + #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h index d5cf3072f8..82c91aa51f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h @@ -3,16 +3,14 @@ #pragma once +#include +#include + #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" #include "opentelemetry/version.h" -#include -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h index c6e11aeff3..4f92b8e665 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h @@ -3,16 +3,34 @@ #pragma once -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" -#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "opentelemetry/proto/metrics/v1/metrics.pb.h" -#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on -#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/metrics/export/metric_producer.h" +namespace opentelemetry +{ +namespace proto +{ +namespace collector +{ +namespace metrics +{ +namespace v1 +{ +class ExportMetricsServiceRequest; +} +} // namespace metrics +} // namespace collector +} // namespace proto +} // namespace opentelemetry OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h index dc43827641..499aa3685f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h @@ -3,18 +3,37 @@ #pragma once -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -#include "opentelemetry/proto/resource/v1/resource.pb.h" -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -// clang-format on - #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" +namespace opentelemetry +{ +namespace proto +{ + +namespace common +{ +namespace v1 +{ +class AnyValue; +class KeyValue; +} // namespace v1 +} // namespace common + +namespace resource +{ +namespace v1 +{ +class Resource; +} +} // namespace resource + +} // namespace proto +} // namespace opentelemetry + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index 88e7cd91cf..103357d11f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -3,14 +3,28 @@ #pragma once -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include +#include +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/common/v1/common.pb.h" #include "opentelemetry/proto/resource/v1/resource.pb.h" #include "opentelemetry/proto/trace/v1/trace.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h index 74a4cd9aeb..0651abc2b9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h @@ -5,18 +5,36 @@ #include -#include "opentelemetry/nostd/unique_ptr.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" -#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +namespace opentelemetry +{ +namespace proto +{ +namespace collector +{ -#include "opentelemetry/sdk/trace/recordable.h" +namespace logs +{ +namespace v1 +{ +class ExportLogsServiceRequest; +} +} // namespace logs +namespace trace +{ +namespace v1 +{ +class ExportTraceServiceRequest; +} +} // namespace trace -#include "opentelemetry/sdk/logs/recordable.h" +} // namespace collector +} // namespace proto +} // namespace opentelemetry OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_environment.cc b/exporters/otlp/src/otlp_environment.cc index a7af30bb73..276d9fc709 100644 --- a/exporters/otlp/src/otlp_environment.cc +++ b/exporters/otlp/src/otlp_environment.cc @@ -1,15 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/kv_properties.h" #include "opentelemetry/exporters/otlp/otlp_environment.h" - +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/env_variables.h" -#include "opentelemetry/sdk/version/version.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/version.h" -namespace nostd = opentelemetry::nostd; namespace sdk_common = opentelemetry::sdk::common; /* diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index 9678b22476..bd36a602c4 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -10,7 +10,7 @@ #endif // clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep // clang-format on #include "google/protobuf/message.h" @@ -19,15 +19,14 @@ #include "nlohmann/json.hpp" // clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep // clang-format on -#include "opentelemetry/common/macros.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/base64.h" #include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/version.h" #include #include diff --git a/exporters/otlp/src/otlp_file_exporter.cc b/exporters/otlp/src/otlp_file_exporter.cc index 816151719a..b98a6b2007 100644 --- a/exporters/otlp/src/otlp_file_exporter.cc +++ b/exporters/otlp/src/otlp_file_exporter.cc @@ -1,19 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_file_exporter.h" +#include +#include +#include +#include +#include + #include "opentelemetry/exporters/otlp/otlp_file_client.h" +#include "opentelemetry/exporters/otlp/otlp_file_client_options.h" +#include "opentelemetry/exporters/otlp/otlp_file_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_file_log_record_exporter.cc b/exporters/otlp/src/otlp_file_log_record_exporter.cc index 49cbfd3ab2..7df1c70b29 100644 --- a/exporters/otlp/src/otlp_file_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_file_log_record_exporter.cc @@ -1,18 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_file_client.h" +#include "opentelemetry/exporters/otlp/otlp_file_client_options.h" #include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_file_metric_exporter.cc b/exporters/otlp/src/otlp_file_metric_exporter.cc index 2c414c31b4..78aea66956 100644 --- a/exporters/otlp/src/otlp_file_metric_exporter.cc +++ b/exporters/otlp/src/otlp_file_metric_exporter.cc @@ -1,17 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_file_client.h" +#include "opentelemetry/exporters/otlp/otlp_file_client_options.h" #include "opentelemetry/exporters/otlp/otlp_file_metric_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 8bada1e0e0..03eb5fb434 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -1,7 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_client.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #if defined(HAVE_GSL) # include @@ -9,42 +24,33 @@ # include #endif -#include "opentelemetry/ext/http/client/http_client_factory.h" -#include "opentelemetry/ext/http/common/url_parser.h" - -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -// clang-format on - -#include "google/protobuf/message.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/stubs/common.h" #include "nlohmann/json.hpp" - -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -// clang-format on - #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/ext/http/common/url_parser.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/base64.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/version.h" -#include -#include -#include -#include -#include -#include -#include -#include +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include +#include +#include +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on #ifdef GetMessage # undef GetMessage #endif -namespace nostd = opentelemetry::nostd; namespace http_client = opentelemetry::ext::http::client; OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index aa00c3f79a..f740a0babf 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -1,20 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" - -namespace nostd = opentelemetry::nostd; +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -78,7 +91,8 @@ std::unique_ptr OtlpHttpExporter::MakeRec } opentelemetry::sdk::common::ExportResult OtlpHttpExporter::Export( - const nostd::span> &spans) noexcept + const opentelemetry::nostd::span> + &spans) noexcept { if (http_client_->IsShutdown()) { diff --git a/exporters/otlp/src/otlp_http_exporter_options.cc b/exporters/otlp/src/otlp_http_exporter_options.cc index d88b8d2e3d..753efcb481 100644 --- a/exporters/otlp/src/otlp_http_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -1,13 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" - #include -#include -#include #include +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index 0d08c66a79..bd76bd10bd 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -1,20 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" - -namespace nostd = opentelemetry::nostd; +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -82,7 +95,8 @@ OtlpHttpLogRecordExporter::MakeRecordable() noexcept } opentelemetry::sdk::common::ExportResult OtlpHttpLogRecordExporter::Export( - const nostd::span> &logs) noexcept + const opentelemetry::nostd::span> + &logs) noexcept { if (http_client_->IsShutdown()) { diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc index cf2227a8d5..08a04cfa80 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc @@ -1,13 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" - #include -#include -#include #include +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index 1782bb6acb..18b4ed0712 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -1,19 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -#include "opentelemetry/sdk/common/global_log_handler.h" - -namespace nostd = opentelemetry::nostd; +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_http_metric_exporter_options.cc b/exporters/otlp/src/otlp_http_metric_exporter_options.cc index 7e2c145639..66d65fa54b 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_options.cc @@ -1,13 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" - #include -#include -#include #include +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/otlp/src/otlp_log_recordable.cc b/exporters/otlp/src/otlp_log_recordable.cc index 8acb4073d2..03c89626f2 100644 --- a/exporters/otlp/src/otlp_log_recordable.cc +++ b/exporters/otlp/src/otlp_log_recordable.cc @@ -1,14 +1,23 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/common/macros.h" +#include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" -#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/readable_log_record.h" - -namespace nostd = opentelemetry::nostd; +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -216,7 +225,7 @@ void OtlpLogRecordable::SetTraceFlags(const opentelemetry::trace::TraceFlags &tr proto_record_.set_flags(trace_flags.flags()); } -void OtlpLogRecordable::SetAttribute(nostd::string_view key, +void OtlpLogRecordable::SetAttribute(opentelemetry::nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept { OtlpPopulateAttributeUtils::PopulateAttribute(proto_record_.add_attributes(), key, value); diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index e75b17ddd7..da162d117e 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -1,9 +1,32 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/metrics/v1/metrics.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/otlp/src/otlp_populate_attribute_utils.cc b/exporters/otlp/src/otlp_populate_attribute_utils.cc index 69a284835a..a2ef2edafa 100644 --- a/exporters/otlp/src/otlp_populate_attribute_utils.cc +++ b/exporters/otlp/src/otlp_populate_attribute_utils.cc @@ -1,7 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on namespace nostd = opentelemetry::nostd; diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index f9cee24677..356472fb48 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -1,10 +1,36 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include +#include +#include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" -#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on namespace nostd = opentelemetry::nostd; diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 59e4aadf4e..df29cca838 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -1,23 +1,36 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -#include "opentelemetry/proto/logs/v1/logs.pb.h" -#include "opentelemetry/proto/trace/v1/trace.pb.h" - -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include +#include +#include +#include +#include +#include +#include #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" #include "opentelemetry/exporters/otlp/otlp_recordable.h" - -#include -#include - -namespace nostd = opentelemetry::nostd; +#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -48,7 +61,7 @@ struct InstrumentationScopePointerEqual } // namespace void OtlpRecordableUtils::PopulateRequest( - const nostd::span> &spans, + const opentelemetry::nostd::span> &spans, proto::collector::trace::v1::ExportTraceServiceRequest *request) noexcept { if (nullptr == request) @@ -108,7 +121,7 @@ void OtlpRecordableUtils::PopulateRequest( } void OtlpRecordableUtils::PopulateRequest( - const nostd::span> &logs, + const opentelemetry::nostd::span> &logs, proto::collector::logs::v1::ExportLogsServiceRequest *request) noexcept { if (nullptr == request) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 9f3ba62b16..caa17c8a46 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -13,6 +13,12 @@ #include +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h index 09955711e3..0331178f2a 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h @@ -3,8 +3,22 @@ #pragma once +#include +#include + #include "nlohmann/json.hpp" + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index effa2dfe75..19e7af9cf6 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -3,16 +3,20 @@ #pragma once -#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" -#include "opentelemetry/ext/http/client/http_client_factory.h" -#include "opentelemetry/ext/http/common/url_parser.h" -#include "opentelemetry/sdk/common/env_variables.h" -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/span_data.h" +#include +#include +#include #include "nlohmann/json.hpp" -#include +#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/common/url_parser.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h index 3f84c6041b..b1564a7977 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h @@ -7,6 +7,7 @@ #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index ed43cb8a2d..69899e7fad 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -1,12 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include + +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/exporters/zipkin/recordable.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/resource/semantic_conventions.h" - -#include -#include +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index a8a97b58af..e6d3ce8b26 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -2,12 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 #define _WINSOCKAPI_ // stops including winsock.h -#include "opentelemetry/exporters/zipkin/zipkin_exporter.h" -#include + +#include +#include +#include +#include +#include +#include + +#include "nlohmann/json.hpp" + #include "opentelemetry/exporters/zipkin/recordable.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/ext/http/common/url_parser.h" -#include "opentelemetry/sdk_config.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" namespace http_client = opentelemetry::ext::http::client; diff --git a/exporters/zipkin/src/zipkin_exporter_factory.cc b/exporters/zipkin/src/zipkin_exporter_factory.cc index 5003dbb0a0..edacb79842 100644 --- a/exporters/zipkin/src/zipkin_exporter_factory.cc +++ b/exporters/zipkin/src/zipkin_exporter_factory.cc @@ -4,6 +4,8 @@ #include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" #include "opentelemetry/exporters/zipkin/zipkin_exporter.h" #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/version.h" namespace http_client = opentelemetry::ext::http::client; diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h index 63702be09a..902981f392 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h @@ -3,20 +3,27 @@ #pragma once -#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" -#include "opentelemetry/ext/http/client/http_client.h" -#include "opentelemetry/ext/http/common/url_parser.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/version.h" - +#include #include +#include +#include +#include #include +#include +#include #include #include #include #include #include -#include +#include + +#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 11c1435b1f..38ca2e7348 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -1,15 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "opentelemetry/ext/http/client/curl/http_client_curl.h" -#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/common/url_parser.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" #ifdef ENABLE_OTLP_COMPRESSION_PREVIEW # include +#else +# include "opentelemetry/sdk/common/global_log_handler.h" #endif -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace ext { diff --git a/ext/src/http/client/curl/http_client_factory_curl.cc b/ext/src/http/client/curl/http_client_factory_curl.cc index f6266c2931..fd0a7d6a81 100644 --- a/ext/src/http/client/curl/http_client_factory_curl.cc +++ b/ext/src/http/client/curl/http_client_factory_curl.cc @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include + #include "opentelemetry/ext/http/client/curl/http_client_curl.h" #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index fe06384414..f82c17ccc5 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -1,12 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include #include - -#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "opentelemetry/ext/http/client/curl/http_client_curl.h" +#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/version.h" // CURL_VERSION_BITS was added in CURL 7.43.0 #ifndef CURL_VERSION_BITS diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 08b7807998..4f6c144a43 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -1,16 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" - -#include -#include +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index d3555ba4ec..e9935c5107 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index c3b1fb7dd4..1eaa0d186e 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -12,7 +11,6 @@ #include "opentelemetry/logs/logger.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/logger.h" diff --git a/sdk/src/logs/readable_log_record.cc b/sdk/src/logs/readable_log_record.cc index 4c8d119347..8d35c1eb2e 100644 --- a/sdk/src/logs/readable_log_record.cc +++ b/sdk/src/logs/readable_log_record.cc @@ -7,7 +7,6 @@ #include "opentelemetry/logs/severity.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/readable_log_record.h" #include "opentelemetry/sdk/resource/resource.h" diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index f472ac726e..8b4413113b 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 959ff32800..6ddba6aa7c 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -2,9 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include -#include #include #include "opentelemetry/common/key_value_iterable.h" diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 4da46ddfe3..8db11d4605 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index f23ce5f628..fd02548c7b 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -12,7 +11,6 @@ #include "opentelemetry/context/context.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/trace/id_generator.h" diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 7421e07de4..9440e3d469 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -3,9 +3,7 @@ #include #include -#include #include -#include #include #include From eb2b9753ea2df64079e07d40489388ea1b323108 Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Thu, 11 Jul 2024 05:45:17 -0400 Subject: [PATCH 20/71] [Code Health] clang-tidy cleanup, part 1 (#2990) --- .clang-tidy | 69 ++++ api/test/baggage/baggage_benchmark.cc | 2 +- api/test/baggage/baggage_test.cc | 2 +- .../propagation/baggage_propagator_test.cc | 2 +- api/test/common/kv_properties_test.cc | 2 +- api/test/context/context_test.cc | 6 +- api/test/context/runtime_context_test.cc | 2 + api/test/logs/logger_benchmark.cc | 10 +- api/test/logs/logger_test.cc | 1 - api/test/metrics/meter_provider_test.cc | 1 - api/test/nostd/shared_ptr_test.cc | 10 +- api/test/nostd/unique_ptr_test.cc | 12 +- api/test/trace/trace_state_test.cc | 4 +- examples/etw_threads/main.cc | 2 +- examples/grpc/client.cc | 7 +- examples/grpc/server.cc | 9 +- examples/logs_simple/main.cc | 4 +- examples/multi_processor/main.cc | 18 +- examples/multithreaded/main.cc | 1 + examples/otlp/http_log_main.cc | 4 +- examples/simple/main.cc | 2 +- .../elasticsearch/es_log_recordable.h | 6 +- .../elasticsearch/src/es_log_recordable.cc | 6 +- .../memory/test/in_memory_span_data_test.cc | 1 - .../exporters/ostream/log_record_exporter.h | 4 +- .../exporters/ostream/metric_exporter.h | 2 +- .../exporters/ostream/span_exporter.h | 2 +- exporters/ostream/src/log_record_exporter.cc | 10 +- exporters/ostream/src/metric_exporter.cc | 2 +- exporters/ostream/src/span_exporter.cc | 8 +- exporters/ostream/test/ostream_log_test.cc | 60 ++- exporters/ostream/test/ostream_span_test.cc | 2 +- exporters/otlp/src/otlp_file_client.cc | 9 +- exporters/otlp/src/otlp_grpc_client.cc | 6 +- exporters/otlp/src/otlp_http_client.cc | 10 +- .../otlp/test/otlp_http_exporter_test.cc | 215 ++++++----- .../otlp_http_log_record_exporter_test.cc | 363 +++++++++--------- .../test/otlp_http_metric_exporter_test.cc | 265 ++++++------- .../test/otlp_metrics_serialization_test.cc | 6 +- exporters/otlp/test/otlp_recordable_test.cc | 6 +- exporters/prometheus/src/exporter_utils.cc | 4 +- exporters/prometheus/test/exporter_test.cc | 1 - .../prometheus/test/exporter_utils_test.cc | 7 +- exporters/zipkin/src/zipkin_exporter.cc | 2 +- exporters/zipkin/test/zipkin_exporter_test.cc | 3 +- .../http/client/curl/http_operation_curl.h | 3 +- ext/src/dll/dllmain.cc | 2 +- ext/src/http/client/curl/http_client_curl.cc | 2 +- .../http/client/curl/http_operation_curl.cc | 8 +- ext/test/http/curl_http_test.cc | 5 +- ext/test/w3c_tracecontext_test/main.cc | 6 +- functional/otlp/func_http_main.cc | 24 +- .../opentelemetry/sdk/logs/logger_context.h | 2 +- .../opentelemetry/sdk/logs/logger_provider.h | 4 +- .../opentelemetry/sdk/metrics/meter_context.h | 4 +- .../sdk/metrics/meter_provider.h | 4 +- .../metrics/state/temporal_metric_storage.h | 2 +- .../sdk/metrics/sync_instruments.h | 12 +- .../opentelemetry/sdk/trace/samplers/parent.h | 2 +- .../sdk/trace/samplers/parent_factory.h | 2 +- .../opentelemetry/sdk/trace/tracer_context.h | 2 +- .../opentelemetry/sdk/trace/tracer_provider.h | 4 +- sdk/src/common/global_log_handler.cc | 2 +- sdk/src/logs/event_logger.cc | 2 +- sdk/src/logs/logger.cc | 2 +- sdk/src/logs/logger_context.cc | 2 +- sdk/src/logs/logger_provider.cc | 4 +- sdk/src/metrics/async_instruments.cc | 4 +- sdk/src/metrics/exemplar/reservoir.cc | 10 +- sdk/src/metrics/meter.cc | 4 +- sdk/src/metrics/meter_context.cc | 6 +- sdk/src/metrics/meter_provider.cc | 4 +- sdk/src/metrics/state/metric_collector.cc | 4 +- .../metrics/state/temporal_metric_storage.cc | 4 +- sdk/src/metrics/sync_instruments.cc | 12 +- sdk/src/metrics/view/view_factory.cc | 5 +- sdk/src/trace/batch_span_processor.cc | 1 - sdk/src/trace/samplers/parent.cc | 2 +- sdk/src/trace/samplers/parent_factory.cc | 8 +- sdk/src/trace/span.cc | 2 +- sdk/src/trace/tracer.cc | 2 +- sdk/src/trace/tracer_context.cc | 2 +- sdk/src/trace/tracer_provider.cc | 4 +- sdk/test/common/empty_attributes_test.cc | 2 +- .../logs/batch_log_record_processor_test.cc | 12 +- sdk/test/logs/logger_sdk_test.cc | 3 +- .../logs/simple_log_record_processor_test.cc | 3 +- sdk/test/metrics/async_instruments_test.cc | 1 + sdk/test/metrics/async_metric_storage_test.cc | 4 +- sdk/test/metrics/cardinality_limit_test.cc | 4 +- .../instrument_metadata_validator_test.cc | 6 +- sdk/test/metrics/meter_test.cc | 2 +- ...ync_metric_storage_up_down_counter_test.cc | 12 +- sdk/test/resource/resource_test.cc | 11 +- sdk/test/trace/batch_span_processor_test.cc | 11 +- sdk/test/trace/span_data_test.cc | 4 +- sdk/test/trace/tracer_test.cc | 1 - 97 files changed, 759 insertions(+), 661 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..5abedb62fd --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,69 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +Checks: > + -*, + abseil-*, + -abseil-string-find-str-contains, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-inc-dec-in-conditions, + -bugprone-narrowing-conversions, + -bugprone-unchecked-optional-access, + -bugprone-unhandled-exception-at-new, + -bugprone-unused-local-non-trivial-variable, + -bugprone-unused-return-value, + google-*, + -google-build-using-namespace, + -google-default-arguments, + -google-explicit-constructor, + -google-readability-avoid-underscore-in-googletest-name, + -google-readability-braces-around-statements, + -google-readability-namespace-comments, + -google-readability-todo, + -google-runtime-references, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-non-private-member-variables-in-classes, + -misc-unused-alias-decls, + -misc-use-anonymous-namespace, + performance-*, + -performance-move-const-arg, + portability-* +# readability-*, +# -readability-convert-member-functions-to-static, +# -readability-else-after-return, +# -readability-function-cognitive-complexity, +# -readability-identifier-length, +# -readability-implicit-bool-conversion, +# -readability-isolate-declaration, +# -readability-magic-numbers, +# -readability-named-parameter, +# -readability-redundant-*, +# -readability-string-compare, +# cppcoreguidelines-*, +# -cppcoreguidelines-avoid-c-arrays, +# -cppcoreguidelines-avoid-magic-numbers, +# -cppcoreguidelines-init-variables, +# -cppcoreguidelines-macro-usage, +# -cppcoreguidelines-non-private-member-variables-in-classes, +# -cppcoreguidelines-pro-*, +# modernize-*, +# -modernize-use-default-member-init, +# -modernize-use-nodiscard, +# -modernize-use-trailing-return-type, +# -modernize-avoid-c-arrays, +# -modernize-use-using + +# Use existing clang-format for formatting the code +# FormatStyle: 'file' + +# TODO: include checks: readability, cppcoreguidelines, modernize , google-readability-namespace-comments, google-readability-avoid-underscore-in-googletest-name, performance-move-const-arg + + + + + + diff --git a/api/test/baggage/baggage_benchmark.cc b/api/test/baggage/baggage_benchmark.cc index 0f2efa9939..4ced142327 100644 --- a/api/test/baggage/baggage_benchmark.cc +++ b/api/test/baggage/baggage_benchmark.cc @@ -22,7 +22,7 @@ std::string header_with_custom_entries(size_t num_entries) { std::string key = "ADecentlyLargekey" + std::to_string(i); std::string value = "ADecentlyLargeValue" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != num_entries - 1) { header += ","; diff --git a/api/test/baggage/baggage_test.cc b/api/test/baggage/baggage_test.cc index 9c14fc892f..f29615c983 100644 --- a/api/test/baggage/baggage_test.cc +++ b/api/test/baggage/baggage_test.cc @@ -19,7 +19,7 @@ std::string header_with_custom_entries(size_t num_entries) { std::string key = "key" + std::to_string(i); std::string value = "value" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != num_entries - 1) { header += ","; diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index 94fe8b005b..83de75757b 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -62,7 +62,7 @@ TEST(BaggagePropagatorTest, ExtractAndInjectBaggage) {"invalid_header", ""}, // invalid header {very_large_baggage_header, ""}}; // baggage header larger than allowed size. - for (auto baggage : baggages) + for (const auto &baggage : baggages) { BaggageCarrierTest carrier1; carrier1.headers_[baggage::kBaggageHeader.data()] = baggage.first; diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index e5d9a2439e..f616664265 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -31,7 +31,7 @@ TEST(EntryTest, KeyValueConstruction) TEST(EntryTest, Copy) { KeyValueProperties::Entry e("test_key", "test_value"); - KeyValueProperties::Entry copy(e); + const KeyValueProperties::Entry ©(e); EXPECT_EQ(copy.GetKey(), e.GetKey()); EXPECT_EQ(copy.GetValue(), e.GetValue()); } diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 764dac6477..294f1cd180 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -105,8 +105,8 @@ TEST(ContextTest, ContextCopyOperator) {"foo_key", static_cast(456)}, {"other_key", static_cast(789)}}; - context::Context test_context = context::Context(test_map); - context::Context copied_context = test_context; + context::Context test_context = context::Context(test_map); + const context::Context &copied_context = test_context; EXPECT_EQ(nostd::get(copied_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(copied_context.GetValue("foo_key")), 456); @@ -135,7 +135,7 @@ TEST(ContextTest, ContextCopyCompare) { std::map map_test = {{"test_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); - context::Context copied_test = context_test; + const context::Context &copied_test = context_test; EXPECT_TRUE(context_test == copied_test); } diff --git a/api/test/context/runtime_context_test.cc b/api/test/context/runtime_context_test.cc index c2ec732fe0..cd551c599c 100644 --- a/api/test/context/runtime_context_test.cc +++ b/api/test/context/runtime_context_test.cc @@ -113,6 +113,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder) indices.push_back(3); std::vector contexts; + contexts.reserve(indices.size()); for (auto i : indices) { contexts.push_back(context::Context("index", static_cast(i))); @@ -122,6 +123,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder) { std::vector> tokens; + tokens.reserve(contexts.size()); for (auto &c : contexts) { tokens.push_back(context::RuntimeContext::Attach(c)); diff --git a/api/test/logs/logger_benchmark.cc b/api/test/logs/logger_benchmark.cc index 098b9c7df8..db225d496a 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -16,13 +16,8 @@ #include using opentelemetry::logs::EventId; -using opentelemetry::logs::Logger; -using opentelemetry::logs::LoggerProvider; using opentelemetry::logs::Provider; using opentelemetry::logs::Severity; -using opentelemetry::nostd::shared_ptr; -using opentelemetry::nostd::span; -using opentelemetry::nostd::string_view; namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; @@ -66,7 +61,7 @@ class Barrier static void ThreadRoutine(Barrier &barrier, benchmark::State &state, int thread_id, - std::function func) + const std::function &func) { barrier.Wait(); @@ -87,7 +82,7 @@ static void ThreadRoutine(Barrier &barrier, barrier.Wait(); } -void MultiThreadRunner(benchmark::State &state, std::function func) +void MultiThreadRunner(benchmark::State &state, const std::function &func) { int num_threads = std::thread::hardware_concurrency(); @@ -95,6 +90,7 @@ void MultiThreadRunner(benchmark::State &state, std::function func) std::vector threads; + threads.reserve(num_threads); for (int i = 0; i < num_threads; i++) { threads.emplace_back(ThreadRoutine, std::ref(barrier), std::ref(state), i, func); diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 43d7afc685..848f053453 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -16,7 +16,6 @@ using opentelemetry::logs::LoggerProvider; using opentelemetry::logs::Provider; using opentelemetry::logs::Severity; using opentelemetry::nostd::shared_ptr; -using opentelemetry::nostd::span; using opentelemetry::nostd::string_view; namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index 878c5e9a3b..b8fb083799 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -6,7 +6,6 @@ #include "opentelemetry/metrics/provider.h" #include "opentelemetry/nostd/shared_ptr.h" -using opentelemetry::metrics::Meter; using opentelemetry::metrics::MeterProvider; using opentelemetry::metrics::NoopMeterProvider; using opentelemetry::metrics::Provider; diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 0c79c7efd2..5c290c6284 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -63,7 +63,7 @@ TEST(SharedPtrTest, MoveConstruction) auto value = new int{123}; shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -72,7 +72,7 @@ TEST(SharedPtrTest, MoveConstructionFromDifferentType) auto value = new int{123}; shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -81,14 +81,14 @@ TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr) auto value = new int{123}; std::shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } TEST(SharedPtrTest, Destruction) { bool was_destructed; - shared_ptr{new A{was_destructed}}; + shared_ptr{new A{was_destructed}}; // NOLINT EXPECT_TRUE(was_destructed); } @@ -173,7 +173,7 @@ static void SharedPtrTest_Sort(size_t size = 10) auto nums2 = nums; std::sort(nums.begin(), nums.end(), - [](shared_ptr a, shared_ptr b) { return *a < *b; }); + [](const shared_ptr &a, const shared_ptr &b) { return *a < *b; }); EXPECT_NE(nums, nums2); diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index f3684be0b8..893525c266 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -49,7 +49,7 @@ TEST(UniquePtrTest, MoveConstruction) auto value = new int{123}; unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -58,7 +58,7 @@ TEST(UniquePtrTest, MoveConstructionFromDifferentType) auto value = new int{123}; unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -67,14 +67,14 @@ TEST(UniquePtrTest, MoveConstructionFromStdUniquePtr) auto value = new int{123}; std::unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } TEST(UniquePtrTest, Destruction) { bool was_destructed; - unique_ptr{new A{was_destructed}}; + unique_ptr{new A{was_destructed}}; // NOLINT EXPECT_TRUE(was_destructed); } @@ -83,13 +83,13 @@ TEST(UniquePtrTest, StdUniquePtrConversionOperator) auto value = new int{123}; unique_ptr ptr1{value}; std::unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); value = new int{456}; ptr1 = unique_ptr{value}; ptr2 = std::move(ptr1); - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); ptr2 = nullptr; diff --git a/api/test/trace/trace_state_test.cc b/api/test/trace/trace_state_test.cc index 7f5a05cfe6..e6ed73c1f4 100644 --- a/api/test/trace/trace_state_test.cc +++ b/api/test/trace/trace_state_test.cc @@ -20,7 +20,7 @@ const char *kLongString = // -------------------------- TraceState class tests --------------------------- -std::string create_ts_return_header(std::string header) +std::string create_ts_return_header(const std::string &header) { auto ts = TraceState::FromHeader(header); return ts->ToHeader(); @@ -34,7 +34,7 @@ std::string header_with_max_members() { std::string key = "key" + std::to_string(i); std::string value = "value" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != max_members - 1) { header += ","; diff --git a/examples/etw_threads/main.cc b/examples/etw_threads/main.cc index d25883d1d1..e5b8dbac9f 100644 --- a/examples/etw_threads/main.cc +++ b/examples/etw_threads/main.cc @@ -113,7 +113,7 @@ void beep() // Max number of threads to spawn constexpr int kMaxThreads = 10; -int main(int arc, char **argv) +int main(int /*arc*/, char ** /*argv*/) { std::thread pool[kMaxThreads]; diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index b8f233dcc7..9ca41c6958 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -20,7 +20,6 @@ using grpc::Channel; using grpc::ClientContext; -using grpc::ClientReader; using grpc::Status; using grpc_example::Greeter; @@ -34,7 +33,7 @@ using namespace opentelemetry::trace; class GreeterClient { public: - GreeterClient(std::shared_ptr channel) : stub_(Greeter::NewStub(channel)) {} + GreeterClient(const std::shared_ptr &channel) : stub_(Greeter::NewStub(channel)) {} std::string Greet(std::string ip, uint16_t port) { @@ -77,7 +76,7 @@ class GreeterClient } else { - std::cout << status.error_code() << ": " << status.error_message() << std::endl; + std::cout << status.error_code() << ": " << status.error_message() << '\n'; span->SetStatus(StatusCode::kError); span->SetAttribute(SemanticConventions::kRpcGrpcStatusCode, status.error_code()); // Make sure to end your spans! @@ -95,7 +94,7 @@ void RunClient(uint16_t port) GreeterClient greeter( grpc::CreateChannel("0.0.0.0:" + std::to_string(port), grpc::InsecureChannelCredentials())); std::string response = greeter.Greet("0.0.0.0", port); - std::cout << "grpc_server says: " << response << std::endl; + std::cout << "grpc_server says: " << response << '\n'; } } // namespace diff --git a/examples/grpc/server.cc b/examples/grpc/server.cc index a8fac8b5f0..3c3fcede4f 100644 --- a/examples/grpc/server.cc +++ b/examples/grpc/server.cc @@ -27,7 +27,6 @@ using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; -using grpc::ServerWriter; using grpc::Status; using grpc_example::Greeter; @@ -49,7 +48,7 @@ class GreeterServer final : public Greeter::Service const GreetRequest *request, GreetResponse *response) override { - for (auto elem : context->client_metadata()) + for (const auto &elem : context->client_metadata()) { std::cout << "ELEM: " << elem.first << " " << elem.second << "\n"; } @@ -78,8 +77,8 @@ class GreeterServer final : public Greeter::Service // Fetch and parse whatever HTTP headers we can from the gRPC request. span->AddEvent("Processing client attributes"); - std::string req = request->request(); - std::cout << std::endl << "grpc_client says: " << req << std::endl; + const std::string &req = request->request(); + std::cout << '\n' << "grpc_client says: " << req << '\n'; std::string message = "The pleasure is mine."; // Send response to client response->set_response(message); @@ -102,7 +101,7 @@ void RunServer(uint16_t port) builder.AddListeningPort(address, grpc::InsecureServerCredentials()); std::unique_ptr server(builder.BuildAndStart()); - std::cout << "Server listening on port: " << address << std::endl; + std::cout << "Server listening on port: " << address << '\n'; server->Wait(); server->Shutdown(); } diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index 35827b6502..444775dc59 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -53,7 +53,7 @@ void InitTracer() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; trace_api::Provider::SetTracerProvider(api_provider); } @@ -79,7 +79,7 @@ void InitLogger() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global logger provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; logs_api::Provider::SetLoggerProvider(api_provider); } diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index ceb7cdfcf9..d99d77de7d 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -70,29 +70,29 @@ void dumpSpans(std::vector> &spans) char span_buf[trace_api::SpanId::kSize * 2]; char trace_buf[trace_api::TraceId::kSize * 2]; char parent_span_buf[trace_api::SpanId::kSize * 2]; - std::cout << "\nSpans from memory :" << std::endl; + std::cout << "\nSpans from memory :" << '\n'; for (auto &span : spans) { - std::cout << "\n\tSpan: " << std::endl; - std::cout << "\t\tName: " << span->GetName() << std::endl; + std::cout << "\n\tSpan: " << '\n'; + std::cout << "\t\tName: " << span->GetName() << '\n'; span->GetSpanId().ToLowerBase16(span_buf); span->GetTraceId().ToLowerBase16(trace_buf); span->GetParentSpanId().ToLowerBase16(parent_span_buf); - std::cout << "\t\tTraceId: " << std::string(trace_buf, sizeof(trace_buf)) << std::endl; - std::cout << "\t\tSpanId: " << std::string(span_buf, sizeof(span_buf)) << std::endl; + std::cout << "\t\tTraceId: " << std::string(trace_buf, sizeof(trace_buf)) << '\n'; + std::cout << "\t\tSpanId: " << std::string(span_buf, sizeof(span_buf)) << '\n'; std::cout << "\t\tParentSpanId: " << std::string(parent_span_buf, sizeof(parent_span_buf)) - << std::endl; + << '\n'; - std::cout << "\t\tDescription: " << span->GetDescription() << std::endl; + std::cout << "\t\tDescription: " << span->GetDescription() << '\n'; std::cout << "\t\tSpan kind:" << static_cast::type>( span->GetSpanKind()) - << std::endl; + << '\n'; std::cout << "\t\tSpan Status: " << static_cast::type>( span->GetStatus()) - << std::endl; + << '\n'; } } } // namespace diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index d92a4ab2ac..675a6053ec 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -55,6 +55,7 @@ void run_threads() auto thread_span = get_tracer()->StartSpan(__func__); std::vector threads; + threads.reserve(5); for (int thread_num = 0; thread_num < 5; ++thread_num) { // This shows how one can effectively use Scope objects to correctly diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 38aa009d04..37bace2b0f 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -71,7 +71,7 @@ void InitTracer() trace_opts.url = opentelemetry::exporter::otlp::GetOtlpDefaultHttpTracesEndpoint(); } } - std::cout << "Using " << trace_opts.url << " to export trace spans." << std::endl; + std::cout << "Using " << trace_opts.url << " to export trace spans." << '\n'; // Create OTLP exporter instance auto exporter = otlp::OtlpHttpExporterFactory::Create(trace_opts); @@ -110,7 +110,7 @@ std::shared_ptr logger_provider; void InitLogger() { - std::cout << "Using " << logger_opts.url << " to export log records." << std::endl; + std::cout << "Using " << logger_opts.url << " to export log records." << '\n'; logger_opts.console_debug = true; // Create OTLP exporter instance auto exporter = otlp::OtlpHttpLogRecordExporterFactory::Create(logger_opts); diff --git a/examples/simple/main.cc b/examples/simple/main.cc index a872816ba1..349aec500a 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -40,7 +40,7 @@ void InitTracer() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; trace_api::Provider::SetTracerProvider(api_provider); } diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h index feb68f7f9c..af4ccb16ef 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -33,13 +33,13 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable */ void WriteKeyValue(nostd::string_view key, const opentelemetry::common::AttributeValue &value, - std::string name); + const std::string &name); void WriteKeyValue(nostd::string_view key, const opentelemetry::sdk::common::OwnedAttributeValue &value, - std::string name); + const std::string &name); - void WriteValue(const opentelemetry::common::AttributeValue &value, std::string name); + void WriteValue(const opentelemetry::common::AttributeValue &value, const std::string &name); public: /** diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 139d22e863..663691273b 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -16,7 +16,7 @@ namespace logs { void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key, const opentelemetry::common::AttributeValue &value, - std::string name) + const std::string &name) { switch (value.index()) { @@ -53,7 +53,7 @@ void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key, void ElasticSearchRecordable::WriteKeyValue( nostd::string_view key, const opentelemetry::sdk::common::OwnedAttributeValue &value, - std::string name) + const std::string &name) { namespace common = opentelemetry::sdk::common; switch (value.index()) @@ -85,7 +85,7 @@ void ElasticSearchRecordable::WriteKeyValue( } void ElasticSearchRecordable::WriteValue(const opentelemetry::common::AttributeValue &value, - std::string name) + const std::string &name) { // Assert size of variant to ensure that this method gets updated if the variant diff --git a/exporters/memory/test/in_memory_span_data_test.cc b/exporters/memory/test/in_memory_span_data_test.cc index bc19550264..be013734ef 100644 --- a/exporters/memory/test/in_memory_span_data_test.cc +++ b/exporters/memory/test/in_memory_span_data_test.cc @@ -8,7 +8,6 @@ #include using opentelemetry::exporter::memory::InMemorySpanData; -using opentelemetry::sdk::trace::Recordable; using opentelemetry::sdk::trace::SpanData; TEST(InMemorySpanData, AddRecordable) diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h index 24bc8e5be7..840d7d5b8a 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -66,10 +66,10 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor bool isShutdown() const noexcept; void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); }; } // namespace logs } // namespace exporter diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h index 1ad124a9ab..f1b2cd6ef9 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h @@ -79,7 +79,7 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr void printPointData(const opentelemetry::sdk::metrics::PointType &point_data); void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes); void printAttributes(const std::map &map, - const std::string prefix); + const std::string &prefix); void printResources(const opentelemetry::sdk::resource::Resource &resources); }; } // namespace metrics diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index a7de9a5eb4..e22eb77f3e 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -69,7 +69,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter // various print helpers void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printEvents(const std::vector &events); diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 7f661276c8..26266161c3 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -75,11 +75,11 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( // Convert trace, spanid, traceflags into exportable representation constexpr int trace_id_len = 32; - constexpr int span_id__len = 16; + constexpr int span_id_len = 16; constexpr int trace_flags_len = 2; char trace_id[trace_id_len] = {0}; - char span_id[span_id__len] = {0}; + char span_id[span_id_len] = {0}; char trace_flags[trace_flags_len] = {0}; log_record->GetTraceId().ToLowerBase16(trace_id); @@ -120,7 +120,7 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( << " event_id : " << event_id << "\n" << " event_name : " << log_record->GetEventName() << "\n" << " trace_id : " << std::string(trace_id, trace_id_len) << "\n" - << " span_id : " << std::string(span_id, span_id__len) << "\n" + << " span_id : " << std::string(span_id, span_id_len) << "\n" << " trace_flags : " << std::string(trace_flags, trace_flags_len) << "\n" << " scope : \n" << " name : " << log_record->GetInstrumentationScope().GetName() << "\n" @@ -155,7 +155,7 @@ bool OStreamLogRecordExporter::isShutdown() const noexcept void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -166,7 +166,7 @@ void OStreamLogRecordExporter::printAttributes( void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 08bfe340c7..4bdd122492 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -117,7 +117,7 @@ sdk::common::ExportResult OStreamMetricExporter::Export( void OStreamMetricExporter::printAttributes( const std::map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index 9437ae561a..f41d33ae6c 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -100,7 +100,7 @@ sdk::common::ExportResult OStreamSpanExporter::Export( << "\n duration : " << span->GetDuration().count() << "\n description : " << span->GetDescription() << "\n span kind : " << span->GetSpanKind() - << "\n status : " << statusMap[int(span->GetStatus())] + << "\n status : " << statusMap[static_cast(span->GetStatus())] << "\n attributes : "; printAttributes(span->GetAttributes()); sout_ << "\n events : "; @@ -137,7 +137,7 @@ bool OStreamSpanExporter::isShutdown() const noexcept void OStreamSpanExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -177,7 +177,7 @@ void OStreamSpanExporter::printLinks(const std::vector void OStreamSpanExporter::printResources(const opentelemetry::sdk::resource::Resource &resources) { - auto attributes = resources.GetAttributes(); + const auto &attributes = resources.GetAttributes(); if (attributes.size()) { printAttributes(attributes, "\n\t"); @@ -188,7 +188,7 @@ void OStreamSpanExporter::printInstrumentationScope( const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope) { sout_ << instrumentation_scope.GetName(); - auto version = instrumentation_scope.GetVersion(); + const auto &version = instrumentation_scope.GetVersion(); if (version.size()) { sout_ << "-" << version; diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 7b22d9b3fd..b7708f3153 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -97,17 +97,17 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) std::cout.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -126,7 +126,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -167,9 +167,8 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) std::cout.rdbuf(original); std::vector expected_output{ - "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + + "{\n", + " timestamp : " + std::to_string(now.time_since_epoch().count()) + "\n" " observed_timestamp : " + std::to_string(now.time_since_epoch().count()) + @@ -182,7 +181,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -201,7 +200,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -243,10 +242,10 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) std::cerr.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -256,7 +255,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) " key1: val1\n", " attributes : \n", " a: 1\n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -275,7 +274,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -324,10 +323,10 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) std::clog.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " service.name: unknown_service\n", @@ -337,7 +336,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) " res1: [1,2,3]\n", " attributes : \n", " attr1: [0,1,0]\n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -356,7 +355,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -398,11 +397,10 @@ TEST(OStreamLogRecordExporter, IntegrationTest) // Compare actual vs expected outputs std::vector expected_output{ - "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + "\n", - " severity_num : 5\n" - " severity_text : DEBUG\n" + "{\n", + " timestamp : " + std::to_string(now.time_since_epoch().count()) + "\n", + " severity_num : 5\n", + " severity_text : DEBUG\n", " body : Hello\n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -410,7 +408,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -429,7 +427,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -472,8 +470,8 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) // Compare actual vs expected outputs std::vector expected_output{ - " severity_num : 5\n" - " severity_text : DEBUG\n" + " severity_num : 5\n", + " severity_text : DEBUG\n", " body : Hello {key1} {key2}\n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -481,7 +479,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 12345678\n" + " event_id : 12345678\n", " event_name : test_event_id\n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -500,7 +498,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index f92f1bbffd..cadc1b9d38 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -31,7 +31,7 @@ using Attributes = std::initializer_listEXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } \ else \ { \ - VAR = tm_obj_ptr->EXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } for (size_t i = 0; i < fmt.size() && ret < bufz && running; ++i) @@ -619,7 +619,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL FileSystemUtil } #if !defined(UTIL_FS_DISABLE_LINK) - enum class LinkOption : int32_t + enum class LinkOption : uint8_t { kDefault = 0x00, // hard link for default kSymbolicLink = 0x01, // or soft link @@ -749,6 +749,7 @@ static void ConvertListFieldToJson(nlohmann::json &value, const google::protobuf::Message &message, const google::protobuf::FieldDescriptor *field_descriptor); +// NOLINTBEGIN(misc-no-recursion) static void ConvertGenericMessageToJson(nlohmann::json &value, const google::protobuf::Message &message) { @@ -952,6 +953,8 @@ void ConvertListFieldToJson(nlohmann::json &value, } } +// NOLINTEND(misc-no-recursion) suppressing for performance as if implemented with stack needs +// Dynamic memory allocation } // namespace class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 3410726cf8..a5760bdd81 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -132,7 +132,7 @@ static std::string GetFileContentsOrInMemoryContents(const std::string &file_pat #ifdef ENABLE_ASYNC_EXPORT template static sdk::common::ExportResult InternalDelegateAsyncExport( - std::shared_ptr async_data, + const std::shared_ptr &async_data, StubType *stub, std::unique_ptr &&context, std::unique_ptr &&arena, @@ -163,8 +163,8 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( call_data->arena.swap(arena); call_data->result_callback.swap(result_callback); - call_data->request = - google::protobuf::Arena::Create(call_data->arena.get(), std::move(request)); + call_data->request = google::protobuf::Arena::Create( + call_data->arena.get(), std::forward(request)); call_data->response = google::protobuf::Arena::Create(call_data->arena.get()); if (call_data->request == nullptr || call_data->response == nullptr) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 03eb5fb434..94f02a9967 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -434,6 +434,7 @@ static void ConvertListFieldToJson(nlohmann::json &value, const google::protobuf::FieldDescriptor *field_descriptor, const OtlpHttpClientOptions &options); +// NOLINTBEGIN(misc-no-recursion) static void ConvertGenericMessageToJson(nlohmann::json &value, const google::protobuf::Message &message, const OtlpHttpClientOptions &options) @@ -654,6 +655,9 @@ void ConvertListFieldToJson(nlohmann::json &value, } } +// NOLINTEND(misc-no-recursion) suppressing for performance, if implemented iterative process needs +// Dynamic memory allocation + } // namespace OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) @@ -696,7 +700,7 @@ OtlpHttpClient::~OtlpHttpClient() OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, std::shared_ptr http_client) - : is_shutdown_(false), options_(options), http_client_(http_client) + : is_shutdown_(false), options_(options), http_client_(std::move(http_client)) { http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); } @@ -881,7 +885,7 @@ OtlpHttpClient::createSession( std::string error_message = "[OTLP HTTP Client] Export failed, invalid url: " + options_.url; if (options_.console_debug) { - std::cerr << error_message << std::endl; + std::cerr << error_message << '\n'; } OTEL_INTERNAL_LOG_ERROR(error_message.c_str()); @@ -946,7 +950,7 @@ OtlpHttpClient::createSession( const char *error_message = "[OTLP HTTP Client] Export failed, exporter is shutdown"; if (options_.console_debug) { - std::cerr << error_message << std::endl; + std::cerr << error_message << '\n'; } OTEL_INTERNAL_LOG_ERROR(error_message); diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index e4f69f502b..4c4a6dbeb2 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -58,8 +58,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t options.content_type = content_type; options.console_debug = true; options.timeout = std::chrono::system_clock::duration::zero(); - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -158,34 +157,35 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); - ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); - if (user_agent_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); - } - - // let the otlp_http_client to continue - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); + ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); + if (user_agent_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); + } + + // let the otlp_http_client to continue + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); @@ -249,38 +249,39 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); - ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); - if (user_agent_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); - } - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); + ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); + if (user_agent_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); + } + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); child_span->End(); parent_span->End(); @@ -343,25 +344,27 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto received_trace_id = + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); @@ -424,30 +427,32 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto received_trace_id = + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); child_span->End(); parent_span->End(); diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 5fbf95798f..35a0bb62e2 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -57,8 +57,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t OtlpHttpLogRecordExporterOptions options; options.content_type = content_type; options.console_debug = true; - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -151,46 +150,47 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resourceLogs"].begin(); - auto scope_logs = *resource_logs["scopeLogs"].begin(); - auto scope = scope_logs["scope"]; - auto log = *scope_logs["logRecords"].begin(); - auto received_trace_id = log["traceId"].get(); - auto received_span_id = log["spanId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log message", log["body"]["stringValue"].get()); - EXPECT_LE(15, log["attributes"].size()); - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - bool check_scope_attribute = false; - auto scope_attributes = scope["attributes"]; - for (auto &attribute : scope_attributes) - { - if (!attribute.is_object()) - { - continue; - } - if ("scope_key1" == attribute["key"]) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); - } - } - ASSERT_TRUE(check_scope_attribute); - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); + auto scope = scope_logs["scope"]; + auto log = *scope_logs["logRecords"].begin(); + auto received_trace_id = log["traceId"].get(); + auto received_span_id = log["spanId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + EXPECT_EQ(received_span_id, report_span_id); + EXPECT_EQ("Log message", log["body"]["stringValue"].get()); + EXPECT_LE(15, log["attributes"].size()); + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + bool check_scope_attribute = false; + auto scope_attributes = scope["attributes"]; + for (auto &attribute : scope_attributes) + { + if (!attribute.is_object()) + { + continue; + } + if ("scope_key1" == attribute["key"]) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); + } + } + ASSERT_TRUE(check_scope_attribute); + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -268,57 +268,58 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resourceLogs"].begin(); - auto scope_logs = *resource_logs["scopeLogs"].begin(); - auto schema_url = scope_logs["schemaUrl"].get(); - auto scope = scope_logs["scope"]; - auto scope_name = scope["name"]; - auto scope_version = scope["version"]; - auto log = *scope_logs["logRecords"].begin(); - auto received_trace_id = log["traceId"].get(); - auto received_span_id = log["spanId"].get(); - EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0"); - EXPECT_EQ(scope_name, "opentelelemtry_library"); - EXPECT_EQ(scope_version, "1.2.0"); - EXPECT_EQ(received_trace_id, report_trace_id); - EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log message", log["body"]["stringValue"].get()); - EXPECT_LE(15, log["attributes"].size()); - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - bool check_scope_attribute = false; - auto scope_attributes = scope["attributes"]; - for (auto &attribute : scope_attributes) - { - if (!attribute.is_object()) - { - continue; - } - if ("scope_key1" == attribute["key"]) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); + auto schema_url = scope_logs["schemaUrl"].get(); + auto scope = scope_logs["scope"]; + auto scope_name = scope["name"]; + auto scope_version = scope["version"]; + auto log = *scope_logs["logRecords"].begin(); + auto received_trace_id = log["traceId"].get(); + auto received_span_id = log["spanId"].get(); + EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0"); + EXPECT_EQ(scope_name, "opentelelemtry_library"); + EXPECT_EQ(scope_version, "1.2.0"); + EXPECT_EQ(received_trace_id, report_trace_id); + EXPECT_EQ(received_span_id, report_span_id); + EXPECT_EQ("Log message", log["body"]["stringValue"].get()); + EXPECT_LE(15, log["attributes"].size()); + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + bool check_scope_attribute = false; + auto scope_attributes = scope["attributes"]; + for (auto &attribute : scope_attributes) + { + if (!attribute.is_object()) + { + continue; + } + if ("scope_key1" == attribute["key"]) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -390,47 +391,49 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto scope_log = request_body.resource_logs(0).scope_logs(0); - EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); - EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); - EXPECT_EQ(scope_log.scope().version(), "1.2.0"); - auto received_log = scope_log.log_records(0); - EXPECT_EQ(received_log.trace_id(), report_trace_id); - EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log message", received_log.body().string_value()); - EXPECT_LE(15, received_log.attributes_size()); - bool check_service_name = false; - for (auto &attribute : received_log.attributes()) - { - if ("service.name" == attribute.key()) - { - check_service_name = true; - EXPECT_EQ("unit_test_service", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_service_name); - - bool check_scope_attribute = false; - for (auto &attribute : scope_log.scope().attributes()) - { - if ("scope_key1" == attribute.key()) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto scope_log = request_body.resource_logs(0).scope_logs(0); + EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); + EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); + EXPECT_EQ(scope_log.scope().version(), "1.2.0"); + const auto &received_log = scope_log.log_records(0); + EXPECT_EQ(received_log.trace_id(), report_trace_id); + EXPECT_EQ(received_log.span_id(), report_span_id); + EXPECT_EQ("Log message", received_log.body().string_value()); + EXPECT_LE(15, received_log.attributes_size()); + bool check_service_name = false; + for (auto &attribute : received_log.attributes()) + { + if ("service.name" == attribute.key()) + { + check_service_name = true; + EXPECT_EQ("unit_test_service", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_service_name); + + bool check_scope_attribute = false; + for (auto &attribute : scope_log.scope().attributes()) + { + if ("scope_key1" == attribute.key()) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -503,51 +506,53 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id, schema_url]( - std::shared_ptr callback) { - opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto &scope_log = request_body.resource_logs(0).scope_logs(0); - auto received_log = scope_log.log_records(0); - EXPECT_EQ(received_log.trace_id(), report_trace_id); - EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log message", received_log.body().string_value()); - EXPECT_LE(15, received_log.attributes_size()); - bool check_service_name = false; - for (auto &attribute : received_log.attributes()) - { - if ("service.name" == attribute.key()) - { - check_service_name = true; - EXPECT_EQ("unit_test_service", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_service_name); - - auto &scope = scope_log.scope(); - EXPECT_EQ(scope.name(), "opentelelemtry_library"); - EXPECT_EQ(scope_log.schema_url(), schema_url); - bool check_scope_attribute = false; - for (auto &attribute : scope.attributes()) - { - if ("scope_key1" == attribute.key()) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id, schema_url]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto &scope_log = request_body.resource_logs(0).scope_logs(0); + auto received_log = scope_log.log_records(0); + EXPECT_EQ(received_log.trace_id(), report_trace_id); + EXPECT_EQ(received_log.span_id(), report_span_id); + EXPECT_EQ("Log message", received_log.body().string_value()); + EXPECT_LE(15, received_log.attributes_size()); + bool check_service_name = false; + for (auto &attribute : received_log.attributes()) + { + if ("service.name" == attribute.key()) + { + check_service_name = true; + EXPECT_EQ("unit_test_service", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_service_name); + + auto &scope = scope_log.scope(); + EXPECT_EQ(scope.name(), "opentelelemtry_library"); + EXPECT_EQ(scope_log.schema_url(), schema_url); + bool check_scope_attribute = false; + for (auto &attribute : scope.attributes()) + { + if ("scope_key1" == attribute.key()) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 1e5fe6469f..174597248b 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -64,8 +64,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t OtlpHttpMetricExporterOptions options; options.content_type = content_type; options.console_debug = true; - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -154,36 +153,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["sum"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["sum"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -237,7 +237,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -335,36 +336,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["gauge"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["gauge"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -427,7 +429,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -530,71 +533,72 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["histogram"]["dataPoints"]; - EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); - EXPECT_EQ(900.5, data_points[0]["sum"].get()); - EXPECT_EQ(1.8, data_points[0]["min"].get()); - EXPECT_EQ(19, data_points[0]["max"].get()); - EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); - if (4 == data_points[0]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); - if (3 == data_points[0]["explicitBounds"].size()) - { - EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); - EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); - EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); - } - - EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); - EXPECT_EQ(900.0, data_points[1]["sum"].get()); - EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); - if (4 == data_points[1]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); - if (3 == data_points[1]["explicitBounds"].size()) - { - EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); - EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); - EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); - } - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["histogram"]["dataPoints"]; + EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); + EXPECT_EQ(900.5, data_points[0]["sum"].get()); + EXPECT_EQ(1.8, data_points[0]["min"].get()); + EXPECT_EQ(19, data_points[0]["max"].get()); + EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); + if (4 == data_points[0]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); + if (3 == data_points[0]["explicitBounds"].size()) + { + EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); + EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); + EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); + } + + EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); + EXPECT_EQ(900.0, data_points[1]["sum"].get()); + EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); + if (4 == data_points[1]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); + if (3 == data_points[1]["explicitBounds"].size()) + { + EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); + EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); + EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); + } + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -661,7 +665,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index b945cb28fe..2ad76dfd1d 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -200,7 +200,7 @@ TEST(OtlpMetricSerializationTest, Counter) EXPECT_EQ(sum.is_monotonic(), true); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = sum.data_points(i); + const auto &proto_number_point = sum.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 10.2 : 20.2); } @@ -230,7 +230,7 @@ TEST(OtlpMetricSerializationTest, Histogram) proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = histogram.data_points(i); + const auto &proto_number_point = histogram.data_points(i); EXPECT_EQ(proto_number_point.sum(), i == 0 ? 100.2 : 200.2); } @@ -244,7 +244,7 @@ TEST(OtlpMetricSerializationTest, ObservableGauge) otlp_exporter::OtlpMetricUtils::ConvertGaugeMetric(data, &gauge); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = gauge.data_points(i); + const auto &proto_number_point = gauge.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 30.2 : 50.2); } diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index caa17c8a46..537f10340d 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -216,7 +216,7 @@ TEST(OtlpRecordable, SetResource) bool found_service_name = false; for (int i = 0; i < proto_resource.attributes_size(); i++) { - auto attr = proto_resource.attributes(static_cast(i)); + const auto &attr = proto_resource.attributes(static_cast(i)); if (attr.key() == service_name_key && attr.value().string_value() == service_name) { found_service_name = true; @@ -322,7 +322,7 @@ TEST(OtlpRecordable, PopulateRequest) OtlpRecordableUtils::PopulateRequest(spans_span, &req); EXPECT_EQ(req.resource_spans().size(), 2); - for (auto resource_spans : req.resource_spans()) + for (const auto &resource_spans : req.resource_spans()) { auto service_name = resource_spans.resource().attributes(0).value().string_value(); auto scope_spans_size = resource_spans.scope_spans().size(); @@ -359,7 +359,7 @@ TEST(OtlpRecordable, PopulateRequestMissing) OtlpRecordableUtils::PopulateRequest(spans_span, &req); EXPECT_EQ(req.resource_spans().size(), 2); - for (auto resource_spans : req.resource_spans()) + for (const auto &resource_spans : req.resource_spans()) { // Both should have scope spans EXPECT_EQ(resource_spans.scope_spans().size(), 1); diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 68d8586bcc..35ee748273 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -88,7 +88,7 @@ inline std::string Sanitize(std::string name, const T &valid) */ std::string SanitizeLabel(std::string label_key) { - return Sanitize(label_key, [](int i, char c) { + return Sanitize(std::move(label_key), [](int i, char c) { return (c >= 'a' && c <= 'z') || // (c >= 'A' && c <= 'Z') || // c == '_' || // @@ -396,7 +396,7 @@ std::string PrometheusExporterUtils::RemoveUnitPortionInBraces(const std::string std::string PrometheusExporterUtils::ConvertRateExpressedToPrometheusUnit( const std::string &rate_expressed_unit) { - size_t pos = rate_expressed_unit.find("/"); + size_t pos = rate_expressed_unit.find('/'); if (pos == std::string::npos) { return rate_expressed_unit; diff --git a/exporters/prometheus/test/exporter_test.cc b/exporters/prometheus/test/exporter_test.cc index 3bda4c3d7b..b268ac8514 100644 --- a/exporters/prometheus/test/exporter_test.cc +++ b/exporters/prometheus/test/exporter_test.cc @@ -16,7 +16,6 @@ * private constructor is only to be used here for testing */ -using opentelemetry::exporter::metrics::PrometheusCollector; using opentelemetry::exporter::metrics::PrometheusExporter; using opentelemetry::exporter::metrics::PrometheusExporterOptions; using opentelemetry::sdk::metrics::AggregationTemporality; diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index b876e7369c..7ad5eee1fd 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include + +#include #include "prometheus/metric_family.h" #include "prometheus/metric_type.h" @@ -24,7 +26,7 @@ class SanitizeNameTester public: static std::string sanitize(std::string name) { - return PrometheusExporterUtils::SanitizeNames(name); + return PrometheusExporterUtils::SanitizeNames(std::move(name)); } static std::string getPrometheusUnit(const std::string &unit_abbreviation) { @@ -104,14 +106,13 @@ void assert_basic(prometheus_client::MetricFamily &metric, ASSERT_TRUE(false); break; case prometheus::MetricType::Untyped: - break; default: break; } } void assert_histogram(prometheus_client::MetricFamily &metric, - std::list boundaries, + const std::list &boundaries, std::vector correct) { int cumulative_count = 0; diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index e6d3ce8b26..a554cbf4cc 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// NOLINTNEXTLINE #define _WINSOCKAPI_ // stops including winsock.h #include @@ -105,7 +106,6 @@ sdk::common::ExportResult ZipkinExporter::Export( } return sdk::common::ExportResult::kFailure; } - return sdk::common::ExportResult::kSuccess; } void ZipkinExporter::InitializeLocalEndpoint() diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index 18c47bcab5..8e58f83d2e 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -17,6 +17,7 @@ # include "nlohmann/json.hpp" # include +# include # if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" @@ -47,7 +48,7 @@ class ZipkinExporterTestPeer : public ::testing::Test std::unique_ptr GetExporter( std::shared_ptr http_client) { - return std::unique_ptr(new ZipkinExporter(http_client)); + return std::unique_ptr(new ZipkinExporter(std::move(http_client))); } // Get the options associated with the given exporter. diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h index 58dd154bb7..b6654ce3ad 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h @@ -124,7 +124,8 @@ class HttpOperation double ulnow); #endif public: - void DispatchEvent(opentelemetry::ext::http::client::SessionState type, std::string reason = ""); + void DispatchEvent(opentelemetry::ext::http::client::SessionState type, + const std::string &reason = ""); /** * Create local CURL instance for url and body diff --git a/ext/src/dll/dllmain.cc b/ext/src/dll/dllmain.cc index 1812377374..df1d2bc70d 100644 --- a/ext/src/dll/dllmain.cc +++ b/ext/src/dll/dllmain.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include +#include // NOLINT // Include API header files here for exporting #include diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 38ca2e7348..67b0b93a54 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -562,7 +562,7 @@ bool HttpClient::doAbortSessions() } bool has_data = false; - for (auto session : pending_to_abort_sessions) + for (const auto &session : pending_to_abort_sessions) { if (!session.second) { diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index f82c17ccc5..4de014fd82 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -240,7 +240,7 @@ int HttpOperation::OnProgressCallback(void *clientp, #endif void HttpOperation::DispatchEvent(opentelemetry::ext::http::client::SessionState type, - std::string reason) + const std::string &reason) { if (event_handle_ != nullptr) { @@ -273,7 +273,7 @@ HttpOperation::HttpOperation(opentelemetry::ext::http::client::Method method, last_curl_result_(CURLE_OK), event_handle_(event_handle), method_(method), - url_(url), + url_(std::move(url)), ssl_options_(ssl_options), // Local vars request_headers_(request_headers), @@ -453,7 +453,7 @@ void HttpOperation::Cleanup() # define HAVE_TLS_VERSION #endif -static long parse_min_ssl_version(std::string version) +static long parse_min_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.2") @@ -470,7 +470,7 @@ static long parse_min_ssl_version(std::string version) return 0; } -static long parse_max_ssl_version(std::string version) +static long parse_max_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.2") diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 6e30323eeb..0dc6e5d5e8 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #define HTTP_PORT 19000 @@ -74,7 +75,9 @@ class PostEventHandler : public CustomEventHandler class FinishInCallbackHandler : public CustomEventHandler { public: - FinishInCallbackHandler(std::shared_ptr session) : session_(session) {} + FinishInCallbackHandler(std::shared_ptr session) + : session_(std::move(session)) + {} void OnResponse(http_client::Response &response) noexcept override { diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 349626e219..d9819cde0d 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -75,10 +75,10 @@ struct Uri uint16_t port; std::string path; - Uri(std::string uri) + Uri(const std::string &uri) { - size_t host_end = uri.substr(7, std::string::npos).find(":"); - size_t port_end = uri.substr(host_end + 1, std::string::npos).find("/"); + size_t host_end = uri.substr(7, std::string::npos).find(':'); + size_t port_end = uri.substr(host_end + 1, std::string::npos).find('/'); host = uri.substr(0, host_end + 7); port = std::stoi(uri.substr(7 + host_end + 1, port_end)); diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 4f6c144a43..ece1588425 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -39,7 +39,7 @@ const int TEST_FAILED = 1; Command line parameters. */ -enum test_mode +enum test_mode : std::uint8_t { MODE_NONE, MODE_HTTP, @@ -84,7 +84,7 @@ struct TestResult struct TestResult g_test_result; -void parse_error_msg(TestResult *result, std::string msg) +void parse_error_msg(TestResult *result, const std::string &msg) { static std::string connection_failed("Session state: connection failed."); @@ -129,11 +129,11 @@ void parse_error_msg(TestResult *result, std::string msg) } } -void parse_warning_msg(TestResult * /* result */, std::string /* msg */) {} +void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_info_msg(TestResult * /* result */, std::string /* msg */) {} +void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_debug_msg(TestResult *result, std::string msg) +void parse_debug_msg(TestResult *result, const std::string &msg) { static std::string export_success("Export 1 trace span(s) success"); @@ -162,19 +162,19 @@ class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandl case opentelemetry::sdk::common::internal_log::LogLevel::None: break; case opentelemetry::sdk::common::internal_log::LogLevel::Error: - std::cout << " - [E] " << msg << std::endl; + std::cout << " - [E] " << msg << '\n'; parse_error_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Warning: - std::cout << " - [W] " << msg << std::endl; + std::cout << " - [W] " << msg << '\n'; parse_warning_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Info: - std::cout << " - [I] " << msg << std::endl; + std::cout << " - [I] " << msg << '\n'; parse_info_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Debug: - std::cout << " - [D] " << msg << std::endl; + std::cout << " - [D] " << msg << '\n'; parse_debug_msg(&g_test_result, msg); break; } @@ -429,12 +429,12 @@ void list_test_cases() while (current->m_func != nullptr) { - std::cout << current->m_name << std::endl; + std::cout << current->m_name << '\n'; current++; } } -int run_test_case(std::string name) +int run_test_case(const std::string &name) { const test_case *current = all_tests; @@ -448,7 +448,7 @@ int run_test_case(std::string name) current++; } - std::cerr << "Unknown test <" << name << ">" << std::endl; + std::cerr << "Unknown test <" << name << ">" << '\n'; return 1; } diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context.h b/sdk/include/opentelemetry/sdk/logs/logger_context.h index bab002b231..11eca41d16 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context.h @@ -34,7 +34,7 @@ class LoggerContext { public: explicit LoggerContext(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index 6c035ad5e9..dd2a52789d 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -38,11 +38,11 @@ class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::Lo * @param resource The resources for this logger provider. */ explicit LoggerProvider(std::unique_ptr &&processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; explicit LoggerProvider(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index 40a57a6f88..fe85fe04cc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -54,7 +54,7 @@ class MeterContext : public std::enable_shared_from_this */ MeterContext( std::unique_ptr views = std::unique_ptr(new ViewRegistry()), - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** @@ -131,7 +131,7 @@ class MeterContext : public std::enable_shared_from_this * * @param meter */ - void AddMeter(std::shared_ptr meter); + void AddMeter(const std::shared_ptr &meter); void RemoveMeter(nostd::string_view name, nostd::string_view version, diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index a838f2a96a..c34f16e0a1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -39,8 +39,8 @@ class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics:: * @param resource The resources for this meter provider. */ MeterProvider( - std::unique_ptr views = std::unique_ptr(new ViewRegistry()), - sdk::resource::Resource resource = sdk::resource::Resource::Create({})) noexcept; + std::unique_ptr views = std::unique_ptr(new ViewRegistry()), + const sdk::resource::Resource &resource = sdk::resource::Resource::Create({})) noexcept; /** * Initialize a new meter provider with a specified context diff --git a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h index 2d01710e47..007b3c74cd 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -40,7 +40,7 @@ class TemporalMetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - std::shared_ptr delta_metrics, + const std::shared_ptr &delta_metrics, nostd::function_ref callback) noexcept; private: diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 1d2c5bf25f..1d5f8dbc55 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -37,7 +37,7 @@ class Synchronous class LongCounter : public Synchronous, public opentelemetry::metrics::Counter { public: - LongCounter(InstrumentDescriptor instrument_descriptor, + LongCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(uint64_t value, @@ -56,7 +56,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter { public: - DoubleCounter(InstrumentDescriptor instrument_descriptor, + DoubleCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(double value, @@ -72,7 +72,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter { public: - LongUpDownCounter(InstrumentDescriptor instrument_descriptor, + LongUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(int64_t value, @@ -88,7 +88,7 @@ class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpD class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter { public: - DoubleUpDownCounter(InstrumentDescriptor instrument_descriptor, + DoubleUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(double value, @@ -104,7 +104,7 @@ class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::U class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: - LongHistogram(InstrumentDescriptor instrument_descriptor, + LongHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); #if OPENTELEMETRY_ABI_VERSION_NO >= 2 @@ -124,7 +124,7 @@ class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogr class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: - DoubleHistogram(InstrumentDescriptor instrument_descriptor, + DoubleHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); #if OPENTELEMETRY_ABI_VERSION_NO >= 2 diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h index d5054d9218..e44e9fa320 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h @@ -27,7 +27,7 @@ namespace trace class ParentBasedSampler : public Sampler { public: - explicit ParentBasedSampler(std::shared_ptr delegate_sampler) noexcept; + explicit ParentBasedSampler(const std::shared_ptr &delegate_sampler) noexcept; /** The decision either respects the parent span's sampling decision or delegates to * delegateSampler for root spans * @return Returns DROP always diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h index 68557ace79..d5cf598311 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h @@ -23,7 +23,7 @@ class ParentBasedSamplerFactory /** * Create a ParentBasedSampler. */ - static std::unique_ptr Create(std::shared_ptr delegate_sampler); + static std::unique_ptr Create(const std::shared_ptr &delegate_sampler); }; } // namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 73bbe4f84b..e1b2cb25d2 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -39,7 +39,7 @@ class TracerContext public: explicit TracerContext( std::vector> &&processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 0d05a94043..13a65a2d87 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -43,7 +43,7 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T */ explicit TracerProvider( std::unique_ptr processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = @@ -51,7 +51,7 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T explicit TracerProvider( std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = diff --git a/sdk/src/common/global_log_handler.cc b/sdk/src/common/global_log_handler.cc index 40968f2b7e..f60527eee8 100644 --- a/sdk/src/common/global_log_handler.cc +++ b/sdk/src/common/global_log_handler.cc @@ -31,7 +31,7 @@ void DefaultLogHandler::Handle(LogLevel level, { output_s << msg; } - output_s << std::endl; + output_s << '\n'; // TBD - print attributes switch (level) diff --git a/sdk/src/logs/event_logger.cc b/sdk/src/logs/event_logger.cc index 6b0afacfaf..df9ba44c31 100644 --- a/sdk/src/logs/event_logger.cc +++ b/sdk/src/logs/event_logger.cc @@ -21,7 +21,7 @@ namespace logs EventLogger::EventLogger( opentelemetry::nostd::shared_ptr delegate_logger, opentelemetry::nostd::string_view event_domain) noexcept - : delegate_logger_(delegate_logger), event_domain_(event_domain) + : delegate_logger_(std::move(delegate_logger)), event_domain_(event_domain) {} const opentelemetry::nostd::string_view EventLogger::GetName() noexcept diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index e9935c5107..2d57ab9faa 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -38,7 +38,7 @@ Logger::Logger( std::unique_ptr instrumentation_scope) noexcept : logger_name_(std::string(name)), instrumentation_scope_(std::move(instrumentation_scope)), - context_(context) + context_(std::move(context)) {} const opentelemetry::nostd::string_view Logger::GetName() noexcept diff --git a/sdk/src/logs/logger_context.cc b/sdk/src/logs/logger_context.cc index 2bfb89161e..a6eb063661 100644 --- a/sdk/src/logs/logger_context.cc +++ b/sdk/src/logs/logger_context.cc @@ -19,7 +19,7 @@ namespace logs { LoggerContext::LoggerContext(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : resource_(resource), processor_( std::unique_ptr(new MultiLogRecordProcessor(std::move(processors)))) diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 1eaa0d186e..fdea3eb51a 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -27,7 +27,7 @@ namespace logs { LoggerProvider::LoggerProvider(std::unique_ptr &&processor, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept { std::vector> processors; processors.emplace_back(std::move(processor)); @@ -36,7 +36,7 @@ LoggerProvider::LoggerProvider(std::unique_ptr &&processor, } LoggerProvider::LoggerProvider(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : context_{std::make_shared(std::move(processors), std::move(resource))} {} diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 311efc1e7e..709957d68e 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -20,9 +20,9 @@ namespace metrics ObservableInstrument::ObservableInstrument(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage, std::shared_ptr observable_registry) - : instrument_descriptor_(instrument_descriptor), + : instrument_descriptor_(std::move(instrument_descriptor)), storage_(std::move(storage)), - observable_registry_{observable_registry} + observable_registry_{std::move(observable_registry)} {} diff --git a/sdk/src/metrics/exemplar/reservoir.cc b/sdk/src/metrics/exemplar/reservoir.cc index 4e7501799e..264a000828 100644 --- a/sdk/src/metrics/exemplar/reservoir.cc +++ b/sdk/src/metrics/exemplar/reservoir.cc @@ -3,9 +3,11 @@ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +# include + # include "opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" # include "opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.h" @@ -20,8 +22,8 @@ nostd::shared_ptr ExemplarReservoir::GetSimpleFixedSizeExempl std::shared_ptr reservoir_cell_selector, MapAndResetCellType map_and_reset_cell) { - return nostd::shared_ptr{ - new SimpleFixedSizeExemplarReservoir{size, reservoir_cell_selector, map_and_reset_cell}}; + return nostd::shared_ptr{new SimpleFixedSizeExemplarReservoir{ + size, std::move(reservoir_cell_selector), map_and_reset_cell}}; } nostd::shared_ptr ExemplarReservoir::GetAlignedHistogramBucketExemplarReservoir( @@ -30,7 +32,7 @@ nostd::shared_ptr ExemplarReservoir::GetAlignedHistogramBucke MapAndResetCellType map_and_reset_cell) { return nostd::shared_ptr{new AlignedHistogramBucketExemplarReservoir{ - size, reservoir_cell_selector, map_and_reset_cell}}; + size, std::move(reservoir_cell_selector), map_and_reset_cell}}; } nostd::shared_ptr ExemplarReservoir::GetNoExemplarReservoir() diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 8b4413113b..c61f3a8d31 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -53,7 +53,7 @@ Meter::Meter( std::weak_ptr meter_context, std::unique_ptr instrumentation_scope) noexcept : scope_{std::move(instrumentation_scope)}, - meter_context_{meter_context}, + meter_context_{std::move(meter_context)}, observable_registry_(new ObservableRegistry()) {} @@ -455,7 +455,7 @@ std::vector Meter::Collect(CollectorHandle *collector, for (auto &metric_storage : storage_registry_) { metric_storage.second->Collect(collector, ctx->GetCollectors(), ctx->GetSDKStartTime(), - collect_ts, [&metric_data_list](MetricData metric_data) { + collect_ts, [&metric_data_list](const MetricData &metric_data) { metric_data_list.push_back(metric_data); return true; }); diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index de32c469d8..40b9da42b2 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -36,7 +36,7 @@ namespace metrics { MeterContext::MeterContext(std::unique_ptr views, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : resource_{resource}, views_(std::move(views)), sdk_start_ts_{std::chrono::system_clock::now()} {} @@ -82,7 +82,7 @@ opentelemetry::common::SystemTimestamp MeterContext::GetSDKStartTime() noexcept void MeterContext::AddMetricReader(std::shared_ptr reader) noexcept { - auto collector = std::shared_ptr{new MetricCollector(this, reader)}; + auto collector = std::shared_ptr{new MetricCollector(this, std::move(reader))}; collectors_.push_back(collector); } @@ -107,7 +107,7 @@ ExemplarFilterType MeterContext::GetExemplarFilter() const noexcept #endif // ENABLE_METRICS_EXEMPLAR_PREVIEW -void MeterContext::AddMeter(std::shared_ptr meter) +void MeterContext::AddMeter(const std::shared_ptr &meter) { std::lock_guard guard(meter_lock_); meters_.push_back(meter); diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 6ddba6aa7c..4f2ca4b44f 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -37,7 +37,7 @@ MeterProvider::MeterProvider(std::unique_ptr context) noexcept {} MeterProvider::MeterProvider(std::unique_ptr views, - sdk::resource::Resource resource) noexcept + const sdk::resource::Resource &resource) noexcept : context_(std::make_shared(std::move(views), resource)) { OTEL_INTERNAL_LOG_DEBUG("[MeterProvider] MeterProvider created."); @@ -110,7 +110,7 @@ const resource::Resource &MeterProvider::GetResource() const noexcept void MeterProvider::AddMetricReader(std::shared_ptr reader) noexcept { - context_->AddMetricReader(reader); + context_->AddMetricReader(std::move(reader)); } void MeterProvider::AddView(std::unique_ptr instrument_selector, diff --git a/sdk/src/metrics/state/metric_collector.cc b/sdk/src/metrics/state/metric_collector.cc index 5ecf41cecf..a790a6b6a1 100644 --- a/sdk/src/metrics/state/metric_collector.cc +++ b/sdk/src/metrics/state/metric_collector.cc @@ -27,7 +27,7 @@ namespace metrics MetricCollector::MetricCollector(opentelemetry::sdk::metrics::MeterContext *context, std::shared_ptr metric_reader) - : meter_context_{context}, metric_reader_{metric_reader} + : meter_context_{context}, metric_reader_{std::move(metric_reader)} { metric_reader_->SetMetricProducer(this); } @@ -48,7 +48,7 @@ bool MetricCollector::Collect( return false; } ResourceMetrics resource_metrics; - meter_context_->ForEachMeter([&](std::shared_ptr meter) noexcept { + meter_context_->ForEachMeter([&](const std::shared_ptr &meter) noexcept { auto collection_ts = std::chrono::system_clock::now(); auto metric_data = meter->Collect(this, collection_ts); if (!metric_data.empty()) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 2ba74d9213..c26339a79f 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -35,7 +35,7 @@ namespace metrics TemporalMetricStorage::TemporalMetricStorage(InstrumentDescriptor instrument_descriptor, AggregationType aggregation_type, const AggregationConfig *aggregation_config) - : instrument_descriptor_(instrument_descriptor), + : instrument_descriptor_(std::move(instrument_descriptor)), aggregation_type_(aggregation_type), aggregation_config_(aggregation_config) {} @@ -44,7 +44,7 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - std::shared_ptr delta_metrics, + const std::shared_ptr &delta_metrics, nostd::function_ref callback) noexcept { std::lock_guard guard(lock_); diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index a99fa80868..56429a079f 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -20,7 +20,7 @@ namespace sdk { namespace metrics { -LongCounter::LongCounter(InstrumentDescriptor instrument_descriptor, +LongCounter::LongCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -80,7 +80,7 @@ void LongCounter::Add(uint64_t value, const opentelemetry::context::Context &con return storage_->RecordLong(value, context); } -DoubleCounter::DoubleCounter(InstrumentDescriptor instrument_descriptor, +DoubleCounter::DoubleCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -164,7 +164,7 @@ void DoubleCounter::Add(double value, const opentelemetry::context::Context &con return storage_->RecordDouble(value, context); } -LongUpDownCounter::LongUpDownCounter(InstrumentDescriptor instrument_descriptor, +LongUpDownCounter::LongUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -228,7 +228,7 @@ void LongUpDownCounter::Add(int64_t value, const opentelemetry::context::Context return storage_->RecordLong(value, context); } -DoubleUpDownCounter::DoubleUpDownCounter(InstrumentDescriptor instrument_descriptor, +DoubleUpDownCounter::DoubleUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -292,7 +292,7 @@ void DoubleUpDownCounter::Add(double value, const opentelemetry::context::Contex return storage_->RecordDouble(value, context); } -LongHistogram::LongHistogram(InstrumentDescriptor instrument_descriptor, +LongHistogram::LongHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -355,7 +355,7 @@ void LongHistogram::Record(uint64_t value) noexcept } #endif -DoubleHistogram::DoubleHistogram(InstrumentDescriptor instrument_descriptor, +DoubleHistogram::DoubleHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { diff --git a/sdk/src/metrics/view/view_factory.cc b/sdk/src/metrics/view/view_factory.cc index 36496f62d6..319c10b956 100644 --- a/sdk/src/metrics/view/view_factory.cc +++ b/sdk/src/metrics/view/view_factory.cc @@ -53,7 +53,7 @@ std::unique_ptr ViewFactory::Create(const std::string &name, auto attributes_processor = std::unique_ptr(new DefaultAttributesProcessor()); - return Create(name, description, unit, aggregation_type, aggregation_config, + return Create(name, description, unit, aggregation_type, std::move(aggregation_config), std::move(attributes_processor)); } @@ -64,7 +64,8 @@ std::unique_ptr ViewFactory::Create(const std::string &name, std::shared_ptr aggregation_config, std::unique_ptr attributes_processor) { - std::unique_ptr view(new View(name, description, unit, aggregation_type, aggregation_config, + std::unique_ptr view(new View(name, description, unit, aggregation_type, + std::move(aggregation_config), std::move(attributes_processor))); return view; } diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 03b79f6ebb..6aa6a49949 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -29,7 +29,6 @@ #include "opentelemetry/version.h" using opentelemetry::sdk::common::AtomicUniquePtr; -using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; using opentelemetry::trace::SpanContext; diff --git a/sdk/src/trace/samplers/parent.cc b/sdk/src/trace/samplers/parent.cc index a69ede92d4..9bffb7b030 100644 --- a/sdk/src/trace/samplers/parent.cc +++ b/sdk/src/trace/samplers/parent.cc @@ -22,7 +22,7 @@ namespace sdk { namespace trace { -ParentBasedSampler::ParentBasedSampler(std::shared_ptr delegate_sampler) noexcept +ParentBasedSampler::ParentBasedSampler(const std::shared_ptr &delegate_sampler) noexcept : delegate_sampler_(delegate_sampler), description_("ParentBased{" + std::string{delegate_sampler->GetDescription()} + "}") {} diff --git a/sdk/src/trace/samplers/parent_factory.cc b/sdk/src/trace/samplers/parent_factory.cc index 978fb75946..7f1bc088d6 100644 --- a/sdk/src/trace/samplers/parent_factory.cc +++ b/sdk/src/trace/samplers/parent_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/samplers/parent_factory.h" +#include + #include "opentelemetry/sdk/trace/samplers/parent.h" +#include "opentelemetry/sdk/trace/samplers/parent_factory.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,9 +14,9 @@ namespace trace { std::unique_ptr ParentBasedSamplerFactory::Create( - std::shared_ptr delegate_sampler) + const std::shared_ptr &delegate_sampler) { - std::unique_ptr sampler(new ParentBasedSampler(delegate_sampler)); + std::unique_ptr sampler(new ParentBasedSampler(std::move(delegate_sampler))); return sampler; } diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index ca3a475707..2b9e9d2908 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -78,7 +78,7 @@ Span::Span(std::shared_ptr &&tracer, return true; }); - links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, + links.ForEachKeyValue([&](const opentelemetry::trace::SpanContext &span_context, const common::KeyValueIterable &attributes) { recordable_->AddLink(span_context, attributes); return true; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index fd02548c7b..73fc08d5dc 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -39,7 +39,7 @@ namespace trace Tracer::Tracer(std::shared_ptr context, std::unique_ptr instrumentation_scope) noexcept - : instrumentation_scope_{std::move(instrumentation_scope)}, context_{context} + : instrumentation_scope_{std::move(instrumentation_scope)}, context_{std::move(context)} {} nostd::shared_ptr Tracer::StartSpan( diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc index 0fb4fd35cf..65300d6f22 100644 --- a/sdk/src/trace/tracer_context.cc +++ b/sdk/src/trace/tracer_context.cc @@ -22,7 +22,7 @@ namespace trace namespace resource = opentelemetry::sdk::resource; TracerContext::TracerContext(std::vector> &&processors, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept : resource_(resource), diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 9440e3d469..3b5462a083 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -38,7 +38,7 @@ TracerProvider::TracerProvider(std::unique_ptr context) noexcept } TracerProvider::TracerProvider(std::unique_ptr processor, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { @@ -49,7 +49,7 @@ TracerProvider::TracerProvider(std::unique_ptr processor, } TracerProvider::TracerProvider(std::vector> &&processors, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { diff --git a/sdk/test/common/empty_attributes_test.cc b/sdk/test/common/empty_attributes_test.cc index f37ea0a5c4..894cafc8a7 100644 --- a/sdk/test/common/empty_attributes_test.cc +++ b/sdk/test/common/empty_attributes_test.cc @@ -15,5 +15,5 @@ TEST(EmptyAttributesTest, TestMemory) { auto attributes1 = opentelemetry::sdk::GetEmptyAttributes(); auto attributes2 = opentelemetry::sdk::GetEmptyAttributes(); - EXPECT_EQ(memcmp(&attributes1, &attributes2, sizeof(attributes1)), 0); + EXPECT_EQ(memcmp(&attributes1, &attributes2, sizeof(attributes1)), 0); // NOLINT } diff --git a/sdk/test/logs/batch_log_record_processor_test.cc b/sdk/test/logs/batch_log_record_processor_test.cc index 33db0da479..3bdd849938 100644 --- a/sdk/test/logs/batch_log_record_processor_test.cc +++ b/sdk/test/logs/batch_log_record_processor_test.cc @@ -9,6 +9,7 @@ #include #include #include +#include using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -74,10 +75,10 @@ class MockLogExporter final : public LogRecordExporter std::shared_ptr> is_shutdown, std::shared_ptr> is_export_completed, const std::chrono::milliseconds export_delay = std::chrono::milliseconds(0)) - : logs_received_(logs_received), - force_flush_counter_(force_flush_counter), - is_shutdown_(is_shutdown), - is_export_completed_(is_export_completed), + : logs_received_(std::move(logs_received)), + force_flush_counter_(std::move(force_flush_counter)), + is_shutdown_(std::move(is_shutdown)), + is_export_completed_(std::move(is_export_completed)), export_delay_(export_delay) {} @@ -154,7 +155,8 @@ class BatchLogRecordProcessorTest : public testing::Test // ::testing::Test { return std::shared_ptr(new BatchLogRecordProcessor( std::unique_ptr(new MockLogExporter( - logs_received, force_flush_counter, is_shutdown, is_export_completed, export_delay)), + std::move(logs_received), std::move(force_flush_counter), std::move(is_shutdown), + std::move(is_export_completed), export_delay)), max_queue_size, scheduled_delay_millis, max_export_batch_size)); } }; diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 62d523b92a..9e63672d3c 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -3,6 +3,7 @@ #include #include +#include #include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/nostd/string_view.h" @@ -172,7 +173,7 @@ class MockProcessor final : public LogRecordProcessor public: // A processor used for testing that keeps a track of the recordable it received explicit MockProcessor(std::shared_ptr record_received) noexcept - : record_received_(record_received) + : record_received_(std::move(record_received)) {} std::unique_ptr MakeRecordable() noexcept override diff --git a/sdk/test/logs/simple_log_record_processor_test.cc b/sdk/test/logs/simple_log_record_processor_test.cc index 484cc63e71..30e5771394 100644 --- a/sdk/test/logs/simple_log_record_processor_test.cc +++ b/sdk/test/logs/simple_log_record_processor_test.cc @@ -10,6 +10,7 @@ #include #include +#include using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -75,7 +76,7 @@ class TestExporter final : public LogRecordExporter size_t *batch_size_received) : force_flush_counter_(force_flush_counter), shutdown_counter_(shutdown_counter), - logs_received_(logs_received), + logs_received_(std::move(logs_received)), batch_size_received(batch_size_received) {} diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index 10c0335559..b7ad885bbd 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -12,6 +12,7 @@ using namespace opentelemetry::sdk::metrics; using M = std::map; +// NOLINTNEXTLINE void asyc_generate_measurements(opentelemetry::metrics::ObserverResult /* observer */, void * /* state */) {} diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 3b72e99d96..dcbe105418 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -262,7 +262,7 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); storage.Collect( - collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) { + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (auto data_attr : metric_data.point_data_attr_) { auto data = opentelemetry::nostd::get(data_attr.point_data); @@ -288,7 +288,7 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) storage.RecordLong(measurements2, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); storage.Collect( - collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) { + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (auto data_attr : metric_data.point_data_attr_) { auto data = opentelemetry::nostd::get(data_attr.point_data); diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index 8c2edb4b0c..3f9483ac1c 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -26,7 +26,7 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) return std::unique_ptr(new LongSumAggregation(true)); }; // add 10 unique metric points. 9 should be added to hashmap, 10th should be overflow. - long record_value = 100; + int64_t record_value = 100; for (auto i = 0; i < 10; i++) { FilteredOrderedAttributeMap attributes = {{"key", std::to_string(i)}}; @@ -76,7 +76,7 @@ TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregati #endif nullptr, attributes_limit); - long record_value = 100; + int64_t record_value = 100; // add 9 unique metric points, and 6 more above limit. for (auto i = 0; i < 15; i++) { diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 172df1af3c..28c6d4a4fd 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -19,9 +19,9 @@ TEST(InstrumentMetadataValidator, TestName) { opentelemetry::sdk::metrics::InstrumentMetaDataValidator validator; std::vector invalid_names = { - "", // empty string - "1sdf", // string starting with number - "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42" // unicode characters + "", // empty string + "1sdf", // string starting with number + "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42", // unicode characters "/\\sdsd", // string starting with special character "***sSSs", // string starting with special character "a\\broken\\path", // contains backward slash diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index 084f50fc09..b5ed86f55a 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -18,7 +18,7 @@ using namespace opentelemetry::sdk::metrics; namespace { nostd::shared_ptr InitMeter(MetricReader **metricReaderPtr, - std::string meter_name = "meter_name") + const std::string &meter_name = "meter_name") { static std::shared_ptr provider(new MeterProvider()); std::unique_ptr metric_reader(new MockMetricReader()); diff --git a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc index 216574a587..88ae56eb3f 100644 --- a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc @@ -71,7 +71,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -105,7 +105,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(data.start_ts, sdk_start_ts); @@ -147,7 +147,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -224,7 +224,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -259,7 +259,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(data.start_ts, sdk_start_ts); @@ -301,7 +301,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index e6b56cae43..419264862c 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -25,7 +25,8 @@ namespace nostd = opentelemetry::nostd; class TestResource : public Resource { public: - TestResource(ResourceAttributes attributes = ResourceAttributes(), std::string schema_url = {}) + TestResource(const ResourceAttributes &attributes = ResourceAttributes(), + const std::string &schema_url = {}) : Resource(attributes, schema_url) {} }; @@ -122,10 +123,10 @@ TEST(ResourceTest, create_with_emptyatrributes) TEST(ResourceTest, create_with_schemaurl) { - const std::string schema_url = "https://opentelemetry.io/schemas/1.2.0"; - ResourceAttributes attributes = {}; - auto resource = Resource::Create(attributes, schema_url); - auto received_schema_url = resource.GetSchemaURL(); + const std::string schema_url = "https://opentelemetry.io/schemas/1.2.0"; + ResourceAttributes attributes = {}; + auto resource = Resource::Create(attributes, schema_url); + const auto &received_schema_url = resource.GetSchemaURL(); EXPECT_EQ(received_schema_url, schema_url); } diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index 411b4dacfe..9bb09d6e55 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -16,6 +16,7 @@ #include #include #include +#include OPENTELEMETRY_BEGIN_NAMESPACE @@ -32,10 +33,10 @@ class MockSpanExporter final : public sdk::trace::SpanExporter std::shared_ptr> is_export_completed = std::shared_ptr>(new std::atomic(false)), const std::chrono::milliseconds export_delay = std::chrono::milliseconds(0)) noexcept - : spans_received_(spans_received), - shut_down_counter_(shut_down_counter), - is_shutdown_(is_shutdown), - is_export_completed_(is_export_completed), + : spans_received_(std::move(spans_received)), + shut_down_counter_(std::move(shut_down_counter)), + is_shutdown_(std::move(is_shutdown)), + is_export_completed_(std::move(is_export_completed)), export_delay_(export_delay) {} @@ -96,7 +97,7 @@ class BatchSpanProcessorTestPeer : public testing::Test { public: std::unique_ptr>> GetTestSpans( - std::shared_ptr processor, + const std::shared_ptr &processor, const int num_spans) { std::unique_ptr>> test_spans( diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 98d00843dd..6dfc09bd12 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -96,8 +96,8 @@ TEST(SpanData, EventAttributes) TEST(SpanData, Resources) { SpanData data; - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - auto input_attr = resource.GetAttributes(); + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + const auto &input_attr = resource.GetAttributes(); data.SetResource(resource); auto output_attr = data.GetResource().GetAttributes(); EXPECT_EQ(input_attr, output_attr); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 99bab95b0f..c57b638e3d 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -20,7 +20,6 @@ using opentelemetry::common::SystemTimestamp; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; namespace trace_api = opentelemetry::trace; -using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; From 63fa4fde4ec7d1151cbf4095e442ec1f96dcb4a1 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 12 Jul 2024 12:17:04 +0200 Subject: [PATCH 21/71] [CI] Build failures with ABSEIL 20240116 and CMAKE 3.30 (#3002) --- ci/fix-abseil-cpp-issue-1536.patch | 23 +++++++++++++++++++ ci/install_abseil.sh | 37 ++++++++++++++++++++++++++++++ tools/format.sh | 4 ++-- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 ci/fix-abseil-cpp-issue-1536.patch diff --git a/ci/fix-abseil-cpp-issue-1536.patch b/ci/fix-abseil-cpp-issue-1536.patch new file mode 100644 index 0000000000..7004cf0479 --- /dev/null +++ b/ci/fix-abseil-cpp-issue-1536.patch @@ -0,0 +1,23 @@ +commit 779a3565ac6c5b69dd1ab9183e500a27633117d5 +Author: Derek Mauro +Date: Tue Jan 30 10:13:25 2024 -0800 + + Avoid export of testonly target absl::test_allocator in CMake builds + + Closes #1536 + + PiperOrigin-RevId: 602764437 + Change-Id: Ia5c20a3874262a2ddb8797f608af17d7e86dd6d6 + +diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt +index 449a2cad..ee9ca9c3 100644 +--- a/absl/container/CMakeLists.txt ++++ b/absl/container/CMakeLists.txt +@@ -213,6 +213,7 @@ absl_cc_library( + DEPS + absl::config + GTest::gmock ++ TESTONLY + ) + + absl_cc_test( diff --git a/ci/install_abseil.sh b/ci/install_abseil.sh index 46a7870627..ced090cc64 100755 --- a/ci/install_abseil.sh +++ b/ci/install_abseil.sh @@ -7,6 +7,8 @@ set -ex export DEBIAN_FRONTEND=noninteractive [ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20240116.1" +TOPDIR=`pwd` + BUILD_DIR=/tmp/ INSTALL_DIR=/usr/local/ pushd $BUILD_DIR @@ -22,6 +24,41 @@ if [ ! -z "${CXX_STANDARD}" ]; then ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") fi +# +# ABSEIL_CPP_VERSION="20240116.1" fails to build with CMake 3.30 +# ABSEIL_CPP_VERSION="20240116.2" fails to build with CMake 3.30 +# note that somehow the same builds with CMake 3.29.6 +# +# Error reported: +# CMake Error at CMake/AbseilHelpers.cmake:317 (target_link_libraries): +# The link interface of target "test_allocator" contains: +# +# GTest::gmock +# +# but the target was not found. Possible reasons include: +# +# * There is a typo in the target name. +# * A find_package call is missing for an IMPORTED target. +# * An ALIAS target is missing. +# +# Call Stack (most recent call first): +# absl/container/CMakeLists.txt:206 (absl_cc_library) +# +# Root cause: +# https://github.com/abseil/abseil-cpp/pull/1536 +# +# Applying fix from abseil commit 779a3565ac6c5b69dd1ab9183e500a27633117d5 +# +# TODO(marcalff) Cleanup once abseil is upgraded to the next LTS + + +if [ "${ABSEIL_CPP_VERSION}" = "20240116.1" ] || [ "${ABSEIL_CPP_VERSION}" = "20240116.2" ]; then + echo "Patching abseil" + patch -p1 < ${TOPDIR}/ci/fix-abseil-cpp-issue-1536.patch +else + echo "Not patching abseil" +fi + mkdir build && pushd build cmake "${ABSEIL_CPP_BUILD_OPTIONS[@]}" .. make -j $(nproc) diff --git a/tools/format.sh b/tools/format.sh index 65728b385f..3a3863a8ea 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -23,8 +23,8 @@ fi # No CRLF line endings, except Windows files. "${SED[@]}" 's/\r$//' $($FIND -name '*.ps1' -prune -o \ -name '*.cmd' -prune -o -type f -print) -# No trailing spaces. -"${SED[@]}" 's/ \+$//' $($FIND -type f -print) +# No trailing spaces, except in patch. +"${SED[@]}" 's/ \+$//' $($FIND -name "*.patch" -prune -o -type f -print) # If not overridden, try to use clang-format-18 or clang-format. if [[ -z "$CLANG_FORMAT" ]]; then From 323a279ec5b2e91f26630830464fb45a3ad10564 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 12 Jul 2024 14:03:17 -0700 Subject: [PATCH 22/71] [CI] Enable bzlmod (#2995) --- .bazelrc | 3 --- MODULE.bazel | 4 ++-- ci/do_ci.ps1 | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.bazelrc b/.bazelrc index fc170b0e8b..f169347647 100644 --- a/.bazelrc +++ b/.bazelrc @@ -4,9 +4,6 @@ # bazel configurations for running tests under sanitizers. # Based on https://github.com/bazelment/trunk/blob/master/tools/bazel.rc -# TODO: Remove once support is added, avoid MODULE.bazel creation for now -common --enable_bzlmod=false - # Enable automatic configs based on platform common --enable_platform_specific_config diff --git a/MODULE.bazel b/MODULE.bazel index 7b84c2b719..4a03753e15 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,8 +10,8 @@ module( bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "com_google_absl") bazel_dep(name = "bazel_skylib", version = "1.5.0") -bazel_dep(name = "curl", version = "8.4.0") -bazel_dep(name = "grpc", version = "1.62.1", repo_name = "com_github_grpc_grpc") +bazel_dep(name = "curl", version = "8.8.0") +bazel_dep(name = "grpc", version = "1.63.1.bcr.1", repo_name = "com_github_grpc_grpc") bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohmann_json") bazel_dep(name = "opentelemetry-proto", version = "1.3.1", repo_name = "com_github_opentelemetry_proto") bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing") diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 62e174854e..bcae6359bb 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -11,8 +11,8 @@ $nproc = (Get-ComputerInfo).CsNumberOfLogicalProcessors $SRC_DIR = (Get-Item -Path ".\").FullName # Workaround https://github.com/bazelbuild/bazel/issues/18683 -$BAZEL_STARTUP_OPTIONS = "--output_base=C:\Out" -$BAZEL_OPTIONS = "--copt=-DENABLE_ASYNC_EXPORT" +$BAZEL_STARTUP_OPTIONS = "--output_base=C:\O" +$BAZEL_OPTIONS = "--copt=-DENABLE_ASYNC_EXPORT --compilation_mode=dbg" $BAZEL_TEST_OPTIONS = "$BAZEL_OPTIONS --test_output=errors" if (!(test-path build)) { From d8ae09e53d6988a063364c86a8362053432a3f9f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 17 Jul 2024 07:00:20 -0700 Subject: [PATCH 23/71] [Metrics SDK] Fix hash calculation for nostd::string (#2999) * add test to validate cardinaity limit * format * warning * Format * maint mode CI * modify test to reproduce the issue * Format * remove vscode settings * remove redundant test * remove unused code * fix to calculate hash on string_view * remove iostream * template specialization for const char *, and varous string type tests * unused variable warning * more warnings * format * fix use-after-stack-scope * format * another try * format --------- Co-authored-by: Tom Tan --- .../sdk/common/attributemap_hash.h | 11 ++- sdk/test/metrics/attributes_hashmap_test.cc | 76 ++++++++++++++++++- sdk/test/metrics/cardinality_limit_test.cc | 41 +++++++++- 3 files changed, 122 insertions(+), 6 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h index 408070255a..e09b03d08b 100644 --- a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h +++ b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h @@ -35,6 +35,15 @@ inline void GetHash(size_t &seed, const std::vector &arg) } } +// Specialization for const char* +// this creates an intermediate string. +template <> +inline void GetHash(size_t &seed, const char *const &arg) +{ + std::hash hasher; + seed ^= hasher(std::string(arg)) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} + struct GetHashForAttributeValueVisitor { GetHashForAttributeValueVisitor(size_t &seed) : seed_(seed) {} @@ -71,7 +80,7 @@ inline size_t GetHashForAttributeMap( { return true; } - GetHash(seed, key.data()); + GetHash(seed, key); auto attr_val = nostd::visit(converter, value); nostd::visit(GetHashForAttributeValueVisitor(seed), attr_val); return true; diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index 7e03deed47..9ae8f5cfd5 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -13,7 +13,6 @@ namespace nostd = opentelemetry::nostd; TEST(AttributesHashMap, BasicTests) { - // Empty map AttributesHashMap hash_map; EXPECT_EQ(hash_map.Size(), 0); @@ -73,3 +72,78 @@ TEST(AttributesHashMap, BasicTests) }); EXPECT_EQ(count, hash_map.Size()); } + +std::string make_unique_string(const char *str) +{ + return std::string(str); +} + +TEST(AttributesHashMap, HashWithKeyValueIterable) +{ + std::string key1 = make_unique_string("k1"); + std::string value1 = make_unique_string("v1"); + std::string key2 = make_unique_string("k2"); + std::string value2 = make_unique_string("v2"); + std::string key3 = make_unique_string("k3"); + std::string value3 = make_unique_string("v3"); + + // Create mock KeyValueIterable instances with the same content but different variables + std::map attributes1({{key1, value1}, {key2, value2}}); + std::map attributes2({{key1, value1}, {key2, value2}}); + std::map attributes3({{key1, value1}, {key2, value2}, {key3, value3}}); + + // Create a callback that filters "k3" key + auto is_key_filter_k3_callback = [](nostd::string_view key) { + if (key == "k3") + { + return false; + } + return true; + }; + // Calculate hash + size_t hash1 = opentelemetry::sdk::common::GetHashForAttributeMap( + opentelemetry::common::KeyValueIterableView>(attributes1), + is_key_filter_k3_callback); + size_t hash2 = opentelemetry::sdk::common::GetHashForAttributeMap( + opentelemetry::common::KeyValueIterableView>(attributes2), + is_key_filter_k3_callback); + + size_t hash3 = opentelemetry::sdk::common::GetHashForAttributeMap( + opentelemetry::common::KeyValueIterableView>(attributes3), + is_key_filter_k3_callback); + + // Expect the hashes to be the same because the content is the same + EXPECT_EQ(hash1, hash2); + // Expect the hashes to be the same because the content is the same + EXPECT_EQ(hash1, hash3); +} + +TEST(AttributesHashMap, HashConsistencyAcrossStringTypes) +{ + const char *c_str = "teststring"; + std::string std_str = "teststring"; + nostd::string_view nostd_str_view = "teststring"; +#if __cplusplus >= 201703L + std::string_view std_str_view = "teststring"; +#endif + + size_t hash_c_str = 0; + size_t hash_std_str = 0; + size_t hash_nostd_str_view = 0; +#if __cplusplus >= 201703L + size_t hash_std_str_view = 0; +#endif + + opentelemetry::sdk::common::GetHash(hash_c_str, c_str); + opentelemetry::sdk::common::GetHash(hash_std_str, std_str); + opentelemetry::sdk::common::GetHash(hash_nostd_str_view, nostd_str_view); +#if __cplusplus >= 201703L + opentelemetry::sdk::common::GetHash(hash_std_str_view, std_str_view); +#endif + + EXPECT_EQ(hash_c_str, hash_std_str); + EXPECT_EQ(hash_c_str, hash_nostd_str_view); +#if __cplusplus >= 201703L + EXPECT_EQ(hash_c_str, hash_std_str_view); +#endif +} diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index 3f9483ac1c..cf94112f1a 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -47,14 +47,47 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) ->Aggregate(record_value); } EXPECT_EQ(hash_map.Size(), 10); // only one more metric point should be added as overflow. + // record 5 more measurements to already existing (and not-overflow) metric points. They + // should get aggregated to these existing metric points. + for (auto i = 0; i < 5; i++) + { + FilteredOrderedAttributeMap attributes = {{"key", std::to_string(i)}}; + auto hash = opentelemetry::sdk::common::GetHashForAttributeMap(attributes); + static_cast( + hash_map.GetOrSetDefault(attributes, aggregation_callback, hash)) + ->Aggregate(record_value); + } + EXPECT_EQ(hash_map.Size(), 10); // no new metric point added + // get the overflow metric point - auto agg = hash_map.GetOrSetDefault( + auto agg1 = hash_map.GetOrSetDefault( FilteredOrderedAttributeMap({{kAttributesLimitOverflowKey, kAttributesLimitOverflowValue}}), aggregation_callback, kOverflowAttributesHash); - EXPECT_NE(agg, nullptr); - auto sum_agg = static_cast(agg); - EXPECT_EQ(nostd::get(nostd::get(sum_agg->ToPoint()).value_), + EXPECT_NE(agg1, nullptr); + auto sum_agg1 = static_cast(agg1); + EXPECT_EQ(nostd::get(nostd::get(sum_agg1->ToPoint()).value_), record_value * 6); // 1 from previous 10, 5 from current 5. + // get remaining metric points + for (auto i = 0; i < 9; i++) + { + FilteredOrderedAttributeMap attributes = {{"key", std::to_string(i)}}; + auto hash = opentelemetry::sdk::common::GetHashForAttributeMap(attributes); + auto agg2 = hash_map.GetOrSetDefault( + FilteredOrderedAttributeMap({{kAttributesLimitOverflowKey, kAttributesLimitOverflowValue}}), + aggregation_callback, hash); + EXPECT_NE(agg2, nullptr); + auto sum_agg2 = static_cast(agg2); + if (i < 5) + { + EXPECT_EQ(nostd::get(nostd::get(sum_agg2->ToPoint()).value_), + record_value * 2); // 1 from first recording, 1 from third recording + } + else + { + EXPECT_EQ(nostd::get(nostd::get(sum_agg2->ToPoint()).value_), + record_value); // 1 from first recording + } + } } class WritableMetricStorageCardinalityLimitTestFixture From baecbb95bd63df53e0af16e87bc683967962c5f8 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 17 Jul 2024 22:04:10 +0200 Subject: [PATCH 24/71] [RELEASE] Release opentelemetry-cpp version 1.16.1 (#3007) --- CHANGELOG.md | 39 ++++++++++++++++++- api/include/opentelemetry/version.h | 4 +- docs/public/conf.py | 2 +- .../opentelemetry/sdk/version/version.h | 2 +- sdk/src/version/version.cc | 8 ++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e234a77b..fad2b0cc78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,15 +15,50 @@ Increment the: ## [Unreleased] +## [1.16.1 2024-07-17] + +* [BUILD] Add bazel missing BUILD file + [#2720](https://github.com/open-telemetry/opentelemetry-cpp/pull/2720) + +* [SDK] Added reserve for spans array in BatchSpanProcessor. + [#2724](https://github.com/open-telemetry/opentelemetry-cpp/pull/2724) + +* [DOC] Update "Using triplets" section in building-with-vcpkg documentation. + [#2726](https://github.com/open-telemetry/opentelemetry-cpp/pull/2726) + +* [DOC] Remove comment for unused LoggerProvider initialization params + [#2972](https://github.com/open-telemetry/opentelemetry-cpp/pull/2972) + * [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1, require TLS 1.2 or better - [#2721](https://github.com/open-telemetry/opentelemetry-cpp/pull/2721) + [#2722](https://github.com/open-telemetry/opentelemetry-cpp/pull/2722) + +* [TEST] Fix opentelemetry-collector bind address + [#2989](https://github.com/open-telemetry/opentelemetry-cpp/pull/2989) + +* [EXPORTER] Fix references in AttributeValueVisitor + [#2985](https://github.com/open-telemetry/opentelemetry-cpp/pull/2985) + +* [Code health] include-what-you-use cleanup, part 2 + [#2704](https://github.com/open-telemetry/opentelemetry-cpp/pull/2704) + +* [Code Health] clang-tidy cleanup, part 1 + [#2990](https://github.com/open-telemetry/opentelemetry-cpp/pull/2990) + +* [CI] Build failures with ABSEIL 20240116 and CMAKE 3.30 + [#3002](https://github.com/open-telemetry/opentelemetry-cpp/pull/3002) + +* [CI] Enable bzlmod + [#2995](https://github.com/open-telemetry/opentelemetry-cpp/pull/2995) + +* [Metrics SDK] Fix hash calculation for nostd::string + [#2999](https://github.com/open-telemetry/opentelemetry-cpp/pull/2999) Breaking changes: * [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1, require TLS 1.2 or better - [#2721](https://github.com/open-telemetry/opentelemetry-cpp/pull/2721) + [#2722](https://github.com/open-telemetry/opentelemetry-cpp/pull/2722) * The OTLP HTTP exporter no longer accept options like: * min_TLS = 1.0 * min_TLS = 1.1 diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index e09c193659..d98ac978f2 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -10,10 +10,10 @@ # define OPENTELEMETRY_ABI_VERSION_NO 1 #endif -#define OPENTELEMETRY_VERSION "1.16.0" +#define OPENTELEMETRY_VERSION "1.16.1" #define OPENTELEMETRY_VERSION_MAJOR 1 #define OPENTELEMETRY_VERSION_MINOR 16 -#define OPENTELEMETRY_VERSION_PATCH 0 +#define OPENTELEMETRY_VERSION_PATCH 1 #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) diff --git a/docs/public/conf.py b/docs/public/conf.py index 927e07751a..96caa2b43a 100644 --- a/docs/public/conf.py +++ b/docs/public/conf.py @@ -24,7 +24,7 @@ author = 'OpenTelemetry authors' # The full version, including alpha/beta/rc tags -release = "1.16.0" +release = "1.16.1" # Run sphinx on subprojects and copy output # ----------------------------------------- diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index bfc93238b4..86b815e3bc 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -3,7 +3,7 @@ #pragma once -#define OPENTELEMETRY_SDK_VERSION "1.16.0" +#define OPENTELEMETRY_SDK_VERSION "1.16.1" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index e5fdbda99d..80f2226400 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -13,12 +13,12 @@ namespace version { const int major_version = 1; const int minor_version = 16; -const int patch_version = 0; +const int patch_version = 1; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.16.0"; -const char *full_version = "1.16.0-NONE-NONE"; -const char *build_date = "Fri Jun 21 16:41:17 UTC 2024"; +const char *short_version = "1.16.1"; +const char *full_version = "1.16.1-NONE-NONE"; +const char *build_date = "Wed Jul 17 17:34:38 UTC 2024"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From aac2b775afa77840b91a37b4a959c9afae03a06b Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Wed, 17 Jul 2024 17:19:41 -0400 Subject: [PATCH 25/71] [CI] Add a clang-tidy build (#3001) --- .clang-tidy | 48 ++++-------------- .github/workflows/clang-tidy.yaml | 84 +++++++++++++++++++++++++++++++ CHANGELOG.md | 3 ++ CMakeLists.txt | 6 +++ 4 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/clang-tidy.yaml diff --git a/.clang-tidy b/.clang-tidy index 5abedb62fd..9a30fbef54 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,8 @@ Checks: > -*, + performance-*, + portability-*, abseil-*, -abseil-string-find-str-contains, bugprone-*, @@ -13,7 +15,6 @@ Checks: > -bugprone-unchecked-optional-access, -bugprone-unhandled-exception-at-new, -bugprone-unused-local-non-trivial-variable, - -bugprone-unused-return-value, google-*, -google-build-using-namespace, -google-default-arguments, @@ -29,41 +30,10 @@ Checks: > -misc-non-private-member-variables-in-classes, -misc-unused-alias-decls, -misc-use-anonymous-namespace, - performance-*, - -performance-move-const-arg, - portability-* -# readability-*, -# -readability-convert-member-functions-to-static, -# -readability-else-after-return, -# -readability-function-cognitive-complexity, -# -readability-identifier-length, -# -readability-implicit-bool-conversion, -# -readability-isolate-declaration, -# -readability-magic-numbers, -# -readability-named-parameter, -# -readability-redundant-*, -# -readability-string-compare, -# cppcoreguidelines-*, -# -cppcoreguidelines-avoid-c-arrays, -# -cppcoreguidelines-avoid-magic-numbers, -# -cppcoreguidelines-init-variables, -# -cppcoreguidelines-macro-usage, -# -cppcoreguidelines-non-private-member-variables-in-classes, -# -cppcoreguidelines-pro-*, -# modernize-*, -# -modernize-use-default-member-init, -# -modernize-use-nodiscard, -# -modernize-use-trailing-return-type, -# -modernize-avoid-c-arrays, -# -modernize-use-using - -# Use existing clang-format for formatting the code -# FormatStyle: 'file' - -# TODO: include checks: readability, cppcoreguidelines, modernize , google-readability-namespace-comments, google-readability-avoid-underscore-in-googletest-name, performance-move-const-arg - - - - - - + cppcoreguidelines-*, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-pro-* \ No newline at end of file diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml new file mode 100644 index 0000000000..9e5f6c26db --- /dev/null +++ b/.github/workflows/clang-tidy.yaml @@ -0,0 +1,84 @@ +name: clang-tidy + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + clang-tidy: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Environment + env: + PROTOBUF_VERSION: '23.3' + ABSEIL_CPP_VERSION: '20230125.3' + CXX_STANDARD: '14' + run: | + sudo apt update -y + sudo apt install -y --no-install-recommends --no-install-suggests \ + build-essential \ + iwyu \ + cmake \ + libssl-dev \ + libcurl4-openssl-dev \ + libprotobuf-dev \ + protobuf-compiler \ + libgmock-dev \ + libgtest-dev \ + libbenchmark-dev + + if ! command -v clang-tidy &> /dev/null; then + echo "clang-tidy could not be found" + exit 1 + fi + echo "Using clang-tidy version: $(clang-tidy --version)" + echo "clang-tidy installed at: $(which clang-tidy)" + + + - name: Prepare CMake + env: + CC: clang + CXX: clang++ + run: | + mkdir -p build && cd build + echo "Running cmake..." + cmake .. \ + -DCMAKE_CXX_STANDARD=14 \ + -DWITH_STL=CXX14 \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_FILE=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_ZIPKIN=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_CLANG_TIDY="clang-tidy" + + - name: Run clang-tidy + run: | + cd build + make -j$(nproc) 2>&1 | tee -a clang-tidy.log || exit 1 + + - uses: actions/upload-artifact@v4 + with: + name: Logs (clang-tidy) + path: ./build/clang-tidy.log + + - name: Count warnings + run: | + cd build + COUNT=$(grep -c "warning:" clang-tidy.log) + echo "clang-tidy reported ${COUNT} warning(s)" + +# TODO: include WITH_OTLP_GRPC and WITH_ABSEIL flags. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fad2b0cc78..e7e13ec3d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [CI] Add a clang-tidy build + [#3001](https://github.com/open-telemetry/opentelemetry-cpp/pull/3001) + ## [1.16.1 2024-07-17] * [BUILD] Add bazel missing BUILD file diff --git a/CMakeLists.txt b/CMakeLists.txt index 711ac14c4c..44ddd05e1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -364,9 +364,12 @@ if(WITH_PROMETHEUS) message(STATUS "Trying to use local prometheus-cpp from submodule") if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git) set(SAVED_ENABLE_TESTING ${ENABLE_TESTING}) + set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY}) set(ENABLE_TESTING OFF) + set(CMAKE_CXX_CLANG_TIDY "") add_subdirectory(third_party/prometheus-cpp) set(ENABLE_TESTING ${SAVED_ENABLE_TESTING}) + set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY}) else() message( FATAL_ERROR @@ -444,7 +447,10 @@ if(WITH_OTLP_GRPC include(CMakeDependentOption) message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}") + set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY}) + set(CMAKE_CXX_CLANG_TIDY "") include(cmake/opentelemetry-proto.cmake) + set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY}) endif() # From 0a43c1f2b16e2636e7c768c88957c4f0e4d3f8ce Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 18 Jul 2024 00:48:26 +0200 Subject: [PATCH 26/71] [BUILD] Upgrade to opentelemetry-proto 1.3.2 (#2991) --- MODULE.bazel | 2 +- bazel/repository.bzl | 6 +- cmake/opentelemetry-proto.cmake | 2 +- docs/maintaining-dependencies.md | 321 +++++++++++++++++++++++++++++++ third_party/opentelemetry-proto | 2 +- third_party_release | 2 +- 6 files changed, 328 insertions(+), 7 deletions(-) create mode 100644 docs/maintaining-dependencies.md diff --git a/MODULE.bazel b/MODULE.bazel index 4a03753e15..311d4cbc16 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,7 +13,7 @@ bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "curl", version = "8.8.0") bazel_dep(name = "grpc", version = "1.63.1.bcr.1", repo_name = "com_github_grpc_grpc") bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohmann_json") -bazel_dep(name = "opentelemetry-proto", version = "1.3.1", repo_name = "com_github_opentelemetry_proto") +bazel_dep(name = "opentelemetry-proto", version = "1.3.2", repo_name = "com_github_opentelemetry_proto") bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing") bazel_dep(name = "platforms", version = "0.0.8") bazel_dep(name = "prometheus-cpp", version = "1.2.4", repo_name = "com_github_jupp0r_prometheus_cpp") diff --git a/bazel/repository.bzl b/bazel/repository.bzl index bac1e45b34..508b95a39a 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -88,10 +88,10 @@ def opentelemetry_cpp_deps(): http_archive, name = "com_github_opentelemetry_proto", build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", - sha256 = "bed250ceec8e4a83aa5604d7d5595a61945059dc662edd058a9da082283f7a00", - strip_prefix = "opentelemetry-proto-1.3.1", + sha256 = "c069c0d96137cf005d34411fa67dd3b6f1f8c64af1e7fb2fe0089a41c425acd7", + strip_prefix = "opentelemetry-proto-1.3.2", urls = [ - "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.1.tar.gz", + "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.2.tar.gz", ], ) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 62197068e2..498a7e5681 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -49,7 +49,7 @@ else() "opentelemetry-proto=[ \\t]*([A-Za-z0-9_\\.\\-]+)") set(opentelemetry-proto "${CMAKE_MATCH_1}") else() - set(opentelemetry-proto "v1.3.1") + set(opentelemetry-proto "v1.3.2") endif() unset(OTELCPP_THIRD_PARTY_RELEASE_CONTENT) endif() diff --git a/docs/maintaining-dependencies.md b/docs/maintaining-dependencies.md new file mode 100644 index 0000000000..a1969785d8 --- /dev/null +++ b/docs/maintaining-dependencies.md @@ -0,0 +1,321 @@ + +# Maintaining dependencies + +In general, several places in the code base need to be adjusted when +upgrading a dependency to a new version. + +This documentation contains notes about which place to fix, +to make maintenance easier and less error prone. + +This doc is only useful when up to date, +so make sure to add details about missing parts if any. + +Also, another good place to start when upgrading something to N+1 +is to find the commit that upgraded to version N (use `git blame`), +and inspect the commit for the last upgrade. + +## opentelemetry-proto + +### Comments + +Unlike other opentelemetry SIGs, opentelemetry-cpp generates code +from opentelemetry-proto as part of the opentelemetry-cpp build. + +Only the source code of opentelemetry-proto is required, +which is why this repository is used as a git submodule under third_party. + +Code is generated by the protobuf compiler during the build, +so that generated code is never checked in. + +This allows more flexibility, should the compiler (protobuf) be +upgraded even when the source code (opentelemetry-proto) is unchanged. + +### Origin + +The repository for opentelemetry-proto is: + +* [repository](https://github.com/open-telemetry/opentelemetry-proto) + +Check release notes at: + +* [release-notes](https://github.com/open-telemetry/opentelemetry-proto/releases) + +### Upgrade + +When upgrading opentelemetry-proto to a newer release, +a few places in the code need adjustment. + +In this example, we upgrade from 1.3.1 to 1.3.2 + +#### directory third_party/opentelemetry-proto + +This is a `git submodule`, it needs to point to the new tag. + +```shell +cd third_party/opentelemetry-proto +git log -1 +``` + +The current submodule show something like: + +```shell +commit b3060d2104df364136d75a35779e6bd48bac449a (HEAD, tag: v1.3.1) +Author: Damien Mathieu <42@dmathieu.com> +Date: Thu Apr 25 17:55:35 2024 +0200 + + generate profiles proto for CI (#552) +``` + +Pull new tags: + +```shell +git pull --tag origin +``` + +Upgrade to a new tag: + +```shell +git pull origin v1.3.2 +``` + +Check the new state: + +```shell +git log -1 +``` + +```shell +commit 40b3c1b746767cbc13c2e39da3eaf1a23e54ffdd (HEAD, tag: v1.3.2) +Author: jack-berg <34418638+jack-berg@users.noreply.github.com> +Date: Fri Jun 28 08:19:11 2024 -0500 + + Prepare changelog for 1.3.2 release (#563) + + Co-authored-by: Armin Ruech <7052238+arminru@users.noreply.github.com> +``` + +Go back to the root of opentelemetry-cpp + +```shell +cd ../.. +git status +``` + +```shell +On branch upgrade_proto_1.3.2 +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: third_party/opentelemetry-proto (new commits) +``` + +Add the upgraded submodule: + +```shell +git add third_party/opentelemetry-proto +``` + +#### file third_party_release + +Update the line pointing to the opentelemetry-proto tag. + +```text +opentelemetry-proto=v1.3.2 +``` + +Typical change: + +```shell +[malff@malff-desktop opentelemetry-cpp]$ git diff third_party_release +diff --git a/third_party_release b/third_party_release +index 0bbf67f3..7362473f 100644 +--- a/third_party_release ++++ b/third_party_release +@@ -19,7 +19,7 @@ benchmark=v1.8.3 + googletest=1.14.0 + ms-gsl=v3.1.0-67-g6f45293 + nlohmann-json=v3.11.3 +-opentelemetry-proto=v1.3.1 ++opentelemetry-proto=v1.3.2 + opentracing-cpp=v1.6.0 + prometheus-cpp=v1.2.4 + vcpkg=2024.02.14 +``` + +#### file bazel/repository.bzl + +Locate the entry for opentelemetry-proto: + +```text + # OTLP Protocol definition + maybe( + http_archive, + name = "com_github_opentelemetry_proto", + build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", + sha256 = "bed250ceec8e4a83aa5604d7d5595a61945059dc662edd058a9da082283f7a00", + strip_prefix = "opentelemetry-proto-1.3.1", + urls = [ + "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.1.tar.gz", + ], + ) +``` + +Update the URL to the new tag: + +```text + urls = [ + "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.2.tar.gz", + ], +``` + +Update strip_prefix to the new tag: + +```text + strip_prefix = "opentelemetry-proto-1.3.2", +``` + +Download the new URL: + +```shell +wget https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.2.tar.gz +``` + +Run a checksum on the new file: + +```shell +sha256sum v1.3.2.tar.gz +``` + +```shell +c069c0d96137cf005d34411fa67dd3b6f1f8c64af1e7fb2fe0089a41c425acd7 v1.3.2.tar.gz +``` + +Update the checksum in file bazel/repository.bzl: + +```text + sha256 = "c069c0d96137cf005d34411fa67dd3b6f1f8c64af1e7fb2fe0089a41c425acd7", +``` + +Typical change: + +```shell +[malff@malff-desktop opentelemetry-cpp]$ git diff bazel/repository.bzl +diff --git a/bazel/repository.bzl b/bazel/repository.bzl +index bac1e45b..508b95a3 100644 +--- a/bazel/repository.bzl ++++ b/bazel/repository.bzl +@@ -88,10 +88,10 @@ def opentelemetry_cpp_deps(): + http_archive, + name = "com_github_opentelemetry_proto", + build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", +- sha256 = "bed250ceec8e4a83aa5604d7d5595a61945059dc662edd058a9da082283f7a00", +- strip_prefix = "opentelemetry-proto-1.3.1", ++ sha256 = "c069c0d96137cf005d34411fa67dd3b6f1f8c64af1e7fb2fe0089a41c425acd7", ++ strip_prefix = "opentelemetry-proto-1.3.2", + urls = [ +- "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.1.tar.gz", ++ "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.2.tar.gz", + ], + ) +``` + +#### file cmake/opentelemetry-proto.cmake + +Update the tag in the CMake logic: + +```cmake + set(opentelemetry-proto "v1.3.2") +``` + +Typical change: + +```shell +[malff@malff-desktop opentelemetry-cpp]$ git diff cmake/opentelemetry-proto.cmake +diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake +index 19516c3b..dd6213c1 100644 +--- a/cmake/opentelemetry-proto.cmake ++++ b/cmake/opentelemetry-proto.cmake +@@ -49,7 +49,7 @@ else() + "opentelemetry-proto=[ \\t]*([A-Za-z0-9_\\.\\-]+)") + set(opentelemetry-proto "${CMAKE_MATCH_1}") + else() +- set(opentelemetry-proto "v1.3.1") ++ set(opentelemetry-proto "v1.3.2") + endif() + unset(OTELCPP_THIRD_PARTY_RELEASE_CONTENT) + endif() +``` + +If opentelemetry-proto contains new files, +the makefile needs to be adjusted to build the new code. + +Depending on the actual changes in the opentelemetry-proto files, +the C++ code in opentelemetry-cpp may need adjustments. + +Typically, when opentelemetry-proto: + +* defines a new message (for example, for profiling) +* adds new optional fields to an existing message (for example, trace flags) + +the existing C++ code should work as is with the new opentelemetry-proto +format. + +In this case, it is better to: + +* upgrade the opentelemetry-proto version independently with one PR. +* upgrade the C++ code later (to use the new message, of provide new fields) + in a different PR. + +When the C++ code requires a newer minimum version of opentelemetry-proto, +make sure to document this, including in the release notes. + +#### file MODULE.bazel + +Make sure the new tag is available in bazel central: + +* [bazel-central](https://registry.bazel.build/modules/opentelemetry-proto) + +If missing, file a PR to add it, or contact the maintainer: + +* [repository](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/opentelemetry-proto) + +Update the opentelemetry-proto version to the new tag: + +```text +bazel_dep(name = "opentelemetry-proto", version = "1.3.2", repo_name = "com_github_opentelemetry_proto") +``` + +File `MODULE.bazel` is used in the github CI for repository +opentelemetry-cpp, so using a tag that does not exist (yet) in bazel central +will break the CI build. + +See the known issues section. + +Typical change: + +```shell +[malff@malff-desktop opentelemetry-cpp]$ git diff MODULE.bazel +diff --git a/MODULE.bazel b/MODULE.bazel +index 7b84c2b7..3161ffb1 100644 +--- a/MODULE.bazel ++++ b/MODULE.bazel +@@ -13,7 +13,7 @@ bazel_dep(name = "bazel_skylib", version = "1.5.0") + bazel_dep(name = "curl", version = "8.4.0") + bazel_dep(name = "grpc", version = "1.62.1", repo_name = "com_github_grpc_grpc") + bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohmann_json") +-bazel_dep(name = "opentelemetry-proto", version = "1.3.1", repo_name = "com_github_opentelemetry_proto") ++bazel_dep(name = "opentelemetry-proto", version = "1.3.2", repo_name = "com_github_opentelemetry_proto") + bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing") + bazel_dep(name = "platforms", version = "0.0.8") + bazel_dep(name = "prometheus-cpp", version = "1.2.4", repo_name = "com_github_jupp0r_prometheus_cpp") +``` + +### Known issues + +For bazel, two different methods to build exists. + +First, the code can build using file `bazel/repository.bzl`. +This option does not depend on bazel central. + +Secondly, there is also a build using modules, with file `MODULE.bazel`. +This option does depend on bazel central, and CI depends on it. diff --git a/third_party/opentelemetry-proto b/third_party/opentelemetry-proto index b3060d2104..40b3c1b746 160000 --- a/third_party/opentelemetry-proto +++ b/third_party/opentelemetry-proto @@ -1 +1 @@ -Subproject commit b3060d2104df364136d75a35779e6bd48bac449a +Subproject commit 40b3c1b746767cbc13c2e39da3eaf1a23e54ffdd diff --git a/third_party_release b/third_party_release index 0bbf67f3af..7362473f60 100644 --- a/third_party_release +++ b/third_party_release @@ -19,7 +19,7 @@ benchmark=v1.8.3 googletest=1.14.0 ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.11.3 -opentelemetry-proto=v1.3.1 +opentelemetry-proto=v1.3.2 opentracing-cpp=v1.6.0 prometheus-cpp=v1.2.4 vcpkg=2024.02.14 From 611906eeafdbfe4a92fd1f81989692a222da1a78 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 18 Jul 2024 01:27:46 +0200 Subject: [PATCH 27/71] [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` (#2717) --- .github/workflows/iwyu.yml | 1 - CHANGELOG.md | 38 ++++++++ CMakeLists.txt | 19 ---- DEPRECATED.md | 80 +---------------- api/CMakeLists.txt | 5 -- ci/do_ci.ps1 | 2 - ci/do_ci.sh | 4 - examples/logs_simple/main.cc | 10 --- examples/metrics_simple/metrics_ostream.cc | 9 -- examples/otlp/file_log_main.cc | 13 --- examples/otlp/file_main.cc | 8 -- examples/otlp/grpc_log_main.cc | 13 --- examples/otlp/grpc_main.cc | 8 -- examples/otlp/http_log_main.cc | 16 ---- examples/otlp/http_main.cc | 8 -- examples/simple/main.cc | 5 -- .../otlp_grpc_log_record_exporter_test.cc | 7 -- .../sdk/logs/event_logger_provider_factory.h | 9 -- .../sdk/logs/logger_provider_factory.h | 32 ------- .../sdk/metrics/meter_provider_factory.h | 26 ------ .../sdk/trace/tracer_provider_factory.h | 64 -------------- sdk/src/logs/event_logger_provider_factory.cc | 11 --- sdk/src/logs/logger_provider_factory.cc | 46 ---------- sdk/src/metrics/meter_provider_factory.cc | 36 -------- sdk/src/trace/tracer_provider_factory.cc | 86 ------------------- 25 files changed, 39 insertions(+), 517 deletions(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 598f57e97e..2c84b84cdc 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -40,7 +40,6 @@ jobs: -DWITH_STL=CXX14 \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ -DBUILD_TESTING=OFF \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=OFF \ -DWITH_OTLP_GRPC=OFF \ -DWITH_OTLP_HTTP=ON \ diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e13ec3d6..bce84c84df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,44 @@ Increment the: * [CI] Add a clang-tidy build [#3001](https://github.com/open-telemetry/opentelemetry-cpp/pull/3001) +* [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` + [#2717](https://github.com/open-telemetry/opentelemetry-cpp/pull/2717) + +Breaking changes: + +* [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` + [#2717](https://github.com/open-telemetry/opentelemetry-cpp/pull/2717) + + * As announced in opentelemetry-cpp previous release 1.16.0, + CMake option `WITH_DEPRECATED_SDK_FACTORY` was temporary, + and to be removed by the next release. + * This option is now removed. + * Code configuring the SDK must be adjusted, as previously described: + + * [API/SDK] Provider cleanup + [#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664) + + * Before this fix: + * SDK factory methods such as: + * opentelemetry::sdk::trace::TracerProviderFactory::Create() + * opentelemetry::sdk::metrics::MeterProviderFactory::Create() + * opentelemetry::sdk::logs::LoggerProviderFactory::Create() + * opentelemetry::sdk::logs::EventLoggerProviderFactory::Create() + + returned an API object (opentelemetry::trace::TracerProvider) + to the caller. + + * After this fix, these methods return an SDK level object + (opentelemetry::sdk::trace::TracerProvider) to the caller. + * Returning an SDK object is necessary for the application to + cleanup and invoke SDK level methods, such as ForceFlush(), + on a provider. + * The application code that configures the SDK, by calling + the various provider factories, may need adjustment. + * All the examples have been updated, and in particular no + longer perform static_cast do convert an API object to an SDK object. + Please refer to examples for guidance on how to adjust. + ## [1.16.1 2024-07-17] * [BUILD] Add bazel missing BUILD file diff --git a/CMakeLists.txt b/CMakeLists.txt index 44ddd05e1c..d10e831297 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,14 +159,6 @@ message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}") option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) -# This option is temporary, and will be removed. Set -# WITH_DEPRECATED_SDK_FACTORY=OFF to migrate to the new SDK code. -option(WITH_DEPRECATED_SDK_FACTORY "Use deprecated SDK provider factory" ON) - -if(WITH_DEPRECATED_SDK_FACTORY) - message(WARNING "WITH_DEPRECATED_SDK_FACTORY=ON is temporary and deprecated") -endif() - set(WITH_STL "OFF" CACHE STRING "Which version of the Standard Library for C++ to use") @@ -204,13 +196,6 @@ if(NOT WITH_STL STREQUAL "OFF") endif() endif() -if(DEFINED WITH_OTLP) - message( - FATAL_ERROR - "WITH_OTLP is deprecated. Please set either WITH_OTLP_GRPC=ON, WITH_OTLP_HTTP=ON, or both to ON." - ) -endif() - option(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW "Whether to enable mTLS support fro gRPC" OFF) @@ -294,10 +279,6 @@ option( option(WITH_FUNC_TESTS "Whether to build functional tests" ON) -if(DEFINED WITH_LOGS_PREVIEW) - message(WARNING "WITH_LOGS_PREVIEW is removed because logs signal is stable") -endif() - option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF) # Exemplar specs status is experimental, so behind feature flag by default diff --git a/DEPRECATED.md b/DEPRECATED.md index 7db5ba9d93..0632f50503 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -88,85 +88,7 @@ No date set yet for the Jaeger Propagator. ## [opentelemetry-cpp SDK] -### SDK ProviderFactory cleanup - -#### Announcement (SDK ProviderFactory cleanup) - -* Version: 1.15.0 -* Date: 2024-06-03 -* PR: [API/SDK] Provider cleanup - [#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664) - -This PR introduces changes to SDK ProviderFactory methods. - -#### Motivation (SDK ProviderFactory cleanup) - -SDK Factory methods for signal providers, such as: - -* opentelemetry::sdk::trace::TracerProviderFactory -* opentelemetry::sdk::metrics::MeterProviderFactory -* opentelemetry::sdk::logs::LoggerProviderFactory -* opentelemetry::sdk::logs::EventLoggerProviderFactory - -currently returns a unique pointer on a API class. - -This is incorrect, the proper return type should be -a unique pointer on a SDK class instead. - -#### Scope (SDK ProviderFactory cleanup) - -All the current Create methods in: - -* class opentelemetry::sdk::trace::TracerProviderFactory -* class opentelemetry::sdk::metrics::MeterProviderFactory -* class opentelemetry::sdk::logs::LoggerProviderFactory -* class opentelemetry::sdk::logs::EventLoggerProviderFactory - -are marked as deprecated, as they return an API object. - -Instead, another set of Create methods is provided, -with a different return type, an SDK object. - -Both sets can not be exposed at the same time, -as this would cause build breaks, -so a compilation flag is defined to select which methods to use. - -When OPENTELEMETRY_DEPRECATED_SDK_FACTORY is defined, -the old, deprecated, methods are available. - -When OPENTELEMETRY_DEPRECATED_SDK_FACTORY is not defined, -the new methods are available. - -The scope of this deprecation and removal, -is to remove the flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY itself, -which implies that only the new set of Create() methods, -returning an SDK object, are supported. - -#### Mitigation (SDK ProviderFactory cleanup) - -Build without defining flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY. - -Existing code, such as: - -```cpp - std::shared_ptr tracer_provider; - tracer_provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(...); -``` - -should be adjusted to: - -```cpp - std::shared_ptr tracer_provider; - tracer_provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(...); -``` - -#### Planned removal (SDK ProviderFactory cleanup) - -Flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY is introduced in release 1.16.0, -to provide a migration path. - -This flag is meant to be temporary, and short lived. -Expect removal by release 1.17.0 +N/A ## [opentelemetry-cpp Exporter] diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index e07275efed..78e97ad029 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -35,11 +35,6 @@ if(WITH_NO_DEPRECATED_CODE) INTERFACE OPENTELEMETRY_NO_DEPRECATED_CODE) endif() -if(WITH_DEPRECATED_SDK_FACTORY) - target_compile_definitions(opentelemetry_api - INTERFACE OPENTELEMETRY_DEPRECATED_SDK_FACTORY) -endif() - if(WITH_ABSEIL) target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) target_link_libraries( diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index bcae6359bb..e9c1f64646 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -135,7 +135,6 @@ switch ($action) { cmake $SRC_DIR ` -DOTELCPP_MAINTAINER_MODE=ON ` -DWITH_NO_DEPRECATED_CODE=ON ` - -DWITH_DEPRECATED_SDK_FACTORY=OFF ` -DVCPKG_TARGET_TRIPLET=x64-windows ` "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE @@ -160,7 +159,6 @@ switch ($action) { -DCMAKE_CXX_STANDARD=20 ` -DOTELCPP_MAINTAINER_MODE=ON ` -DWITH_NO_DEPRECATED_CODE=ON ` - -DWITH_DEPRECATED_SDK_FACTORY=OFF ` -DVCPKG_TARGET_TRIPLET=x64-windows ` "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE diff --git a/ci/do_ci.sh b/ci/do_ci.sh index efdac9e87e..6d339c8d4e 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -130,7 +130,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ ${IWYU} \ "${SRC_DIR}" @@ -153,7 +152,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ ${IWYU} \ "${SRC_DIR}" @@ -177,7 +175,6 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ "${SRC_DIR}" make -k -j $(nproc) @@ -199,7 +196,6 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF \ -DWITH_ABI_VERSION_1=OFF \ -DWITH_ABI_VERSION_2=ON \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index 444775dc59..3d7dfb8831 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -44,13 +44,8 @@ void InitTracer() auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); -#else std::shared_ptr provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider const std::shared_ptr &api_provider = provider; @@ -70,13 +65,8 @@ void InitLogger() std::unique_ptr(new logs_exporter::OStreamLogRecordExporter); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - std::shared_ptr provider( - opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(processor))); -#else std::shared_ptr provider( opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(processor))); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global logger provider const std::shared_ptr &api_provider = provider; diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 5871b5e6a3..5bdc7339eb 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -57,12 +57,7 @@ void InitMetrics(const std::string &name) auto reader = metrics_sdk::PeriodicExportingMetricReaderFactory::Create(std::move(exporter), options); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - auto u_provider = opentelemetry::sdk::metrics::MeterProviderFactory::Create(); - auto *provider = static_cast(u_provider.get()); -#else auto provider = opentelemetry::sdk::metrics::MeterProviderFactory::Create(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ provider->AddMetricReader(std::move(reader)); @@ -118,11 +113,7 @@ void InitMetrics(const std::string &name) provider->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - std::shared_ptr api_provider(std::move(u_provider)); -#else std::shared_ptr api_provider(std::move(provider)); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ metrics_api::Provider::SetMeterProvider(api_provider); } diff --git a/examples/otlp/file_log_main.cc b/examples/otlp/file_log_main.cc index 30eb71cc2b..3cd59f7240 100644 --- a/examples/otlp/file_log_main.cc +++ b/examples/otlp/file_log_main.cc @@ -46,13 +46,8 @@ namespace opentelemetry::exporter::otlp::OtlpFileExporterOptions opts; opentelemetry::exporter::otlp::OtlpFileLogRecordExporterOptions log_opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr tracer_provider; -std::shared_ptr logger_provider; -#else std::shared_ptr tracer_provider; std::shared_ptr logger_provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -71,11 +66,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (tracer_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(tracer_provider.get())->ForceFlush(); -#else tracer_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } tracer_provider.reset(); @@ -99,11 +90,7 @@ void CleanupLogger() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (logger_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(logger_provider.get())->ForceFlush(); -#else logger_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } logger_provider.reset(); diff --git a/examples/otlp/file_main.cc b/examples/otlp/file_main.cc index 243ad44428..377662aee4 100644 --- a/examples/otlp/file_main.cc +++ b/examples/otlp/file_main.cc @@ -31,11 +31,7 @@ namespace { opentelemetry::exporter::otlp::OtlpFileExporterOptions opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr provider; -#else std::shared_ptr provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -54,11 +50,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(provider.get())->ForceFlush(); -#else provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } provider.reset(); diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index 24037f6190..c7aca2ea31 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -38,13 +38,8 @@ namespace opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterOptions log_opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr tracer_provider; -std::shared_ptr logger_provider; -#else std::shared_ptr tracer_provider; std::shared_ptr logger_provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -63,11 +58,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (tracer_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(tracer_provider.get())->ForceFlush(); -#else tracer_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } tracer_provider.reset(); @@ -92,11 +83,7 @@ void CleanupLogger() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (logger_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(logger_provider.get())->ForceFlush(); -#else logger_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } logger_provider.reset(); diff --git a/examples/otlp/grpc_main.cc b/examples/otlp/grpc_main.cc index 15499985af..9b29e16edd 100644 --- a/examples/otlp/grpc_main.cc +++ b/examples/otlp/grpc_main.cc @@ -24,11 +24,7 @@ namespace { opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr provider; -#else std::shared_ptr provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -47,11 +43,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(provider.get())->ForceFlush(); -#else provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } provider.reset(); diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 37bace2b0f..4f42b61ce9 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -48,11 +48,7 @@ namespace opentelemetry::exporter::otlp::OtlpHttpExporterOptions trace_opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr tracer_provider; -#else std::shared_ptr tracer_provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -88,11 +84,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (tracer_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(tracer_provider.get())->ForceFlush(); -#else tracer_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } tracer_provider.reset(); @@ -102,11 +94,7 @@ void CleanupTracer() opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterOptions logger_opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr logger_provider; -#else std::shared_ptr logger_provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitLogger() { @@ -126,11 +114,7 @@ void CleanupLogger() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (logger_provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(logger_provider.get())->ForceFlush(); -#else logger_provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } logger_provider.reset(); diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index 6217bdcb34..ce88e46fca 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -35,11 +35,7 @@ namespace { opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY -std::shared_ptr provider; -#else std::shared_ptr provider; -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ void InitTracer() { @@ -57,11 +53,7 @@ void CleanupTracer() // We call ForceFlush to prevent to cancel running exportings, It's optional. if (provider) { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - static_cast(provider.get())->ForceFlush(); -#else provider->ForceFlush(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ } provider.reset(); diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 349aec500a..245786688c 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -31,13 +31,8 @@ void InitTracer() auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); -#else std::shared_ptr provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider const std::shared_ptr &api_provider = provider; diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index 4c7a9fd7f1..90827f576f 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -288,17 +288,10 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) std::unique_ptr trace_stub_interface( trace_mock_stub); -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - auto trace_provider = opentelemetry::nostd::shared_ptr( - opentelemetry::sdk::trace::TracerProviderFactory::Create( - opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create( - GetExporter(trace_stub_interface)))); -#else auto trace_provider = opentelemetry::nostd::shared_ptr( opentelemetry::sdk::trace::TracerProviderFactory::Create( opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create( GetExporter(trace_stub_interface)))); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Trace and Logs should both receive datas when links static gRPC on ELF ABI. EXPECT_CALL(*trace_mock_stub, Export(_, _, _)) diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h index 621cbea6c8..5559605171 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h @@ -24,16 +24,7 @@ class EventLoggerProviderFactory * Create a EventLoggerProvider. */ -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -# ifndef OPENTELEMETRY_NO_DEPRECATED_CODE - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create(); -# endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ - -#else static std::unique_ptr Create(); -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ }; } // namespace logs diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h index 7b8f636e68..490393209c 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -24,36 +24,6 @@ namespace logs class OPENTELEMETRY_EXPORT LoggerProviderFactory { public: -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -# ifndef OPENTELEMETRY_NO_DEPRECATED_CODE - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr &&processor); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr &&processor, - const opentelemetry::sdk::resource::Resource &resource); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr context); - -# endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ - -#else - /** * Create a LoggerProvider. */ @@ -85,8 +55,6 @@ class OPENTELEMETRY_EXPORT LoggerProviderFactory */ static std::unique_ptr Create( std::unique_ptr context); - -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ }; } // namespace logs diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h index cb9106ddc8..499c87ae6a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h @@ -21,30 +21,6 @@ namespace metrics class OPENTELEMETRY_EXPORT MeterProviderFactory { public: -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -# ifndef OPENTELEMETRY_NO_DEPRECATED_CODE - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create(); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr views); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr views, - const opentelemetry::sdk::resource::Resource &resource); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr context); - -# endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ - -#else - static std::unique_ptr Create(); static std::unique_ptr Create( @@ -56,8 +32,6 @@ class OPENTELEMETRY_EXPORT MeterProviderFactory static std::unique_ptr Create( std::unique_ptr context); - -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h index 7c4b6903de..ed451a8c99 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h @@ -28,68 +28,6 @@ namespace trace class OPENTELEMETRY_EXPORT TracerProviderFactory { public: -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -# ifndef OPENTELEMETRY_NO_DEPRECATED_CODE - - /* Serie of builders with a single processor. */ - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr processor); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler, - std::unique_ptr id_generator); - - /* Serie of builders with a vector of processor. */ - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler); - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler, - std::unique_ptr id_generator); - - /* Create with a tracer context. */ - - OPENTELEMETRY_DEPRECATED - static std::unique_ptr Create( - std::unique_ptr context); - -# endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ - -#else - /* Serie of builders with a single processor. */ static std::unique_ptr Create( @@ -134,8 +72,6 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory static std::unique_ptr Create( std::unique_ptr context); - -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ }; } // namespace trace diff --git a/sdk/src/logs/event_logger_provider_factory.cc b/sdk/src/logs/event_logger_provider_factory.cc index 7f5c8cadf1..daff8a8590 100644 --- a/sdk/src/logs/event_logger_provider_factory.cc +++ b/sdk/src/logs/event_logger_provider_factory.cc @@ -11,22 +11,11 @@ namespace sdk namespace logs { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -std::unique_ptr EventLoggerProviderFactory::Create() -{ - return std::unique_ptr(new EventLoggerProvider()); -} - -#else - std::unique_ptr EventLoggerProviderFactory::Create() { return std::unique_ptr(new EventLoggerProvider()); } -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ - } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc index 08567c65d9..530d1c2db4 100644 --- a/sdk/src/logs/logger_provider_factory.cc +++ b/sdk/src/logs/logger_provider_factory.cc @@ -18,50 +18,6 @@ namespace sdk namespace logs { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -std::unique_ptr LoggerProviderFactory::Create( - std::unique_ptr &&processor) -{ - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processor), resource); -} - -std::unique_ptr LoggerProviderFactory::Create( - std::unique_ptr &&processor, - const opentelemetry::sdk::resource::Resource &resource) -{ - std::unique_ptr provider( - new LoggerProvider(std::move(processor), resource)); - return provider; -} - -std::unique_ptr LoggerProviderFactory::Create( - std::vector> &&processors) -{ - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processors), resource); -} - -std::unique_ptr LoggerProviderFactory::Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource) -{ - std::unique_ptr provider( - new LoggerProvider(std::move(processors), resource)); - return provider; -} - -std::unique_ptr LoggerProviderFactory::Create( - std::unique_ptr context) -{ - std::unique_ptr provider( - new LoggerProvider(std::move(context))); - return provider; -} - -#else - std::unique_ptr LoggerProviderFactory::Create( std::unique_ptr &&processor) { @@ -102,8 +58,6 @@ std::unique_ptr LoggerProviderFactory: return provider; } -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ - } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/meter_provider_factory.cc b/sdk/src/metrics/meter_provider_factory.cc index 7749a13124..c5e368aca6 100644 --- a/sdk/src/metrics/meter_provider_factory.cc +++ b/sdk/src/metrics/meter_provider_factory.cc @@ -18,40 +18,6 @@ namespace sdk namespace metrics { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -std::unique_ptr MeterProviderFactory::Create() -{ - auto views = ViewRegistryFactory::Create(); - return Create(std::move(views)); -} - -std::unique_ptr MeterProviderFactory::Create( - std::unique_ptr views) -{ - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(views), resource); -} - -std::unique_ptr MeterProviderFactory::Create( - std::unique_ptr views, - const opentelemetry::sdk::resource::Resource &resource) -{ - std::unique_ptr provider( - new opentelemetry::sdk::metrics::MeterProvider(std::move(views), resource)); - return provider; -} - -std::unique_ptr MeterProviderFactory::Create( - std::unique_ptr context) -{ - std::unique_ptr provider( - new opentelemetry::sdk::metrics::MeterProvider(std::move(context))); - return provider; -} - -#else - std::unique_ptr MeterProviderFactory::Create() { auto views = ViewRegistryFactory::Create(); @@ -82,8 +48,6 @@ std::unique_ptr MeterProviderFactory return provider; } -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ - } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_provider_factory.cc b/sdk/src/trace/tracer_provider_factory.cc index eeb18a1e59..eaeb669b91 100644 --- a/sdk/src/trace/tracer_provider_factory.cc +++ b/sdk/src/trace/tracer_provider_factory.cc @@ -22,90 +22,6 @@ namespace sdk namespace trace { -#ifdef OPENTELEMETRY_DEPRECATED_SDK_FACTORY - -std::unique_ptr TracerProviderFactory::Create( - std::unique_ptr processor) -{ - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processor), resource); -} - -std::unique_ptr TracerProviderFactory::Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource) -{ - auto sampler = AlwaysOnSamplerFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler)); -} - -std::unique_ptr TracerProviderFactory::Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler) -{ - auto id_generator = RandomIdGeneratorFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator)); -} - -std::unique_ptr TracerProviderFactory::Create( - std::unique_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler, - std::unique_ptr id_generator) -{ - std::unique_ptr provider( - new opentelemetry::sdk::trace::TracerProvider(std::move(processor), resource, - std::move(sampler), std::move(id_generator))); - return provider; -} - -std::unique_ptr TracerProviderFactory::Create( - std::vector> &&processors) -{ - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processors), resource); -} - -std::unique_ptr TracerProviderFactory::Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource) -{ - auto sampler = AlwaysOnSamplerFactory::Create(); - return Create(std::move(processors), resource, std::move(sampler)); -} - -std::unique_ptr TracerProviderFactory::Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler) -{ - auto id_generator = RandomIdGeneratorFactory::Create(); - return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator)); -} - -std::unique_ptr TracerProviderFactory::Create( - std::vector> &&processors, - const opentelemetry::sdk::resource::Resource &resource, - std::unique_ptr sampler, - std::unique_ptr id_generator) -{ - std::unique_ptr provider( - new opentelemetry::sdk::trace::TracerProvider(std::move(processors), resource, - std::move(sampler), std::move(id_generator))); - return provider; -} - -std::unique_ptr TracerProviderFactory::Create( - std::unique_ptr context) -{ - std::unique_ptr provider( - new opentelemetry::sdk::trace::TracerProvider(std::move(context))); - return provider; -} - -#else - std::unique_ptr TracerProviderFactory::Create( std::unique_ptr processor) { @@ -186,8 +102,6 @@ std::unique_ptr TracerProviderFactory return provider; } -#endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ - } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE From f195b9e3da9c7987c377fafe8a7a6873b0d34549 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 19 Jul 2024 17:34:40 +0800 Subject: [PATCH 28/71] [EXPORTER] ForceFlush before canceling the running requests on shutdown. (#2727) --- .../exporters/otlp/otlp_http_client.h | 5 ++- exporters/otlp/src/otlp_grpc_client.cc | 9 ++++- exporters/otlp/src/otlp_http_client.cc | 38 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h index 6806f1cdf9..3753704bb3 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -275,7 +276,7 @@ class OtlpHttpClient std::shared_ptr http_client); // Stores if this HTTP client had its Shutdown() method called - bool is_shutdown_; + std::atomic is_shutdown_; // The configuration options associated with this HTTP client. const OtlpHttpClientOptions options_; @@ -296,6 +297,8 @@ class OtlpHttpClient // Condition variable and mutex to control the concurrency count of running sessions std::mutex session_waker_lock_; std::condition_variable session_waker_; + std::atomic start_session_counter_; + std::atomic finished_session_counter_; }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index a5760bdd81..d3d59bce6e 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -567,14 +567,19 @@ bool OtlpGrpcClient::Shutdown(std::chrono::microseconds timeout) noexcept return true; } + bool force_flush_result; if (false == is_shutdown_.exchange(true, std::memory_order_acq_rel)) { - is_shutdown_ = true; + force_flush_result = ForceFlush(timeout); async_data_->cq.Shutdown(); } + else + { + force_flush_result = ForceFlush(timeout); + } - return ForceFlush(timeout); + return force_flush_result; } #endif diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 94f02a9967..07b9108a3a 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -41,9 +41,11 @@ // clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep -#include +// clang-format on #include +#include #include +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep // clang-format on @@ -661,7 +663,11 @@ void ConvertListFieldToJson(nlohmann::json &value, } // namespace OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) - : is_shutdown_(false), options_(options), http_client_(http_client::HttpClientFactory::Create()) + : is_shutdown_(false), + options_(options), + http_client_(http_client::HttpClientFactory::Create()), + start_session_counter_(0), + finished_session_counter_(0) { http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); } @@ -700,7 +706,11 @@ OtlpHttpClient::~OtlpHttpClient() OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, std::shared_ptr http_client) - : is_shutdown_(false), options_(options), http_client_(std::move(http_client)) + : is_shutdown_(false), + options_(options), + http_client_(std::move(http_client)), + start_session_counter_(0), + finished_session_counter_(0) { http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); } @@ -799,6 +809,8 @@ bool OtlpHttpClient::ForceFlush(std::chrono::microseconds timeout) noexcept timeout_steady = (std::chrono::steady_clock::duration::max)(); } + size_t wait_counter = start_session_counter_.load(std::memory_order_acquire); + while (timeout_steady > std::chrono::steady_clock::duration::zero()) { { @@ -816,7 +828,7 @@ bool OtlpHttpClient::ForceFlush(std::chrono::microseconds timeout) noexcept { cleanupGCSessions(); } - else + else if (finished_session_counter_.load(std::memory_order_acquire) >= wait_counter) { break; } @@ -829,20 +841,24 @@ bool OtlpHttpClient::ForceFlush(std::chrono::microseconds timeout) noexcept bool OtlpHttpClient::Shutdown(std::chrono::microseconds timeout) noexcept { + is_shutdown_.store(true, std::memory_order_release); + + bool force_flush_result = ForceFlush(timeout); + { std::lock_guard guard{session_manager_lock_}; - is_shutdown_ = true; // Shutdown the session manager http_client_->CancelAllSessions(); http_client_->FinishAllSessions(); } - ForceFlush(timeout); - + // Wait util all sessions are canceled. while (cleanupGCSessions()) - ; - return true; + { + ForceFlush(std::chrono::milliseconds{1}); + } + return force_flush_result; } void OtlpHttpClient::ReleaseSession( @@ -859,6 +875,7 @@ void OtlpHttpClient::ReleaseSession( gc_sessions_.emplace_back(std::move(session_iter->second)); running_sessions_.erase(session_iter); + finished_session_counter_.fetch_add(1, std::memory_order_release); has_session = true; } @@ -1003,6 +1020,7 @@ void OtlpHttpClient::addSession(HttpSessionData &&session_data) noexcept store_session_data = std::move(session_data); } + start_session_counter_.fetch_add(1, std::memory_order_release); // Send request after the session is added session->SendRequest(handle); } @@ -1027,7 +1045,7 @@ bool OtlpHttpClient::cleanupGCSessions() noexcept bool OtlpHttpClient::IsShutdown() const noexcept { - return is_shutdown_; + return is_shutdown_.load(std::memory_order_acquire); } } // namespace otlp From 4520aa598b7c100eefbb4ce9a9f73cb50bb69514 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 19 Jul 2024 18:12:48 +0800 Subject: [PATCH 29/71] [SDK] Fix crash in `PeriodicExportingMetricReader`. (#2983) --- api/include/opentelemetry/common/macros.h | 31 ++++++++ examples/plugin/plugin/tracer.cc | 1 + exporters/otlp/src/otlp_file_client.cc | 22 +++--- .../periodic_exporting_metric_reader.cc | 77 ++++++++++++++----- .../periodic_exporting_metric_reader_test.cc | 38 +++++++-- 5 files changed, 133 insertions(+), 36 deletions(-) diff --git a/api/include/opentelemetry/common/macros.h b/api/include/opentelemetry/common/macros.h index b4a270084d..b74c1048fc 100644 --- a/api/include/opentelemetry/common/macros.h +++ b/api/include/opentelemetry/common/macros.h @@ -387,6 +387,37 @@ point. #endif +// OPENTELEMETRY_HAVE_EXCEPTIONS +// +// Checks whether the compiler both supports and enables exceptions. Many +// compilers support a "no exceptions" mode that disables exceptions. +// +// Generally, when OPENTELEMETRY_HAVE_EXCEPTIONS is not defined: +// +// * Code using `throw` and `try` may not compile. +// * The `noexcept` specifier will still compile and behave as normal. +// * The `noexcept` operator may still return `false`. +// +// For further details, consult the compiler's documentation. +#ifndef OPENTELEMETRY_HAVE_EXCEPTIONS +# if defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__) < 306 +// Clang < 3.6 +// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro +# if defined(__EXCEPTIONS) && OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions) +# define OPENTELEMETRY_HAVE_EXCEPTIONS 1 +# endif // defined(__EXCEPTIONS) && OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions) +# elif OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions) +# define OPENTELEMETRY_HAVE_EXCEPTIONS 1 +// Handle remaining special cases and default to exceptions being supported. +# elif !(defined(__GNUC__) && !defined(__EXCEPTIONS) && !defined(__cpp_exceptions)) && \ + !(defined(_MSC_VER) && !defined(_CPPUNWIND)) +# define OPENTELEMETRY_HAVE_EXCEPTIONS 1 +# endif +#endif +#ifndef OPENTELEMETRY_HAVE_EXCEPTIONS +# define OPENTELEMETRY_HAVE_EXCEPTIONS 0 +#endif + /* OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function parameter or implicit object parameter is retained by the return value of the diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 5361197584..05ff971fb1 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -9,6 +9,7 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" #include "tracer.h" diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index 62552bdeff..8efa5c15b5 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -14,8 +14,6 @@ // clang-format on #include "google/protobuf/message.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/stubs/common.h" #include "nlohmann/json.hpp" // clang-format off @@ -28,15 +26,26 @@ #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/version.h" +#ifdef _MSC_VER +# include +# define strcasecmp _stricmp +#else +# include +#endif + +#include #include #include +#include #include -#include #include +#include #include +#include #include #include #include +#include #include #if !defined(__CYGWIN__) && defined(_WIN32) @@ -64,11 +73,8 @@ #else -# include -# include # include # include -# include # include # define FS_ACCESS(x) access(x, F_OK) @@ -89,10 +95,6 @@ # undef GetMessage #endif -#ifdef _MSC_VER -# define strcasecmp _stricmp -#endif - #if (defined(_MSC_VER) && _MSC_VER >= 1600) || \ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || defined(__STDC_LIB_EXT1__) # ifdef _MSC_VER diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index f6ae47977d..7ca2747337 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -13,6 +13,7 @@ #include #include +#include "opentelemetry/common/macros.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" @@ -29,6 +30,10 @@ # include #endif +#if OPENTELEMETRY_HAVE_EXCEPTIONS +# include +#endif + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -90,31 +95,61 @@ void PeriodicExportingMetricReader::DoBackgroundWork() bool PeriodicExportingMetricReader::CollectAndExportOnce() { std::atomic cancel_export_for_timeout{false}; - auto future_receive = std::async(std::launch::async, [this, &cancel_export_for_timeout] { - Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { - if (cancel_export_for_timeout) - { - OTEL_INTERNAL_LOG_ERROR( - "[Periodic Exporting Metric Reader] Collect took longer configured time: " - << export_timeout_millis_.count() << " ms, and timed out"); - return false; - } - this->exporter_->Export(metric_data); - return true; - }); - }); - std::future_status status; std::uint64_t notify_force_flush = force_flush_pending_sequence_.load(std::memory_order_acquire); - do + std::unique_ptr task_thread; + +#if OPENTELEMETRY_HAVE_EXCEPTIONS + try { - status = future_receive.wait_for(std::chrono::milliseconds(export_timeout_millis_)); - if (status == std::future_status::timeout) +#endif + std::promise sender; + auto receiver = sender.get_future(); + + task_thread.reset(new std::thread([this, &cancel_export_for_timeout] { + this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { + if (cancel_export_for_timeout.load(std::memory_order_acquire)) + { + OTEL_INTERNAL_LOG_ERROR( + "[Periodic Exporting Metric Reader] Collect took longer configured time: " + << this->export_timeout_millis_.count() << " ms, and timed out"); + return false; + } + this->exporter_->Export(metric_data); + return true; + }); + })); + + std::future_status status; + do { - cancel_export_for_timeout = true; - break; - } - } while (status != std::future_status::ready); + status = receiver.wait_for(std::chrono::milliseconds(export_timeout_millis_)); + if (status == std::future_status::timeout) + { + cancel_export_for_timeout.store(true, std::memory_order_release); + break; + } + } while (status != std::future_status::ready); +#if OPENTELEMETRY_HAVE_EXCEPTIONS + } + catch (std::exception &e) + { + OTEL_INTERNAL_LOG_ERROR("[Periodic Exporting Metric Reader] Collect failed with exception " + << e.what()); + return false; + } + catch (...) + { + OTEL_INTERNAL_LOG_ERROR( + "[Periodic Exporting Metric Reader] Collect failed with unknown exception"); + return false; + } +#endif + + if (task_thread && task_thread->joinable()) + { + task_thread->join(); + } std::uint64_t notified_sequence = force_flush_notified_sequence_.load(std::memory_order_acquire); while (notify_force_flush > notified_sequence) diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index e115f79f75..f65c10ca05 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -7,6 +7,10 @@ #include +#include +#include +#include + using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; @@ -14,8 +18,14 @@ using namespace opentelemetry::sdk::metrics; class MockPushMetricExporter : public PushMetricExporter { public: + MockPushMetricExporter(std::chrono::milliseconds wait) : wait_(wait) {} + opentelemetry::sdk::common::ExportResult Export(const ResourceMetrics &record) noexcept override { + if (wait_ > std::chrono::milliseconds::zero()) + { + std::this_thread::sleep_for(wait_); + } records_.push_back(record); return opentelemetry::sdk::common::ExportResult::kSuccess; } @@ -34,6 +44,7 @@ class MockPushMetricExporter : public PushMetricExporter private: std::vector records_; + std::chrono::milliseconds wait_; }; class MockMetricProducer : public MetricProducer @@ -61,17 +72,34 @@ class MockMetricProducer : public MetricProducer TEST(PeriodicExporingMetricReader, BasicTests) { - std::unique_ptr exporter(new MockPushMetricExporter()); + std::unique_ptr exporter( + new MockPushMetricExporter(std::chrono::milliseconds{0})); PeriodicExportingMetricReaderOptions options; options.export_timeout_millis = std::chrono::milliseconds(200); options.export_interval_millis = std::chrono::milliseconds(500); auto exporter_ptr = exporter.get(); - PeriodicExportingMetricReader reader(std::move(exporter), options); + std::shared_ptr reader = + std::make_shared(std::move(exporter), options); MockMetricProducer producer; - reader.SetMetricProducer(&producer); + reader->SetMetricProducer(&producer); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - EXPECT_NO_THROW(reader.ForceFlush()); - reader.Shutdown(); + EXPECT_NO_THROW(reader->ForceFlush()); + reader->Shutdown(); EXPECT_EQ(static_cast(exporter_ptr)->GetDataCount(), static_cast(&producer)->GetDataCount()); } + +TEST(PeriodicExporingMetricReader, Timeout) +{ + std::unique_ptr exporter( + new MockPushMetricExporter(std::chrono::milliseconds{2000})); + PeriodicExportingMetricReaderOptions options; + options.export_timeout_millis = std::chrono::milliseconds(200); + options.export_interval_millis = std::chrono::milliseconds(500); + std::shared_ptr reader = + std::make_shared(std::move(exporter), options); + MockMetricProducer producer; + reader->SetMetricProducer(&producer); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + reader->Shutdown(); +} From deed1e3a0c3d67afd9db522b69daad567cdb0592 Mon Sep 17 00:00:00 2001 From: Weipeng Hong <961365124@qq.com> Date: Sat, 20 Jul 2024 02:13:04 +0800 Subject: [PATCH 30/71] [SDK] Fix memory leak in TlsRandomNumberGenerator() constructor (#2661) --- sdk/src/common/random.cc | 9 ++++++++- sdk/test/common/random_test.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/sdk/src/common/random.cc b/sdk/src/common/random.cc index 77b88cfa2a..9b696dea65 100644 --- a/sdk/src/common/random.cc +++ b/sdk/src/common/random.cc @@ -5,6 +5,7 @@ #include "src/common/random.h" #include "src/common/platform/fork.h" +#include #include #include @@ -26,12 +27,17 @@ class TlsRandomNumberGenerator TlsRandomNumberGenerator() noexcept { Seed(); - platform::AtFork(nullptr, nullptr, OnFork); + if (!flag.test_and_set()) + { + platform::AtFork(nullptr, nullptr, OnFork); + } } static FastRandomNumberGenerator &engine() noexcept { return engine_; } private: + static std::atomic_flag flag; + static thread_local FastRandomNumberGenerator engine_; static void OnFork() noexcept { Seed(); } @@ -44,6 +50,7 @@ class TlsRandomNumberGenerator } }; +std::atomic_flag TlsRandomNumberGenerator::flag; thread_local FastRandomNumberGenerator TlsRandomNumberGenerator::engine_{}; } // namespace diff --git a/sdk/test/common/random_test.cc b/sdk/test/common/random_test.cc index 8132b2d5a4..243a998041 100644 --- a/sdk/test/common/random_test.cc +++ b/sdk/test/common/random_test.cc @@ -4,7 +4,10 @@ #include "src/common/random.h" #include +#include #include +#include +#include #include using opentelemetry::sdk::common::Random; @@ -34,3 +37,27 @@ TEST(RandomTest, GenerateRandomBuffer) std::equal(std::begin(buf1_vector), std::end(buf1_vector), std::begin(buf2_vector))); } } + +void doSomethingOnce(std::atomic_uint *count) +{ + static std::atomic_flag flag; + if (!flag.test_and_set()) + { + (*count)++; + } +} + +TEST(RandomTest, AtomicFlagMultiThreadTest) +{ + std::vector threads; + std::atomic_uint count(0); + for (int i = 0; i < 10; ++i) + { + threads.push_back(std::thread(doSomethingOnce, &count)); + } + for (auto &t : threads) + { + t.join(); + } + EXPECT_EQ(1, count.load()); +} From 84368cd76151bfad525739d675061bd071477f81 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Mon, 29 Jul 2024 23:25:44 +0800 Subject: [PATCH 31/71] [EXPORTER] Ignore exception when create thread in OTLP file exporter. (#3012) --- exporters/otlp/src/otlp_file_client.cc | 122 +++++++++++++++---------- 1 file changed, 72 insertions(+), 50 deletions(-) diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index 8efa5c15b5..cc6e074bfd 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -47,6 +47,9 @@ #include #include #include +#if OPENTELEMETRY_HAVE_EXCEPTIONS +# include +#endif #if !defined(__CYGWIN__) && defined(_WIN32) # ifndef WIN32_LEAN_AND_MEAN @@ -1424,71 +1427,90 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender return; } - std::lock_guard lock_guard_caller{file_->background_thread_lock}; - if (file_->background_flush_thread) +#if OPENTELEMETRY_HAVE_EXCEPTIONS + try { - return; - } - - std::shared_ptr concurrency_file = file_; - std::chrono::microseconds flush_interval = options_.flush_interval; - file_->background_flush_thread.reset(new std::thread([concurrency_file, flush_interval]() { - std::chrono::system_clock::time_point last_free_job_timepoint = - std::chrono::system_clock::now(); - std::size_t last_record_count = 0; +#endif - while (true) + std::lock_guard lock_guard_caller{file_->background_thread_lock}; + if (file_->background_flush_thread) { - std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - // Exit flush thread if there is not data to flush more than one minute. - if (now - last_free_job_timepoint > std::chrono::minutes{1}) - { - break; - } + return; + } - if (concurrency_file->is_shutdown.load(std::memory_order_acquire)) - { - break; - } + std::shared_ptr concurrency_file = file_; + std::chrono::microseconds flush_interval = options_.flush_interval; + file_->background_flush_thread.reset(new std::thread([concurrency_file, flush_interval]() { + std::chrono::system_clock::time_point last_free_job_timepoint = + std::chrono::system_clock::now(); + std::size_t last_record_count = 0; + while (true) { - std::unique_lock lk(concurrency_file->background_thread_waker_lock); - concurrency_file->background_thread_waker_cv.wait_for(lk, flush_interval); - } + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + // Exit flush thread if there is not data to flush more than one minute. + if (now - last_free_job_timepoint > std::chrono::minutes{1}) + { + break; + } - { - std::size_t current_record_count = - concurrency_file->record_count.load(std::memory_order_acquire); - std::lock_guard lock_guard{concurrency_file->file_lock}; - if (current_record_count != last_record_count) + if (concurrency_file->is_shutdown.load(std::memory_order_acquire)) { - last_record_count = current_record_count; - last_free_job_timepoint = std::chrono::system_clock::now(); + break; } - if (concurrency_file->current_file) { - fflush(concurrency_file->current_file.get()); + std::unique_lock lk(concurrency_file->background_thread_waker_lock); + concurrency_file->background_thread_waker_cv.wait_for(lk, flush_interval); } - concurrency_file->flushed_record_count.store(current_record_count, - std::memory_order_release); - } + { + std::size_t current_record_count = + concurrency_file->record_count.load(std::memory_order_acquire); + std::lock_guard lock_guard{concurrency_file->file_lock}; + if (current_record_count != last_record_count) + { + last_record_count = current_record_count; + last_free_job_timepoint = std::chrono::system_clock::now(); + } - concurrency_file->background_thread_waiter_cv.notify_all(); - } + if (concurrency_file->current_file) + { + fflush(concurrency_file->current_file.get()); + } - // Detach running thread because it will exit soon - std::unique_ptr background_flush_thread; - { - std::lock_guard lock_guard_inner{concurrency_file->background_thread_lock}; - background_flush_thread.swap(concurrency_file->background_flush_thread); - } - if (background_flush_thread && background_flush_thread->joinable()) - { - background_flush_thread->detach(); - } - })); + concurrency_file->flushed_record_count.store(current_record_count, + std::memory_order_release); + } + + concurrency_file->background_thread_waiter_cv.notify_all(); + } + + // Detach running thread because it will exit soon + std::unique_ptr background_flush_thread; + { + std::lock_guard lock_guard_inner{concurrency_file->background_thread_lock}; + background_flush_thread.swap(concurrency_file->background_flush_thread); + } + if (background_flush_thread && background_flush_thread->joinable()) + { + background_flush_thread->detach(); + } + })); +#if OPENTELEMETRY_HAVE_EXCEPTIONS + } + catch (std::exception &e) + { + OTEL_INTERNAL_LOG_WARN("[OTLP FILE Client] Try to spawn background but got a exception: " + << e.what() << ".Data writing may experience some delays."); + } + catch (...) + { + OTEL_INTERNAL_LOG_WARN( + "[OTLP FILE Client] Try to spawn background but got a unknown exception.Data writing may " + "experience some delays."); + } +#endif } private: From eda6e93f47bd8c2fbc1619098d9334e4d1937ec2 Mon Sep 17 00:00:00 2001 From: Carbo Kuo Date: Fri, 2 Aug 2024 15:30:41 -0400 Subject: [PATCH 32/71] [BUILD] Update MODULE.bazel (#3015) --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 311d4cbc16..13175f2c21 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -3,7 +3,7 @@ module( name = "opentelemetry-cpp", - version = "0", + version = "1.16.1", compatibility_level = 0, repo_name = "io_opentelemetry_cpp", ) From 34ca855055ebb9804756ff220fd64cb45d0c6de5 Mon Sep 17 00:00:00 2001 From: Manuel Bergler Date: Sat, 3 Aug 2024 00:54:26 +0200 Subject: [PATCH 33/71] [BUILD] Fix build without vcpkg on Windows when gRPC is disabled (#3016) --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d10e831297..b247f47fc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,7 +385,8 @@ if(WITH_OTLP_GRPC if(WITH_OTLP_GRPC) find_package(gRPC) endif() - if((NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) OR (NOT gRPC_FOUND)) + if((NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) OR (WITH_OTLP_GRPC + AND NOT gRPC_FOUND)) if(WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE)) install_windows_deps() endif() From 7c6b9dbcaf43af9a281029121392aef31445b770 Mon Sep 17 00:00:00 2001 From: Carbo Kuo Date: Tue, 6 Aug 2024 13:43:02 -0400 Subject: [PATCH 34/71] [BUILD] Add abi_version_no bazel flag. (#3020) --- api/BUILD | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/api/BUILD b/api/BUILD index fdfe3ca146..dfc7d3c645 100644 --- a/api/BUILD +++ b/api/BUILD @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "int_flag", "string_flag") package(default_visibility = ["//visibility:public"]) @@ -35,6 +35,9 @@ cc_library( ":set_cxx_stdlib_2020": ["OPENTELEMETRY_STL_VERSION=2020"], ":set_cxx_stdlib_2023": ["OPENTELEMETRY_STL_VERSION=2023"], "//conditions:default": [], + }) + select({ + ":abi_version_no_1": ["OPENTELEMETRY_ABI_VERSION_NO=1"], + ":abi_version_no_2": ["OPENTELEMETRY_ABI_VERSION_NO=2"], }), strip_include_prefix = "include", tags = ["api"], @@ -61,3 +64,18 @@ bool_flag( build_setting_default = False, deprecation = "The value of this flag is ignored. Bazel builds always depend on Abseil for its pre-adopted `std::` types. You should remove this flag from your build command.", ) + +int_flag( + name = "abi_version_no", + build_setting_default = 1, +) + +config_setting( + name = "abi_version_no_1", + flag_values = {":abi_version_no": "1"}, +) + +config_setting( + name = "abi_version_no_2", + flag_values = {":abi_version_no": "2"}, +) From cc60934199c39506b69e80263eaa1503a03bf7f3 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 8 Aug 2024 21:13:54 +0200 Subject: [PATCH 35/71] [Code health] Expand iwyu coverage to include unit tests. (#3022) --- .github/workflows/iwyu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 2c84b84cdc..c675193cdb 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -39,8 +39,8 @@ jobs: -DCMAKE_CXX_STANDARD=14 \ -DWITH_STL=CXX14 \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ - -DBUILD_TESTING=OFF \ - -DBUILD_W3CTRACECONTEXT_TEST=OFF \ + -DBUILD_TESTING=ON \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_OTLP_GRPC=OFF \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_FILE=ON \ From 41538b0525963031747d61c7775e1246231c7049 Mon Sep 17 00:00:00 2001 From: Troels Hoffmeyer Date: Fri, 9 Aug 2024 13:38:17 +0200 Subject: [PATCH 36/71] [BUILD] Version opentelemetry_proto/proto_grpc shared libraries (#2992) --- cmake/opentelemetry-proto.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 498a7e5681..fa6e185c13 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -325,6 +325,7 @@ add_library( ${TRACE_SERVICE_PB_CPP_FILE} ${LOGS_SERVICE_PB_CPP_FILE} ${METRICS_SERVICE_PB_CPP_FILE}) +set_target_version(opentelemetry_proto) # Disable include-what-you-use on generated code. set_target_properties( @@ -341,6 +342,7 @@ if(WITH_OTLP_GRPC) opentelemetry_proto_grpc ${OTELCPP_PROTO_TARGET_OPTIONS} ${TRACE_SERVICE_GRPC_PB_CPP_FILE} ${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE}) + set_target_version(opentelemetry_proto_grpc) list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc) target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto) From 9e062b5bdd0920e1d6f5e7ffadc468e0b7ec945b Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 13 Aug 2024 10:51:39 +0200 Subject: [PATCH 37/71] [SEMANTIC CONVENTIONS] Upgrade semantic conventions to 1.27.0 (#3023) --- RELEASING.md | 2 +- .../trace/semantic_conventions.h | 1092 +++++++++++++---- buildscripts/semantic-convention/generate.sh | 6 +- docs/maintaining-dependencies.md | 131 +- docs/semantic-conventions.md | 76 -- .../sdk/resource/semantic_conventions.h | 1092 +++++++++++++---- 6 files changed, 1811 insertions(+), 588 deletions(-) delete mode 100644 docs/semantic-conventions.md diff --git a/RELEASING.md b/RELEASING.md index 8246e8fe44..852332e820 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -2,7 +2,7 @@ ## Pre Release -1: Upgrade to latest [semantic-conventions](docs/semantic-conventions.md) +1: Upgrade to latest [dependencies](docs/maintaining-dependencies.md) if required. 2: Make sure all relevant changes for this release are included under diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index a9290bff44..fb26385fbc 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -22,7 +22,7 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.26.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.27.0"; /** * Uniquely identifies the framework API revision offered by a version ({@code os.version}) of the @@ -31,6 +31,69 @@ static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.26 */ static constexpr const char *kAndroidOsApiLevel = "android.os.api_level"; +/** + * The provenance filename of the built attestation which directly relates to the build artifact + * filename. This filename SHOULD accompany the artifact at publish time. See the SLSA + * Relationship specification for more information. + */ +static constexpr const char *kArtifactAttestationFilename = "artifact.attestation.filename"; + +/** + * The full hash value (see + * glossary), of the built attestation. Some envelopes in the software attestation space also + * refer to this as the digest. + */ +static constexpr const char *kArtifactAttestationHash = "artifact.attestation.hash"; + +/** + * The id of the build software attestation. + */ +static constexpr const char *kArtifactAttestationId = "artifact.attestation.id"; + +/** + * The human readable file name of the artifact, typically generated during build and release +processes. Often includes the package name and version in the file name. + * + *

Notes: +

  • This file name can also act as the Package Name in cases where the +package ecosystem maps accordingly. Additionally, the artifact can be published for others, +but that is not a guarantee.
+ */ +static constexpr const char *kArtifactFilename = "artifact.filename"; + +/** + * The full hash value (see +glossary), often found in checksum.txt on a release of the artifact and used to verify package +integrity. + * + *

Notes: +

  • The specific algorithm used to create the cryptographic hash value is +not defined. In situations where an artifact has multiple +cryptographic hashes, it is up to the implementer to choose which +hash value to set here; this should be the most secure hash algorithm +that is suitable for the situation and consistent with the +corresponding attestation. The implementer can then provide the other +hash values through an additional set of attribute extensions as they +deem necessary.
+ */ +static constexpr const char *kArtifactHash = "artifact.hash"; + +/** + * The Package URL of the package artifact provides a + * standard way to identify and locate the packaged artifact. + */ +static constexpr const char *kArtifactPurl = "artifact.purl"; + +/** + * The version of the artifact. + */ +static constexpr const char *kArtifactVersion = "artifact.version"; + /** * Rate-limiting result, shows whether the lease was acquired or contains a rejection reason */ @@ -397,6 +460,12 @@ href="https://docs.aws.amazon.com/cli/latest/reference/s3api/upload-part-copy.ht */ static constexpr const char *kAwsS3UploadId = "aws.s3.upload_id"; +/** + * The unique identifier of the service request. It's generated by the Azure service and returned + * with the response. + */ +static constexpr const char *kAzServiceRequestId = "az.service_request_id"; + /** * Array of brand name and version separated by a space * @@ -443,6 +512,39 @@ provides. */ static constexpr const char *kBrowserPlatform = "browser.platform"; +/** + * The human readable name of the pipeline within a CI/CD system. + */ +static constexpr const char *kCicdPipelineName = "cicd.pipeline.name"; + +/** + * The unique identifier of a pipeline run within a CI/CD system. + */ +static constexpr const char *kCicdPipelineRunId = "cicd.pipeline.run.id"; + +/** + * The human readable name of a task within a pipeline. Task here most closely aligns with a computing process in a pipeline. + * Other terms for tasks include commands, steps, and procedures. + */ +static constexpr const char *kCicdPipelineTaskName = "cicd.pipeline.task.name"; + +/** + * The unique identifier of a task run within a pipeline. + */ +static constexpr const char *kCicdPipelineTaskRunId = "cicd.pipeline.task.run.id"; + +/** + * The URL of the pipeline run providing the + * complete address in order to locate and identify the pipeline run. + */ +static constexpr const char *kCicdPipelineTaskRunUrlFull = "cicd.pipeline.task.run.url.full"; + +/** + * The type of the task within a pipeline. + */ +static constexpr const char *kCicdPipelineTaskType = "cicd.pipeline.task.type"; + /** * Client address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. @@ -523,7 +625,7 @@ Lambda: The function ARN. Take care not to use the "invoked ARN" directly but replace any alias suffix with -the resolved function version, as the same runtime instance may be invokable with multiple different +the resolved function version, as the same runtime instance may be invocable with multiple different aliases.
  • GCP: The URI of the resource
  • Azure: The identify Docker @@ -688,26 +785,36 @@ static constexpr const char *kContainerName = "container.name"; */ static constexpr const char *kContainerRuntime = "container.runtime"; +/** + * The mode of the CPU + */ +static constexpr const char *kCpuMode = "cpu.mode"; + /** * The name of the connection pool; unique within the instrumented application. In case the - * connection pool implementation doesn't provide a name, instrumentation should use a combination - * of {@code server.address} and {@code server.port} attributes formatted as {@code - * server.address:server.port}. + * connection pool implementation doesn't provide a name, instrumentation SHOULD use a combination + * of parameters that would make the name unique, for example, combining attributes {@code + * server.address}, {@code server.port}, and {@code db.namespace}, formatted as {@code + * server.address:server.port/db.namespace}. Instrumentations that generate connection pool name + * following different patterns SHOULD document it. */ -static constexpr const char *kDbClientConnectionsPoolName = "db.client.connections.pool.name"; +static constexpr const char *kDbClientConnectionPoolName = "db.client.connection.pool.name"; /** * The state of a connection in the pool */ -static constexpr const char *kDbClientConnectionsState = "db.client.connections.state"; +static constexpr const char *kDbClientConnectionState = "db.client.connection.state"; /** * The name of a collection (table, container) within the database. * *

    Notes: -

    • If the collection name is parsed from the query, it SHOULD match the value provided in -the query and may be qualified with the schema and database name. It is RECOMMENDED to capture the -value as provided by the application without attempting to do any case normalization.
    +
    • It is RECOMMENDED to capture the value as provided by the application without attempting +to do any case normalization. If the collection name is parsed from the query text, it SHOULD be the +first collection name found in the query and it SHOULD match the value provided in the query text +including any schema and database name prefix. For batch operations, if the individual operations +are known to have the same collection name then that collection name SHOULD be used, otherwise +{@code db.collection.name} SHOULD NOT be captured.
    */ static constexpr const char *kDbCollectionName = "db.collection.name"; @@ -725,17 +832,42 @@ provided by the application without attempting to do any case normalization.
  • batch operation. + * + *

    Notes: +

    • Operations are only considered batches when they contain two or more operations, and so + {@code db.operation.batch.size} SHOULD never be {@code 1}.
    + */ +static constexpr const char *kDbOperationBatchSize = "db.operation.batch.size"; + /** * The name of the operation or command being executed. * *

    Notes:

    • It is RECOMMENDED to capture the value as provided by the application without attempting - to do any case normalization.
    +to do any case normalization. If the operation name is parsed from the query text, it SHOULD be the +first operation name found in the query. For batch operations, if the individual operations are +known to have the same operation name then that operation name SHOULD be used prepended by {@code +BATCH}, otherwise {@code db.operation.name} SHOULD be {@code BATCH} or some other database system +specific term if more applicable. */ static constexpr const char *kDbOperationName = "db.operation.name"; /** * The database query being executed. + * + *

    Notes: +

    • For sanitization see Sanitization of {@code +db.query.text}. For batch operations, if the individual operations are known to have the same +query text then that query text SHOULD be used, otherwise all of the individual query texts SHOULD +be concatenated with separator {@code ;} or some other database system specific separator if more +applicable. Even though parameterized query text can potentially have sensitive data, by using a +parameterized query the user is giving a strong signal that any sensitive data will be passed as +parameter values, and the benefit to observability of capturing the static part of the query text by +default outweighs the risk.
    */ static constexpr const char *kDbQueryText = "db.query.text"; @@ -817,11 +949,6 @@ static constexpr const char *kDbCosmosdbStatusCode = "db.cosmosdb.status_code"; */ static constexpr const char *kDbCosmosdbSubStatusCode = "db.cosmosdb.sub_status_code"; -/** - * Represents the identifier of an Elasticsearch cluster. - */ -static constexpr const char *kDbElasticsearchClusterName = "db.elasticsearch.cluster.name"; - /** * Represents the human-readable identifier of the node/instance to which a request was routed. */ @@ -832,15 +959,30 @@ static constexpr const char *kDbElasticsearchNodeName = "db.elasticsearch.node.n environment (aka deployment tier). * *

    Notes: -

    • {@code deployment.environment} does not affect the uniqueness constraints defined through -the {@code service.namespace}, {@code service.name} and {@code service.instance.id} resource +
      • {@code deployment.environment.name} does not affect the uniqueness constraints defined +through the {@code service.namespace}, {@code service.name} and {@code service.instance.id} resource attributes. This implies that resources carrying the following attribute combinations MUST be considered to be identifying the same service:
      • {@code service.name=frontend}, {@code -deployment.environment=production}
      • {@code service.name=frontend}, {@code -deployment.environment=staging}.
      • +deployment.environment.name=production}
      • {@code service.name=frontend}, {@code +deployment.environment.name=staging}.
      */ -static constexpr const char *kDeploymentEnvironment = "deployment.environment"; +static constexpr const char *kDeploymentEnvironmentName = "deployment.environment.name"; + +/** + * The id of the deployment. + */ +static constexpr const char *kDeploymentId = "deployment.id"; + +/** + * The name of the deployment. + */ +static constexpr const char *kDeploymentName = "deployment.name"; + +/** + * The status of the deployment. + */ +static constexpr const char *kDeploymentStatus = "deployment.status"; /** * Deprecated use the {@code device.app.lifecycle} event definition including {@code android.state} @@ -853,6 +995,14 @@ static constexpr const char *kDeploymentEnvironment = "deployment.environment"; */ static constexpr const char *kAndroidState = "android.state"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kContainerCpuState = "container.cpu.state"; + /** * Deprecated, use {@code db.collection.name} instead. * @@ -877,6 +1027,14 @@ static constexpr const char *kDbConnectionString = "db.connection_string"; OPENTELEMETRY_DEPRECATED static constexpr const char *kDbCosmosdbContainer = "db.cosmosdb.container"; +/** + * Deprecated, use {@code db.namespace} instead. + * + * @deprecated Deprecated, use `db.namespace` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbElasticsearchClusterName = "db.elasticsearch.cluster.name"; + /** * Deprecated, no general replacement at this time. For Elasticsearch, use {@code * db.elasticsearch.node.name} instead. @@ -961,21 +1119,85 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kDbUser = "db.user"; /** - * Deprecated, use {@code db.client.connections.pool.name} instead. + * Deprecated, use {@code db.client.connection.pool.name} instead. + * + * @deprecated Deprecated, use `db.client.connection.pool.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbClientConnectionsPoolName = "db.client.connections.pool.name"; + +/** + * Deprecated, use {@code db.client.connection.state} instead. + * + * @deprecated Deprecated, use `db.client.connection.state` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbClientConnectionsState = "db.client.connections.state"; + +/** + * Deprecated, use {@code db.client.connection.pool.name} instead. * - * @deprecated Deprecated, use `db.client.connections.pool.name` instead. + * @deprecated Deprecated, use `db.client.connection.pool.name` instead. */ OPENTELEMETRY_DEPRECATED static constexpr const char *kPoolName = "pool.name"; /** - * Deprecated, use {@code db.client.connections.state} instead. + * Deprecated, use {@code db.client.connection.state} instead. * - * @deprecated Deprecated, use `db.client.connections.state` instead. + * @deprecated Deprecated, use `db.client.connection.state` instead. */ OPENTELEMETRY_DEPRECATED static constexpr const char *kState = "state"; +/** + * 'Deprecated, use {@code deployment.environment.name} instead.' + * + * @deprecated 'Deprecated, use `deployment.environment.name` instead.'. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDeploymentEnvironment = "deployment.environment"; + +/** + * Deprecated, use {@code user.id} instead. + * + * @deprecated Deprecated, use `user.id` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserId = "enduser.id"; + +/** + * Deprecated, use {@code user.roles} instead. + * + * @deprecated Deprecated, use `user.roles` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserRole = "enduser.role"; + +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserScope = "enduser.scope"; + +/** + * Deprecated, use {@code gen_ai.usage.output_tokens} instead. + * + * @deprecated Deprecated, use `gen_ai.usage.output_tokens` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kGenAiUsageCompletionTokens = "gen_ai.usage.completion_tokens"; + +/** + * Deprecated, use {@code gen_ai.usage.input_tokens} instead. + * + * @deprecated Deprecated, use `gen_ai.usage.input_tokens` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kGenAiUsagePromptTokens = "gen_ai.usage.prompt_tokens"; + /** * Deprecated, use {@code client.address} instead. * @@ -1107,6 +1329,41 @@ static constexpr const char *kHttpUserAgent = "http.user_agent"; OPENTELEMETRY_DEPRECATED static constexpr const char *kIosState = "ios.state"; +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingDestinationPublishAnonymous = + "messaging.destination_publish.anonymous"; + +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingDestinationPublishName = + "messaging.destination_publish.name"; + +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingEventhubsConsumerGroup = + "messaging.eventhubs.consumer.group"; + +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.consumer.group"; + /** * Deprecated, use {@code messaging.destination.partition.id} instead. * @@ -1116,6 +1373,14 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kMessagingKafkaDestinationPartition = "messaging.kafka.destination.partition"; +/** + * Deprecated, use {@code messaging.kafka.offset} instead. + * + * @deprecated Deprecated, use `messaging.kafka.offset` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingKafkaMessageOffset = "messaging.kafka.message.offset"; + /** * Deprecated, use {@code messaging.operation.type} instead. * @@ -1124,6 +1389,23 @@ static constexpr const char *kMessagingKafkaDestinationPartition = OPENTELEMETRY_DEPRECATED static constexpr const char *kMessagingOperation = "messaging.operation"; +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingRocketmqClientGroup = "messaging.rocketmq.client_group"; + +/** + * Deprecated, use {@code messaging.servicebus.destination.subscription_name} instead. + * + * @deprecated Deprecated, use `messaging.servicebus.destination.subscription_name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingServicebusDestinationSubscriptionName = + "messaging.servicebus.destination.subscription_name"; + /** * Deprecated, use {@code network.local.address}. * @@ -1247,21 +1529,29 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kNetTransport = "net.transport"; /** - * None * - * @deprecated None. + * + * @deprecated . */ OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryName = "otel.library.name"; /** - * None * - * @deprecated None. + * + * @deprecated . */ OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryVersion = "otel.library.version"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kProcessCpuState = "process.cpu.state"; + /** * Deprecated, use {@code rpc.message.compressed_size} instead. * @@ -1294,6 +1584,14 @@ static constexpr const char *kMessageType = "message.type"; OPENTELEMETRY_DEPRECATED static constexpr const char *kMessageUncompressedSize = "message.uncompressed_size"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kSystemCpuState = "system.cpu.state"; + /** * Deprecated, use {@code system.process.status} instead. * @@ -1302,6 +1600,14 @@ static constexpr const char *kMessageUncompressedSize = "message.uncompressed_si OPENTELEMETRY_DEPRECATED static constexpr const char *kSystemProcessesStatus = "system.processes.status"; +/** + * Deprecated, use {@code server.address} instead. + * + * @deprecated Deprecated, use `server.address` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kTlsClientServerName = "tls.client.server_name"; + /** * Destination address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. @@ -1380,29 +1686,6 @@ static constexpr const char *kDiskIoDirection = "disk.io.direction"; */ static constexpr const char *kDnsQuestionName = "dns.question.name"; -/** - * Username or client_id extracted from the access token or Authorization header in the inbound - * request from outside the system. - */ -static constexpr const char *kEnduserId = "enduser.id"; - -/** - * Actual/assumed role the client is making the request under extracted from token or application - * security context. - */ -static constexpr const char *kEnduserRole = "enduser.role"; - -/** - * Scopes or granted authorities the client currently possesses extracted from token or application - * security context. The value would come from the scope associated with an OAuth 2.0 Access Token or an attribute - * value in a SAML 2.0 - * Assertion. - */ -static constexpr const char *kEnduserScope = "enduser.scope"; - /** * Describes a class of error the operation ended with. * @@ -1428,9 +1711,9 @@ static constexpr const char *kErrorType = "error.type"; * *

      Notes:

      • Event names are subject to the same rules as attribute - names. Notably, event names are namespaced to avoid collisions and provide a clean separation - of semantics for events in separate domains like browser, mobile, and kubernetes.
      + href="/docs/general/attribute-naming.md">attribute names. Notably, event names are namespaced + to avoid collisions and provide a clean separation of semantics for events in separate domains like + browser, mobile, and kubernetes.
    */ static constexpr const char *kEventName = "event.name"; @@ -1665,6 +1948,16 @@ static constexpr const char *kFilePath = "file.path"; */ static constexpr const char *kFileSize = "file.size"; +/** + * Identifies the Google Cloud service for which the official client library is intended. + * + *

    Notes: +

    • Intended to be a stable identifier for Google Cloud client libraries that is uniform + across implementation languages. The value should be derived from the canonical service domain for + the service; for example, 'foo.googleapis.com' should result in a value of 'foo'.
    + */ +static constexpr const char *kGcpClientService = "gcp.client.service"; + /** * The name of the Cloud Run execution being run for the @@ -1697,7 +1990,7 @@ static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostnam static constexpr const char *kGcpGceInstanceName = "gcp.gce.instance.name"; /** - * The full response received from the LLM. + * The full response received from the GenAI model. * *

    Notes:

    */ static constexpr const char *kDbOperationName = "db.operation.name"; /** * The database query being executed. + * + *

    Notes: +

    • For sanitization see Sanitization of {@code +db.query.text}. For batch operations, if the individual operations are known to have the same +query text then that query text SHOULD be used, otherwise all of the individual query texts SHOULD +be concatenated with separator {@code ;} or some other database system specific separator if more +applicable. Even though parameterized query text can potentially have sensitive data, by using a +parameterized query the user is giving a strong signal that any sensitive data will be passed as +parameter values, and the benefit to observability of capturing the static part of the query text by +default outweighs the risk.
    */ static constexpr const char *kDbQueryText = "db.query.text"; @@ -819,11 +951,6 @@ static constexpr const char *kDbCosmosdbStatusCode = "db.cosmosdb.status_code"; */ static constexpr const char *kDbCosmosdbSubStatusCode = "db.cosmosdb.sub_status_code"; -/** - * Represents the identifier of an Elasticsearch cluster. - */ -static constexpr const char *kDbElasticsearchClusterName = "db.elasticsearch.cluster.name"; - /** * Represents the human-readable identifier of the node/instance to which a request was routed. */ @@ -834,15 +961,30 @@ static constexpr const char *kDbElasticsearchNodeName = "db.elasticsearch.node.n environment (aka deployment tier). * *

    Notes: -

    • {@code deployment.environment} does not affect the uniqueness constraints defined through -the {@code service.namespace}, {@code service.name} and {@code service.instance.id} resource +
      • {@code deployment.environment.name} does not affect the uniqueness constraints defined +through the {@code service.namespace}, {@code service.name} and {@code service.instance.id} resource attributes. This implies that resources carrying the following attribute combinations MUST be considered to be identifying the same service:
      • {@code service.name=frontend}, {@code -deployment.environment=production}
      • {@code service.name=frontend}, {@code -deployment.environment=staging}.
      • +deployment.environment.name=production}
      • {@code service.name=frontend}, {@code +deployment.environment.name=staging}.
      */ -static constexpr const char *kDeploymentEnvironment = "deployment.environment"; +static constexpr const char *kDeploymentEnvironmentName = "deployment.environment.name"; + +/** + * The id of the deployment. + */ +static constexpr const char *kDeploymentId = "deployment.id"; + +/** + * The name of the deployment. + */ +static constexpr const char *kDeploymentName = "deployment.name"; + +/** + * The status of the deployment. + */ +static constexpr const char *kDeploymentStatus = "deployment.status"; /** * Deprecated use the {@code device.app.lifecycle} event definition including {@code android.state} @@ -855,6 +997,14 @@ static constexpr const char *kDeploymentEnvironment = "deployment.environment"; */ static constexpr const char *kAndroidState = "android.state"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kContainerCpuState = "container.cpu.state"; + /** * Deprecated, use {@code db.collection.name} instead. * @@ -879,6 +1029,14 @@ static constexpr const char *kDbConnectionString = "db.connection_string"; OPENTELEMETRY_DEPRECATED static constexpr const char *kDbCosmosdbContainer = "db.cosmosdb.container"; +/** + * Deprecated, use {@code db.namespace} instead. + * + * @deprecated Deprecated, use `db.namespace` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbElasticsearchClusterName = "db.elasticsearch.cluster.name"; + /** * Deprecated, no general replacement at this time. For Elasticsearch, use {@code * db.elasticsearch.node.name} instead. @@ -963,21 +1121,85 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kDbUser = "db.user"; /** - * Deprecated, use {@code db.client.connections.pool.name} instead. + * Deprecated, use {@code db.client.connection.pool.name} instead. + * + * @deprecated Deprecated, use `db.client.connection.pool.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbClientConnectionsPoolName = "db.client.connections.pool.name"; + +/** + * Deprecated, use {@code db.client.connection.state} instead. + * + * @deprecated Deprecated, use `db.client.connection.state` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDbClientConnectionsState = "db.client.connections.state"; + +/** + * Deprecated, use {@code db.client.connection.pool.name} instead. * - * @deprecated Deprecated, use `db.client.connections.pool.name` instead. + * @deprecated Deprecated, use `db.client.connection.pool.name` instead. */ OPENTELEMETRY_DEPRECATED static constexpr const char *kPoolName = "pool.name"; /** - * Deprecated, use {@code db.client.connections.state} instead. + * Deprecated, use {@code db.client.connection.state} instead. * - * @deprecated Deprecated, use `db.client.connections.state` instead. + * @deprecated Deprecated, use `db.client.connection.state` instead. */ OPENTELEMETRY_DEPRECATED static constexpr const char *kState = "state"; +/** + * 'Deprecated, use {@code deployment.environment.name} instead.' + * + * @deprecated 'Deprecated, use `deployment.environment.name` instead.'. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kDeploymentEnvironment = "deployment.environment"; + +/** + * Deprecated, use {@code user.id} instead. + * + * @deprecated Deprecated, use `user.id` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserId = "enduser.id"; + +/** + * Deprecated, use {@code user.roles} instead. + * + * @deprecated Deprecated, use `user.roles` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserRole = "enduser.role"; + +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kEnduserScope = "enduser.scope"; + +/** + * Deprecated, use {@code gen_ai.usage.output_tokens} instead. + * + * @deprecated Deprecated, use `gen_ai.usage.output_tokens` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kGenAiUsageCompletionTokens = "gen_ai.usage.completion_tokens"; + +/** + * Deprecated, use {@code gen_ai.usage.input_tokens} instead. + * + * @deprecated Deprecated, use `gen_ai.usage.input_tokens` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kGenAiUsagePromptTokens = "gen_ai.usage.prompt_tokens"; + /** * Deprecated, use {@code client.address} instead. * @@ -1109,6 +1331,41 @@ static constexpr const char *kHttpUserAgent = "http.user_agent"; OPENTELEMETRY_DEPRECATED static constexpr const char *kIosState = "ios.state"; +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingDestinationPublishAnonymous = + "messaging.destination_publish.anonymous"; + +/** + * Deprecated, no replacement at this time. + * + * @deprecated Deprecated, no replacement at this time. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingDestinationPublishName = + "messaging.destination_publish.name"; + +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingEventhubsConsumerGroup = + "messaging.eventhubs.consumer.group"; + +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.consumer.group"; + /** * Deprecated, use {@code messaging.destination.partition.id} instead. * @@ -1118,6 +1375,14 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kMessagingKafkaDestinationPartition = "messaging.kafka.destination.partition"; +/** + * Deprecated, use {@code messaging.kafka.offset} instead. + * + * @deprecated Deprecated, use `messaging.kafka.offset` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingKafkaMessageOffset = "messaging.kafka.message.offset"; + /** * Deprecated, use {@code messaging.operation.type} instead. * @@ -1126,6 +1391,23 @@ static constexpr const char *kMessagingKafkaDestinationPartition = OPENTELEMETRY_DEPRECATED static constexpr const char *kMessagingOperation = "messaging.operation"; +/** + * Deprecated, use {@code messaging.consumer.group.name} instead. + * + * @deprecated Deprecated, use `messaging.consumer.group.name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingRocketmqClientGroup = "messaging.rocketmq.client_group"; + +/** + * Deprecated, use {@code messaging.servicebus.destination.subscription_name} instead. + * + * @deprecated Deprecated, use `messaging.servicebus.destination.subscription_name` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kMessagingServicebusDestinationSubscriptionName = + "messaging.servicebus.destination.subscription_name"; + /** * Deprecated, use {@code network.local.address}. * @@ -1249,21 +1531,29 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kNetTransport = "net.transport"; /** - * None * - * @deprecated None. + * + * @deprecated . */ OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryName = "otel.library.name"; /** - * None * - * @deprecated None. + * + * @deprecated . */ OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryVersion = "otel.library.version"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kProcessCpuState = "process.cpu.state"; + /** * Deprecated, use {@code rpc.message.compressed_size} instead. * @@ -1296,6 +1586,14 @@ static constexpr const char *kMessageType = "message.type"; OPENTELEMETRY_DEPRECATED static constexpr const char *kMessageUncompressedSize = "message.uncompressed_size"; +/** + * Deprecated, use {@code cpu.mode} instead. + * + * @deprecated Deprecated, use `cpu.mode` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kSystemCpuState = "system.cpu.state"; + /** * Deprecated, use {@code system.process.status} instead. * @@ -1304,6 +1602,14 @@ static constexpr const char *kMessageUncompressedSize = "message.uncompressed_si OPENTELEMETRY_DEPRECATED static constexpr const char *kSystemProcessesStatus = "system.processes.status"; +/** + * Deprecated, use {@code server.address} instead. + * + * @deprecated Deprecated, use `server.address` instead. + */ +OPENTELEMETRY_DEPRECATED +static constexpr const char *kTlsClientServerName = "tls.client.server_name"; + /** * Destination address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. @@ -1382,29 +1688,6 @@ static constexpr const char *kDiskIoDirection = "disk.io.direction"; */ static constexpr const char *kDnsQuestionName = "dns.question.name"; -/** - * Username or client_id extracted from the access token or Authorization header in the inbound - * request from outside the system. - */ -static constexpr const char *kEnduserId = "enduser.id"; - -/** - * Actual/assumed role the client is making the request under extracted from token or application - * security context. - */ -static constexpr const char *kEnduserRole = "enduser.role"; - -/** - * Scopes or granted authorities the client currently possesses extracted from token or application - * security context. The value would come from the scope associated with an OAuth 2.0 Access Token or an attribute - * value in a SAML 2.0 - * Assertion. - */ -static constexpr const char *kEnduserScope = "enduser.scope"; - /** * Describes a class of error the operation ended with. * @@ -1430,9 +1713,9 @@ static constexpr const char *kErrorType = "error.type"; * *

      Notes:

      • Event names are subject to the same rules as attribute - names. Notably, event names are namespaced to avoid collisions and provide a clean separation - of semantics for events in separate domains like browser, mobile, and kubernetes.
      + href="/docs/general/attribute-naming.md">attribute names. Notably, event names are namespaced + to avoid collisions and provide a clean separation of semantics for events in separate domains like + browser, mobile, and kubernetes.
    */ static constexpr const char *kEventName = "event.name"; @@ -1667,6 +1950,16 @@ static constexpr const char *kFilePath = "file.path"; */ static constexpr const char *kFileSize = "file.size"; +/** + * Identifies the Google Cloud service for which the official client library is intended. + * + *

    Notes: +

    • Intended to be a stable identifier for Google Cloud client libraries that is uniform + across implementation languages. The value should be derived from the canonical service domain for + the service; for example, 'foo.googleapis.com' should result in a value of 'foo'.
    + */ +static constexpr const char *kGcpClientService = "gcp.client.service"; + /** * The name of the Cloud Run execution being run for the @@ -1699,7 +1992,7 @@ static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostnam static constexpr const char *kGcpGceInstanceName = "gcp.gce.instance.name"; /** - * The full response received from the LLM. + * The full response received from the GenAI model. * *

    Notes:

    • It's RECOMMENDED to format completions as JSON string matching Notes: +
      • If one of the predefined values applies, but specific system uses a different name it's + RECOMMENDED to document it in the semantic conventions for specific GenAI system and use + system-specific name in the instrumentation. If a different name is not documented, instrumentation + libraries SHOULD use applicable predefined value.
      + */ +static constexpr const char *kGenAiOperationName = "gen_ai.operation.name"; + +/** + * The full prompt sent to the GenAI model. * *

      Notes:

      • It's RECOMMENDED to format prompts as JSON string matching Notes: -
        • The actual GenAI product may differ from the one identified by the client. For example, - when using OpenAI client libraries to communicate with Mistral, the {@code gen_ai.system} is set to - {@code openai} based on the instrumentation's best knowledge.
        +
        • The {@code gen_ai.system} describes a family of GenAI models with specific model +identified by {@code gen_ai.request.model} and {@code gen_ai.response.model} attributes.
        • The +actual GenAI product may differ from the one identified by the client. For example, when using +OpenAI client libraries to communicate with Mistral, the {@code gen_ai.system} is set to {@code +openai} based on the instrumentation's best knowledge.
        • For custom model, a custom friendly +name SHOULD be used. If none of these options apply, the {@code gen_ai.system} SHOULD be set to +{@code _OTHER}.
        */ static constexpr const char *kGenAiSystem = "gen_ai.system"; /** - * The number of tokens used in the LLM response (completion). + * The type of token being counted. */ -static constexpr const char *kGenAiUsageCompletionTokens = "gen_ai.usage.completion_tokens"; +static constexpr const char *kGenAiTokenType = "gen_ai.token.type"; /** - * The number of tokens used in the LLM prompt. + * The number of tokens used in the GenAI input (prompt). */ -static constexpr const char *kGenAiUsagePromptTokens = "gen_ai.usage.prompt_tokens"; +static constexpr const char *kGenAiUsageInputTokens = "gen_ai.usage.input_tokens"; + +/** + * The number of tokens used in the GenAI response (completion). + */ +static constexpr const char *kGenAiUsageOutputTokens = "gen_ai.usage.output_tokens"; + +/** + * The type of memory. + */ +static constexpr const char *kGoMemoryType = "go.memory.type"; /** * The GraphQL document being executed. @@ -2178,6 +2516,11 @@ static constexpr const char *kK8sStatefulsetName = "k8s.statefulset.name"; */ static constexpr const char *kK8sStatefulsetUid = "k8s.statefulset.uid"; +/** + * The Linux Slab memory state + */ +static constexpr const char *kLinuxMemorySlabState = "linux.memory.slab.state"; + /** * The stream associated with the log. See below for a list of well-known values. */ @@ -2203,6 +2546,16 @@ static constexpr const char *kLogFilePath = "log.file.path"; */ static constexpr const char *kLogFilePathResolved = "log.file.path_resolved"; +/** + * The complete orignal Log Record. + * + *

        Notes: +

        • This value MAY be added when processing a Log Record which was originally transmitted as + a string or equivalent data type AND the Body field of the Log Record does not contain the same + value. (e.g. a syslog or a log record read from a file.)
        + */ +static constexpr const char *kLogRecordOriginal = "log.record.original"; + /** * A unique identifier for the Log Record. * @@ -2231,6 +2584,16 @@ static constexpr const char *kMessagingBatchMessageCount = "messaging.batch.mess */ static constexpr const char *kMessagingClientId = "messaging.client.id"; +/** + * The name of the consumer group with which a consumer is associated. + * + *

        Notes: +

        • Semantic conventions for individual messaging systems SHOULD document whether {@code + messaging.consumer.group.name} is applicable and what it means in the context of that system.
        • +
        + */ +static constexpr const char *kMessagingConsumerGroupName = "messaging.consumer.group.name"; + /** * A boolean that is true if the message destination is anonymous (could be unnamed or have * auto-generated name). @@ -2254,6 +2617,17 @@ static constexpr const char *kMessagingDestinationName = "messaging.destination. static constexpr const char *kMessagingDestinationPartitionId = "messaging.destination.partition.id"; +/** + * The name of the destination subscription from which a message is consumed. + * + *

        Notes: +

        • Semantic conventions for individual messaging systems SHOULD document whether {@code + messaging.destination.subscription.name} is applicable and what it means in the context of that + system.
        + */ +static constexpr const char *kMessagingDestinationSubscriptionName = + "messaging.destination.subscription.name"; + /** * Low cardinality representation of the messaging destination name * @@ -2271,24 +2645,6 @@ static constexpr const char *kMessagingDestinationTemplate = "messaging.destinat */ static constexpr const char *kMessagingDestinationTemporary = "messaging.destination.temporary"; -/** - * A boolean that is true if the publish message destination is anonymous (could be unnamed or have - * auto-generated name). - */ -static constexpr const char *kMessagingDestinationPublishAnonymous = - "messaging.destination_publish.anonymous"; - -/** - * The name of the original destination the message was published to - * - *

        Notes: -

        • The name SHOULD uniquely identify a specific queue, topic, or other entity within the -broker. If the broker doesn't have such notion, the original destination name SHOULD uniquely -identify the broker.
        - */ -static constexpr const char *kMessagingDestinationPublishName = - "messaging.destination_publish.name"; - /** * The size of the message body in bytes. * @@ -2341,12 +2697,6 @@ static constexpr const char *kMessagingOperationType = "messaging.operation.type */ static constexpr const char *kMessagingSystem = "messaging.system"; -/** - * Name of the Kafka Consumer Group that is handling the message. Only applies to consumers, not - * producers. - */ -static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.consumer.group"; - /** * Message keys in Kafka are used for grouping alike messages to ensure they're processed on the same partition. They differ from {@code messaging.message.id} in that they're not unique. If the @@ -2360,14 +2710,14 @@ static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.con static constexpr const char *kMessagingKafkaMessageKey = "messaging.kafka.message.key"; /** - * The offset of a record in the corresponding Kafka partition. + * A boolean that is true if the message is a tombstone. */ -static constexpr const char *kMessagingKafkaMessageOffset = "messaging.kafka.message.offset"; +static constexpr const char *kMessagingKafkaMessageTombstone = "messaging.kafka.message.tombstone"; /** - * A boolean that is true if the message is a tombstone. + * The offset of a record in the corresponding Kafka partition. */ -static constexpr const char *kMessagingKafkaMessageTombstone = "messaging.kafka.message.tombstone"; +static constexpr const char *kMessagingKafkaOffset = "messaging.kafka.offset"; /** * RabbitMQ message routing key. @@ -2381,12 +2731,6 @@ static constexpr const char *kMessagingRabbitmqDestinationRoutingKey = static constexpr const char *kMessagingRabbitmqMessageDeliveryTag = "messaging.rabbitmq.message.delivery_tag"; -/** - * Name of the RocketMQ producer/consumer group that is handling the message. The client type is - * identified by the SpanKind. - */ -static constexpr const char *kMessagingRocketmqClientGroup = "messaging.rocketmq.client_group"; - /** * Model of message consumption. This only applies to consumer spans. */ @@ -2456,12 +2800,6 @@ static constexpr const char *kMessagingGcpPubsubMessageDeliveryAttempt = static constexpr const char *kMessagingGcpPubsubMessageOrderingKey = "messaging.gcp_pubsub.message.ordering_key"; -/** - * The name of the subscription in the topic messages are received from. - */ -static constexpr const char *kMessagingServicebusDestinationSubscriptionName = - "messaging.servicebus.destination.subscription_name"; - /** * Describes the
        settlement @@ -2482,12 +2820,6 @@ static constexpr const char *kMessagingServicebusMessageDeliveryCount = static constexpr const char *kMessagingServicebusMessageEnqueuedTime = "messaging.servicebus.message.enqueued_time"; -/** - * The name of the consumer group the event consumer is associated with. - */ -static constexpr const char *kMessagingEventhubsConsumerGroup = - "messaging.eventhubs.consumer.group"; - /** * The UTC epoch seconds at which the message has been accepted and stored in the entity. */ @@ -2771,8 +3103,7 @@ static constexpr const char *kProcessRealUserName = "process.real_user.name"; static constexpr const char *kProcessRuntimeDescription = "process.runtime.description"; /** - * The name of the runtime of this process. For compiled native binaries, this SHOULD be the name of - * the compiler. + * The name of the runtime of this process. */ static constexpr const char *kProcessRuntimeName = "process.runtime.name"; @@ -2816,11 +3147,6 @@ static constexpr const char *kProcessUserName = "process.user.name"; */ static constexpr const char *kProcessVpid = "process.vpid"; -/** - * The CPU state of the process. - */ -static constexpr const char *kProcessCpuState = "process.cpu.state"; - /** * The error codes of the Connect * request. Error codes are always string values. @@ -3040,11 +3366,6 @@ static constexpr const char *kSystemDevice = "system.device"; */ static constexpr const char *kSystemCpuLogicalNumber = "system.cpu.logical_number"; -/** - * The state of the CPU - */ -static constexpr const char *kSystemCpuState = "system.cpu.state"; - /** * The memory state */ @@ -3136,6 +3457,27 @@ static constexpr const char *kTelemetryDistroName = "telemetry.distro.name"; */ static constexpr const char *kTelemetryDistroVersion = "telemetry.distro.version"; +/** + * The fully qualified human readable name of the test case. + */ +static constexpr const char *kTestCaseName = "test.case.name"; + +/** + * The status of the actual test case result from test execution. + */ +static constexpr const char *kTestCaseResultStatus = "test.case.result.status"; + +/** + * The human readable name of a test suite. + */ +static constexpr const char *kTestSuiteName = "test.suite.name"; + +/** + * The status of the test suite run. + */ +static constexpr const char *kTestSuiteRunStatus = "test.suite.run.status"; + /** * Current "managed" thread ID (as opposed to OS thread ID). */ @@ -3215,12 +3557,6 @@ static constexpr const char *kTlsClientNotAfter = "tls.client.not_after"; */ static constexpr const char *kTlsClientNotBefore = "tls.client.not_before"; -/** - * Also called an SNI, this tells the server which hostname to which the client is attempting to - * connect to. - */ -static constexpr const char *kTlsClientServerName = "tls.client.server_name"; - /** * Distinguished name of subject of the x.509 certificate presented by the client. */ @@ -3483,6 +3819,102 @@ static constexpr const char *kUserAgentOriginal = "user_agent.original"; */ static constexpr const char *kUserAgentVersion = "user_agent.version"; +/** + * User email address. + */ +static constexpr const char *kUserEmail = "user.email"; + +/** + * User's full name + */ +static constexpr const char *kUserFullName = "user.full_name"; + +/** + * Unique user hash to correlate information for a user in anonymized form. + * + *

        Notes: +

        • Useful if {@code user.id} or {@code user.name} contain confidential information and + cannot be used.
        + */ +static constexpr const char *kUserHash = "user.hash"; + +/** + * Unique identifier of the user. + */ +static constexpr const char *kUserId = "user.id"; + +/** + * Short name or login/username of the user. + */ +static constexpr const char *kUserName = "user.name"; + +/** + * Array of user roles at the time of the event. + */ +static constexpr const char *kUserRoles = "user.roles"; + +/** + * The type of garbage collection. + */ +static constexpr const char *kV8jsGcType = "v8js.gc.type"; + +/** + * The name of the space type of heap memory. + * + *

        Notes: +

        + */ +static constexpr const char *kV8jsHeapSpaceName = "v8js.heap.space.name"; + +/** + * The ID of the change (pull request/merge request) if applicable. This is usually a unique (within + * repository) identifier generated by the VCS system. + */ +static constexpr const char *kVcsRepositoryChangeId = "vcs.repository.change.id"; + +/** + * The human readable title of the change (pull request/merge request). This title is often a brief + * summary of the change and may get merged in to a ref as the commit summary. + */ +static constexpr const char *kVcsRepositoryChangeTitle = "vcs.repository.change.title"; + +/** + * The name of the reference such as + * branch or tag in the repository. + */ +static constexpr const char *kVcsRepositoryRefName = "vcs.repository.ref.name"; + +/** + * The revision, literally revised +version, The revision most often refers to a commit object in Git, or a revision number in SVN. + * + *

        Notes: +

        • The revision can be a full hash value (see glossary), of +the recorded change to a ref within a repository pointing to a commit commit object. It does not necessarily have to be a +hash; it can simply define a revision number which +is an integer that is monotonically increasing. In cases where it is identical to the {@code +ref.name}, it SHOULD still be included. It is up to the implementer to decide which value to set as +the revision based on the VCS system and situational context.
        + */ +static constexpr const char *kVcsRepositoryRefRevision = "vcs.repository.ref.revision"; + +/** + * The type of the reference in the + * repository. + */ +static constexpr const char *kVcsRepositoryRefType = "vcs.repository.ref.type"; + +/** + * The URL of the repository providing the complete + * address in order to locate and identify the repository. + */ +static constexpr const char *kVcsRepositoryUrlFull = "vcs.repository.url.full"; + /** * Additional description of the web engine (e.g. detailed version and edition information). */ @@ -3539,6 +3971,16 @@ static constexpr const char *kEc2 = "ec2"; static constexpr const char *kFargate = "fargate"; } // namespace AwsEcsLaunchtypeValues +namespace CicdPipelineTaskTypeValues +{ +/** build. */ +static constexpr const char *kBuild = "build"; +/** test. */ +static constexpr const char *kTest = "test"; +/** deploy. */ +static constexpr const char *kDeploy = "deploy"; +} // namespace CicdPipelineTaskTypeValues + namespace CloudPlatformValues { /** Alibaba Cloud Elastic Compute Service. */ @@ -3617,132 +4059,144 @@ static constexpr const char *kIbmCloud = "ibm_cloud"; static constexpr const char *kTencentCloud = "tencent_cloud"; } // namespace CloudProviderValues -namespace ContainerCpuStateValues +namespace CpuModeValues { -/** When tasks of the cgroup are in user mode (Linux). When all container processes are in user mode - * (Windows). */ +/** user. */ static constexpr const char *kUser = "user"; -/** When CPU is used by the system (host OS). */ +/** system. */ static constexpr const char *kSystem = "system"; -/** When tasks of the cgroup are in kernel mode (Linux). When all container processes are in kernel - * mode (Windows). */ +/** nice. */ +static constexpr const char *kNice = "nice"; +/** idle. */ +static constexpr const char *kIdle = "idle"; +/** iowait. */ +static constexpr const char *kIowait = "iowait"; +/** interrupt. */ +static constexpr const char *kInterrupt = "interrupt"; +/** steal. */ +static constexpr const char *kSteal = "steal"; +/** kernel. */ static constexpr const char *kKernel = "kernel"; -} // namespace ContainerCpuStateValues +} // namespace CpuModeValues -namespace DbClientConnectionsStateValues +namespace DbClientConnectionStateValues { /** idle. */ static constexpr const char *kIdle = "idle"; /** used. */ static constexpr const char *kUsed = "used"; -} // namespace DbClientConnectionsStateValues +} // namespace DbClientConnectionStateValues namespace DbSystemValues { /** Some other SQL database. Fallback only. See notes. */ static constexpr const char *kOtherSql = "other_sql"; -/** Microsoft SQL Server. */ -static constexpr const char *kMssql = "mssql"; -/** Microsoft SQL Server Compact. */ -static constexpr const char *kMssqlcompact = "mssqlcompact"; -/** MySQL. */ -static constexpr const char *kMysql = "mysql"; -/** Oracle Database. */ -static constexpr const char *kOracle = "oracle"; -/** IBM Db2. */ -static constexpr const char *kDb2 = "db2"; -/** PostgreSQL. */ -static constexpr const char *kPostgresql = "postgresql"; -/** Amazon Redshift. */ -static constexpr const char *kRedshift = "redshift"; -/** Apache Hive. */ -static constexpr const char *kHive = "hive"; -/** Cloudscape. */ -static constexpr const char *kCloudscape = "cloudscape"; -/** HyperSQL DataBase. */ -static constexpr const char *kHsqldb = "hsqldb"; -/** Progress Database. */ -static constexpr const char *kProgress = "progress"; -/** SAP MaxDB. */ -static constexpr const char *kMaxdb = "maxdb"; -/** SAP HANA. */ -static constexpr const char *kHanadb = "hanadb"; -/** Ingres. */ -static constexpr const char *kIngres = "ingres"; -/** FirstSQL. */ -static constexpr const char *kFirstsql = "firstsql"; -/** EnterpriseDB. */ -static constexpr const char *kEdb = "edb"; -/** InterSystems Caché. */ -static constexpr const char *kCache = "cache"; /** Adabas (Adaptable Database System). */ static constexpr const char *kAdabas = "adabas"; -/** Firebird. */ -static constexpr const char *kFirebird = "firebird"; +/** Deprecated, use `intersystems_cache` instead. */ +static constexpr const char *kCache = "cache"; +/** InterSystems Caché. */ +static constexpr const char *kIntersystemsCache = "intersystems_cache"; +/** Apache Cassandra. */ +static constexpr const char *kCassandra = "cassandra"; +/** ClickHouse. */ +static constexpr const char *kClickhouse = "clickhouse"; +/** Deprecated, use `other_sql` instead. */ +static constexpr const char *kCloudscape = "cloudscape"; +/** CockroachDB. */ +static constexpr const char *kCockroachdb = "cockroachdb"; +/** Deprecated, no replacement at this time. */ +static constexpr const char *kColdfusion = "coldfusion"; +/** Microsoft Azure Cosmos DB. */ +static constexpr const char *kCosmosdb = "cosmosdb"; +/** Couchbase. */ +static constexpr const char *kCouchbase = "couchbase"; +/** CouchDB. */ +static constexpr const char *kCouchdb = "couchdb"; +/** IBM Db2. */ +static constexpr const char *kDb2 = "db2"; /** Apache Derby. */ static constexpr const char *kDerby = "derby"; +/** Amazon DynamoDB. */ +static constexpr const char *kDynamodb = "dynamodb"; +/** EnterpriseDB. */ +static constexpr const char *kEdb = "edb"; +/** Elasticsearch. */ +static constexpr const char *kElasticsearch = "elasticsearch"; /** FileMaker. */ static constexpr const char *kFilemaker = "filemaker"; +/** Firebird. */ +static constexpr const char *kFirebird = "firebird"; +/** Deprecated, use `other_sql` instead. */ +static constexpr const char *kFirstsql = "firstsql"; +/** Apache Geode. */ +static constexpr const char *kGeode = "geode"; +/** H2. */ +static constexpr const char *kH2 = "h2"; +/** SAP HANA. */ +static constexpr const char *kHanadb = "hanadb"; +/** Apache HBase. */ +static constexpr const char *kHbase = "hbase"; +/** Apache Hive. */ +static constexpr const char *kHive = "hive"; +/** HyperSQL DataBase. */ +static constexpr const char *kHsqldb = "hsqldb"; +/** InfluxDB. */ +static constexpr const char *kInfluxdb = "influxdb"; /** Informix. */ static constexpr const char *kInformix = "informix"; +/** Ingres. */ +static constexpr const char *kIngres = "ingres"; /** InstantDB. */ static constexpr const char *kInstantdb = "instantdb"; /** InterBase. */ static constexpr const char *kInterbase = "interbase"; /** MariaDB. */ static constexpr const char *kMariadb = "mariadb"; +/** SAP MaxDB. */ +static constexpr const char *kMaxdb = "maxdb"; +/** Memcached. */ +static constexpr const char *kMemcached = "memcached"; +/** MongoDB. */ +static constexpr const char *kMongodb = "mongodb"; +/** Microsoft SQL Server. */ +static constexpr const char *kMssql = "mssql"; +/** Deprecated, Microsoft SQL Server Compact is discontinued. */ +static constexpr const char *kMssqlcompact = "mssqlcompact"; +/** MySQL. */ +static constexpr const char *kMysql = "mysql"; +/** Neo4j. */ +static constexpr const char *kNeo4j = "neo4j"; /** Netezza. */ static constexpr const char *kNetezza = "netezza"; +/** OpenSearch. */ +static constexpr const char *kOpensearch = "opensearch"; +/** Oracle Database. */ +static constexpr const char *kOracle = "oracle"; /** Pervasive PSQL. */ static constexpr const char *kPervasive = "pervasive"; /** PointBase. */ static constexpr const char *kPointbase = "pointbase"; +/** PostgreSQL. */ +static constexpr const char *kPostgresql = "postgresql"; +/** Progress Database. */ +static constexpr const char *kProgress = "progress"; +/** Redis. */ +static constexpr const char *kRedis = "redis"; +/** Amazon Redshift. */ +static constexpr const char *kRedshift = "redshift"; +/** Cloud Spanner. */ +static constexpr const char *kSpanner = "spanner"; /** SQLite. */ static constexpr const char *kSqlite = "sqlite"; /** Sybase. */ static constexpr const char *kSybase = "sybase"; /** Teradata. */ static constexpr const char *kTeradata = "teradata"; -/** Vertica. */ -static constexpr const char *kVertica = "vertica"; -/** H2. */ -static constexpr const char *kH2 = "h2"; -/** ColdFusion IMQ. */ -static constexpr const char *kColdfusion = "coldfusion"; -/** Apache Cassandra. */ -static constexpr const char *kCassandra = "cassandra"; -/** Apache HBase. */ -static constexpr const char *kHbase = "hbase"; -/** MongoDB. */ -static constexpr const char *kMongodb = "mongodb"; -/** Redis. */ -static constexpr const char *kRedis = "redis"; -/** Couchbase. */ -static constexpr const char *kCouchbase = "couchbase"; -/** CouchDB. */ -static constexpr const char *kCouchdb = "couchdb"; -/** Microsoft Azure Cosmos DB. */ -static constexpr const char *kCosmosdb = "cosmosdb"; -/** Amazon DynamoDB. */ -static constexpr const char *kDynamodb = "dynamodb"; -/** Neo4j. */ -static constexpr const char *kNeo4j = "neo4j"; -/** Apache Geode. */ -static constexpr const char *kGeode = "geode"; -/** Elasticsearch. */ -static constexpr const char *kElasticsearch = "elasticsearch"; -/** Memcached. */ -static constexpr const char *kMemcached = "memcached"; -/** CockroachDB. */ -static constexpr const char *kCockroachdb = "cockroachdb"; -/** OpenSearch. */ -static constexpr const char *kOpensearch = "opensearch"; -/** ClickHouse. */ -static constexpr const char *kClickhouse = "clickhouse"; -/** Cloud Spanner. */ -static constexpr const char *kSpanner = "spanner"; /** Trino. */ static constexpr const char *kTrino = "trino"; +/** Vertica. */ +static constexpr const char *kVertica = "vertica"; } // namespace DbSystemValues namespace DbCassandraConsistencyLevelValues @@ -3813,6 +4267,14 @@ static constexpr const char *kQueryPlan = "QueryPlan"; static constexpr const char *kExecuteJavascript = "ExecuteJavaScript"; } // namespace DbCosmosdbOperationTypeValues +namespace DeploymentStatusValues +{ +/** failed. */ +static constexpr const char *kFailed = "failed"; +/** succeeded. */ +static constexpr const char *kSucceeded = "succeeded"; +} // namespace DeploymentStatusValues + namespace AndroidStateValues { /** Any time before Activity.onResume() or, if the app has no Activity, Context.startService() has @@ -3826,6 +4288,26 @@ static constexpr const char *kBackground = "background"; static constexpr const char *kForeground = "foreground"; } // namespace AndroidStateValues +namespace ContainerCpuStateValues +{ +/** When tasks of the cgroup are in user mode (Linux). When all container processes are in user mode + * (Windows). */ +static constexpr const char *kUser = "user"; +/** When CPU is used by the system (host OS). */ +static constexpr const char *kSystem = "system"; +/** When tasks of the cgroup are in kernel mode (Linux). When all container processes are in kernel + * mode (Windows). */ +static constexpr const char *kKernel = "kernel"; +} // namespace ContainerCpuStateValues + +namespace DbClientConnectionsStateValues +{ +/** idle. */ +static constexpr const char *kIdle = "idle"; +/** used. */ +static constexpr const char *kUsed = "used"; +} // namespace DbClientConnectionsStateValues + namespace StateValues { /** idle. */ @@ -3890,6 +4372,16 @@ static constexpr const char *kInproc = "inproc"; static constexpr const char *kOther = "other"; } // namespace NetTransportValues +namespace ProcessCpuStateValues +{ +/** system. */ +static constexpr const char *kSystem = "system"; +/** user. */ +static constexpr const char *kUser = "user"; +/** wait. */ +static constexpr const char *kWait = "wait"; +} // namespace ProcessCpuStateValues + namespace MessageTypeValues { /** sent. */ @@ -3898,6 +4390,24 @@ static constexpr const char *kSent = "SENT"; static constexpr const char *kReceived = "RECEIVED"; } // namespace MessageTypeValues +namespace SystemCpuStateValues +{ +/** user. */ +static constexpr const char *kUser = "user"; +/** system. */ +static constexpr const char *kSystem = "system"; +/** nice. */ +static constexpr const char *kNice = "nice"; +/** idle. */ +static constexpr const char *kIdle = "idle"; +/** iowait. */ +static constexpr const char *kIowait = "iowait"; +/** interrupt. */ +static constexpr const char *kInterrupt = "interrupt"; +/** steal. */ +static constexpr const char *kSteal = "steal"; +} // namespace SystemCpuStateValues + namespace SystemProcessesStatusValues { /** running. */ @@ -3962,12 +4472,46 @@ static constexpr const char *kTimer = "timer"; static constexpr const char *kOther = "other"; } // namespace FaasTriggerValues +namespace GenAiOperationNameValues +{ +/** Chat completion operation such as [OpenAI Chat + * API](https://platform.openai.com/docs/api-reference/chat). */ +static constexpr const char *kChat = "chat"; +/** Text completions operation such as [OpenAI Completions API + * (Legacy)](https://platform.openai.com/docs/api-reference/completions). */ +static constexpr const char *kTextCompletion = "text_completion"; +} // namespace GenAiOperationNameValues + namespace GenAiSystemValues { /** OpenAI. */ static constexpr const char *kOpenai = "openai"; +/** Vertex AI. */ +static constexpr const char *kVertexAi = "vertex_ai"; +/** Anthropic. */ +static constexpr const char *kAnthropic = "anthropic"; +/** Cohere. */ +static constexpr const char *kCohere = "cohere"; } // namespace GenAiSystemValues +namespace GenAiTokenTypeValues +{ +/** Input tokens (prompt, input, etc.). */ +static constexpr const char *kInput = "input"; +/** Output tokens (completion, response, etc.). */ +static constexpr const char *kCompletion = "output"; +} // namespace GenAiTokenTypeValues + +namespace GoMemoryTypeValues +{ +/** Memory allocated from the heap that is reserved for stack space, whether or not it is currently + * in-use. */ +static constexpr const char *kStack = "stack"; +/** Memory used by the Go runtime, excluding other categories of memory usage described in this + * enumeration. */ +static constexpr const char *kOther = "other"; +} // namespace GoMemoryTypeValues + namespace GraphqlOperationTypeValues { /** GraphQL query. */ @@ -4056,6 +4600,14 @@ static constexpr const char *kTimedWaiting = "timed_waiting"; static constexpr const char *kTerminated = "terminated"; } // namespace JvmThreadStateValues +namespace LinuxMemorySlabStateValues +{ +/** reclaimable. */ +static constexpr const char *kReclaimable = "reclaimable"; +/** unreclaimable. */ +static constexpr const char *kUnreclaimable = "unreclaimable"; +} // namespace LinuxMemorySlabStateValues + namespace LogIostreamValues { /** Logs from stdout stream. */ @@ -4076,10 +4628,12 @@ static constexpr const char *kCreate = "create"; /** One or more messages are requested by a consumer. This operation refers to pull-based scenarios, * where consumers explicitly call methods of messaging SDKs to receive messages. */ static constexpr const char *kReceive = "receive"; -/** One or more messages are delivered to or processed by a consumer. */ -static constexpr const char *kDeliver = "process"; +/** One or more messages are processed by a consumer. */ +static constexpr const char *kProcess = "process"; /** One or more messages are settled. */ static constexpr const char *kSettle = "settle"; +/** Deprecated. Use `process` instead. */ +static constexpr const char *kDeliver = "deliver"; } // namespace MessagingOperationTypeValues namespace MessagingSystemValues @@ -4104,6 +4658,8 @@ static constexpr const char *kKafka = "kafka"; static constexpr const char *kRabbitmq = "rabbitmq"; /** Apache RocketMQ. */ static constexpr const char *kRocketmq = "rocketmq"; +/** Apache Pulsar. */ +static constexpr const char *kPulsar = "pulsar"; } // namespace MessagingSystemValues namespace MessagingRocketmqConsumptionModelValues @@ -4216,6 +4772,8 @@ static constexpr const char *kUdp = "udp"; static constexpr const char *kPipe = "pipe"; /** Unix domain socket. */ static constexpr const char *kUnix = "unix"; +/** QUIC. */ +static constexpr const char *kQuic = "quic"; } // namespace NetworkTransportValues namespace NetworkTypeValues @@ -4285,16 +4843,6 @@ static constexpr const char *kMajor = "major"; static constexpr const char *kMinor = "minor"; } // namespace ProcessPagingFaultTypeValues -namespace ProcessCpuStateValues -{ -/** system. */ -static constexpr const char *kSystem = "system"; -/** user. */ -static constexpr const char *kUser = "user"; -/** wait. */ -static constexpr const char *kWait = "wait"; -} // namespace ProcessCpuStateValues - namespace RpcConnectRpcErrorCodeValues { /** cancelled. */ @@ -4411,24 +4959,6 @@ static constexpr const char *kLongPolling = "long_polling"; static constexpr const char *kWebSockets = "web_sockets"; } // namespace SignalrTransportValues -namespace SystemCpuStateValues -{ -/** user. */ -static constexpr const char *kUser = "user"; -/** system. */ -static constexpr const char *kSystem = "system"; -/** nice. */ -static constexpr const char *kNice = "nice"; -/** idle. */ -static constexpr const char *kIdle = "idle"; -/** iowait. */ -static constexpr const char *kIowait = "iowait"; -/** interrupt. */ -static constexpr const char *kInterrupt = "interrupt"; -/** steal. */ -static constexpr const char *kSteal = "steal"; -} // namespace SystemCpuStateValues - namespace SystemMemoryStateValues { /** used. */ @@ -4561,6 +5091,30 @@ static constexpr const char *kSwift = "swift"; static constexpr const char *kWebjs = "webjs"; } // namespace TelemetrySdkLanguageValues +namespace TestCaseResultStatusValues +{ +/** pass. */ +static constexpr const char *kPass = "pass"; +/** fail. */ +static constexpr const char *kFail = "fail"; +} // namespace TestCaseResultStatusValues + +namespace TestSuiteRunStatusValues +{ +/** success. */ +static constexpr const char *kSuccess = "success"; +/** failure. */ +static constexpr const char *kFailure = "failure"; +/** skipped. */ +static constexpr const char *kSkipped = "skipped"; +/** aborted. */ +static constexpr const char *kAborted = "aborted"; +/** timed_out. */ +static constexpr const char *kTimedOut = "timed_out"; +/** in_progress. */ +static constexpr const char *kInProgress = "in_progress"; +} // namespace TestSuiteRunStatusValues + namespace TlsProtocolNameValues { /** ssl. */ @@ -4569,6 +5123,40 @@ static constexpr const char *kSsl = "ssl"; static constexpr const char *kTls = "tls"; } // namespace TlsProtocolNameValues +namespace V8jsGcTypeValues +{ +/** Major (Mark Sweep Compact). */ +static constexpr const char *kMajor = "major"; +/** Minor (Scavenge). */ +static constexpr const char *kMinor = "minor"; +/** Incremental (Incremental Marking). */ +static constexpr const char *kIncremental = "incremental"; +/** Weak Callbacks (Process Weak Callbacks). */ +static constexpr const char *kWeakcb = "weakcb"; +} // namespace V8jsGcTypeValues + +namespace V8jsHeapSpaceNameValues +{ +/** New memory space. */ +static constexpr const char *kNewSpace = "new_space"; +/** Old memory space. */ +static constexpr const char *kOldSpace = "old_space"; +/** Code memory space. */ +static constexpr const char *kCodeSpace = "code_space"; +/** Map memory space. */ +static constexpr const char *kMapSpace = "map_space"; +/** Large object memory space. */ +static constexpr const char *kLargeObjectSpace = "large_object_space"; +} // namespace V8jsHeapSpaceNameValues + +namespace VcsRepositoryRefTypeValues +{ +/** [branch](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch). */ +static constexpr const char *kBranch = "branch"; +/** [tag](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag). */ +static constexpr const char *kTag = "tag"; +} // namespace VcsRepositoryRefTypeValues + } // namespace SemanticConventions } // namespace resource } // namespace sdk From 1203bcf2647cfb8d10a217a0a04d43c6295bd12a Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 14 Aug 2024 10:47:59 -0700 Subject: [PATCH 38/71] [SDK] Support empty histogram buckets (#3027) * support empty buckets * Update histogram_test.cc * Update histogram_test.cc * test for negative values * fix count --- .../aggregation/histogram_aggregation.cc | 4 +- sdk/test/metrics/histogram_test.cc | 120 ++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index da725cf09c..d6b4c90a0b 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -28,7 +28,7 @@ namespace metrics LongHistogramAggregation::LongHistogramAggregation(const AggregationConfig *aggregation_config) { auto ac = static_cast(aggregation_config); - if (ac && ac->boundaries_.size()) + if (ac) { point_data_.boundaries_ = ac->boundaries_; } @@ -109,7 +109,7 @@ PointType LongHistogramAggregation::ToPoint() const noexcept DoubleHistogramAggregation::DoubleHistogramAggregation(const AggregationConfig *aggregation_config) { auto ac = static_cast(aggregation_config); - if (ac && ac->boundaries_.size()) + if (ac) { point_data_.boundaries_ = ac->boundaries_; } diff --git a/sdk/test/metrics/histogram_test.cc b/sdk/test/metrics/histogram_test.cc index 4daceb685b..57f7790ba1 100644 --- a/sdk/test/metrics/histogram_test.cc +++ b/sdk/test/metrics/histogram_test.cc @@ -134,6 +134,66 @@ TEST(Histogram, DoubleCustomBuckets) ASSERT_EQ(std::vector({10, 20, 30, 40}), actual.boundaries_); ASSERT_EQ(std::vector({2, 2, 2, 2, 2}), actual.counts_); } + +TEST(Histogram, DoubleEmptyBuckets) +{ + MeterProvider mp; + auto m = mp.GetMeter("meter1", "version1", "schema1"); + std::string instrument_unit = "ms"; + std::string instrument_name = "historgram1"; + std::string instrument_desc = "histogram metrics"; + + std::unique_ptr exporter(new MockMetricExporter()); + std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; + mp.AddMetricReader(reader); + + std::shared_ptr config(new HistogramAggregationConfig()); + config->boundaries_ = {}; + std::unique_ptr view{ + new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)}; + std::unique_ptr instrument_selector{ + new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)}; + std::unique_ptr meter_selector{new MeterSelector("meter1", "version1", "schema1")}; + mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); + + auto h = m->CreateDoubleHistogram(instrument_name, instrument_desc, instrument_unit); + + h->Record(-5, {}); + h->Record(10, {}); + h->Record(15, {}); + h->Record(20, {}); + h->Record(25, {}); + h->Record(30, {}); + h->Record(35, {}); + h->Record(40, {}); + h->Record(45, {}); + h->Record(50, {}); + + std::vector actuals; + reader->Collect([&](ResourceMetrics &rm) { + for (const ScopeMetrics &smd : rm.scope_metric_data_) + { + for (const MetricData &md : smd.metric_data_) + { + for (const PointDataAttributes &dp : md.point_data_attr_) + { + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + } + } + } + return true; + }); + + ASSERT_EQ(1, actuals.size()); + + const auto &actual = actuals.at(0); + ASSERT_EQ(270.0, opentelemetry::nostd::get(actual.sum_)); + ASSERT_EQ(9, actual.count_); + ASSERT_EQ(10.0, opentelemetry::nostd::get(actual.min_)); + ASSERT_EQ(50.0, opentelemetry::nostd::get(actual.max_)); + ASSERT_EQ(std::vector({}), actual.boundaries_); + ASSERT_EQ(std::vector({9}), actual.counts_); +} #endif TEST(Histogram, UInt64) @@ -249,4 +309,64 @@ TEST(Histogram, UInt64CustomBuckets) ASSERT_EQ(std::vector({10, 20, 30, 40}), actual.boundaries_); ASSERT_EQ(std::vector({2, 2, 2, 2, 2}), actual.counts_); } + +TEST(Histogram, UInt64EmptyBuckets) +{ + MeterProvider mp; + auto m = mp.GetMeter("meter1", "version1", "schema1"); + std::string instrument_name = "historgram1"; + std::string instrument_desc = "histogram metrics"; + std::string instrument_unit = "ms"; + + std::unique_ptr exporter(new MockMetricExporter()); + std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; + mp.AddMetricReader(reader); + + std::shared_ptr config(new HistogramAggregationConfig()); + config->boundaries_ = {}; + std::unique_ptr view{ + new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)}; + std::unique_ptr instrument_selector{ + new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)}; + std::unique_ptr meter_selector{new MeterSelector("meter1", "version1", "schema1")}; + mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); + + auto h = m->CreateUInt64Histogram(instrument_name, instrument_desc, instrument_unit); + + h->Record(5, {}); + h->Record(10, {}); + h->Record(15, {}); + h->Record(20, {}); + h->Record(25, {}); + h->Record(30, {}); + h->Record(35, {}); + h->Record(40, {}); + h->Record(45, {}); + h->Record(50, {}); + + std::vector actuals; + reader->Collect([&](ResourceMetrics &rm) { + for (const ScopeMetrics &smd : rm.scope_metric_data_) + { + for (const MetricData &md : smd.metric_data_) + { + for (const PointDataAttributes &dp : md.point_data_attr_) + { + actuals.push_back(opentelemetry::nostd::get(dp.point_data)); + } + } + } + return true; + }); + + ASSERT_EQ(1, actuals.size()); + + const auto &actual = actuals.at(0); + ASSERT_EQ(275, opentelemetry::nostd::get(actual.sum_)); + ASSERT_EQ(10, actual.count_); + ASSERT_EQ(5, opentelemetry::nostd::get(actual.min_)); + ASSERT_EQ(50, opentelemetry::nostd::get(actual.max_)); + ASSERT_EQ(std::vector({}), actual.boundaries_); + ASSERT_EQ(std::vector({10}), actual.counts_); +} #endif From b8909692c64dfbbeae6d10ce8f887a6250ac04a4 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 16 Aug 2024 21:30:29 +0800 Subject: [PATCH 39/71] [TEST] Fix sync problems in OTLP File exporter tests. (#3031) --- .../otlp/test/otlp_file_exporter_test.cc | 24 ++++++++++++++----- .../otlp_file_log_record_exporter_test.cc | 6 ++++- .../test/otlp_file_metric_exporter_test.cc | 18 +++++++++++--- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/exporters/otlp/test/otlp_file_exporter_test.cc b/exporters/otlp/test/otlp_file_exporter_test.cc index 16a1306f88..81e1baab44 100644 --- a/exporters/otlp/test/otlp_file_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_exporter_test.cc @@ -25,6 +25,7 @@ #include "nlohmann/json.hpp" #include +#include #include using namespace testing; @@ -112,13 +113,24 @@ class OtlpFileExporterTestPeer : public ::testing::Test provider->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); + if (!check_json.is_discarded()) + { + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + } + else + { + FAIL() << "Failed to parse json:" << check_json_text; + } } } }; diff --git a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc index 9f04bcece4..5bc1e4a473 100644 --- a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc @@ -122,8 +122,12 @@ class OtlpFileLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_logs = *check_json["resourceLogs"].begin(); auto scope_logs = *resource_logs["scopeLogs"].begin(); auto scope = scope_logs["scope"]; diff --git a/exporters/otlp/test/otlp_file_metric_exporter_test.cc b/exporters/otlp/test/otlp_file_metric_exporter_test.cc index f08c8854ba..50f60e15b7 100644 --- a/exporters/otlp/test/otlp_file_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_metric_exporter_test.cc @@ -106,8 +106,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); @@ -167,8 +171,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); @@ -233,8 +241,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test exporter->ForceFlush(); + output.flush(); + output.sync(); + auto check_json_text = output.str(); + if (!check_json_text.empty()) { - auto check_json = nlohmann::json::parse(output.str(), nullptr, false); + auto check_json = nlohmann::json::parse(check_json_text, nullptr, false); auto resource_metrics = *check_json["resourceMetrics"].begin(); auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); From 242d52ac67a8c20484cddabd2b3feeebeb4399b0 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Thu, 22 Aug 2024 06:36:53 +0800 Subject: [PATCH 40/71] [SDK] PeriodicExportingMetricReader: future is never set, blocks until timeout (#3030) --- .../periodic_exporting_metric_reader.cc | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 7ca2747337..1ebfc2a1b6 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -106,19 +106,22 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce() std::promise sender; auto receiver = sender.get_future(); - task_thread.reset(new std::thread([this, &cancel_export_for_timeout] { - this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { - if (cancel_export_for_timeout.load(std::memory_order_acquire)) - { - OTEL_INTERNAL_LOG_ERROR( - "[Periodic Exporting Metric Reader] Collect took longer configured time: " - << this->export_timeout_millis_.count() << " ms, and timed out"); - return false; - } - this->exporter_->Export(metric_data); - return true; - }); - })); + task_thread.reset( + new std::thread([this, &cancel_export_for_timeout, sender = std::move(sender)] { + this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { + if (cancel_export_for_timeout.load(std::memory_order_acquire)) + { + OTEL_INTERNAL_LOG_ERROR( + "[Periodic Exporting Metric Reader] Collect took longer configured time: " + << this->export_timeout_millis_.count() << " ms, and timed out"); + return false; + } + this->exporter_->Export(metric_data); + return true; + }); + + const_cast &>(sender).set_value(); + })); std::future_status status; do From a71642fe678f90ba6d379d699e533ce441394bdf Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Sun, 25 Aug 2024 23:28:32 +0530 Subject: [PATCH 41/71] [Code Health] Clang Tidy cleanup, Part 2 (#3038) --- .clang-tidy | 3 ++ .github/workflows/clang-tidy.yaml | 2 +- .../propagation/baggage_propagator_test.cc | 4 +-- .../propagation/composite_propagator_test.cc | 6 ++-- api/test/logs/logger_benchmark.cc | 8 ++--- api/test/nostd/shared_ptr_test.cc | 2 +- .../trace/propagation/b3_propagation_test.cc | 4 +-- .../propagation/http_text_format_test.cc | 4 +-- .../propagation/jaeger_propagation_test.cc | 4 +-- examples/http/server.cc | 4 +-- exporters/otlp/src/otlp_file_client.cc | 6 ++-- .../src/otlp_file_metric_exporter_options.cc | 3 +- .../src/otlp_grpc_metric_exporter_options.cc | 3 +- exporters/otlp/src/otlp_http_client.cc | 2 +- .../otlp/src/otlp_http_exporter_options.cc | 29 ++++++++--------- .../otlp_http_log_record_exporter_options.cc | 29 ++++++++--------- .../src/otlp_http_metric_exporter_options.cc | 31 ++++++++++--------- .../otlp/src/otlp_populate_attribute_utils.cc | 15 ++++++--- exporters/prometheus/src/exporter_utils.cc | 10 +++--- exporters/prometheus/test/collector_test.cc | 4 +-- exporters/zipkin/src/zipkin_exporter.cc | 6 ++-- ext/src/http/client/curl/http_client_curl.cc | 7 ++--- ext/test/http/curl_http_test.cc | 13 ++++---- ext/test/w3c_tracecontext_test/main.cc | 4 +-- .../sdk/common/circular_buffer.h | 1 - sdk/src/common/base64.cc | 7 +---- sdk/src/logs/logger_provider.cc | 4 +-- .../aggregation/lastvalue_aggregation.cc | 22 ++++++------- .../metrics/aggregation/sum_aggregation.cc | 4 +-- sdk/src/metrics/state/sync_metric_storage.cc | 2 +- sdk/src/trace/batch_span_processor.cc | 2 +- sdk/src/trace/samplers/parent_factory.cc | 2 +- sdk/test/common/random_test.cc | 1 + .../periodic_exporting_metric_reader_test.cc | 4 +-- 34 files changed, 127 insertions(+), 125 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9a30fbef54..db61b810c9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -31,9 +31,12 @@ Checks: > -misc-unused-alias-decls, -misc-use-anonymous-namespace, cppcoreguidelines-*, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-init-variables, -cppcoreguidelines-macro-usage, -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-pro-* \ No newline at end of file diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 9e5f6c26db..612ff05270 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -68,7 +68,7 @@ jobs: - name: Run clang-tidy run: | cd build - make -j$(nproc) 2>&1 | tee -a clang-tidy.log || exit 1 + make 2>&1 | tee -a clang-tidy.log || exit 1 - uses: actions/upload-artifact@v4 with: diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index 83de75757b..c966fe7603 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -15,7 +15,7 @@ class BaggageCarrierTest : public context::propagation::TextMapCarrier { public: BaggageCarrierTest() = default; - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -24,7 +24,7 @@ class BaggageCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } diff --git a/api/test/context/propagation/composite_propagator_test.cc b/api/test/context/propagation/composite_propagator_test.cc index 5bf18710ed..075841080f 100644 --- a/api/test/context/propagation/composite_propagator_test.cc +++ b/api/test/context/propagation/composite_propagator_test.cc @@ -31,7 +31,7 @@ static std::string Hex(const T &id_item) class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -40,7 +40,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } @@ -66,7 +66,7 @@ class CompositePropagatorTest : public ::testing::Test new context::propagation::CompositePropagator(std::move(propogator_list)); } - ~CompositePropagatorTest() { delete composite_propagator_; } + ~CompositePropagatorTest() override { delete composite_propagator_; } protected: context::propagation::CompositePropagator *composite_propagator_; diff --git a/api/test/logs/logger_benchmark.cc b/api/test/logs/logger_benchmark.cc index db225d496a..7e8913a3f7 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -32,7 +32,7 @@ constexpr int64_t kMaxIterations = 1000000000; class Barrier { public: - explicit Barrier(std::size_t iCount) : mThreshold(iCount), mCount(iCount), mGeneration(0) {} + explicit Barrier(std::size_t iCount) : mThreshold(iCount), mCount(iCount) {} void Wait() { @@ -55,7 +55,7 @@ class Barrier std::condition_variable mCond; std::size_t mThreshold; std::size_t mCount; - std::size_t mGeneration; + std::size_t mGeneration{0}; }; static void ThreadRoutine(Barrier &barrier, @@ -84,14 +84,14 @@ static void ThreadRoutine(Barrier &barrier, void MultiThreadRunner(benchmark::State &state, const std::function &func) { - int num_threads = std::thread::hardware_concurrency(); + uint32_t num_threads = std::thread::hardware_concurrency(); Barrier barrier(num_threads); std::vector threads; threads.reserve(num_threads); - for (int i = 0; i < num_threads; i++) + for (uint32_t i = 0; i < num_threads; i++) { threads.emplace_back(ThreadRoutine, std::ref(barrier), std::ref(state), i, func); } diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 5c290c6284..2ebba82628 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -35,7 +35,7 @@ class C class D : public C { public: - virtual ~D() {} + ~D() override {} }; TEST(SharedPtrTest, DefaultConstruction) diff --git a/api/test/trace/propagation/b3_propagation_test.cc b/api/test/trace/propagation/b3_propagation_test.cc index 5546916abc..732db1bd34 100644 --- a/api/test/trace/propagation/b3_propagation_test.cc +++ b/api/test/trace/propagation/b3_propagation_test.cc @@ -15,7 +15,7 @@ using namespace opentelemetry; class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -24,7 +24,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } diff --git a/api/test/trace/propagation/http_text_format_test.cc b/api/test/trace/propagation/http_text_format_test.cc index e41e0fe65c..99f7117928 100644 --- a/api/test/trace/propagation/http_text_format_test.cc +++ b/api/test/trace/propagation/http_text_format_test.cc @@ -18,7 +18,7 @@ using namespace opentelemetry; class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -27,7 +27,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } diff --git a/api/test/trace/propagation/jaeger_propagation_test.cc b/api/test/trace/propagation/jaeger_propagation_test.cc index add38eac6c..f0fdaf734d 100644 --- a/api/test/trace/propagation/jaeger_propagation_test.cc +++ b/api/test/trace/propagation/jaeger_propagation_test.cc @@ -14,7 +14,7 @@ using namespace opentelemetry; class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -23,7 +23,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } diff --git a/examples/http/server.cc b/examples/http/server.cc index 3dbdae8512..85cccc234d 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -21,8 +21,8 @@ constexpr const char *server_name = "localhost"; class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback { public: - virtual int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request, - HTTP_SERVER_NS::HttpResponse &response) override + int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request, + HTTP_SERVER_NS::HttpResponse &response) override { StartSpanOptions options; options.kind = SpanKind::kServer; // server diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index cc6e074bfd..bdd6eac27d 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -966,7 +966,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender { public: explicit OtlpFileSystemBackend(const OtlpFileClientFileSystemOptions &options) - : options_(options), is_initialized_{false}, check_file_path_interval_{0} + : options_(options), is_initialized_{false} { file_ = std::make_shared(); file_->is_shutdown.store(false); @@ -1539,7 +1539,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender std::shared_ptr file_; std::atomic is_initialized_; - std::time_t check_file_path_interval_; + std::time_t check_file_path_interval_{0}; }; class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppender @@ -1568,7 +1568,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppende }; OtlpFileClient::OtlpFileClient(OtlpFileClientOptions &&options) - : is_shutdown_(false), options_(options) + : is_shutdown_(false), options_(std::move(options)) { if (nostd::holds_alternative(options_.backend_options)) { diff --git a/exporters/otlp/src/otlp_file_metric_exporter_options.cc b/exporters/otlp/src/otlp_file_metric_exporter_options.cc index 3ad8eaa457..e1b1f5ca7a 100644 --- a/exporters/otlp/src/otlp_file_metric_exporter_options.cc +++ b/exporters/otlp/src/otlp_file_metric_exporter_options.cc @@ -13,6 +13,7 @@ namespace otlp { OtlpFileMetricExporterOptions::OtlpFileMetricExporterOptions() + : aggregation_temporality(PreferredAggregationTemporality::kCumulative) { console_debug = false; @@ -25,8 +26,6 @@ OtlpFileMetricExporterOptions::OtlpFileMetricExporterOptions() fs_options.rotate_size = 10; backend_options = fs_options; - - aggregation_temporality = PreferredAggregationTemporality::kCumulative; } OtlpFileMetricExporterOptions::~OtlpFileMetricExporterOptions() {} diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc index 983561424f..0d84ec276f 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc @@ -11,6 +11,7 @@ namespace otlp { OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions() + : aggregation_temporality(PreferredAggregationTemporality::kCumulative) { endpoint = GetOtlpDefaultGrpcMetricsEndpoint(); use_ssl_credentials = !GetOtlpDefaultGrpcMetricsIsInsecure(); /* negation intended. */ @@ -28,8 +29,6 @@ OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions() metadata = GetOtlpDefaultMetricsHeaders(); user_agent = GetOtlpDefaultUserAgent(); - aggregation_temporality = PreferredAggregationTemporality::kCumulative; - max_threads = 0; compression = GetOtlpDefaultMetricsCompression(); diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 07b9108a3a..876719fa1e 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -707,7 +707,7 @@ OtlpHttpClient::~OtlpHttpClient() OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, std::shared_ptr http_client) : is_shutdown_(false), - options_(options), + options_(std::move(options)), http_client_(std::move(http_client)), start_session_counter_(0), finished_session_counter_(0) diff --git a/exporters/otlp/src/otlp_http_exporter_options.cc b/exporters/otlp/src/otlp_http_exporter_options.cc index 753efcb481..0b00fc9708 100644 --- a/exporters/otlp/src/otlp_http_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -16,27 +16,28 @@ namespace otlp { OtlpHttpExporterOptions::OtlpHttpExporterOptions() + : json_bytes_mapping(JsonBytesMappingKind::kHexId), + use_json_name(false), + console_debug(false), + ssl_insecure_skip_verify(false) { - url = GetOtlpDefaultHttpTracesEndpoint(); - content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpTracesProtocol()); - json_bytes_mapping = JsonBytesMappingKind::kHexId; - use_json_name = false; - console_debug = false; - timeout = GetOtlpDefaultTracesTimeout(); - http_headers = GetOtlpDefaultTracesHeaders(); + url = GetOtlpDefaultHttpTracesEndpoint(); + content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpTracesProtocol()); + + timeout = GetOtlpDefaultTracesTimeout(); + http_headers = GetOtlpDefaultTracesHeaders(); #ifdef ENABLE_ASYNC_EXPORT max_concurrent_requests = 64; max_requests_per_connection = 8; #endif /* ENABLE_ASYNC_EXPORT */ - ssl_insecure_skip_verify = false; - ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath(); - ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString(); - ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); - ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); - ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); - ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); + ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion(); ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion(); diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc index 08a04cfa80..f193ea10df 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc @@ -16,27 +16,28 @@ namespace otlp { OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions() + : json_bytes_mapping(JsonBytesMappingKind::kHexId), + use_json_name(false), + console_debug(false), + ssl_insecure_skip_verify(false) { - url = GetOtlpDefaultHttpLogsEndpoint(); - content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpLogsProtocol()); - json_bytes_mapping = JsonBytesMappingKind::kHexId; - use_json_name = false; - console_debug = false; - timeout = GetOtlpDefaultLogsTimeout(); - http_headers = GetOtlpDefaultLogsHeaders(); + url = GetOtlpDefaultHttpLogsEndpoint(); + content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpLogsProtocol()); + + timeout = GetOtlpDefaultLogsTimeout(); + http_headers = GetOtlpDefaultLogsHeaders(); #ifdef ENABLE_ASYNC_EXPORT max_concurrent_requests = 64; max_requests_per_connection = 8; #endif - ssl_insecure_skip_verify = false; - ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); - ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString(); - ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); - ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); - ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); - ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); + ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion(); diff --git a/exporters/otlp/src/otlp_http_metric_exporter_options.cc b/exporters/otlp/src/otlp_http_metric_exporter_options.cc index 66d65fa54b..95a8dd885c 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_options.cc @@ -17,28 +17,29 @@ namespace otlp { OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions() + : json_bytes_mapping(JsonBytesMappingKind::kHexId), + use_json_name(false), + console_debug(false), + aggregation_temporality(PreferredAggregationTemporality::kCumulative), + ssl_insecure_skip_verify(false) { - url = GetOtlpDefaultMetricsEndpoint(); - content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpMetricsProtocol()); - json_bytes_mapping = JsonBytesMappingKind::kHexId; - use_json_name = false; - console_debug = false; - timeout = GetOtlpDefaultMetricsTimeout(); - http_headers = GetOtlpDefaultMetricsHeaders(); - aggregation_temporality = PreferredAggregationTemporality::kCumulative; + url = GetOtlpDefaultMetricsEndpoint(); + content_type = GetOtlpHttpProtocolFromString(GetOtlpDefaultHttpMetricsProtocol()); + + timeout = GetOtlpDefaultMetricsTimeout(); + http_headers = GetOtlpDefaultMetricsHeaders(); #ifdef ENABLE_ASYNC_EXPORT max_concurrent_requests = 64; max_requests_per_connection = 8; #endif - ssl_insecure_skip_verify = false; - ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath(); - ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString(); - ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); - ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); - ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); - ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); + ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion(); ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion(); diff --git a/exporters/otlp/src/otlp_populate_attribute_utils.cc b/exporters/otlp/src/otlp_populate_attribute_utils.cc index a2ef2edafa..490e4c771b 100644 --- a/exporters/otlp/src/otlp_populate_attribute_utils.cc +++ b/exporters/otlp/src/otlp_populate_attribute_utils.cc @@ -72,7 +72,8 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( } else if (nostd::holds_alternative(value)) { - proto_value->set_int_value(nostd::get(value)); + proto_value->set_int_value( + nostd::get(value)); // NOLINT(cppcoreguidelines-narrowing-conversions) } else if (nostd::holds_alternative(value)) { @@ -132,7 +133,8 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - array_value->add_values()->set_int_value(val); + array_value->add_values()->set_int_value( + val); // NOLINT(cppcoreguidelines-narrowing-conversions) } } else if (nostd::holds_alternative>(value)) @@ -186,7 +188,8 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( } else if (nostd::holds_alternative(value)) { - proto_value->set_int_value(nostd::get(value)); + proto_value->set_int_value( + nostd::get(value)); // NOLINT(cppcoreguidelines-narrowing-conversions) } else if (nostd::holds_alternative(value)) { @@ -217,7 +220,8 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - array_value->add_values()->set_int_value(val); + array_value->add_values()->set_int_value( + val); // NOLINT(cppcoreguidelines-narrowing-conversions) } } else if (nostd::holds_alternative>(value)) @@ -233,7 +237,8 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - array_value->add_values()->set_int_value(val); + array_value->add_values()->set_int_value( + val); // NOLINT(cppcoreguidelines-narrowing-conversions) } } else if (nostd::holds_alternative>(value)) diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 35ee748273..77fcd56ad2 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -284,11 +284,11 @@ std::string PrometheusExporterUtils::SanitizeNames(std::string name) } #if OPENTELEMETRY_HAVE_WORKING_REGEX -std::regex INVALID_CHARACTERS_PATTERN("[^a-zA-Z0-9]"); -std::regex CHARACTERS_BETWEEN_BRACES_PATTERN("\\{(.*?)\\}"); -std::regex SANITIZE_LEADING_UNDERSCORES("^_+"); -std::regex SANITIZE_TRAILING_UNDERSCORES("_+$"); -std::regex SANITIZE_CONSECUTIVE_UNDERSCORES("[_]{2,}"); +const std::regex INVALID_CHARACTERS_PATTERN("[^a-zA-Z0-9]"); +const std::regex CHARACTERS_BETWEEN_BRACES_PATTERN("\\{(.*?)\\}"); +const std::regex SANITIZE_LEADING_UNDERSCORES("^_+"); +const std::regex SANITIZE_TRAILING_UNDERSCORES("_+$"); +const std::regex SANITIZE_CONSECUTIVE_UNDERSCORES("[_]{2,}"); #endif std::string PrometheusExporterUtils::GetEquivalentPrometheusUnit( diff --git a/exporters/prometheus/test/collector_test.cc b/exporters/prometheus/test/collector_test.cc index 63f840bc9a..a70fd317b3 100644 --- a/exporters/prometheus/test/collector_test.cc +++ b/exporters/prometheus/test/collector_test.cc @@ -23,7 +23,7 @@ class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer public: MockMetricProducer(std::chrono::microseconds sleep_ms = std::chrono::microseconds::zero()) - : sleep_ms_{sleep_ms}, data_sent_size_(0) + : sleep_ms_{sleep_ms} {} bool Collect(nostd::function_ref callback) noexcept override @@ -39,7 +39,7 @@ class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer private: std::chrono::microseconds sleep_ms_; - size_t data_sent_size_; + size_t data_sent_size_{0}; }; class MockMetricReader : public opentelemetry::sdk::metrics::MetricReader diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index a554cbf4cc..4c5723c674 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -50,9 +50,11 @@ ZipkinExporter::ZipkinExporter() : options_(ZipkinExporterOptions()), url_parser ZipkinExporter::ZipkinExporter( std::shared_ptr http_client) - : options_(ZipkinExporterOptions()), url_parser_(options_.endpoint) + : options_(ZipkinExporterOptions()), + http_client_(std::move(http_client)), + url_parser_(options_.endpoint) { - http_client_ = http_client; + InitializeLocalEndpoint(); } diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 67b0b93a54..22f20fb0e0 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -185,13 +185,12 @@ void Session::FinishOperation() } HttpClient::HttpClient() - : next_session_id_{0}, + : multi_handle_(curl_multi_init()), + next_session_id_{0}, max_sessions_per_connection_{8}, scheduled_delay_milliseconds_{std::chrono::milliseconds(256)}, curl_global_initializer_(HttpCurlGlobalInitializer::GetInstance()) -{ - multi_handle_ = curl_multi_init(); -} +{} HttpClient::~HttpClient() { diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 0dc6e5d5e8..d5351d2314 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -26,12 +26,11 @@ namespace nostd = opentelemetry::nostd; class CustomEventHandler : public http_client::EventHandler { public: - virtual void OnResponse(http_client::Response & /* response */) noexcept override + void OnResponse(http_client::Response & /* response */) noexcept override { got_response_ = true; } - virtual void OnEvent(http_client::SessionState state, - nostd::string_view /* reason */) noexcept override + void OnEvent(http_client::SessionState state, nostd::string_view /* reason */) noexcept override { switch (state) { @@ -113,7 +112,7 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe public: BasicCurlHttpTests() : is_setup_(false), is_running_(false) {} - virtual void SetUp() override + void SetUp() override { if (is_setup_.exchange(true)) { @@ -132,7 +131,7 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe is_running_ = true; } - virtual void TearDown() override + void TearDown() override { if (!is_setup_.exchange(false)) return; @@ -140,8 +139,8 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe is_running_ = false; } - virtual int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request, - HTTP_SERVER_NS::HttpResponse &response) override + int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request, + HTTP_SERVER_NS::HttpResponse &response) override { int response_status = 404; if (request.uri == "/get/") diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index d9819cde0d..4e9fb36796 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -30,7 +30,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: TextMapCarrierTest(std::map &headers) : headers_(headers) {} - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + nostd::string_view Get(nostd::string_view key) const noexcept override { auto it = headers_.find(std::string(key)); if (it != headers_.end()) @@ -39,7 +39,7 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier } return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_[std::string(key)] = std::string(value); } diff --git a/sdk/include/opentelemetry/sdk/common/circular_buffer.h b/sdk/include/opentelemetry/sdk/common/circular_buffer.h index c2548012b1..6541612158 100644 --- a/sdk/include/opentelemetry/sdk/common/circular_buffer.h +++ b/sdk/include/opentelemetry/sdk/common/circular_buffer.h @@ -113,7 +113,6 @@ class CircularBuffer data_[head_index].Swap(ptr); } } - return true; } bool Add(std::unique_ptr &&ptr) noexcept diff --git a/sdk/src/common/base64.cc b/sdk/src/common/base64.cc index 3c572fe344..a78b88ad68 100644 --- a/sdk/src/common/base64.cc +++ b/sdk/src/common/base64.cc @@ -200,15 +200,10 @@ static int Base64UnescapeInternal(unsigned char *dst, ++line_len; if (src[i] == padding_char) { - if (++j > 2) + if (++j > 2 || (valid_slen & 3) == 1 || (valid_slen & 3) == 2) { return -2; } - else if ((valid_slen & 3) == 1 || (valid_slen & 3) == 2) - { - // First and second char of every group can not be padding char - return -2; - } } else { diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index fdea3eb51a..46bf1ade33 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -31,13 +31,13 @@ LoggerProvider::LoggerProvider(std::unique_ptr &&processor, { std::vector> processors; processors.emplace_back(std::move(processor)); - context_ = std::make_shared(std::move(processors), std::move(resource)); + context_ = std::make_shared(std::move(processors), resource); OTEL_INTERNAL_LOG_DEBUG("[LoggerProvider] LoggerProvider created."); } LoggerProvider::LoggerProvider(std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource) noexcept - : context_{std::make_shared(std::move(processors), std::move(resource))} + : context_{std::make_shared(std::move(processors), resource)} {} LoggerProvider::LoggerProvider() noexcept diff --git a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc index 0380015234..2bc0eddb0e 100644 --- a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc +++ b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc @@ -28,9 +28,7 @@ LongLastValueAggregation::LongLastValueAggregation() point_data_.value_ = static_cast(0); } -LongLastValueAggregation::LongLastValueAggregation(LastValuePointData &&data) - : point_data_{std::move(data)} -{} +LongLastValueAggregation::LongLastValueAggregation(LastValuePointData &&data) : point_data_{data} {} LongLastValueAggregation::LongLastValueAggregation(const LastValuePointData &data) : point_data_{data} @@ -51,12 +49,12 @@ std::unique_ptr LongLastValueAggregation::Merge( if (nostd::get(ToPoint()).sample_ts_.time_since_epoch() > nostd::get(delta.ToPoint()).sample_ts_.time_since_epoch()) { - LastValuePointData merge_data = std::move(nostd::get(ToPoint())); + LastValuePointData merge_data = nostd::get(ToPoint()); return std::unique_ptr(new LongLastValueAggregation(std::move(merge_data))); } else { - LastValuePointData merge_data = std::move(nostd::get(delta.ToPoint())); + LastValuePointData merge_data = nostd::get(delta.ToPoint()); return std::unique_ptr(new LongLastValueAggregation(std::move(merge_data))); } } @@ -66,12 +64,12 @@ std::unique_ptr LongLastValueAggregation::Diff(const Aggregation &n if (nostd::get(ToPoint()).sample_ts_.time_since_epoch() > nostd::get(next.ToPoint()).sample_ts_.time_since_epoch()) { - LastValuePointData diff_data = std::move(nostd::get(ToPoint())); + LastValuePointData diff_data = nostd::get(ToPoint()); return std::unique_ptr(new LongLastValueAggregation(std::move(diff_data))); } else { - LastValuePointData diff_data = std::move(nostd::get(next.ToPoint())); + LastValuePointData diff_data = nostd::get(next.ToPoint()); return std::unique_ptr(new LongLastValueAggregation(std::move(diff_data))); } } @@ -89,7 +87,7 @@ DoubleLastValueAggregation::DoubleLastValueAggregation() } DoubleLastValueAggregation::DoubleLastValueAggregation(LastValuePointData &&data) - : point_data_{std::move(data)} + : point_data_{data} {} DoubleLastValueAggregation::DoubleLastValueAggregation(const LastValuePointData &data) @@ -111,12 +109,12 @@ std::unique_ptr DoubleLastValueAggregation::Merge( if (nostd::get(ToPoint()).sample_ts_.time_since_epoch() > nostd::get(delta.ToPoint()).sample_ts_.time_since_epoch()) { - LastValuePointData merge_data = std::move(nostd::get(ToPoint())); + LastValuePointData merge_data = nostd::get(ToPoint()); return std::unique_ptr(new DoubleLastValueAggregation(std::move(merge_data))); } else { - LastValuePointData merge_data = std::move(nostd::get(delta.ToPoint())); + LastValuePointData merge_data = nostd::get(delta.ToPoint()); return std::unique_ptr(new DoubleLastValueAggregation(std::move(merge_data))); } } @@ -127,12 +125,12 @@ std::unique_ptr DoubleLastValueAggregation::Diff( if (nostd::get(ToPoint()).sample_ts_.time_since_epoch() > nostd::get(next.ToPoint()).sample_ts_.time_since_epoch()) { - LastValuePointData diff_data = std::move(nostd::get(ToPoint())); + LastValuePointData diff_data = nostd::get(ToPoint()); return std::unique_ptr(new DoubleLastValueAggregation(std::move(diff_data))); } else { - LastValuePointData diff_data = std::move(nostd::get(next.ToPoint())); + LastValuePointData diff_data = nostd::get(next.ToPoint()); return std::unique_ptr(new DoubleLastValueAggregation(std::move(diff_data))); } } diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index 1e0442e92c..ce0d4c5de5 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -27,7 +27,7 @@ LongSumAggregation::LongSumAggregation(bool is_monotonic) point_data_.is_monotonic_ = is_monotonic; } -LongSumAggregation::LongSumAggregation(SumPointData &&data) : point_data_{std::move(data)} {} +LongSumAggregation::LongSumAggregation(SumPointData &&data) : point_data_{data} {} LongSumAggregation::LongSumAggregation(const SumPointData &data) : point_data_{data} {} @@ -81,7 +81,7 @@ DoubleSumAggregation::DoubleSumAggregation(bool is_monotonic) point_data_.is_monotonic_ = is_monotonic; } -DoubleSumAggregation::DoubleSumAggregation(SumPointData &&data) : point_data_(std::move(data)) {} +DoubleSumAggregation::DoubleSumAggregation(SumPointData &&data) : point_data_(data) {} DoubleSumAggregation::DoubleSumAggregation(const SumPointData &data) : point_data_(data) {} diff --git a/sdk/src/metrics/state/sync_metric_storage.cc b/sdk/src/metrics/state/sync_metric_storage.cc index fe736e64f3..ad6ea27821 100644 --- a/sdk/src/metrics/state/sync_metric_storage.cc +++ b/sdk/src/metrics/state/sync_metric_storage.cc @@ -39,7 +39,7 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector, } return temporal_metric_storage_.buildMetrics(collector, collectors, sdk_start_ts, collection_ts, - std::move(delta_metrics), callback); + delta_metrics, callback); } } // namespace metrics diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 6aa6a49949..f0f55d20e8 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -66,7 +66,7 @@ void BatchSpanProcessor::OnEnd(std::unique_ptr &&span) noexcept return; } - if (buffer_.Add(span) == false) + if (buffer_.Add(std::move(span)) == false) { OTEL_INTERNAL_LOG_WARN("BatchSpanProcessor queue is full - dropping span."); return; diff --git a/sdk/src/trace/samplers/parent_factory.cc b/sdk/src/trace/samplers/parent_factory.cc index 7f1bc088d6..63a7eff1c4 100644 --- a/sdk/src/trace/samplers/parent_factory.cc +++ b/sdk/src/trace/samplers/parent_factory.cc @@ -16,7 +16,7 @@ namespace trace std::unique_ptr ParentBasedSamplerFactory::Create( const std::shared_ptr &delegate_sampler) { - std::unique_ptr sampler(new ParentBasedSampler(std::move(delegate_sampler))); + std::unique_ptr sampler(new ParentBasedSampler(delegate_sampler)); return sampler; } diff --git a/sdk/test/common/random_test.cc b/sdk/test/common/random_test.cc index 243a998041..e22e0508fc 100644 --- a/sdk/test/common/random_test.cc +++ b/sdk/test/common/random_test.cc @@ -51,6 +51,7 @@ TEST(RandomTest, AtomicFlagMultiThreadTest) { std::vector threads; std::atomic_uint count(0); + threads.reserve(10); for (int i = 0; i < 10; ++i) { threads.push_back(std::thread(doSomethingOnce, &count)); diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index f65c10ca05..277a20582f 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -51,7 +51,7 @@ class MockMetricProducer : public MetricProducer { public: MockMetricProducer(std::chrono::microseconds sleep_ms = std::chrono::microseconds::zero()) - : sleep_ms_{sleep_ms}, data_sent_size_(0) + : sleep_ms_{sleep_ms} {} bool Collect(nostd::function_ref callback) noexcept override @@ -67,7 +67,7 @@ class MockMetricProducer : public MetricProducer private: std::chrono::microseconds sleep_ms_; - size_t data_sent_size_; + size_t data_sent_size_{0}; }; TEST(PeriodicExporingMetricReader, BasicTests) From a9208987c5ac1b2b9136e00ecfbf18890f80aa95 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 26 Aug 2024 21:59:17 +0200 Subject: [PATCH 42/71] [Code Health] include-what-you-use cleanup, part 3 (#3004) --- .iwyu.imp | 3 ++ .../baggage/propagation/baggage_propagator.h | 6 +++ .../common/key_value_iterable_view.h | 5 +++ api/include/opentelemetry/context/context.h | 3 ++ .../opentelemetry/context/runtime_context.h | 4 ++ .../opentelemetry/nostd/function_ref.h | 6 ++- api/include/opentelemetry/nostd/string_view.h | 5 ++- api/include/opentelemetry/nostd/variant.h | 2 +- .../opentelemetry/plugin/dynamic_load.h | 6 +-- api/include/opentelemetry/trace/noop.h | 10 ++++- api/include/opentelemetry/trace/provider.h | 4 +- api/include/opentelemetry/trace/scope.h | 4 +- .../opentelemetry/trace/span_context.h | 2 + api/include/opentelemetry/trace/trace_state.h | 5 ++- api/test/baggage/baggage_benchmark.cc | 9 ++-- api/test/baggage/baggage_test.cc | 41 ++++++++++--------- .../propagation/baggage_propagator_test.cc | 11 ++++- api/test/common/kv_properties_test.cc | 7 +++- api/test/common/spinlock_benchmark.cc | 17 ++++++-- api/test/common/string_util_test.cc | 6 +-- api/test/context/context_test.cc | 11 +++-- .../propagation/composite_propagator_test.cc | 30 +++++++++----- api/test/context/runtime_context_test.cc | 17 ++++++-- api/test/core/timestamp_test.cc | 6 ++- api/test/core/version_test.cc | 6 ++- api/test/logs/logger_benchmark.cc | 25 +++++------ api/test/logs/logger_test.cc | 18 +++++++- api/test/logs/provider_test.cc | 9 +++- api/test/metrics/meter_provider_test.cc | 2 + api/test/metrics/noop_sync_instrument_test.cc | 7 ++++ api/test/nostd/shared_ptr_test.cc | 8 ++-- api/test/nostd/span_test.cc | 8 ++-- api/test/nostd/string_view_test.cc | 7 +++- api/test/nostd/unique_ptr_test.cc | 6 ++- api/test/nostd/utility_test.cc | 6 +-- api/test/plugin/dynamic_load_test.cc | 6 +-- api/test/singleton/component_a.cc | 5 ++- api/test/singleton/component_b.cc | 5 ++- api/test/singleton/component_c.cc | 5 ++- api/test/singleton/component_d.cc | 5 ++- api/test/singleton/component_e.cc | 5 ++- api/test/singleton/component_f.cc | 5 ++- api/test/singleton/component_g.cc | 5 ++- api/test/singleton/component_h.cc | 5 ++- api/test/singleton/singleton_test.cc | 10 ++++- .../trace/key_value_iterable_view_test.cc | 11 ++++- api/test/trace/noop_test.cc | 23 ++++++++--- .../trace/propagation/b3_propagation_test.cc | 26 +++++++++--- api/test/trace/propagation/detail/hex_test.cc | 9 ++-- .../propagation/http_text_format_test.cc | 30 +++++++++++--- .../propagation/jaeger_propagation_test.cc | 30 +++++++++++--- api/test/trace/provider_test.cc | 8 ++-- api/test/trace/scope_test.cc | 12 ++++-- api/test/trace/span_benchmark.cc | 17 ++++++-- api/test/trace/span_id_benchmark.cc | 5 ++- api/test/trace/trace_flags_test.cc | 7 ++-- api/test/trace/trace_state_test.cc | 7 +++- api/test/trace/tracer_test.cc | 9 ++-- .../otlp/otlp_grpc_metric_exporter_factory.h | 2 + .../ext/http/client/http_client.h | 2 + functional/otlp/func_http_main.cc | 1 + 61 files changed, 415 insertions(+), 162 deletions(-) diff --git a/.iwyu.imp b/.iwyu.imp index 53fddd24aa..7ebbeae511 100644 --- a/.iwyu.imp +++ b/.iwyu.imp @@ -9,5 +9,8 @@ # Local opentelemetry-cpp + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, ] diff --git a/api/include/opentelemetry/baggage/propagation/baggage_propagator.h b/api/include/opentelemetry/baggage/propagation/baggage_propagator.h index 6de32882c0..d75409ed60 100644 --- a/api/include/opentelemetry/baggage/propagation/baggage_propagator.h +++ b/api/include/opentelemetry/baggage/propagation/baggage_propagator.h @@ -3,9 +3,15 @@ #pragma once +#include +#include + #include "opentelemetry/baggage/baggage.h" #include "opentelemetry/baggage/baggage_context.h" +#include "opentelemetry/context/context.h" #include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/common/key_value_iterable_view.h b/api/include/opentelemetry/common/key_value_iterable_view.h index fb1a6ea019..e22fb6f06f 100644 --- a/api/include/opentelemetry/common/key_value_iterable_view.h +++ b/api/include/opentelemetry/common/key_value_iterable_view.h @@ -3,9 +3,14 @@ #pragma once +#include +#include #include +#include #include +#include +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/span.h" diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index cf5c9cd319..620ca51c8b 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -4,9 +4,12 @@ #pragma once #include +#include + #include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h index cccc71e32f..73d4dcd908 100644 --- a/api/include/opentelemetry/context/runtime_context.h +++ b/api/include/opentelemetry/context/runtime_context.h @@ -3,8 +3,12 @@ #pragma once +#include +#include + #include "opentelemetry/common/macros.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" diff --git a/api/include/opentelemetry/nostd/function_ref.h b/api/include/opentelemetry/nostd/function_ref.h index 1064c966d7..6f0c2dd330 100644 --- a/api/include/opentelemetry/nostd/function_ref.h +++ b/api/include/opentelemetry/nostd/function_ref.h @@ -3,8 +3,10 @@ #pragma once -#include +#include +#include // IWYU pragma: keep #include +#include #include "opentelemetry/version.h" @@ -12,7 +14,7 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace nostd { template -class function_ref; +class function_ref; // IWYU pragma: keep /** * Non-owning function reference that can be used as a more performant diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 5ee86dce23..f0e5bd9e2a 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -12,13 +12,14 @@ #if !defined(OPENTELEMETRY_HAVE_STD_STRING_VIEW) # include -# include # include +# include # include # include # include +# include +# include -# include "opentelemetry/common/macros.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index d0b2d96001..6f3837c588 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -54,7 +54,7 @@ OPENTELEMETRY_END_NAMESPACE # ifdef HAVE_ABSEIL # include "absl/types/variant.h" # else -# include "./internal/absl/types/variant.h" +# include "opentelemetry/nostd/internal/absl/types/variant.h" # endif # ifdef _MSC_VER diff --git a/api/include/opentelemetry/plugin/dynamic_load.h b/api/include/opentelemetry/plugin/dynamic_load.h index 10b4a34af4..2da2713555 100644 --- a/api/include/opentelemetry/plugin/dynamic_load.h +++ b/api/include/opentelemetry/plugin/dynamic_load.h @@ -6,19 +6,19 @@ #include #include +#include "opentelemetry/plugin/factory.h" +#include "opentelemetry/version.h" + #ifdef _WIN32 # include "opentelemetry/plugin/detail/dynamic_load_windows.h" // IWYU pragma: export #else # include "opentelemetry/plugin/detail/dynamic_load_unix.h" // IWYU pragma: export #endif -#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace plugin { -class Factory; - /** * Load an OpenTelemetry implementation as a plugin. * @param plugin the path to the plugin to load diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 345c4ba0c9..fa0c7957df 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -7,15 +7,21 @@ // This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be // used directly. Please refer to span.h and tracer.h for documentation on these interfaces. -#include +#include +#include -#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/span_startoptions.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/version.h" diff --git a/api/include/opentelemetry/trace/provider.h b/api/include/opentelemetry/trace/provider.h index d5a52a02f6..1439b579be 100644 --- a/api/include/opentelemetry/trace/provider.h +++ b/api/include/opentelemetry/trace/provider.h @@ -5,18 +5,16 @@ #include -#include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/noop.h" +#include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { -class TracerProvider; - /** * Stores the singleton global TracerProvider. */ diff --git a/api/include/opentelemetry/trace/scope.h b/api/include/opentelemetry/trace/scope.h index 11ded4ab6c..20c415cc72 100644 --- a/api/include/opentelemetry/trace/scope.h +++ b/api/include/opentelemetry/trace/scope.h @@ -3,9 +3,11 @@ #pragma once +#include "opentelemetry/context/context.h" #include "opentelemetry/context/runtime_context.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_metadata.h" #include "opentelemetry/version.h" @@ -13,8 +15,6 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { -class Span; - /** * Controls how long a span is active. * diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index 5fcab6e7ed..9403a74fb6 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_flags.h" diff --git a/api/include/opentelemetry/trace/trace_state.h b/api/include/opentelemetry/trace/trace_state.h index f51410025a..753f48c99e 100644 --- a/api/include/opentelemetry/trace/trace_state.h +++ b/api/include/opentelemetry/trace/trace_state.h @@ -3,13 +3,14 @@ #pragma once -#include +#include +#include #include +#include #include "opentelemetry/common/kv_properties.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" diff --git a/api/test/baggage/baggage_benchmark.cc b/api/test/baggage/baggage_benchmark.cc index 4ced142327..0786537cc0 100644 --- a/api/test/baggage/baggage_benchmark.cc +++ b/api/test/baggage/baggage_benchmark.cc @@ -1,11 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + #include "opentelemetry/baggage/baggage.h" #include "opentelemetry/nostd/string_view.h" - -#include -#include +#include "opentelemetry/nostd/utility.h" using namespace opentelemetry::baggage; namespace nostd = opentelemetry::nostd; diff --git a/api/test/baggage/baggage_test.cc b/api/test/baggage/baggage_test.cc index f29615c983..6f0347eef9 100644 --- a/api/test/baggage/baggage_test.cc +++ b/api/test/baggage/baggage_test.cc @@ -1,15 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/string_view.h" - +#include #include +#include #include #include #include "opentelemetry/baggage/baggage.h" +#include "opentelemetry/common/kv_properties.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" -using namespace opentelemetry; using namespace opentelemetry::baggage; std::string header_with_custom_entries(size_t num_entries) @@ -82,7 +84,8 @@ TEST(BaggageTest, ValidateExtractHeader) { auto baggage = Baggage::FromHeader(testcase.input); size_t index = 0; - baggage->GetAllEntries([&testcase, &index](nostd::string_view key, nostd::string_view value) { + baggage->GetAllEntries([&testcase, &index](opentelemetry::nostd::string_view key, + opentelemetry::nostd::string_view value) { EXPECT_EQ(key, testcase.keys[index]); EXPECT_EQ(value, testcase.values[index]); index++; @@ -97,7 +100,7 @@ TEST(BaggageTest, ValidateExtractHeader) // Entries beyond threshold are dropped auto baggage = Baggage::FromHeader(header_with_custom_entries(Baggage::kMaxKeyValuePairs + 1)); auto header = baggage->ToHeader(); - common::KeyValueStringTokenizer kv_str_tokenizer(header); + opentelemetry::common::KeyValueStringTokenizer kv_str_tokenizer(header); int expected_tokens = Baggage::kMaxKeyValuePairs; EXPECT_EQ(kv_str_tokenizer.NumTokens(), expected_tokens); @@ -126,7 +129,7 @@ TEST(BaggageTest, ValidateInjectHeader) for (auto &testcase : testcases) { - nostd::shared_ptr baggage(new Baggage{}); + opentelemetry::nostd::shared_ptr baggage(new Baggage{}); for (size_t i = 0; i < testcase.keys.size(); i++) { baggage = baggage->Set(testcase.keys[i], testcase.values[i]); @@ -202,17 +205,17 @@ TEST(BaggageTest, BaggageRemove) TEST(BaggageTest, BaggageGetAll) { - std::string baggage_header = "k1=v1,k2=v2,k3=v3"; - auto baggage = Baggage::FromHeader(baggage_header); - const int kNumPairs = 3; - nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; - nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; - size_t index = 0; - baggage->GetAllEntries( - [&keys, &values, &index](nostd::string_view key, nostd::string_view value) { - EXPECT_EQ(key, keys[index]); - EXPECT_EQ(value, values[index]); - index++; - return true; - }); + std::string baggage_header = "k1=v1,k2=v2,k3=v3"; + auto baggage = Baggage::FromHeader(baggage_header); + const int kNumPairs = 3; + opentelemetry::nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + opentelemetry::nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + size_t index = 0; + baggage->GetAllEntries([&keys, &values, &index](opentelemetry::nostd::string_view key, + opentelemetry::nostd::string_view value) { + EXPECT_EQ(key, keys[index]); + EXPECT_EQ(value, values[index]); + index++; + return true; + }); } diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index c966fe7603..0efe1fac19 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -2,11 +2,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/baggage/propagation/baggage_propagator.h" #include #include +#include #include +#include +#include + +#include "opentelemetry/baggage/baggage.h" #include "opentelemetry/baggage/baggage_context.h" +#include "opentelemetry/baggage/propagation/baggage_propagator.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" using namespace opentelemetry; using namespace opentelemetry::baggage::propagation; diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index f616664265..e81ee6979c 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -3,12 +3,15 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - +#include #include #include #include +#include +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" + // ------------------------- Entry class tests --------------------------------- using namespace opentelemetry; diff --git a/api/test/common/spinlock_benchmark.cc b/api/test/common/spinlock_benchmark.cc index d0fef2c41b..b5e98a2108 100644 --- a/api/test/common/spinlock_benchmark.cc +++ b/api/test/common/spinlock_benchmark.cc @@ -1,10 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/common/spin_lock_mutex.h" - #include -#include +#include +#include +#include +#include +#include + +#if defined(__i386__) || defined(__x86_64__) +# if defined(__clang__) || defined(__INTEL_COMPILER) +# include // for _mm_pause +# endif +#endif + +#include "opentelemetry/common/macros.h" +#include "opentelemetry/common/spin_lock_mutex.h" namespace { diff --git a/api/test/common/string_util_test.cc b/api/test/common/string_util_test.cc index da2e635119..f074d4fbe3 100644 --- a/api/test/common/string_util_test.cc +++ b/api/test/common/string_util_test.cc @@ -2,11 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include -#include -#include -#include +#include // ------------------------- StringUtil class tests --------------------------------- diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 294f1cd180..0798d7a130 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -1,11 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/context/context.h" - +#include +#include #include +#include -#include +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" using namespace opentelemetry; diff --git a/api/test/context/propagation/composite_propagator_test.cc b/api/test/context/propagation/composite_propagator_test.cc index 075841080f..e905f64e1a 100644 --- a/api/test/context/propagation/composite_propagator_test.cc +++ b/api/test/context/propagation/composite_propagator_test.cc @@ -1,22 +1,32 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/trace/scope.h" -#include "opentelemetry/trace/span.h" -#include "opentelemetry/trace/span_context.h" +#include +#include +#include +#include +#include +#include +#include +#include "opentelemetry/context/context.h" #include "opentelemetry/context/propagation/composite_propagator.h" #include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/propagation/b3_propagator.h" #include "opentelemetry/trace/propagation/http_trace_context.h" - -#include -#include -#include - -#include +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" using namespace opentelemetry; diff --git a/api/test/context/runtime_context_test.cc b/api/test/context/runtime_context_test.cc index cd551c599c..f8407b0ca8 100644 --- a/api/test/context/runtime_context_test.cc +++ b/api/test/context/runtime_context_test.cc @@ -1,13 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/context/context.h" - +#include +#include +#include #include #include +#include +#include +#include -#include +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/variant.h" using namespace opentelemetry; diff --git a/api/test/core/timestamp_test.cc b/api/test/core/timestamp_test.cc index 8efc0215be..ba3c70e4e5 100644 --- a/api/test/core/timestamp_test.cc +++ b/api/test/core/timestamp_test.cc @@ -1,9 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/common/timestamp.h" - #include +#include +#include + +#include "opentelemetry/common/timestamp.h" using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; diff --git a/api/test/core/version_test.cc b/api/test/core/version_test.cc index 2e360ffdad..1ceb68602b 100644 --- a/api/test/core/version_test.cc +++ b/api/test/core/version_test.cc @@ -1,9 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/version.h" - #include +#include +#include + +#include "opentelemetry/version.h" TEST(VersionTest, Consistency) { diff --git a/api/test/logs/logger_benchmark.cc b/api/test/logs/logger_benchmark.cc index 7e8913a3f7..29808fa003 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -1,29 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/common/timestamp.h" -#include "opentelemetry/logs/logger.h" -#include "opentelemetry/logs/provider.h" -#include "opentelemetry/nostd/shared_ptr.h" - -#include +#include +#include +#include #include +#include #include #include #include #include -#include +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/logs/event_id.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" using opentelemetry::logs::EventId; using opentelemetry::logs::Provider; using opentelemetry::logs::Severity; -namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; -namespace trace = opentelemetry::trace; -namespace log_api = opentelemetry::logs; - namespace { diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 848f053453..351e079dd4 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -2,13 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include +#include +#include #include -#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/logs/event_id.h" +#include "opentelemetry/logs/event_logger.h" +#include "opentelemetry/logs/event_logger_provider.h" +#include "opentelemetry/logs/log_record.h" #include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" +#include "opentelemetry/logs/severity.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/utility.h" using opentelemetry::logs::EventId; using opentelemetry::logs::Logger; diff --git a/api/test/logs/provider_test.cc b/api/test/logs/provider_test.cc index 92c589ef7e..298289ceab 100644 --- a/api/test/logs/provider_test.cc +++ b/api/test/logs/provider_test.cc @@ -2,10 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/logs/event_logger.h" +#include "opentelemetry/logs/event_logger_provider.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" using opentelemetry::logs::EventLogger; using opentelemetry::logs::EventLoggerProvider; diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index b8fb083799..639f0e8f49 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include + +#include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/provider.h" #include "opentelemetry/nostd/shared_ptr.h" diff --git a/api/test/metrics/noop_sync_instrument_test.cc b/api/test/metrics/noop_sync_instrument_test.cc index 6411e0e820..4218f2b4ff 100644 --- a/api/test/metrics/noop_sync_instrument_test.cc +++ b/api/test/metrics/noop_sync_instrument_test.cc @@ -2,8 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include +#include +#include + +#include "opentelemetry/context/context.h" #include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/string_view.h" TEST(Counter, Add) { diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 2ebba82628..e5f77709b1 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -1,11 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/shared_ptr.h" - #include - +#include #include +#include +#include + +#include "opentelemetry/nostd/shared_ptr.h" using opentelemetry::nostd::shared_ptr; diff --git a/api/test/nostd/span_test.cc b/api/test/nostd/span_test.cc index 17427a249a..b54883d67a 100644 --- a/api/test/nostd/span_test.cc +++ b/api/test/nostd/span_test.cc @@ -1,10 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/span.h" - -#include - +#include +#include #include #include #include @@ -12,7 +10,7 @@ #include #include -#include +#include "opentelemetry/nostd/span.h" using opentelemetry::nostd::span; diff --git a/api/test/nostd/string_view_test.cc b/api/test/nostd/string_view_test.cc index bbd5cb0648..f32da62b42 100644 --- a/api/test/nostd/string_view_test.cc +++ b/api/test/nostd/string_view_test.cc @@ -1,11 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/string_view.h" - #include #include #include +#include +#include +#include + +#include "opentelemetry/nostd/string_view.h" using opentelemetry::nostd::string_view; diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index 893525c266..9fbe058822 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -1,9 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/unique_ptr.h" - #include +#include +#include + +#include "opentelemetry/nostd/unique_ptr.h" using opentelemetry::nostd::unique_ptr; diff --git a/api/test/nostd/utility_test.cc b/api/test/nostd/utility_test.cc index 821b2a70a4..5c62df0c88 100644 --- a/api/test/nostd/utility_test.cc +++ b/api/test/nostd/utility_test.cc @@ -1,13 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/utility.h" - +#include +#include #include #include #include -#include +#include "opentelemetry/nostd/utility.h" namespace nostd = opentelemetry::nostd; diff --git a/api/test/plugin/dynamic_load_test.cc b/api/test/plugin/dynamic_load_test.cc index 8e8b14800c..68a27b5a8f 100644 --- a/api/test/plugin/dynamic_load_test.cc +++ b/api/test/plugin/dynamic_load_test.cc @@ -1,10 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/plugin/dynamic_load.h" -#include "opentelemetry/plugin/factory.h" - #include +#include + +#include "opentelemetry/plugin/dynamic_load.h" TEST(LoadFactoryTest, FailureTest) { diff --git a/api/test/singleton/component_a.cc b/api/test/singleton/component_a.cc index bdf03cb699..1660f85685 100644 --- a/api/test/singleton/component_a.cc +++ b/api/test/singleton/component_a.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #include "component_a.h" diff --git a/api/test/singleton/component_b.cc b/api/test/singleton/component_b.cc index 966d9c461a..ea53f39b6e 100644 --- a/api/test/singleton/component_b.cc +++ b/api/test/singleton/component_b.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #include "component_b.h" diff --git a/api/test/singleton/component_c.cc b/api/test/singleton/component_c.cc index cd87ceb727..9fae8b41db 100644 --- a/api/test/singleton/component_c.cc +++ b/api/test/singleton/component_c.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #define BUILD_COMPONENT_C diff --git a/api/test/singleton/component_d.cc b/api/test/singleton/component_d.cc index 313fd1d23a..57f3252826 100644 --- a/api/test/singleton/component_d.cc +++ b/api/test/singleton/component_d.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #define BUILD_COMPONENT_D diff --git a/api/test/singleton/component_e.cc b/api/test/singleton/component_e.cc index 9c88d27732..94eec808ab 100644 --- a/api/test/singleton/component_e.cc +++ b/api/test/singleton/component_e.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #define BUILD_COMPONENT_E diff --git a/api/test/singleton/component_f.cc b/api/test/singleton/component_f.cc index 33b0af2fbd..9083e2bced 100644 --- a/api/test/singleton/component_f.cc +++ b/api/test/singleton/component_f.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" #define BUILD_COMPONENT_F diff --git a/api/test/singleton/component_g.cc b/api/test/singleton/component_g.cc index 50de03ee98..0529ca7c27 100644 --- a/api/test/singleton/component_g.cc +++ b/api/test/singleton/component_g.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; diff --git a/api/test/singleton/component_h.cc b/api/test/singleton/component_h.cc index 3ff6e0cc5a..a66ab96858 100644 --- a/api/test/singleton/component_h.cc +++ b/api/test/singleton/component_h.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/provider.h" -#include "opentelemetry/version.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index fb4551cfe9..d212221118 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include /* TODO: @@ -12,8 +13,6 @@ # include #endif -#include - #include "component_a.h" #include "component_b.h" #include "component_c.h" @@ -21,11 +20,18 @@ #include "component_e.h" #include "component_f.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/noop.h" #include "opentelemetry/trace/provider.h" #include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" using namespace opentelemetry; diff --git a/api/test/trace/key_value_iterable_view_test.cc b/api/test/trace/key_value_iterable_view_test.cc index e0f43c4afb..b2334b8f98 100644 --- a/api/test/trace/key_value_iterable_view_test.cc +++ b/api/test/trace/key_value_iterable_view_test.cc @@ -1,11 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/common/key_value_iterable_view.h" - #include #include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/nostd/utility.h" using namespace opentelemetry; diff --git a/api/test/trace/noop_test.cc b/api/test/trace/noop_test.cc index b47700d442..26663c738f 100644 --- a/api/test/trace/noop_test.cc +++ b/api/test/trace/noop_test.cc @@ -1,14 +1,27 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/noop.h" -#include "opentelemetry/common/timestamp.h" - +#include +#include +#include #include -#include #include +#include +#include -#include +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/noop.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" namespace trace_api = opentelemetry::trace; namespace nonstd = opentelemetry::nostd; diff --git a/api/test/trace/propagation/b3_propagation_test.cc b/api/test/trace/propagation/b3_propagation_test.cc index 732db1bd34..a2a0581ad1 100644 --- a/api/test/trace/propagation/b3_propagation_test.cc +++ b/api/test/trace/propagation/b3_propagation_test.cc @@ -1,14 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include "util.h" + +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/propagation/b3_propagator.h" #include "opentelemetry/trace/scope.h" -#include "util.h" - -#include - -#include +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" using namespace opentelemetry; diff --git a/api/test/trace/propagation/detail/hex_test.cc b/api/test/trace/propagation/detail/hex_test.cc index f4bd765f48..88cf5b46b0 100644 --- a/api/test/trace/propagation/detail/hex_test.cc +++ b/api/test/trace/propagation/detail/hex_test.cc @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/propagation/detail/hex.h" - -#include - #include +#include +#include + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/propagation/detail/hex.h" using namespace opentelemetry; diff --git a/api/test/trace/propagation/http_text_format_test.cc b/api/test/trace/propagation/http_text_format_test.cc index 99f7117928..54f041a9cc 100644 --- a/api/test/trace/propagation/http_text_format_test.cc +++ b/api/test/trace/propagation/http_text_format_test.cc @@ -1,17 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include "util.h" + +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" #include "opentelemetry/context/propagation/global_propagator.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/context.h" +#include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/propagation/http_trace_context.h" #include "opentelemetry/trace/scope.h" -#include "util.h" - -#include -#include - -#include +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" using namespace opentelemetry; diff --git a/api/test/trace/propagation/jaeger_propagation_test.cc b/api/test/trace/propagation/jaeger_propagation_test.cc index f0fdaf734d..637d2206b8 100644 --- a/api/test/trace/propagation/jaeger_propagation_test.cc +++ b/api/test/trace/propagation/jaeger_propagation_test.cc @@ -1,13 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/propagation/jaeger.h" -#include "opentelemetry/trace/scope.h" -#include "util.h" - +#include +#include +#include #include +#include +#include +#include +#include "util.h" -#include +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/trace/context.h" +#include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/propagation/jaeger.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" using namespace opentelemetry; diff --git a/api/test/trace/provider_test.cc b/api/test/trace/provider_test.cc index be2ca2842c..6b59d91245 100644 --- a/api/test/trace/provider_test.cc +++ b/api/test/trace/provider_test.cc @@ -1,12 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/provider.h" +#include + #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" -#include - using opentelemetry::trace::Provider; using opentelemetry::trace::Tracer; using opentelemetry::trace::TracerProvider; diff --git a/api/test/trace/scope_test.cc b/api/test/trace/scope_test.cc index b74905b167..1383122bbc 100644 --- a/api/test/trace/scope_test.cc +++ b/api/test/trace/scope_test.cc @@ -1,12 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/scope.h" -#include "opentelemetry/context/context.h" +#include + +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/runtime_context.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/noop.h" - -#include +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_metadata.h" using opentelemetry::trace::kSpanKey; using opentelemetry::trace::NoopSpan; diff --git a/api/test/trace/span_benchmark.cc b/api/test/trace/span_benchmark.cc index 3120eb0e5a..8770ec14a0 100644 --- a/api/test/trace/span_benchmark.cc +++ b/api/test/trace/span_benchmark.cc @@ -1,15 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include + +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/runtime_context.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/context.h" +#include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/noop.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" - -#include - -#include +#include "opentelemetry/trace/tracer.h" using opentelemetry::trace::SpanContext; namespace trace_api = opentelemetry::trace; diff --git a/api/test/trace/span_id_benchmark.cc b/api/test/trace/span_id_benchmark.cc index 42d4aeb465..236fa3ac76 100644 --- a/api/test/trace/span_id_benchmark.cc +++ b/api/test/trace/span_id_benchmark.cc @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/span_id.h" - #include #include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/trace/span_id.h" + namespace { using opentelemetry::trace::SpanId; diff --git a/api/test/trace/trace_flags_test.cc b/api/test/trace/trace_flags_test.cc index 783b56d839..d900c6f7d5 100644 --- a/api/test/trace/trace_flags_test.cc +++ b/api/test/trace/trace_flags_test.cc @@ -1,12 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/trace_flags.h" - -#include +#include +#include #include -#include +#include "opentelemetry/trace/trace_flags.h" namespace { diff --git a/api/test/trace/trace_state_test.cc b/api/test/trace/trace_state_test.cc index e6ed73c1f4..d136bddb00 100644 --- a/api/test/trace/trace_state_test.cc +++ b/api/test/trace/trace_state_test.cc @@ -1,10 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/trace/trace_state.h" - #include +#include +#include +#include + #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/trace_state.h" namespace { diff --git a/api/test/trace/tracer_test.cc b/api/test/trace/tracer_test.cc index 8e16f15e25..77396a24d2 100644 --- a/api/test/trace/tracer_test.cc +++ b/api/test/trace/tracer_test.cc @@ -1,11 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include + +#include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/noop.h" -#include "opentelemetry/trace/scope.h" - -#include +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/tracer.h" namespace trace_api = opentelemetry::trace; namespace nostd = opentelemetry::nostd; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h index f8b3ee1fc3..11b185a384 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" diff --git a/ext/include/opentelemetry/ext/http/client/http_client.h b/ext/include/opentelemetry/ext/http/client/http_client.h index 1089402e28..d17215da9b 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client.h +++ b/ext/include/opentelemetry/ext/http/client/http_client.h @@ -6,8 +6,10 @@ #include #include #include +#include #include #include + #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index ece1588425..99fec8443e 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include #include #include From f02d70bdb82985bea713b283bdd3da9937cb2172 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Tue, 3 Sep 2024 09:19:57 -0400 Subject: [PATCH 43/71] Fix overflow in timeout logic (#3046) --- .../periodic_exporting_metric_reader.cc | 2 +- sdk/src/metrics/meter_context.cc | 34 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 1ebfc2a1b6..42fd6003ae 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -218,7 +218,7 @@ bool PeriodicExportingMetricReader::OnForceFlush(std::chrono::microseconds timeo // - If original `timeout` is `zero`, use that in exporter::forceflush // - Else if remaining `timeout_steady` more than zero, use that in exporter::forceflush // - Else don't invoke exporter::forceflush ( as remaining time is zero or less) - if (timeout <= std::chrono::steady_clock::duration::zero()) + if (timeout <= std::chrono::milliseconds::duration::zero()) { result = exporter_->ForceFlush(std::chrono::duration_cast(timeout)); diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index 40b9da42b2..42efce76fb 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -168,46 +168,36 @@ bool MeterContext::ForceFlush(std::chrono::microseconds timeout) noexcept bool result = true; // Simultaneous flush not allowed. const std::lock_guard locked(forceflush_lock_); - // Convert to nanos to prevent overflow - auto timeout_ns = (std::chrono::nanoseconds::max)(); - if (std::chrono::duration_cast(timeout_ns) > timeout) - { - timeout_ns = std::chrono::duration_cast(timeout); - } - - auto current_time = std::chrono::system_clock::now(); - std::chrono::system_clock::time_point expire_time; - auto overflow_checker = (std::chrono::system_clock::time_point::max)(); - // check if the expected expire time doesn't overflow. - if (overflow_checker - current_time > timeout_ns) + auto time_remaining = (std::chrono::steady_clock::duration::max)(); + if (std::chrono::duration_cast(time_remaining) > timeout) { - expire_time = - current_time + std::chrono::duration_cast(timeout_ns); + time_remaining = timeout; } - else + + auto current_time = std::chrono::steady_clock::now(); + auto expire_time = (std::chrono::steady_clock::time_point::max)(); + if (expire_time - current_time > time_remaining) { - // overflow happens, reset expire time to max. - expire_time = overflow_checker; + expire_time = current_time + time_remaining; } for (auto &collector : collectors_) { if (!std::static_pointer_cast(collector)->ForceFlush( - std::chrono::duration_cast(timeout_ns))) + std::chrono::duration_cast(time_remaining))) { result = false; } - current_time = std::chrono::system_clock::now(); - + current_time = std::chrono::steady_clock::now(); if (expire_time >= current_time) { - timeout_ns = std::chrono::duration_cast(expire_time - current_time); + time_remaining = expire_time - current_time; } else { - timeout_ns = std::chrono::nanoseconds::zero(); + time_remaining = std::chrono::steady_clock::duration::zero(); } } if (!result) From 7f785b5d5c1c3b6125eca9685a9eb6d7f443038a Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Tue, 3 Sep 2024 15:08:37 -0400 Subject: [PATCH 44/71] [TEST] Add missing tests to Bazel build (#3045) * Fix overflow in timeout logic Also use steady clock consistently. Prior to this change, the test would fail under ASAN: bazel test --config=asan --test_output=errors //sdk/test/metrics:meter_provider_sdk_test INFO: Analyzed target //sdk/test/metrics:meter_provider_sdk_test (0 packages loaded, 0 targets configured). FAIL: //sdk/test/metrics:meter_provider_sdk_test (see /private/var/tmp/_bazel_punya/e3bd968ba61238cdeb1a5537fc3dbf7d/execroot/_main/bazel-out/darwin_arm64-fastbuild-asan/testlogs/sdk/test/metrics/meter_provider_sdk_test/test.log) INFO: From Testing //sdk/test/metrics:meter_provider_sdk_test: ==================== Test output for //sdk/test/metrics:meter_provider_sdk_test: Running main() from gmock_main.cc [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from MeterProvider [ RUN ] MeterProvider.GetMeter [Warning] File: sdk/src/metrics/meter_provider.cc:65 [MeterProvider::GetMeter] Library name is empty. [Warning] File: sdk/src/metrics/meter_provider.cc:65 [MeterProvider::GetMeter] Library name is empty. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__chrono/duration.h:102:59: runtime error: signed integer overflow: 9221646818050376183 * 1000 cannot be represented in type '_Ct' (aka 'long long') SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__chrono/duration.h:102:59 in ================================================================================ INFO: Found 1 test target... Target //sdk/test/metrics:meter_provider_sdk_test up-to-date: bazel-bin/sdk/test/metrics/meter_provider_sdk_test INFO: Elapsed time: 2.251s, Critical Path: 2.13s INFO: 5 processes: 5 darwin-sandbox. INFO: Build completed, 1 test FAILED, 5 total actions //sdk/test/metrics:meter_provider_sdk_test FAILED in 0.6s /private/var/tmp/_bazel_punya/e3bd968ba61238cdeb1a5537fc3dbf7d/execroot/_main/bazel-out/darwin_arm64-fastbuild-asan/testlogs/sdk/test/metrics/meter_provider_sdk_test/test.log Executed 1 out of 1 test: 1 fails locally. Fix overflow in periodic_exporting_metric_reader * Add missing tests to Bazel build by globbing test files Previously, we were missing * instrument_metadata_validator_test * observable_registry_test * cardinality_limit_test * periodic_exporting_metric_reader_test And there were no checks in place to prevent things from getting worse. Remove unnecessary exception checks in attributes_hashmap_test, which simplifies the build and CI script. Resolve symbol collision using anonymous namespaces. --------- Co-authored-by: Lalit Kumar Bhasin --- ci/do_ci.sh | 4 +- sdk/test/metrics/BUILD | 303 +----------------- sdk/test/metrics/async_instruments_test.cc | 3 + sdk/test/metrics/attributes_hashmap_test.cc | 10 +- sdk/test/metrics/meter_test.cc | 2 +- .../periodic_exporting_metric_reader_test.cc | 2 +- 6 files changed, 14 insertions(+), 310 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 6d339c8d4e..4cd97a7f43 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -484,8 +484,8 @@ elif [[ "$1" == "bazel.noexcept" ]]; then # there are some exceptions and error handling code from the Prometheus Client # as well as Opentracing shim (due to some third party code in its Opentracing dependency) # that make this test always fail. Ignore these packages in the noexcept test here. - bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/... - bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/... + bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//opentracing-shim/... + bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//opentracing-shim/... exit 0 elif [[ "$1" == "bazel.nortti" ]]; then # there are some exceptions and error handling code from the Prometheus Client diff --git a/sdk/test/metrics/BUILD b/sdk/test/metrics/BUILD index 3cf379494d..70d0cc063a 100644 --- a/sdk/test/metrics/BUILD +++ b/sdk/test/metrics/BUILD @@ -19,307 +19,8 @@ cc_library( ) cc_test( - name = "meter_test", - srcs = [ - "meter_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "meter_provider_sdk_test", - srcs = [ - "meter_provider_sdk_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "metric_reader_test", - srcs = [ - "metric_reader_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "histogram_test", - srcs = [ - "histogram_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "view_registry_test", - srcs = [ - "view_registry_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "aggregation_test", - srcs = [ - "aggregation_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "sync_metric_storage_counter_test", - srcs = [ - "sync_metric_storage_counter_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "sync_metric_storage_up_down_counter_test", - srcs = [ - "sync_metric_storage_up_down_counter_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "sync_metric_storage_histogram_test", - srcs = [ - "sync_metric_storage_histogram_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "sync_instruments_test", - srcs = [ - "sync_instruments_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "async_instruments_test", - srcs = [ - "async_instruments_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "async_metric_storage_test", - srcs = [ - "async_metric_storage_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "observer_result_test", - srcs = [ - "observer_result_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "multi_metric_storage_test", - srcs = [ - "multi_metric_storage_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "attributes_processor_test", - srcs = [ - "attributes_processor_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "attributes_hashmap_test", - srcs = [ - "attributes_hashmap_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "circular_buffer_counter_test", - srcs = [ - "circular_buffer_counter_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "//sdk/src/metrics", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "base2_exponential_histogram_indexer_test", - srcs = [ - "base2_exponential_histogram_indexer_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "histogram_aggregation_test", - srcs = [ - "histogram_aggregation_test.cc", - ], - tags = [ - "metrics", - "test", - ], - deps = [ - "metrics_common_test_utils", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "sum_aggregation_test", - srcs = [ - "sum_aggregation_test.cc", - ], + name = "all_tests", + srcs = glob(["*_test.cc"]), tags = [ "metrics", "test", diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index b7ad885bbd..01a421e046 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -12,10 +12,13 @@ using namespace opentelemetry::sdk::metrics; using M = std::map; +namespace +{ // NOLINTNEXTLINE void asyc_generate_measurements(opentelemetry::metrics::ObserverResult /* observer */, void * /* state */) {} +} // namespace TEST(AsyncInstruments, ObservableInstrument) { diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index 9ae8f5cfd5..7d77e6166a 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -26,14 +26,14 @@ TEST(AttributesHashMap, BasicTests) std::unique_ptr aggregation1( new DropAggregation()); // = std::unique_ptr(new DropAggregation); hash_map.Set(m1, std::move(aggregation1), hash); - EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate(static_cast(1))); + hash_map.Get(hash)->Aggregate(static_cast(1)); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(hash), true); // Set same key again auto aggregation2 = std::unique_ptr(new DropAggregation()); hash_map.Set(m1, std::move(aggregation2), hash); - EXPECT_NO_THROW(hash_map.Get(hash)->Aggregate(static_cast(1))); + hash_map.Get(hash)->Aggregate(static_cast(1)); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(hash), true); @@ -44,7 +44,7 @@ TEST(AttributesHashMap, BasicTests) hash_map.Set(m3, std::move(aggregation3), hash3); EXPECT_EQ(hash_map.Has(hash), true); EXPECT_EQ(hash_map.Has(hash3), true); - EXPECT_NO_THROW(hash_map.Get(hash3)->Aggregate(static_cast(1))); + hash_map.Get(hash3)->Aggregate(static_cast(1)); EXPECT_EQ(hash_map.Size(), 2); // GetOrSetDefault @@ -54,8 +54,8 @@ TEST(AttributesHashMap, BasicTests) }; MetricAttributes m4 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; auto hash4 = opentelemetry::sdk::common::GetHashForAttributeMap(m4); - EXPECT_NO_THROW(hash_map.GetOrSetDefault(m4, create_default_aggregation, hash4) - ->Aggregate(static_cast(1))); + hash_map.GetOrSetDefault(m4, create_default_aggregation, hash4) + ->Aggregate(static_cast(1)); EXPECT_EQ(hash_map.Size(), 3); // Set attributes with different order - shouldn't create a new entry. diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index b5ed86f55a..cd66737465 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -28,7 +28,6 @@ nostd::shared_ptr InitMeter(MetricReader **metricReaderPtr, auto meter = provider->GetMeter(meter_name); return meter; } -} // namespace void asyc_generate_measurements(opentelemetry::metrics::ObserverResult observer, void * /* state */) { @@ -36,6 +35,7 @@ void asyc_generate_measurements(opentelemetry::metrics::ObserverResult observer, nostd::get>>(observer); observer_long->Observe(10); } +} // namespace TEST(MeterTest, BasicAsyncTests) { diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index 277a20582f..2eec5e8c61 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -83,7 +83,7 @@ TEST(PeriodicExporingMetricReader, BasicTests) MockMetricProducer producer; reader->SetMetricProducer(&producer); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - EXPECT_NO_THROW(reader->ForceFlush()); + reader->ForceFlush(); reader->Shutdown(); EXPECT_EQ(static_cast(exporter_ptr)->GetDataCount(), static_cast(&producer)->GetDataCount()); From 080356950e121630f0ba518b963f00fce25a589b Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:45:12 -0700 Subject: [PATCH 45/71] [TEST] update collector example with debug exporter (#3050) The logging exporter was renamed debug in 2023, the logging exporter will be removed in the near future, updating the example accordingly. --- functional/otlp/otel-config-http.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functional/otlp/otel-config-http.yaml b/functional/otlp/otel-config-http.yaml index da68e6f96c..858b3b7fe5 100644 --- a/functional/otlp/otel-config-http.yaml +++ b/functional/otlp/otel-config-http.yaml @@ -22,12 +22,12 @@ processors: check_interval: 5s exporters: - logging: - loglevel: debug + debug: + verbosity: debug service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] - exporters: [logging] + exporters: [debug] From 0d5a387b00f4d5fa25839883929e37365324b3de Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:58:53 -0700 Subject: [PATCH 46/71] [EXAMPLE] update collector example with debug exporter (#3049) The logging exporter was renamed debug in 2023, the logging exporter will be removed in the near future, updating the example accordingly. Co-authored-by: Marc Alff --- .../opentelemetry-collector-config/config.dev.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/otlp/opentelemetry-collector-config/config.dev.yaml b/examples/otlp/opentelemetry-collector-config/config.dev.yaml index 267b7250d6..8fbe3634ea 100644 --- a/examples/otlp/opentelemetry-collector-config/config.dev.yaml +++ b/examples/otlp/opentelemetry-collector-config/config.dev.yaml @@ -2,8 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 exporters: - logging: - loglevel: DEBUG + debug: + verbosity: debug receivers: otlp: protocols: @@ -17,14 +17,14 @@ service: receivers: - otlp exporters: - - logging + - debug logs: receivers: - otlp exporters: - - logging + - debug metrics: receivers: - otlp exporters: - - logging + - debug From 261a15182964faf5115b4209adefa7054f07abf1 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:34:20 -0700 Subject: [PATCH 47/71] [TEST] update references to logging exporter (#3053) This exporter has been replaced by the debug exporter and will be removed soon Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .../otlp/opentelemetry-collector-config/config.dev.yaml | 2 +- functional/otlp/otel-config-http.yaml | 2 +- functional/otlp/otel-config-https.yaml | 6 +++--- functional/otlp/otel-docker-config-http.yaml | 6 +++--- functional/otlp/otel-docker-config-https.yaml | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/otlp/opentelemetry-collector-config/config.dev.yaml b/examples/otlp/opentelemetry-collector-config/config.dev.yaml index 8fbe3634ea..b98e384917 100644 --- a/examples/otlp/opentelemetry-collector-config/config.dev.yaml +++ b/examples/otlp/opentelemetry-collector-config/config.dev.yaml @@ -3,7 +3,7 @@ exporters: debug: - verbosity: debug + verbosity: detailed receivers: otlp: protocols: diff --git a/functional/otlp/otel-config-http.yaml b/functional/otlp/otel-config-http.yaml index 858b3b7fe5..8e5fcb6aee 100644 --- a/functional/otlp/otel-config-http.yaml +++ b/functional/otlp/otel-config-http.yaml @@ -23,7 +23,7 @@ processors: exporters: debug: - verbosity: debug + verbosity: detailed service: pipelines: diff --git a/functional/otlp/otel-config-https.yaml b/functional/otlp/otel-config-https.yaml index f106baf8b6..63ae36f211 100644 --- a/functional/otlp/otel-config-https.yaml +++ b/functional/otlp/otel-config-https.yaml @@ -29,12 +29,12 @@ processors: check_interval: 5s exporters: - logging: - loglevel: debug + debug: + verbosity: detailed service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] - exporters: [logging] + exporters: [debug] diff --git a/functional/otlp/otel-docker-config-http.yaml b/functional/otlp/otel-docker-config-http.yaml index c18f0e54a4..beadb85130 100644 --- a/functional/otlp/otel-docker-config-http.yaml +++ b/functional/otlp/otel-docker-config-http.yaml @@ -21,12 +21,12 @@ processors: check_interval: 5s exporters: - logging: - loglevel: debug + debug: + verbosity: detailed service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] - exporters: [logging] + exporters: [debug] diff --git a/functional/otlp/otel-docker-config-https.yaml b/functional/otlp/otel-docker-config-https.yaml index db8f2b3756..ef15696e70 100644 --- a/functional/otlp/otel-docker-config-https.yaml +++ b/functional/otlp/otel-docker-config-https.yaml @@ -28,12 +28,12 @@ processors: check_interval: 5s exporters: - logging: - loglevel: debug + debug: + verbosity: detailed service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] - exporters: [logging] + exporters: [debug] From d623bc57f6d41aea2b8508886e7f831208876964 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 5 Sep 2024 13:40:26 -0700 Subject: [PATCH 48/71] [EXAMPLE] Clean the tracer initialization in OStream example (#3051) --- examples/logs_simple/main.cc | 20 ++++++++++---------- examples/simple/main.cc | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index 3d7dfb8831..b1304f9a63 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -44,18 +44,18 @@ void InitTracer() auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr sdk_provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider - const std::shared_ptr &api_provider = provider; + const std::shared_ptr &api_provider = sdk_provider; trace_api::Provider::SetTracerProvider(api_provider); } void CleanupTracer() { - std::shared_ptr none; - trace_api::Provider::SetTracerProvider(none); + std::shared_ptr noop; + trace_api::Provider::SetTracerProvider(noop); } void InitLogger() @@ -65,18 +65,18 @@ void InitLogger() std::unique_ptr(new logs_exporter::OStreamLogRecordExporter); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); - std::shared_ptr provider( - opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(processor))); + std::shared_ptr sdk_provider( + logs_sdk::LoggerProviderFactory::Create(std::move(processor))); // Set the global logger provider - const std::shared_ptr &api_provider = provider; + const std::shared_ptr &api_provider = sdk_provider; logs_api::Provider::SetLoggerProvider(api_provider); } void CleanupLogger() { - std::shared_ptr none; - logs_api::Provider::SetLoggerProvider(none); + std::shared_ptr noop; + logs_api::Provider::SetLoggerProvider(noop); } } // namespace diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 245786688c..d8cf4009ad 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -31,18 +31,18 @@ void InitTracer() auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor)); + std::shared_ptr sdk_provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); // Set the global trace provider - const std::shared_ptr &api_provider = provider; + const std::shared_ptr &api_provider = sdk_provider; trace_api::Provider::SetTracerProvider(api_provider); } void CleanupTracer() { - std::shared_ptr none; - trace_api::Provider::SetTracerProvider(none); + std::shared_ptr noop; + trace_api::Provider::SetTracerProvider(noop); } } // namespace From 4eb78a6a04994b48a6d81318539d826801d148c1 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Sun, 8 Sep 2024 00:22:15 -0700 Subject: [PATCH 49/71] [EXPORTER] Fix the format of SpanLink for ETW (#3054) --- .../opentelemetry/exporters/etw/etw_fields.h | 5 ++- .../opentelemetry/exporters/etw/etw_tracer.h | 34 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h index 041929d1c0..ea4354426d 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h @@ -113,6 +113,9 @@ # define ETW_FIELD_SPAN_KIND "Kind" /* Span Kind */ # define ETW_FIELD_SPAN_LINKS "Links" /* Span Links array */ +# define ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "toSpanId" /* Span Links toSpanId */ +# define ETW_FIELD_SPAN_LINKS_TO_TRACE_ID "toTraceId" /* Span Links toTraceId */ + # define ETW_FIELD_PAYLOAD_NAME "Name" /* ETW Payload["Name"] */ /* Span option constants */ @@ -136,7 +139,7 @@ /* Log specific */ # define ETW_FIELD_LOG_BODY "body" /* Log body */ # define ETW_FIELD_LOG_SEVERITY_TEXT "severityText" /* Sev text */ -# define ETW_FIELD_LOG_SEVERITY_NUM "severityNumber" /* Sev num */ +# define ETW_FIELD_LOG_SEVERITY_NUM "severityNumber" /* Sev num */ #endif diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index 9071fd47d4..272558cead 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -212,19 +212,41 @@ class Tracer : public opentelemetry::trace::Tracer, // Add `SpanLinks` attribute if the list is not empty if (links.size()) { - size_t idx = 0; + bool first = true; std::string linksValue; + + // reserve space for all the SpanLinks. + // A single SpanLink will be outptut as: + // [{"toSpanId":"9a43c801557f26b7","toTraceId":"ac6cd70ac4bb168a99cb7651b048d965"}] + // The second and above link output to string are 1 byte less than the first SpanLink. + const size_t kSingleSpanLinkSizeInBytes = 80; + linksValue.reserve(kSingleSpanLinkSizeInBytes + + (links.size() - 1) * (kSingleSpanLinkSizeInBytes - 1)); + linksValue += "["; + links.ForEachKeyValue([&](opentelemetry::trace::SpanContext ctx, const opentelemetry::common::KeyValueIterable &) { - if (!linksValue.empty()) + if (first) + { + first = false; + linksValue += "{\"" ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "\":\""; + } + else { - linksValue += ','; - linksValue += ToLowerBase16(ctx.span_id()); + linksValue += ",{\"" ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "\":\""; } - idx++; + + linksValue += ToLowerBase16(ctx.span_id()); + linksValue += "\",\"" ETW_FIELD_SPAN_LINKS_TO_TRACE_ID "\":\""; + linksValue += ToLowerBase16(ctx.trace_id()); + linksValue += "\"}"; + return true; }); - attributes[ETW_FIELD_SPAN_LINKS] = linksValue; + + linksValue += "]"; + + attributes[ETW_FIELD_SPAN_LINKS] = std::move(linksValue); } } From c37df2318dd2a9fde6f256a9a861f4b281938a45 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Tue, 10 Sep 2024 10:27:48 -0400 Subject: [PATCH 50/71] Implement in-memory metric exporter (#3043) Fixes #1405 --- CHANGELOG.md | 3 + exporters/memory/BUILD | 78 +++++++++++++++- exporters/memory/CMakeLists.txt | 38 ++++++++ .../exporters/memory/in_memory_metric_data.h | 72 ++++++++++++++ .../in_memory_metric_exporter_factory.h | 44 +++++++++ exporters/memory/src/in_memory_metric_data.cc | 54 +++++++++++ .../src/in_memory_metric_exporter_factory.cc | 93 +++++++++++++++++++ .../memory/test/in_memory_metric_data_test.cc | 55 +++++++++++ .../test/in_memory_metric_exporter_test.cc | 60 ++++++++++++ 9 files changed, 496 insertions(+), 1 deletion(-) create mode 100644 exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_data.h create mode 100644 exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h create mode 100644 exporters/memory/src/in_memory_metric_data.cc create mode 100644 exporters/memory/src/in_memory_metric_exporter_factory.cc create mode 100644 exporters/memory/test/in_memory_metric_data_test.cc create mode 100644 exporters/memory/test/in_memory_metric_exporter_test.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index bce84c84df..66d60f3513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ Increment the: * [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` [#2717](https://github.com/open-telemetry/opentelemetry-cpp/pull/2717) +* [EXPORTER] Add in-memory metric exporter + [#3043](https://github.com/open-telemetry/opentelemetry-cpp/pull/3043) + Breaking changes: * [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` diff --git a/exporters/memory/BUILD b/exporters/memory/BUILD index a65066480c..033c85d369 100644 --- a/exporters/memory/BUILD +++ b/exporters/memory/BUILD @@ -4,14 +4,90 @@ package(default_visibility = ["//visibility:public"]) cc_library( - name = "in_memory_span_data", + name = "in_memory_metric_data", + srcs = [ + "src/in_memory_metric_data.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/memory/in_memory_metric_data.h", + ], + strip_include_prefix = "include", + tags = [ + "memory", + "test", + ], + deps = [ + ":in_memory_data", + "//sdk/src/metrics", + ], +) + +cc_test( + name = "in_memory_metric_data_test", + srcs = ["test/in_memory_metric_data_test.cc"], + tags = [ + "memory", + "test", + ], + deps = [ + ":in_memory_metric_data", + "@com_google_googletest//:gtest_main", + ], +) + +cc_library( + name = "in_memory_metric_exporter_factory", + srcs = [ + "src/in_memory_metric_exporter_factory.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h", + ], + strip_include_prefix = "include", + tags = [ + "memory", + "test", + ], + deps = [ + ":in_memory_metric_data", + "//sdk/src/metrics", + ], +) + +cc_test( + name = "in_memory_metric_exporter_test", + srcs = ["test/in_memory_metric_exporter_test.cc"], + tags = [ + "memory", + "test", + ], + deps = [ + ":in_memory_metric_exporter_factory", + "@com_google_googletest//:gtest_main", + ], +) + +cc_library( + name = "in_memory_data", hdrs = [ "include/opentelemetry/exporters/memory/in_memory_data.h", + ], + strip_include_prefix = "include", + tags = ["memory"], + deps = [ + "//sdk:headers", + ], +) + +cc_library( + name = "in_memory_span_data", + hdrs = [ "include/opentelemetry/exporters/memory/in_memory_span_data.h", ], strip_include_prefix = "include", tags = ["memory"], deps = [ + ":in_memory_data", "//api", "//sdk/src/resource", "//sdk/src/trace", diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 3dff044018..0738759a96 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -16,9 +16,26 @@ set_target_version(opentelemetry_exporter_in_memory) target_link_libraries(opentelemetry_exporter_in_memory PUBLIC opentelemetry_trace) +add_library( + opentelemetry_exporter_in_memory_metric + src/in_memory_metric_exporter_factory.cc src/in_memory_metric_data.cc) + +target_include_directories( + opentelemetry_exporter_in_memory_metric + PUBLIC "$" + "$") + +set_target_properties(opentelemetry_exporter_in_memory_metric + PROPERTIES EXPORT_NAME in_memory_metric_exporter) +set_target_version(opentelemetry_exporter_in_memory_metric) + +target_link_libraries(opentelemetry_exporter_in_memory_metric + PUBLIC opentelemetry_metrics) + if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_exporter_in_memory + opentelemetry_exporter_in_memory_metric EXPORT "${PROJECT_NAME}-target" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -35,16 +52,29 @@ if(BUILD_TESTING) add_executable(in_memory_span_data_test test/in_memory_span_data_test.cc) add_executable(in_memory_span_exporter_test test/in_memory_span_exporter_test.cc) + add_executable(in_memory_metric_data_test test/in_memory_metric_data_test.cc) + add_executable(in_memory_metric_exporter_test + test/in_memory_metric_exporter_test.cc) target_link_libraries( in_memory_span_data_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory opentelemetry_resources) + target_link_libraries( + in_memory_metric_data_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory_metric + opentelemetry_resources) + target_link_libraries( in_memory_span_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory opentelemetry_resources) + target_link_libraries( + in_memory_metric_exporter_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory_metric + opentelemetry_resources) + gtest_add_tests( TARGET in_memory_span_data_test TEST_PREFIX exporter. @@ -53,4 +83,12 @@ if(BUILD_TESTING) TARGET in_memory_span_exporter_test TEST_PREFIX exporter. TEST_LIST in_memory_span_exporter_test) + gtest_add_tests( + TARGET in_memory_metric_data_test + TEST_PREFIX exporter. + TEST_LIST in_memory_metric_data_test) + gtest_add_tests( + TARGET in_memory_metric_exporter_test + TEST_PREFIX exporter. + TEST_LIST in_memory_metric_exporter_test) endif() diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_data.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_data.h new file mode 100644 index 0000000000..8d24c586b2 --- /dev/null +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_data.h @@ -0,0 +1,72 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include +#include + +#include "opentelemetry/exporters/memory/in_memory_data.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +struct ResourceMetrics; +} +} // namespace sdk +namespace exporter +{ +namespace memory +{ + +/// The abstract base class for types used to store in-memory data backing an +/// InMemoryMetricExporter. +class InMemoryMetricData +{ +public: + InMemoryMetricData() = default; + virtual ~InMemoryMetricData() = default; + + InMemoryMetricData(const InMemoryMetricData &) = delete; + InMemoryMetricData(InMemoryMetricData &&) = delete; + InMemoryMetricData &operator=(const InMemoryMetricData &) = delete; + InMemoryMetricData &operator=(InMemoryMetricData &&) = delete; + + virtual void Add(std::unique_ptr resource_metrics) = 0; +}; + +/// An implementation of InMemoryMetricData that stores full-fidelity data points in a circular +/// buffer. This allows tests to inspect every aspect of exported data, in exchange for a somewhat +/// cumbersome API. +class CircularBufferInMemoryMetricData final : public InMemoryMetricData, + public InMemoryData +{ +public: + explicit CircularBufferInMemoryMetricData(size_t buffer_size); + void Add(std::unique_ptr resource_metrics) override; +}; + +/// An implementation of InMemoryMetricData that stores only the most recent data point in each time +/// series, and allows convenient lookups of time series. This makes simple tests easier to write. +class SimpleAggregateInMemoryMetricData final : public InMemoryMetricData +{ +public: + using AttributeToPoint = std::map; + + void Add(std::unique_ptr resource_metrics) override; + const AttributeToPoint &Get(const std::string &scope, const std::string &metric); + void Clear(); + +private: + std::map, AttributeToPoint> data_; +}; + +} // namespace memory +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h new file mode 100644 index 0000000000..f6934df727 --- /dev/null +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class PushMetricExporter; +} // namespace metrics +} // namespace sdk +namespace exporter +{ +namespace memory +{ +class InMemoryMetricData; + +/// A factory for InMemoryMetricExporter +class InMemoryMetricExporterFactory +{ +public: + /// Create a InMemoryMetricExporter with a default buffer size and aggregation + /// temporality selector. + /// @param [out] data the InMemoryMetricData the exporter will write to, + /// for the caller to inspect + /// @param [in] buffer_size number of entries to save in the circular buffer + /// @param [in] temporality output temporality as a function of instrument kind + static std::unique_ptr Create( + const std::shared_ptr &data, + const sdk::metrics::AggregationTemporalitySelector &temporality); + + static std::unique_ptr Create( + const std::shared_ptr &data); +}; +} // namespace memory +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/src/in_memory_metric_data.cc b/exporters/memory/src/in_memory_metric_data.cc new file mode 100644 index 0000000000..2a77e0b5a3 --- /dev/null +++ b/exporters/memory/src/in_memory_metric_data.cc @@ -0,0 +1,54 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/memory/in_memory_metric_data.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace memory +{ +using sdk::metrics::ResourceMetrics; + +CircularBufferInMemoryMetricData::CircularBufferInMemoryMetricData(size_t buffer_size) + : InMemoryData(buffer_size) +{} + +void CircularBufferInMemoryMetricData::Add(std::unique_ptr resource_metrics) +{ + InMemoryData::Add(std::move(resource_metrics)); +} + +void SimpleAggregateInMemoryMetricData::Add(std::unique_ptr resource_metrics) +{ + for (const auto &sm : resource_metrics->scope_metric_data_) + { + const auto &scope = sm.scope_->GetName(); + for (const auto &m : sm.metric_data_) + { + const auto &metric = m.instrument_descriptor.name_; + for (const auto &pda : m.point_data_attr_) + { + data_[{scope, metric}].insert({pda.attributes, pda.point_data}); + } + } + } +} + +const SimpleAggregateInMemoryMetricData::AttributeToPoint &SimpleAggregateInMemoryMetricData::Get( + const std::string &scope, + const std::string &metric) +{ + return data_[{scope, metric}]; +} + +void SimpleAggregateInMemoryMetricData::Clear() +{ + data_.clear(); +} + +} // namespace memory +} // namespace exporter +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 new file mode 100644 index 0000000000..f2577c4e9b --- /dev/null +++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc @@ -0,0 +1,93 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h" +#include "opentelemetry/exporters/memory/in_memory_metric_data.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" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace memory +{ + +using opentelemetry::sdk::metrics::PushMetricExporter; +using sdk::common::ExportResult; +using sdk::metrics::AggregationTemporality; +using sdk::metrics::AggregationTemporalitySelector; +using sdk::metrics::InstrumentType; +using sdk::metrics::ResourceMetrics; + +namespace +{ + +/// A Push Metric Exporter which accumulates metrics data in memory and allows it to be inspected. +/// It is not thread-safe. +class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter +{ +public: + /// @param buffer_size a required value that sets the size of the CircularBuffer + /// @param temporality Output temporality as a function of instrument kind. + InMemoryMetricExporter(const std::shared_ptr &data, + const sdk::metrics::AggregationTemporalitySelector &temporality) + : data_(data), temporality_(temporality) + {} + + ~InMemoryMetricExporter() override = default; + + InMemoryMetricExporter(const InMemoryMetricExporter &) = delete; + InMemoryMetricExporter(const InMemoryMetricExporter &&) = delete; + void operator=(const InMemoryMetricExporter &) = delete; + void operator=(const InMemoryMetricExporter &&) = delete; + + ExportResult Export(const ResourceMetrics &data) noexcept override + { + if (is_shutdown_) + { + OTEL_INTERNAL_LOG_ERROR("[In Memory Metric Exporter] Exporting failed, exporter is shutdown"); + return ExportResult::kFailure; + } + data_->Add(std::make_unique(data)); + return ExportResult::kSuccess; + } + + AggregationTemporality GetAggregationTemporality( + InstrumentType instrument_type) const noexcept override + { + return temporality_(instrument_type); + } + + bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept override { return true; } + + bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override + { + is_shutdown_ = true; + return true; + } + +private: + std::shared_ptr data_; + std::atomic is_shutdown_{false}; + sdk::metrics::AggregationTemporalitySelector temporality_; +}; + +} // namespace + +std::unique_ptr InMemoryMetricExporterFactory::Create( + const std::shared_ptr &data) +{ + return Create(data, [](auto) { return AggregationTemporality::kCumulative; }); +} + +std::unique_ptr InMemoryMetricExporterFactory::Create( + const std::shared_ptr &data, + const AggregationTemporalitySelector &temporality) +{ + return std::make_unique(data, temporality); +} + +} // namespace memory +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/memory/test/in_memory_metric_data_test.cc b/exporters/memory/test/in_memory_metric_data_test.cc new file mode 100644 index 0000000000..ffaba2cfb9 --- /dev/null +++ b/exporters/memory/test/in_memory_metric_data_test.cc @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/memory/in_memory_metric_data.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/resource/resource.h" + +#include + +#include + +using opentelemetry::exporter::memory::CircularBufferInMemoryMetricData; +using opentelemetry::exporter::memory::SimpleAggregateInMemoryMetricData; +using opentelemetry::sdk::metrics::MetricData; +using opentelemetry::sdk::metrics::PointDataAttributes; +using opentelemetry::sdk::metrics::ResourceMetrics; +using opentelemetry::sdk::metrics::ScopeMetrics; +using opentelemetry::sdk::metrics::SumPointData; +using opentelemetry::sdk::resource::Resource; + +TEST(InMemoryMetricDataTest, CircularBuffer) +{ + CircularBufferInMemoryMetricData buf(10); + Resource resource = Resource::GetEmpty(); + buf.Add(std::make_unique( + &resource, std::vector{{nullptr, std::vector{}}})); + EXPECT_EQ((*buf.Get().begin())->resource_, &resource); +} + +TEST(InMemoryMetricDataTest, SimpleAggregate) +{ + SimpleAggregateInMemoryMetricData agg; + + Resource resource = Resource::GetEmpty(); + + auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( + "my-scope", "1.0.0", "http://example.com"); + + SumPointData spd; + spd.value_ = 42.0; + PointDataAttributes pda{{{"hello", "world"}}, spd}; + + MetricData md; + md.instrument_descriptor.name_ = "my-metric"; + md.point_data_attr_.push_back(pda); + + agg.Add(std::make_unique( + &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); + + EXPECT_EQ(opentelemetry::nostd::get(saved_point.value_), 42.0); +} diff --git a/exporters/memory/test/in_memory_metric_exporter_test.cc b/exporters/memory/test/in_memory_metric_exporter_test.cc new file mode 100644 index 0000000000..adaa322f71 --- /dev/null +++ b/exporters/memory/test/in_memory_metric_exporter_test.cc @@ -0,0 +1,60 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/memory/in_memory_metric_data.h" +#include "opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/resource/resource.h" + +#include + +using opentelemetry::exporter::memory::CircularBufferInMemoryMetricData; +using opentelemetry::exporter::memory::InMemoryMetricExporterFactory; +using opentelemetry::sdk::common::ExportResult; +using opentelemetry::sdk::metrics::AggregationTemporality; +using opentelemetry::sdk::metrics::InstrumentType; +using opentelemetry::sdk::metrics::PushMetricExporter; +using opentelemetry::sdk::metrics::ResourceMetrics; +using opentelemetry::sdk::metrics::ScopeMetrics; +using opentelemetry::sdk::resource::Resource; + +class InMemoryMetricExporterTest : public ::testing::Test +{ +protected: + InMemoryMetricExporterTest() { exporter_ = InMemoryMetricExporterFactory::Create(data_); } + + std::unique_ptr exporter_; + std::shared_ptr data_ = + std::make_shared(10); + + Resource resource_ = Resource::GetEmpty(); + ResourceMetrics resource_metrics_{&resource_, std::vector{}}; +}; + +TEST_F(InMemoryMetricExporterTest, Export) +{ + EXPECT_EQ(exporter_->Export(resource_metrics_), ExportResult::kSuccess); + + auto data = data_->Get(); + EXPECT_EQ(data.size(), 1); + EXPECT_EQ((*data.begin())->resource_, &resource_); +} + +TEST_F(InMemoryMetricExporterTest, ForceFlush) +{ + EXPECT_TRUE(exporter_->ForceFlush()); +} + +TEST_F(InMemoryMetricExporterTest, Shutdown) +{ + EXPECT_TRUE(exporter_->Shutdown()); + EXPECT_EQ(exporter_->Export(resource_metrics_), ExportResult::kFailure); +} + +TEST_F(InMemoryMetricExporterTest, TemporalitySelector) +{ + EXPECT_EQ(exporter_->GetAggregationTemporality(InstrumentType::kCounter), + AggregationTemporality::kCumulative); +} From c6d394547b012077998b6bd74665145488e85ffe Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 11 Sep 2024 21:05:32 +0200 Subject: [PATCH 51/71] [Code Health] include-what-you-use cleanup, part 4 (#3040) --- .iwyu.imp | 8 +++- .../exporters/memory/in_memory_span_data.h | 8 ++-- .../memory/in_memory_span_exporter.h | 11 ++++- exporters/zipkin/src/zipkin_exporter.cc | 1 + .../ext/http/common/url_parser.h | 5 +- ext/test/http/curl_http_test.cc | 21 +++++---- ext/test/http/url_parser_test.cc | 7 ++- ext/test/w3c_tracecontext_test/main.cc | 25 ++++++++-- .../sdk/common/attribute_utils.h | 8 +++- .../sdk/common/attributemap_hash.h | 7 +++ .../sdk/common/circular_buffer.h | 3 ++ .../sdk/common/circular_buffer_range.h | 3 +- .../sdk/metrics/observer_result.h | 2 + .../sdk/metrics/state/attributes_hashmap.h | 13 +++-- .../sdk/metrics/state/multi_metric_storage.h | 16 ++----- .../sdk/metrics/sync_instruments.h | 1 - .../sdk/metrics/view/attributes_processor.h | 4 +- .../sdk/metrics/view/view_registry.h | 6 ++- .../sdk/trace/simple_processor.h | 3 ++ .../opentelemetry/sdk/trace/span_data.h | 8 +++- sdk/include/opentelemetry/sdk/trace/tracer.h | 2 - .../opentelemetry/sdk/trace/tracer_provider.h | 1 - .../metrics/aggregation/sum_aggregation.cc | 1 - .../periodic_exporting_metric_reader.cc | 2 - sdk/src/metrics/meter_context.cc | 1 - sdk/src/trace/samplers/parent_factory.cc | 3 +- sdk/test/common/attribute_utils_test.cc | 10 ++-- .../common/attributemap_hash_benchmark.cc | 2 + sdk/test/common/circular_buffer_benchmark.cc | 10 +++- sdk/test/common/circular_buffer_range_test.cc | 6 +-- sdk/test/common/circular_buffer_test.cc | 16 +++++-- sdk/test/common/env_var_test.cc | 7 ++- .../fast_random_number_generator_test.cc | 8 ++-- sdk/test/common/global_log_handle_test.cc | 7 +-- sdk/test/common/random_benchmark.cc | 6 +-- sdk/test/common/random_fork_test.cc | 4 +- sdk/test/common/random_test.cc | 8 ++-- .../instrumentationscope_test.cc | 15 ++++-- .../logs/batch_log_record_processor_test.cc | 24 ++++++++-- sdk/test/logs/log_record_test.cc | 22 +++++++-- sdk/test/logs/logger_provider_sdk_test.cc | 24 ++++++++-- sdk/test/logs/logger_sdk_test.cc | 24 ++++++++-- .../logs/simple_log_record_processor_test.cc | 24 +++++++--- sdk/test/metrics/aggregation_test.cc | 10 ++-- sdk/test/metrics/async_instruments_test.cc | 13 ++++- sdk/test/metrics/async_metric_storage_test.cc | 39 ++++++++------- .../metrics/attributes_hashmap_benchmark.cc | 17 ++++--- sdk/test/metrics/attributes_hashmap_test.cc | 20 ++++++-- .../metrics/attributes_processor_benchmark.cc | 5 ++ sdk/test/metrics/attributes_processor_test.cc | 11 ++++- ...exponential_histogram_indexer_benchmark.cc | 5 +- ...ase2_exponential_histogram_indexer_test.cc | 6 ++- sdk/test/metrics/cardinality_limit_test.cc | 31 ++++++++++-- .../metrics/circular_buffer_counter_test.cc | 5 +- sdk/test/metrics/common.cc | 4 +- sdk/test/metrics/common.h | 9 ++-- .../histogram_aggregation_benchmark.cc | 21 +++++++-- .../metrics/histogram_aggregation_test.cc | 21 +++++++-- sdk/test/metrics/histogram_test.cc | 22 +++++++-- .../instrument_metadata_validator_test.cc | 6 ++- sdk/test/metrics/measurements_benchmark.cc | 29 +++++++++--- sdk/test/metrics/meter_provider_sdk_test.cc | 10 +++- sdk/test/metrics/meter_test.cc | 23 +++++++-- sdk/test/metrics/metric_reader_test.cc | 10 +++- sdk/test/metrics/multi_metric_storage_test.cc | 15 +++--- sdk/test/metrics/observable_registry_test.cc | 5 +- sdk/test/metrics/observer_result_test.cc | 12 ++++- .../periodic_exporting_metric_reader_test.cc | 19 ++++++-- sdk/test/metrics/sum_aggregation_benchmark.cc | 24 +++++++--- sdk/test/metrics/sum_aggregation_test.cc | 26 ++++++++-- sdk/test/metrics/sync_instruments_test.cc | 19 +++++--- .../sync_metric_storage_counter_test.cc | 28 +++++++---- .../sync_metric_storage_histogram_test.cc | 29 ++++++++---- ...ync_metric_storage_up_down_counter_test.cc | 29 ++++++++---- sdk/test/metrics/view_registry_test.cc | 15 ++++-- sdk/test/resource/resource_test.cc | 18 ++++--- sdk/test/trace/always_off_sampler_test.cc | 12 +++++ sdk/test/trace/always_on_sampler_test.cc | 18 +++++-- sdk/test/trace/batch_span_processor_test.cc | 28 ++++++----- sdk/test/trace/parent_sampler_test.cc | 18 ++++++- sdk/test/trace/sampler_benchmark.cc | 24 ++++++++-- sdk/test/trace/simple_processor_test.cc | 16 +++++-- sdk/test/trace/span_data_test.cc | 33 +++++++++---- sdk/test/trace/trace_id_ratio_sampler_test.cc | 20 ++++++-- sdk/test/trace/tracer_provider_test.cc | 23 ++++++--- sdk/test/trace/tracer_test.cc | 47 +++++++++++++++++-- .../http/client/http_client_test_factory.h | 4 ++ .../http/client/nosend/http_client_nosend.h | 20 ++++---- .../http/client/nosend/http_client_nosend.cc | 11 +++++ 89 files changed, 912 insertions(+), 305 deletions(-) diff --git a/.iwyu.imp b/.iwyu.imp index 7ebbeae511..6529a92458 100644 --- a/.iwyu.imp +++ b/.iwyu.imp @@ -7,10 +7,16 @@ # Work around for C++ STL { "include": ["", "private", "", "public"] }, - # Local opentelemetry-cpp + # Local opentelemetry-cpp style + # We prefer to include for simplicity { "include": ["", "private", "", "public"] }, { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, { "include": ["", "private", "", "public"] }, + + # We prefer to include for simplicity + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, ] diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_data.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_data.h index 874b475690..6eaae0663c 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_data.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_data.h @@ -3,11 +3,13 @@ #pragma once +#include +#include +#include + #include "opentelemetry/exporters/memory/in_memory_data.h" -#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/span_data.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h index 0c2a14a673..6be83113ce 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h @@ -3,13 +3,20 @@ #pragma once +#include #include -#include +#include +#include +#include +#include #include "opentelemetry/exporters/memory/in_memory_span_data.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/sdk_config.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index 4c5723c674..5d5dd728a6 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include "nlohmann/json.hpp" diff --git a/ext/include/opentelemetry/ext/http/common/url_parser.h b/ext/include/opentelemetry/ext/http/common/url_parser.h index 5e18d85bb6..386d4fcd2f 100644 --- a/ext/include/opentelemetry/ext/http/common/url_parser.h +++ b/ext/include/opentelemetry/ext/http/common/url_parser.h @@ -3,11 +3,12 @@ #pragma once +#include #include #include -#include -#include "opentelemetry/nostd/string_view.h" + #include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace ext { diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index d5351d2314..137c9b7f9b 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -1,23 +1,28 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/ext//http/client/curl/http_client_curl.h" -#include "opentelemetry/ext/http/client/http_client_factory.h" -#include "opentelemetry/ext/http/server/http_server.h" - -#include +#include +#include #include #include #include #include +#include #include -#include +#include +#include #include #include -#define HTTP_PORT 19000 +#include "opentelemetry/ext//http/client/curl/http_client_curl.h" +#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/ext/http/server/http_server.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" -#include +#define HTTP_PORT 19000 namespace curl = opentelemetry::ext::http::client::curl; namespace http_client = opentelemetry::ext::http::client; diff --git a/ext/test/http/url_parser_test.cc b/ext/test/http/url_parser_test.cc index 7b28d763e6..79a5e60a60 100644 --- a/ext/test/http/url_parser_test.cc +++ b/ext/test/http/url_parser_test.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/ext/http/common/url_parser.h" - #include +#include +#include +#include + +#include "opentelemetry/ext/http/common/url_parser.h" namespace http_common = opentelemetry::ext::http::common; diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 4e9fb36796..fed07a2398 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -1,19 +1,38 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/context/runtime_context.h" #include "opentelemetry/exporters/ostream/span_exporter.h" #include "opentelemetry/ext/http/client/curl/http_client_curl.h" +#include "opentelemetry/ext/http/client/curl/http_operation_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/server/http_server.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/trace/propagation/http_trace_context.h" #include "opentelemetry/trace/provider.h" #include "opentelemetry/trace/scope.h" - -#include -#include "nlohmann/json.hpp" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" namespace trace_api = opentelemetry::trace; namespace http_client = opentelemetry::ext::http::client; diff --git a/sdk/include/opentelemetry/sdk/common/attribute_utils.h b/sdk/include/opentelemetry/sdk/common/attribute_utils.h index e21649b695..86b507a66b 100644 --- a/sdk/include/opentelemetry/sdk/common/attribute_utils.h +++ b/sdk/include/opentelemetry/sdk/common/attribute_utils.h @@ -3,13 +3,19 @@ #pragma once +#include +#include #include #include #include +#include #include #include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h index e09b03d08b..39df29b278 100644 --- a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h +++ b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h @@ -3,8 +3,15 @@ #pragma once +#include #include +#include +#include +#include +#include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/variant.h" diff --git a/sdk/include/opentelemetry/sdk/common/circular_buffer.h b/sdk/include/opentelemetry/sdk/common/circular_buffer.h index 6541612158..a35498ecea 100644 --- a/sdk/include/opentelemetry/sdk/common/circular_buffer.h +++ b/sdk/include/opentelemetry/sdk/common/circular_buffer.h @@ -5,9 +5,12 @@ #include #include +#include #include +#include #include +#include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/atomic_unique_ptr.h" #include "opentelemetry/sdk/common/circular_buffer_range.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h b/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h index e9b89f9d02..5e16c3d410 100644 --- a/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h +++ b/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h @@ -3,8 +3,9 @@ #pragma once +#include #include -#include +#include #include "opentelemetry/nostd/span.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/observer_result.h b/sdk/include/opentelemetry/sdk/metrics/observer_result.h index 4ed3cd168d..cc60cf5f64 100644 --- a/sdk/include/opentelemetry/sdk/metrics/observer_result.h +++ b/sdk/include/opentelemetry/sdk/metrics/observer_result.h @@ -5,8 +5,10 @@ #include +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h index a509080318..ddf2a8b206 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h @@ -3,18 +3,21 @@ #pragma once +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/attributemap_hash.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" -#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/version.h" -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h index 6202b0c7fb..2a77b2f856 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h @@ -3,26 +3,20 @@ #pragma once +#include #include #include #include +#include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/common/timestamp.h" -#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace common -{ -class KeyValueIterable; -} // namespace common - -namespace context -{ -class Context; -} // namespace context - namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 1d5f8dbc55..039a37e748 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -12,7 +12,6 @@ #include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" -#include "opentelemetry/sdk_config.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index a71abb7a99..5d53959e1b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -5,9 +5,11 @@ #include #include +#include + +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index 40343c28de..fd1e4bee0c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -3,14 +3,18 @@ #pragma once +#include #include -#include +#include +#include #include #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/view/instrument_selector.h" #include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/predicate.h" #include "opentelemetry/sdk/metrics/view/view.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index dee8e80bb8..ce6d378b79 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -7,12 +7,15 @@ #include #include #include +#include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 8e301c1a01..2bd8b2112b 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -11,14 +11,18 @@ #include #include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/common/macros.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/recordable.h" -#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index fb8342c1d5..f738203b4f 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -4,12 +4,10 @@ #pragma once #include -#include #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/id_generator.h" diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 13a65a2d87..44d5840558 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index ce0d4c5de5..cd518e5460 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/variant.h" diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 42fd6003ae..682badf3a4 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -9,11 +9,9 @@ #include #include #include -#include #include #include -#include "opentelemetry/common/macros.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index 42efce76fb..15e689706a 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/sdk/src/trace/samplers/parent_factory.cc b/sdk/src/trace/samplers/parent_factory.cc index 63a7eff1c4..25a2e94f65 100644 --- a/sdk/src/trace/samplers/parent_factory.cc +++ b/sdk/src/trace/samplers/parent_factory.cc @@ -1,8 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include +#include +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/parent.h" #include "opentelemetry/sdk/trace/samplers/parent_factory.h" #include "opentelemetry/version.h" diff --git a/sdk/test/common/attribute_utils_test.cc b/sdk/test/common/attribute_utils_test.cc index b7ef17244f..9b1f6bd56e 100644 --- a/sdk/test/common/attribute_utils_test.cc +++ b/sdk/test/common/attribute_utils_test.cc @@ -1,13 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/common/attribute_utils.h" - #include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" TEST(AttributeMapTest, DefaultConstruction) { - opentelemetry::sdk::common::AttributeMap attribute_map; EXPECT_EQ(attribute_map.GetAttributes().size(), 0); } diff --git a/sdk/test/common/attributemap_hash_benchmark.cc b/sdk/test/common/attributemap_hash_benchmark.cc index 811ecb23dd..e0641fb961 100644 --- a/sdk/test/common/attributemap_hash_benchmark.cc +++ b/sdk/test/common/attributemap_hash_benchmark.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include + +#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/attributemap_hash.h" using namespace opentelemetry::sdk::common; diff --git a/sdk/test/common/circular_buffer_benchmark.cc b/sdk/test/common/circular_buffer_benchmark.cc index 1f2b9b42cf..7ffc452135 100644 --- a/sdk/test/common/circular_buffer_benchmark.cc +++ b/sdk/test/common/circular_buffer_benchmark.cc @@ -1,18 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "benchmark/benchmark.h" - +#include #include #include +#include +#include #include #include #include #include #include +#include "benchmark/benchmark.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" #include "opentelemetry/sdk/common/circular_buffer.h" +#include "opentelemetry/sdk/common/circular_buffer_range.h" #include "test/common/baseline_circular_buffer.h" + using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; diff --git a/sdk/test/common/circular_buffer_range_test.cc b/sdk/test/common/circular_buffer_range_test.cc index 5852704687..ed2f028978 100644 --- a/sdk/test/common/circular_buffer_range_test.cc +++ b/sdk/test/common/circular_buffer_range_test.cc @@ -1,11 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/common/circular_buffer_range.h" +#include -#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/circular_buffer_range.h" -#include using opentelemetry::sdk::common::CircularBufferRange; TEST(CircularBufferRangeTest, ForEach) diff --git a/sdk/test/common/circular_buffer_test.cc b/sdk/test/common/circular_buffer_test.cc index a20c3e42aa..8a3292ca60 100644 --- a/sdk/test/common/circular_buffer_test.cc +++ b/sdk/test/common/circular_buffer_test.cc @@ -1,14 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/common/circular_buffer.h" - +#include +#include #include +#include #include +#include +#include +#include +#include #include #include +#include + +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include "opentelemetry/sdk/common/circular_buffer.h" +#include "opentelemetry/sdk/common/circular_buffer_range.h" -#include using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; diff --git a/sdk/test/common/env_var_test.cc b/sdk/test/common/env_var_test.cc index 23d3802361..8f64dc1f10 100644 --- a/sdk/test/common/env_var_test.cc +++ b/sdk/test/common/env_var_test.cc @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/common/env_variables.h" - #include +#include +#include +#include + +#include "opentelemetry/sdk/common/env_variables.h" #if defined(_MSC_VER) using opentelemetry::sdk::common::setenv; diff --git a/sdk/test/common/fast_random_number_generator_test.cc b/sdk/test/common/fast_random_number_generator_test.cc index e9209fdb6b..1f87ea13d7 100644 --- a/sdk/test/common/fast_random_number_generator_test.cc +++ b/sdk/test/common/fast_random_number_generator_test.cc @@ -1,11 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "src/common/random.h" - +#include +#include #include +#include +#include -#include +#include "src/common/fast_random_number_generator.h" using opentelemetry::sdk::common::FastRandomNumberGenerator; diff --git a/sdk/test/common/global_log_handle_test.cc b/sdk/test/common/global_log_handle_test.cc index 28b111cc71..3c3fc3d7f3 100644 --- a/sdk/test/common/global_log_handle_test.cc +++ b/sdk/test/common/global_log_handle_test.cc @@ -1,12 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/common/global_log_handler.h" - #include - #include +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" + class CustomLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler { public: diff --git a/sdk/test/common/random_benchmark.cc b/sdk/test/common/random_benchmark.cc index df2ebf95ec..46dadbe260 100644 --- a/sdk/test/common/random_benchmark.cc +++ b/sdk/test/common/random_benchmark.cc @@ -1,12 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "src/common/random.h" - -#include +#include #include -#include +#include "src/common/random.h" namespace { diff --git a/sdk/test/common/random_fork_test.cc b/sdk/test/common/random_fork_test.cc index 2db8b9fcdf..15f7a43cf2 100644 --- a/sdk/test/common/random_fork_test.cc +++ b/sdk/test/common/random_fork_test.cc @@ -7,13 +7,13 @@ // See https://github.com/opentracing-contrib/nginx-opentracing/issues/52 # include "src/common/random.h" +# include # include -# include # include # include -# include # include # include + using opentelemetry::sdk::common::Random; static uint64_t *child_id; diff --git a/sdk/test/common/random_test.cc b/sdk/test/common/random_test.cc index e22e0508fc..85292babe4 100644 --- a/sdk/test/common/random_test.cc +++ b/sdk/test/common/random_test.cc @@ -1,15 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "src/common/random.h" - +#include #include #include +#include +#include #include #include #include -#include +#include "src/common/random.h" + using opentelemetry::sdk::common::Random; TEST(RandomTest, GenerateRandom64) diff --git a/sdk/test/instrumentationscope/instrumentationscope_test.cc b/sdk/test/instrumentationscope/instrumentationscope_test.cc index 2f376d5d6b..da00ec8e93 100644 --- a/sdk/test/instrumentationscope/instrumentationscope_test.cc +++ b/sdk/test/instrumentationscope/instrumentationscope_test.cc @@ -1,15 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" - #include +#include +#include #include #include +#include #include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" + using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; diff --git a/sdk/test/logs/batch_log_record_processor_test.cc b/sdk/test/logs/batch_log_record_processor_test.cc index 3bdd849938..036146f4e6 100644 --- a/sdk/test/logs/batch_log_record_processor_test.cc +++ b/sdk/test/logs/batch_log_record_processor_test.cc @@ -1,15 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/batch_log_record_processor.h" -#include "opentelemetry/sdk/logs/exporter.h" -#include "opentelemetry/sdk/logs/recordable.h" - #include +#include +#include #include +#include #include +#include #include #include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index bd9e462012..99ba9f296d 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -1,21 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include -#include +#include +#include #include -#include +#include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/event_id.h" +#include "opentelemetry/logs/log_record.h" #include "opentelemetry/logs/logger.h" -#include "opentelemetry/logs/provider.h" +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/logs/read_write_log_record.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" -#include - using opentelemetry::sdk::logs::ReadWriteLogRecord; namespace trace_api = opentelemetry::trace; namespace logs_api = opentelemetry::logs; diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index ecb9ea6f9c..a5a3d3a68a 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -1,20 +1,38 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include +#include +#include +#include +#include #include +#include +#include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/logs/provider.h" +#include "opentelemetry/logs/severity.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/event_logger_provider.h" #include "opentelemetry/sdk/logs/event_logger_provider_factory.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/logger.h" +#include "opentelemetry/sdk/logs/logger_context.h" #include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/logs/simple_log_record_processor.h" - -#include +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" using namespace opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 9e63672d3c..4af0fb3745 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -1,26 +1,44 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include #include #include #include - +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/event_logger.h" +#include "opentelemetry/logs/event_logger_provider.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger.h" #include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/event_logger.h" #include "opentelemetry/sdk/logs/event_logger_provider.h" #include "opentelemetry/sdk/logs/logger.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/processor.h" #include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/tracer.h" -#include - using namespace opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; namespace nostd = opentelemetry::nostd; diff --git a/sdk/test/logs/simple_log_record_processor_test.cc b/sdk/test/logs/simple_log_record_processor_test.cc index 30e5771394..b8a9f03e0c 100644 --- a/sdk/test/logs/simple_log_record_processor_test.cc +++ b/sdk/test/logs/simple_log_record_processor_test.cc @@ -1,16 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/logs/simple_log_record_processor.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/sdk/logs/exporter.h" -#include "opentelemetry/sdk/logs/recordable.h" - #include - +#include +#include #include -#include +#include +#include #include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index d52cc9e732..d56f33545a 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -2,13 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include +#include + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" #include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" - -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" using namespace opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index 01a421e046..cda08a1549 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -1,12 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +#include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/sdk/metrics/async_instruments.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" #include "opentelemetry/sdk/metrics/state/observable_registry.h" -#include - using namespace opentelemetry; using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index dcbe105418..912310415a 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -1,30 +1,37 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" -#include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/sdk/metrics/async_instruments.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/async_metric_storage.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/filter_type.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #endif -#include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/meter_context.h" -#include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/sdk/metrics/observer_result.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" -#include "opentelemetry/sdk/metrics/state/async_metric_storage.h" -#include "opentelemetry/sdk/metrics/state/metric_collector.h" -#include "opentelemetry/sdk/metrics/state/observable_registry.h" - -#include -#include -#include -#include - using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::resource; diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index 5dc02ca5be..ed080d911d 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -2,17 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include "opentelemetry/sdk/common/attributemap_hash.h" -#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" -#include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" - +#include +#include +#include #include +#include #include #include #include +#include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" + using namespace opentelemetry::sdk::metrics; constexpr size_t MAX_THREADS = 500; namespace diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index 7d77e6166a..c7f0f01ee5 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -1,12 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include -#include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" -#include "opentelemetry/sdk/metrics/instruments.h" - +#include +#include #include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" using namespace opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; diff --git a/sdk/test/metrics/attributes_processor_benchmark.cc b/sdk/test/metrics/attributes_processor_benchmark.cc index 28f1984b40..708549406b 100644 --- a/sdk/test/metrics/attributes_processor_benchmark.cc +++ b/sdk/test/metrics/attributes_processor_benchmark.cc @@ -3,7 +3,12 @@ #include #include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" + using namespace opentelemetry::sdk::metrics; namespace { diff --git a/sdk/test/metrics/attributes_processor_test.cc b/sdk/test/metrics/attributes_processor_test.cc index 62c0879ca9..5299af1358 100644 --- a/sdk/test/metrics/attributes_processor_test.cc +++ b/sdk/test/metrics/attributes_processor_test.cc @@ -1,8 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; diff --git a/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc b/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc index 9f1d0d864d..40ea14d575 100644 --- a/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc +++ b/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc @@ -1,12 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" - #include +#include #include #include +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" + using namespace opentelemetry::sdk::metrics; namespace { diff --git a/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc b/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc index 85f6fe72e9..716985e7cf 100644 --- a/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc +++ b/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc @@ -1,9 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" - #include +#include +#include + +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index cf94112f1a..926062709b 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -1,18 +1,39 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" + +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attributemap_hash.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" -#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" -#endif +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" -#include -#include +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" +#endif using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; diff --git a/sdk/test/metrics/circular_buffer_counter_test.cc b/sdk/test/metrics/circular_buffer_counter_test.cc index a8218d9e6b..38b6000d3e 100644 --- a/sdk/test/metrics/circular_buffer_counter_test.cc +++ b/sdk/test/metrics/circular_buffer_counter_test.cc @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/data/circular_buffer.h" - #include +#include #include +#include "opentelemetry/sdk/metrics/data/circular_buffer.h" + using namespace opentelemetry::sdk::metrics; class AdaptingIntegerArrayTest : public testing::TestWithParam diff --git a/sdk/test/metrics/common.cc b/sdk/test/metrics/common.cc index 87343f6186..8aff2f91fa 100644 --- a/sdk/test/metrics/common.cc +++ b/sdk/test/metrics/common.cc @@ -2,8 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #include "common.h" +#include + +#include "opentelemetry/sdk/metrics/data/point_data.h" -using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::sdk::common; diff --git a/sdk/test/metrics/common.h b/sdk/test/metrics/common.h index b3b73e15d6..ff2060e285 100644 --- a/sdk/test/metrics/common.h +++ b/sdk/test/metrics/common.h @@ -3,13 +3,16 @@ #pragma once -#include "opentelemetry/sdk/metrics/data/point_data.h" +#include +#include + +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" -#include - class MockMetricExporter : public opentelemetry::sdk::metrics::PushMetricExporter { public: diff --git a/sdk/test/metrics/histogram_aggregation_benchmark.cc b/sdk/test/metrics/histogram_aggregation_benchmark.cc index f85a4f4706..80ebb59069 100644 --- a/sdk/test/metrics/histogram_aggregation_benchmark.cc +++ b/sdk/test/metrics/histogram_aggregation_benchmark.cc @@ -1,18 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" -#include -#include - using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/histogram_aggregation_test.cc b/sdk/test/metrics/histogram_aggregation_test.cc index 6fd13c902c..264e223ccc 100644 --- a/sdk/test/metrics/histogram_aggregation_test.cc +++ b/sdk/test/metrics/histogram_aggregation_test.cc @@ -1,17 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/macros.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" #if OPENTELEMETRY_HAVE_WORKING_REGEX diff --git a/sdk/test/metrics/histogram_test.cc b/sdk/test/metrics/histogram_test.cc index 57f7790ba1..8e0f3c1c1c 100644 --- a/sdk/test/metrics/histogram_test.cc +++ b/sdk/test/metrics/histogram_test.cc @@ -1,17 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include #include "common.h" #include "opentelemetry/common/macros.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" #if OPENTELEMETRY_HAVE_WORKING_REGEX # include diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 28c6d4a4fd..1ecdc17025 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -1,8 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/instrument_metadata_validator.h" #include +#include +#include +#include + +#include "opentelemetry/sdk/metrics/instrument_metadata_validator.h" static std::string CreateVeryLargeString(size_t multiple) { diff --git a/sdk/test/metrics/measurements_benchmark.cc b/sdk/test/metrics/measurements_benchmark.cc index 06ac75a65a..15d96130b5 100644 --- a/sdk/test/metrics/measurements_benchmark.cc +++ b/sdk/test/metrics/measurements_benchmark.cc @@ -1,15 +1,30 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include -#include -#include using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index 60ac7ab46f..36cb28c228 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -1,16 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include #include "common.h" -#include -#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/sdk/metrics/view/instrument_selector.h" #include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index cd66737465..196be7b105 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -1,16 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/meter_provider.h" +#include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" -#include - using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/metric_reader_test.cc b/sdk/test/metrics/metric_reader_test.cc index 061d505a1d..fb0c5a9cf0 100644 --- a/sdk/test/metrics/metric_reader_test.cc +++ b/sdk/test/metrics/metric_reader_test.cc @@ -1,12 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include #include "common.h" -#include +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; diff --git a/sdk/test/metrics/multi_metric_storage_test.cc b/sdk/test/metrics/multi_metric_storage_test.cc index 97c5a438ee..e2449db9d5 100644 --- a/sdk/test/metrics/multi_metric_storage_test.cc +++ b/sdk/test/metrics/multi_metric_storage_test.cc @@ -1,18 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" -#include "opentelemetry/common/key_value_iterable_view.h" +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/state/metric_storage.h" +#include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" #endif // ENABLE_METRICS_EXEMPLAR_PREVIEW -#include "opentelemetry/sdk/metrics/instruments.h" - -#include - using namespace opentelemetry; using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/observable_registry_test.cc b/sdk/test/metrics/observable_registry_test.cc index 6b6efb755a..23957b8275 100644 --- a/sdk/test/metrics/observable_registry_test.cc +++ b/sdk/test/metrics/observable_registry_test.cc @@ -1,11 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/state/observable_registry.h" -#include "opentelemetry/metrics/observer_result.h" - #include +#include "opentelemetry/sdk/metrics/state/observable_registry.h" + using namespace opentelemetry::sdk::metrics; #if 0 diff --git a/sdk/test/metrics/observer_result_test.cc b/sdk/test/metrics/observer_result_test.cc index eea56738b9..73b7b86ec5 100644 --- a/sdk/test/metrics/observer_result_test.cc +++ b/sdk/test/metrics/observer_result_test.cc @@ -1,11 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/observer_result.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" -#include - using namespace opentelemetry::sdk::metrics; TEST(ObserverResult, BasicTests) { diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index 2eec5e8c61..50fe7f20d8 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -1,15 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" -#include "opentelemetry/sdk/metrics/export/metric_producer.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" - #include - +#include +#include #include #include +#include #include +#include +#include + +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; diff --git a/sdk/test/metrics/sum_aggregation_benchmark.cc b/sdk/test/metrics/sum_aggregation_benchmark.cc index 728b3542a1..b2e44b15e5 100644 --- a/sdk/test/metrics/sum_aggregation_benchmark.cc +++ b/sdk/test/metrics/sum_aggregation_benchmark.cc @@ -1,19 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" -#include -#include -#include - using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index 33a111974e..73caebbe7e 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -1,17 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/macros.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/sync_instruments.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/data/point_data.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" - -#include +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" #if OPENTELEMETRY_HAVE_WORKING_REGEX diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 723d29f20e..fb59e1d033 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -1,15 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/sync_instruments.h" +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -#include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" - -#include -#include -#include +#include "opentelemetry/sdk/metrics/sync_instruments.h" using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; diff --git a/sdk/test/metrics/sync_metric_storage_counter_test.cc b/sdk/test/metrics/sync_metric_storage_counter_test.cc index 2593b69719..c67b9d499a 100644 --- a/sdk/test/metrics/sync_metric_storage_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_counter_test.cc @@ -1,25 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" -#include +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #if ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/filter_type.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #endif -#include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" -#include "opentelemetry/sdk/metrics/view/attributes_processor.h" - -#include -#include - using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; using M = std::map; diff --git a/sdk/test/metrics/sync_metric_storage_histogram_test.cc b/sdk/test/metrics/sync_metric_storage_histogram_test.cc index 71a16b85c6..34145743d9 100644 --- a/sdk/test/metrics/sync_metric_storage_histogram_test.cc +++ b/sdk/test/metrics/sync_metric_storage_histogram_test.cc @@ -1,24 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" +#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/filter_type.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #endif -#include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" -#include "opentelemetry/sdk/metrics/view/attributes_processor.h" - -#include -#include -#include - using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; using M = std::map; diff --git a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc index 88ae56eb3f..4732e5b9f2 100644 --- a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc @@ -1,22 +1,33 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" +#include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/shared_ptr.h" - -#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" -#endif - +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" -#include -#include -#include +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/filter_type.h" +#endif using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; diff --git a/sdk/test/metrics/view_registry_test.cc b/sdk/test/metrics/view_registry_test.cc index fb188e7124..0135227e16 100644 --- a/sdk/test/metrics/view_registry_test.cc +++ b/sdk/test/metrics/view_registry_test.cc @@ -1,12 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include +#include +#include +#include + +#include "opentelemetry/common/macros.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/view/predicate.h" - -#include +#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" #if OPENTELEMETRY_HAVE_WORKING_REGEX # include diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 419264862c..c15087e9b7 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -1,17 +1,21 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/common/attribute_utils.h" -#include "opentelemetry/sdk/resource/resource_detector.h" -#include "opentelemetry/sdk/resource/semantic_conventions.h" -#include "opentelemetry/sdk/version/version.h" - +#include +#include #include #include #include +#include +#include -#include +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/resource/resource_detector.h" +#include "opentelemetry/sdk/resource/semantic_conventions.h" +#include "opentelemetry/sdk/version/version.h" #if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" diff --git a/sdk/test/trace/always_off_sampler_test.cc b/sdk/test/trace/always_off_sampler_test.cc index 1c32bd5a8f..5680e22c75 100644 --- a/sdk/test/trace/always_off_sampler_test.cc +++ b/sdk/test/trace/always_off_sampler_test.cc @@ -2,8 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_off.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" using opentelemetry::sdk::trace::AlwaysOffSampler; using opentelemetry::sdk::trace::Decision; diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index c483f9b8be..04b7e60a2b 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -1,12 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" - -#include -#include +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" using namespace opentelemetry::sdk::trace; using namespace opentelemetry::nostd; diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index 9bb09d6e55..293747350a 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -1,22 +1,28 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/batch_span_processor.h" -#include "opentelemetry/sdk/common/exporter_utils.h" -#include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk/trace/batch_span_processor_options.h" -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/sdk/trace/tracer.h" - #include - #include +#include #include -#include -#include +#include +#include #include #include +#include + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/test/trace/parent_sampler_test.cc b/sdk/test/trace/parent_sampler_test.cc index 7d2ef7f107..a6ed8ff7f8 100644 --- a/sdk/test/trace/parent_sampler_test.cc +++ b/sdk/test/trace/parent_sampler_test.cc @@ -2,11 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_off.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/samplers/parent.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" using opentelemetry::sdk::trace::AlwaysOffSampler; using opentelemetry::sdk::trace::AlwaysOnSampler; diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index ec188b84a1..529143b53e 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -1,20 +1,34 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/exporters/memory/in_memory_span_exporter.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_off.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/samplers/parent.h" #include "opentelemetry/sdk/trace/samplers/trace_id_ratio.h" #include "opentelemetry/sdk/trace/simple_processor.h" -#include "opentelemetry/sdk/trace/span_data.h" #include "opentelemetry/sdk/trace/tracer.h" - -#include - -#include +#include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_context_kv_iterable_view.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" using namespace opentelemetry::sdk::trace; using opentelemetry::exporter::memory::InMemorySpanExporter; diff --git a/sdk/test/trace/simple_processor_test.cc b/sdk/test/trace/simple_processor_test.cc index 7653bb2cfc..92fdf71d58 100644 --- a/sdk/test/trace/simple_processor_test.cc +++ b/sdk/test/trace/simple_processor_test.cc @@ -1,13 +1,23 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/simple_processor.h" +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/memory/in_memory_span_data.h" #include "opentelemetry/exporters/memory/in_memory_span_exporter.h" #include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/span_data.h" - -#include +#include "opentelemetry/trace/span_context.h" using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::common; diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 6dfc09bd12..054af65330 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -1,18 +1,32 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/span_data.h" +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/variant.h" -#include "opentelemetry/trace/span.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" - -#include +#include "opentelemetry/trace/trace_state.h" using opentelemetry::sdk::trace::SpanData; namespace trace_api = opentelemetry::trace; namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; TEST(SpanData, DefaultValues) { @@ -70,7 +84,7 @@ TEST(SpanData, Set) ASSERT_EQ(data.GetDescription(), "description"); ASSERT_EQ(data.GetStartTime().time_since_epoch(), now.time_since_epoch()); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(1000000)); - ASSERT_EQ(nostd::get(data.GetAttributes().at("attr1")), 314159); + ASSERT_EQ(opentelemetry::nostd::get(data.GetAttributes().at("attr1")), 314159); ASSERT_EQ(data.GetEvents().at(0).GetName(), "event1"); ASSERT_EQ(data.GetEvents().at(0).GetTimestamp(), now); } @@ -89,7 +103,9 @@ TEST(SpanData, EventAttributes) for (int i = 0; i < kNumAttributes; i++) { - EXPECT_EQ(nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), values[i]); + EXPECT_EQ( + opentelemetry::nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), + values[i]); } } @@ -130,6 +146,7 @@ TEST(SpanData, Links) EXPECT_EQ(data.GetLinks().at(0).GetSpanContext(), span_context); for (int i = 0; i < kNumAttributes; i++) { - EXPECT_EQ(nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), values[i]); + EXPECT_EQ(opentelemetry::nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), + values[i]); } } diff --git a/sdk/test/trace/trace_id_ratio_sampler_test.cc b/sdk/test/trace/trace_id_ratio_sampler_test.cc index 1b0088f134..ac83a8dc6d 100644 --- a/sdk/test/trace/trace_id_ratio_sampler_test.cc +++ b/sdk/test/trace/trace_id_ratio_sampler_test.cc @@ -1,14 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/trace_id_ratio.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" #include "src/common/random.h" -#include -#include -#include - using opentelemetry::sdk::common::Random; using opentelemetry::sdk::trace::Decision; using opentelemetry::sdk::trace::TraceIdRatioBasedSampler; diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 9715a7e0b8..fa3afa2690 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -1,20 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/tracer_provider.h" +#include +#include +#include +#include + +#include "opentelemetry/common/macros.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/id_generator.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/random_id_generator.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_off.h" -#include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/tracer.h" - -#include +#include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; -#include - TEST(TracerProvider, GetTracer) { std::unique_ptr processor(new SimpleSpanProcessor(nullptr)); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index c57b638e3d..2c4de8e83c 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -1,17 +1,58 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/tracer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/context/context_value.h" +#include "opentelemetry/exporters/memory/in_memory_span_data.h" #include "opentelemetry/exporters/memory/in_memory_span_exporter.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/id_generator.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/random_id_generator.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/sdk/trace/samplers/always_off.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/samplers/parent.h" #include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/sdk/trace/tracer.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/trace/context.h" - -#include +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/trace_state.h" +#include "opentelemetry/trace/tracer.h" using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h b/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h index 51f9502bb8..eb56b59806 100644 --- a/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h +++ b/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h @@ -2,7 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + +#include + #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h index 3207857743..a5f8c2f0e1 100644 --- a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h +++ b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h @@ -3,16 +3,18 @@ #pragma once -#include "opentelemetry/ext/http/client/http_client.h" -#include "opentelemetry/ext/http/common/url_parser.h" -#include "opentelemetry/version.h" - -#include +#include +#include +#include +#include +#include #include -#include +#include -#include -#include "gmock/gmock.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext @@ -116,7 +118,7 @@ class Response : public opentelemetry::ext::http::client::Response opentelemetry::ext::http::client::StatusCode status_code_; }; -class HttpClient; +class HttpClient; // IWYU pragma: keep class Session : public opentelemetry::ext::http::client::Session { diff --git a/test_common/src/http/client/nosend/http_client_nosend.cc b/test_common/src/http/client/nosend/http_client_nosend.cc index 98cae0476a..46784869c4 100644 --- a/test_common/src/http/client/nosend/http_client_nosend.cc +++ b/test_common/src/http/client/nosend/http_client_nosend.cc @@ -1,7 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext From 2314e061a533808a1f4a693fac86e4cb0b8fa7e4 Mon Sep 17 00:00:00 2001 From: loong_hy <88186554+loong-hy@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:03:42 +0800 Subject: [PATCH 52/71] [BUILD] add loongarch info (#3052) --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b247f47fc9..fd41fa7148 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,8 @@ else() set(ARCH s390x) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(sparc.*|SPARC.*)") set(ARCH sparc) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(loongarch.*|LOONGARCH.*)") + set(ARCH loongarch) else() message( FATAL_ERROR From 23818a7105c2565ff0a07580a585d10ec3dc8db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADzio=20de=20Royes=20Mello?= Date: Fri, 20 Sep 2024 10:49:22 -0300 Subject: [PATCH 53/71] [CI] Update otel-collector version (#3067) Looks like otel-collector equal or higher than 0.86.0 has the "debug" exporter. So updated the README.md with the latest version of the otel-collector (v0.109.0) and also the CI script. --- ci/do_ci.sh | 2 +- examples/otlp/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 4cd97a7f43..c31d5e887a 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -20,7 +20,7 @@ function install_prometheus_cpp_client function run_benchmarks { docker run -d --rm -it -p 4317:4317 -p 4318:4318 -v \ - $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.38.0 \ + $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.109.0 \ --config=/cfg/opentelemetry-collector-config/config.dev.yaml [ -z "${BENCHMARK_DIR}" ] && export BENCHMARK_DIR=$HOME/benchmark diff --git a/examples/otlp/README.md b/examples/otlp/README.md index e845786346..d1846a88a2 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -50,13 +50,13 @@ OpenTelemetry Collector with an OTLP receiver by running: - On Unix based systems use: ```console -docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.59.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.109.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml ``` - On Windows use: ```console -docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.59.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.109.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml ``` Note that the OTLP gRPC and HTTP exporters connects to the Collector at `localhost:4317` and `localhost:4318/v1/traces` respectively. This can be changed with first argument from command-line, for example: From 7b824738c3cf6bd56fc833918fd034820a4c9735 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Tue, 1 Oct 2024 16:29:22 -0400 Subject: [PATCH 54/71] [SDK] Update MetricProducer interface to match spec (#3044) Following https://github.com/open-telemetry/opentelemetry-specification/blob/v1.36.0/specification/metrics/sdk.md#metricproducer. Updates #1831 --- exporters/prometheus/test/collector_test.cc | 18 ++++----- .../sdk/metrics/export/metric_producer.h | 38 +++++++++++++------ .../sdk/metrics/state/metric_collector.h | 2 +- sdk/src/metrics/metric_reader.cc | 12 +++++- sdk/src/metrics/state/metric_collector.cc | 9 ++--- sdk/test/metrics/metric_reader_test.cc | 2 +- .../periodic_exporting_metric_reader_test.cc | 5 +-- 7 files changed, 53 insertions(+), 33 deletions(-) diff --git a/exporters/prometheus/test/collector_test.cc b/exporters/prometheus/test/collector_test.cc index a70fd317b3..a31d23ab72 100644 --- a/exporters/prometheus/test/collector_test.cc +++ b/exporters/prometheus/test/collector_test.cc @@ -12,12 +12,13 @@ #include using opentelemetry::exporter::metrics::PrometheusCollector; +using opentelemetry::sdk::metrics::MetricProducer; using opentelemetry::sdk::metrics::ResourceMetrics; namespace metric_api = opentelemetry::metrics; namespace metric_sdk = opentelemetry::sdk::metrics; namespace metric_exporter = opentelemetry::exporter::metrics; -class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer +class MockMetricProducer : public MetricProducer { TestDataPoints test_data_points_; @@ -26,13 +27,12 @@ class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer : sleep_ms_{sleep_ms} {} - bool Collect(nostd::function_ref callback) noexcept override + MetricProducer::Result Produce() noexcept override { std::this_thread::sleep_for(sleep_ms_); data_sent_size_++; ResourceMetrics data = test_data_points_.CreateSumPointData(); - callback(data); - return true; + return {data, MetricProducer::Status::kSuccess}; } size_t GetDataCount() { return data_sent_size_; } @@ -70,15 +70,13 @@ class MockMetricReader : public opentelemetry::sdk::metrics::MetricReader */ TEST(PrometheusCollector, BasicTests) { - MockMetricReader *reader = new MockMetricReader(); - MockMetricProducer *producer = new MockMetricProducer(); - reader->SetMetricProducer(producer); - PrometheusCollector collector(reader, true, false); + MockMetricReader reader; + MockMetricProducer producer; + reader.SetMetricProducer(&producer); + PrometheusCollector collector(&reader, true, false); auto data = collector.Collect(); // Collection size should be the same as the size // of the records collection produced by MetricProducer. ASSERT_EQ(data.size(), 2); - delete reader; - delete producer; } diff --git a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h index 11eb113e1e..f6aa4ca2a4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h @@ -7,6 +7,7 @@ #include #include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/version.h" @@ -70,27 +71,42 @@ struct ResourceMetrics }; /** - * MetricProducer is the interface that is used to make metric data available to the - * OpenTelemetry exporters. Implementations should be stateful, in that each call to - * `Collect` will return any metric generated since the last call was made. + * MetricProducer defines the interface which bridges to third-party metric sources MUST implement, + * so they can be plugged into an OpenTelemetry MetricReader as a source of aggregated metric data. * - *

        Implementations must be thread-safe. + * Implementations must be thread-safe, and should accept configuration for the + * AggregationTemporality of produced metrics. */ - class MetricProducer { public: MetricProducer() = default; virtual ~MetricProducer() = default; + MetricProducer(const MetricProducer &) = delete; + MetricProducer(const MetricProducer &&) = delete; + void operator=(const MetricProducer &) = delete; + void operator=(const MetricProducer &&) = delete; + + enum class Status + { + kSuccess, + kFailure, + kTimeout, + }; + + struct Result + { + ResourceMetrics points_; + Status status_; + }; + /** - * The callback to be called for each metric exporter. This will only be those - * metrics that have been produced since the last time this method was called. - * - * @return a status of completion of method. + * Produce returns a batch of Metric Points, with a single instrumentation scope that identifies + * the MetricProducer. Implementations may return successfully collected points even if there is a + * partial failure. */ - virtual bool Collect( - nostd::function_ref callback) noexcept = 0; + virtual Result Produce() noexcept = 0; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index e652ba12a9..bfc3a06324 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -53,7 +53,7 @@ class MetricCollector : public MetricProducer, public CollectorHandle * * @return a status of completion of method. */ - bool Collect(nostd::function_ref callback) noexcept override; + Result Produce() noexcept override; bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; diff --git a/sdk/src/metrics/metric_reader.cc b/sdk/src/metrics/metric_reader.cc index e2f5bc1f1c..024f91fe0f 100644 --- a/sdk/src/metrics/metric_reader.cc +++ b/sdk/src/metrics/metric_reader.cc @@ -26,7 +26,7 @@ bool MetricReader::Collect( if (!metric_producer_) { OTEL_INTERNAL_LOG_WARN( - "MetricReader::Collect Cannot invoke Collect(). No MetricProducer registered for " + "MetricReader::Collect Cannot invoke Produce(). No MetricProducer registered for " "collection!") return false; } @@ -36,7 +36,15 @@ bool MetricReader::Collect( OTEL_INTERNAL_LOG_WARN("MetricReader::Collect invoked while Shutdown in progress!"); } - return metric_producer_->Collect(callback); + auto result = metric_producer_->Produce(); + + // According to the spec, + // When the Produce operation fails, the MetricProducer MAY return successfully collected + // results and a failed reasons list to the caller. + // So we invoke the callback with whatever points we get back, even if the overall operation may + // have failed. + auto success = callback(result.points_); + return (result.status_ == MetricProducer::Status::kSuccess) && success; } bool MetricReader::Shutdown(std::chrono::microseconds timeout) noexcept diff --git a/sdk/src/metrics/state/metric_collector.cc b/sdk/src/metrics/state/metric_collector.cc index a790a6b6a1..2a799b7fda 100644 --- a/sdk/src/metrics/state/metric_collector.cc +++ b/sdk/src/metrics/state/metric_collector.cc @@ -24,6 +24,7 @@ namespace sdk { namespace metrics { +using opentelemetry::sdk::resource::Resource; MetricCollector::MetricCollector(opentelemetry::sdk::metrics::MeterContext *context, std::shared_ptr metric_reader) @@ -38,14 +39,13 @@ AggregationTemporality MetricCollector::GetAggregationTemporality( return metric_reader_->GetAggregationTemporality(instrument_type); } -bool MetricCollector::Collect( - nostd::function_ref callback) noexcept +MetricProducer::Result MetricCollector::Produce() noexcept { if (!meter_context_) { OTEL_INTERNAL_LOG_ERROR("[MetricCollector::Collect] - Error during collecting." << "The metric context is invalid"); - return false; + return {{}, MetricProducer::Status::kFailure}; } ResourceMetrics resource_metrics; meter_context_->ForEachMeter([&](const std::shared_ptr &meter) noexcept { @@ -61,8 +61,7 @@ bool MetricCollector::Collect( return true; }); resource_metrics.resource_ = &meter_context_->GetResource(); - callback(resource_metrics); - return true; + return {resource_metrics, MetricProducer::Status::kSuccess}; } bool MetricCollector::ForceFlush(std::chrono::microseconds timeout) noexcept diff --git a/sdk/test/metrics/metric_reader_test.cc b/sdk/test/metrics/metric_reader_test.cc index fb0c5a9cf0..330bca7818 100644 --- a/sdk/test/metrics/metric_reader_test.cc +++ b/sdk/test/metrics/metric_reader_test.cc @@ -31,5 +31,5 @@ TEST(MetricReaderTest, BasicTests) std::shared_ptr meter_context2(new MeterContext()); std::shared_ptr metric_producer{ new MetricCollector(meter_context2.get(), std::move(metric_reader2))}; - metric_producer->Collect([](ResourceMetrics & /* metric_data */) { return true; }); + metric_producer->Produce(); } diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index 50fe7f20d8..4e92ecd683 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -63,13 +63,12 @@ class MockMetricProducer : public MetricProducer : sleep_ms_{sleep_ms} {} - bool Collect(nostd::function_ref callback) noexcept override + MetricProducer::Result Produce() noexcept override { std::this_thread::sleep_for(sleep_ms_); data_sent_size_++; ResourceMetrics data; - callback(data); - return true; + return {data, MetricProducer::Status::kSuccess}; } size_t GetDataCount() { return data_sent_size_; } From 3910b049c1469651b1d5dd585785880efae52f4a Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Mon, 7 Oct 2024 15:03:21 +0800 Subject: [PATCH 55/71] Fix URL in ES exporter, fix ipv6 supporting for http client. (#3081) --- .../src/es_log_record_exporter.cc | 2 +- .../ext/http/common/url_parser.h | 36 +++++++++++- ext/test/http/url_parser_test.cc | 57 ++++++++++++++++++- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index 3b3e8c4aeb..bfc1ad3d64 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -323,7 +323,7 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export( } // Create a connection to the ElasticSearch instance - auto session = http_client_->CreateSession(options_.host_ + std::to_string(options_.port_)); + auto session = http_client_->CreateSession(options_.host_ + ":" + std::to_string(options_.port_)); auto request = session->CreateRequest(); // Populate the request with headers and methods diff --git a/ext/include/opentelemetry/ext/http/common/url_parser.h b/ext/include/opentelemetry/ext/http/common/url_parser.h index 386d4fcd2f..75f53ce943 100644 --- a/ext/include/opentelemetry/ext/http/common/url_parser.h +++ b/ext/include/opentelemetry/ext/http/common/url_parser.h @@ -65,7 +65,7 @@ class UrlParser cpos = pos1 + 1; } } - pos = url_.find_first_of(":", cpos); + pos = FindPortPosition(url_, cpos); bool is_port = false; if (pos == std::string::npos) { @@ -130,6 +130,40 @@ class UrlParser query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length()); } } + +private: + static std::string::size_type FindPortPosition(const std::string &url, + std::string::size_type offset) + { + // @see https://www.rfc-editor.org/rfc/rfc3986#page-18 + size_t sub_expression_counter = 0; + for (std::string::size_type i = offset; i < url.size(); ++i) + { + char c = url[i]; + if (0 == sub_expression_counter && c == ':') + { + return i; + } + + if (c == '[') + { + ++sub_expression_counter; + } + else if (c == ']') + { + if (sub_expression_counter > 0) + { + --sub_expression_counter; + } + } + else if (0 == sub_expression_counter && c == '/') + { + break; + } + } + + return std::string::npos; + } }; class UrlDecoder diff --git a/ext/test/http/url_parser_test.cc b/ext/test/http/url_parser_test.cc index 79a5e60a60..aceb43966a 100644 --- a/ext/test/http/url_parser_test.cc +++ b/ext/test/http/url_parser_test.cc @@ -123,7 +123,62 @@ TEST(UrlParserTests, BasicTests) {"path", "/path1@bbb/path2"}, {"query", "q1=a1&q2=a2"}, {"success", "true"}}}, - + {"http://1.2.3.4/path1/path2?q1=a1&q2=a2", + {{"host", "1.2.3.4"}, + {"port", "80"}, + {"scheme", "http"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"user:password@1.2.3.4:8080/path1/path2?q1=a1&q2=a2", + {{"host", "1.2.3.4"}, + {"port", "8080"}, + {"scheme", "http"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"https://user@1.2.3.4/path1/path2?q1=a1&q2=a2", + {{"host", "1.2.3.4"}, + {"port", "443"}, + {"scheme", "https"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"http://1.2.3.4/path1@bbb/path2?q1=a1&q2=a2", + {{"host", "1.2.3.4"}, + {"port", "80"}, + {"scheme", "http"}, + {"path", "/path1@bbb/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"http://[fe80::225:93da:bfde:b5f5]/path1/path2?q1=a1&q2=a2", + {{"host", "[fe80::225:93da:bfde:b5f5]"}, + {"port", "80"}, + {"scheme", "http"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"user:password@[fe80::225:93da:bfde:b5f5]:8080/path1/path2?q1=a1&q2=a2", + {{"host", "[fe80::225:93da:bfde:b5f5]"}, + {"port", "8080"}, + {"scheme", "http"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"https://user@[fe80::225:93da:bfde:b5f5]/path1/path2?q1=a1&q2=a2", + {{"host", "[fe80::225:93da:bfde:b5f5]"}, + {"port", "443"}, + {"scheme", "https"}, + {"path", "/path1/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, + {"http://[fe80::225:93da:bfde:b5f5]/path1@bbb/path2?q1=a1&q2=a2", + {{"host", "[fe80::225:93da:bfde:b5f5]"}, + {"port", "80"}, + {"scheme", "http"}, + {"path", "/path1@bbb/path2"}, + {"query", "q1=a1&q2=a2"}, + {"success", "true"}}}, }; for (auto &url_map : urls_map) { From 35e8d17420ff9e216a72cfbb3a066f21aa5dba8b Mon Sep 17 00:00:00 2001 From: ShadowMaxLeb Date: Mon, 7 Oct 2024 22:44:24 +0200 Subject: [PATCH 56/71] [EXPORTER] Add possibility to give custom HttpHeaders for (#3083) --- .../elasticsearch/es_log_record_exporter.h | 19 +++++++++++++------ .../src/es_log_record_exporter.cc | 7 +++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h index 2035b32d4b..36f2dfbca4 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h @@ -26,6 +26,8 @@ namespace logs */ struct ElasticsearchExporterOptions { + using HttpHeaders = std::multimap; + // Configuration options to establish Elasticsearch connection std::string host_; int port_; @@ -37,6 +39,9 @@ struct ElasticsearchExporterOptions // Whether to print the status of the exporter in the console bool console_debug_; + /** Additional HTTP headers. */ + HttpHeaders http_headers_; + /** * Constructor for the ElasticsearchExporterOptions. By default, the endpoint is * localhost:9200/logs with a timeout of 30 seconds and disabled console debugging @@ -47,16 +52,18 @@ struct ElasticsearchExporterOptions * from elasticsearch * @param console_debug If true, print the status of the exporter methods in the console */ - ElasticsearchExporterOptions(std::string host = "localhost", - int port = 9200, - std::string index = "logs", - int response_timeout = 30, - bool console_debug = false) + ElasticsearchExporterOptions(std::string host = "localhost", + int port = 9200, + std::string index = "logs", + int response_timeout = 30, + bool console_debug = false, + HttpHeaders http_headers = {}) : host_{host}, port_{port}, index_{index}, response_timeout_{response_timeout}, - console_debug_{console_debug} + console_debug_{console_debug}, + http_headers_{http_headers} {} }; diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index bfc1ad3d64..f464df5006 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -330,6 +330,13 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export( request->SetUri(options_.index_ + "/_bulk?pretty"); request->SetMethod(http_client::Method::Post); request->AddHeader("Content-Type", "application/json"); + + // Add options headers + for (auto it = options_.http_headers_.cbegin(); it != options_.http_headers_.cend(); ++it) + { + request->AddHeader(it->first, it->second); + } + request->SetTimeoutMs(std::chrono::milliseconds(1000 * options_.response_timeout_)); // Create the request body From fa0a5200ddbe9ae6f487a228e658aedc102dab56 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 7 Oct 2024 23:57:27 +0200 Subject: [PATCH 57/71] [RELEASE] Release opentelemetry-cpp 1.17.0 (#3076) --- CHANGELOG.md | 89 +++++++++++++++++++ api/include/opentelemetry/version.h | 6 +- docs/public/conf.py | 2 +- .../opentelemetry/sdk/version/version.h | 2 +- sdk/src/version/version.cc | 10 +-- 5 files changed, 99 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d60f3513..3bc2401d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,15 +15,104 @@ Increment the: ## [Unreleased] +## [1.17 2024-10-07] + * [CI] Add a clang-tidy build [#3001](https://github.com/open-telemetry/opentelemetry-cpp/pull/3001) +* [BUILD] Upgrade to opentelemetry-proto 1.3.2 + [#2991](https://github.com/open-telemetry/opentelemetry-cpp/pull/2991) + * [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` [#2717](https://github.com/open-telemetry/opentelemetry-cpp/pull/2717) +* [EXPORTER] ForceFlush before canceling the running requests on shutdown + [#2727](https://github.com/open-telemetry/opentelemetry-cpp/pull/2727) + +* [SDK] Fix crash in PeriodicExportingMetricReader + [#2983](https://github.com/open-telemetry/opentelemetry-cpp/pull/2983) + +* [SDK] Fix memory leak in TlsRandomNumberGenerator() constructor + [#2661](https://github.com/open-telemetry/opentelemetry-cpp/pull/2661) + +* [EXPORTER] Ignore exception when create thread in OTLP file exporter + [#3012](https://github.com/open-telemetry/opentelemetry-cpp/pull/3012) + +* [BUILD] Update the version in MODULE.bazel + [#3015](https://github.com/open-telemetry/opentelemetry-cpp/pull/3015) + +* [BUILD] Fix build without vcpkg on Windows when gRPC is disabled + [#3016](https://github.com/open-telemetry/opentelemetry-cpp/pull/3016) + +* [BUILD] Add abi_version_no bazel flag + [#3020](https://github.com/open-telemetry/opentelemetry-cpp/pull/3020) + +* [Code health] Expand iwyu coverage to include unit tests + [#3022](https://github.com/open-telemetry/opentelemetry-cpp/pull/3022) + +* [BUILD] Version opentelemetry_proto/proto_grpc shared libraries + [#2992](https://github.com/open-telemetry/opentelemetry-cpp/pull/2992) + +* [SEMANTIC CONVENTIONS] Upgrade semantic conventions to 1.27.0 + [#3023](https://github.com/open-telemetry/opentelemetry-cpp/pull/3023) + +* [SDK] Support empty histogram buckets + [#3027](https://github.com/open-telemetry/opentelemetry-cpp/pull/3027) + +* [TEST] Fix sync problems in OTLP File exporter tests + [#3031](https://github.com/open-telemetry/opentelemetry-cpp/pull/3031) + +* [SDK] PeriodicExportingMetricReader: future is never set, blocks until timeout + [#3030](https://github.com/open-telemetry/opentelemetry-cpp/pull/3030) + +* [Code Health] Clang Tidy cleanup, Part 2 + [#3038](https://github.com/open-telemetry/opentelemetry-cpp/pull/3038) + +* [Code Health] include-what-you-use cleanup, part 3 + [#3004](https://github.com/open-telemetry/opentelemetry-cpp/pull/3004) + +* [SDK] Fix overflow in timeout logic + [#3046](https://github.com/open-telemetry/opentelemetry-cpp/pull/3046) + +* [TEST] Add missing tests to Bazel build + [#3045](https://github.com/open-telemetry/opentelemetry-cpp/pull/3045) + +* [TEST] update collector tests with debug exporter + [#3050](https://github.com/open-telemetry/opentelemetry-cpp/pull/3050) + +* [EXAMPLE] update collector example with debug exporter + [#3049](https://github.com/open-telemetry/opentelemetry-cpp/pull/3049) + +* [TEST] update references to logging exporter + [#3053](https://github.com/open-telemetry/opentelemetry-cpp/pull/3053) + +* [EXAMPLE] Clean the tracer initialization in OStream example + [#3051](https://github.com/open-telemetry/opentelemetry-cpp/pull/3051) + +* [EXPORTER] Fix the format of SpanLink for ETW + [#3054](https://github.com/open-telemetry/opentelemetry-cpp/pull/3054) + * [EXPORTER] Add in-memory metric exporter [#3043](https://github.com/open-telemetry/opentelemetry-cpp/pull/3043) +* [Code Health] include-what-you-use cleanup, part 4 + [#3040](https://github.com/open-telemetry/opentelemetry-cpp/pull/3040) + +* [BUILD] add loongarch info + [#3052](https://github.com/open-telemetry/opentelemetry-cpp/pull/3052) + +* [CI] Update otel-collector version + [#3067](https://github.com/open-telemetry/opentelemetry-cpp/pull/3067) + +* [SDK] Update MetricProducer interface to match spec + [#3044](https://github.com/open-telemetry/opentelemetry-cpp/pull/3044) + +* [EXPORTER] Fix URL in ES exporter, fix ipv6 supporting for http client + [#3081](https://github.com/open-telemetry/opentelemetry-cpp/pull/3081) + +* [EXPORTER] Add HttpHeaders in ElasticsearchLogRecordExporter + [#3083](https://github.com/open-telemetry/opentelemetry-cpp/pull/3083) + Breaking changes: * [REMOVAL] Remove build option `WITH_DEPRECATED_SDK_FACTORY` diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index d98ac978f2..d3e18ce1d8 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -10,10 +10,10 @@ # define OPENTELEMETRY_ABI_VERSION_NO 1 #endif -#define OPENTELEMETRY_VERSION "1.16.1" +#define OPENTELEMETRY_VERSION "1.17.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 16 -#define OPENTELEMETRY_VERSION_PATCH 1 +#define OPENTELEMETRY_VERSION_MINOR 17 +#define OPENTELEMETRY_VERSION_PATCH 0 #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) diff --git a/docs/public/conf.py b/docs/public/conf.py index 96caa2b43a..96b70cb6fa 100644 --- a/docs/public/conf.py +++ b/docs/public/conf.py @@ -24,7 +24,7 @@ author = 'OpenTelemetry authors' # The full version, including alpha/beta/rc tags -release = "1.16.1" +release = "1.17.0" # Run sphinx on subprojects and copy output # ----------------------------------------- diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index 86b815e3bc..b8f4c076f1 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -3,7 +3,7 @@ #pragma once -#define OPENTELEMETRY_SDK_VERSION "1.16.1" +#define OPENTELEMETRY_SDK_VERSION "1.17.0" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index 80f2226400..97e7f15549 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -12,13 +12,13 @@ namespace sdk namespace version { const int major_version = 1; -const int minor_version = 16; -const int patch_version = 1; +const int minor_version = 17; +const int patch_version = 0; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.16.1"; -const char *full_version = "1.16.1-NONE-NONE"; -const char *build_date = "Wed Jul 17 17:34:38 UTC 2024"; +const char *short_version = "1.17.0"; +const char *full_version = "1.17.0-NONE-NONE"; +const char *build_date = "Mon Oct 7 08:55:12 PM UTC 2024"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From 0ea1f2c6442ac53f567077633865930794649699 Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Tue, 8 Oct 2024 09:12:37 +0200 Subject: [PATCH 58/71] [EXPORTER] Fix crash in ElasticsearchLogRecordExporter when (#3082) using constructor with user given options (#3078) Closes #3078 --- .../elasticsearch/src/es_log_record_exporter.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index f464df5006..1ec786a198 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -288,7 +288,12 @@ class AsyncResponseHandler : public http_client::EventHandler #endif ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter() - : options_{ElasticsearchExporterOptions()}, + : ElasticsearchLogRecordExporter(ElasticsearchExporterOptions()) +{} + +ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( + const ElasticsearchExporterOptions &options) + : options_{options}, http_client_{ext::http::client::HttpClientFactory::Create()} #ifdef ENABLE_ASYNC_EXPORT , @@ -301,11 +306,6 @@ ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter() #endif } -ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( - const ElasticsearchExporterOptions &options) - : options_{options}, http_client_{ext::http::client::HttpClientFactory::Create()} -{} - std::unique_ptr ElasticsearchLogRecordExporter::MakeRecordable() noexcept { return std::unique_ptr(new ElasticSearchRecordable()); From 3d9c2b538272b553cfb83f605061382724921426 Mon Sep 17 00:00:00 2001 From: "Romain Geissler @ Amadeus" Date: Tue, 8 Oct 2024 17:28:30 +0200 Subject: [PATCH 59/71] [BUILD] Avoid buggy "should be explicitly initialized in the copy constructor" warning with gcc <= 8 (#3087) gcc <= 8, when building with -Wextra (and -Werror) wrongly raises this: /data/mwrep/res/mdw/SIOTF/internal/opentelemetry_cpp/trace/18-0-0-7/include/opentelemetry/trace/default_span.h: In copy constructor 'opentelemetry::v1::trace::DefaultSpan::DefaultSpan(const opentelemetry::v1::trace::DefaultSpan&)': /data/mwrep/res/mdw/SIOTF/internal/opentelemetry_cpp/trace/18-0-0-7/include/opentelemetry/trace/default_span.h:70:3: error: base class 'class opentelemetry::v1::trace::Span' should be explicitly initialized in the copy constructor [-Werror=extra] DefaultSpan(const DefaultSpan &spn) noexcept : span_context_(spn.GetContext()) {} ^~~~~~~~~~~ See on Compiler Explorer here: https://godbolt.org/z/ed5rv74nT I believe Jason Merrill fixed it in gcc for all gcc >= 9 with: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f3f7cefecc833b4ab652215ceb8b408c21dca225;hp=777083bb806dbe31ab97002b7d445191d3ee7a2d Workaround this by calling explicitly the empty Span constructor. --- api/include/opentelemetry/trace/default_span.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/trace/default_span.h b/api/include/opentelemetry/trace/default_span.h index 7e3979501e..7ad6a3726e 100644 --- a/api/include/opentelemetry/trace/default_span.h +++ b/api/include/opentelemetry/trace/default_span.h @@ -66,8 +66,8 @@ class DefaultSpan : public Span DefaultSpan(SpanContext span_context) noexcept : span_context_(span_context) {} // movable and copiable - DefaultSpan(DefaultSpan &&spn) noexcept : span_context_(spn.GetContext()) {} - DefaultSpan(const DefaultSpan &spn) noexcept : span_context_(spn.GetContext()) {} + DefaultSpan(DefaultSpan &&spn) noexcept : Span(), span_context_(spn.GetContext()) {} + DefaultSpan(const DefaultSpan &spn) noexcept : Span(), span_context_(spn.GetContext()) {} private: SpanContext span_context_; From 6445819fceeb3bfea1444a88418f00a0df69cd2f Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 8 Oct 2024 18:49:56 +0200 Subject: [PATCH 60/71] [API] Jaeger Propagator should not be deprecated (#3086) --- CHANGELOG.md | 14 +++++++ DEPRECATED.md | 40 +------------------ .../opentelemetry/trace/propagation/jaeger.h | 6 +-- api/test/trace/propagation/CMakeLists.txt | 16 +------- 4 files changed, 18 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bc2401d60..540479eb97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,20 @@ Increment the: ## [Unreleased] +* [API] Jaeger Propagator should not be deprecated + [#3086](https://github.com/open-telemetry/opentelemetry-cpp/pull/3086) + +Important changes: + +* [API] Jaeger Propagator should not be deprecated + [#3086](https://github.com/open-telemetry/opentelemetry-cpp/pull/3086) + + * Deprecation of the Jaeger propagator, as announced on 2023-01-31 + in version 1.8.2, is now reverted. + * This deprecation turned out to be not justified, + as the Jaeger propagator can be used without the (now removed) + Jaeger exporter. + ## [1.17 2024-10-07] * [CI] Add a clang-tidy build diff --git a/DEPRECATED.md b/DEPRECATED.md index 0632f50503..eea861ffe6 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -46,45 +46,7 @@ N/A ## [opentelemetry-cpp API] -### Jaeger propagator - -#### Announcement (Jaeger) - -* Version: 1.8.2 -* Date: 2023-01-31 -* PR: [DEPRECATION] Deprecate the Jaeger exporter - [#1923](https://github.com/open-telemetry/opentelemetry-cpp/pull/1923) - -This PR also listed the Jaeger propagator as deprecated. - -#### Motivation (Jaeger) - -The Jaeger Exporter is now (July 2023) removed from the OpenTelemetry specification. - -The Jaeger Propagator remains, because changing propagation is a longer -process compared to changing an export format. - -New deployments however are encouraged to use a W3C compliant propagator, -and avoid the Jaeger propagator, which is now deprecated. - -#### Scope (Jaeger) - -The following are deprecated and planned for removal: - -* the API header `opentelemetry/trace/propagation/jaeger.h`, including: - * the C++ class `JaegerPropagator` - -#### Mitigation (Jaeger) - -Use a W3C compliant propagator instead. - -That is, use class HttpTraceContext and "traceparent" tags. - -Do not use class JaegerPropagator and "uber-trace-id" tags. - -#### Planned removal (Jaeger) - -No date set yet for the Jaeger Propagator. +N/A ## [opentelemetry-cpp SDK] diff --git a/api/include/opentelemetry/trace/propagation/jaeger.h b/api/include/opentelemetry/trace/propagation/jaeger.h index 1f0195a248..45a9370919 100644 --- a/api/include/opentelemetry/trace/propagation/jaeger.h +++ b/api/include/opentelemetry/trace/propagation/jaeger.h @@ -3,10 +3,6 @@ #pragma once -#ifdef OPENTELEMETRY_NO_DEPRECATED_CODE -# error "header is deprecated." -#endif - #include "detail/hex.h" #include "detail/string.h" #include "opentelemetry/context/propagation/text_map_propagator.h" @@ -21,7 +17,7 @@ namespace propagation static const nostd::string_view kJaegerTraceHeader = "uber-trace-id"; -class OPENTELEMETRY_DEPRECATED JaegerPropagator : public context::propagation::TextMapPropagator +class JaegerPropagator : public context::propagation::TextMapPropagator { public: void Inject(context::propagation::TextMapCarrier &carrier, diff --git a/api/test/trace/propagation/CMakeLists.txt b/api/test/trace/propagation/CMakeLists.txt index a1cfcf83ee..f55c738165 100644 --- a/api/test/trace/propagation/CMakeLists.txt +++ b/api/test/trace/propagation/CMakeLists.txt @@ -3,7 +3,8 @@ add_subdirectory(detail) -foreach(testname http_text_format_test b3_propagation_test) +foreach(testname http_text_format_test b3_propagation_test + jaeger_propagation_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) @@ -12,16 +13,3 @@ foreach(testname http_text_format_test b3_propagation_test) TEST_PREFIX trace. TEST_LIST ${testname}) endforeach() - -if(NOT WITH_NO_DEPRECATED_CODE) - foreach(testname jaeger_propagation_test) - - add_executable(${testname} "${testname}.cc") - target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) - gtest_add_tests( - TARGET ${testname} - TEST_PREFIX trace. - TEST_LIST ${testname}) - endforeach() -endif() From f69963f587b148d2eb20f7d30f8b4a1ccb184a6f Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Sun, 13 Oct 2024 23:18:22 +0800 Subject: [PATCH 61/71] Update bzlmod version (#3093) --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 13175f2c21..a9171d7424 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -3,7 +3,7 @@ module( name = "opentelemetry-cpp", - version = "1.16.1", + version = "1.17.0", compatibility_level = 0, repo_name = "io_opentelemetry_cpp", ) From 70ed9bcac0739eb3981c5b8d71f1ab23bc279701 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Wed, 16 Oct 2024 17:21:59 +0800 Subject: [PATCH 62/71] [BUILD] Remove std::make_unique (#3098) --- exporters/memory/src/in_memory_metric_exporter_factory.cc | 4 ++-- exporters/memory/test/in_memory_metric_data_test.cc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exporters/memory/src/in_memory_metric_exporter_factory.cc b/exporters/memory/src/in_memory_metric_exporter_factory.cc index f2577c4e9b..7f6ab83346 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(std::unique_ptr(new ResourceMetrics{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 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 ffaba2cfb9..3f2d661759 100644 --- a/exporters/memory/test/in_memory_metric_data_test.cc +++ b/exporters/memory/test/in_memory_metric_data_test.cc @@ -23,8 +23,8 @@ TEST(InMemoryMetricDataTest, CircularBuffer) { CircularBufferInMemoryMetricData buf(10); Resource resource = Resource::GetEmpty(); - buf.Add(std::make_unique( - &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,8 +45,8 @@ TEST(InMemoryMetricDataTest, SimpleAggregate) md.instrument_descriptor.name_ = "my-metric"; md.point_data_attr_.push_back(pda); - agg.Add(std::make_unique( - &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 63683c1596484161c085ff642cb0e34b7bdf2bfb Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Thu, 17 Oct 2024 15:57:10 +0800 Subject: [PATCH 63/71] [BUILD] Fix compiling problems for gcc 4.8 (#3100) * Fix compiling problems for gcc 4.8 * Apply suggestions from code review --------- Co-authored-by: Marc Alff --- exporters/memory/src/in_memory_metric_data.cc | 7 +++++-- exporters/memory/src/in_memory_metric_exporter_factory.cc | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/exporters/memory/src/in_memory_metric_data.cc b/exporters/memory/src/in_memory_metric_data.cc index 2a77e0b5a3..90f1c1450f 100644 --- a/exporters/memory/src/in_memory_metric_data.cc +++ b/exporters/memory/src/in_memory_metric_data.cc @@ -31,7 +31,9 @@ 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}); + // NOTE: Explicit type conversion added for C++11 (gcc 4.8) + data_[std::tuple{scope, metric}].insert( + {pda.attributes, pda.point_data}); } } } @@ -41,7 +43,8 @@ const SimpleAggregateInMemoryMetricData::AttributeToPoint &SimpleAggregateInMemo const std::string &scope, const std::string &metric) { - return data_[{scope, metric}]; + // NOTE: Explicit type conversion added for C++11 (gcc 4.8) + 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 7f6ab83346..0deff73dcd 100644 --- a/exporters/memory/src/in_memory_metric_exporter_factory.cc +++ b/exporters/memory/src/in_memory_metric_exporter_factory.cc @@ -78,7 +78,8 @@ 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( From 1185405c46290175127f279193a71e2d4f68f7ce Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 18 Oct 2024 18:20:42 +0800 Subject: [PATCH 64/71] [TEST] Fix linking order and gmock linking (#3106) * Fix link order * Fix gmock linking --- ext/test/http/CMakeLists.txt | 6 +++--- test_common/src/http/client/nosend/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index 328f78638b..9f5514d07b 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -5,7 +5,7 @@ if(WITH_HTTP_CLIENT_CURL) set(FILENAME curl_http_test) add_compile_definitions(WITH_CURL) add_executable(${FILENAME} ${FILENAME}.cc) - target_link_libraries(${FILENAME} ${GTEST_BOTH_LIBRARIES} + target_link_libraries(${FILENAME} ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) if(TARGET CURL::libcurl) @@ -24,8 +24,8 @@ endif() set(URL_PARSER_FILENAME url_parser_test) add_executable(${URL_PARSER_FILENAME} ${URL_PARSER_FILENAME}.cc) -target_link_libraries(${URL_PARSER_FILENAME} ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +target_link_libraries(${URL_PARSER_FILENAME} opentelemetry_api ${GMOCK_LIB} + ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) gtest_add_tests( TARGET ${URL_PARSER_FILENAME} TEST_PREFIX ext.http.urlparser. diff --git a/test_common/src/http/client/nosend/CMakeLists.txt b/test_common/src/http/client/nosend/CMakeLists.txt index 92a2c1f98c..7394053a22 100644 --- a/test_common/src/http/client/nosend/CMakeLists.txt +++ b/test_common/src/http/client/nosend/CMakeLists.txt @@ -28,7 +28,7 @@ if(${BUILD_TESTING}) endif() target_link_libraries( - opentelemetry_http_client_nosend ${GTEST_BOTH_LIBRARIES} opentelemetry_ext - opentelemetry_test_common) + opentelemetry_http_client_nosend opentelemetry_ext + opentelemetry_test_common ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES}) endif() From b1488cd37c3077d67021c3a63b3dabe1d7147a10 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Mon, 21 Oct 2024 16:43:30 -0400 Subject: [PATCH 65/71] [EXPORTER] Add config options to prometheus exporter (#3104) --- .../exporters/prometheus/exporter_options.h | 6 ++ .../exporters/prometheus/exporter_utils.h | 12 ++- exporters/prometheus/src/exporter_options.cc | 25 ++++- exporters/prometheus/src/exporter_utils.cc | 62 +++++++----- .../prometheus/test/exporter_utils_test.cc | 94 ++++++++++++++++++- 5 files changed, 169 insertions(+), 30 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h index 5d8b4932fc..da9d124029 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h @@ -28,6 +28,12 @@ struct PrometheusExporterOptions // Populating otel_scope_name/otel_scope_labels attributes bool without_otel_scope = false; + + // Option to export metrics without the unit suffix + bool without_units = false; + + // Option to export metrics without the type suffix + bool without_type_suffix = false; }; } // namespace metrics diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index ccf3d03ff3..29c0f66daf 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -30,12 +30,18 @@ class PrometheusExporterUtils * @param populate_target_info whether to populate target_info * @param without_otel_scope whether to populate otel_scope_name and otel_scope_version * attributes + * @param without_units exporter configuration controlling whether to append unit suffix in + * the exported metrics. + * @param without_type_suffix exporter configuration controlling whether to append type suffix in + * the exported metrics. * @return a collection of translated metrics that is acceptable by Prometheus */ static std::vector<::prometheus::MetricFamily> TranslateToPrometheus( const sdk::metrics::ResourceMetrics &data, bool populate_target_info = true, - bool without_otel_scope = false); + bool without_otel_scope = false, + bool without_units = false, + bool without_type_suffix = false); private: /** @@ -61,7 +67,9 @@ class PrometheusExporterUtils static std::string MapToPrometheusName(const std::string &name, const std::string &unit, - ::prometheus::MetricType prometheus_type); + ::prometheus::MetricType prometheus_type, + bool without_units, + bool without_type_suffix); /** * A utility function that returns the equivalent Prometheus name for the provided OTLP metric diff --git a/exporters/prometheus/src/exporter_options.cc b/exporters/prometheus/src/exporter_options.cc index f2c49f7a57..a9de8f4eb4 100644 --- a/exporters/prometheus/src/exporter_options.cc +++ b/exporters/prometheus/src/exporter_options.cc @@ -48,10 +48,33 @@ inline bool GetPrometheusPopulateTargetInfo() return exists ? setting : true; } +inline bool GetPrometheusWithoutUnits() +{ + constexpr char kPrometheusWithoutUnits[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_UNITS"; + bool setting; + const auto exists = + opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusWithoutUnits, setting); + + return exists ? setting : false; +} + +inline bool GetPrometheusWithoutTypeSuffix() +{ + constexpr char kPrometheusWithoutTypeSuffix[] = + "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_TYPE_SUFFIX"; + bool setting; + const auto exists = + opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusWithoutTypeSuffix, setting); + + return exists ? setting : false; +} + PrometheusExporterOptions::PrometheusExporterOptions() : url(GetPrometheusDefaultHttpEndpoint()), populate_target_info(GetPrometheusPopulateTargetInfo()), - without_otel_scope(GetPrometheusWithoutOtelScope()) + without_otel_scope(GetPrometheusWithoutOtelScope()), + without_units(GetPrometheusWithoutUnits()), + without_type_suffix(GetPrometheusWithoutTypeSuffix()) {} } // namespace metrics diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 77fcd56ad2..27385f3f6f 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -102,13 +102,15 @@ std::string SanitizeLabel(std::string label_key) * Helper function to convert OpenTelemetry metrics data collection * to Prometheus metrics data collection * - * @param records a collection of metrics in OpenTelemetry + * @param data a collection of metrics in OpenTelemetry * @return a collection of translated metrics that is acceptable by Prometheus */ std::vector PrometheusExporterUtils::TranslateToPrometheus( const sdk::metrics::ResourceMetrics &data, bool populate_target_info, - bool without_otel_scope) + bool without_otel_scope, + bool without_units, + bool without_type_suffix) { // initialize output vector @@ -150,7 +152,8 @@ std::vector PrometheusExporterUtils::TranslateT } const prometheus_client::MetricType type = TranslateType(kind, is_monotonic); metric_family.name = MapToPrometheusName(metric_data.instrument_descriptor.name_, - metric_data.instrument_descriptor.unit_, type); + metric_data.instrument_descriptor.unit_, type, + without_units, without_type_suffix); metric_family.type = type; const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope = without_otel_scope ? nullptr : instrumentation_info.scope_; @@ -492,34 +495,43 @@ std::string PrometheusExporterUtils::CleanUpString(const std::string &str) std::string PrometheusExporterUtils::MapToPrometheusName( const std::string &name, const std::string &unit, - prometheus_client::MetricType prometheus_type) + prometheus_client::MetricType prometheus_type, + bool without_units, + bool without_type_suffix) { - auto sanitized_name = SanitizeNames(name); - std::string prometheus_equivalent_unit = GetEquivalentPrometheusUnit(unit); - - // Append prometheus unit if not null or empty. - if (!prometheus_equivalent_unit.empty() && - sanitized_name.find(prometheus_equivalent_unit) == std::string::npos) - { - sanitized_name += "_" + prometheus_equivalent_unit; - } - - // Special case - counter - if (prometheus_type == prometheus_client::MetricType::Counter) - { - auto t_pos = sanitized_name.rfind("_total"); - bool ends_with_total = t_pos == sanitized_name.size() - 6; - if (!ends_with_total) + auto sanitized_name = SanitizeNames(name); + // append unit suffixes + if (!without_units) + { + std::string prometheus_equivalent_unit = GetEquivalentPrometheusUnit(unit); + // Append prometheus unit if not null or empty. + if (!prometheus_equivalent_unit.empty() && + sanitized_name.find(prometheus_equivalent_unit) == std::string::npos) { - sanitized_name += "_total"; + sanitized_name += "_" + prometheus_equivalent_unit; + } + // Special case - gauge + if (unit == "1" && prometheus_type == prometheus_client::MetricType::Gauge && + sanitized_name.find("ratio") == std::string::npos) + { + // this is replacing the unit name + sanitized_name += "_ratio"; } } - // Special case - gauge - if (unit == "1" && prometheus_type == prometheus_client::MetricType::Gauge && - sanitized_name.find("ratio") == std::string::npos) + // append type suffixes + if (!without_type_suffix) { - sanitized_name += "_ratio"; + // Special case - counter + if (prometheus_type == prometheus_client::MetricType::Counter) + { + auto t_pos = sanitized_name.rfind("_total"); + bool ends_with_total = t_pos == sanitized_name.size() - 6; + if (!ends_with_total) + { + sanitized_name += "_total"; + } + } } return CleanUpString(SanitizeNames(sanitized_name)); diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 7ad5eee1fd..76ec869a6f 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -54,9 +54,12 @@ class SanitizeNameTester } static std::string mapToPrometheusName(const std::string &name, const std::string &unit, - prometheus_client::MetricType prometheus_type) + prometheus_client::MetricType prometheus_type, + bool without_units = false, + bool without_type_suffix = false) { - return PrometheusExporterUtils::MapToPrometheusName(name, unit, prometheus_type); + return PrometheusExporterUtils::MapToPrometheusName(name, unit, prometheus_type, without_units, + without_type_suffix); } }; } // namespace metrics @@ -419,6 +422,93 @@ TEST(PrometheusExporterUtils, ConvertRateExpressedToPrometheusUnit) "_per_minute"); } +TEST(PromentheusExporterUtils, PrometheusNameMapping) +{ + // General test cases on unit expansions and name sanitization + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric___name", "g", prometheus::MetricType::Counter), + "sample_metric_name_grams_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "s", prometheus::MetricType::Counter), + "sample_metric_name_seconds_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "s", prometheus::MetricType::Gauge), + "sample_metric_name_seconds"); + // Test without_units & without_type_suffix with Counters and unit = 1 + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Counter), + "sample_metric_name_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Counter, true, false), + "sample_metric_name_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Counter, false, true), + "sample_metric_name"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Counter, true, true), + "sample_metric_name"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Counter, true, true), + "sample_metric_name"); + // Test without_units & without_type_suffix with Counters and non-special units + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "%", prometheus::MetricType::Counter), + "sample_metric_name_percent_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "m", prometheus::MetricType::Counter, true, false), + "sample_metric_name_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "By", prometheus::MetricType::Counter, false, true), + "sample_metric_name_bytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "s", prometheus::MetricType::Counter, true, true), + "sample_metric_name"); + // Special case Gauges & ratio + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Gauge), + "sample_metric_name_ratio"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Gauge, false, true), + "sample_metric_name_ratio"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Gauge, true, false), + "sample_metric_name"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "1", prometheus::MetricType::Gauge, true, true), + "sample_metric_name"); + // Test without_type_suffix affects only counters + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Counter), + "sample_metric_name_hertz_total"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Counter, false, true), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Gauge), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Gauge, false, true), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Histogram), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Histogram, false, true), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Summary), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Summary, false, true), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Info), + "sample_metric_name_hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::mapToPrometheusName( + "sample_metric_name", "Hz", prometheus::MetricType::Info, false, true), + "sample_metric_name_hertz"); +} + TEST_F(AttributeCollisionTest, JoinsCollidingKeys) { CheckTranslation({{"foo.a", "value1"}, {"foo_a", "value2"}}, {{"foo_a", "value1;value2"}, From 7402ed9bac9265ea22ddb1dd4e61029f745f7436 Mon Sep 17 00:00:00 2001 From: tobim Date: Mon, 21 Oct 2024 23:27:57 +0200 Subject: [PATCH 66/71] [BUILD] Add a CMake option to disable shared libs (#3095) * Add a CMake option to disable shared libs This option is useful to support platforms that do not support dynamic libraries and `dlopen`. --- CMakeLists.txt | 4 ++++ api/test/CMakeLists.txt | 5 ++++- examples/plugin/CMakeLists.txt | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd41fa7148..a0710834bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF) option(WITH_METRICS_EXEMPLAR_PREVIEW "Whether to enable exemplar within metrics" OFF) +option(OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS + "Whether to build test libraries that are always linked as shared libs" + OFF) + # # Verify options dependencies # diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 20c9f4e949..66eeee2092 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -10,4 +10,7 @@ add_subdirectory(metrics) add_subdirectory(logs) add_subdirectory(common) add_subdirectory(baggage) -add_subdirectory(singleton) + +if(NOT OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS) + add_subdirectory(singleton) +endif() diff --git a/examples/plugin/CMakeLists.txt b/examples/plugin/CMakeLists.txt index e1a44690e4..5dfc79963c 100644 --- a/examples/plugin/CMakeLists.txt +++ b/examples/plugin/CMakeLists.txt @@ -2,4 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory(load) -add_subdirectory(plugin) + +if(NOT OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS) + add_subdirectory(plugin) +endif() From 751ba5b48f6f6ce90b2b22466540e66b2e114851 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Oct 2024 14:11:55 -0700 Subject: [PATCH 67/71] [EXPORTER] Remove out of date ETW exporter doc (#3103) --- exporters/etw/README.md | 214 +--------------------------------------- 1 file changed, 2 insertions(+), 212 deletions(-) diff --git a/exporters/etw/README.md b/exporters/etw/README.md index 3339223fa6..372aa5738e 100644 --- a/exporters/etw/README.md +++ b/exporters/etw/README.md @@ -12,215 +12,5 @@ subsequent data recording or forwarding to alternate pipelines and flows. Windows Event Tracing infrastructure is available to any vendor or application being deployed on Windows. -## API support - -These are the features planned to be supported by ETW exporter: - -- [x] OpenTelemetry Tracing API and SDK headers are **stable** and moving - towards GA. -- [ ] OpenTelemetry Logging API is work-in-progress, pending implementation of - [Latest Logging API spec - here](https://github.com/open-telemetry/oteps/pull/150) -- [ ] OpenTelemetry Metrics API is not implemented yet. - -Implementation of OpenTelemetry C++ SDK ETW exporter on Windows OS is `header -only` : - -- full definitions of all macros, functions and classes comprising the library -are visible to the compiler in a header file form. -- implementation does not need to be separately compiled, packaged and installed - in order to be used. - -All that is required is to point the compiler at the location of the headers, -and then `#include` the header files into the application source. Compiler's -optimizer can do a much better job when all the library's source code is -available. Several options below may be turned on to optimize the code with the -usage of standard C++ library, Microsoft Guidelines Support library, Google -Abseil Variant library. Or enabling support for non-standard features, such as -8-bit byte arrays support that enables performance-efficient representation of -binary blobs on ETW wire. - -## Example project - -The following include directories are required, relative to the top-level source -tree of OpenTelemetry C++ repo: - -- api/include/ -- exporters/etw/include/ -- sdk/include/ - -Code that instantiates ETW TracerProvider, subsequently obtaining a Tracer bound -to `OpenTelemetry-ETW-Provider`, and emitting a span named `MySpan` with -attributes on it, as well as `MyEvent` within that span. - -```cpp - -#include -#include - -#include "opentelemetry/exporters/etw/etw_tracer_exporter.h" - -using namespace OPENTELEMETRY_NAMESPACE; -using namespace opentelemetry::exporter::etw; - -// Supply unique instrumentation name (ETW Provider Name) here: -std::string providerName = "OpenTelemetry-ETW-Provider"; - -exporter::etw::TracerProvider tp; - -int main(int argc, const char* argv[]) -{ - // Obtain a Tracer object for instrumentation name. - // Each Tracer is associated with unique TraceId. - auto tracer = tp.GetTracer(providerName, "TLD"); - - // Properties is a helper class in ETW namespace that is otherwise compatible - // with Key-Value Iterable accepted by OpenTelemetry API. Using Properties - // should enable more efficient data transfer without unnecessary memcpy. - - // Span attributes - Properties attribs = - { - {"attrib1", 1}, - {"attrib2", 2} - }; - - // Start Span with attributes - auto span = tracer->StartSpan("MySpan", attribs); - - // Emit an event on Span - std::string eventName = "MyEvent1"; - Properties event = - { - {"uint32Key", (uint32_t)1234}, - {"uint64Key", (uint64_t)1234567890}, - {"strKey", "someValue"} - }; - span->AddEvent(eventName, event); - - // End Span. - span->End(); - - // Close the Tracer on application stop. - tracer->CloseWithMicroseconds(0); - - return 0; -} -``` - -Note that different `Tracer` objects may be bound to different ETW destinations. - -## Build options and Compiler Defines - -While including OpenTelemetry C++ SDK with ETW exporter, the customers are in -complete control of what options they would like to enable for their project -using `Preprocessor Definitions`. - -These options affect how "embedded in application" OpenTelemetry C++ SDK code is -compiled: - -| Name | Description | -|---------------------|------------------------------------------------------------------------------------------------------------------------| -| OPENTELEMETRY_STL_VERSION | Use STL classes for API surface. C++20 is recommended. Some customers may benefit from STL library provided with the compiler instead of using custom OpenTelemetry `nostd::` implementation due to security and performance considerations. | -| HAVE_GSL | Use [Microsoft GSL](https://github.com/microsoft/GSL) for `gsl::span` implementation. Library must be in include path. Microsoft GSL claims to be the most feature-complete implementation of `std::span`. It may be used instead of `nostd::span` implementation in projects that statically link OpenTelemetry SDK. | -| HAVE_TLD | Use ETW/TraceLogging Dynamic protocol. This is the default implementation compatible with existing C# "listeners" / "decoders" of ETW events. This option requires an additional optional Microsoft MIT-licensed `TraceLoggingDynamic.h` header. | - -## Debugging - -### ETW TraceLogging Dynamic Events - -ETW supports a mode that is called "Dynamic Manifest", where event may contain -strongly-typed key-value pairs, with primitive types such as `integer`, -`double`, `string`, etc. This mode requires `TraceLoggingDynamic.h` header. -Please refer to upstream repository containining [Microsoft TraceLogging Dynamic -framework](https://github.com/microsoft/tracelogging-dynamic-windows) licensed -under [MIT -License](https://github.com/microsoft/tracelogging-dynamic-windows/blob/main/LICENSE). - -Complete [list of ETW -types](https://docs.microsoft.com/en-us/windows/win32/wes/eventmanifestschema-outputtype-complextype#remarks). - -OpenTelemetry C++ ETW exporter implements the following type mapping: - -| OpenTelemetry C++ API type | ETW type | -|----------------------------|-----------------| -| bool | xs:byte | -| int (32-bit) | xs:int | -| int (64-bit) | xs:long | -| uint (32-bit) | xs:unsignedInt | -| uint (64-bit) | xs:unsignedLong | -| double | xs:double | -| string | win:Utf8 | - -Support for arrays of primitive types is not implemented yet. - -Visual Studio 2019 allows to use `View -> Other Windows -> Diagnostic Events` to -capture events that are emitted by instrumented application and sent to ETW -provider in a live view. Instrumentation name passed to `GetTracer` API above -corresponds to `ETW Provider Name`. If Instrumentation name contains a GUID - -starts with a curly brace, e.g. `{deadbeef-fade-dead-c0de-cafebabefeed}` then -the parameter is assumed to be `ETW Provider GUID`. - -Click on `Settings` and add the provider to monitor either by its Name or by -GUID. In above example, the provider name is `OpenTelemetry-ETW-Provider`. -Please refer to Diagnostic Events usage instructions -[here](https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-diagnostics-how-to-monitor-and-diagnose-services-locally#view-service-fabric-system-events-in-visual-studio) -to learn more. Note that running ETW Listener in Visual Studio requires -Elevation, i.e. Visual Studio would prompt you to confirm that you accept to run -the ETW Listener process as Administrator. This is a limitation of ETW -Listeners, they must be run as privileged process. - -### ETW events encoded in MessagePack - -OpenTelemetry ETW exporter optionally allows to encode the incoming event -payload using [MessagePack](https://msgpack.org/index.html) compact binary -protocol. ETW/MsgPack encoding requires -[nlohmann/json](https://github.com/nlohmann/json) library to be included in the -build of OpenTelemetry ETW exporter. Any recent version of `nlohmann/json` is -compatible with ETW exporter. For example, the version included in -`third_party/nlohmann-json` directory may be used. - -There is currently **no built-in decoder available** for this format. However, -there is ongoing effort to include the ETW/MsgPack decoder in -[Azure/diagnostics-eventflow](https://github.com/Azure/diagnostics-eventflow) -project, which may be used as a side-car listener to forward incoming -ETW/MsgPack events to many other destinations, such as: - -- StdOutput (console output) -- HTTP (json via http) -- Application Insights -- Azure EventHub -- Elasticsearch -- Azure Monitor Logs - -And community-contributed exporters: - -- Google Big Query output -- SQL Server output -- ReflectInsight output -- Splunk output - -[This PR](https://github.com/Azure/diagnostics-eventflow/pull/382) implements -the `Input adapter` for OpenTelemetry ETW/MsgPack protocol encoded events for -Azure EventFlow. - -Other standard tools for processing ETW events on Windows OS, such as: - -- [PerfView](https://github.com/microsoft/perfview) -- [PerfViewJS](https://github.com/microsoft/perfview/tree/main/src/PerfViewJS) - -will be augmented in future with support for ETW/MsgPack encoding. - -## Addendum - -This document needs to be supplemented with additional information: - -- [ ] mapping between OpenTelemetry fields and concepts and their corresponding - ETW counterparts -- [ ] links to E2E instrumentation example and ETW listener -- [ ] Logging API example -- [ ] Metrics API example (once Metrics spec is finalized) -- [ ] example how ETW Listener may employ OpenTelemetry .NET SDK to 1-1 - transform from ETW events back to OpenTelemetry flow -- [ ] links to NuGet package that contains the source code of SDK that includes - OpenTelemetry SDK and ETW exporter +It is recommended to consume this exporter via +[vcpkg](https://vcpkg.io/en/package/opentelemetry-cpp). From 994761988eed36a41014de6291d470c738190ae0 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 24 Oct 2024 14:32:48 +0200 Subject: [PATCH 68/71] [EXPORTER] Add logging for async gRPC errors (#3108) --- exporters/otlp/src/otlp_grpc_client.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index d3d59bce6e..44d86004a9 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -207,7 +207,7 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( stub->experimental_async() # endif ->Export(call_data->grpc_context.get(), call_data->request, call_data->response, - [call_data, async_data](::grpc::Status grpc_status) { + [call_data, async_data, export_data_name](::grpc::Status grpc_status) { --async_data->running_requests; ++async_data->finished_request_counter; @@ -216,6 +216,13 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( { call_data->export_result = opentelemetry::sdk::common::ExportResult::kSuccess; } + else + { + OTEL_INTERNAL_LOG_ERROR("[OTLP GRPC Client] ERROR: Export " + << export_data_name << " failed with status_code: \"" + << grpc_status.error_code() << "\" error_message: \"" + << grpc_status.error_message() << "\""); + } if (call_data->grpc_async_callback) { From 2c912d50a52b14761b37dfadd6d26723d1025a1a Mon Sep 17 00:00:00 2001 From: ColoredCarrot <7807570+ColoredCarrot@users.noreply.github.com> Date: Sat, 26 Oct 2024 01:16:10 +0200 Subject: [PATCH 69/71] [BUILD] Remove aligned_storage from nostd (#3112) std::aligned_storage was deprecated in C++23. Abseil removed its aligned_storage in https://github.com/abseil/abseil-cpp/commit/42133464db0ae5383fef723067835ef768b849f8 --- .../nostd/internal/absl/meta/type_traits.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h index 00c90f82d1..7fba912312 100644 --- a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h +++ b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h @@ -106,18 +106,6 @@ struct VoidTImpl { using type = void; }; -// This trick to retrieve a default alignment is necessary for our -// implementation of aligned_storage_t to be consistent with any implementation -// of std::aligned_storage. -template > -struct default_alignment_of_aligned_storage; - -template -struct default_alignment_of_aligned_storage> { - static constexpr size_t value = Align; -}; - //////////////////////////////// // Library Fundamentals V2 TS // //////////////////////////////// @@ -619,10 +607,6 @@ using remove_extent_t = typename std::remove_extent::type; template using remove_all_extents_t = typename std::remove_all_extents::type; -template ::value> -using aligned_storage_t = typename std::aligned_storage::type; - template using decay_t = typename std::decay::type; From 5e62859ffce873fd8f996d1c72d7a87f8f61f07b Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Sun, 27 Oct 2024 17:50:41 +0100 Subject: [PATCH 70/71] [EXPORTER] Elastic Search exporter follow ECS guidelines (#3107) * [EXPORTERS]: elastic search log message within `message` key instead of `body` According to ECS logging reference https://www.elastic.co/guide/en/ecs/8.11/ecs-base.html#field-message Refs #3091 * [EXPORTERS]: elastic search set severity within `log.level` key instead of `severity` According to ECS logging reference https://www.elastic.co/guide/en/ecs/8.11/ecs-log.html#field-log-level Refs #3091 * [EXPORTERS]: elastic search set timestamp within `@timestamp` instead of `timestamp` Also changes the format to be a Date string. According to ECS logging reference https://www.elastic.co/guide/en/ecs/8.11/ecs-base.html#field-timestamp Refs #3091 * [EXPORTERS]: elastic search set instrumentation scope within `log.logger` instead of `name` According to ECS logging reference https://www.elastic.co/guide/en/ecs/8.11/ecs-log.html#field-log-logger Refs #3091 * EXPORTERS]: elastic search recorable constructor sets `ecs.version` field to 8.11.0 According to ECS guidelines this field is mandatory https://www.elastic.co/guide/en/ecs/8.11/ecs-guidelines.html Refs #3091 * [EXPORTERS]: elastic search put attributes in json root instead of under `attributes` This allows user to set other fields that are part of the [ECS log documentation](https://www.elastic.co/guide/en/ecs/8.11/ecs-log.html). For instance, it allows to have an attribute with key `log.file`, that will, thanks to `nlohmann::json`, appear as : ``` { "log": { "file": "xxx" } } ``` Closes #3091 --- .../elasticsearch/es_log_recordable.h | 2 + .../elasticsearch/src/es_log_recordable.cc | 50 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h index af4ccb16ef..52d24cada6 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -42,6 +42,8 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable void WriteValue(const opentelemetry::common::AttributeValue &value, const std::string &name); public: + ElasticSearchRecordable() noexcept; + /** * Returns a JSON object contain the log information */ diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 663691273b..56d7cea71b 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -197,6 +197,11 @@ void ElasticSearchRecordable::WriteValue(const opentelemetry::common::AttributeV } } +ElasticSearchRecordable::ElasticSearchRecordable() noexcept : sdk::logs::Recordable() +{ + json_["ecs"]["version"] = "8.11.0"; +} + nlohmann::json ElasticSearchRecordable::GetJSON() noexcept { return json_; @@ -205,7 +210,38 @@ nlohmann::json ElasticSearchRecordable::GetJSON() noexcept void ElasticSearchRecordable::SetTimestamp( opentelemetry::common::SystemTimestamp timestamp) noexcept { - json_["timestamp"] = timestamp.time_since_epoch().count(); + const std::chrono::system_clock::time_point timePoint{timestamp}; + + // If built with with at least cpp 20 then use std::format + // Otherwise use the old style to format the timestamp in UTC +#if __cplusplus >= 202002L + const std::string dateStr = std::format("{:%FT%T%Ez}", timePoint); +#else + const static int dateToSecondsSize = 19; + const static int millisecondsSize = 8; + const static int timeZoneSize = 1; + const static int dateSize = dateToSecondsSize + millisecondsSize + timeZoneSize; + + std::time_t time = std::chrono::system_clock::to_time_t(timePoint); + std::tm tm = *std::gmtime(&time); + + char bufferDate[dateSize]; // example: 2024-10-18T07:26:00.123456Z + std::strftime(bufferDate, sizeof(bufferDate), "%Y-%m-%dT%H:%M:%S", &tm); + auto microseconds = + std::chrono::duration_cast(timePoint.time_since_epoch()) % + std::chrono::seconds(1); + + char bufferMilliseconds[millisecondsSize]; + std::snprintf(bufferMilliseconds, sizeof(bufferMilliseconds), ".%06ld", + static_cast(microseconds.count())); + + std::strcat(bufferDate, bufferMilliseconds); + std::strcat(bufferDate, "Z"); + + const std::string dateStr(bufferDate); +#endif + + json_["@timestamp"] = dateStr; } void ElasticSearchRecordable::SetObservedTimestamp( @@ -216,23 +252,25 @@ void ElasticSearchRecordable::SetObservedTimestamp( void ElasticSearchRecordable::SetSeverity(opentelemetry::logs::Severity severity) noexcept { + auto &severityField = json_["log"]["level"]; + // Convert the severity enum to a string std::uint32_t severity_index = static_cast(severity); if (severity_index >= std::extent::value) { std::stringstream sout; sout << "Invalid severity(" << severity_index << ")"; - json_["severity"] = sout.str(); + severityField = sout.str(); } else { - json_["severity"] = opentelemetry::logs::SeverityNumToText[severity_index]; + severityField = opentelemetry::logs::SeverityNumToText[severity_index]; } } void ElasticSearchRecordable::SetBody(const opentelemetry::common::AttributeValue &message) noexcept { - WriteValue(message, "body"); + WriteValue(message, "message"); } void ElasticSearchRecordable::SetTraceId(const opentelemetry::trace::TraceId &trace_id) noexcept @@ -275,7 +313,7 @@ void ElasticSearchRecordable::SetAttribute( nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept { - WriteKeyValue(key, value, "attributes"); + WriteValue(value, key.data()); } void ElasticSearchRecordable::SetResource( @@ -291,7 +329,7 @@ void ElasticSearchRecordable::SetInstrumentationScope( const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope) noexcept { - json_["name"] = instrumentation_scope.GetName(); + json_["log"]["logger"] = instrumentation_scope.GetName(); } } // namespace logs From 6292a6a74e83f93c8270a0d2973f5702b34a1fa8 Mon Sep 17 00:00:00 2001 From: tobim Date: Wed, 30 Oct 2024 18:27:15 +0100 Subject: [PATCH 71/71] [INSTALL] Resolve dependencies in opentelemetry-cpp-config.cmake (#3094) * Resolve dependencies in opentelemetry-cpp-config.cmake Before this change, consumers of the exported CMake targets had to know which dependencies are needed to get the transitive target dependencies like `absl::*`, `gRPC::grpc++`, or `protobuf::libprotobuf`. * Add find_dependency calls for remaining deps Now we also resolve `OpenTracing`, and `prometheus-cpp`. If necessary, `CURL` and `ZLIB` are also resolved. --------- Co-authored-by: Marc Alff Co-authored-by: Lalit Kumar Bhasin --- cmake/opentelemetry-cpp-config.cmake.in | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 36215c8af7..f5c6e5e722 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -70,7 +70,39 @@ set(OPENTELEMETRY_VERSION # ############################################################################## -find_package(Threads) +include(CMakeFindDependencyMacro) + +find_dependency(Threads) + +if(@WITH_ABSEIL@) + find_dependency(absl) +endif() + +if(@WITH_OTLP_GRPC@) + find_dependency(gRPC) +endif() + +if("@OpenTracing_FOUND@") + find_dependency(OpenTracing) +endif() + +if("@prometheus-cpp_FOUND@") + find_dependency(prometheus-cpp) +endif() + +if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@") + find_dependency(Protobuf) +endif() + +if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) + if("@CURL_FOUND@") + find_dependency(CURL) + endif() + + if("@ZLIB_FOUND@") + find_dependency(ZLIB) + endif() +endif() set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")