From 5e290c909d208915f4cb6383c225279f63889a26 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 26 May 2023 02:42:54 -0700 Subject: [PATCH 001/119] [DOC] Small fix for Histogram documentation. (#2156) --- api/include/opentelemetry/metrics/sync_instruments.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index b81a412680..b26e527c2c 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -97,14 +97,14 @@ class Histogram : public SynchronousInstrument /** * Records a value. * - * @param value The increment amount. May be positive, negative or zero. + * @param value The measurement value. MUST be non-negative. */ virtual void Record(T value, const context::Context &context) noexcept = 0; /** * Records a value with a set of attributes. * - * @param value The increment amount. May be positive, negative or zero. + * @param value The measurement value. MUST be non-negative. * @param attributes A set of attributes to associate with the count. */ virtual void Record(T value, From 3707bc04e0000a17710d0e52bb6940f1162b5da0 Mon Sep 17 00:00:00 2001 From: Bailey Chittle <39804642+bachittle@users.noreply.github.com> Date: Fri, 26 May 2023 07:39:29 -0400 Subject: [PATCH 002/119] [BUILD] Fixing CMake to build GTest on Windows (#1887) --- CMakeLists.txt | 10 ++++++++-- test_common/src/http/client/nosend/CMakeLists.txt | 4 ++-- tools/setup-buildtools.cmd | 4 +--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbfb6a209d..96941f0d91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,7 +278,12 @@ function(install_windows_deps) COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/setup-buildtools.cmd) set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tools/vcpkg/scripts/buildsystems/vcpkg.cmake - PARENT_SCOPE) + CACHE FILEPATH "") + message( + "Make sure that vcpkg.cmake is set as the CMAKE_TOOLCHAIN_FILE at the START of the cmake build process! + Can be command-line arg (cmake -DCMAKE_TOOLCHAIN_FILE=...) or set in your editor of choice." + ) + endfunction() function(set_target_version target_name) @@ -548,9 +553,10 @@ if(BUILD_TESTING) ${CMAKE_BINARY_DIR}/lib/libgmock.a) elseif(WIN32) # Make sure we are always bootsrapped with vcpkg on Windows - find_package(GTest REQUIRED) + find_package(GTest) if(NOT (GTEST_FOUND OR GTest_FOUND)) install_windows_deps() + include(${CMAKE_TOOLCHAIN_FILE}) find_package(GTest REQUIRED) endif() else() diff --git a/test_common/src/http/client/nosend/CMakeLists.txt b/test_common/src/http/client/nosend/CMakeLists.txt index 071e109fe5..1f32861b41 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} ${GMOCK_LIB} - opentelemetry_ext opentelemetry_test_common) + opentelemetry_http_client_nosend ${GTEST_BOTH_LIBRARIES} opentelemetry_ext + opentelemetry_test_common) endif() diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index 43be03a267..c9a9d9ca2b 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -9,6 +9,7 @@ if defined VCPKG_ROOT ( set "PATH=%VCPKG_ROOT%;%PATH%" ) else ( set "PATH=%~dp0vcpkg;%PATH%" + set "VCPKG_ROOT=%~dp0vcpkg" ) pushd %~dp0 @@ -53,9 +54,6 @@ where /Q vcpkg.exe if %ERRORLEVEL% == 1 ( REM Build our own vcpkg from source REM Prefer building in VCPKG_ROOT - if not defined VCPKG_ROOT ( - set "VCPKG_ROOT=%~dp0\vcpkg" - ) pushd "!VCPKG_ROOT!" call bootstrap-vcpkg.bat popd From f55346262bd58ce35461a51f267d0bbb85d79541 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 26 May 2023 20:01:50 +0200 Subject: [PATCH 003/119] [CI] Add a C++11 build (#2152) --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ ci/do_ci.sh | 25 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17465af27d..8ac8999459 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,43 @@ jobs: sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.test + # + # This build uses the latest libraries compatible + # with C++11 + # + cmake_gcc_maintainer_cpp11_async_test: + name: CMake gcc 12 (maintainer mode, C++11, async) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + env: + CC: /usr/bin/gcc-12 + CXX: /usr/bin/g++-12 + GOOGLETEST_VERSION: 1.12.1 + PROTOBUF_VERSION: 21.12 + run: | + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/install_protobuf.sh + - name: run cmake gcc (maintainer mode, C++11, async) + env: + CC: /usr/bin/gcc-12 + CXX: /usr/bin/g++-12 + run: | + ./ci/do_ci.sh cmake.maintainer.cpp11.async.test + - name: generate test cert + env: + CFSSL_VERSION: 1.6.3 + run: | + sudo -E ./tools/setup-cfssl.sh + (cd ./functional/cert; ./generate_cert.sh) + - name: run func test + run: | + (cd ./functional/otlp; ./run_test.sh) + cmake_gcc_maintainer_sync_test: name: CMake gcc 12 (maintainer mode, sync) runs-on: ubuntu-latest diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 64d3b72308..04fdbc483c 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -138,6 +138,31 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then make -k -j $(nproc) make test exit 0 +elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=11 \ + -DWITH_OTLP=ON \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ + -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ + -DWITH_ZIPKIN=ON \ + -DWITH_JAEGER=OFF \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_LOGS_PREVIEW=ON \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DOTELCPP_MAINTAINER_MODE=ON \ + -DWITH_NO_DEPRECATED_CODE=ON \ + "${SRC_DIR}" + make -k -j $(nproc) + make test + exit 0 elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * From 8b7f9b4209498ffe7e7aea6e7df91576aeaf5446 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Sat, 27 May 2023 16:17:44 +0800 Subject: [PATCH 004/119] Change OTLP Json field name to camelCase (#2162) --- exporters/otlp/src/otlp_http_client.cc | 2 +- .../otlp/test/otlp_http_exporter_test.cc | 12 ++-- .../otlp_http_log_record_exporter_test.cc | 30 ++++---- .../test/otlp_http_metric_exporter_test.cc | 70 +++++++++---------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 5cbc65952c..efb60ff982 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -451,7 +451,7 @@ static void ConvertGenericMessageToJson(nlohmann::json &value, { const google::protobuf::FieldDescriptor *field_descriptor = fields_with_data[i]; nlohmann::json &child_value = options.use_json_name ? value[field_descriptor->json_name()] - : value[field_descriptor->name()]; + : value[field_descriptor->camelcase_name()]; if (field_descriptor->is_repeated()) { ConvertListFieldToJson(child_value, message, field_descriptor, options); diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 007cd56249..9c5bfe1766 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -165,10 +165,10 @@ class OtlpHttpExporterTestPeer : public ::testing::Test std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resource_spans"].begin(); - auto scope_span = *resource_span["scope_spans"].begin(); + 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["trace_id"].get(); + 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"); @@ -256,10 +256,10 @@ class OtlpHttpExporterTestPeer : public ::testing::Test std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resource_spans"].begin(); - auto scope_span = *resource_span["scope_spans"].begin(); + 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["trace_id"].get(); + 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"); 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 aa55e7fc7c..aba1c9c503 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -160,15 +160,15 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resource_logs"].begin(); - auto scope_logs = *resource_logs["scope_logs"].begin(); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); auto scope = scope_logs["scope"]; - auto log = *scope_logs["log_records"].begin(); - auto received_trace_id = log["trace_id"].get(); - auto received_span_id = log["span_id"].get(); + 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"]["string_value"].get()); + 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()); @@ -188,7 +188,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test if ("scope_key1" == attribute["key"]) { check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["string_value"].get()); + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); } } ASSERT_TRUE(check_scope_attribute); @@ -277,21 +277,21 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resource_logs"].begin(); - auto scope_logs = *resource_logs["scope_logs"].begin(); - auto schema_url = scope_logs["schema_url"].get(); + 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["log_records"].begin(); - auto received_trace_id = log["trace_id"].get(); - auto received_span_id = log["span_id"].get(); + 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"]["string_value"].get()); + 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()); @@ -311,7 +311,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test if ("scope_key1" == attribute["key"]) { check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["string_value"].get()); + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); } } ASSERT_TRUE(check_scope_attribute); diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 27f4614157..c47c86e110 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -160,8 +160,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_metrics = *check_json["resource_metrics"].begin(); - auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + 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()); @@ -171,9 +171,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); - auto data_points = metric["sum"]["data_points"]; - EXPECT_EQ(10.0, data_points[0]["as_double"].get()); - EXPECT_EQ(20.0, data_points[1]["as_double"].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()); @@ -341,8 +341,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_metrics = *check_json["resource_metrics"].begin(); - auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + 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()); @@ -352,9 +352,9 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); - auto data_points = metric["gauge"]["data_points"]; - EXPECT_EQ(10.0, data_points[0]["as_double"].get()); - EXPECT_EQ(20l, JsonToInteger(data_points[1]["as_int"])); + 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()); @@ -536,8 +536,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_metrics = *check_json["resource_metrics"].begin(); - auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + 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()); @@ -547,43 +547,43 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); - auto data_points = metric["histogram"]["data_points"]; + 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]["bucket_counts"].size()); - if (4 == data_points[0]["bucket_counts"].size()) + EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); + if (4 == data_points[0]["bucketCounts"].size()) { - EXPECT_EQ(200, JsonToInteger(data_points[0]["bucket_counts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[0]["bucket_counts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[0]["bucket_counts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[0]["bucket_counts"][3])); + 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]["explicit_bounds"].size()); - if (3 == data_points[0]["explicit_bounds"].size()) + EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); + if (3 == data_points[0]["explicitBounds"].size()) { - EXPECT_EQ(10.1, data_points[0]["explicit_bounds"][0].get()); - EXPECT_EQ(20.2, data_points[0]["explicit_bounds"][1].get()); - EXPECT_EQ(30.2, data_points[0]["explicit_bounds"][2].get()); + 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]["bucket_counts"].size()); - if (4 == data_points[1]["bucket_counts"].size()) + EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); + if (4 == data_points[1]["bucketCounts"].size()) { - EXPECT_EQ(200, JsonToInteger(data_points[1]["bucket_counts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[1]["bucket_counts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[1]["bucket_counts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[1]["bucket_counts"][3])); + 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]["explicit_bounds"].size()); - if (3 == data_points[1]["explicit_bounds"].size()) + EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); + if (3 == data_points[1]["explicitBounds"].size()) { - EXPECT_EQ(10.0, data_points[1]["explicit_bounds"][0].get()); - EXPECT_EQ(20.0, data_points[1]["explicit_bounds"][1].get()); - EXPECT_EQ(30.0, data_points[1]["explicit_bounds"][2].get()); + 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"); From 0eca570bbf93019f28843488e5a7474abae36ca3 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 31 May 2023 18:47:41 +0200 Subject: [PATCH 005/119] [EXPORTER] Support empty arrays in `OtlpRecordable` attributes (#2166) --- .../otlp/src/otlp_populate_attribute_utils.cc | 45 ++++++++++++------- exporters/otlp/test/otlp_recordable_test.cc | 23 ++++++++++ 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/exporters/otlp/src/otlp_populate_attribute_utils.cc b/exporters/otlp/src/otlp_populate_attribute_utils.cc index d86953506c..69a284835a 100644 --- a/exporters/otlp/src/otlp_populate_attribute_utils.cc +++ b/exporters/otlp/src/otlp_populate_attribute_utils.cc @@ -67,58 +67,66 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_bool_value(val); + array_value->add_values()->set_bool_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_double_value(val); + array_value->add_values()->set_double_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_string_value(val.data(), val.size()); + array_value->add_values()->set_string_value(val.data(), val.size()); } } } @@ -168,51 +176,58 @@ void OtlpPopulateAttributeUtils::PopulateAnyValue( } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_bool_value(val); + array_value->add_values()->set_bool_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_int_value(val); + array_value->add_values()->set_int_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_double_value(val); + array_value->add_values()->set_double_value(val); } } else if (nostd::holds_alternative>(value)) { + auto array_value = proto_value->mutable_array_value(); for (const auto &val : nostd::get>(value)) { - proto_value->mutable_array_value()->add_values()->set_string_value(val); + array_value->add_values()->set_string_value(val); } } } diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index abad2991b7..f1b1c73741 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -284,6 +284,29 @@ TEST(OtlpRecordable, SetArrayAttribute) } } +template +struct EmptyArrayAttributeTest : public testing::Test +{ + using ElementType = T; +}; + +using ArrayElementTypes = + testing::Types; +TYPED_TEST_SUITE(EmptyArrayAttributeTest, ArrayElementTypes); + +// Test empty arrays. +TYPED_TEST(EmptyArrayAttributeTest, SetEmptyArrayAttribute) +{ + using ArrayElementType = typename TestFixture::ElementType; + OtlpRecordable rec; + + nostd::span span = {}; + rec.SetAttribute("empty_arr_attr", span); + + EXPECT_TRUE(rec.span().attributes(0).value().has_array_value()); + EXPECT_TRUE(rec.span().attributes(0).value().array_value().values().empty()); +} + /** * AttributeValue can contain different int types, such as int, int64_t, * unsigned int, and uint64_t. To avoid writing test cases for each, we can From 8ba95296e4c93f85d43f482c553a0c2b89acfb02 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 31 May 2023 12:06:18 -0700 Subject: [PATCH 006/119] [BUILD] Remove option WITH_OTLP (#2161) --- CMakeLists.txt | 24 +++++++++--------------- CMakeSettings.json | 10 +++++----- INSTALL.md | 3 ++- ci/do_ci.sh | 13 +++++-------- docker/Dockerfile | 2 +- docker/Dockerfile.centos | 3 ++- docker/ubuntuLatest/Dockerfile | 3 ++- exporters/CMakeLists.txt | 2 +- 8 files changed, 27 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96941f0d91..37e0be94a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,15 +159,16 @@ if(WITH_STL) endif() endif() -option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF) - -if(WITH_OTLP) +if(DEFINED WITH_OTLP) message( - WARNING - "WITH_OTLP is deprecated and will be removed in future. Please set either WITH_OTLP_GRPC or WITH_OTLP_HTTP, or even both." + 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 "Whether to include the OTLP gRPC exporter in the SDK" + OFF) + option(WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" OFF) @@ -355,11 +356,10 @@ if(WITH_PROMETHEUS) endif() endif() -if(WITH_OTLP) +if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) set(protobuf_MODULE_COMPATIBLE ON) find_package(Protobuf) - if(WITH_OTLP_GRPC OR (NOT DEFINED WITH_OTLP_GRPC AND NOT DEFINED - CACHE{WITH_OTLP_GRPC})) + if(WITH_OTLP_GRPC) find_package(gRPC) endif() if((NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) OR (NOT gRPC_FOUND)) @@ -377,9 +377,7 @@ if(WITH_OTLP) if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) find_package(Protobuf REQUIRED) endif() - if(NOT gRPC_FOUND - AND (WITH_OTLP_GRPC OR (NOT DEFINED WITH_OTLP_GRPC - AND NOT DEFINED CACHE{WITH_OTLP_GRPC}))) + if(NOT gRPC_FOUND AND WITH_OTLP_GRPC) find_package(gRPC) endif() if(WIN32) @@ -397,10 +395,6 @@ if(WITH_OTLP) endif() include(CMakeDependentOption) - cmake_dependent_option( - WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON - "gRPC_FOUND" OFF) - message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}") include(cmake/opentelemetry-proto.cmake) endif() diff --git a/CMakeSettings.json b/CMakeSettings.json index 4890a66411..02d068a3a1 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -14,7 +14,7 @@ "ctestCommandArgs": "", "variables": [ { - "name": "WITH_OTLP", + "name": "WITH_OTLP_GRPC", "value": "True", "type": "BOOL" }, @@ -40,7 +40,7 @@ "cmakeToolchain": "", "variables": [ { - "name": "WITH_OTLP", + "name": "WITH_OTLP_GRPC", "value": "True", "type": "BOOL" }, @@ -70,7 +70,7 @@ "type": "BOOL" }, { - "name": "WITH_OTLP", + "name": "WITH_OTLP_GRPC", "value": "True", "type": "BOOL" }, @@ -106,7 +106,7 @@ "type": "BOOL" }, { - "name": "WITH_OTLP", + "name": "WITH_OTLP_GRPC", "value": "True", "type": "BOOL" }, @@ -123,4 +123,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/INSTALL.md b/INSTALL.md index a5fb65f9ad..48d1ee8a45 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -82,7 +82,8 @@ You can link OpenTelemetry C++ SDK with libraries provided in - `-DBUILD_SHARED_LIBS=ON` : To build shared libraries for the targets. Please refer to note [below](#building-shared-libs-for-windows) for Windows DLL support. - - `-DWITH_OTLP=ON` : To enable building OTLP exporter. + - `-DWITH_OTLP_GRPC=ON` : To enable building OTLP GRPC exporter. + - `-DWITH_OTLP_HTTP=ON` : To enable building OTLP HTTP exporter. - `-DWITH_PROMETHEUS=ON` : To enable building prometheus exporter. 3. Once the build configuration is created, build the CMake targets - this diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 04fdbc483c..d504b33ae8 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -94,7 +94,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -118,7 +117,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -143,7 +141,6 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_STANDARD=11 \ - -DWITH_OTLP=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -245,7 +242,7 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then ${SRC_DIR}/tools/build-benchmark.sh cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_STANDARD=11 \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ "${SRC_DIR}" @@ -259,7 +256,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ "${SRC_DIR}" grpc_cpp_plugin=`which grpc_cpp_plugin` @@ -272,7 +269,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]] cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DBUILD_SHARED_LIBS=ON \ "${SRC_DIR}" @@ -286,7 +283,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ "${SRC_DIR}" @@ -300,7 +297,7 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOPENTELEMETRY_INSTALL=OFF \ diff --git a/docker/Dockerfile b/docker/Dockerfile index 412f997747..75360e6cbb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -28,8 +28,8 @@ RUN git clone --recurse-submodules -j ${CORES} --depth=1 \ -DWITH_JAEGER=ON \ -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ -DBUILD_TESTING=OFF \ - -DWITH_OTLP=ON \ -DWITH_OTLP_GRPC=ON \ + -DWITH_OTLP_HTTP=ON \ -DBUILD_SHARED_LIBS=ON \ .. \ && cmake --build . -j ${CORES} --target install diff --git a/docker/Dockerfile.centos b/docker/Dockerfile.centos index c95595691b..25a6f2442f 100644 --- a/docker/Dockerfile.centos +++ b/docker/Dockerfile.centos @@ -80,6 +80,7 @@ RUN git clone --depth=1 https://github.com/open-telemetry/opentelemetry-cpp.git -DWITH_ZIPKIN=ON \ -DWITH_JAEGER=ON \ -DBUILD_TESTING=OFF \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ + -DWITH_OTLP_HTTP=ON \ .. \ && make -j${nproc} install && ldconfig diff --git a/docker/ubuntuLatest/Dockerfile b/docker/ubuntuLatest/Dockerfile index 5e13a7d3b8..aec2296401 100644 --- a/docker/ubuntuLatest/Dockerfile +++ b/docker/ubuntuLatest/Dockerfile @@ -59,7 +59,8 @@ RUN apt-get install -y --no-install-recommends libcurl4-openssl-dev && git clone -DWITH_ZIPKIN=ON \ -DWITH_JAEGER=ON \ -DBUILD_TESTING=OFF \ - -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ + -DWITH_OTLP_HTTP=ON \ .. && \ make -j${nproc} install && ldconfig && \ cd ../.. diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt index f852f420f5..d980fbd838 100644 --- a/exporters/CMakeLists.txt +++ b/exporters/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -if(WITH_OTLP) +if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) add_subdirectory(otlp) endif() From f5fd9062de9dcd3c694769e34d47c0142227ab90 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin Date: Thu, 1 Jun 2023 00:14:39 -0700 Subject: [PATCH 007/119] [SDK] Add AdaptingCircularBufferCounter for exponential histograms (#2158) --- .../sdk/metrics/data/circular_buffer.h | 158 +++++++++++++++ sdk/src/metrics/CMakeLists.txt | 1 + sdk/src/metrics/data/circular_buffer.cc | 182 ++++++++++++++++++ sdk/test/metrics/BUILD | 15 ++ sdk/test/metrics/CMakeLists.txt | 1 + .../metrics/circular_buffer_counter_test.cc | 149 ++++++++++++++ 6 files changed, 506 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h create mode 100644 sdk/src/metrics/data/circular_buffer.cc create mode 100644 sdk/test/metrics/circular_buffer_counter_test.cc diff --git a/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h new file mode 100644 index 0000000000..1608a3a011 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h @@ -0,0 +1,158 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/nostd/variant.h" + +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +/** + * An integer array that automatically expands its memory consumption (via copy/allocation) when + * reaching limits. This assumes counts remain low, to lower memory overhead. + * + * This class is NOT thread-safe. It is expected to be behind a synchronized incrementer. + * + * Instances start by attempting to store one-byte per-cell in the integer array. As values grow, + * this will automatically instantiate the next-size integer array (uint8_t -> uint16_t -> uint32_t + * -> uint64_t) and copy over values into the larger array. This class expects most usage to remain + * within the uint8_t boundary (e.g. cell values < 256). + */ +class AdaptingIntegerArray +{ +public: + // Construct an adapting integer array of a given size. + explicit AdaptingIntegerArray(size_t size) : backing_(std::vector(size, 0)) {} + AdaptingIntegerArray(const AdaptingIntegerArray &other) = default; + AdaptingIntegerArray(AdaptingIntegerArray &&other) = default; + AdaptingIntegerArray &operator=(const AdaptingIntegerArray &other) = default; + AdaptingIntegerArray &operator=(AdaptingIntegerArray &&other) = default; + + /** + * Increments the value at the specified index by the given count in the array. + * + * @param index The index of the value to increment. + * @param count The count by which to increment the value. + */ + void Increment(size_t index, uint64_t count); + + /** + * Returns the value at the specified index from the array. + * + * @param index The index of the value to retrieve. + * @return The value at the specified index. + */ + uint64_t Get(size_t index) const; + + /** + * Returns the size of the array. + * + * @return The size of the array. + */ + size_t Size() const; + + /** + * Clears the array, resetting all values to zero. + */ + void Clear(); + +private: + void EnlargeToFit(uint64_t value); + + nostd::variant, + std::vector, + std::vector, + std::vector> + backing_; +}; + +/** + * A circle-buffer-backed exponential counter. + * + * The first recorded value becomes the 'base_index'. Going backwards leads to start/stop index. + * + * This expand start/end index as it sees values. + * + * This class is NOT thread-safe. It is expected to be behind a synchronized incrementer. + */ +class AdaptingCircularBufferCounter +{ +public: + explicit AdaptingCircularBufferCounter(size_t max_size) : backing_(max_size) {} + AdaptingCircularBufferCounter(const AdaptingCircularBufferCounter &other) = default; + AdaptingCircularBufferCounter(AdaptingCircularBufferCounter &&other) = default; + AdaptingCircularBufferCounter &operator=(const AdaptingCircularBufferCounter &other) = default; + AdaptingCircularBufferCounter &operator=(AdaptingCircularBufferCounter &&other) = default; + + /** + * The first index with a recording. May be negative. + * + * Note: the returned value is not meaningful when Empty returns true. + * + * @return the first index with a recording. + */ + int32_t StartIndex() const { return start_index_; } + + /** + * The last index with a recording. May be negative. + * + * Note: the returned value is not meaningful when Empty returns true. + * + * @return The last index with a recording. + */ + int32_t EndIndex() const { return end_index_; } + + /** + * Returns true if no recordings, false if at least one recording. + */ + bool Empty() const { return base_index_ == kNullIndex; } + + /** + * Returns the maximum number of buckets allowed in this counter. + */ + size_t MaxSize() const { return backing_.Size(); } + + /** Resets all bucket counts to zero and resets index start/end tracking. **/ + void Clear(); + + /** + * Persist new data at index, incrementing by delta amount. + * + * @param index The index of where to perform the incrementation. + * @param delta How much to increment the index by. + * @return success status. + */ + bool Increment(int32_t index, uint64_t delta); + + /** + * Get the number of recordings for the given index. + * + * @return the number of recordings for the index, or 0 if the index is out of bounds. + */ + uint64_t Get(int32_t index); + +private: + size_t ToBufferIndex(int32_t index) const; + + static constexpr int32_t kNullIndex = std::numeric_limits::min(); + + // Index of the first populated element, may be kNullIndex if container is empty. + int32_t start_index_ = kNullIndex; + // Index of the last populated element, may be kNullIndex if container is empty. + int32_t end_index_ = kNullIndex; + // Index corresponding to the element located at the start of the backing array, may be kNullIndex + // if container is empty. + int32_t base_index_ = kNullIndex; + AdaptingIntegerArray backing_; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index 46d6d67212..db8283fc43 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -17,6 +17,7 @@ add_library( aggregation/histogram_aggregation.cc aggregation/lastvalue_aggregation.cc aggregation/sum_aggregation.cc + data/circular_buffer.cc exemplar/filter.cc exemplar/reservoir.cc sync_instruments.cc) diff --git a/sdk/src/metrics/data/circular_buffer.cc b/sdk/src/metrics/data/circular_buffer.cc new file mode 100644 index 0000000000..9117e67ae5 --- /dev/null +++ b/sdk/src/metrics/data/circular_buffer.cc @@ -0,0 +1,182 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/data/circular_buffer.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +namespace +{ + +struct AdaptingIntegerArrayIncrement +{ + size_t index; + uint64_t count; + + template + uint64_t operator()(std::vector &backing) + { + const uint64_t result = backing[index] + count; + OPENTELEMETRY_LIKELY_IF(result <= uint64_t(std::numeric_limits::max())) + { + backing[index] = static_cast(result); + return 0; + } + return result; + } +}; + +struct AdaptingIntegerArrayGet +{ + size_t index; + + template + uint64_t operator()(const std::vector &backing) + { + return backing[index]; + } +}; + +struct AdaptingIntegerArraySize +{ + template + size_t operator()(const std::vector &backing) + { + return backing.size(); + } +}; + +struct AdaptingIntegerArrayClear +{ + template + void operator()(std::vector &backing) + { + std::fill(backing.begin(), backing.end(), static_cast(0)); + } +}; + +struct AdaptingIntegerArrayCopy +{ + template + void operator()(const std::vector &from, std::vector &to) + { + for (size_t i = 0; i < from.size(); i++) + { + to[i] = static_cast(from[i]); + } + } +}; + +} // namespace + +void AdaptingIntegerArray::Increment(size_t index, uint64_t count) +{ + const uint64_t result = nostd::visit(AdaptingIntegerArrayIncrement{index, count}, backing_); + OPENTELEMETRY_LIKELY_IF(result == 0) { return; } + EnlargeToFit(result); + Increment(index, count); +} + +uint64_t AdaptingIntegerArray::Get(size_t index) const +{ + return nostd::visit(AdaptingIntegerArrayGet{index}, backing_); +} + +size_t AdaptingIntegerArray::Size() const +{ + return nostd::visit(AdaptingIntegerArraySize{}, backing_); +} + +void AdaptingIntegerArray::Clear() +{ + nostd::visit(AdaptingIntegerArrayClear{}, backing_); +} + +void AdaptingIntegerArray::EnlargeToFit(uint64_t value) +{ + const size_t backing_size = Size(); + decltype(backing_) backing; + if (value <= std::numeric_limits::max()) + { + backing = std::vector(backing_size, 0); + } + else if (value <= std::numeric_limits::max()) + { + backing = std::vector(backing_size, 0); + } + else + { + backing = std::vector(backing_size, 0); + } + std::swap(backing_, backing); + nostd::visit(AdaptingIntegerArrayCopy{}, backing, backing_); +} + +void AdaptingCircularBufferCounter::Clear() +{ + start_index_ = kNullIndex; + end_index_ = kNullIndex; + base_index_ = kNullIndex; + backing_.Clear(); +} + +bool AdaptingCircularBufferCounter::Increment(int32_t index, uint64_t delta) +{ + if (Empty()) + { + start_index_ = index; + end_index_ = index; + base_index_ = index; + backing_.Increment(0, delta); + return true; + } + + if (index > end_index_) + { + // Move end, check max size. + if (index + 1 > static_cast(backing_.Size()) + start_index_) + { + return false; + } + end_index_ = index; + } + else if (index < start_index_) + { + // Move end, check max size. + if (end_index_ + 1 > static_cast(backing_.Size()) + index) + { + return false; + } + start_index_ = index; + } + backing_.Increment(ToBufferIndex(index), delta); + return true; +} + +uint64_t AdaptingCircularBufferCounter::Get(int32_t index) +{ + if (index < start_index_ || index > end_index_) + { + return 0; + } + return backing_.Get(ToBufferIndex(index)); +} + +size_t AdaptingCircularBufferCounter::ToBufferIndex(int32_t index) const +{ + // Figure out the index relative to the start of the circular buffer. + if (index < base_index_) + { + // If index is before the base one, wrap around. + return static_cast(index + backing_.Size() - base_index_); + } + return static_cast(index - base_index_); +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/metrics/BUILD b/sdk/test/metrics/BUILD index d7ed9e5fb6..df56f9c67d 100644 --- a/sdk/test/metrics/BUILD +++ b/sdk/test/metrics/BUILD @@ -270,6 +270,21 @@ cc_test( ], ) +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 = "histogram_aggregation_test", srcs = [ diff --git a/sdk/test/metrics/CMakeLists.txt b/sdk/test/metrics/CMakeLists.txt index c167a27dd5..47598fbbb8 100644 --- a/sdk/test/metrics/CMakeLists.txt +++ b/sdk/test/metrics/CMakeLists.txt @@ -14,6 +14,7 @@ foreach( histogram_aggregation_test attributes_processor_test attributes_hashmap_test + circular_buffer_counter_test histogram_test sync_metric_storage_counter_test sync_metric_storage_histogram_test diff --git a/sdk/test/metrics/circular_buffer_counter_test.cc b/sdk/test/metrics/circular_buffer_counter_test.cc new file mode 100644 index 0000000000..a8218d9e6b --- /dev/null +++ b/sdk/test/metrics/circular_buffer_counter_test.cc @@ -0,0 +1,149 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/data/circular_buffer.h" + +#include +#include + +using namespace opentelemetry::sdk::metrics; + +class AdaptingIntegerArrayTest : public testing::TestWithParam +{}; + +INSTANTIATE_TEST_SUITE_P(InterestingValues, + AdaptingIntegerArrayTest, + testing::Values(1, + std::numeric_limits::max() + 1ull, + std::numeric_limits::max() + 1ull, + std::numeric_limits::max() + 1ull)); + +TEST_P(AdaptingIntegerArrayTest, PreservesSizeOnEnlargement) +{ + AdaptingIntegerArray counter(10); + EXPECT_EQ(counter.Size(), 10); + counter.Increment(0, GetParam()); + EXPECT_EQ(counter.Size(), 10); +} + +TEST_P(AdaptingIntegerArrayTest, IncrementAndGet) +{ + AdaptingIntegerArray counter(10); + for (int idx = 0; idx < 10; idx += 1) + { + EXPECT_EQ(counter.Get(idx), 0); + counter.Increment(idx, 1); + EXPECT_EQ(counter.Get(idx), 1); + counter.Increment(idx, GetParam()); + EXPECT_EQ(counter.Get(idx), GetParam() + 1); + } +} + +TEST_P(AdaptingIntegerArrayTest, Copy) +{ + AdaptingIntegerArray counter(10); + counter.Increment(0, GetParam()); + EXPECT_EQ(counter.Get(0), GetParam()); + + AdaptingIntegerArray copy = counter; + EXPECT_EQ(copy.Get(0), GetParam()); + + counter.Increment(0, 1); + EXPECT_EQ(counter.Get(0), GetParam() + 1); + EXPECT_EQ(copy.Get(0), GetParam()); +} + +TEST_P(AdaptingIntegerArrayTest, Clear) +{ + AdaptingIntegerArray counter(10); + counter.Increment(0, GetParam()); + EXPECT_EQ(counter.Get(0), GetParam()); + + counter.Clear(); + counter.Increment(0, 1); + EXPECT_EQ(counter.Get(0), 1); +} + +TEST(AdaptingCircularBufferCounterTest, ReturnsZeroOutsidePopulatedRange) +{ + AdaptingCircularBufferCounter counter{10}; + EXPECT_EQ(counter.Get(0), 0); + EXPECT_EQ(counter.Get(100), 0); + counter.Increment(2, 1); + counter.Increment(99, 1); + EXPECT_EQ(counter.Get(0), 0); + EXPECT_EQ(counter.Get(100), 0); +} + +TEST(AdaptingCircularBufferCounterTest, ExpandLower) +{ + AdaptingCircularBufferCounter counter{160}; + EXPECT_TRUE(counter.Increment(10, 1)); + // Add BEFORE the initial see (array index 0) and make sure we wrap around the datastructure. + EXPECT_TRUE(counter.Increment(0, 1)); + EXPECT_EQ(counter.Get(10), 1); + EXPECT_EQ(counter.Get(0), 1); + EXPECT_EQ(counter.StartIndex(), 0); + EXPECT_EQ(counter.EndIndex(), 10); + // Add AFTER initial entry and just push back end. + EXPECT_TRUE(counter.Increment(20, 1)); + EXPECT_EQ(counter.Get(20), 1); + EXPECT_EQ(counter.Get(10), 1); + EXPECT_EQ(counter.Get(0), 1); + EXPECT_EQ(counter.StartIndex(), 0); + EXPECT_EQ(counter.EndIndex(), 20); +} + +TEST(AdaptingCircularBufferCounterTest, ShouldFailAtLimit) +{ + AdaptingCircularBufferCounter counter{10}; + EXPECT_TRUE(counter.Increment(10, 1)); + EXPECT_TRUE(counter.Increment(15, 2)); + EXPECT_TRUE(counter.Increment(6, 3)); + // Check state + EXPECT_EQ(counter.StartIndex(), 6); + EXPECT_EQ(counter.EndIndex(), 15); + EXPECT_EQ(counter.Get(6), 3); + EXPECT_EQ(counter.Get(10), 1); + EXPECT_EQ(counter.Get(15), 2); + // Adding over the maximum # of buckets + EXPECT_FALSE(counter.Increment(5, 1)); + EXPECT_FALSE(counter.Increment(16, 1)); +} + +TEST(AdaptingCircularBufferCounterTest, ShouldCopyCounters) +{ + AdaptingCircularBufferCounter counter{2}; + EXPECT_TRUE(counter.Increment(2, 1)); + EXPECT_TRUE(counter.Increment(1, 1)); + EXPECT_FALSE(counter.Increment(3, 1)); + + AdaptingCircularBufferCounter copy{counter}; + EXPECT_EQ(counter.Get(2), 1); + EXPECT_EQ(copy.Get(2), 1); + EXPECT_EQ(copy.MaxSize(), counter.MaxSize()); + EXPECT_EQ(copy.StartIndex(), counter.StartIndex()); + EXPECT_EQ(copy.EndIndex(), counter.EndIndex()); + // Mutate copy and make sure original is unchanged. + EXPECT_TRUE(copy.Increment(2, 1)); + EXPECT_EQ(copy.Get(2), 2); + EXPECT_EQ(counter.Get(2), 1); +} + +TEST(AdaptingCircularBufferCounterTest, Clear) +{ + AdaptingCircularBufferCounter counter{10}; + EXPECT_TRUE(counter.Empty()); + EXPECT_TRUE(counter.Increment(2, 1)); + EXPECT_FALSE(counter.Empty()); + EXPECT_TRUE(counter.Increment(8, 1)); + // Check state. + EXPECT_EQ(counter.StartIndex(), 2); + EXPECT_EQ(counter.EndIndex(), 8); + EXPECT_EQ(counter.Get(2), 1); + EXPECT_EQ(counter.Get(8), 1); + // Clear and verify. + EXPECT_FALSE(counter.Empty()); + counter.Clear(); + EXPECT_TRUE(counter.Empty()); +} From 41416ce21f603a2397895d68ba3263eeb55467ef Mon Sep 17 00:00:00 2001 From: jaelrod <64549955+jaelrod@users.noreply.github.com> Date: Sat, 3 Jun 2023 02:35:24 -0400 Subject: [PATCH 008/119] [EXPORTER] set is_monotonic only for instrument type kCounter (#2171) --- exporters/otlp/src/otlp_metric_utils.cc | 3 +- .../test/otlp_metrics_serialization_test.cc | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index c4ab641567..4f56c2f356 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -50,7 +50,8 @@ void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data { sum->set_aggregation_temporality( GetProtoAggregationTemporality(metric_data.aggregation_temporality)); - sum->set_is_monotonic(true); + sum->set_is_monotonic(metric_data.instrument_descriptor.type_ == + metric_sdk::InstrumentType::kCounter); auto start_ts = metric_data.start_ts.time_since_epoch().count(); auto ts = metric_data.end_ts.time_since_epoch().count(); for (auto &point_data_with_attributes : metric_data.point_data_attr_) diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index cc3781c66f..ac0f717b25 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -35,7 +35,34 @@ static metrics_sdk::MetricData CreateSumAggregationData() point_data_attr_1.point_data = s_data_1; point_data_attr_2.attributes = {{"k2", "v2"}}; - point_data_attr_2.point_data = s_data_1; + point_data_attr_2.point_data = s_data_2; + std::vector point_data_attr; + point_data_attr.push_back(point_data_attr_1); + point_data_attr.push_back(point_data_attr_2); + data.point_data_attr_ = std::move(point_data_attr); + return data; +} + +static metrics_sdk::MetricData CreateUpDownCounterAggregationData() +{ + metrics_sdk::MetricData data; + data.start_ts = opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()); + metrics_sdk::InstrumentDescriptor inst_desc = {"UpDownCounter", "Robot Pose Y", "Meter", + metrics_sdk::InstrumentType::kUpDownCounter, + metrics_sdk::InstrumentValueType::kDouble}; + metrics_sdk::SumPointData s_data_1, s_data_2; + s_data_1.value_ = 1.35; + s_data_2.value_ = 1.37; + + data.aggregation_temporality = metrics_sdk::AggregationTemporality::kCumulative; + data.end_ts = opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()); + data.instrument_descriptor = inst_desc; + metrics_sdk::PointDataAttributes point_data_attr_1, point_data_attr_2; + point_data_attr_1.attributes = {{"environment_id", "DEV-AYS"}}; + point_data_attr_1.point_data = s_data_1; + + point_data_attr_2.attributes = {{"robot_id", "DEV-AYS-03-02"}}; + point_data_attr_2.point_data = s_data_2; std::vector point_data_attr; point_data_attr.push_back(point_data_attr_1); point_data_attr.push_back(point_data_attr_2); @@ -68,7 +95,7 @@ static metrics_sdk::MetricData CreateHistogramAggregationData() point_data_attr_1.point_data = s_data_1; point_data_attr_2.attributes = {{"k2", "v2"}}; - point_data_attr_2.point_data = s_data_1; + point_data_attr_2.point_data = s_data_2; std::vector point_data_attr; point_data_attr.push_back(point_data_attr_1); point_data_attr.push_back(point_data_attr_2); @@ -95,7 +122,7 @@ static metrics_sdk::MetricData CreateObservableGaugeAggregationData() point_data_attr_1.point_data = s_data_1; point_data_attr_2.attributes = {{"k2", "v2"}}; - point_data_attr_2.point_data = s_data_1; + point_data_attr_2.point_data = s_data_2; std::vector point_data_attr; point_data_attr.push_back(point_data_attr_1); point_data_attr.push_back(point_data_attr_2); @@ -120,6 +147,20 @@ TEST(OtlpMetricSerializationTest, Counter) EXPECT_EQ(1, 1); } +TEST(OtlpMetricSerializationTest, UpDownCounter) +{ + metrics_sdk::MetricData data = CreateUpDownCounterAggregationData(); + opentelemetry::proto::metrics::v1::Sum sum; + otlp_exporter::OtlpMetricUtils::ConvertSumMetric(data, &sum); + EXPECT_EQ(sum.aggregation_temporality(), + proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE); + EXPECT_EQ(sum.is_monotonic(), false); + EXPECT_EQ(sum.data_points(0).as_double(), 1.35); + EXPECT_EQ(sum.data_points(1).as_double(), 1.37); + + EXPECT_EQ(1, 1); +} + TEST(OtlpMetricSerializationTest, Histogram) { metrics_sdk::MetricData data = CreateHistogramAggregationData(); From 082bb9309899029af7c01962f61290532ff6b234 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin Date: Sat, 3 Jun 2023 01:52:39 -0700 Subject: [PATCH 009/119] [SDK] Add base2 exponential histogram indexer (#2173) --- .../base2_exponential_histogram_indexer.h | 46 +++++ sdk/src/metrics/CMakeLists.txt | 1 + .../base2_exponential_histogram_indexer.cc | 71 +++++++ sdk/test/metrics/BUILD | 15 ++ sdk/test/metrics/CMakeLists.txt | 1 + ...ase2_exponential_histogram_indexer_test.cc | 178 ++++++++++++++++++ 6 files changed, 312 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h create mode 100644 sdk/src/metrics/aggregation/base2_exponential_histogram_indexer.cc create mode 100644 sdk/test/metrics/base2_exponential_histogram_indexer_test.cc diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h new file mode 100644 index 0000000000..14c00070b1 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +/* + * An indexer for base2 exponential histograms. It is used to calculate index for a given value and + * scale. + */ +class Base2ExponentialHistogramIndexer +{ +public: + /* + * Construct a new indexer for a given scale. + */ + explicit Base2ExponentialHistogramIndexer(int32_t scale = 0); + Base2ExponentialHistogramIndexer(const Base2ExponentialHistogramIndexer &other) = default; + Base2ExponentialHistogramIndexer &operator=(const Base2ExponentialHistogramIndexer &other) = + default; + + /** + * Compute the index for the given value. + * + * @param value Measured value (must be non-zero). + * @return the index of the bucket which the value maps to. + */ + int32_t ComputeIndex(double value) const; + +private: + int32_t scale_; + double scale_factor_; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index db8283fc43..cd831eaac8 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -14,6 +14,7 @@ add_library( state/observable_registry.cc state/sync_metric_storage.cc state/temporal_metric_storage.cc + aggregation/base2_exponential_histogram_indexer.cc aggregation/histogram_aggregation.cc aggregation/lastvalue_aggregation.cc aggregation/sum_aggregation.cc diff --git a/sdk/src/metrics/aggregation/base2_exponential_histogram_indexer.cc b/sdk/src/metrics/aggregation/base2_exponential_histogram_indexer.cc new file mode 100644 index 0000000000..a46a2775e5 --- /dev/null +++ b/sdk/src/metrics/aggregation/base2_exponential_histogram_indexer.cc @@ -0,0 +1,71 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +namespace +{ + +const double kLogBase2E = 1.0 / std::log(2.0); + +double ComputeScaleFactor(int32_t scale) +{ + return std::scalbn(kLogBase2E, scale); +} + +// Compute the bucket index using a logarithm based approach. +int32_t GetIndexByLogarithm(double value, double scale_factor) +{ + return static_cast(std::ceil(std::log(value) * scale_factor)) - 1; +} + +// Compute the bucket index at scale 0. +int32_t MapToIndexScaleZero(double value) +{ + // Note: std::frexp() rounds submnormal values to the smallest normal value and returns an + // exponent corresponding to fractions in the range [0.5, 1), whereas an exponent for the range + // [1, 2), so subtract 1 from the exponent immediately. + int exp; + double frac = std::frexp(value, &exp); + exp--; + + if (frac == 0.5) + { + // Special case for powers of two: they fall into the bucket numbered one less. + exp--; + } + return exp; +} + +} // namespace + +Base2ExponentialHistogramIndexer::Base2ExponentialHistogramIndexer(int32_t scale) + : scale_(scale), scale_factor_(scale > 0 ? ComputeScaleFactor(scale) : 0) +{} + +int32_t Base2ExponentialHistogramIndexer::ComputeIndex(double value) const +{ + const double abs_value = std::fabs(value); + // For positive scales, compute the index by logarithm, which is simpler but may be + // inaccurate near bucket boundaries + if (scale_ > 0) + { + return GetIndexByLogarithm(abs_value, scale_factor_); + } + // For scale zero, compute the exact index by extracting the exponent. + // For negative scales, compute the exact index by extracting the exponent and shifting it to + // the right by -scale + return MapToIndexScaleZero(abs_value) >> -scale_; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/metrics/BUILD b/sdk/test/metrics/BUILD index df56f9c67d..24b426fdf5 100644 --- a/sdk/test/metrics/BUILD +++ b/sdk/test/metrics/BUILD @@ -285,6 +285,21 @@ cc_test( ], ) +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 = [ diff --git a/sdk/test/metrics/CMakeLists.txt b/sdk/test/metrics/CMakeLists.txt index 47598fbbb8..8e60e3b342 100644 --- a/sdk/test/metrics/CMakeLists.txt +++ b/sdk/test/metrics/CMakeLists.txt @@ -14,6 +14,7 @@ foreach( histogram_aggregation_test attributes_processor_test attributes_hashmap_test + base2_exponential_histogram_indexer_test circular_buffer_counter_test histogram_test sync_metric_storage_counter_test diff --git a/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc b/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc new file mode 100644 index 0000000000..85f6fe72e9 --- /dev/null +++ b/sdk/test/metrics/base2_exponential_histogram_indexer_test.cc @@ -0,0 +1,178 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" + +#include + +using namespace opentelemetry::sdk::metrics; + +TEST(Base2ExponentialHistogramIndexerTest, ScaleOne) +{ + const Base2ExponentialHistogramIndexer indexer{1}; + auto compute_index = [indexer](double value) { return indexer.ComputeIndex(value); }; + + EXPECT_EQ(compute_index(std::numeric_limits::max()), 2047); + EXPECT_EQ(compute_index(strtod("0x1p1023", nullptr)), 2045); + EXPECT_EQ(compute_index(strtod("0x1.1p1023", nullptr)), 2046); + EXPECT_EQ(compute_index(strtod("0x1p1022", nullptr)), 2043); + EXPECT_EQ(compute_index(strtod("0x1.1p1022", nullptr)), 2044); + EXPECT_EQ(compute_index(strtod("0x1p-1022", nullptr)), -2045); + EXPECT_EQ(compute_index(strtod("0x1.1p-1022", nullptr)), -2044); + EXPECT_EQ(compute_index(strtod("0x1p-1021", nullptr)), -2043); + EXPECT_EQ(compute_index(strtod("0x1.1p-1021", nullptr)), -2042); + EXPECT_EQ(compute_index(std::numeric_limits::min()), -2045); + EXPECT_EQ(compute_index(std::numeric_limits::denorm_min()), -2149); + EXPECT_EQ(compute_index(15.0), 7); + EXPECT_EQ(compute_index(9.0), 6); + EXPECT_EQ(compute_index(7.0), 5); + EXPECT_EQ(compute_index(5.0), 4); + EXPECT_EQ(compute_index(3.0), 3); + EXPECT_EQ(compute_index(2.5), 2); + EXPECT_EQ(compute_index(1.5), 1); + EXPECT_EQ(compute_index(1.2), 0); + EXPECT_EQ(compute_index(1.0), -1); + EXPECT_EQ(compute_index(0.75), -1); + EXPECT_EQ(compute_index(0.55), -2); + EXPECT_EQ(compute_index(0.45), -3); +} + +TEST(Base2ExponentialHistogramIndexerTest, ScaleZero) +{ + const Base2ExponentialHistogramIndexer indexer{0}; + auto compute_index = [indexer](double value) { return indexer.ComputeIndex(value); }; + + // Near +Inf. + // Use constant for exp, as max_exponent constant includes bias. + EXPECT_EQ(compute_index(std::numeric_limits::max()), 1023); + EXPECT_EQ(compute_index(strtod("0x1p1023", nullptr)), 1022); + EXPECT_EQ(compute_index(strtod("0x1.1p1023", nullptr)), 1023); + EXPECT_EQ(compute_index(strtod("0x1p1022", nullptr)), 1021); + EXPECT_EQ(compute_index(strtod("0x1.1p1022", nullptr)), 1022); + // Near 0. + EXPECT_EQ(compute_index(strtod("0x1p-1022", nullptr)), -1023); + EXPECT_EQ(compute_index(strtod("0x1.1p-1022", nullptr)), -1022); + EXPECT_EQ(compute_index(strtod("0x1p-1021", nullptr)), -1022); + EXPECT_EQ(compute_index(strtod("0x1.1p-1021", nullptr)), -1021); + EXPECT_EQ(compute_index(std::numeric_limits::min()), -1023); + EXPECT_EQ(compute_index(std::numeric_limits::denorm_min()), -1075); + // Near 1. + EXPECT_EQ(compute_index(4.0), 1); + EXPECT_EQ(compute_index(3.0), 1); + EXPECT_EQ(compute_index(2.0), 0); + EXPECT_EQ(compute_index(1.5), 0); + EXPECT_EQ(compute_index(1.0), -1); + EXPECT_EQ(compute_index(0.75), -1); + EXPECT_EQ(compute_index(0.51), -1); + EXPECT_EQ(compute_index(0.5), -2); + EXPECT_EQ(compute_index(0.26), -2); + EXPECT_EQ(compute_index(0.25), -3); + EXPECT_EQ(compute_index(0.126), -3); + EXPECT_EQ(compute_index(0.125), -4); +} + +TEST(Base2ExponentialHistogramIndexerTest, ScaleNegativeOne) +{ + const Base2ExponentialHistogramIndexer indexer{-1}; + auto compute_index = [indexer](double value) { return indexer.ComputeIndex(value); }; + + EXPECT_EQ(compute_index(17.0), 2); + EXPECT_EQ(compute_index(16.0), 1); + EXPECT_EQ(compute_index(15.0), 1); + EXPECT_EQ(compute_index(9.0), 1); + EXPECT_EQ(compute_index(8.0), 1); + EXPECT_EQ(compute_index(5.0), 1); + EXPECT_EQ(compute_index(4.0), 0); + EXPECT_EQ(compute_index(3.0), 0); + EXPECT_EQ(compute_index(2.0), 0); + EXPECT_EQ(compute_index(1.5), 0); + EXPECT_EQ(compute_index(1.0), -1); + EXPECT_EQ(compute_index(0.75), -1); + EXPECT_EQ(compute_index(0.5), -1); + EXPECT_EQ(compute_index(0.25), -2); + EXPECT_EQ(compute_index(0.20), -2); + EXPECT_EQ(compute_index(0.13), -2); + EXPECT_EQ(compute_index(0.125), -2); + EXPECT_EQ(compute_index(0.10), -2); + EXPECT_EQ(compute_index(0.0625), -3); + EXPECT_EQ(compute_index(0.06), -3); +} + +TEST(Base2ExponentialHistogramIndexerTest, ScaleNegativeFour) +{ + const Base2ExponentialHistogramIndexer indexer{-4}; + auto compute_index = [indexer](double value) { return indexer.ComputeIndex(value); }; + + EXPECT_EQ(compute_index(strtod("0x1p0", nullptr)), -1); + EXPECT_EQ(compute_index(strtod("0x10p0", nullptr)), 0); + EXPECT_EQ(compute_index(strtod("0x100p0", nullptr)), 0); + EXPECT_EQ(compute_index(strtod("0x1000p0", nullptr)), 0); + EXPECT_EQ(compute_index(strtod("0x10000p0", nullptr)), 0); // Base == 2**16 + EXPECT_EQ(compute_index(strtod("0x100000p0", nullptr)), 1); + EXPECT_EQ(compute_index(strtod("0x1000000p0", nullptr)), 1); + EXPECT_EQ(compute_index(strtod("0x10000000p0", nullptr)), 1); + EXPECT_EQ(compute_index(strtod("0x100000000p0", nullptr)), 1); // == 2**32 + EXPECT_EQ(compute_index(strtod("0x1000000000p0", nullptr)), 2); + EXPECT_EQ(compute_index(strtod("0x10000000000p0", nullptr)), 2); + EXPECT_EQ(compute_index(strtod("0x100000000000p0", nullptr)), 2); + EXPECT_EQ(compute_index(strtod("0x1000000000000p0", nullptr)), 2); // 2**48 + EXPECT_EQ(compute_index(strtod("0x10000000000000p0", nullptr)), 3); + EXPECT_EQ(compute_index(strtod("0x100000000000000p0", nullptr)), 3); + EXPECT_EQ(compute_index(strtod("0x1000000000000000p0", nullptr)), 3); + EXPECT_EQ(compute_index(strtod("0x10000000000000000p0", nullptr)), 3); // 2**64 + EXPECT_EQ(compute_index(strtod("0x100000000000000000p0", nullptr)), 4); + EXPECT_EQ(compute_index(strtod("0x1000000000000000000p0", nullptr)), 4); + EXPECT_EQ(compute_index(strtod("0x10000000000000000000p0", nullptr)), 4); + EXPECT_EQ(compute_index(strtod("0x100000000000000000000p0", nullptr)), 4); + EXPECT_EQ(compute_index(strtod("0x1000000000000000000000p0", nullptr)), 5); + EXPECT_EQ(compute_index(1 / strtod("0x1p0", nullptr)), -1); + EXPECT_EQ(compute_index(1 / strtod("0x10p0", nullptr)), -1); + EXPECT_EQ(compute_index(1 / strtod("0x100p0", nullptr)), -1); + EXPECT_EQ(compute_index(1 / strtod("0x1000p0", nullptr)), -1); + EXPECT_EQ(compute_index(1 / strtod("0x10000p0", nullptr)), -2); // 2**-16 + EXPECT_EQ(compute_index(1 / strtod("0x100000p0", nullptr)), -2); + EXPECT_EQ(compute_index(1 / strtod("0x1000000p0", nullptr)), -2); + EXPECT_EQ(compute_index(1 / strtod("0x10000000p0", nullptr)), -2); + EXPECT_EQ(compute_index(1 / strtod("0x100000000p0", nullptr)), -3); // 2**-32 + EXPECT_EQ(compute_index(1 / strtod("0x1000000000p0", nullptr)), -3); + EXPECT_EQ(compute_index(1 / strtod("0x10000000000p0", nullptr)), -3); + EXPECT_EQ(compute_index(1 / strtod("0x100000000000p0", nullptr)), -3); + EXPECT_EQ(compute_index(1 / strtod("0x1000000000000p0", nullptr)), -4); // 2**-48 + EXPECT_EQ(compute_index(1 / strtod("0x10000000000000p0", nullptr)), -4); + EXPECT_EQ(compute_index(1 / strtod("0x100000000000000p0", nullptr)), -4); + EXPECT_EQ(compute_index(1 / strtod("0x1000000000000000p0", nullptr)), -4); + EXPECT_EQ(compute_index(1 / strtod("0x10000000000000000p0", nullptr)), -5); // 2**-64 + EXPECT_EQ(compute_index(1 / strtod("0x100000000000000000p0", nullptr)), -5); + // Max values. + EXPECT_EQ(compute_index(0x1.FFFFFFFFFFFFFp1023), 63); + EXPECT_EQ(compute_index(strtod("0x1p1023", nullptr)), 63); + EXPECT_EQ(compute_index(strtod("0x1p1019", nullptr)), 63); + EXPECT_EQ(compute_index(strtod("0x1p1009", nullptr)), 63); + EXPECT_EQ(compute_index(strtod("0x1p1008", nullptr)), 62); + EXPECT_EQ(compute_index(strtod("0x1p1007", nullptr)), 62); + EXPECT_EQ(compute_index(strtod("0x1p1000", nullptr)), 62); + EXPECT_EQ(compute_index(strtod("0x1p0993", nullptr)), 62); + EXPECT_EQ(compute_index(strtod("0x1p0992", nullptr)), 61); + EXPECT_EQ(compute_index(strtod("0x1p0991", nullptr)), 61); + // Min and subnormal values. + EXPECT_EQ(compute_index(strtod("0x1p-1074", nullptr)), -68); + EXPECT_EQ(compute_index(strtod("0x1p-1073", nullptr)), -68); + EXPECT_EQ(compute_index(strtod("0x1p-1072", nullptr)), -68); + EXPECT_EQ(compute_index(strtod("0x1p-1057", nullptr)), -67); + EXPECT_EQ(compute_index(strtod("0x1p-1056", nullptr)), -67); + EXPECT_EQ(compute_index(strtod("0x1p-1041", nullptr)), -66); + EXPECT_EQ(compute_index(strtod("0x1p-1040", nullptr)), -66); + EXPECT_EQ(compute_index(strtod("0x1p-1025", nullptr)), -65); + EXPECT_EQ(compute_index(strtod("0x1p-1024", nullptr)), -65); + EXPECT_EQ(compute_index(strtod("0x1p-1023", nullptr)), -64); + EXPECT_EQ(compute_index(strtod("0x1p-1022", nullptr)), -64); + EXPECT_EQ(compute_index(strtod("0x1p-1009", nullptr)), -64); + EXPECT_EQ(compute_index(strtod("0x1p-1008", nullptr)), -64); + EXPECT_EQ(compute_index(strtod("0x1p-1007", nullptr)), -63); + EXPECT_EQ(compute_index(strtod("0x1p-0993", nullptr)), -63); + EXPECT_EQ(compute_index(strtod("0x1p-0992", nullptr)), -63); + EXPECT_EQ(compute_index(strtod("0x1p-0991", nullptr)), -62); + EXPECT_EQ(compute_index(strtod("0x1p-0977", nullptr)), -62); + EXPECT_EQ(compute_index(strtod("0x1p-0976", nullptr)), -62); + EXPECT_EQ(compute_index(strtod("0x1p-0975", nullptr)), -61); +} From 834c0c4d1b31291a606a3d4061b9d5ff00c91203 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Sat, 3 Jun 2023 10:44:58 -0700 Subject: [PATCH 010/119] [DLL Build] link to opentelemetry_logs even without OTLP (#2177) --- .../exporters/otlp/otlp_grpc_metric_exporter.h | 8 ++++---- ext/src/dll/CMakeLists.txt | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 69bc8ca78d..11bb64c24f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -5,10 +5,10 @@ // clang-format off -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index 4cfcd87412..d9156a5f8c 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -23,16 +23,16 @@ if(WITH_OTLP_HTTP) endif() if(WITH_LOGS_PREVIEW) + target_link_libraries(opentelemetry_cpp PRIVATE opentelemetry_logs) + if(WITH_OTLP_GRPC) - target_link_libraries( - opentelemetry_cpp PRIVATE opentelemetry_logs - opentelemetry_exporter_otlp_grpc_log) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_grpc_log) endif() if(WITH_OTLP_HTTP) - target_link_libraries( - opentelemetry_cpp PRIVATE opentelemetry_logs - opentelemetry_exporter_otlp_http_log) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_http_log) endif() endif() From 500cf98f0b9549da5539af60ce4a0a0f79f4eb11 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 6 Jun 2023 08:47:01 +0200 Subject: [PATCH 011/119] [EXPORTER] Fixed HTTP CURL for 32bits platforms --- .../http/client/curl/http_operation_curl.h | 2 ++ .../http/client/curl/http_operation_curl.cc | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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 65355a05cd..b711ac8445 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 @@ -269,6 +269,8 @@ class HttpOperation CURLcode SetCurlLongOption(CURLoption option, long value); + CURLcode SetCurlOffOption(CURLoption option, curl_off_t value); + const char *GetCurlErrorMessage(CURLcode code); std::atomic is_aborted_; // Set to 'true' when async callback is aborted diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index dcb1ec9042..22b2565e6f 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -556,6 +556,26 @@ CURLcode HttpOperation::SetCurlLongOption(CURLoption option, long value) return rc; } +CURLcode HttpOperation::SetCurlOffOption(CURLoption option, curl_off_t value) +{ + CURLcode rc; + + /* + curl_easy_setopt() is a macro with variadic arguments, type unsafe. + SetCurlOffOption() ensures it is called with a curl_off_t. + */ + rc = curl_easy_setopt(curl_resource_.easy_handle, option, value); + + if (rc != CURLE_OK) + { + const char *message = GetCurlErrorMessage(rc); + OTEL_INTERNAL_LOG_ERROR("CURL, set option <" << std::to_string(option) << "> failed: <" + << message << ">"); + } + + return rc; +} + CURLcode HttpOperation::Setup() { if (!curl_resource_.easy_handle) @@ -980,7 +1000,7 @@ CURLcode HttpOperation::Setup() return rc; } - rc = SetCurlLongOption(CURLOPT_POSTFIELDSIZE_LARGE, req_size); + rc = SetCurlOffOption(CURLOPT_POSTFIELDSIZE_LARGE, req_size); if (rc != CURLE_OK) { return rc; From 600bd305fec6cf5e7a9e206953f9602799b3f3fe Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 6 Jun 2023 10:16:24 +0200 Subject: [PATCH 012/119] [BUILD] Avoid dependency on protobuf from the OTLP HTTP metrics exporter header --- .../opentelemetry/exporters/otlp/otlp_http_metric_exporter.h | 1 - 1 file changed, 1 deletion(-) 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 d09d7f525c..0aebf79760 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 @@ -8,7 +8,6 @@ #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 "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include #include From d980e8b4066d3b268be7c246345732d31da1f7cf Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 6 Jun 2023 12:25:57 +0200 Subject: [PATCH 013/119] [SDK] Simplify SDK version --- buildscripts/pre-commit | 27 ++++++++----------- .../opentelemetry/sdk/version/version.h | 3 --- sdk/src/version/version.cc | 20 ++++++-------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/buildscripts/pre-commit b/buildscripts/pre-commit index eb09e01c2c..c21f363b5a 100755 --- a/buildscripts/pre-commit +++ b/buildscripts/pre-commit @@ -10,7 +10,7 @@ if [[ ! -w "$(pwd)/sdk/src/version/version.cc" && ! -w "$(pwd)/api/include/open exit 1 fi -# format: "v..-+--g"" +# format: "v..-+--g" semver_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?-([0-9]+)-g([0-9|a-z]+)$" git_tag=$(git describe --tags --long 2>/dev/null) || true if [[ ! -z $git_tag ]] && [[ $git_tag =~ $semver_regex ]]; then @@ -22,7 +22,7 @@ if [[ ! -z $git_tag ]] && [[ $git_tag =~ $semver_regex ]]; then count_new_commits="${BASH_REMATCH[9]}" latest_commit_hash="${BASH_REMATCH[10]}" if [[ -z ${major} ]] || [[ -z ${minor} ]] || [[ -z ${patch} ]] || [[ -z ${count_new_commits} ]] || [[ -z ${latest_commit_hash} ]]; then - echo "Error: Incorrect tag format recevived. Exiting.." + echo "Error: Incorrect tag format received. Exiting.." exit 1 fi else @@ -38,9 +38,8 @@ if [[ -z ${latest_commit_hash} ]]; then exit 1 fi -branch="$(git rev-parse --abbrev-ref HEAD)" short_version="${major}.${minor}.${patch}" -full_version="${short_version}-${pre_release}-${build_metadata}-${count_new_commits}-${branch}-${latest_commit_hash}" +full_version="${short_version}-${pre_release}-${build_metadata}" # Update api version.h sed -i "/^\#define OPENTELEMETRY_VERSION /c\#define OPENTELEMETRY_VERSION \"${short_version}\"" "$(pwd)/api/include/opentelemetry/version.h" @@ -64,18 +63,14 @@ namespace sdk { namespace version { -const int major_version = ${major}; -const int minor_version = ${minor}; -const int patch_version = ${patch}; -const char *pre_release = "${pre_release}"; -const char *build_metadata = "${build_metadata}"; -const int count_new_commits = ${count_new_commits}; -const char *branch = "${branch}"; -const char *commit_hash = "${latest_commit_hash}"; -const char *short_version = "${short_version}"; -const char *full_version = - "${full_version}"; -const char *build_date = "$(date -u)"; +const int major_version = ${major}; +const int minor_version = ${minor}; +const int patch_version = ${patch}; +const char *pre_release = "${pre_release}"; +const char *build_metadata = "${build_metadata}"; +const char *short_version = "${short_version}"; +const char *full_version = "${full_version}"; +const char *build_date = "$(date -u)"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index 758805b19c..1c9c285f90 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -19,9 +19,6 @@ extern const int minor_version; extern const int patch_version; extern const char *pre_release; extern const char *build_metadata; -extern const int count_new_commits; -extern const char *branch; -extern const char *commit_hash; extern const char *short_version; extern const char *full_version; extern const char *build_date; diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index 6dfc299814..a658331f27 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -11,18 +11,14 @@ namespace sdk { namespace version { -const int major_version = 1; -const int minor_version = 9; -const int patch_version = 1; -const char *pre_release = "NONE"; -const char *build_metadata = "NONE"; -const int count_new_commits = 22; -const char *branch = "make_release_1.9.1"; -const char *commit_hash = "5592180d539b59c4e8293bc927f5a6431fcbacdf"; -const char *short_version = "1.9.1"; -const char *full_version = - "1.9.1-NONE-NONE-22-make_release_1.9.1-5592180d539b59c4e8293bc927f5a6431fcbacdf"; -const char *build_date = "Fri 26 May 2023 07:14:07 AM UTC"; +const int major_version = 1; +const int minor_version = 9; +const int patch_version = 1; +const char *pre_release = "NONE"; +const char *build_metadata = "NONE"; +const char *short_version = "1.9.1"; +const char *full_version = "1.9.1-NONE-NONE"; +const char *build_date = "Fri 26 May 2023 07:14:07 AM UTC"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From d233b9bc1a3445e0c4caafd8d26398edeac495a0 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin Date: Wed, 7 Jun 2023 00:07:01 -0700 Subject: [PATCH 014/119] [SDK] Add benchmark for base2 exponential histogram indexer (#2181) --- sdk/test/metrics/BUILD | 15 +++++ sdk/test/metrics/CMakeLists.txt | 6 ++ ...exponential_histogram_indexer_benchmark.cc | 65 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc diff --git a/sdk/test/metrics/BUILD b/sdk/test/metrics/BUILD index 24b426fdf5..3cf379494d 100644 --- a/sdk/test/metrics/BUILD +++ b/sdk/test/metrics/BUILD @@ -360,6 +360,21 @@ otel_cc_benchmark( ], ) +otel_cc_benchmark( + name = "base2_exponential_histogram_indexer_benchmark", + srcs = [ + "base2_exponential_histogram_indexer_benchmark.cc", + ], + tags = [ + "benchmark", + "metrics", + "test", + ], + deps = [ + "metrics_common_test_utils", + ], +) + otel_cc_benchmark( name = "histogram_aggregation_benchmark", srcs = [ diff --git a/sdk/test/metrics/CMakeLists.txt b/sdk/test/metrics/CMakeLists.txt index 8e60e3b342..b30d71ae22 100644 --- a/sdk/test/metrics/CMakeLists.txt +++ b/sdk/test/metrics/CMakeLists.txt @@ -49,6 +49,12 @@ if(WITH_BENCHMARK) target_link_libraries(attributes_hashmap_benchmark benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT} opentelemetry_common) + add_executable(base2_exponential_histogram_indexer_benchmark + base2_exponential_histogram_indexer_benchmark.cc) + target_link_libraries( + base2_exponential_histogram_indexer_benchmark benchmark::benchmark + opentelemetry_metrics ${CMAKE_THREAD_LIBS_INIT} opentelemetry_common) + add_executable(histogram_aggregation_benchmark histogram_aggregation_benchmark.cc) target_link_libraries( diff --git a/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc b/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc new file mode 100644 index 0000000000..9f1d0d864d --- /dev/null +++ b/sdk/test/metrics/base2_exponential_histogram_indexer_benchmark.cc @@ -0,0 +1,65 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" + +#include +#include +#include + +using namespace opentelemetry::sdk::metrics; +namespace +{ + +void BM_NewIndexer(benchmark::State &state) +{ + std::array batch; + std::default_random_engine generator; + std::uniform_int_distribution distribution(1, 32); + + while (state.KeepRunningBatch(static_cast(batch.size()))) + { + state.PauseTiming(); + for (auto &value : batch) + { + value = distribution(generator); + } + state.ResumeTiming(); + + for (const auto value : batch) + { + benchmark::DoNotOptimize(Base2ExponentialHistogramIndexer(value)); + } + } +} + +BENCHMARK(BM_NewIndexer); + +void BM_ComputeIndex(benchmark::State &state) +{ + std::array batch; + std::default_random_engine generator; + std::uniform_real_distribution distribution(0, 1000); + Base2ExponentialHistogramIndexer indexer(static_cast(state.range(0))); + + while (state.KeepRunningBatch(static_cast(batch.size()))) + { + state.PauseTiming(); + for (auto &value : batch) + { + value = distribution(generator); + } + state.ResumeTiming(); + + for (const auto value : batch) + { + benchmark::DoNotOptimize(indexer.ComputeIndex(value)); + } + } +} + +BENCHMARK(BM_ComputeIndex)->Arg(-1)->Arg(0)->Arg(1)->Arg(20); + +} // namespace + +BENCHMARK_MAIN(); From c89a6fde66a4a86d4d5476899da74f1f4d9b2287 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 8 Jun 2023 23:56:38 -0700 Subject: [PATCH 015/119] Add ctime header to metrics_exporter.cc (#2187) --- exporters/ostream/src/metric_exporter.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 21ecd0109a..d963c4f420 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -4,6 +4,7 @@ #include "opentelemetry/exporters/ostream/metric_exporter.h" #include #include +#include #include #include "opentelemetry/exporters/ostream/common_utils.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" From bd83aa367c3d48b23334ca0352ea06105e4925ac Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Fri, 9 Jun 2023 17:30:24 -0700 Subject: [PATCH 016/119] Fix the exported symbol name for 32-bit win32 DLL build (#2190) --- ext/src/dll/opentelemetry_cpp.src | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 9f5ee76ba3..043b6a96d6 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -7,7 +7,11 @@ EXPORTS // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::trace::OStreamSpanExporterFactory::Create(void) ?Create@OStreamSpanExporterFactory@trace@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@XZ // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::SimpleSpanProcessorFactory::Create(class std::unique_ptr > && __ptr64) +#if defined(_WIN64) ?Create@SimpleSpanProcessorFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@7@@Z +#else + ?Create@SimpleSpanProcessorFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@std@@$$QAV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@7@@Z +#endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::TracerProviderFactory::Create(class std::unique_ptr >) ?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VTracerProvider@trace@v1@opentelemetry@@U?$default_delete@VTracerProvider@trace@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@7@@Z #if defined(WITH_OTLP_GRPC) @@ -20,13 +24,29 @@ EXPORTS #endif // defined(WITH_OTLP_HTTP) #if defined(ENABLE_LOGS_PREVIEW) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) +#if defined(_WIN64) ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z +#else + ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z +#endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::BatchLogRecordProcessorFactory::Create(class std::unique_ptr > && __ptr64,struct opentelemetry::v1::sdk::logs::BatchLogRecordProcessorOptions const & __ptr64) +#if defined(_WIN64) ?Create@BatchLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@AEBUBatchLogRecordProcessorOptions@2345@@Z +#else + ?Create@BatchLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@AEBUBatchLogRecordProcessorOptions@2345@@Z +#endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::SimpleLogRecordProcessorFactory::Create(class std::unique_ptr > && __ptr64) +#if defined(_WIN64) ?Create@SimpleLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@@Z +#else + ?Create@SimpleLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@@Z +#endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::MultiLogRecordProcessorFactory::Create(class std::vector >,class std::allocator > > > && __ptr64) +#if defined(WIN32) ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z +#else + ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z +#endif #if defined(WITH_OTLP_GRPC) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z From 773a172ddbf692bd98e2352f9f6dbf807d2c5a78 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Tue, 13 Jun 2023 01:16:06 +0800 Subject: [PATCH 017/119] Remove include_trace_context (#2194) --- CHANGELOG.md | 3 +++ api/include/opentelemetry/logs/logger_provider.h | 7 ++----- api/include/opentelemetry/logs/noop.h | 1 - api/test/logs/logger_test.cc | 1 - api/test/logs/provider_test.cc | 1 - .../opentelemetry/exporters/etw/etw_logger.h | 2 -- exporters/ostream/test/ostream_log_test.cc | 4 ++-- .../test/otlp_grpc_log_record_exporter_test.cc | 2 +- .../test/otlp_http_log_record_exporter_test.cc | 8 ++++---- sdk/include/opentelemetry/sdk/logs/logger.h | 5 +---- .../opentelemetry/sdk/logs/logger_provider.h | 1 - sdk/src/logs/logger.cc | 14 ++++++-------- sdk/src/logs/logger_provider.cc | 3 +-- sdk/test/logs/log_record_test.cc | 4 +--- sdk/test/logs/logger_provider_sdk_test.cc | 4 ++-- sdk/test/logs/logger_sdk_test.cc | 6 +++--- 16 files changed, 26 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a58e5ad3ca..3330790d2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [API] Remove include_trace_context + [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/api/include/opentelemetry/logs/logger_provider.h b/api/include/opentelemetry/logs/logger_provider.h index 89723725b8..e2a72bcc54 100644 --- a/api/include/opentelemetry/logs/logger_provider.h +++ b/api/include/opentelemetry/logs/logger_provider.h @@ -43,7 +43,6 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name = "", nostd::string_view library_version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) = 0; nostd::shared_ptr GetLogger( @@ -51,10 +50,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, std::initializer_list> attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, nostd::span>{ attributes.begin(), attributes.end()}); } @@ -65,10 +63,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, const T &attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, common::KeyValueIterableView(attributes)); } }; diff --git a/api/include/opentelemetry/logs/noop.h b/api/include/opentelemetry/logs/noop.h index ed4ba64bc7..5303b2e77f 100644 --- a/api/include/opentelemetry/logs/noop.h +++ b/api/include/opentelemetry/logs/noop.h @@ -54,7 +54,6 @@ class NoopLoggerProvider final : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const common::KeyValueIterable & /* attributes */) override { return logger_; diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index ccdcd990c5..789ffd1259 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -202,7 +202,6 @@ class TestProvider : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const common::KeyValueIterable & /* attributes */) override { return nostd::shared_ptr(new TestLogger()); diff --git a/api/test/logs/provider_test.cc b/api/test/logs/provider_test.cc index 0d607f1d01..27af9b0c43 100644 --- a/api/test/logs/provider_test.cc +++ b/api/test/logs/provider_test.cc @@ -24,7 +24,6 @@ class TestProvider : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const opentelemetry::common::KeyValueIterable & /* attributes */) override { return shared_ptr(nullptr); diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index ccf332b599..8040032597 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -359,13 +359,11 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider nostd::string_view library_name, nostd::string_view version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) override { UNREFERENCED_PARAMETER(library_name); UNREFERENCED_PARAMETER(version); UNREFERENCED_PARAMETER(schema_url); - UNREFERENCED_PARAMETER(include_trace_context); UNREFERENCED_PARAMETER(attributes); ETWProvider::EventFormat evtFmt = config_.encoding; return nostd::shared_ptr{ diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 30cf64c5eb..82bc91a747 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -377,7 +377,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) logs_api::Provider::SetLoggerProvider(provider); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger( - "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, true, + "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, {{"scope.attr.key", 123}}); // Back up cout's streambuf @@ -449,7 +449,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) logs_api::Provider::SetLoggerProvider(provider); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger( - "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, true, + "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, {{"scope.attr.key", 123}}); // Back up cout's streambuf 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 a0455adb70..f2962a0b0c 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -170,7 +170,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) auto trace_span = tracer->StartSpan("test_log"); opentelemetry::trace::Scope trace_scope{trace_span}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); std::unordered_map attributes; attributes["service.name"] = "unit_test_service"; 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 aba1c9c503..7720b6e5d8 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -143,7 +143,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); trace_id.ToLowerBase16(MakeSpan(trace_id_hex)); @@ -260,7 +260,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); trace_id.ToLowerBase16(MakeSpan(trace_id_hex)); @@ -385,7 +385,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); report_trace_id.assign(reinterpret_cast(trace_id_bin), sizeof(trace_id_bin)); @@ -498,7 +498,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); report_trace_id.assign(reinterpret_cast(trace_id_bin), sizeof(trace_id_bin)); diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index ece83a8b57..d290df98c3 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -33,8 +33,7 @@ class Logger final : public opentelemetry::logs::Logger opentelemetry::nostd::string_view name, std::shared_ptr context, std::unique_ptr instrumentation_scope = - instrumentationscope::InstrumentationScope::Create(""), - bool include_trace_context = true) noexcept; + instrumentationscope::InstrumentationScope::Create("")) noexcept; /** * Returns the name of this logger. @@ -67,8 +66,6 @@ class Logger final : public opentelemetry::logs::Logger // logger-context. std::unique_ptr instrumentation_scope_; std::shared_ptr context_; - - bool include_trace_context_; }; } // namespace logs diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index a52c1a7220..a5190c7a30 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -78,7 +78,6 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const opentelemetry::common::KeyValueIterable &attributes = opentelemetry::common::NoopKeyValueIterable()) noexcept override; diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 190bfe6f5a..4c76b198bb 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -16,14 +16,13 @@ namespace trace_api = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; -Logger::Logger(nostd::string_view name, - std::shared_ptr context, - std::unique_ptr instrumentation_scope, - bool include_trace_context) noexcept +Logger::Logger( + nostd::string_view name, + std::shared_ptr context, + std::unique_ptr instrumentation_scope) noexcept : logger_name_(std::string(name)), instrumentation_scope_(std::move(instrumentation_scope)), - context_(context), - include_trace_context_(include_trace_context) + context_(context) {} const nostd::string_view Logger::GetName() noexcept @@ -43,8 +42,7 @@ nostd::unique_ptr Logger::CreateLogRecord() noex recordable->SetObservedTimestamp(std::chrono::system_clock::now()); - if (include_trace_context_ && - opentelemetry::context::RuntimeContext::GetCurrent().HasKey(opentelemetry::trace::kSpanKey)) + if (opentelemetry::context::RuntimeContext::GetCurrent().HasKey(opentelemetry::trace::kSpanKey)) { opentelemetry::context::ContextValue context_value = opentelemetry::context::RuntimeContext::GetCurrent().GetValue( diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 2f75a09247..66948b1744 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -61,7 +61,6 @@ nostd::shared_ptr LoggerProvider::GetLogger( nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, const opentelemetry::common::KeyValueIterable &attributes) noexcept { // Ensure only one thread can read/write from the map of loggers @@ -105,7 +104,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( } loggers_.push_back(std::shared_ptr( - new Logger(logger_name, context_, std::move(lib), include_trace_context))); + new Logger(logger_name, context_, std::move(lib)))); return nostd::shared_ptr{loggers_.back()}; } diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 204827bfb0..cce81d9910 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -118,7 +118,6 @@ class TestBodyProvider : public opentelemetry::logs::LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const opentelemetry::common::KeyValueIterable & /* attributes */) override { return nostd::shared_ptr(new TestBodyLogger()); @@ -132,8 +131,7 @@ TEST(LogBody, BodyConversation) // Check that the implementation was pushed by calling TestLogger's GetName() nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = - lp.GetLogger("TestBodyProvider", "opentelelemtry_library", "", schema_url, false, {}); + auto logger = lp.GetLogger("TestBodyProvider", "opentelelemtry_library", "", schema_url, {}); auto real_logger = static_cast(logger.get()); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index ae606876b3..510f02b4df 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -75,7 +75,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) auto sdk_logger2 = static_cast(logger2.get()); ASSERT_EQ(sdk_logger2->GetInstrumentationScope(), sdk_logger1->GetInstrumentationScope()); - auto logger3 = lp->GetLogger("logger3", "opentelelemtry_library", "", schema_url, true, + auto logger3 = lp->GetLogger("logger3", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); auto sdk_logger3 = static_cast(logger3.get()); @@ -89,7 +89,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) std::unordered_map scope_attributes = {{"scope_key", "scope_value"}}; auto logger4 = - lp->GetLogger("logger4", "opentelelemtry_library", "", schema_url, true, scope_attributes); + lp->GetLogger("logger4", "opentelelemtry_library", "", schema_url, scope_attributes); auto sdk_logger4 = static_cast(logger4.get()); EXPECT_EQ(sdk_logger4->GetInstrumentationScope().GetAttributes().size(), 1); diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 78189ed8db..0e5050a973 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -200,13 +200,13 @@ TEST(LoggerSDK, LogToAProcessor) // Create an API LoggerProvider and logger auto api_lp = std::shared_ptr(new LoggerProvider()); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, true); + auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); // Cast the API LoggerProvider to an SDK Logger Provider and assert that it is still the same // LoggerProvider by checking that getting a logger with the same name as the previously defined // logger is the same instance auto lp = static_cast(api_lp.get()); - auto logger2 = lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, true); + auto logger2 = lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); ASSERT_EQ(logger, logger2); nostd::shared_ptr include_span; @@ -261,7 +261,7 @@ TEST(LoggerSDK, EventLog) // Create an API LoggerProvider and logger auto api_lp = std::shared_ptr(new LoggerProvider()); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, false); + auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); auto api_elp = std::shared_ptr(new EventLoggerProvider()); auto event_logger = api_elp->CreateEventLogger(logger, "otel-cpp.event_domain"); From 4b20067c3565a1da64acf476f0ecad014b52fd2a Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 13 Jun 2023 21:20:53 +0200 Subject: [PATCH 018/119] Upgrade to opentelemetry-proto 0.20.0 (#2195) --- bazel/repository.bzl | 6 +++--- cmake/opentelemetry-proto.cmake | 2 +- third_party/opentelemetry-proto | 2 +- third_party_release | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index daa9dcd3eb..1cf6410488 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -100,10 +100,10 @@ def opentelemetry_cpp_deps(): http_archive, name = "com_github_opentelemetry_proto", build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", - sha256 = "464bc2b348e674a1a03142e403cbccb01be8655b6de0f8bfe733ea31fcd421be", - strip_prefix = "opentelemetry-proto-0.19.0", + sha256 = "6ab267cf82832ed60ad075d574c78da736193eecb9693e8a8d02f65d6d3f3520", + strip_prefix = "opentelemetry-proto-0.20.0", urls = [ - "https://github.com/open-telemetry/opentelemetry-proto/archive/v0.19.0.tar.gz", + "https://github.com/open-telemetry/opentelemetry-proto/archive/v0.20.0.tar.gz", ], ) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 34b33d3cff..c3ea5a65ce 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -43,7 +43,7 @@ else() message( STATUS "opentelemetry-proto dependency satisfied by: github download") if("${opentelemetry-proto}" STREQUAL "") - set(opentelemetry-proto "v0.19.0") + set(opentelemetry-proto "v0.20.0") endif() include(ExternalProject) ExternalProject_Add( diff --git a/third_party/opentelemetry-proto b/third_party/opentelemetry-proto index 6459e1aae1..1608f92cf0 160000 --- a/third_party/opentelemetry-proto +++ b/third_party/opentelemetry-proto @@ -1 +1 @@ -Subproject commit 6459e1aae1c22e273ac92be86016f0ae55a2430a +Subproject commit 1608f92cf08119f9aec237c910b200d1317ec696 diff --git a/third_party_release b/third_party_release index c8af81b0c4..53ef723721 100644 --- a/third_party_release +++ b/third_party_release @@ -20,7 +20,7 @@ benchmark=v1.7.1 googletest=release-1.12.1 ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.11.2 -opentelemetry-proto=v0.19.0 +opentelemetry-proto=v0.20.0 opentracing-cpp=v1.6.0 prometheus-cpp=v1.1.0 vcpkg=2022.08.15 From fc8853e4186dae92574b6f9f3d07cb2808d83d9a Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Wed, 14 Jun 2023 05:08:05 +0800 Subject: [PATCH 019/119] Fix OTLP HTTP exporting in sync mode. (#2193) --- exporters/otlp/src/otlp_http_client.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index efb60ff982..44c154f725 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -712,12 +712,13 @@ OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, opentelemetry::sdk::common::ExportResult OtlpHttpClient::Export( const google::protobuf::Message &message) noexcept { - opentelemetry::sdk::common::ExportResult session_result = - opentelemetry::sdk::common::ExportResult::kSuccess; + std::shared_ptr session_result = + std::make_shared( + opentelemetry::sdk::common::ExportResult::kSuccess); opentelemetry::sdk::common::ExportResult export_result = Export( message, - [&session_result](opentelemetry::sdk::common::ExportResult result) { - session_result = result; + [session_result](opentelemetry::sdk::common::ExportResult result) { + *session_result = result; return result == opentelemetry::sdk::common::ExportResult::kSuccess; }, 0); @@ -727,7 +728,7 @@ opentelemetry::sdk::common::ExportResult OtlpHttpClient::Export( return export_result; } - return session_result; + return *session_result; } sdk::common::ExportResult OtlpHttpClient::Export( From 763f11d65bc49a020ca8610c350e6cda7dfdc1b2 Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Fri, 16 Jun 2023 14:08:18 +0200 Subject: [PATCH 020/119] Prometheus exporter sanitizes invalid characters (#1934) --- .../exporters/prometheus/exporter_utils.h | 3 ++ exporters/prometheus/src/exporter_utils.cc | 39 +++++++++++++++++-- .../prometheus/test/exporter_utils_test.cc | 32 +++++++++++++-- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index e602c87737..ce7f0a1191 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -107,6 +107,9 @@ class PrometheusExporterUtils const std::vector &boundaries, const std::vector &counts, ::prometheus::ClientMetric *metric); + + // For testing + friend class SanitizeNameTester; }; } // namespace metrics } // namespace exporter diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 451c34ff45..0a072d3303 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -39,9 +39,10 @@ std::vector PrometheusExporterUtils::TranslateT for (const auto &metric_data : instrumentation_info.metric_data_) { auto origin_name = metric_data.instrument_descriptor.name_; + auto unit = metric_data.instrument_descriptor.unit_; auto sanitized = SanitizeNames(origin_name); prometheus_client::MetricFamily metric_family; - metric_family.name = sanitized; + metric_family.name = sanitized + "_" + unit; metric_family.help = metric_data.instrument_descriptor.description_; auto time = metric_data.start_ts.time_since_epoch(); for (const auto &point_data_attr : metric_data.point_data_attr_) @@ -129,10 +130,40 @@ std::vector PrometheusExporterUtils::TranslateT */ std::string PrometheusExporterUtils::SanitizeNames(std::string name) { - // replace all '.' and '-' with '_' - std::replace(name.begin(), name.end(), '.', '_'); - std::replace(name.begin(), name.end(), '-', '_'); + constexpr const auto replacement = '_'; + constexpr const auto replacement_dup = '='; + auto valid = [](int i, char c) { + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ':' || + (c >= '0' && c <= '9' && i > 0)) + { + return true; + } + return false; + }; + + bool has_dup = false; + for (int i = 0; i < (int)name.size(); ++i) + { + if (valid(i, name[i])) + { + continue; + } + if (i > 0 && (name[i - 1] == replacement || name[i - 1] == replacement_dup)) + { + has_dup = true; + name[i] = replacement_dup; + } + else + { + name[i] = replacement; + } + } + if (has_dup) + { + auto end = std::remove(name.begin(), name.end(), replacement_dup); + return std::string{name.begin(), end}; + } return name; } diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 2b37ab77ad..2eac7a6d8b 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -14,6 +14,22 @@ namespace metric_api = opentelemetry::metrics; namespace prometheus_client = ::prometheus; OPENTELEMETRY_BEGIN_NAMESPACE + +namespace exporter +{ +namespace metrics +{ +class SanitizeNameTester +{ +public: + static std::string sanitize(std::string name) + { + return PrometheusExporterUtils::SanitizeNames(name); + } +}; +} // namespace metrics +} // namespace exporter + template void assert_basic(prometheus_client::MetricFamily &metric, const std::string &sanitized_name, @@ -22,9 +38,9 @@ void assert_basic(prometheus_client::MetricFamily &metric, int label_num, std::vector vals) { - ASSERT_EQ(metric.name, sanitized_name); // name sanitized - ASSERT_EQ(metric.help, description); // description not changed - ASSERT_EQ(metric.type, type); // type translated + ASSERT_EQ(metric.name, sanitized_name + "_unit"); // name sanitized + ASSERT_EQ(metric.help, description); // description not changed + ASSERT_EQ(metric.type, type); // type translated auto metric_data = metric.metric[0]; ASSERT_EQ(metric_data.label.size(), label_num); @@ -129,4 +145,14 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); } +TEST(PrometheusExporterUtils, SanitizeName) +{ + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name"), "name"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?"), "name_"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name???"), "name_"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__"), "name_"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name"), "name_name"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name:"), "name_name:"); +} + OPENTELEMETRY_END_NAMESPACE From 4cae6aae8ccbbb9e4e25345e642ec982eec663c7 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Fri, 16 Jun 2023 08:52:08 -0700 Subject: [PATCH 021/119] move Reiley Yang to emeritus (#2198) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd90c97221..6dd56949fd 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,6 @@ For edit access, get in touch on ([@open-telemetry/cpp-approvers](https://github.com/orgs/open-telemetry/teams/cpp-approvers)): * [Josh Suereth](https://github.com/jsuereth), Google -* [Reiley Yang](https://github.com/reyang), Microsoft * [WenTao Ou](https://github.com/owent), Tencent [Emeritus @@ -116,6 +115,7 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma * [Jodee Varney](https://github.com/jodeev) * [Johannes Tax](https://github.com/pyohannes) * [Max Golovanov](https://github.com/maxgolov) +* [Reiley Yang](https://github.com/reyang) * [Ryan Burn](https://github.com/rnburn) ### Thanks to all the people who have contributed From 2db5f29396c65aa4e19e08de3bcdeed875975bbb Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 20 Jun 2023 18:03:54 +0200 Subject: [PATCH 022/119] [EXPORTER] Prometheus: Error on ingesting samples with different value but same timestamp (#2200) --- exporters/prometheus/src/exporter_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 0a072d3303..966d665df6 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -44,7 +44,7 @@ std::vector PrometheusExporterUtils::TranslateT prometheus_client::MetricFamily metric_family; metric_family.name = sanitized + "_" + unit; metric_family.help = metric_data.instrument_descriptor.description_; - auto time = metric_data.start_ts.time_since_epoch(); + auto time = metric_data.end_ts.time_since_epoch(); for (const auto &point_data_attr : metric_data.point_data_attr_) { auto kind = getAggregationType(point_data_attr.point_data); From cfcda5728e75e51215d118eccd639e21cf4fd74d Mon Sep 17 00:00:00 2001 From: Cengizhan Pasaoglu Date: Wed, 21 Jun 2023 01:11:31 +0300 Subject: [PATCH 023/119] [SDK] Header files cleanup, use forward declarations (#2182) --- .../trace/span_context_kv_iterable_view.h | 2 + examples/batch/main.cc | 4 ++ examples/grpc/tracer_common.h | 3 + examples/http/tracer_common.h | 3 + examples/jaeger/main.cc | 2 + examples/logs_simple/main.cc | 3 + examples/multithreaded/main.cc | 2 + examples/otlp/grpc_log_main.cc | 4 ++ examples/otlp/grpc_main.cc | 1 + examples/otlp/http_log_main.cc | 2 + examples/otlp/http_main.cc | 1 + examples/simple/main.cc | 2 + examples/zipkin/main.cc | 2 + .../elasticsearch/src/es_log_recordable.cc | 6 ++ .../opentelemetry/exporters/etw/etw_tracer.h | 1 + exporters/jaeger/src/recordable.cc | 1 + exporters/jaeger/test/jaeger_exporter_test.cc | 10 +++- .../exporters/ostream/log_record_exporter.h | 3 + .../exporters/ostream/metric_exporter.h | 10 ++++ exporters/ostream/src/log_record_exporter.cc | 2 + exporters/ostream/src/metric_exporter.cc | 12 ++-- exporters/ostream/test/ostream_log_test.cc | 5 +- exporters/ostream/test/ostream_metric_test.cc | 14 +++-- exporters/otlp/src/otlp_metric_utils.cc | 1 + .../otlp_grpc_log_record_exporter_test.cc | 2 + .../otlp/test/otlp_http_exporter_test.cc | 1 + .../test/otlp_http_metric_exporter_test.cc | 2 + exporters/otlp/test/otlp_recordable_test.cc | 1 + exporters/zipkin/src/recordable.cc | 1 + exporters/zipkin/test/zipkin_exporter_test.cc | 4 +- ext/test/w3c_tracecontext_test/main.cc | 1 + functional/otlp/func_http_main.cc | 2 + .../sdk/common/atomic_shared_ptr.h | 1 + .../sdk/common/attribute_utils.h | 2 + .../sdk/common/attributemap_hash.h | 7 ++- .../sdk/common/circular_buffer.h | 1 + .../sdk/common/circular_buffer_range.h | 2 - .../sdk/common/empty_attributes.h | 8 +-- .../sdk/common/global_log_handler.h | 1 - .../instrumentation_library.h | 1 + .../instrumentation_scope.h | 8 +-- .../sdk/logs/batch_log_record_processor.h | 1 + .../logs/batch_log_record_processor_factory.h | 8 ++- .../logs/batch_log_record_processor_options.h | 4 +- .../opentelemetry/sdk/logs/event_logger.h | 10 ++-- .../sdk/logs/event_logger_provider.h | 5 +- .../sdk/logs/event_logger_provider_factory.h | 9 ++- sdk/include/opentelemetry/sdk/logs/exporter.h | 7 ++- sdk/include/opentelemetry/sdk/logs/logger.h | 5 +- .../opentelemetry/sdk/logs/logger_context.h | 5 +- .../sdk/logs/logger_context_factory.h | 11 +++- .../opentelemetry/sdk/logs/logger_provider.h | 11 ++-- .../sdk/logs/logger_provider_factory.h | 19 +++++-- .../sdk/logs/multi_log_record_processor.h | 4 +- .../logs/multi_log_record_processor_factory.h | 3 +- .../opentelemetry/sdk/logs/multi_recordable.h | 3 +- .../opentelemetry/sdk/logs/processor.h | 5 +- .../sdk/logs/read_write_log_record.h | 5 +- .../sdk/logs/readable_log_record.h | 26 ++++++--- .../opentelemetry/sdk/logs/recordable.h | 22 ++++---- .../sdk/logs/simple_log_record_processor.h | 7 ++- .../simple_log_record_processor_factory.h | 5 +- .../sdk/metrics/aggregation/aggregation.h | 6 +- .../metrics/aggregation/aggregation_config.h | 4 +- .../metrics/aggregation/default_aggregation.h | 7 +-- .../metrics/aggregation/drop_aggregation.h | 7 ++- .../aggregation/histogram_aggregation.h | 8 ++- .../aggregation/lastvalue_aggregation.h | 6 +- .../sdk/metrics/aggregation/sum_aggregation.h | 6 +- .../sdk/metrics/async_instruments.h | 6 +- .../sdk/metrics/data/exemplar_data.h | 3 +- .../sdk/metrics/data/metric_data.h | 4 +- .../sdk/metrics/data/point_data.h | 5 +- .../metrics/exemplar/always_sample_filter.h | 6 ++ .../sdk/metrics/exemplar/filter.h | 14 ++++- .../exemplar/filtered_exemplar_reservoir.h | 15 ++++- .../exemplar/fixed_size_exemplar_reservoir.h | 1 + .../exemplar/histogram_exemplar_reservoir.h | 15 ++++- .../metrics/exemplar/never_sample_filter.h | 6 ++ .../metrics/exemplar/no_exemplar_reservoir.h | 19 ++++++- .../sdk/metrics/exemplar/reservoir.h | 16 +++++- .../sdk/metrics/exemplar/reservoir_cell.h | 12 ++-- .../exemplar/reservoir_cell_selector.h | 12 ++-- .../exemplar/with_trace_sample_filter.h | 1 + .../sdk/metrics/export/metric_producer.h | 16 +++++- .../export/periodic_exporting_metric_reader.h | 8 ++- .../metrics/instrument_metadata_validator.h | 1 + .../opentelemetry/sdk/metrics/instruments.h | 4 +- sdk/include/opentelemetry/sdk/metrics/meter.h | 11 +++- .../opentelemetry/sdk/metrics/meter_context.h | 18 +++--- .../sdk/metrics/meter_provider.h | 18 ++++-- .../opentelemetry/sdk/metrics/metric_reader.h | 11 ++-- .../sdk/metrics/observer_result.h | 5 +- .../sdk/metrics/push_metric_exporter.h | 11 ++-- .../sdk/metrics/state/async_metric_storage.h | 6 +- .../sdk/metrics/state/metric_collector.h | 6 +- .../sdk/metrics/state/metric_storage.h | 18 +++++- .../sdk/metrics/state/multi_metric_storage.h | 19 ++++++- .../sdk/metrics/state/observable_registry.h | 7 ++- .../sdk/metrics/state/sync_metric_storage.h | 16 ++++-- .../metrics/state/temporal_metric_storage.h | 17 ++++-- .../sdk/metrics/sync_instruments.h | 7 +-- .../sdk/metrics/view/attributes_processor.h | 7 +++ .../sdk/metrics/view/instrument_selector.h | 4 ++ .../sdk/metrics/view/meter_selector.h | 3 + .../sdk/metrics/view/predicate_factory.h | 3 + .../opentelemetry/sdk/metrics/view/view.h | 7 ++- .../sdk/metrics/view/view_registry.h | 5 ++ .../opentelemetry/sdk/resource/resource.h | 9 +-- .../sdk/resource/resource_detector.h | 4 +- .../sdk/trace/batch_span_processor.h | 14 +++-- .../sdk/trace/batch_span_processor_factory.h | 8 +-- .../sdk/trace/batch_span_processor_options.h | 4 +- .../opentelemetry/sdk/trace/exporter.h | 9 ++- .../opentelemetry/sdk/trace/id_generator.h | 1 + .../sdk/trace/multi_recordable.h | 4 +- .../sdk/trace/multi_span_processor.h | 5 +- .../opentelemetry/sdk/trace/processor.h | 10 +++- .../sdk/trace/random_id_generator.h | 2 + .../sdk/trace/random_id_generator_factory.h | 3 +- .../opentelemetry/sdk/trace/recordable.h | 20 ++++--- sdk/include/opentelemetry/sdk/trace/sampler.h | 27 ++++++--- .../sdk/trace/samplers/always_off.h | 5 ++ .../sdk/trace/samplers/always_off_factory.h | 3 +- .../sdk/trace/samplers/always_on.h | 15 +++++ .../sdk/trace/samplers/always_on_factory.h | 3 +- .../opentelemetry/sdk/trace/samplers/parent.h | 17 +++++- .../sdk/trace/samplers/parent_factory.h | 3 +- .../sdk/trace/samplers/trace_id_ratio.h | 18 ++++++ .../trace/samplers/trace_id_ratio_factory.h | 3 +- .../sdk/trace/simple_processor.h | 5 ++ .../sdk/trace/simple_processor_factory.h | 5 +- .../opentelemetry/sdk/trace/span_data.h | 9 ++- sdk/include/opentelemetry/sdk/trace/tracer.h | 30 ++++++---- .../opentelemetry/sdk/trace/tracer_context.h | 5 +- .../sdk/trace/tracer_context_factory.h | 15 ++++- .../opentelemetry/sdk/trace/tracer_provider.h | 26 +++++---- .../sdk/trace/tracer_provider_factory.h | 21 +++++-- sdk/src/common/global_log_handler.cc | 3 +- sdk/src/logs/batch_log_record_processor.cc | 4 ++ sdk/src/logs/logger.cc | 9 ++- sdk/src/logs/logger_context_factory.cc | 3 + sdk/src/logs/logger_provider.cc | 10 ++-- sdk/src/logs/multi_log_record_processor.cc | 6 +- sdk/src/logs/readable_log_record.cc | 7 ++- sdk/src/logs/simple_log_record_processor.cc | 7 ++- .../aggregation/histogram_aggregation.cc | 1 + sdk/src/metrics/async_instruments.cc | 3 +- sdk/src/metrics/meter_context.cc | 4 +- sdk/src/metrics/meter_provider.cc | 2 + sdk/src/metrics/metric_reader.cc | 1 + .../metrics/state/temporal_metric_storage.cc | 14 +++-- sdk/src/resource/resource.cc | 1 + sdk/src/resource/resource_detector.cc | 3 + sdk/src/trace/batch_span_processor.cc | 5 ++ sdk/src/trace/samplers/parent.cc | 1 + sdk/src/trace/span.cc | 14 +++-- sdk/src/trace/tracer.cc | 55 ++++++++++--------- sdk/src/trace/tracer_provider.cc | 3 + sdk/src/trace/tracer_provider_factory.cc | 1 + sdk/test/logs/log_record_test.cc | 1 + sdk/test/logs/logger_provider_sdk_test.cc | 1 + sdk/test/logs/logger_sdk_test.cc | 6 +- sdk/test/metrics/aggregation_test.cc | 1 + sdk/test/metrics/async_instruments_test.cc | 1 + .../metrics/attributes_hashmap_benchmark.cc | 2 + .../exemplar/always_sample_filter_test.cc | 2 + sdk/test/metrics/multi_metric_storage_test.cc | 1 - sdk/test/resource/resource_test.cc | 5 +- sdk/test/trace/batch_span_processor_test.cc | 4 ++ sdk/test/trace/sampler_benchmark.cc | 8 ++- sdk/test/trace/tracer_test.cc | 5 +- 172 files changed, 859 insertions(+), 361 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index c20155edd6..6a21aaf54a 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -9,8 +9,10 @@ #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/utility.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/version.h" diff --git a/examples/batch/main.cc b/examples/batch/main.cc index a417933247..0e05c1b700 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -2,7 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/ostream/span_exporter_factory.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/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index 073bffd50a..347e7a8184 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -7,7 +7,10 @@ #include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/sdk/trace/tracer_context_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/propagation/http_trace_context.h" diff --git a/examples/http/tracer_common.h b/examples/http/tracer_common.h index 0b74d2ff8e..7d9f1ca571 100644 --- a/examples/http/tracer_common.h +++ b/examples/http/tracer_common.h @@ -4,7 +4,10 @@ #pragma once #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/sdk/trace/tracer_context_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/jaeger/main.cc b/examples/jaeger/main.cc index faa9758f02..a5b3c38c35 100644 --- a/examples/jaeger/main.cc +++ b/examples/jaeger/main.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/jaeger/jaeger_exporter_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index f4bcecbb39..c12733d4c3 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -3,6 +3,8 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/ostream/span_exporter_factory.h" +# include "opentelemetry/sdk/trace/exporter.h" +# include "opentelemetry/sdk/trace/processor.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -10,6 +12,7 @@ # include "opentelemetry/exporters/ostream/log_record_exporter.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/processor.h" # include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" # ifdef BAZEL_BUILD diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 49eaf4d16d..6071e2597a 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -3,6 +3,8 @@ #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index e0c85c38c2..f6f6685922 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -5,8 +5,12 @@ # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" # include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" # include "opentelemetry/logs/provider.h" +# include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/processor.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/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" diff --git a/examples/otlp/grpc_main.cc b/examples/otlp/grpc_main.cc index d7e3b29d6c..c238d9ad2a 100644 --- a/examples/otlp/grpc_main.cc +++ b/examples/otlp/grpc_main.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index a1171b04e0..5a5eeb599a 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -8,7 +8,9 @@ # include "opentelemetry/logs/provider.h" # include "opentelemetry/sdk/common/global_log_handler.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/processor.h" # include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +# include "opentelemetry/sdk/trace/processor.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index 09b8daeee2..6a0667b918 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -4,6 +4,7 @@ #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/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 6a8b28e4dd..48768b6448 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 6788d8cabe..0052cd430e 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 03c6c640e5..e3f60be0a9 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -4,6 +4,12 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/elasticsearch/es_log_recordable.h" +# include "opentelemetry/logs/severity.h" +# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.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" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index 039351f66e..6601f850df 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -32,6 +32,7 @@ #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/sdk/common/empty_attributes.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index d147d96553..1fd7e99dff 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -3,6 +3,7 @@ #include "opentelemetry/exporters/jaeger/recordable.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/resource/semantic_conventions.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/jaeger/test/jaeger_exporter_test.cc b/exporters/jaeger/test/jaeger_exporter_test.cc index 7f86f877bc..ea305267c5 100644 --- a/exporters/jaeger/test/jaeger_exporter_test.cc +++ b/exporters/jaeger/test/jaeger_exporter_test.cc @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include -#include +#include "opentelemetry/exporters/jaeger/jaeger_exporter.h" #include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/tracer.h" #include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/trace/span_startoptions.h" #ifdef BAZEL_BUILD # include "exporters/jaeger/src/thrift_sender.h" @@ -16,6 +17,9 @@ #include #include "gmock/gmock.h" +#include +#include + namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; 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 34806bd200..54dae898d2 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -4,14 +4,17 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/common/attribute_value.h" # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/nostd/type_traits.h" +# include "opentelemetry/sdk/common/attribute_utils.h" # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/version.h" # include # include +# include OPENTELEMETRY_BEGIN_NAMESPACE 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 36e5917457..92419fdea0 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h @@ -5,13 +5,23 @@ #include #include + #include "opentelemetry/common/spin_lock_mutex.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/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace resource +{ +class Resource; +} // namespace resource +} // namespace sdk + namespace exporter { namespace metrics diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 18552d7a65..611a749184 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -4,7 +4,9 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/ostream/log_record_exporter.h" # include "opentelemetry/exporters/ostream/common_utils.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/sdk_config.h" # include diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index d963c4f420..003aaa075f 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -2,15 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/ostream/metric_exporter.h" -#include -#include -#include -#include #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 + namespace { std::string timeToString(opentelemetry::common::SystemTimestamp time_stamp) diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 82bc91a747..92ff3ece76 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -3,15 +3,18 @@ #ifdef ENABLE_LOGS_PREVIEW -# include # include "opentelemetry/exporters/ostream/log_record_exporter.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/nostd/span.h" +# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" # include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/logs/read_write_log_record.h" # include "opentelemetry/sdk/logs/simple_log_record_processor.h" +# include "opentelemetry/sdk/version/version.h" # include + +# include # include namespace sdklogs = opentelemetry::sdk::logs; diff --git a/exporters/ostream/test/ostream_metric_test.cc b/exporters/ostream/test/ostream_metric_test.cc index cb4a8a3ab4..17fbcb5880 100644 --- a/exporters/ostream/test/ostream_metric_test.cc +++ b/exporters/ostream/test/ostream_metric_test.cc @@ -2,18 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include -#include -#include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/resource/resource_detector.h" -#include "opentelemetry/sdk/version/version.h" -#include #include "opentelemetry/exporters/ostream/metric_exporter.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/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/resource/resource_detector.h" +#include "opentelemetry/sdk/version/version.h" + +#include +#include +#include namespace metric_sdk = opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index 4f56c2f356..f642bbf85e 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -3,6 +3,7 @@ #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include "opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" OPENTELEMETRY_BEGIN_NAMESPACE 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 f2962a0b0c..f2ed416327 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -19,8 +19,10 @@ # include "opentelemetry/sdk/logs/batch_log_record_processor.h" # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/logs/recordable.h" # include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/sdk/trace/exporter.h" +# include "opentelemetry/sdk/trace/processor.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 9c5bfe1766..2ac698b0de 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -17,6 +17,7 @@ # include "opentelemetry/ext/http/client/http_client_factory.h" # include "opentelemetry/ext/http/server/http_server.h" # include "opentelemetry/sdk/trace/batch_span_processor.h" +# include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include "opentelemetry/trace/provider.h" diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index c47c86e110..97586b101c 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -16,9 +16,11 @@ #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/ext/http/server/http_server.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/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index f1b1c73741..4db58844f7 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include "opentelemetry/sdk/resource/resource.h" #if defined(__GNUC__) // GCC raises -Wsuggest-override warnings on GTest, diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 96b486e51e..3397053e29 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/zipkin/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/resource/semantic_conventions.h" #include diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index f8493bec6d..fab19efb65 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -4,10 +4,10 @@ #ifndef HAVE_CPP_STDLIB # include "opentelemetry/exporters/zipkin/zipkin_exporter.h" -# include # include "opentelemetry/ext/http/client/curl/http_client_curl.h" # include "opentelemetry/ext/http/server/http_server.h" # include "opentelemetry/sdk/trace/batch_span_processor.h" +# include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" # include "opentelemetry/trace/provider.h" @@ -16,6 +16,8 @@ # include "nlohmann/json.hpp" +# include + # if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 562f45f107..92807dd8ad 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -6,6 +6,7 @@ #include "opentelemetry/ext/http/client/curl/http_client_curl.h" #include "opentelemetry/ext/http/server/http_server.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" diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 72fbb5e21c..cfe12a2707 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -4,10 +4,12 @@ #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/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" +#include #include namespace trace = opentelemetry::trace; diff --git a/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h b/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h index 07e19ac0f8..39c0ce91cc 100644 --- a/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h +++ b/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h @@ -6,6 +6,7 @@ #include #include #include + #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/common/attribute_utils.h b/sdk/include/opentelemetry/sdk/common/attribute_utils.h index b7839bddc7..c8afd657e2 100644 --- a/sdk/include/opentelemetry/sdk/common/attribute_utils.h +++ b/sdk/include/opentelemetry/sdk/common/attribute_utils.h @@ -7,8 +7,10 @@ #include #include #include + #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h index 086f6b7901..408070255a 100644 --- a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h +++ b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h @@ -3,8 +3,13 @@ #pragma once -#include +#include + +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/common/circular_buffer.h b/sdk/include/opentelemetry/sdk/common/circular_buffer.h index 9f34659352..c2548012b1 100644 --- a/sdk/include/opentelemetry/sdk/common/circular_buffer.h +++ b/sdk/include/opentelemetry/sdk/common/circular_buffer.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include diff --git a/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h b/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h index 9ef3b66be0..e9b89f9d02 100644 --- a/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h +++ b/sdk/include/opentelemetry/sdk/common/circular_buffer_range.h @@ -4,8 +4,6 @@ #pragma once #include -#include -#include #include #include "opentelemetry/nostd/span.h" diff --git a/sdk/include/opentelemetry/sdk/common/empty_attributes.h b/sdk/include/opentelemetry/sdk/common/empty_attributes.h index 4f740bf10e..664f907d23 100644 --- a/sdk/include/opentelemetry/sdk/common/empty_attributes.h +++ b/sdk/include/opentelemetry/sdk/common/empty_attributes.h @@ -3,14 +3,14 @@ #pragma once -#include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/common/macros.h" - #include -#include #include #include +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index 56103d3818..74dd90ccc6 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -3,7 +3,6 @@ #pragma once -#include #include #include diff --git a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h index 8a7f9b808a..52f58c6f4e 100644 --- a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h +++ b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h b/sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h index 5d75e61f75..9bae218ba4 100644 --- a/sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h +++ b/sdk/include/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h @@ -3,16 +3,16 @@ #pragma once -#include "opentelemetry/common/key_value_iterable.h" +#include + #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/type_traits.h" #include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/version.h" -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk 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 d13e8782f1..23a1d947aa 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h @@ -8,6 +8,7 @@ # 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 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 55adc68f72..83740542cb 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 @@ -7,9 +7,7 @@ # 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 namespace sdk @@ -18,6 +16,10 @@ namespace sdk namespace logs { +struct BatchLogRecordProcessorOptions; +class LogRecordExporter; +class LogRecordProcessor; + /** * Factory class for BatchLogRecordProcessor. */ diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h index 1449bb48dc..05a2c48c3c 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h @@ -5,11 +5,11 @@ #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/sdk/version/version.h" - # include # include +# include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger.h b/sdk/include/opentelemetry/sdk/logs/event_logger.h index 85ad924766..b15754940a 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger.h @@ -4,19 +4,21 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include -# include +# include -# include "opentelemetry/common/macros.h" # include "opentelemetry/logs/event_logger.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/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { +class Logger; +class LogRecord; class EventLogger final : public opentelemetry::logs::EventLogger { diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h index ba12d94600..0eb9435f45 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h @@ -5,9 +5,9 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/logs/event_logger_provider.h" -# include "opentelemetry/logs/logger.h" # include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/logs/logger.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/version.h" // Define the maximum number of loggers that are allowed to be registered to the loggerprovider. // TODO: Add link to logging spec once this is added to it @@ -18,6 +18,7 @@ namespace sdk { namespace logs { +class EventLogger; class Logger; class EventLoggerProvider final : public opentelemetry::logs::EventLoggerProvider 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 06aa1c4f2e..ecc78d1b80 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h @@ -5,10 +5,15 @@ #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/logs/event_logger_provider.h" -# include "opentelemetry/nostd/shared_ptr.h" +# include +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace logs +{ +class EventLoggerProvider; +} // namespace logs + namespace sdk { namespace logs diff --git a/sdk/include/opentelemetry/sdk/logs/exporter.h b/sdk/include/opentelemetry/sdk/logs/exporter.h index 069fd8784c..fc0e68564c 100644 --- a/sdk/include/opentelemetry/sdk/logs/exporter.h +++ b/sdk/include/opentelemetry/sdk/logs/exporter.h @@ -4,19 +4,20 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW +# include # include -# include # include "opentelemetry/nostd/span.h" # include "opentelemetry/sdk/common/exporter_utils.h" -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/logs/recordable.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE 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 d290df98c3..67eafe84bc 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -5,14 +5,15 @@ #ifdef ENABLE_LOGS_PREVIEW # include -# include +# include # include "opentelemetry/common/macros.h" # include "opentelemetry/logs/logger.h" +# include "opentelemetry/nostd/string_view.h" # include "opentelemetry/nostd/unique_ptr.h" # include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" # include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context.h b/sdk/include/opentelemetry/sdk/logs/logger_context.h index fe6db6822a..0b2de9bc15 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context.h @@ -5,9 +5,10 @@ #ifdef ENABLE_LOGS_PREVIEW +# include # include +# include -# include "opentelemetry/sdk/logs/processor.h" # include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/version.h" @@ -16,6 +17,8 @@ namespace sdk { namespace logs { +class LogRecordProcessor; + /** * A class which stores the LoggerContext context. * diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h index 377094d5db..0e3502c10c 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -6,17 +6,22 @@ #ifdef ENABLE_LOGS_PREVIEW # 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 a5190c7a30..3c9211cc36 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -6,16 +6,13 @@ # include # include -# include # include # include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/logs/noop.h" # include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/common/atomic_shared_ptr.h" -# include "opentelemetry/sdk/logs/logger.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/version.h" // Define the maximum number of loggers that are allowed to be registered to the loggerprovider. // TODO: Add link to logging spec once this is added to it @@ -27,6 +24,8 @@ namespace sdk namespace logs { class Logger; +class LoggerContext; +class LogRecordProcessor; class LoggerProvider final : public opentelemetry::logs::LoggerProvider { diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h index 0795129df3..bbd715dc89 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -8,18 +8,25 @@ # include # include -# include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/common/atomic_shared_ptr.h" -# include "opentelemetry/sdk/logs/logger.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace logs +{ +class LoggerProvider; +} // namespace logs + namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + namespace logs { +class LoggerContext; +class LogRecordProcessor; /** * Factory class for LoggerProvider. 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 54a7e7959e..91995aa6a3 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h @@ -5,12 +5,11 @@ #ifdef ENABLE_LOGS_PREVIEW +# include # include # include -# include "opentelemetry/sdk/logs/multi_recordable.h" # include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -18,6 +17,7 @@ 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 c91cad52ff..c3e87c12db 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 @@ -8,13 +8,14 @@ # include # include -# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE 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 5944d49b39..97ae1451fc 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h @@ -10,7 +10,6 @@ # include # include "opentelemetry/common/macros.h" -# include "opentelemetry/sdk/logs/processor.h" # include "opentelemetry/sdk/logs/recordable.h" # include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/version.h" @@ -20,6 +19,8 @@ namespace sdk { namespace logs { +class LogRecordProcessor; + class MultiRecordable final : public Recordable { public: diff --git a/sdk/include/opentelemetry/sdk/logs/processor.h b/sdk/include/opentelemetry/sdk/logs/processor.h index 97f823a25b..8a409e0020 100644 --- a/sdk/include/opentelemetry/sdk/logs/processor.h +++ b/sdk/include/opentelemetry/sdk/logs/processor.h @@ -7,14 +7,15 @@ # include # include -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/sdk/logs/recordable.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { +class Recordable; + /** * The Log Processor is responsible for passing log records * to the configured exporter. diff --git a/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h b/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h index a850072134..915c8852e9 100644 --- a/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h @@ -6,18 +6,17 @@ # include # include +# include # include "opentelemetry/common/attribute_value.h" # include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/timestamp.h" # include "opentelemetry/logs/log_record.h" # include "opentelemetry/logs/severity.h" -# include "opentelemetry/nostd/unique_ptr.h" +# include "opentelemetry/nostd/string_view.h" # include "opentelemetry/sdk/common/attribute_utils.h" # include "opentelemetry/sdk/common/empty_attributes.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" # include "opentelemetry/sdk/logs/readable_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" diff --git a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h index 90a1c4b7b7..ba20ca7949 100644 --- a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h @@ -8,22 +8,32 @@ # include # include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/timestamp.h" # include "opentelemetry/logs/severity.h" -# include "opentelemetry/sdk/common/attribute_utils.h" -# include "opentelemetry/sdk/common/empty_attributes.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +# include "opentelemetry/nostd/string_view.h" # include "opentelemetry/sdk/logs/recordable.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 trace +{ +class SpanId; +class TraceId; +class TraceFlags; +} // namespace trace + namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + +namespace instrumentationscope +{ +class InstrumentationScope; +} // namespace instrumentationscope + namespace logs { /** diff --git a/sdk/include/opentelemetry/sdk/logs/recordable.h b/sdk/include/opentelemetry/sdk/logs/recordable.h index 983a2e6b57..ff0099af56 100644 --- a/sdk/include/opentelemetry/sdk/logs/recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/recordable.h @@ -4,24 +4,22 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/key_value_iterable.h" -# include "opentelemetry/common/timestamp.h" # include "opentelemetry/logs/log_record.h" -# include "opentelemetry/logs/severity.h" -# include "opentelemetry/sdk/common/attribute_utils.h" -# include "opentelemetry/sdk/common/empty_attributes.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/sdk/logs/recordable.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 { +namespace resource +{ +class Resource; +} // namespace resource + +namespace instrumentationscope +{ +class InstrumentationScope; +} // namespace instrumentationscope + namespace logs { /** 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 f3d6bc27c3..4bb3dab2de 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h @@ -5,18 +5,21 @@ #ifdef ENABLE_LOGS_PREVIEW # include +# include # include -# include # include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE 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 aec65349c5..cd022aadd6 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 @@ -7,14 +7,15 @@ # include -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { +class LogRecordExporter; +class LogRecordProcessor; /** * Factory class for SimpleLogRecordProcessor. diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h index 361a1cd3b8..a4ec9175c5 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h @@ -3,9 +3,11 @@ #pragma once -#include "opentelemetry/nostd/string_view.h" +#include + #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/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h index 69dc4c8864..f5a48d7ddb 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h @@ -3,10 +3,10 @@ #pragma once -#include "opentelemetry/version.h" - #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 927c17e968..203a2d32b9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -4,23 +4,22 @@ #pragma once #include -#include "opentelemetry/common/spin_lock_mutex.h" + #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" #include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.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/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/instruments.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { +class AggregationConfig; class DefaultAggregation { diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h index 713ce60b8e..4664f8dcd4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h @@ -3,10 +3,11 @@ #pragma once -#include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include -#include +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h index 5d1097d93f..4419ee81f3 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h @@ -3,18 +3,20 @@ #pragma once +#include #include + #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" -#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" - -#include +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { +class AggregationConfig; class LongHistogramAggregation : public Aggregation { diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h index 05242e304d..859fe26d6b 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 "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" - -#include +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h index 881854e0c2..a098d86b72 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 "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" - -#include +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index 321c8089c1..a22ce1f0f8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -3,11 +3,12 @@ #pragma once +#include + #include "opentelemetry/metrics/async_instruments.h" #include "opentelemetry/metrics/observer_result.h" -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/instruments.h" -#include "opentelemetry/sdk/metrics/state/observable_registry.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -16,6 +17,7 @@ namespace metrics { class AsyncWritableMetricStorage; +class ObservableRegistry; class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument { diff --git a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h index b9f72e9b58..0420b50aab 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h @@ -6,11 +6,10 @@ #include #include "opentelemetry/common/timestamp.h" -#include "opentelemetry/context/context.h" #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/metrics/data/metric_data.h" -#include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/trace/span_context.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h index 28a53dd407..ad1084f581 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h @@ -3,12 +3,12 @@ #pragma once +#include + #include "opentelemetry/nostd/variant.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/instruments.h" -#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h index 62ba3df1bc..9bf82e040a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h @@ -3,13 +3,12 @@ #pragma once +#include + #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/variant.h" -#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h index c10ec061bb..4a1366aa80 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h @@ -4,8 +4,14 @@ #pragma once #include "opentelemetry/sdk/metrics/exemplar/filter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h index cfc3439992..f3bc904e26 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h @@ -3,12 +3,24 @@ #pragma once -#include "opentelemetry/context/context.h" +#include + #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace context +{ +class Context; +} // namespace context + namespace sdk { +namespace common +{ +class OrderedAttributeMap; +} // namespace common + namespace metrics { using MetricAttributes = opentelemetry::sdk::common::OrderedAttributeMap; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h index 5264c33170..6ed97a689e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h @@ -5,13 +5,22 @@ #include #include -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attribute_utils.h" + #include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class SystemTimestamp; +} // namespace common + +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h index d2cc13f20c..76f5742ca2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h @@ -5,6 +5,7 @@ #include #include + #include "opentelemetry/context/context.h" #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/shared_ptr.h" diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h index 7da7dc8ac0..bbc032df3b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h @@ -5,16 +5,25 @@ #include #include -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attribute_utils.h" + #include "opentelemetry/sdk/metrics/data/exemplar_data.h" #include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class OrderedAttributeMap; +} // namespace common + +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h index 1f2967467b..84d4ef9f77 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h @@ -4,8 +4,14 @@ #pragma once #include "opentelemetry/sdk/metrics/exemplar/filter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h index d137991f71..edcde3c12f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h @@ -3,17 +3,30 @@ #pragma once +#include #include -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attribute_utils.h" + +#include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class SystemTimestamp; +} // namespace common + +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics { +class ExemplarData; + class NoExemplarReservoir final : public ExemplarReservoir { diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h index ea418b698d..258e099f0f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h @@ -3,16 +3,30 @@ #pragma once +#include #include -#include "opentelemetry/sdk/metrics/data/exemplar_data.h" + #include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class SystemTimestamp; +} // namespace common + +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics { +class ExemplarData; + /** * An interface for an exemplar reservoir of samples. * diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h index 2309fc72e4..6074393d2d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h @@ -5,16 +5,20 @@ #include #include -#include + #include "opentelemetry/common/timestamp.h" -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/metrics/data/exemplar_data.h" #include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/trace/context.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h index 1017d64aa7..b3b2f09e23 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h @@ -4,14 +4,18 @@ #pragma once #include -#include #include -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/attribute_utils.h" + +#include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace context +{ +class Context; +} // namespace context + namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h index de01cbc632..fbc0489d3d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h @@ -5,6 +5,7 @@ #include "opentelemetry/sdk/metrics/exemplar/filter.h" #include "opentelemetry/trace/context.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h index 82b8c1c474..2a0c87fcaa 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h @@ -3,13 +3,25 @@ #pragma once -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include + +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/metrics/data/metric_data.h" -#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + +namespace instrumentationscope +{ +class InstrumentationScope; +} // namespace instrumentationscope + namespace metrics { 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 83773ffb61..29c2e351e5 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 @@ -3,14 +3,16 @@ #pragma once -#include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/version.h" - #include #include #include +#include +#include #include +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h b/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h index 95848a8eec..fec1027746 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h +++ b/sdk/include/opentelemetry/sdk/metrics/instrument_metadata_validator.h @@ -4,6 +4,7 @@ #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/instruments.h b/sdk/include/opentelemetry/sdk/metrics/instruments.h index 6c6497555b..84244128a4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/instruments.h @@ -4,8 +4,10 @@ #pragma once #include -#include "opentelemetry/common/macros.h" +#include + #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 6beff61063..41a10f69e9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -4,15 +4,22 @@ #pragma once #include +#include +#include +#include +#include + +#include "opentelemetry/common/macros.h" #include "opentelemetry/metrics/meter.h" #include "opentelemetry/metrics/noop.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/metrics/instrument_metadata_validator.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/state/async_metric_storage.h" - -#include "opentelemetry/common/macros.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk_config.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 75ab2a4be9..8155b4da9f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -3,18 +3,19 @@ #pragma once +#include +#include +#include +#include + #include "opentelemetry/common/spin_lock_mutex.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/common/timestamp.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -22,8 +23,11 @@ namespace metrics { // forward declaration +class CollectorHandle; +class InstrumentSelector; class Meter; class MetricReader; +class MeterSelector; /** * A class which stores the MeterProvider context. diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index f2c72e2d25..fedf6aac61 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -3,24 +3,30 @@ #pragma once +#include #include #include -#include -#include "opentelemetry/metrics/meter.h" + #include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/metrics/meter.h" -#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ +class Meter; +} // namespace metrics + namespace sdk { namespace metrics { // forward declaration +class MeterContext; class MetricCollector; class MetricReader; @@ -40,7 +46,7 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider * Initialize a new meter provider with a specified context * @param context The shared meter configuration/pipeline for this provider. */ - explicit MeterProvider(std::shared_ptr context) noexcept; + explicit MeterProvider(std::shared_ptr context) noexcept; nostd::shared_ptr GetMeter( nostd::string_view name, @@ -88,7 +94,7 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider ~MeterProvider() override; private: - std::shared_ptr context_; + std::shared_ptr context_; std::mutex lock_; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h index 86101e39a0..96b34a4427 100644 --- a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h +++ b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h @@ -3,21 +3,22 @@ #pragma once +#include +#include + #include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/sdk/common/global_log_handler.h" +#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" -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE 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/observer_result.h b/sdk/include/opentelemetry/sdk/metrics/observer_result.h index 4b6a55e3bc..38c5843633 100644 --- a/sdk/include/opentelemetry/sdk/metrics/observer_result.h +++ b/sdk/include/opentelemetry/sdk/metrics/observer_result.h @@ -3,12 +3,13 @@ #pragma once +#include + #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/metrics/observer_result.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h b/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h index 58e2c68c62..409a826ca9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h +++ b/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h @@ -3,21 +3,20 @@ #pragma once -#include "opentelemetry/nostd/span.h" +#include + #include "opentelemetry/sdk/common/exporter_utils.h" -#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/version.h" -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { - class MetricData; +struct ResourceMetrics; + /** * PushMetricExporter defines the interface to be used by metrics libraries to * push metrics data to the OpenTelemetry exporters. diff --git a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h index aad00bb5cf..aada06142a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -3,6 +3,10 @@ #pragma once +#include +#include +#include + #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/common/attributemap_hash.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" @@ -14,8 +18,6 @@ #include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index 95cd8a7d10..e94c005ecc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -3,8 +3,12 @@ #pragma once -#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include +#include + #include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h index 0f8f4ddba7..277b45fbb6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h @@ -3,14 +3,28 @@ #pragma once -#include "opentelemetry/common/key_value_iterable_view.h" +#include +#include + #include "opentelemetry/common/timestamp.h" -#include "opentelemetry/context/context.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/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/state/multi_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h index 421c12b34c..6202b0c7fb 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h @@ -3,13 +3,26 @@ #pragma once -#include "opentelemetry/common/key_value_iterable_view.h" +#include +#include +#include + +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" - -#include +#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/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index 09c439afa4..5eb5b6d6ff 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -3,13 +3,14 @@ #pragma once -#include "opentelemetry/common/timestamp.h" -#include "opentelemetry/metrics/async_instruments.h" - #include #include #include +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { 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 b8146872e3..37b0e06707 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -3,8 +3,18 @@ #pragma once +#include +#include +#include +#include +#include #include -#include "opentelemetry/common/key_value_iterable_view.h" + +#include "opentelemetry/common/spin_lock_mutex.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/default_aggregation.h" #include "opentelemetry/sdk/metrics/exemplar/reservoir.h" @@ -14,9 +24,7 @@ #include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" #include "opentelemetry/sdk/metrics/view/attributes_processor.h" - -#include -#include +#include "opentelemetry/version.h" 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 4ddc593149..0a08e7d100 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -3,19 +3,26 @@ #pragma once -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" -#include "opentelemetry/sdk/metrics/state/metric_collector.h" - #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/instruments.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE 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 803191170c..825547a846 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -3,14 +3,13 @@ #pragma once -#include "opentelemetry/common/key_value_iterable.h" +#include + #include "opentelemetry/metrics/sync_instruments.h" -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" #include "opentelemetry/sdk_config.h" - -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index c3328bfa1e..91e4b268cf 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -3,7 +3,14 @@ #pragma once +#include +#include + +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h index a8cf38b49f..2055ed96fa 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h @@ -3,9 +3,13 @@ #pragma once +#include + #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/view/predicate_factory.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h index de61d21412..16d777b71f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h @@ -3,8 +3,11 @@ #pragma once +#include + #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/view/predicate_factory.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h index 7df3955873..ba2303ff92 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h @@ -3,8 +3,11 @@ #pragma once +#include + #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/view/predicate.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index 678c53f6c6..2d3edcee0e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -3,12 +3,13 @@ #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/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index 87773b2091..9f12259665 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -3,11 +3,16 @@ #pragma once +#include #include +#include + +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.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/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/resource/resource.h b/sdk/include/opentelemetry/sdk/resource/resource.h index 09da0b8c97..d578491d78 100644 --- a/sdk/include/opentelemetry/sdk/resource/resource.h +++ b/sdk/include/opentelemetry/sdk/resource/resource.h @@ -3,18 +3,11 @@ #pragma once -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/common/key_value_iterable_view.h" +#include #include "opentelemetry/sdk/common/attribute_utils.h" -#include "opentelemetry/sdk/resource/resource_detector.h" -#include "opentelemetry/sdk/version/version.h" #include "opentelemetry/version.h" -#include -#include -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/resource/resource_detector.h b/sdk/include/opentelemetry/sdk/resource/resource_detector.h index 6447a2660d..dcbd874847 100644 --- a/sdk/include/opentelemetry/sdk/resource/resource_detector.h +++ b/sdk/include/opentelemetry/sdk/resource/resource_detector.h @@ -3,7 +3,7 @@ #pragma once -#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,8 +12,6 @@ namespace sdk namespace resource { -class Resource; - /** * Interface for a Resource Detector */ diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h index 60e93d8a9f..34d499a2ef 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h @@ -3,21 +3,23 @@ #pragma once -#include "opentelemetry/sdk/common/circular_buffer.h" -#include "opentelemetry/sdk/trace/batch_span_processor_options.h" -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/processor.h" - #include #include +#include +#include #include +#include "opentelemetry/sdk/common/circular_buffer.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { - namespace trace { +class SpanExporter; +struct BatchSpanProcessorOptions; /** * This is an implementation of the SpanProcessor which creates batches of finished spans and passes diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h index 6e66d2d2b9..4f645b2633 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h @@ -5,16 +5,16 @@ #include -#include "opentelemetry/sdk/trace/batch_span_processor_options.h" -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/processor.h" -#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class SpanExporter; +class SpanProcessor; +struct BatchSpanProcessorOptions; /** * Factory class for BatchSpanProcessor. diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h index 053126c065..ac1052383b 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_options.h @@ -3,10 +3,10 @@ #pragma once -#include "opentelemetry/sdk/version/version.h" - #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/trace/exporter.h b/sdk/include/opentelemetry/sdk/trace/exporter.h index ffacca2b35..f9ed068b64 100644 --- a/sdk/include/opentelemetry/sdk/trace/exporter.h +++ b/sdk/include/opentelemetry/sdk/trace/exporter.h @@ -3,16 +3,20 @@ #pragma once +#include #include + #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" -#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class Recordable; + /** * SpanExporter defines the interface that protocol-specific span exporters must * implement. @@ -40,8 +44,7 @@ class OPENTELEMETRY_EXPORT SpanExporter * @param spans a span of unique pointers to span recordables */ virtual sdk::common::ExportResult Export( - const nostd::span> - &spans) noexcept = 0; + const nostd::span> &spans) noexcept = 0; /** * Export all spans that have been exported. diff --git a/sdk/include/opentelemetry/sdk/trace/id_generator.h b/sdk/include/opentelemetry/sdk/trace/id_generator.h index 559870d961..bd807ff89a 100644 --- a/sdk/include/opentelemetry/sdk/trace/id_generator.h +++ b/sdk/include/opentelemetry/sdk/trace/id_generator.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" diff --git a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h index 6abd39f90b..8519591286 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h @@ -3,13 +3,13 @@ #pragma once +#include + #include "opentelemetry/common/timestamp.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h b/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h index e3b4a2031e..094c5b3e24 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h @@ -3,13 +3,14 @@ #pragma once +#include +#include #include #include #include "opentelemetry/sdk/trace/multi_recordable.h" #include "opentelemetry/sdk/trace/processor.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/processor.h b/sdk/include/opentelemetry/sdk/trace/processor.h index f87b893837..3701422eb5 100644 --- a/sdk/include/opentelemetry/sdk/trace/processor.h +++ b/sdk/include/opentelemetry/sdk/trace/processor.h @@ -5,13 +5,21 @@ #include #include -#include "opentelemetry/sdk/trace/recordable.h" + +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +class SpanContext; +} // namespace trace + namespace sdk { namespace trace { +class Recordable; + /** * Span processor allow hooks for span start and end method invocations. * diff --git a/sdk/include/opentelemetry/sdk/trace/random_id_generator.h b/sdk/include/opentelemetry/sdk/trace/random_id_generator.h index 59df91651f..f06f02f5e7 100644 --- a/sdk/include/opentelemetry/sdk/trace/random_id_generator.h +++ b/sdk/include/opentelemetry/sdk/trace/random_id_generator.h @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include "opentelemetry/sdk/trace/id_generator.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/random_id_generator_factory.h b/sdk/include/opentelemetry/sdk/trace/random_id_generator_factory.h index 1b8f7e3c3b..6c94984403 100644 --- a/sdk/include/opentelemetry/sdk/trace/random_id_generator_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/random_id_generator_factory.h @@ -5,13 +5,14 @@ #include -#include "opentelemetry/sdk/trace/id_generator.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class IdGenerator; /** * Factory class for RandomIdGenerator. diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index 721e33232d..cb73ef5f64 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -3,27 +3,33 @@ #pragma once +#include + #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/common/empty_attributes.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/trace/canonical_code.h" -#include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" -#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/span_metadata.h" #include "opentelemetry/version.h" -#include - // TODO: Create generic short pattern for opentelemetry::common and opentelemetry::trace OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + namespace trace { diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 799d490e8b..b90a2e66b2 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -3,19 +3,30 @@ #pragma once -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/trace/span.h" -#include "opentelemetry/trace/span_context.h" -#include "opentelemetry/trace/span_context_kv_iterable.h" -#include "opentelemetry/trace/trace_id.h" -#include "opentelemetry/trace/trace_state.h" -#include "opentelemetry/version.h" - #include #include #include +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + +namespace trace +{ +class SpanContext; +class SpanContextKeyValueIterable; +class TraceState; +} // namespace trace + namespace sdk { namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h index 2392b9b2fb..a857086d23 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h @@ -3,7 +3,12 @@ #pragma once +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_off_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_off_factory.h index 2ae09b229c..19f76c715f 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_off_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_off_factory.h @@ -5,13 +5,14 @@ #include -#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class Sampler; /** * Factory class for AlwaysOffSampler. diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h index 6c8583599d..6b983008c7 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h @@ -3,9 +3,24 @@ #pragma once +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + +namespace trace +{ +class SpanContextKeyValueIterable; +} // namespace trace + namespace sdk { namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on_factory.h index 3484f0d4fa..c72d97fdec 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_on_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on_factory.h @@ -5,13 +5,14 @@ #include -#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class Sampler; /** * Factory class for AlwaysOnSampler. diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h index c76a6c2a58..59dd314589 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h @@ -3,10 +3,25 @@ #pragma once -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" +#include + +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + +namespace trace +{ +class SpanContext; +class SpanContextKeyValueIterable; +class TraceState; +} // namespace trace + namespace sdk { namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h index 006bdab1da..2fdf87819d 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h @@ -5,13 +5,14 @@ #include -#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class Sampler; /** * Factory class for ParentBasedSampler. diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h index 407b480d62..b5df576091 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h @@ -3,9 +3,27 @@ #pragma once +#include + +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + +namespace trace +{ +class SpanContext; +class SpanContextKeyValueIterable; +class TraceState; +} // namespace trace + namespace sdk { namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h index 79728ba200..eb434fc6fe 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h @@ -5,13 +5,14 @@ #include -#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class Sampler; /** * Factory class for TraceIdRatioBasedSampler. diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index 671218d0cf..dee8e80bb8 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -4,11 +4,16 @@ #pragma once #include +#include +#include #include #include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h b/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h index efa3078a38..6a106e7f21 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h @@ -5,14 +5,15 @@ #include -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class SpanExporter; +class SpanProcessor; /** * Factory class for SimpleSpanProcessor. diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 61a7ced6fe..4e1a52ce5d 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -4,20 +4,23 @@ #pragma once #include +#include +#include +#include #include #include + #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/macros.h" #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/recordable.h" -#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index 3ac17aad66..67e606ba97 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -3,40 +3,46 @@ #pragma once +#include + #include "opentelemetry/common/macros.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.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/processor.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/tracer_context.h" -#include "opentelemetry/trace/noop.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + namespace trace { +class IdGenerator; +class SpanProcessor; using namespace opentelemetry::sdk::instrumentationscope; -class Tracer final : public trace_api::Tracer, public std::enable_shared_from_this +class Tracer final : public opentelemetry::trace::Tracer, + public std::enable_shared_from_this { public: /** Construct a new Tracer with the given context pipeline. */ - explicit Tracer(std::shared_ptr context, + explicit Tracer(std::shared_ptr context, std::unique_ptr instrumentation_scope = InstrumentationScope::Create("")) noexcept; - nostd::shared_ptr StartSpan( + nostd::shared_ptr StartSpan( nostd::string_view name, const opentelemetry::common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options = {}) noexcept override; + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override; void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override; @@ -70,7 +76,7 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th // order of declaration is important here - instrumentation scope should destroy after // tracer-context. std::shared_ptr instrumentation_scope_; - std::shared_ptr context_; + std::shared_ptr context_; }; } // namespace trace } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 6dcdda8e01..9475c8c0b9 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -3,7 +3,10 @@ #pragma once -#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include +#include +#include + #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/random_id_generator.h" diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h index b03ae297fc..1911db8f93 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h @@ -3,16 +3,25 @@ #pragma once -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/trace/processor.h" -#include "opentelemetry/sdk/trace/tracer_context.h" +#include +#include + #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + namespace trace { +class IdGenerator; +class Sampler; +class SpanProcessor; +class TracerContext; /** * Factory class for TracerContext. diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 06088738c2..e15f686898 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -10,18 +10,22 @@ #include #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/random_id_generator.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" -#include "opentelemetry/sdk/trace/tracer.h" -#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace trace { +class SpanProcessor; +class Tracer; +class TracerContext; + class TracerProvider final : public opentelemetry::trace::TracerProvider { public: @@ -40,24 +44,22 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), - std::unique_ptr id_generator = - std::unique_ptr( - new RandomIdGenerator())) noexcept; + std::unique_ptr id_generator = + std::unique_ptr(new RandomIdGenerator())) noexcept; explicit TracerProvider( std::vector> &&processors, opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), - std::unique_ptr id_generator = - std::unique_ptr( - new RandomIdGenerator())) noexcept; + std::unique_ptr id_generator = + std::unique_ptr(new RandomIdGenerator())) noexcept; /** * Initialize a new tracer provider with a specified context * @param context The shared tracer configuration/pipeline for this provider. */ - explicit TracerProvider(std::shared_ptr context) noexcept; + explicit TracerProvider(std::shared_ptr context) noexcept; ~TracerProvider() override; @@ -94,8 +96,8 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider private: // order of declaration is important here - tracers should destroy only after context. - std::vector> tracers_; - std::shared_ptr context_; + std::vector> tracers_; + std::shared_ptr context_; std::mutex lock_; }; } // namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h index 14458b2409..93bd1085ac 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h @@ -4,16 +4,29 @@ #pragma once #include +#include -#include "opentelemetry/sdk/trace/processor.h" -#include "opentelemetry/sdk/trace/tracer_context.h" -#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +class TracerProvider; +} // namespace trace + namespace sdk { +namespace resource +{ +class Resource; +} // namespace resource + namespace trace { +class IdGenerator; +class Sampler; +class SpanProcessor; +class TracerContext; /** * Factory class for TracerProvider. @@ -65,7 +78,7 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory /* Create with a tracer context. */ static std::unique_ptr Create( - std::shared_ptr context); + std::shared_ptr context); }; } // namespace trace diff --git a/sdk/src/common/global_log_handler.cc b/sdk/src/common/global_log_handler.cc index 040e3e2154..bd1b56a9cd 100644 --- a/sdk/src/common/global_log_handler.cc +++ b/sdk/src/common/global_log_handler.cc @@ -3,8 +3,7 @@ #include "opentelemetry/sdk/common/global_log_handler.h" -#include -#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index 6b1db1c666..5487d70e80 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -2,10 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_LOGS_PREVIEW + # include "opentelemetry/sdk/logs/batch_log_record_processor.h" # include "opentelemetry/common/spin_lock_mutex.h" +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/sdk/logs/recordable.h" # include + using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBufferRange; diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 4c76b198bb..e9ebb8bdc4 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -2,8 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_LOGS_PREVIEW + # include "opentelemetry/sdk/logs/logger.h" # include "opentelemetry/context/runtime_context.h" +# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/sdk/logs/recordable.h" # include "opentelemetry/sdk_config.h" # include "opentelemetry/trace/provider.h" @@ -47,10 +50,10 @@ 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 (nostd::holds_alternative>(context_value)) { - nostd::shared_ptr &data = - nostd::get>(context_value); + nostd::shared_ptr &data = + nostd::get>(context_value); if (data) { recordable->SetTraceId(data->GetContext().trace_id()); diff --git a/sdk/src/logs/logger_context_factory.cc b/sdk/src/logs/logger_context_factory.cc index 985743fd67..1fc07f53e5 100644 --- a/sdk/src/logs/logger_context_factory.cc +++ b/sdk/src/logs/logger_context_factory.cc @@ -4,6 +4,9 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/logs/logger_context_factory.h" +# include "opentelemetry/sdk/logs/logger_context.h" +# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/sdk/resource/resource.h" # include # include diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 66948b1744..1e1b83c7de 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -5,12 +5,10 @@ # include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/common/global_log_handler.h" - -# include -# include -# include -# include -# include +# 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" 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 2859126f80..f6e6c2e176 100644 --- a/sdk/src/logs/multi_log_record_processor.cc +++ b/sdk/src/logs/multi_log_record_processor.cc @@ -4,10 +4,8 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/logs/multi_log_record_processor.h" - -# include -# include -# include +# include "opentelemetry/sdk/logs/multi_recordable.h" +# include "opentelemetry/sdk/logs/recordable.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 9ed5ca7ae7..f02d475d47 100644 --- a/sdk/src/logs/readable_log_record.cc +++ b/sdk/src/logs/readable_log_record.cc @@ -3,11 +3,14 @@ #ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/sdk/logs/readable_log_record.h" +# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +# include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/sdk/version/version.h" + # include # include -# include "opentelemetry/sdk/logs/readable_log_record.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 50d4c20fdd..6514c7acff 100644 --- a/sdk/src/logs/simple_log_record_processor.cc +++ b/sdk/src/logs/simple_log_record_processor.cc @@ -2,10 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_LOGS_PREVIEW + # 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 OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index fe01030f13..3213c27f16 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -2,6 +2,7 @@ // 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 diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 1d2b1a9552..082d6713b4 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -3,10 +3,9 @@ #include "opentelemetry/sdk/metrics/async_instruments.h" #include "opentelemetry/sdk/metrics/state/metric_storage.h" +#include "opentelemetry/sdk/metrics/state/observable_registry.h" #include "opentelemetry/sdk_config.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index de25153e1d..eaf82232d6 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -4,8 +4,10 @@ #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk_config.h" -#include "opentelemetry/version.h" + +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 051ee7269e..1e9dc5f434 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -3,6 +3,8 @@ #include "opentelemetry/sdk/metrics/meter_provider.h" #include "opentelemetry/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/common/global_log_handler.h" diff --git a/sdk/src/metrics/metric_reader.cc b/sdk/src/metrics/metric_reader.cc index a778f0c41c..8b1998fbd3 100644 --- a/sdk/src/metrics/metric_reader.cc +++ b/sdk/src/metrics/metric_reader.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 148588ad54..f988551108 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -1,14 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include -#include -#include "opentelemetry/nostd/shared_ptr.h" - +#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +#include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/metrics/meter.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" -#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/metric_collector.h" + +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk diff --git a/sdk/src/resource/resource.cc b/sdk/src/resource/resource.cc index f71e17a8a7..12f8e16d43 100644 --- a/sdk/src/resource/resource.cc +++ b/sdk/src/resource/resource.cc @@ -5,6 +5,7 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/resource/resource_detector.h" #include "opentelemetry/sdk/resource/semantic_conventions.h" +#include "opentelemetry/sdk/version/version.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/resource/resource_detector.cc b/sdk/src/resource/resource_detector.cc index f5c856f088..82e47a71ad 100644 --- a/sdk/src/resource/resource_detector.cc +++ b/sdk/src/resource/resource_detector.cc @@ -5,6 +5,9 @@ #include "opentelemetry/sdk/common/env_variables.h" #include "opentelemetry/sdk/resource/resource.h" +#include +#include + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index da9f39f054..dd69eaa68f 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -3,9 +3,14 @@ #include "opentelemetry/sdk/trace/batch_span_processor.h" #include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.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/recordable.h" #include + using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; diff --git a/sdk/src/trace/samplers/parent.cc b/sdk/src/trace/samplers/parent.cc index 3aa6b4a455..990e1a954a 100644 --- a/sdk/src/trace/samplers/parent.cc +++ b/sdk/src/trace/samplers/parent.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/trace/samplers/parent.h" +#include "opentelemetry/trace/span_context.h" namespace trace_api = opentelemetry::trace; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 138c966af3..c7524d43aa 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -5,6 +5,8 @@ #include "src/common/random.h" #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/trace/span_metadata.h" #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/version.h" @@ -48,10 +50,10 @@ SteadyTimestamp NowOr(const SteadyTimestamp &steady) Span::Span(std::shared_ptr &&tracer, nostd::string_view name, const common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options, - const trace_api::SpanContext &parent_span_context, - std::unique_ptr span_context) noexcept + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::trace::StartSpanOptions &options, + const opentelemetry::trace::SpanContext &parent_span_context, + std::unique_ptr span_context) noexcept : tracer_{std::move(tracer)}, recordable_{tracer_->GetProcessor().MakeRecordable()}, start_steady_time{options.start_steady_time}, @@ -66,7 +68,7 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetInstrumentationScope(tracer_->GetInstrumentationScope()); recordable_->SetIdentity(*span_context_, parent_span_context.IsValid() ? parent_span_context.span_id() - : trace_api::SpanId()); + : opentelemetry::trace::SpanId()); attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { recordable_->SetAttribute(key, value); @@ -164,7 +166,7 @@ void Span::UpdateName(nostd::string_view name) noexcept recordable_->SetName(name); } -void Span::End(const trace_api::EndSpanOptions &options) noexcept +void Span::End(const opentelemetry::trace::EndSpanOptions &options) noexcept { std::lock_guard lock_guard{mu_}; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 07fd36d5b7..6ca7b37df5 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -3,13 +3,10 @@ #include "opentelemetry/sdk/trace/tracer.h" #include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/trace/context.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" +#include "opentelemetry/trace/noop.h" -#include +#include "src/trace/span.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -17,21 +14,21 @@ namespace sdk namespace trace { -Tracer::Tracer(std::shared_ptr context, +Tracer::Tracer(std::shared_ptr context, std::unique_ptr instrumentation_scope) noexcept : instrumentation_scope_{std::move(instrumentation_scope)}, context_{context} {} -nostd::shared_ptr Tracer::StartSpan( +nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, const opentelemetry::common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::trace::StartSpanOptions &options) noexcept { - trace_api::SpanContext parent_context = GetCurrentSpan()->GetContext(); - if (nostd::holds_alternative(options.parent)) + opentelemetry::trace::SpanContext parent_context = GetCurrentSpan()->GetContext(); + if (nostd::holds_alternative(options.parent)) { - auto span_context = nostd::get(options.parent); + auto span_context = nostd::get(options.parent); if (span_context.IsValid()) { parent_context = span_context; @@ -48,9 +45,9 @@ nostd::shared_ptr Tracer::StartSpan( } } - trace_api::TraceId trace_id; - trace_api::SpanId span_id = GetIdGenerator().GenerateSpanId(); - bool is_parent_span_valid = false; + opentelemetry::trace::TraceId trace_id; + opentelemetry::trace::SpanId span_id = GetIdGenerator().GenerateSpanId(); + bool is_parent_span_valid = false; if (parent_context.IsValid()) { @@ -64,28 +61,32 @@ nostd::shared_ptr Tracer::StartSpan( auto sampling_result = context_->GetSampler().ShouldSample(parent_context, trace_id, name, options.kind, attributes, links); - auto trace_flags = sampling_result.IsSampled() - ? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled} - : trace_api::TraceFlags{}; - - auto span_context = std::unique_ptr(new trace_api::SpanContext( - trace_id, span_id, trace_flags, false, - sampling_result.trace_state ? sampling_result.trace_state - : is_parent_span_valid ? parent_context.trace_state() - : trace_api::TraceState::GetDefault())); + auto trace_flags = + sampling_result.IsSampled() + ? opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled} + : opentelemetry::trace::TraceFlags{}; + + auto span_context = + std::unique_ptr(new opentelemetry::trace::SpanContext( + trace_id, span_id, trace_flags, false, + sampling_result.trace_state + ? sampling_result.trace_state + : is_parent_span_valid ? parent_context.trace_state() + : opentelemetry::trace::TraceState::GetDefault())); if (!sampling_result.IsRecording()) { // create no-op span with valid span-context. - auto noop_span = nostd::shared_ptr{ - new (std::nothrow) trace_api::NoopSpan(this->shared_from_this(), std::move(span_context))}; + auto noop_span = nostd::shared_ptr{ + new (std::nothrow) + opentelemetry::trace::NoopSpan(this->shared_from_this(), std::move(span_context))}; return noop_span; } else { - auto span = nostd::shared_ptr{ + auto span = nostd::shared_ptr{ new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options, parent_context, std::move(span_context)}}; diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index b5eed6312f..7ac66ed6db 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -3,6 +3,9 @@ #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/tracer.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/sdk_config.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/src/trace/tracer_provider_factory.cc b/sdk/src/trace/tracer_provider_factory.cc index df25694781..158ae949ea 100644 --- a/sdk/src/trace/tracer_provider_factory.cc +++ b/sdk/src/trace/tracer_provider_factory.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/random_id_generator_factory.h" #include "opentelemetry/sdk/trace/samplers/always_on_factory.h" #include "opentelemetry/sdk/trace/tracer_provider.h" diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index cce81d9910..0e5de03050 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -12,6 +12,7 @@ # include "opentelemetry/logs/provider.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_id.h" diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 510f02b4df..e9bc897745 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -10,6 +10,7 @@ # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/string_view.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_provider.h" # include "opentelemetry/sdk/logs/recordable.h" diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 0e5050a973..66f9edb8c5 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -6,12 +6,16 @@ # include # include +# include "opentelemetry/logs/logger_provider.h" # include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/variant.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/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/tracer.h" diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index 9f307cb015..94e5f4c1fa 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#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" diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index 87d0a441d5..10c0335559 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -3,6 +3,7 @@ #include "opentelemetry/sdk/metrics/async_instruments.h" #include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" +#include "opentelemetry/sdk/metrics/state/observable_registry.h" #include diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index f0286ec09e..0568080a6d 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -9,6 +9,8 @@ #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" #include +#include +#include #include using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/exemplar/always_sample_filter_test.cc b/sdk/test/metrics/exemplar/always_sample_filter_test.cc index cd9e58f284..30c86fd37f 100644 --- a/sdk/test/metrics/exemplar/always_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/always_sample_filter_test.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include + +#include "opentelemetry/context/context.h" #include "opentelemetry/sdk/metrics/exemplar/filter.h" using namespace opentelemetry::sdk::metrics; diff --git a/sdk/test/metrics/multi_metric_storage_test.cc b/sdk/test/metrics/multi_metric_storage_test.cc index 1c230bafcf..e7e4151f09 100644 --- a/sdk/test/metrics/multi_metric_storage_test.cc +++ b/sdk/test/metrics/multi_metric_storage_test.cc @@ -9,7 +9,6 @@ #include using namespace opentelemetry; -using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; class TestMetricStorage : public SyncWritableMetricStorage diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 803d5666d9..96de75c04a 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/string_view.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 diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index b7a6558538..411b4dacfe 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -2,11 +2,15 @@ // 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 diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index 17999dcf26..42de190980 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -69,11 +69,13 @@ void BenchmarkShouldSampler(Sampler &sampler, benchmark::State &state) using M = std::map; M m1 = {{}}; - using L = std::vector>>; - L l1 = {{trace_api::SpanContext(false, false), {}}, {trace_api::SpanContext(false, false), {}}}; + using L = + std::vector>>; + L l1 = {{opentelemetry::trace::SpanContext(false, false), {}}, + {opentelemetry::trace::SpanContext(false, false), {}}}; opentelemetry::common::KeyValueIterableView view{m1}; - trace_api::SpanContextKeyValueIterableView links{l1}; + opentelemetry::trace::SpanContextKeyValueIterableView links{l1}; while (state.KeepRunning()) { diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index f92c0f6e93..45b5fc010f 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -17,8 +17,9 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; +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; From d0452f829f901f82dc9905a52c88df5f2bd2c7a1 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 28 Jun 2023 19:08:42 +0200 Subject: [PATCH 024/119] [SDK] Provide builders to avoid exposing Metrics SDK internals (#2189) --- examples/metrics_simple/metrics_ostream.cc | 90 ++++++----- examples/otlp/BUILD | 21 ++- examples/otlp/CMakeLists.txt | 34 ++++- examples/otlp/grpc_metric_main.cc | 35 +++-- examples/otlp/http_metric_main.cc | 142 ++++++++++++++++++ examples/prometheus/main.cc | 51 ++++--- exporters/ostream/BUILD | 2 + exporters/ostream/CMakeLists.txt | 3 +- .../ostream/metric_exporter_factory.h | 50 ++++++ .../ostream/src/metric_exporter_factory.cc | 36 +++++ exporters/prometheus/BUILD | 4 + exporters/prometheus/CMakeLists.txt | 6 +- .../exporters/prometheus/exporter.h | 22 +-- .../exporters/prometheus/exporter_factory.h | 34 +++++ .../exporters/prometheus/exporter_options.h | 29 ++++ exporters/prometheus/src/exporter_factory.cc | 27 ++++ exporters/prometheus/src/exporter_options.cc | 32 ++++ .../export/periodic_exporting_metric_reader.h | 17 +-- ...periodic_exporting_metric_reader_factory.h | 28 ++++ ...periodic_exporting_metric_reader_options.h | 35 +++++ .../sdk/metrics/meter_context_factory.h | 41 +++++ .../sdk/metrics/meter_provider_factory.h | 77 ++++++++++ .../view/instrument_selector_factory.h | 27 ++++ .../sdk/metrics/view/meter_selector_factory.h | 29 ++++ .../sdk/metrics/view/view_factory.h | 49 ++++++ .../sdk/metrics/view/view_registry.h | 1 + .../sdk/metrics/view/view_registry_factory.h | 25 +++ sdk/src/metrics/CMakeLists.txt | 7 + ...eriodic_exporting_metric_reader_factory.cc | 26 ++++ sdk/src/metrics/meter_context_factory.cc | 38 +++++ sdk/src/metrics/meter_provider_factory.cc | 58 +++++++ .../view/instrument_selector_factory.cc | 25 +++ .../metrics/view/meter_selector_factory.cc | 25 +++ sdk/src/metrics/view/view_factory.cc | 57 +++++++ sdk/src/metrics/view/view_registry_factory.cc | 22 +++ 35 files changed, 1090 insertions(+), 115 deletions(-) create mode 100644 examples/otlp/http_metric_main.cc create mode 100644 exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h create mode 100644 exporters/ostream/src/metric_exporter_factory.cc create mode 100644 exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_factory.h create mode 100644 exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h create mode 100644 exporters/prometheus/src/exporter_factory.cc create mode 100644 exporters/prometheus/src/exporter_options.cc create mode 100644 sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/view/view_factory.h create mode 100644 sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h create mode 100644 sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc create mode 100644 sdk/src/metrics/meter_context_factory.cc create mode 100644 sdk/src/metrics/meter_provider_factory.cc create mode 100644 sdk/src/metrics/view/instrument_selector_factory.cc create mode 100644 sdk/src/metrics/view/meter_selector_factory.cc create mode 100644 sdk/src/metrics/view/view_factory.cc create mode 100644 sdk/src/metrics/view/view_registry_factory.cc diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 30a82a02b5..a81937099d 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -3,13 +3,19 @@ #include #include -#include "opentelemetry/exporters/ostream/metric_exporter.h" + +#include "opentelemetry/exporters/ostream/metric_exporter_factory.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/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/meter_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/view_factory.h" #ifdef BAZEL_BUILD # include "examples/common/metrics_foo_library/foo_library.h" @@ -17,7 +23,7 @@ # include "metrics_foo_library/foo_library.h" #endif -namespace metric_sdk = opentelemetry::sdk::metrics; +namespace metrics_sdk = opentelemetry::sdk::metrics; namespace common = opentelemetry::common; namespace exportermetrics = opentelemetry::exporter::metrics; namespace metrics_api = opentelemetry::metrics; @@ -27,59 +33,75 @@ namespace void InitMetrics(const std::string &name) { - std::unique_ptr exporter{ - new exportermetrics::OStreamMetricExporter}; + auto exporter = exportermetrics::OStreamMetricExporterFactory::Create(); std::string version{"1.2.0"}; std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; // Initialize and set the global MeterProvider - metric_sdk::PeriodicExportingMetricReaderOptions options; + metrics_sdk::PeriodicExportingMetricReaderOptions options; options.export_interval_millis = std::chrono::milliseconds(1000); options.export_timeout_millis = std::chrono::milliseconds(500); - std::unique_ptr reader{ - new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)}; - auto provider = std::shared_ptr(new metric_sdk::MeterProvider()); - auto p = std::static_pointer_cast(provider); + + auto reader = + metrics_sdk::PeriodicExportingMetricReaderFactory::Create(std::move(exporter), options); + + auto u_provider = metrics_sdk::MeterProviderFactory::Create(); + auto *p = static_cast(u_provider.get()); + p->AddMetricReader(std::move(reader)); // counter view std::string counter_name = name + "_counter"; - std::unique_ptr instrument_selector{ - new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kCounter, counter_name)}; - std::unique_ptr meter_selector{ - new metric_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr sum_view{ - new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; + + auto instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( + metrics_sdk::InstrumentType::kCounter, counter_name); + + auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); + + auto sum_view = + metrics_sdk::ViewFactory::Create(name, "description", metrics_sdk::AggregationType::kSum); + p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); // observable counter view std::string observable_counter_name = name + "_observable_counter"; - std::unique_ptr observable_instrument_selector{ - new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kObservableCounter, - observable_counter_name)}; - std::unique_ptr observable_meter_selector{ - new metric_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr observable_sum_view{ - new metric_sdk::View{name, "test_description", metric_sdk::AggregationType::kSum}}; + + auto observable_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( + metrics_sdk::InstrumentType::kObservableCounter, observable_counter_name); + + auto observable_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); + + auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description", + metrics_sdk::AggregationType::kSum); + p->AddView(std::move(observable_instrument_selector), std::move(observable_meter_selector), std::move(observable_sum_view)); // histogram view std::string histogram_name = name + "_histogram"; - std::unique_ptr histogram_instrument_selector{ - new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kHistogram, histogram_name)}; - std::unique_ptr histogram_meter_selector{ - new metric_sdk::MeterSelector(name, version, schema)}; - std::shared_ptr aggregation_config{ - new opentelemetry::sdk::metrics::HistogramAggregationConfig}; - static_cast(aggregation_config.get()) - ->boundaries_ = std::vector{0.0, 50.0, 100.0, 250.0, 500.0, 750.0, - 1000.0, 2500.0, 5000.0, 10000.0, 20000.0}; - std::unique_ptr histogram_view{new metric_sdk::View{ - name, "description", metric_sdk::AggregationType::kHistogram, aggregation_config}}; + + auto histogram_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( + metrics_sdk::InstrumentType::kHistogram, histogram_name); + + auto histogram_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); + + auto histogram_aggregation_config = std::unique_ptr( + new metrics_sdk::HistogramAggregationConfig); + + histogram_aggregation_config->boundaries_ = std::vector{ + 0.0, 50.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 10000.0, 20000.0}; + + std::shared_ptr aggregation_config( + std::move(histogram_aggregation_config)); + + auto histogram_view = metrics_sdk::ViewFactory::Create( + name, "description", metrics_sdk::AggregationType::kHistogram, aggregation_config); + p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); + + std::shared_ptr provider(std::move(u_provider)); metrics_api::Provider::SetMeterProvider(provider); } diff --git a/examples/otlp/BUILD b/examples/otlp/BUILD index 25c5e84fe7..fcaa535438 100644 --- a/examples/otlp/BUILD +++ b/examples/otlp/BUILD @@ -76,7 +76,7 @@ cc_binary( ) cc_binary( - name = "example_otlp_grpc_metrics", + name = "example_otlp_grpc_metric", srcs = [ "grpc_metric_main.cc", ], @@ -93,3 +93,22 @@ cc_binary( "//sdk/src/metrics", ], ) + +cc_binary( + name = "example_otlp_http_metric", + srcs = [ + "http_metric_main.cc", + ], + tags = [ + "examples", + "metrics", + "otlp", + ], + deps = [ + "//api", + "//examples/common/metrics_foo_library:common_metrics_foo_library", + "//exporters/otlp:otlp_http_exporter", + "//exporters/otlp:otlp_http_metric_exporter", + "//sdk/src/metrics", + ], +) diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index a9263a38b5..dd8cc054c2 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -10,6 +10,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/exporters/otlp/include) if(WITH_OTLP_GRPC) + # TRACE + add_executable(example_otlp_grpc grpc_main.cc) target_link_libraries(example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} @@ -21,6 +23,18 @@ if(WITH_OTLP_GRPC) target_link_libraries(example_otlp_grpc opentelemetry_trace opentelemetry_exporter_otlp_grpc) endif() + + # METRIC + + add_executable(example_otlp_grpc_metric grpc_metric_main.cc) + + target_link_libraries( + example_otlp_grpc_metric ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library opentelemetry_metrics + opentelemetry_exporter_otlp_grpc_metrics) + + # LOG + if(WITH_LOGS_PREVIEW) add_executable(example_otlp_grpc_log grpc_log_main.cc) @@ -37,6 +51,8 @@ if(WITH_OTLP_GRPC) endif() if(WITH_OTLP_HTTP) + # TRACE + add_executable(example_otlp_http http_main.cc) target_link_libraries(example_otlp_http ${CMAKE_THREAD_LIBS_INIT} @@ -49,6 +65,16 @@ if(WITH_OTLP_HTTP) opentelemetry_exporter_otlp_http) endif() + # METRIC + + add_executable(example_otlp_http_metric http_metric_main.cc) + target_link_libraries( + example_otlp_http_metric ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library opentelemetry_metrics + opentelemetry_exporter_otlp_http_metric) + + # LOG + if(WITH_LOGS_PREVIEW) add_executable(example_otlp_http_log http_log_main.cc) target_link_libraries(example_otlp_http_log ${CMAKE_THREAD_LIBS_INIT} @@ -66,11 +92,3 @@ if(WITH_OTLP_HTTP) endif() endif() - -if(WITH_OTLP_GRPC) - add_executable(example_otlp_metric_grpc grpc_metric_main.cc) - target_link_libraries( - example_otlp_metric_grpc ${CMAKE_THREAD_LIBS_INIT} - common_metrics_foo_library opentelemetry_metrics - opentelemetry_exporter_otlp_grpc_metrics) -endif() diff --git a/examples/otlp/grpc_metric_main.cc b/examples/otlp/grpc_metric_main.cc index 1c34ebed75..40d9777776 100644 --- a/examples/otlp/grpc_metric_main.cc +++ b/examples/otlp/grpc_metric_main.cc @@ -5,8 +5,11 @@ #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/meter_context_factory.h" #include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" #include #include @@ -25,24 +28,30 @@ namespace otlp_exporter = opentelemetry::exporter::otlp; namespace { -otlp_exporter::OtlpGrpcMetricExporterOptions options; +otlp_exporter::OtlpGrpcMetricExporterOptions exporter_options; void InitMetrics() { - auto exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(options); + auto exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(exporter_options); std::string version{"1.2.0"}; std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; // Initialize and set the global MeterProvider - metric_sdk::PeriodicExportingMetricReaderOptions options; - options.export_interval_millis = std::chrono::milliseconds(1000); - options.export_timeout_millis = std::chrono::milliseconds(500); - std::unique_ptr reader{ - new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)}; - auto provider = std::shared_ptr(new metric_sdk::MeterProvider()); - auto p = std::static_pointer_cast(provider); - p->AddMetricReader(std::move(reader)); + metric_sdk::PeriodicExportingMetricReaderOptions reader_options; + reader_options.export_interval_millis = std::chrono::milliseconds(1000); + reader_options.export_timeout_millis = std::chrono::milliseconds(500); + + auto reader = + metric_sdk::PeriodicExportingMetricReaderFactory::Create(std::move(exporter), reader_options); + + auto context = metric_sdk::MeterContextFactory::Create(); + context->AddMetricReader(std::move(reader)); + + std::shared_ptr s_context(std::move(context)); + + auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context); + std::shared_ptr provider(std::move(u_provider)); metrics_api::Provider::SetMeterProvider(provider); } @@ -59,14 +68,14 @@ int main(int argc, char *argv[]) std::string example_type; if (argc > 1) { - options.endpoint = argv[1]; + exporter_options.endpoint = argv[1]; if (argc > 2) { example_type = argv[2]; if (argc > 3) { - options.use_ssl_credentials = true; - options.ssl_credentials_cacert_path = argv[3]; + exporter_options.use_ssl_credentials = true; + exporter_options.ssl_credentials_cacert_path = argv[3]; } } } diff --git a/examples/otlp/http_metric_main.cc b/examples/otlp/http_metric_main.cc new file mode 100644 index 0000000000..a361285fed --- /dev/null +++ b/examples/otlp/http_metric_main.cc @@ -0,0 +1,142 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.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/meter_context_factory.h" +#include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" + +#include +#include + +#ifdef BAZEL_BUILD +# include "examples/common/metrics_foo_library/foo_library.h" +#else +# include "metrics_foo_library/foo_library.h" +#endif + +namespace metric_sdk = opentelemetry::sdk::metrics; +namespace common = opentelemetry::common; +namespace metrics_api = opentelemetry::metrics; +namespace otlp_exporter = opentelemetry::exporter::otlp; + +namespace internal_log = opentelemetry::sdk::common::internal_log; + +namespace +{ + +otlp_exporter::OtlpHttpMetricExporterOptions exporter_options; + +void InitMetrics() +{ + auto exporter = otlp_exporter::OtlpHttpMetricExporterFactory::Create(exporter_options); + + std::string version{"1.2.0"}; + std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; + + // Initialize and set the global MeterProvider + metric_sdk::PeriodicExportingMetricReaderOptions reader_options; + reader_options.export_interval_millis = std::chrono::milliseconds(1000); + reader_options.export_timeout_millis = std::chrono::milliseconds(500); + + auto reader = + metric_sdk::PeriodicExportingMetricReaderFactory::Create(std::move(exporter), reader_options); + + auto context = metric_sdk::MeterContextFactory::Create(); + context->AddMetricReader(std::move(reader)); + + std::shared_ptr s_context(std::move(context)); + + auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context); + std::shared_ptr provider(std::move(u_provider)); + + metrics_api::Provider::SetMeterProvider(provider); +} + +void CleanupMetrics() +{ + std::shared_ptr none; + metrics_api::Provider::SetMeterProvider(none); +} +} // namespace + +/* + Usage: + - example_otlp_http_metric + - example_otlp_http_metric + - example_otlp_http_metric + - example_otlp_http_metric + - example_otlp_http_metric + = counter|observable_counter|histogram|all + = yes|no, to turn console debug on or off + = bin, to export in binary format +*/ +int main(int argc, char *argv[]) +{ + std::string example_type; + if (argc > 1) + { + exporter_options.url = argv[1]; + } + + if (argc > 2) + { + example_type = argv[2]; + } + + if (argc > 3) + { + std::string debug = argv[3]; + exporter_options.console_debug = debug != "" && debug != "0" && debug != "no"; + } + + if (argc > 4) + { + std::string binary_mode = argv[4]; + if (binary_mode.size() >= 3 && binary_mode.substr(0, 3) == "bin") + { + exporter_options.content_type = otlp_exporter::HttpRequestContentType::kBinary; + } + } + + if (exporter_options.console_debug) + { + internal_log::GlobalLogHandler::SetLogLevel(internal_log::LogLevel::Debug); + } + + // Removing this line will leave the default noop MetricProvider in place. + InitMetrics(); + std::string name{"otlp_http_metric_example"}; + + if (example_type == "counter") + { + foo_library::counter_example(name); + } + else if (example_type == "observable_counter") + { + foo_library::observable_counter_example(name); + } + else if (example_type == "histogram") + { + foo_library::histogram_example(name); + } + else + { + std::thread counter_example{&foo_library::counter_example, name}; + std::thread observable_counter_example{&foo_library::observable_counter_example, name}; + std::thread histogram_example{&foo_library::histogram_example, name}; + + counter_example.join(); + observable_counter_example.join(); + histogram_example.join(); + } + + CleanupMetrics(); +} diff --git a/examples/prometheus/main.cc b/examples/prometheus/main.cc index d620c761dd..6902a6b3e0 100644 --- a/examples/prometheus/main.cc +++ b/examples/prometheus/main.cc @@ -3,13 +3,18 @@ #include #include -#include "opentelemetry/exporters/prometheus/exporter.h" + +#include "opentelemetry/exporters/prometheus/exporter_factory.h" +#include "opentelemetry/exporters/prometheus/exporter_options.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/export/periodic_exporting_metric_reader.h" #include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/view_factory.h" #ifdef BAZEL_BUILD # include "examples/common/metrics_foo_library/foo_library.h" @@ -37,34 +42,42 @@ void InitMetrics(const std::string &name, const std::string &addr) std::string version{"1.2.0"}; std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; - std::shared_ptr prometheus_exporter( - new metrics_exporter::PrometheusExporter(opts)); + auto prometheus_exporter = metrics_exporter::PrometheusExporterFactory::Create(opts); // Initialize and set the global MeterProvider - auto provider = std::shared_ptr(new metrics_sdk::MeterProvider()); - auto p = std::static_pointer_cast(provider); - p->AddMetricReader(prometheus_exporter); + auto u_provider = metrics_sdk::MeterProviderFactory::Create(); + auto *p = static_cast(u_provider.get()); + + p->AddMetricReader(std::move(prometheus_exporter)); // counter view std::string counter_name = name + "_counter"; - std::unique_ptr instrument_selector{ - new metrics_sdk::InstrumentSelector(metrics_sdk::InstrumentType::kCounter, counter_name)}; - std::unique_ptr meter_selector{ - new metrics_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr sum_view{ - new metrics_sdk::View{counter_name, "description", metrics_sdk::AggregationType::kSum}}; + + auto instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( + metrics_sdk::InstrumentType::kCounter, counter_name); + + auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); + + auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description", + metrics_sdk::AggregationType::kSum); + p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); // histogram view std::string histogram_name = name + "_histogram"; - std::unique_ptr histogram_instrument_selector{ - new metrics_sdk::InstrumentSelector(metrics_sdk::InstrumentType::kHistogram, histogram_name)}; - std::unique_ptr histogram_meter_selector{ - new metrics_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr histogram_view{new metrics_sdk::View{ - histogram_name, "description", metrics_sdk::AggregationType::kHistogram}}; + + auto histogram_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( + metrics_sdk::InstrumentType::kHistogram, histogram_name); + + auto histogram_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); + + auto histogram_view = metrics_sdk::ViewFactory::Create(histogram_name, "description", + metrics_sdk::AggregationType::kHistogram); + p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); + + std::shared_ptr provider(std::move(u_provider)); metrics_api::Provider::SetMeterProvider(provider); } diff --git a/exporters/ostream/BUILD b/exporters/ostream/BUILD index a80e84a024..a8af2e6c28 100644 --- a/exporters/ostream/BUILD +++ b/exporters/ostream/BUILD @@ -36,10 +36,12 @@ cc_library( name = "ostream_metric_exporter", srcs = [ "src/metric_exporter.cc", + "src/metric_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/ostream/common_utils.h", "include/opentelemetry/exporters/ostream/metric_exporter.h", + "include/opentelemetry/exporters/ostream/metric_exporter_factory.h", ], strip_include_prefix = "include", tags = [ diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index af24e9f1ad..10e0792de8 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -40,7 +40,8 @@ if(BUILD_TESTING) TEST_LIST ostream_span_test) endif() # BUILD_TESTING -add_library(opentelemetry_exporter_ostream_metrics src/metric_exporter.cc) +add_library(opentelemetry_exporter_ostream_metrics + src/metric_exporter.cc src/metric_exporter_factory.cc) set_target_properties(opentelemetry_exporter_ostream_metrics PROPERTIES EXPORT_NAME ostream_metrics_exporter) set_target_version(opentelemetry_exporter_ostream_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 new file mode 100644 index 0000000000..0526165026 --- /dev/null +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter_factory.h @@ -0,0 +1,50 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#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 metrics +{ + +/** + * Factory class for OStreamMetricExporter. + */ +class OPENTELEMETRY_EXPORT OStreamMetricExporterFactory +{ +public: + /** + * Creates an OStreamMetricExporter writing to the default location. + */ + static std::unique_ptr Create(); + + /** + * Creates an OStreamMetricExporter writing to the given location. + */ + static std::unique_ptr Create( + std::ostream &sout); + + static std::unique_ptr Create( + std::ostream &sout, + sdk::metrics::AggregationTemporality aggregation_temporality); +}; + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/metric_exporter_factory.cc b/exporters/ostream/src/metric_exporter_factory.cc new file mode 100644 index 0000000000..c5750b6f29 --- /dev/null +++ b/exporters/ostream/src/metric_exporter_factory.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/ostream/metric_exporter_factory.h" +#include "opentelemetry/exporters/ostream/metric_exporter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +std::unique_ptr +OStreamMetricExporterFactory::Create() +{ + return Create(std::cout); +} + +std::unique_ptr +OStreamMetricExporterFactory::Create(std::ostream &sout) +{ + return Create(sout, sdk::metrics::AggregationTemporality::kCumulative); +} + +std::unique_ptr +OStreamMetricExporterFactory::Create(std::ostream &sout, + sdk::metrics::AggregationTemporality aggregation_temporality) +{ + std::unique_ptr exporter( + new OStreamMetricExporter(sout, aggregation_temporality)); + return exporter; +} + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/BUILD b/exporters/prometheus/BUILD index a7fb7e5e8c..fc981921d9 100644 --- a/exporters/prometheus/BUILD +++ b/exporters/prometheus/BUILD @@ -7,9 +7,13 @@ cc_library( name = "prometheus_exporter", srcs = [ "src/exporter.cc", + "src/exporter_factory.cc", + "src/exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/prometheus/exporter.h", + "include/opentelemetry/exporters/prometheus/exporter_factory.h", + "include/opentelemetry/exporters/prometheus/exporter_options.h", ], strip_include_prefix = "include", tags = ["prometheus"], diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 806ca01f70..c6387a66c8 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -6,8 +6,10 @@ if(NOT TARGET prometheus-cpp::core) find_package(prometheus-cpp CONFIG REQUIRED) endif() -add_library(opentelemetry_exporter_prometheus src/exporter.cc src/collector.cc - src/exporter_utils.cc) +add_library( + opentelemetry_exporter_prometheus + src/exporter.cc src/exporter_options.cc src/exporter_factory.cc + src/collector.cc src/exporter_utils.cc) set_target_properties(opentelemetry_exporter_prometheus PROPERTIES EXPORT_NAME prometheus_exporter) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h index fe3c603e8a..4bd624d1e2 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h @@ -10,6 +10,7 @@ #include #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/exporters/prometheus/collector.h" +#include "opentelemetry/exporters/prometheus/exporter_options.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/env_variables.h" #include "opentelemetry/sdk/metrics/metric_reader.h" @@ -28,27 +29,6 @@ namespace exporter namespace metrics { -inline const std::string GetPrometheusDefaultHttpEndpoint() -{ - constexpr char kPrometheusEndpointEnv[] = "PROMETHEUS_EXPORTER_ENDPOINT"; - constexpr char kPrometheusEndpointDefault[] = "localhost:9464"; - - std::string endpoint; - - auto exists = - opentelemetry::sdk::common::GetStringEnvironmentVariable(kPrometheusEndpointEnv, endpoint); - return exists ? endpoint : kPrometheusEndpointDefault; -} - -/** - * Struct to hold Prometheus exporter options. - */ -struct PrometheusExporterOptions -{ - // The endpoint the Prometheus backend can collect metrics from - std::string url = GetPrometheusDefaultHttpEndpoint(); -}; - class PrometheusExporter : public sdk::metrics::MetricReader { public: diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_factory.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_factory.h new file mode 100644 index 0000000000..67a30a5fef --- /dev/null +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_factory.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +struct PrometheusExporterOptions; + +/** + * Factory class for PrometheusExporter. + */ +class PrometheusExporterFactory +{ +public: + /** + * Create a PrometheusExporter using the given options. + */ + static std::unique_ptr Create( + const PrometheusExporterOptions &options); +}; + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h new file mode 100644 index 0000000000..76a08d2a4a --- /dev/null +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +/** + * Struct to hold Prometheus exporter options. + */ +struct PrometheusExporterOptions +{ + PrometheusExporterOptions(); + + // The endpoint the Prometheus backend can collect metrics from + std::string url; +}; + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/src/exporter_factory.cc b/exporters/prometheus/src/exporter_factory.cc new file mode 100644 index 0000000000..93fca80977 --- /dev/null +++ b/exporters/prometheus/src/exporter_factory.cc @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/exporters/prometheus/exporter.h" +#include "opentelemetry/exporters/prometheus/exporter_factory.h" +#include "opentelemetry/exporters/prometheus/exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +std::unique_ptr PrometheusExporterFactory::Create( + const PrometheusExporterOptions &options) +{ + std::unique_ptr exporter( + new PrometheusExporter(options)); + return exporter; +} + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/src/exporter_options.cc b/exporters/prometheus/src/exporter_options.cc new file mode 100644 index 0000000000..507f119eb7 --- /dev/null +++ b/exporters/prometheus/src/exporter_options.cc @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/exporters/prometheus/exporter_options.h" +#include "opentelemetry/sdk/common/env_variables.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +inline const std::string GetPrometheusDefaultHttpEndpoint() +{ + constexpr char kPrometheusEndpointEnv[] = "PROMETHEUS_EXPORTER_ENDPOINT"; + constexpr char kPrometheusEndpointDefault[] = "localhost:9464"; + + std::string endpoint; + + auto exists = + opentelemetry::sdk::common::GetStringEnvironmentVariable(kPrometheusEndpointEnv, endpoint); + return exists ? endpoint : kPrometheusEndpointDefault; +} + +PrometheusExporterOptions::PrometheusExporterOptions() : url(GetPrometheusDefaultHttpEndpoint()) {} + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE 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 29c2e351e5..323727c873 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 @@ -10,6 +10,7 @@ #include #include +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/version.h" @@ -20,22 +21,6 @@ namespace metrics { class PushMetricExporter; -/** - * Struct to hold PeriodicExortingMetricReader options. - */ - -constexpr std::chrono::milliseconds kExportIntervalMillis = std::chrono::milliseconds(60000); -constexpr std::chrono::milliseconds kExportTimeOutMillis = std::chrono::milliseconds(30000); -struct PeriodicExportingMetricReaderOptions -{ - - /* The time interval between two consecutive exports. */ - std::chrono::milliseconds export_interval_millis = - std::chrono::milliseconds(kExportIntervalMillis); - - /* how long the export can run before it is cancelled. */ - std::chrono::milliseconds export_timeout_millis = std::chrono::milliseconds(kExportTimeOutMillis); -}; 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 new file mode 100644 index 0000000000..c4254793f3 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class MetricReader; +class PushMetricExporter; + +class PeriodicExportingMetricReaderFactory +{ +public: + static std::unique_ptr Create(std::unique_ptr exporter, + const PeriodicExportingMetricReaderOptions &option); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h new file mode 100644 index 0000000000..80514f96d8 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +constexpr std::chrono::milliseconds kExportIntervalMillis = std::chrono::milliseconds(60000); +constexpr std::chrono::milliseconds kExportTimeOutMillis = std::chrono::milliseconds(30000); + +/** + * Struct to hold PeriodicExortingMetricReader options. + */ + +struct PeriodicExportingMetricReaderOptions +{ + /* The time interval between two consecutive exports. */ + std::chrono::milliseconds export_interval_millis = + std::chrono::milliseconds(kExportIntervalMillis); + + /* how long the export can run before it is cancelled. */ + std::chrono::milliseconds export_timeout_millis = std::chrono::milliseconds(kExportTimeOutMillis); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h new file mode 100644 index 0000000000..d5ca16cc27 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +// forward declaration +class MeterContext; +class ViewRegistry; + +/** + * Factory class for MeterContext. + */ +class MeterContextFactory +{ +public: + /** + * Create a MeterContext. + */ + static std::unique_ptr Create(); + + static std::unique_ptr Create(std::unique_ptr views); + + static std::unique_ptr Create( + std::unique_ptr views, + const opentelemetry::sdk::resource::Resource &resource); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h new file mode 100644 index 0000000000..7a1343980c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h @@ -0,0 +1,77 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics/meter_provider.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +/* + MAINTAINER: + + The best design is to return an API object: + std::unique_ptr + to shield the calling application from SDK implementation details. + + This however assumes that the SDK object can be created in one call, + instead of making multiple calls to the SDK to setup a meter provider. + + Because existing code, already advertised in examples: + - creates an instance of sdk::MeterProvider + - calls SDK methods on it to continue the setup, such as + MeterProvider::AddMetricReader() + MeterProvider::AddView() + existing applications will need to access the underlying + class sdk::MeterProvider. + + We need to decide whether to return: + - (1) std::unique_ptr + - (2) std::unique_ptr + from a Create() method. + + In the long term, (1) is better, but forces users to use a down cast, + to make additional calls to the SDK class, until such a time when + the builders can take all the necessary input at once, + for example using a std::vector to add all readers. + + Implementing (2) is forcing technical debt, and prevents the + calling application configuring the SDK to be decoupled from it, + making deployment of shared libraries much more difficult. + + The design choice here is to return (1) an API MeterProvider, + even if this forces, temporarily, existing applications to use a downcast. +*/ + +class MeterProviderFactory +{ +public: + static std::unique_ptr Create(); + + static std::unique_ptr Create( + std::unique_ptr views); + + static std::unique_ptr Create( + std::unique_ptr views, + const opentelemetry::sdk::resource::Resource &resource); + + static std::unique_ptr Create( + std::shared_ptr context); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h new file mode 100644 index 0000000000..e5b8b83704 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/metrics/instruments.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class InstrumentSelector; + +class InstrumentSelectorFactory +{ +public: + static std::unique_ptr Create( + opentelemetry::sdk::metrics::InstrumentType instrument_type, + opentelemetry::nostd::string_view name); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h new file mode 100644 index 0000000000..f335f725f7 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class MeterSelector; + +class MeterSelectorFactory +{ +public: + static std::unique_ptr Create(opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view version, + opentelemetry::nostd::string_view schema); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h new file mode 100644 index 0000000000..5e7da2ea62 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h @@ -0,0 +1,49 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#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" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class View; + +/** + * Factory class for View. + */ +class OPENTELEMETRY_EXPORT ViewFactory +{ +public: + static std::unique_ptr Create(const std::string &name); + + static std::unique_ptr Create(const std::string &name, const std::string &description); + + static std::unique_ptr Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type); + + static std::unique_ptr Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type, + std::shared_ptr aggregation_config); + + static std::unique_ptr Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type, + std::shared_ptr aggregation_config, + std::unique_ptr attributes_processor); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index 9f12259665..d017bd7107 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -78,6 +78,7 @@ class ViewRegistry return true; } + ViewRegistry() = default; ~ViewRegistry() = default; private: diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h new file mode 100644 index 0000000000..f8f83c21ad --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry_factory.h @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class ViewRegistry; + +class ViewRegistryFactory +{ +public: + static std::unique_ptr Create(); +}; +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index cd831eaac8..f79d17dda2 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -5,11 +5,14 @@ add_library( opentelemetry_metrics async_instruments.cc meter_provider.cc + meter_provider_factory.cc meter.cc meter_context.cc + meter_context_factory.cc metric_reader.cc instrument_metadata_validator.cc export/periodic_exporting_metric_reader.cc + export/periodic_exporting_metric_reader_factory.cc state/metric_collector.cc state/observable_registry.cc state/sync_metric_storage.cc @@ -21,6 +24,10 @@ add_library( data/circular_buffer.cc exemplar/filter.cc exemplar/reservoir.cc + view/instrument_selector_factory.cc + view/meter_selector_factory.cc + view/view_factory.cc + view/view_registry_factory.cc sync_instruments.cc) set_target_properties(opentelemetry_metrics PROPERTIES EXPORT_NAME metrics) diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc new file mode 100644 index 0000000000..c4f0b8348a --- /dev/null +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader_factory.cc @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr PeriodicExportingMetricReaderFactory::Create( + std::unique_ptr exporter, + const PeriodicExportingMetricReaderOptions &option) +{ + std::unique_ptr reader( + new PeriodicExportingMetricReader(std::move(exporter), option)); + return reader; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/meter_context_factory.cc b/sdk/src/metrics/meter_context_factory.cc new file mode 100644 index 0000000000..d41bb6a193 --- /dev/null +++ b/sdk/src/metrics/meter_context_factory.cc @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/meter_context_factory.h" +#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/view/view_registry_factory.h" + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr MeterContextFactory::Create() +{ + auto views = ViewRegistryFactory::Create(); + return Create(std::move(views)); +} + +std::unique_ptr MeterContextFactory::Create(std::unique_ptr views) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(views), resource); +} + +std::unique_ptr MeterContextFactory::Create( + std::unique_ptr views, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr context(new MeterContext(std::move(views), resource)); + return context; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/meter_provider_factory.cc b/sdk/src/metrics/meter_provider_factory.cc new file mode 100644 index 0000000000..38527c90d8 --- /dev/null +++ b/sdk/src/metrics/meter_provider_factory.cc @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/view/view_registry_factory.h" + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk_config.h" +#include "opentelemetry/version.h" + +#include + +namespace resource = opentelemetry::sdk::resource; +namespace metrics_api = opentelemetry::metrics; +namespace metrics_sdk = opentelemetry::sdk::metrics; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +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 metrics_sdk::MeterProvider(std::move(views), resource)); + return provider; +} + +std::unique_ptr MeterProviderFactory::Create( + std::shared_ptr context) +{ + std::unique_ptr provider( + new metrics_sdk::MeterProvider(std::move(context))); + return provider; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/view/instrument_selector_factory.cc b/sdk/src/metrics/view/instrument_selector_factory.cc new file mode 100644 index 0000000000..24542a57cd --- /dev/null +++ b/sdk/src/metrics/view/instrument_selector_factory.cc @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr InstrumentSelectorFactory::Create( + opentelemetry::sdk::metrics::InstrumentType instrument_type, + opentelemetry::nostd::string_view name) +{ + std::unique_ptr instrument_selector( + new InstrumentSelector(instrument_type, name)); + return instrument_selector; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/view/meter_selector_factory.cc b/sdk/src/metrics/view/meter_selector_factory.cc new file mode 100644 index 0000000000..f8f906d9ad --- /dev/null +++ b/sdk/src/metrics/view/meter_selector_factory.cc @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr MeterSelectorFactory::Create( + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view version, + opentelemetry::nostd::string_view schema) +{ + std::unique_ptr meter_selector(new MeterSelector(name, version, schema)); + return meter_selector; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/view/view_factory.cc b/sdk/src/metrics/view/view_factory.cc new file mode 100644 index 0000000000..2e410accc6 --- /dev/null +++ b/sdk/src/metrics/view/view_factory.cc @@ -0,0 +1,57 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/view/view_factory.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr ViewFactory::Create(const std::string &name) +{ + return Create(name, ""); +} + +std::unique_ptr ViewFactory::Create(const std::string &name, const std::string &description) +{ + return Create(name, description, AggregationType::kDefault); +} + +std::unique_ptr ViewFactory::Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type) +{ + std::shared_ptr aggregation_config(nullptr); + return Create(name, description, aggregation_type, aggregation_config); +} + +std::unique_ptr ViewFactory::Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type, + std::shared_ptr aggregation_config) +{ + auto attributes_processor = + std::unique_ptr(new DefaultAttributesProcessor()); + + return Create(name, description, aggregation_type, aggregation_config, + std::move(attributes_processor)); +} + +std::unique_ptr ViewFactory::Create(const std::string &name, + const std::string &description, + AggregationType aggregation_type, + std::shared_ptr aggregation_config, + std::unique_ptr attributes_processor) +{ + std::unique_ptr view(new View(name, description, aggregation_type, aggregation_config, + std::move(attributes_processor))); + return view; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/metrics/view/view_registry_factory.cc b/sdk/src/metrics/view/view_registry_factory.cc new file mode 100644 index 0000000000..ba8a4c5e21 --- /dev/null +++ b/sdk/src/metrics/view/view_registry_factory.cc @@ -0,0 +1,22 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/view/view_registry_factory.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::unique_ptr ViewRegistryFactory::Create() +{ + std::unique_ptr view_registry(new ViewRegistry()); + return view_registry; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From efde01033b2181c10f2d1b236170c9ab1320b7ec Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Jun 2023 12:03:34 -0700 Subject: [PATCH 025/119] [BUILD] Enable building otel-cpp extensions from main repo (#1937) --- CMakeLists.txt | 2 ++ ...entelemetry-build-external-component.cmake | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 cmake/opentelemetry-build-external-component.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e0be94a6..27930fe793 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -628,6 +628,8 @@ if(NOT WITH_API_ONLY) endif() endif() +include(cmake/opentelemetry-build-external-component.cmake) + if(OPENTELEMETRY_INSTALL) # Export cmake config and support find_packages(opentelemetry-cpp CONFIG) # Write config file for find_packages(opentelemetry-cpp CONFIG) diff --git a/cmake/opentelemetry-build-external-component.cmake b/cmake/opentelemetry-build-external-component.cmake new file mode 100644 index 0000000000..cd30eb082f --- /dev/null +++ b/cmake/opentelemetry-build-external-component.cmake @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable building external components through otel-cpp build +# The config options are +# - OPENTELEMETRY_EXTERNAL_COMPONENT_PATH - Setting local path of the external +# component as env variable +# - OPENTELEMETRY_EXTERNAL_COMPONENT_URL Setting github-repo of external component +# as env variable + + +# Add custom vendor component from local path, or GitHub repo +if(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH}) + # Add custom component path to build tree and consolidate binary artifacts in + # current project binary output directory. + add_subdirectory($ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH} + ${PROJECT_BINARY_DIR}/external) +elseif(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_URL}) + # This option requires CMake 3.11+: add standard remote repo to build tree. + include(FetchContent) + FetchContent_Declare( + external + GIT_REPOSITORY $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_URL} + GIT_TAG "main") + FetchContent_GetProperties(external) + if(NOT external_POPULATED) + FetchContent_Populate(external) + add_subdirectory(${external_SOURCE_DIR}) + endif() +endif() From 313b04d85924d7edb396fca207270ac23bad76ed Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 28 Jun 2023 23:44:54 -0700 Subject: [PATCH 026/119] [BUILD] Fix if check on environment variable and add CMake variable (#2207) --- cmake/opentelemetry-build-external-component.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/opentelemetry-build-external-component.cmake b/cmake/opentelemetry-build-external-component.cmake index cd30eb082f..2d8d78afbf 100644 --- a/cmake/opentelemetry-build-external-component.cmake +++ b/cmake/opentelemetry-build-external-component.cmake @@ -8,9 +8,14 @@ # - OPENTELEMETRY_EXTERNAL_COMPONENT_URL Setting github-repo of external component # as env variable - # Add custom vendor component from local path, or GitHub repo -if(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH}) +# Prefer CMake option, then env variable, then URL. +if(OPENTELEMETRY_EXTERNAL_COMPONENT_PATH) + # Add custom component path to build tree and consolidate binary artifacts in + # current project binary output directory. + add_subdirectory(${OPENTELEMETRY_EXTERNAL_COMPONENT_PATH} + ${PROJECT_BINARY_DIR}/external) +elseif(DEFINED ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH}) # Add custom component path to build tree and consolidate binary artifacts in # current project binary output directory. add_subdirectory($ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH} From 049ab63103b2ede02c6f58c85927e7d4e1834807 Mon Sep 17 00:00:00 2001 From: Kyle L Date: Thu, 29 Jun 2023 04:50:12 -0400 Subject: [PATCH 027/119] [EXPORTER] OTLP GRPC mTLS support (#2120) --- api/CMakeLists.txt | 5 ++++ ci/do_ci.sh | 1 + .../otlp/otlp_grpc_exporter_options.h | 13 +++++++++ exporters/otlp/src/otlp_grpc_client.cc | 28 +++++++++++++------ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 31863b25e3..91d129e179 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -113,6 +113,11 @@ if(WITH_OTLP_HTTP_SSL_PREVIEW) endif() endif() +if(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW) +endif() + if(WITH_METRICS_EXEMPLAR_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index d504b33ae8..6020d22a04 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -258,6 +258,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \ "${SRC_DIR}" grpc_cpp_plugin=`which grpc_cpp_plugin` proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make" diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h index f5a2b9d295..01ac5b43f2 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h @@ -28,6 +28,19 @@ struct OtlpGrpcExporterOptions // ssl_credentials_cacert_as_string in-memory string representation of .pem file to be used for // SSL encryption. std::string ssl_credentials_cacert_as_string = GetOtlpDefaultSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + // At most one of ssl_client_key_* should be non-empty. If use_ssl_credentials, they will + // be read to allow for mTLS. + std::string ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); + std::string ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + + // At most one of ssl_client_cert_* should be non-empty. If use_ssl_credentials, they will + // be read to allow for mTLS. + std::string ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); + std::string ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); +#endif + // Timeout for grpc deadline std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout(); // Additional HTTP headers diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 9250f87cc4..5a94c66b59 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -34,6 +34,18 @@ static std::string GetFileContents(const char *fpath) finstream.close(); return contents; } + +// If the file path is non-empty, returns the contents of the file. Otherwise returns contents. +static std::string GetFileContentsOrInMemoryContents(const std::string &file_path, + const std::string &contents) +{ + if (!file_path.empty()) + { + return GetFileContents(file_path.c_str()); + } + return contents; +} + } // namespace std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporterOptions &options) @@ -61,14 +73,14 @@ std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporte if (options.use_ssl_credentials) { grpc::SslCredentialsOptions ssl_opts; - if (options.ssl_credentials_cacert_path.empty()) - { - ssl_opts.pem_root_certs = options.ssl_credentials_cacert_as_string; - } - else - { - ssl_opts.pem_root_certs = GetFileContents((options.ssl_credentials_cacert_path).c_str()); - } + ssl_opts.pem_root_certs = GetFileContentsOrInMemoryContents( + options.ssl_credentials_cacert_path, options.ssl_credentials_cacert_as_string); +#if ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_opts.pem_private_key = GetFileContentsOrInMemoryContents(options.ssl_client_key_path, + options.ssl_client_key_string); + ssl_opts.pem_cert_chain = GetFileContentsOrInMemoryContents(options.ssl_client_cert_path, + options.ssl_client_cert_string); +#endif channel = grpc::CreateCustomChannel(grpc_target, grpc::SslCredentials(ssl_opts), grpc_arguments); } From 42709f4575180e76463b3e61c5b2cefe797b421c Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sun, 2 Jul 2023 20:16:10 +0200 Subject: [PATCH 028/119] [REMOVAL] Remove the jaeger exporter (#2031) --- .github/workflows/ci.yml | 15 - CHANGELOG.md | 10 + CMakeLists.txt | 22 - DEPRECATED.md | 60 +- bazel/repository.bzl | 34 - ci/do_ci.ps1 | 1 - ci/do_ci.sh | 24 +- ci/setup_thrift.ps1 | 16 - ci/setup_thrift.sh | 68 - cmake/modules/FindThrift.cmake | 34 - cmake/opentelemetry-cpp-config.cmake.in | 2 - docker/Dockerfile | 4 - docker/Dockerfile.alpine.base | 2 +- docker/Dockerfile.centos | 36 - docker/Dockerfile.debian.deps | 9 - docker/README.md | 4 - docker/build.sh | 14 +- docker/thrift/CMakeLists.txt | 90 -- docker/thrift/Dockerfile | 24 - docker/ubuntuLatest/Dockerfile | 26 - docs/dependencies.md | 11 - docs/public/sdk/GettingStarted.rst | 18 - examples/CMakeLists.txt | 3 - examples/jaeger/BUILD | 16 - examples/jaeger/CMakeLists.txt | 9 - examples/jaeger/README.md | 18 - examples/jaeger/main.cc | 54 - exporters/CMakeLists.txt | 4 - exporters/jaeger/BUILD | 226 --- exporters/jaeger/CMakeLists.txt | 111 -- exporters/jaeger/README.md | 67 - .../exporters/jaeger/jaeger_exporter.h | 87 -- .../jaeger/jaeger_exporter_factory.h | 39 - .../jaeger/jaeger_exporter_options.h | 41 - .../exporters/jaeger/recordable.h | 123 -- .../exporters/jaeger/thrift_include_prefix.h | 11 - .../exporters/jaeger/thrift_include_suffix.h | 10 - exporters/jaeger/src/THttpTransport.cc | 61 - exporters/jaeger/src/THttpTransport.h | 40 - exporters/jaeger/src/TUDPTransport.cc | 113 -- exporters/jaeger/src/TUDPTransport.h | 53 - exporters/jaeger/src/http_transport.cc | 37 - exporters/jaeger/src/http_transport.h | 42 - exporters/jaeger/src/jaeger_exporter.cc | 121 -- .../jaeger/src/jaeger_exporter_factory.cc | 29 - exporters/jaeger/src/recordable.cc | 366 ----- exporters/jaeger/src/sender.h | 32 - exporters/jaeger/src/thrift_sender.cc | 99 -- exporters/jaeger/src/thrift_sender.h | 83 - exporters/jaeger/src/transport.h | 34 - exporters/jaeger/src/udp_transport.cc | 86 -- exporters/jaeger/src/udp_transport.h | 62 - exporters/jaeger/test/jaeger_exporter_test.cc | 179 --- .../jaeger/test/jaeger_recordable_test.cc | 334 ---- exporters/jaeger/thrift-gen/Agent.cpp | 380 ----- exporters/jaeger/thrift-gen/Agent.h | 309 ---- .../thrift-gen/Agent_server.skeleton.cpp | 47 - exporters/jaeger/thrift-gen/Collector.cpp | 481 ------ exporters/jaeger/thrift-gen/Collector.h | 299 ---- .../thrift-gen/Collector_server.skeleton.cpp | 42 - .../jaeger/thrift-gen/ZipkinCollector.cpp | 481 ------ exporters/jaeger/thrift-gen/ZipkinCollector.h | 299 ---- .../ZipkinCollector_server.skeleton.cpp | 42 - exporters/jaeger/thrift-gen/agent_types.h | 28 - exporters/jaeger/thrift-gen/jaeger_types.cpp | 1354 ----------------- exporters/jaeger/thrift-gen/jaeger_types.h | 481 ------ .../thrift-gen/zipkincore_constants.cpp | 49 - .../jaeger/thrift-gen/zipkincore_constants.h | 40 - .../jaeger/thrift-gen/zipkincore_types.cpp | 913 ----------- .../jaeger/thrift-gen/zipkincore_types.h | 493 ------ .../exporters/zipkin/zipkin_exporter.h | 2 +- third_party/boost/LICENSE.md | 23 - third_party_release | 1 - tools/format.sh | 2 +- 74 files changed, 45 insertions(+), 8835 deletions(-) delete mode 100644 ci/setup_thrift.ps1 delete mode 100755 ci/setup_thrift.sh delete mode 100644 cmake/modules/FindThrift.cmake delete mode 100644 docker/thrift/CMakeLists.txt delete mode 100644 docker/thrift/Dockerfile delete mode 100644 examples/jaeger/BUILD delete mode 100644 examples/jaeger/CMakeLists.txt delete mode 100644 examples/jaeger/README.md delete mode 100644 examples/jaeger/main.cc delete mode 100644 exporters/jaeger/BUILD delete mode 100644 exporters/jaeger/CMakeLists.txt delete mode 100644 exporters/jaeger/README.md delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_factory.h delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_options.h delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_prefix.h delete mode 100644 exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_suffix.h delete mode 100644 exporters/jaeger/src/THttpTransport.cc delete mode 100644 exporters/jaeger/src/THttpTransport.h delete mode 100644 exporters/jaeger/src/TUDPTransport.cc delete mode 100644 exporters/jaeger/src/TUDPTransport.h delete mode 100644 exporters/jaeger/src/http_transport.cc delete mode 100644 exporters/jaeger/src/http_transport.h delete mode 100644 exporters/jaeger/src/jaeger_exporter.cc delete mode 100644 exporters/jaeger/src/jaeger_exporter_factory.cc delete mode 100644 exporters/jaeger/src/recordable.cc delete mode 100644 exporters/jaeger/src/sender.h delete mode 100644 exporters/jaeger/src/thrift_sender.cc delete mode 100644 exporters/jaeger/src/thrift_sender.h delete mode 100644 exporters/jaeger/src/transport.h delete mode 100644 exporters/jaeger/src/udp_transport.cc delete mode 100644 exporters/jaeger/src/udp_transport.h delete mode 100644 exporters/jaeger/test/jaeger_exporter_test.cc delete mode 100644 exporters/jaeger/test/jaeger_recordable_test.cc delete mode 100644 exporters/jaeger/thrift-gen/Agent.cpp delete mode 100644 exporters/jaeger/thrift-gen/Agent.h delete mode 100644 exporters/jaeger/thrift-gen/Agent_server.skeleton.cpp delete mode 100644 exporters/jaeger/thrift-gen/Collector.cpp delete mode 100644 exporters/jaeger/thrift-gen/Collector.h delete mode 100644 exporters/jaeger/thrift-gen/Collector_server.skeleton.cpp delete mode 100644 exporters/jaeger/thrift-gen/ZipkinCollector.cpp delete mode 100644 exporters/jaeger/thrift-gen/ZipkinCollector.h delete mode 100644 exporters/jaeger/thrift-gen/ZipkinCollector_server.skeleton.cpp delete mode 100644 exporters/jaeger/thrift-gen/agent_types.h delete mode 100644 exporters/jaeger/thrift-gen/jaeger_types.cpp delete mode 100644 exporters/jaeger/thrift-gen/jaeger_types.h delete mode 100644 exporters/jaeger/thrift-gen/zipkincore_constants.cpp delete mode 100644 exporters/jaeger/thrift-gen/zipkincore_constants.h delete mode 100644 exporters/jaeger/thrift-gen/zipkincore_types.cpp delete mode 100644 exporters/jaeger/thrift-gen/zipkincore_types.h delete mode 100644 third_party/boost/LICENSE.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ac8999459..e1666dabbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,6 @@ jobs: CC: /usr/bin/gcc-10 CXX: /usr/bin/g++-10 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.test # @@ -88,7 +87,6 @@ jobs: CC: /usr/bin/gcc-12 CXX: /usr/bin/g++-12 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.maintainer.sync.test - name: generate test cert env: @@ -122,7 +120,6 @@ jobs: CC: /usr/bin/gcc-12 CXX: /usr/bin/g++-12 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.maintainer.async.test - name: generate test cert env: @@ -156,7 +153,6 @@ jobs: CC: /usr/bin/clang-14 CXX: /usr/bin/clang++-14 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.maintainer.sync.test - name: generate test cert env: @@ -190,7 +186,6 @@ jobs: CC: /usr/bin/clang-14 CXX: /usr/bin/clang++-14 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.maintainer.async.test - name: generate test cert env: @@ -235,7 +230,6 @@ jobs: CC: /usr/bin/gcc-10 CXX: /usr/bin/g++-10 run: | - sudo -E ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.with_async_export.test cmake_absel_stl_test: @@ -455,7 +449,6 @@ jobs: key: bazel_test - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -477,7 +470,6 @@ jobs: key: bazel_test - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -499,7 +491,6 @@ jobs: key: bazel_test - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -521,7 +512,6 @@ jobs: key: bazel_valgrind - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -543,7 +533,6 @@ jobs: key: bazel_noexcept - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -565,7 +554,6 @@ jobs: key: bazel_nortti - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -587,7 +575,6 @@ jobs: key: bazel_asan - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -609,7 +596,6 @@ jobs: key: bazel_tsan - name: setup run: | - sudo ./ci/setup_thrift.sh dependencies_only sudo ./ci/setup_ci_environment.sh sudo ./ci/install_bazelisk.sh - name: run tests @@ -738,7 +724,6 @@ jobs: submodules: 'recursive' - name: setup run: | - ./ci/setup_thrift.ps1 ./ci/install_windows_bazelisk.ps1 - name: run tests run: ./ci/do_ci.ps1 bazel.build diff --git a/CHANGELOG.md b/CHANGELOG.md index 3330790d2b..52a9e19f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,19 @@ Increment the: ## [Unreleased] +* [REMOVAL] Remove the jaeger exporter + [#2031](https://github.com/open-telemetry/opentelemetry-cpp/pull/2031) + * [API] Remove include_trace_context [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) +Important changes: + +* [REMOVAL] Remove the jaeger exporter + [#2031](https://github.com/open-telemetry/opentelemetry-cpp/pull/2031) + * The CMake `WITH_JAEGER` option has been removed + * Please remove usage of `WITH_JAEGER` from user scripts and makefiles. + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/CMakeLists.txt b/CMakeLists.txt index 27930fe793..fb483f5a58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,8 +182,6 @@ option(WITH_ELASTICSEARCH option(WITH_ZPAGES "Whether to include the Zpages Server in the SDK" OFF) -option(WITH_JAEGER "DEPRECATED - Whether to include the Jaeger exporter" OFF) - option(WITH_NO_GETENV "Whether the platform supports environment variables" OFF) option(BUILD_TESTING "Whether to enable tests" ON) @@ -295,25 +293,6 @@ function(set_target_version target_name) endif() endfunction() -if(WITH_JAEGER) - if(WITH_NO_DEPRECATED_CODE) - message(FATAL_ERROR "Jaeger is DEPRECATED.") - else() - message(WARNING "Jaeger is DEPRECATED.") - endif() - - find_package(Thrift QUIET) - if(Thrift_FOUND) - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIR}) - else() - # Install Thrift and propagate via vcpkg toolchain file - if(WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE)) - install_windows_deps() - endif() - endif() -endif() - if(MSVC) # Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value # for recent C++ language standards. Without this option MSVC returns the @@ -405,7 +384,6 @@ endif() if(WITH_OTLP_HTTP OR WITH_ELASTICSEARCH - OR WITH_JAEGER OR WITH_ZIPKIN OR BUILD_W3CTRACECONTEXT_TEST OR WITH_EXAMPLES_HTTP) diff --git a/DEPRECATED.md b/DEPRECATED.md index 2284197309..d77c3f073e 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -93,9 +93,7 @@ but the C++11 build will no longer be tested for each new release. ## [Third party dependencies] -### Jaeger - -See [Jaeger exporter](#jaeger-exporter) +N/A ## [Build tools] @@ -107,15 +105,7 @@ N/A ## [opentelemetry-cpp API] -N/A - -## [opentelemetry-cpp SDK] - -N/A - -## [opentelemetry-cpp Exporter] - -### Jaeger exporter +### Jaeger propagator #### Announcement (Jaeger) @@ -124,24 +114,17 @@ N/A * PR: [DEPRECATION] Deprecate the Jaeger exporter [#1923](https://github.com/open-telemetry/opentelemetry-cpp/pull/1923) -#### Motivation (Jaeger) +This PR also listed the Jaeger propagator as deprecated. -The Jaeger client libraries are deprecated, as announced -[here](https://www.jaegertracing.io/docs/1.41/client-libraries/). +#### Motivation (Jaeger) -The initial Jaeger announcement in release 1.35 reads as: +The Jaeger Exporter is now (July 2023) removed from the OpenTelemetry specification. -" -We plan to continue accepting pull requests and making new releases of -Jaeger clients through the end of 2021. In January 2022 we will enter a code -freeze period for 6 months, during which time we will no longer accept pull -requests with new features, with the exception of security-related fixes. -After that we will archive the client library repositories and will no -longer accept new changes. -" +The Jaeger Propagator remains, because changing propagation is a longer +process compared to changing an export format. -At time of writing, Jan 2023, the client libraries have been archived 6 -months ago already. +New deployments however are encouraged to use a W3C compliant propagator, +and avoid the Jaeger propagator, which is now deprecated. #### Scope (Jaeger) @@ -149,25 +132,26 @@ The following are deprecated and planned for removal: * the API header `opentelemetry/trace/propagation/jaeger.h`, including: * the C++ class `JaegerPropagator` -* all the code located under `exporters/jaeger/`, including: - * the jaeger exporter C++ class (`JaegerExporter`) - * the related factory (`JaegerExporterFactory`) - * the related options (`JaegerExporterOptions`) -* the jaeger exporter library(`opentelemetry_exporter_jaeger_trace`) -* the jaeger build options in CMake (`WITH_JAEGER`) -* the dependency on thrift #### Mitigation (Jaeger) -Jaeger supports natively the OTLP protocol, starting with jaeger 1.35. +Use a W3C compliant propagator instead. + +That is, use class HttpTraceContext and "traceparent" tags. -An application instrumented with opentelemetry needs to change how the SDK -and exporter are configured to replace the Jaeger exporter with the OTLP -exporter (both OTLP HTTP and OTLP GRPC are supported). +Do not use class JaegerPropagator and "uber-trace-id" tags. #### Planned removal (Jaeger) -* Date: July, 2023 +No date set yet for the Jaeger Propagator. + +## [opentelemetry-cpp SDK] + +N/A + +## [opentelemetry-cpp Exporter] + +N/A ## [Documentation] diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 1cf6410488..0cf8a2d8b2 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -153,18 +153,6 @@ def opentelemetry_cpp_deps(): ], ) - # libthrift (optional) - maybe( - http_archive, - name = "com_github_thrift", - build_file_content = _ALL_CONTENT, - sha256 = "5ae1c4d16452a22eaf9d802ba7489907147c2b316ff38c9758918552fae5132c", - strip_prefix = "thrift-0.14.1", - urls = [ - "https://github.com/apache/thrift/archive/refs/tags/v0.14.1.tar.gz", - ], - ) - # rules foreign cc maybe( http_archive, @@ -195,25 +183,3 @@ def opentelemetry_cpp_deps(): "https://github.com/opentracing/opentracing-cpp/archive/refs/tags/v1.6.0.tar.gz", ], ) - - # boost headers from vcpkg - maybe( - native.new_local_repository, - name = "boost_all_hdrs", - build_file_content = """ -package(default_visibility = ["//visibility:public"]) -cc_library( - name = "boost_all_hdrs", - hdrs = glob( - ["include/**/*.h*"], - ), - strip_include_prefix = "include", - copts = [ - "-isystem include", - "-fexceptions", - ], - visibility = ["//visibility:public"], -) - """, - path = "tools/vcpkg/installed/x64-windows/", - ) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 0ffe716ca1..a91ebc0255 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -85,7 +85,6 @@ switch ($action) { cmake $SRC_DIR ` -DOTELCPP_MAINTAINER_MODE=ON ` -DWITH_NO_DEPRECATED_CODE=ON ` - -DWITH_JAEGER=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 6020d22a04..e4e4807c82 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -68,7 +68,7 @@ BAZEL_OPTIONS_ASYNC="$BAZEL_OPTIONS --copt=-DENABLE_ASYNC_EXPORT" BAZEL_TEST_OPTIONS_ASYNC="$BAZEL_OPTIONS_ASYNC --test_output=errors" # https://github.com/bazelbuild/bazel/issues/4341 -BAZEL_MACOS_OPTIONS="$BAZEL_OPTIONS_ASYNC --features=-supports_dynamic_linker --build_tag_filters=-jaeger" +BAZEL_MACOS_OPTIONS="$BAZEL_OPTIONS_ASYNC --features=-supports_dynamic_linker" BAZEL_MACOS_TEST_OPTIONS="$BAZEL_MACOS_OPTIONS --test_output=errors" BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel" @@ -81,7 +81,6 @@ if [[ "$1" == "cmake.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_LOGS_PREVIEW=ON \ @@ -101,7 +100,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_LOGS_PREVIEW=ON \ @@ -124,7 +122,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_LOGS_PREVIEW=ON \ @@ -148,7 +145,6 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=OFF \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_LOGS_PREVIEW=ON \ @@ -166,7 +162,6 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_LOGS_PREVIEW=ON \ @@ -359,8 +354,8 @@ elif [[ "$1" == "bazel.benchmark" ]]; then run_benchmarks exit 0 elif [[ "$1" == "bazel.macos.test" ]]; then - bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS -- //... -//exporters/jaeger/... - bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS -- //... -//exporters/jaeger/... + bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS -- //... + bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS -- //... exit 0 elif [[ "$1" == "bazel.legacy.test" ]]; then # we uses C++ future and async() function to test the Prometheus Exporter functionality, @@ -369,17 +364,17 @@ elif [[ "$1" == "bazel.legacy.test" ]]; then bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/otlp/... -//exporters/prometheus/... exit 0 elif [[ "$1" == "bazel.noexcept" ]]; then - # there are some exceptions and error handling code from the Prometheus and Jaeger Clients + # 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 --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/... - bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//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/... -//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/... exit 0 elif [[ "$1" == "bazel.nortti" ]]; then - # there are some exceptions and error handling code from the Prometheus and Jaeger Clients + # there are some exceptions and error handling code from the Prometheus Client # that make this test always fail. Ignore these packages in the nortti test here. - bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... - bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... + bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... + bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... exit 0 elif [[ "$1" == "bazel.asan" ]]; then bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS_ASYNC //... @@ -435,7 +430,6 @@ elif [[ "$1" == "code.coverage" ]]; then exit 0 elif [[ "$1" == "third_party.tags" ]]; then echo "gRPC=v1.49.2" > third_party_release - echo "thrift=0.14.1" >> third_party_release echo "abseil=20220623.1" >> third_party_release git submodule foreach --quiet 'echo "$name=$(git describe --tags HEAD)"' | sed 's:.*/::' >> third_party_release exit 0 diff --git a/ci/setup_thrift.ps1 b/ci/setup_thrift.ps1 deleted file mode 100644 index 52cd96708a..0000000000 --- a/ci/setup_thrift.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -$ErrorActionPreference = "Stop" -trap { $host.SetShouldExit(1) } - -git submodule update -f "tools/vcpkg" -Push-Location -Path "tools/vcpkg" -$VCPKG_DIR = (Get-Item -Path ".\").FullName -setx VCPKG_DIR "$VCPKG_DIR" -./bootstrap-vcpkg.bat - -# boost needed for thrift -./vcpkg "--vcpkg-root=$VCPKG_DIR" install boost-predef[core]:x64-windows boost-locale[core]:x64-windows boost-numeric-conversion[core]:x64-windows boost-scope-exit[core]:x64-windows openssl:x64-windows - -Pop-Location diff --git a/ci/setup_thrift.sh b/ci/setup_thrift.sh deleted file mode 100755 index 1c8897089f..0000000000 --- a/ci/setup_thrift.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -set -e -export DEBIAN_FRONTEND=noninteractive -export THRIFT_VERSION=0.14.1 - -install_dir='/usr/local/' -while getopts ":i:" o; do - case "${o}" in - i) - install_dir=${OPTARG} - ;; - *) - ;; - esac -done - -apt update - -if ! type cmake > /dev/null; then - #cmake not installed, exiting - exit 1 -fi -export BUILD_DIR=/tmp/ -export INSTALL_DIR=${install_dir} - -apt install -y --no-install-recommends \ - libboost-locale-dev \ - libevent-dev \ - libssl-dev \ - ninja-build - -if [[ "$1" == "dependencies_only" ]]; then - exit 0; -fi - -pushd $BUILD_DIR -wget https://github.com/apache/thrift/archive/refs/tags/v${THRIFT_VERSION}.tar.gz -tar -zxvf v${THRIFT_VERSION}.tar.gz -cd thrift-${THRIFT_VERSION} -mkdir -p out -pushd out -cmake -G Ninja .. \ - -DBUILD_COMPILER=OFF \ - -DBUILD_CPP=ON \ - -DBUILD_LIBRARIES=ON \ - -DBUILD_NODEJS=OFF \ - -DBUILD_PYTHON=OFF \ - -DBUILD_JAVASCRIPT=OFF \ - -DBUILD_C_GLIB=OFF \ - -DBUILD_JAVA=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_TUTORIALS=OFF \ - -DWITH_STDTHREADS=ON \ - -DWITH_BOOSTTHREADS=OFF \ - -DWITH_BOOST_FUNCTIONAL=OFF \ - -DWITH_BOOST_SMART_PTR=OFF \ - -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ - -DCMAKE_PREFIX_PATH=$INSTALL_DIR \ - .. - -ninja -j $(nproc) -ninja install -popd -popd diff --git a/cmake/modules/FindThrift.cmake b/cmake/modules/FindThrift.cmake deleted file mode 100644 index 563e2c44d0..0000000000 --- a/cmake/modules/FindThrift.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -# This module defines Thrift_LIBRARIES, libraries to link Thrift_INCLUDE_DIR, -# Thrift_FOUND, If false, do not try to use it. - -# prefer the Thrift version supplied in Thrift_HOME (cmake -DThrift_HOME then -# environment) -find_path( - Thrift_INCLUDE_DIR - NAMES thrift/Thrift.h - HINTS ${Thrift_HOME} ENV Thrift_HOME /usr/local /opt/local - PATH_SUFFIXES include) - -# prefer the Thrift version supplied in Thrift_HOME -find_library( - Thrift_LIBRARIES - NAMES thrift libthrift - HINTS ${Thrift_HOME} ENV Thrift_HOME /usr/local /opt/local - PATH_SUFFIXES lib lib64) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Thrift DEFAULT_MSG Thrift_LIBRARIES - Thrift_INCLUDE_DIR) -mark_as_advanced(Thrift_LIBRARIES Thrift_INCLUDE_DIR) - - -if(Thrift_FOUND AND NOT (TARGET thrift::thrift)) - add_library(thrift::thrift UNKNOWN IMPORTED) - set_target_properties( - thrift::thrift - PROPERTIES IMPORTED_LOCATION ${Thrift_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${Thrift_INCLUDE_DIR}) -endif() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index adae58dd1b..38b3a91259 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -46,7 +46,6 @@ # opentelemetry-cpp::ostream_span_exporter - Imported target of opentelemetry-cpp::ostream_span_exporter # opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of opentelemetry-cpp::elasticsearch_log_record_exporter # opentelemetry-cpp::etw_exporter - Imported target of opentelemetry-cpp::etw_exporter -# opentelemetry-cpp::jaeger_trace_exporter - Imported target of opentelemetry-cpp::jaeger_trace_exporter # opentelemetry-cpp::zpages - Imported target of opentelemetry-cpp::zpages # opentelemetry-cpp::http_client_curl - Imported target of opentelemetry-cpp::http_client_curl # opentelemetry-cpp::opentracing_shim - Imported target of opentelemetry-cpp::opentracing_shim @@ -101,7 +100,6 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS prometheus_exporter elasticsearch_log_record_exporter etw_exporter - jaeger_trace_exporter zpages http_client_curl opentracing_shim) diff --git a/docker/Dockerfile b/docker/Dockerfile index 75360e6cbb..5fe143c4f7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,10 +3,8 @@ ARG BASE_IMAGE=ubuntu:latest ARG GRPC_IMAGE=grpc-${BASE_IMAGE} -ARG THRIFT_IMAGE=thrift-${BASE_IMAGE} FROM ${GRPC_IMAGE} as grpc -FROM ${THRIFT_IMAGE} as thrift FROM base-${BASE_IMAGE}-dev AS otel-cpp @@ -14,7 +12,6 @@ ARG CORES=${nproc} ARG OTEL_GIT_TAG=v1.3.0 COPY --from=grpc / /usr/local -COPY --from=thrift / /usr/local #install opentelemetry-cpp RUN git clone --recurse-submodules -j ${CORES} --depth=1 \ @@ -25,7 +22,6 @@ RUN git clone --recurse-submodules -j ${CORES} --depth=1 \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=ON \ -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ -DBUILD_TESTING=OFF \ -DWITH_OTLP_GRPC=ON \ diff --git a/docker/Dockerfile.alpine.base b/docker/Dockerfile.alpine.base index 0a92f26af5..d4f5932cc6 100644 --- a/docker/Dockerfile.alpine.base +++ b/docker/Dockerfile.alpine.base @@ -11,7 +11,7 @@ RUN apk update RUN apk add --update alpine-sdk \ && apk add cmake openssl openssl-dev g++ \ curl-dev git autoconf libtool linux-headers \ - boost-dev libevent-dev openssl-dev + libevent-dev openssl-dev RUN mkdir -p /opt/third_party/install diff --git a/docker/Dockerfile.centos b/docker/Dockerfile.centos index 25a6f2442f..c38b32b174 100644 --- a/docker/Dockerfile.centos +++ b/docker/Dockerfile.centos @@ -13,8 +13,6 @@ RUN yum install -y devtoolset-${TOOLSET_VER} \ && source /opt/rh/devtoolset-${TOOLSET_VER}/enable RUN echo "source /opt/rh/devtoolset-${TOOLSET_VER}/enable" >> /etc/bashrc -RUN echo "BOOST_LIBRARYDIR=/usr/lib64/boost169" >> /etc/bashrc -RUN echo "BOOST_INCLUDEDIR=/usr/include/boost169" >> /etc/bashrc ARG GRPC_VERSION=v1.43.2 @@ -36,49 +34,15 @@ RUN git clone --depth=1 -b $GRPC_VERSION https://github.com/grpc/grpc.git \ .. && \ make -j${nproc} install && make clean && ldconfig -# install thrift -ARG THRIFT_VERSION=0.14.1 -RUN yum install -y \ - boost169-devel \ - libevent-devel \ - wget \ - && wget https://github.com/apache/thrift/archive/refs/tags/v$THRIFT_VERSION.tar.gz \ - && tar -xvf v$THRIFT_VERSION.tar.gz \ - && mkdir -p thrift-$THRIFT_VERSION/build && cd thrift-$THRIFT_VERSION/build \ - && source /opt/rh/devtoolset-${TOOLSET_VER}/enable \ - && export BOOST_INCLUDEDIR=/usr/include/boost169 \ - && export BOOST_LIBRARYDIR=/usr/lib64/boost169 \ - && cmake3 \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_COMPILER=OFF \ - -DBUILD_CPP=ON \ - -DBUILD_LIBRARIES=ON \ - -DBUILD_NODEJS=OFF \ - -DBUILD_PYTHON=OFF \ - -DBUILD_JAVASCRIPT=OFF \ - -DBUILD_C_GLIB=OFF \ - -DBUILD_JAVA=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_TUTORIALS=OFF \ - -DWITH_STDTHREADS=ON \ - -DWITH_BOOSTTHREADS=OFF \ - -DWITH_BOOST_FUNCTIONAL=OFF \ - -DWITH_BOOST_SMART_PTR=OFF \ - .. \ - && make -j${nproc} && make install && ldconfig - #install opentelemetry-cpp RUN git clone --depth=1 https://github.com/open-telemetry/opentelemetry-cpp.git \ && cd opentelemetry-cpp && git submodule update --init \ && mkdir -p build && cd build \ && source /opt/rh/devtoolset-${TOOLSET_VER}/enable \ - && export BOOST_INCLUDEDIR=/usr/include/boost169 \ - && export BOOST_LIBRARYDIR=/usr/lib64/boost169 \ && cmake3 \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=ON \ -DBUILD_TESTING=OFF \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ diff --git a/docker/Dockerfile.debian.deps b/docker/Dockerfile.debian.deps index 9ee7e9519b..3fe4fe28d9 100644 --- a/docker/Dockerfile.debian.deps +++ b/docker/Dockerfile.debian.deps @@ -22,18 +22,9 @@ ARG GRPC_VERSION=1.43.2 ADD setup_grpc.sh . RUN ./setup_grpc.sh -i "/opt/otel-cpp" -v ${GRPC_VERSION} -FROM base as thrift -RUN apt-get install -y --no-install-recommends wget - -# install thrift -ARG THRIFT_VERSION=0.14.1 -ADD setup_thrift.sh . -RUN ./setup_thrift.sh -i "/opt/otel-cpp" - FROM scratch as final COPY --from=grpc /opt/otel-cpp / -COPY --from=thrift /opt/otel-cpp / # how to use: # diff --git a/docker/README.md b/docker/README.md index 165667117c..8c7ca3ce34 100644 --- a/docker/README.md +++ b/docker/README.md @@ -17,8 +17,4 @@ docker rm -f otel docker create -ti --name grpc grpc- bash docker cp grpc:/ ./ docker rm -f grpc - -docker create -ti --name thrift thrift- bash -docker cp thrift:/ ./ -docker rm -f thrift ``` diff --git a/docker/build.sh b/docker/build.sh index 53773b739f..d418a909d0 100644 --- a/docker/build.sh +++ b/docker/build.sh @@ -18,7 +18,6 @@ Help() echo "o OpenTelemetry-cpp git tag" echo "h Print Help." echo "g gRPC git tag" - echo "t thrift version" echo "j Parallel jobs" echo echo "how to use:" @@ -34,11 +33,10 @@ Help() base_image=${base_image:="alpine"} grpc_git_tag=${grpc_git_tag:="v1.43.2"} -thrift_version=${thrift_version:="0.14.1"} otel_git_tag=${otel_git_tag:="v1.3.0"} cores=${cores:=1} -while getopts ":h:b:o:g:j:t:" option; do +while getopts ":h:b:o:g:j:" option; do case $option in h) # display Help Help @@ -52,9 +50,6 @@ while getopts ":h:b:o:g:j:t:" option; do g) # gRPC git tag grpc_git_tag=$OPTARG ;; - t) # thrfit version - thrift_version=$OPTARG - ;; j) # number of cores cores=$OPTARG ;; @@ -73,13 +68,6 @@ docker build --build-arg BASE_IMAGE=base-${base_image}-dev \ -t grpc-${base_image} -f Dockerfile . popd -pushd thrift/ -docker build --build-arg BASE_IMAGE=base-${base_image}-dev \ - --build-arg THRIFT_VERSION=${thrift_version} \ - --build-arg CORES=${cores} \ - -t thrift-${base_image} -f Dockerfile . -popd - docker build --build-arg BASE_IMAGE=${base_image} \ --build-arg CORES=${cores} \ --build-arg OTEL_GIT_TAG=${otel_git_tag} \ diff --git a/docker/thrift/CMakeLists.txt b/docker/thrift/CMakeLists.txt deleted file mode 100644 index aa94362986..0000000000 --- a/docker/thrift/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.11 FATAL_ERROR) - -project( - dependencies - LANGUAGES CXX - VERSION 0.0.1) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "-O2") - -set(CMAKE_BUILD_TYPE - Release - CACHE STRING "Build type" FORCE) - -include(GNUInstallDirs) - -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY - ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) - -set(INSTALL_LIBDIR - ${CMAKE_INSTALL_LIBDIR} - CACHE PATH "directory for libraries") -set(INSTALL_BINDIR - ${CMAKE_INSTALL_BINDIR} - CACHE PATH "directory for executables") -set(INSTALL_INCLUDEDIR - ${CMAKE_INSTALL_INCLUDEDIR} - CACHE PATH "directory for header files") - -set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) -set(INSTALL_CMAKEDIR - ${DEF_INSTALL_CMAKEDIR} - CACHE PATH "directory for CMake files") - -set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subs) - -set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage) -message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}") - -find_package(OpenSSL REQUIRED) -message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") -message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") - -set(THRIFT_VERSION - "0.14.1" - CACHE STRING "thrift version") - -include(ExternalProject) -ExternalProject_Add( - thrift - URL https://github.com/apache/thrift/archive/refs/tags/v${THRIFT_VERSION}.tar.gz - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE - -DBUILD_COMPILER=OFF - -DBUILD_CPP=ON - -DBUILD_LIBRARIES=ON - -DBUILD_NODEJS=OFF - -DBUILD_PYTHON=OFF - -DBUILD_JAVASCRIPT=OFF - -DBUILD_C_GLIB=OFF - -DBUILD_JAVA=OFF - -DBUILD_TESTING=OFF - -DBUILD_TUTORIALS=OFF - -DWITH_STDTHREADS=ON - -DWITH_BOOSTTHREADS=OFF - -DWITH_BOOST_FUNCTIONAL=OFF - -DWITH_BOOST_SMART_PTR=OFF - CMAKE_CACHE_ARGS -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} - TEST_AFTER_INSTALL 0 - DOWNLOAD_NO_PROGRESS 1 - LOG_CONFIGURE 1 - LOG_BUILD 0 - LOG_INSTALL 1) - -install( - DIRECTORY ${STAGED_INSTALL_PREFIX}/ - DESTINATION . - USE_SOURCE_PERMISSIONS) diff --git a/docker/thrift/Dockerfile b/docker/thrift/Dockerfile deleted file mode 100644 index 60792e597b..0000000000 --- a/docker/thrift/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -ARG BASE_IMAGE=ubuntu:latest -FROM ${BASE_IMAGE} AS thrift - -ARG CORES=${nproc} -ARG THRIFT_VERSION=0.14.1 - -RUN mkdir mkdir -p /opt/third_party/thrift - -WORKDIR /opt/third_party/th - -ADD CMakeLists.txt /opt/third_party/thrift - -RUN mkdir build \ - && cd build \ - && cmake -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ - -DTHRIFT_VERSION=${THRIFT_VERSION} /opt/third_party/thrift \ - && cmake --build . -j ${CORES} --target install - -FROM scratch as final - -COPY --from=thrift /opt/third_party/install / diff --git a/docker/ubuntuLatest/Dockerfile b/docker/ubuntuLatest/Dockerfile index aec2296401..f2c69d0a49 100644 --- a/docker/ubuntuLatest/Dockerfile +++ b/docker/ubuntuLatest/Dockerfile @@ -24,31 +24,6 @@ RUN apt-get update && apt-get install -y build-essential autoconf libtool pkg-co make -j${nproc} install && make clean && ldconfig && \ cd ../.. -#install thrift -ARG THRIFT_VERSION=0.14.1 -RUN apt-get install -y --no-install-recommends \ - libboost-all-dev \ - libevent-dev \ - wget && \ - wget https://github.com/apache/thrift/archive/refs/tags/v$THRIFT_VERSION.tar.gz && \ - tar -xvf v$THRIFT_VERSION.tar.gz && \ - mkdir -p thrift-$THRIFT_VERSION/build && cd thrift-$THRIFT_VERSION/build && \ - cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_COMPILER=OFF \ - -DBUILD_CPP=ON \ - -DBUILD_LIBRARIES=ON \ - -DBUILD_NODEJS=OFF \ - -DBUILD_PYTHON=OFF \ - -DBUILD_JAVASCRIPT=OFF \ - -DBUILD_C_GLIB=OFF \ - -DBUILD_JAVA=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_TUTORIALS=OFF \ - .. && \ - make -j${nproc} install && make clean && ldconfig && \ - cd ../.. - #install opentelemetry-cpp RUN apt-get install -y --no-install-recommends libcurl4-openssl-dev && git clone --depth=1 https://github.com/open-telemetry/opentelemetry-cpp.git && \ cd opentelemetry-cpp && git submodule update --init && \ @@ -57,7 +32,6 @@ RUN apt-get install -y --no-install-recommends libcurl4-openssl-dev && git clone -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ -DWITH_ZIPKIN=ON \ - -DWITH_JAEGER=ON \ -DBUILD_TESTING=OFF \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ diff --git a/docs/dependencies.md b/docs/dependencies.md index 06c3806d34..62fbefc297 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -75,17 +75,6 @@ Both these dependencies are listed here: - `libcurl` for connecting with Zipkin server over HTTP protocol. - `nlohmann/json` for encoding Zipkin messages. -- [Jaeger](/exporters/jaeger) - exporter: - - [Thrift](https://github.com/apache/thrift) - Serialization and RPC - framework. - - `thrift` compiler to generate C++ stubs for IDL data model for Jaeger. - - `libthrift` library to generate serialized trace/metrics/log data to be - sent to remote Jaeger service. Note: libthrift **0.12.0** doesn't work - with this Jaeger exporter. See - [#1680](https://github.com/open-telemetry/opentelemetry-cpp/issues/1680). - - License: `Apache License 2.0` - - [ETW](/exporters/etw) exporter: - `nlohmann/json` for generating MessagePack serialization for message to be diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index 330507d7c1..d93e778d9f 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -13,7 +13,6 @@ An exporter is responsible for sending the telemetry data to a particular backen OpenTelemetry offers six tracing exporters out of the box: - In-Memory Exporter: keeps the data in memory, useful for debugging. -- Jaeger Exporter: prepares and sends the collected telemetry data to a Jaeger backend via UDP and HTTP. - Zipkin Exporter: prepares and sends the collected telemetry data to a Zipkin backend via the Zipkin APIs. - Logging Exporter: saves the telemetry data into log streams. - OpenTelemetry(otlp) Exporter: sends the data to the OpenTelemetry Collector using protobuf/gRPC or protobuf/HTTP. @@ -39,23 +38,6 @@ OpenTelemetry offers six tracing exporters out of the box: auto zipkin_exporter = std::unique_ptr(new opentelemetry::exporter::zipkin::ZipkinExporter(opts)); - // Jaeger UDP exporter - opentelemetry::exporter::jaeger::JaegerExporterOptions opts; - opts.endpoint = "localhost"; - opts.server_port = 6831; - auto jaeger_udp_exporter = - std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); - - // Jaeger HTTP exporter - opentelemetry::exporter::jaeger::JaegerExporterOptions opts; - opts.transport_format = opentelemetry::exporter::jaeger::TransportFormat::kThriftHttp; - opts.endpoint = "localhost"; - opts.server_port = 14268; - opts.headers = {{}}; // optional headers - auto jaeger_http_exporter = - std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); - - // otlp grpc exporter opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; opts.endpoint = "localhost:4317"; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7ffec0fab4..fb64ed21c0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,9 +12,6 @@ endif() if(WITH_ETW) add_subdirectory(etw_threads) endif() -if(WITH_JAEGER) - add_subdirectory(jaeger) -endif() if(WITH_ZIPKIN) add_subdirectory(zipkin) endif() diff --git a/examples/jaeger/BUILD b/examples/jaeger/BUILD deleted file mode 100644 index e2f0ec7bce..0000000000 --- a/examples/jaeger/BUILD +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cc_binary( - name = "example_jaeger", - srcs = [ - "main.cc", - ], - tags = ["jaeger"], - deps = [ - "//api", - "//examples/common/foo_library:common_foo_library", - "//exporters/jaeger:opentelemetry_exporter_jaeger_trace", - "//sdk/src/trace", - ], -) diff --git a/examples/jaeger/CMakeLists.txt b/examples/jaeger/CMakeLists.txt deleted file mode 100644 index 0c75ff4b6d..0000000000 --- a/examples/jaeger/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -include_directories(${CMAKE_SOURCE_DIR}/exporters/jaeger/include) - -add_executable(example_jaeger main.cc) -target_link_libraries( - example_jaeger ${CMAKE_THREAD_LIBS_INIT} common_foo_library - opentelemetry_trace opentelemetry_exporter_jaeger_trace) diff --git a/examples/jaeger/README.md b/examples/jaeger/README.md deleted file mode 100644 index 42ac4e125a..0000000000 --- a/examples/jaeger/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Jaeger Exporter Example - -This is an example of how to use the Jaeger exporter. - -The application in `main.cc` initializes an `JaegerExporter` instance and uses it -to register a tracer provider from the [OpenTelemetry -SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then -calls a `foo_library` which has been instrumented using the [OpenTelemetry -API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). - -Resulting spans are exported to the Jaeger agent using the Jaeger exporter. - -Note that the Jaeger exporter connects to the agent at `localhost:6831` by -default. - -Once you have the Collector running, see -[CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and -running the example. diff --git a/examples/jaeger/main.cc b/examples/jaeger/main.cc deleted file mode 100644 index a5b3c38c35..0000000000 --- a/examples/jaeger/main.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "opentelemetry/exporters/jaeger/jaeger_exporter_factory.h" -#include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/processor.h" -#include "opentelemetry/sdk/trace/simple_processor_factory.h" -#include "opentelemetry/sdk/trace/tracer_provider_factory.h" -#include "opentelemetry/trace/provider.h" - -#ifdef BAZEL_BUILD -# include "examples/common/foo_library/foo_library.h" -#else -# include "foo_library/foo_library.h" -#endif - -namespace trace = opentelemetry::trace; -namespace trace_sdk = opentelemetry::sdk::trace; -namespace jaeger = opentelemetry::exporter::jaeger; - -namespace -{ -opentelemetry::exporter::jaeger::JaegerExporterOptions opts; -void InitTracer() -{ - // Create Jaeger exporter instance - auto exporter = jaeger::JaegerExporterFactory::Create(opts); - auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); - std::shared_ptr provider = - trace_sdk::TracerProviderFactory::Create(std::move(processor)); - // Set the global trace provider - trace::Provider::SetTracerProvider(provider); -} - -void CleanupTracer() -{ - std::shared_ptr none; - trace::Provider::SetTracerProvider(none); -} -} // namespace - -int main(int argc, char *argv[]) -{ - if (argc == 2) - { - opts.endpoint = argv[1]; - } - // Removing this line will leave the default noop TracerProvider in place. - InitTracer(); - - foo_library(); - - CleanupTracer(); -} diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt index d980fbd838..78f845aadf 100644 --- a/exporters/CMakeLists.txt +++ b/exporters/CMakeLists.txt @@ -23,7 +23,3 @@ endif() if(WITH_ETW) add_subdirectory(etw) endif() - -if(WITH_JAEGER) - add_subdirectory(jaeger) -endif() diff --git a/exporters/jaeger/BUILD b/exporters/jaeger/BUILD deleted file mode 100644 index 6f0e030b4d..0000000000 --- a/exporters/jaeger/BUILD +++ /dev/null @@ -1,226 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "configure_make", "configure_make_variant") - -constraint_setting( - name = "incompatible_setting", -) - -constraint_value( - name = "incompatible", - constraint_setting = ":incompatible_setting", -) - -config_setting( - name = "windows", - constraint_values = [ - "@platforms//os:windows", - ], - tags = ["jaeger"], - visibility = ["//visibility:private"], -) - -THRIFT_CACHE_ENTRIES = { - "CMAKE_BUILD_TYPE": "Release", - "BUILD_COMPILER": "OFF", - "BUILD_CPP": "ON", - "BUILD_LIBRARIES": "ON", - "BUILD_NODEJS": "OFF", - "BUILD_PYTHON": "OFF", - "BUILD_JAVASCRIPT": "OFF", - "BUILD_C_GLIB": "OFF", - "BUILD_JAVA": "OFF", - "BUILD_TESTING": "OFF", - "BUILD_TUTORIALS": "OFF", - "WITH_HASKELL": "OFF", -} - -THRIFT_CACHE_ENTRIES_WIN = { - "CMAKE_BUILD_TYPE": "Release", - "BUILD_COMPILER": "OFF", - "BUILD_CPP": "ON", - "BUILD_LIBRARIES": "ON", - "BUILD_NODEJS": "OFF", - "BUILD_PYTHON": "OFF", - "BUILD_JAVASCRIPT": "OFF", - "BUILD_C_GLIB": "OFF", - "BUILD_JAVA": "OFF", - "BUILD_TESTING": "OFF", - "BUILD_TUTORIALS": "OFF", - "WITH_HASKELL": "OFF", - "WITH_STDTHREADS": "ON", - "WITH_BOOSTTHREADS": "OFF", - "WITH_BOOST_FUNCTIONAL": "OFF", - "WITH_BOOST_SMART_PTR": "OFF", - "BUILD_SHARED_LIBS": "OFF", - "CMAKE_TOOLCHAIN_FILE": "$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake", -} - -cmake( - name = "thrift", - cache_entries = select({ - "@platforms//os:osx": THRIFT_CACHE_ENTRIES, - "@platforms//os:linux": THRIFT_CACHE_ENTRIES, - "@platforms//os:windows": THRIFT_CACHE_ENTRIES_WIN, - }), - copts = [ - "-Ilibs/exporters/jaeger/openssl/include", - "-fexceptions", - ], - generate_args = select({ - "@platforms//os:osx": [], - "@platforms//os:linux": [], - "@platforms//os:windows": [ - "-G \"NMake Makefiles\"", - ], - }), - install = True, - lib_source = "@com_github_thrift//:all_srcs", - out_lib_dir = select({ - "@platforms//os:osx": "lib", - "@platforms//os:linux": "lib", - "@platforms//os:windows": "bin", - }), - out_static_libs = select({ - "@platforms//os:osx": [ - "libthrift.a", - "libthriftz.a", - ], - "@platforms//os:linux": [ - "libthrift.a", - "libthriftz.a", - ], - "@platforms//os:windows": [ - "thriftmd.lib", - ], - }), - tags = ["jaeger"], - visibility = ["//visibility:private"], - deps = [], -) - -THRIFT_GEN_DEPS = [ - ":thrift", - "//ext/src/http/client/curl:http_client_curl", -] - -THRIFT_GEN_DEPS_WIN = THRIFT_GEN_DEPS + [ - "@boost_all_hdrs//:boost_all_hdrs", -] - -cc_library( - name = "jaeger_thrift_gencpp", - srcs = [ - "thrift-gen/Agent.cpp", - "thrift-gen/Collector.cpp", - "thrift-gen/ZipkinCollector.cpp", - "thrift-gen/jaeger_types.cpp", - "thrift-gen/zipkincore_constants.cpp", - "thrift-gen/zipkincore_types.cpp", - ], - hdrs = [ - "thrift-gen/Agent.h", - "thrift-gen/Collector.h", - "thrift-gen/ZipkinCollector.h", - "thrift-gen/agent_types.h", - "thrift-gen/jaeger_types.h", - "thrift-gen/zipkincore_constants.h", - "thrift-gen/zipkincore_types.h", - ], - copts = [ - "-fexceptions", - ], - strip_include_prefix = "thrift-gen", - tags = ["jaeger"], - deps = select({ - "@platforms//os:osx": THRIFT_GEN_DEPS, - "@platforms//os:linux": THRIFT_GEN_DEPS, - "@platforms//os:windows": THRIFT_GEN_DEPS_WIN, - }), -) - -cc_library( - name = "jaeger_exporter", - srcs = [ - ], - hdrs = [ - "src/THttpTransport.h", - "src/TUDPTransport.h", - "src/http_transport.h", - "src/sender.h", - "src/thrift_sender.h", - "src/transport.h", - "src/udp_transport.h", - ], - copts = ["-fexceptions"], - strip_include_prefix = "src", - tags = ["jaeger"], - deps = [ - ":jaeger_thrift_gencpp", - ], -) - -cc_library( - name = "opentelemetry_exporter_jaeger_trace", - srcs = [ - "src/THttpTransport.cc", - "src/TUDPTransport.cc", - "src/http_transport.cc", - "src/jaeger_exporter.cc", - "src/jaeger_exporter_factory.cc", - "src/recordable.cc", - "src/thrift_sender.cc", - "src/udp_transport.cc", - ], - hdrs = [ - "include/opentelemetry/exporters/jaeger/jaeger_exporter.h", - "include/opentelemetry/exporters/jaeger/jaeger_exporter_factory.h", - "include/opentelemetry/exporters/jaeger/jaeger_exporter_options.h", - "include/opentelemetry/exporters/jaeger/recordable.h", - "include/opentelemetry/exporters/jaeger/thrift_include_prefix.h", - "include/opentelemetry/exporters/jaeger/thrift_include_suffix.h", - ], - copts = ["-fexceptions"], - strip_include_prefix = "include", - tags = ["jaeger"], - deps = [ - ":jaeger_exporter", - "//sdk/src/common:global_log_handler", - "//sdk/src/trace", - ], -) - -cc_test( - name = "jaeger_recordable_test", - srcs = ["test/jaeger_recordable_test.cc"], - copts = ["-fexceptions"], - tags = [ - "jaeger", - "test", - ], - deps = [ - ":opentelemetry_exporter_jaeger_trace", - "//sdk/src/resource", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "jaeger_exporter_test", - srcs = ["test/jaeger_exporter_test.cc"], - copts = ["-fexceptions"], - defines = ["BAZEL_BUILD"], - tags = [ - "jaeger", - "test", - ], - deps = [ - ":opentelemetry_exporter_jaeger_trace", - "//sdk/src/resource", - "//sdk/src/trace", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/exporters/jaeger/CMakeLists.txt b/exporters/jaeger/CMakeLists.txt deleted file mode 100644 index 222084eeb7..0000000000 --- a/exporters/jaeger/CMakeLists.txt +++ /dev/null @@ -1,111 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -include_directories(thrift-gen) - -find_package(Thrift REQUIRED) -# vcpkg config recipe points to THRIFT_INCLUDE_DIR=...\thrift . Ensure that the -# include dir for thrift-gen code is 1 level-up from that: -include_directories(SYSTEM ${THRIFT_INCLUDE_DIR}/..) - -set(JAEGER_THRIFT_GENCPP_SOURCES - thrift-gen/Agent.cpp thrift-gen/jaeger_types.cpp thrift-gen/Collector.cpp - thrift-gen/zipkincore_types.cpp) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - message("Relaxing GCC warnings on thrift-gen") - # THRIFT generated code is not warning clean for gcc. - set_source_files_properties( - ${JAEGER_THRIFT_GENCPP_SOURCES} PROPERTIES COMPILE_OPTIONS - "-Wno-suggest-override") -endif() - -set(JAEGER_EXPORTER_SOURCES - src/jaeger_exporter.cc - src/jaeger_exporter_factory.cc - src/thrift_sender.cc - src/udp_transport.cc - src/recordable.cc - src/TUDPTransport.cc - src/http_transport.cc - src/THttpTransport.cc) - -add_library(opentelemetry_exporter_jaeger_trace ${JAEGER_EXPORTER_SOURCES} - ${JAEGER_THRIFT_GENCPP_SOURCES}) - -set_target_properties(opentelemetry_exporter_jaeger_trace - PROPERTIES EXPORT_NAME jaeger_trace_exporter) -set_target_version(opentelemetry_exporter_jaeger_trace) - -target_include_directories( - opentelemetry_exporter_jaeger_trace - PUBLIC "$" - "$") - -target_link_libraries( - opentelemetry_exporter_jaeger_trace - PUBLIC opentelemetry_resources opentelemetry_trace - opentelemetry_http_client_curl - PRIVATE thrift::thrift) - -if(MSVC) - target_compile_definitions(opentelemetry_exporter_jaeger_trace - PUBLIC NOMINMAX) - if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(opentelemetry_exporter_jaeger_trace - PUBLIC THRIFT_STATIC_DEFINE) - endif() -endif() - -if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_jaeger_trace - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - - install( - DIRECTORY include/opentelemetry/exporters/jaeger - DESTINATION include/opentelemetry/exporters - FILES_MATCHING - PATTERN "*.h" - PATTERN "recordable.h" EXCLUDE) -endif() - -if(BUILD_TESTING) - add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1) - - add_executable(jaeger_recordable_test test/jaeger_recordable_test.cc) - target_link_libraries( - jaeger_recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_jaeger_trace) - - gtest_add_tests( - TARGET jaeger_recordable_test - TEST_PREFIX exporter. - TEST_LIST jaeger_recordable_test) - - add_executable(jaeger_exporter_test test/jaeger_exporter_test.cc) - if(MSVC) - if(GMOCK_LIB) - unset(GMOCK_LIB CACHE) - endif() - endif() - if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug") - find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib) - else() - find_library(GMOCK_LIB gmock PATH_SUFFIXES lib) - endif() - target_link_libraries( - jaeger_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIB} opentelemetry_trace opentelemetry_exporter_jaeger_trace) - - target_include_directories(jaeger_exporter_test - PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src) - - gtest_add_tests( - TARGET jaeger_exporter_test - TEST_PREFIX exporter. - TEST_LIST jaeger_exporter_test) -endif() # BUILD_TESTING diff --git a/exporters/jaeger/README.md b/exporters/jaeger/README.md deleted file mode 100644 index 2a795596a4..0000000000 --- a/exporters/jaeger/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Jaeger Exporter for OpenTelemetry C++ - -## DEPRECATED - -The Jaeger Exporter is deprecated, and will be removed in a future release. - -See [DEPRECATED](../../DEPRECATED.md) for details. - -## Prerequisite - -* [Get Jaeger](https://www.jaegertracing.io/docs/getting-started/) and run - Jaeger agent. - -## Installation - -### CMake Installation Instructions - -Refer to install instructions -[INSTALL.md](../../INSTALL.md#building-as-standalone-cmake-project). Modify step -2 to create `cmake` build configuration for compiling with Jaeger exporter as -below: - -```console - $ cmake -DWITH_JAEGER=ON .. - -- The C compiler identification is GNU 9.3.0 - -- The CXX compiler identification is GNU 9.3.0 - ... - -- Configuring done - -- Generating done - -- Build files have been written to: /home//source/opentelemetry-cpp/build - $ -``` - -### Bazel install Instructions - -Refer to install instructions -[INSTALL.md](../../INSTALL.md#building-as-standalone-bazel-project). - -```console -bazel build //exporters/jaeger:opentelemetry_exporter_jaeger_trace -``` - -## Usage - -Install the exporter in your application, initialize and pass the `options` to it. - -```cpp -opentelemetry::exporter::jaeger::JaegerExporterOptions options; -options.server_addr = "localhost"; -options.server_port = 6831; -options.transport_format = opentelemetry::exporter::jaeger::TransportFormat::kThriftUdpCompact; - -auto exporter = std::unique_ptr( - new opentelemetry::exporter::jaeger::JaegerExporter(options)); -auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); -auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor)); - -// Set the global trace provider -opentelemetry::trace::Provider::SetTracerProvider(provider); - -``` - -## Viewing your traces - -Please visit the Jaeger UI endpoint . diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h deleted file mode 100644 index eac6dc6940..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#ifdef OPENTELEMETRY_NO_DEPRECATED_CODE -# error "header is deprecated." -#endif - -#include -#include -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -class ThriftSender; - -class OPENTELEMETRY_DEPRECATED JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter -{ -public: - /** - * Create a JaegerExporter using all default options. - */ - JaegerExporter(); - - /** - * Create a JaegerExporter using the given options. - */ - explicit JaegerExporter(const JaegerExporterOptions &options); - - /** - * Create a span recordable. - * @return a new initialized Recordable object. - */ - std::unique_ptr MakeRecordable() noexcept override; - - /** - * Export a batch of spans. - * @param spans a span of unique pointers to span recordables. - */ - opentelemetry::sdk::common::ExportResult Export( - const nostd::span> &spans) noexcept - override; - - /** - * Force flush the exporter. - * @param timeout an option timeout, default to max. - * @return return true when all data are exported, and false when timeout - */ - bool ForceFlush( - std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; - - /** - * Shutdown the exporter. - * @param timeout an option timeout, default to max. - */ - bool Shutdown( - std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; - -private: - void InitializeEndpoint(); - -private: - // The configuration options associated with this exporter. - bool is_shutdown_ = false; - JaegerExporterOptions options_; - std::unique_ptr sender_; - mutable opentelemetry::common::SpinLockMutex lock_; - bool isShutdown() const noexcept; - // For testing - friend class JaegerExporterTestPeer; - /** - * Create an JaegerExporter using the specified thrift sender. - * Only tests can call this constructor directly. - * @param sender the thrift sender to be used for exporting - */ - JaegerExporter(std::unique_ptr sender); -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_factory.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_factory.h deleted file mode 100644 index e8f4f75eb0..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_factory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#ifdef OPENTELEMETRY_NO_DEPRECATED_CODE -# error "header is deprecated." -#endif - -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -/** - * Factory class for JaegerExporter. - */ -class OPENTELEMETRY_DEPRECATED JaegerExporterFactory -{ -public: - /** - * Create a JaegerExporter using all default options. - */ - static std::unique_ptr Create(); - - /** - * Create a JaegerExporter using the given options. - */ - static std::unique_ptr Create( - const JaegerExporterOptions &options); -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_options.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_options.h deleted file mode 100644 index 8250f09aab..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter_options.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#ifdef OPENTELEMETRY_NO_DEPRECATED_CODE -# error "header is deprecated." -#endif - -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ -enum class TransportFormat -{ - kThriftUdp, - kThriftUdpCompact, - kThriftHttp, - kProtobufGrpc, -}; - -/** - * Struct to hold Jaeger exporter options. - */ -struct OPENTELEMETRY_DEPRECATED JaegerExporterOptions -{ - TransportFormat transport_format = TransportFormat::kThriftUdpCompact; - std::string endpoint = "localhost"; - uint16_t server_port = 6831; - // Only applicable when using kThriftHttp transport. - ext::http::client::Headers headers; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h deleted file mode 100644 index b1b944fd07..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include - -#include - -#include -#include - -#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -# define JAEGER_IS_LITTLE_ENDIAN 1 -#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define JAEGER_IS_LITTLE_ENDIAN 0 -#elif defined(_WIN32) -# define JAEGER_IS_LITTLE_ENDIAN 1 -#else -# error "Endian detection needs to be set up for your compiler" -#endif - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -#if JAEGER_IS_LITTLE_ENDIAN == 1 - -# if defined(__clang__) || \ - (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ >= 5)) -inline uint64_t otel_bswap_64(uint64_t host_int) -{ - return __builtin_bswap64(host_int); -} - -# elif defined(_MSC_VER) -inline uint64_t otel_bswap_64(uint64_t host_int) -{ - return _byteswap_uint64(host_int); -} - -# else -# error "Port need to support endianess conversion" - -# endif - -#endif - -using namespace jaegertracing; - -class JaegerRecordable final : public sdk::trace::Recordable -{ -public: - JaegerRecordable(); - - thrift::Span *Span() noexcept { return span_.release(); } - std::vector Tags() noexcept { return std::move(tags_); } - std::vector ResourceTags() noexcept { return std::move(resource_tags_); } - std::vector Logs() noexcept { return std::move(logs_); } - std::vector References() noexcept { return std::move(references_); } - const std::string &ServiceName() const noexcept { return service_name_; } - - void SetIdentity(const opentelemetry::trace::SpanContext &span_context, - opentelemetry::trace::SpanId parent_span_id) noexcept override; - - void SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept override; - - void AddEvent(nostd::string_view key, - common::SystemTimestamp timestamp, - const common::KeyValueIterable &attributes) noexcept override; - - void AddLink(const opentelemetry::trace::SpanContext &span_context, - const common::KeyValueIterable &attributes) noexcept override; - - void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override; - - void SetName(nostd::string_view name) noexcept override; - - void SetStartTime(common::SystemTimestamp start_time) noexcept override; - - void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; - - void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; - - void SetDuration(std::chrono::nanoseconds duration) noexcept override; - - void SetInstrumentationScope(const opentelemetry::sdk::instrumentationscope::InstrumentationScope - &instrumentation_scope) noexcept override; - -private: - void AddTag(const std::string &key, const std::string &value, std::vector &tags); - void AddTag(const std::string &key, const char *value, std::vector &tags); - void AddTag(const std::string &key, bool value, std::vector &tags); - void AddTag(const std::string &key, int64_t value, std::vector &tags); - void AddTag(const std::string &key, double value, std::vector &tags); - - void PopulateAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value, - std::vector &tags); - - void PopulateAttribute(nostd::string_view key, - const sdk::common::OwnedAttributeValue &value, - std::vector &tags); - -private: - std::unique_ptr span_; - std::vector tags_; - std::vector resource_tags_; - std::vector logs_; - std::vector references_; - std::string service_name_; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_prefix.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_prefix.h deleted file mode 100644 index 92754d4800..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_prefix.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -// This file may be include multiple times, do not add #pragma once here - -#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__) -# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460 -# pragma GCC diagnostic push -# endif -# pragma GCC diagnostic ignored "-Wsuggest-override" -#endif diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_suffix.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_suffix.h deleted file mode 100644 index fc276705c3..0000000000 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/thrift_include_suffix.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -// This file may be include multiple times, do not add #pragma once here - -#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__) -# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460 -# pragma GCC diagnostic pop -# endif -#endif diff --git a/exporters/jaeger/src/THttpTransport.cc b/exporters/jaeger/src/THttpTransport.cc deleted file mode 100644 index db2c8a0cd2..0000000000 --- a/exporters/jaeger/src/THttpTransport.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "THttpTransport.h" -#include "opentelemetry/ext/http/client/http_client_factory.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -THttpTransport::THttpTransport(std::string endpoint, ext::http::client::Headers extra_headers) - : endpoint(std::move(endpoint)), - headers(std::move(extra_headers)), - client(ext::http::client::HttpClientFactory::CreateSync()) -{ - headers.insert({{"Content-Type", "application/vnd.apache.thrift.binary"}}); -} - -THttpTransport::~THttpTransport() {} - -bool THttpTransport::isOpen() const -{ - return true; -} - -uint32_t THttpTransport::read(uint8_t *buf, uint32_t len) -{ - (void)buf; - (void)len; - return 0; -} - -void THttpTransport::write(const uint8_t *buf, uint32_t len) -{ - request_buffer.insert(request_buffer.end(), buf, buf + len); -} - -bool THttpTransport::sendSpans() -{ - auto result = client->PostNoSsl(endpoint, request_buffer, headers); - request_buffer.clear(); - - // TODO: Add logging once global log handling is available. - if (!result) - { - return false; - } - - if (result.GetResponse().GetStatusCode() >= 400) - { - return false; - } - - return true; -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/THttpTransport.h b/exporters/jaeger/src/THttpTransport.h deleted file mode 100644 index 9c796e67a0..0000000000 --- a/exporters/jaeger/src/THttpTransport.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include -#include - -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -class THttpTransport : public apache::thrift::transport::TVirtualTransport -{ -public: - THttpTransport(std::string endpoint, ext::http::client::Headers extra_headers); - ~THttpTransport() override; - - bool isOpen() const override; - - uint32_t read(uint8_t *buf, uint32_t len); - - void write(const uint8_t *buf, uint32_t len); - - bool sendSpans(); - -private: - std::string endpoint; - ext::http::client::Headers headers; - std::shared_ptr client; - std::vector request_buffer; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/TUDPTransport.cc b/exporters/jaeger/src/TUDPTransport.cc deleted file mode 100644 index e411127392..0000000000 --- a/exporters/jaeger/src/TUDPTransport.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include // std::stringstream - -#include "TUDPTransport.h" -#include "opentelemetry/sdk_config.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -TUDPTransport::TUDPTransport(const std::string &host, int port) - : host_(host), port_(port), socket_(THRIFT_INVALID_SOCKET) -{} - -TUDPTransport::~TUDPTransport() -{ - if (server_addr_info_) - { - freeaddrinfo(server_addr_info_); - server_addr_info_ = nullptr; - sockaddr_len = 0; - } - close(); -} - -bool TUDPTransport::isOpen() const -{ - return (socket_ != THRIFT_INVALID_SOCKET); -} - -void TUDPTransport::open() -{ - if (isOpen()) - { - return; - } - - struct addrinfo hints; - int error; - char port[sizeof("65535") + 1]; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; - - sprintf(port, "%d", port_); - - error = getaddrinfo(host_.c_str(), port, &hints, &server_addr_info_); - - if (error) - { - OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: getaddrinfo failed with error: " << error); - return; - } - - socket_ = socket(server_addr_info_->ai_family, server_addr_info_->ai_socktype, - server_addr_info_->ai_protocol); - sockaddr_len = server_addr_info_->ai_addr->sa_family == AF_INET ? sizeof(struct sockaddr_in) - : sizeof(struct sockaddr_in6); -} - -void TUDPTransport::close() -{ - if (socket_ != THRIFT_INVALID_SOCKET) - { - ::THRIFT_CLOSESOCKET(socket_); - } - socket_ = THRIFT_INVALID_SOCKET; -} - -uint32_t TUDPTransport::read(uint8_t *buf, uint32_t len) -{ - if (!server_addr_info_) - { - return 0; - } - uint32_t num_read = recvfrom(socket_, -#if defined(_WIN32) - reinterpret_cast(buf), len, 0, server_addr_info_->ai_addr, - reinterpret_cast(&sockaddr_len) -#else - buf, len, 0, server_addr_info_->ai_addr, &sockaddr_len -#endif - ); - - return num_read; -} - -void TUDPTransport::write(const uint8_t *buf, uint32_t len) -{ - if (!server_addr_info_) - { - return; - } - sendto(socket_, -#if defined(_WIN32) - reinterpret_cast(buf), -#else - buf, -#endif - len, 0, server_addr_info_->ai_addr, sockaddr_len); -} - -void TUDPTransport::flush() {} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/TUDPTransport.h b/exporters/jaeger/src/TUDPTransport.h deleted file mode 100644 index df3151d110..0000000000 --- a/exporters/jaeger/src/TUDPTransport.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#ifdef _WIN32 -# include -#else -# include -# include -# include -# include -#endif - -#include -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -class TUDPTransport : public apache::thrift::transport::TVirtualTransport -{ -public: - TUDPTransport(const std::string &host, int port); - ~TUDPTransport() override; - - bool isOpen() const override; - - void open() override; - - void close() override; - - uint32_t read(uint8_t *buf, uint32_t len); - - void write(const uint8_t *buf, uint32_t len); - - void flush() override; - -private: - std::string host_; - int port_; - THRIFT_SOCKET socket_; - struct addrinfo *server_addr_info_ = nullptr; - uint32_t sockaddr_len = 0; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/http_transport.cc b/exporters/jaeger/src/http_transport.cc deleted file mode 100644 index f804ccc843..0000000000 --- a/exporters/jaeger/src/http_transport.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "http_transport.h" - -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using TBinaryProtocol = apache::thrift::protocol::TBinaryProtocol; -using TTransport = apache::thrift::transport::TTransport; - -HttpTransport::HttpTransport(std::string endpoint, ext::http::client::Headers headers) -{ - endpoint_transport_ = std::make_shared(std::move(endpoint), std::move(headers)); - protocol_ = std::shared_ptr(new TBinaryProtocol(endpoint_transport_)); -} - -int HttpTransport::EmitBatch(const thrift::Batch &batch) -{ - batch.write(protocol_.get()); - - if (!endpoint_transport_->sendSpans()) - { - return 0; - } - - return static_cast(batch.spans.size()); -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/http_transport.h b/exporters/jaeger/src/http_transport.h deleted file mode 100644 index 8748ae53a2..0000000000 --- a/exporters/jaeger/src/http_transport.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "THttpTransport.h" -#include "transport.h" - -#include -#include -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using TProtocol = apache::thrift::protocol::TProtocol; - -class HttpTransport : public Transport -{ -public: - HttpTransport(std::string endpoint, ext::http::client::Headers headers); - - int EmitBatch(const thrift::Batch &batch) override; - - uint32_t MaxPacketSize() const override - { - // Default to 4 MiB POST body size. - return 1 << 22; - } - -private: - std::shared_ptr endpoint_transport_; - std::shared_ptr protocol_; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc deleted file mode 100644 index 7f413caf30..0000000000 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include - -#include - -#include - -#include -#include -#include "opentelemetry/sdk_config.h" - -#include "http_transport.h" -#include "thrift_sender.h" -#include "udp_transport.h" - -#include -#include - -namespace sdk_common = opentelemetry::sdk::common; -namespace trace_sdk = opentelemetry::sdk::trace; - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -JaegerExporter::JaegerExporter(const JaegerExporterOptions &options) : options_(options) -{ - InitializeEndpoint(); -} - -JaegerExporter::JaegerExporter() : JaegerExporter(JaegerExporterOptions()) {} - -JaegerExporter::JaegerExporter(std::unique_ptr sender) - : options_(JaegerExporterOptions()), sender_(std::move(sender)) -{} - -std::unique_ptr JaegerExporter::MakeRecordable() noexcept -{ - return std::unique_ptr(new JaegerRecordable); -} - -sdk_common::ExportResult JaegerExporter::Export( - const nostd::span> &spans) noexcept -{ - if (isShutdown()) - { - OTEL_INTERNAL_LOG_ERROR("[Jaeger Trace Exporter] Exporting " - << spans.size() << " span(s) failed, exporter is shutdown"); - return sdk_common::ExportResult::kFailure; - } - - std::size_t exported_size = 0; - - for (auto &recordable : spans) - { - auto rec = - std::unique_ptr(static_cast(recordable.release())); - if (rec != nullptr) - { - exported_size += sender_->Append(std::move(rec)); - } - } - - exported_size += sender_->Flush(); - - if (exported_size == 0) - { - return sdk_common::ExportResult::kFailure; - } - - return sdk_common::ExportResult::kSuccess; -} - -void JaegerExporter::InitializeEndpoint() -{ - if (options_.transport_format == TransportFormat::kThriftUdpCompact) - { - // TODO: do we need support any authentication mechanism? - auto transport = std::unique_ptr( - static_cast(new UDPTransport(options_.endpoint, options_.server_port))); - sender_ = std::unique_ptr(new ThriftSender(std::move(transport))); - return; - } - - if (options_.transport_format == TransportFormat::kThriftHttp) - { - auto transport = - std::unique_ptr(new HttpTransport(options_.endpoint, options_.headers)); - sender_ = std::unique_ptr(new ThriftSender(std::move(transport))); - return; - } - - // The transport format is not implemented. - assert(false); -} - -bool JaegerExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept -{ - return true; -} - -bool JaegerExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept -{ - const std::lock_guard locked(lock_); - is_shutdown_ = true; - return true; -} - -bool JaegerExporter::isShutdown() const noexcept -{ - const std::lock_guard locked(lock_); - return is_shutdown_; -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/jaeger_exporter_factory.cc b/exporters/jaeger/src/jaeger_exporter_factory.cc deleted file mode 100644 index 5eae137cff..0000000000 --- a/exporters/jaeger/src/jaeger_exporter_factory.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -std::unique_ptr JaegerExporterFactory::Create() -{ - JaegerExporterOptions options; - return Create(options); -} - -std::unique_ptr JaegerExporterFactory::Create( - const JaegerExporterOptions &options) -{ - std::unique_ptr exporter(new JaegerExporter(options)); - return exporter; -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc deleted file mode 100644 index 1fd7e99dff..0000000000 --- a/exporters/jaeger/src/recordable.cc +++ /dev/null @@ -1,366 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "opentelemetry/exporters/jaeger/recordable.h" -#include "opentelemetry/sdk/common/global_log_handler.h" -#include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/resource/semantic_conventions.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using namespace opentelemetry::sdk::resource; -namespace trace_api = opentelemetry::trace; - -JaegerRecordable::JaegerRecordable() : span_{new thrift::Span} {} - -void JaegerRecordable::PopulateAttribute(nostd::string_view key, - const common::AttributeValue &value, - std::vector &tags) -{ - if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, int64_t{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, int64_t{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, std::string{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, std::string{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, val, tags); - } - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, int64_t{val}, tags); - } - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, val, tags); - } - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, int64_t{val}, tags); - } - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, val, tags); - } - } - else if (nostd::holds_alternative>(value)) - { - for (const auto &val : nostd::get>(value)) - { - AddTag(std::string{key}, std::string{val}, tags); - } - } - else - { - OTEL_INTERNAL_LOG_ERROR( - "[TRACE JAEGER Exporter] SetAttribute() failed, attribute type not supported "); - } -} - -void JaegerRecordable::PopulateAttribute(nostd::string_view key, - const sdk::common::OwnedAttributeValue &value, - std::vector &tags) -{ - if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, int64_t{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, int64_t{nostd::get(value)}, tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, nostd::get(value), tags); - } - else if (nostd::holds_alternative(value)) - { - AddTag(std::string{key}, std::string{nostd::get(value)}, tags); - } - else - { - OTEL_INTERNAL_LOG_ERROR( - "[TRACE JAEGER Exporter] SetAttribute() failed, attribute type not supported "); - } -} - -void JaegerRecordable::SetIdentity(const trace::SpanContext &span_context, - trace::SpanId parent_span_id) noexcept -{ - // IDs should be converted to big endian before transmission. - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#ids -#if JAEGER_IS_LITTLE_ENDIAN == 1 - span_->__set_traceIdHigh( - otel_bswap_64(*(reinterpret_cast(span_context.trace_id().Id().data())))); - span_->__set_traceIdLow( - otel_bswap_64(*(reinterpret_cast(span_context.trace_id().Id().data()) + 1))); - span_->__set_spanId( - otel_bswap_64(*(reinterpret_cast(span_context.span_id().Id().data())))); - span_->__set_parentSpanId( - otel_bswap_64(*(reinterpret_cast(parent_span_id.Id().data())))); -#else - span_->__set_traceIdLow( - *(reinterpret_cast(span_context.trace_id().Id().data()))); - span_->__set_traceIdHigh( - *(reinterpret_cast(span_context.trace_id().Id().data()) + 1)); - span_->__set_spanId(*(reinterpret_cast(span_context.span_id().Id().data()))); - span_->__set_parentSpanId(*(reinterpret_cast(parent_span_id.Id().data()))); -#endif - - // TODO: set trace_state. -} - -void JaegerRecordable::SetAttribute(nostd::string_view key, - const common::AttributeValue &value) noexcept -{ - PopulateAttribute(key, value, tags_); -} - -void JaegerRecordable::AddEvent(nostd::string_view name, - common::SystemTimestamp timestamp, - const common::KeyValueIterable &attributes) noexcept -{ - std::vector tags; - PopulateAttribute("event", static_cast(name.data()), tags); - - attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { - PopulateAttribute(key, value, tags); - return true; - }); - thrift::Log log; - log.__set_fields(tags); - log.__set_timestamp( - std::chrono::duration_cast(timestamp.time_since_epoch()).count()); - logs_.push_back(log); -} - -void JaegerRecordable::SetInstrumentationScope( - const opentelemetry::sdk::instrumentationscope::InstrumentationScope - &instrumentation_scope) noexcept -{ - AddTag("otel.library.name", instrumentation_scope.GetName(), tags_); - AddTag("otel.library.version", instrumentation_scope.GetVersion(), tags_); -} - -void JaegerRecordable::AddLink(const trace::SpanContext &span_context, - const common::KeyValueIterable & /* attributes */) noexcept -{ - // Note: "The Link’s attributes cannot be represented in Jaeger explicitly." - // -- https://opentelemetry.io/docs/reference/specification/trace/sdk_exporters/jaeger/#links - // - // This implementation does not (currently) implement the optional conversion to span logs. - - thrift::SpanRef reference; - - reference.__set_refType(thrift::SpanRefType::FOLLOWS_FROM); - - // IDs should be converted to big endian before transmission. - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#ids -#if JAEGER_IS_LITTLE_ENDIAN == 1 - reference.__set_traceIdHigh( - otel_bswap_64(*(reinterpret_cast(span_context.trace_id().Id().data())))); - reference.__set_traceIdLow( - otel_bswap_64(*(reinterpret_cast(span_context.trace_id().Id().data()) + 1))); - reference.__set_spanId( - otel_bswap_64(*(reinterpret_cast(span_context.span_id().Id().data())))); -#else - reference.__set_traceIdLow( - *(reinterpret_cast(span_context.trace_id().Id().data()))); - reference.__set_traceIdHigh( - *(reinterpret_cast(span_context.trace_id().Id().data()) + 1)); - reference.__set_spanId(*(reinterpret_cast(span_context.span_id().Id().data()))); -#endif - - references_.push_back(reference); -} - -void JaegerRecordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept -{ - if (code == trace::StatusCode::kUnset) - { - return; - } - - if (code == trace::StatusCode::kOk) - { - AddTag("otel.status_code", "OK", tags_); - } - else if (code == trace::StatusCode::kError) - { - AddTag("otel.status_code", "ERROR", tags_); - AddTag("error", true, tags_); - } - - AddTag("otel.status_description", std::string{description}, tags_); -} - -void JaegerRecordable::SetName(nostd::string_view name) noexcept -{ - span_->__set_operationName(static_cast(name)); -} - -void JaegerRecordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept -{ - for (const auto &attribute_iter : resource.GetAttributes()) - { - if (attribute_iter.first != "service.name") - { - PopulateAttribute(nostd::string_view{attribute_iter.first}, attribute_iter.second, - resource_tags_); - } - else - { - service_name_ = nostd::get(attribute_iter.second); - } - } -} - -void JaegerRecordable::SetStartTime(common::SystemTimestamp start_time) noexcept -{ - span_->__set_startTime( - std::chrono::duration_cast(start_time.time_since_epoch()).count()); -} - -void JaegerRecordable::SetDuration(std::chrono::nanoseconds duration) noexcept -{ - span_->__set_duration(std::chrono::duration_cast(duration).count()); -} - -void JaegerRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept -{ - const char *span_kind_str = nullptr; - - // map SpanKind to Jaeger tag span.kind. - switch (span_kind) - { - case trace_api::SpanKind::kClient: { - span_kind_str = "client"; - break; - } - case trace_api::SpanKind::kServer: { - span_kind_str = "server"; - break; - } - case trace_api::SpanKind::kConsumer: { - span_kind_str = "consumer"; - break; - } - case trace_api::SpanKind::kProducer: { - span_kind_str = "producer"; - break; - } - default: - break; - } - - if (span_kind_str != nullptr) - { - AddTag("span.kind", span_kind_str, tags_); - } -} - -void JaegerRecordable::AddTag(const std::string &key, - const std::string &value, - std::vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(thrift::TagType::STRING); - tag.__set_vStr(value); - - tags.push_back(tag); -} - -void JaegerRecordable::AddTag(const std::string &key, - const char *value, - std::vector &tags) -{ - AddTag(key, std::string{value}, tags); -} - -void JaegerRecordable::AddTag(const std::string &key, bool value, std::vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(thrift::TagType::BOOL); - tag.__set_vBool(value); - - tags.push_back(tag); -} - -void JaegerRecordable::AddTag(const std::string &key, int64_t value, std::vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(thrift::TagType::LONG); - tag.__set_vLong(value); - - tags.push_back(tag); -} - -void JaegerRecordable::AddTag(const std::string &key, double value, std::vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(thrift::TagType::DOUBLE); - tag.__set_vDouble(value); - - tags.push_back(tag); -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/sender.h b/exporters/jaeger/src/sender.h deleted file mode 100644 index f4827b5502..0000000000 --- a/exporters/jaeger/src/sender.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using namespace jaegertracing; - -class Sender -{ -public: - Sender() = default; - virtual ~Sender() = default; - - virtual int Append(std::unique_ptr &&span) = 0; - - virtual int Flush() = 0; - - virtual void Close() = 0; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/thrift_sender.cc b/exporters/jaeger/src/thrift_sender.cc deleted file mode 100644 index 46f0dcd5aa..0000000000 --- a/exporters/jaeger/src/thrift_sender.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "thrift_sender.h" -#include -#include "opentelemetry/sdk/common/global_log_handler.h" -#include "udp_transport.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using namespace jaegertracing; - -ThriftSender::ThriftSender(std::unique_ptr &&transport) - : transport_(std::move(transport)), - protocol_factory_(new apache::thrift::protocol::TCompactProtocolFactory()), - thrift_buffer_(new apache::thrift::transport::TMemoryBuffer(transport_->MaxPacketSize())) -{} - -int ThriftSender::Append(std::unique_ptr &&span) noexcept -{ - if (span == nullptr) - { - return 0; - } - - uint32_t max_span_bytes = transport_->MaxPacketSize() - kEmitBatchOverhead; - if (process_.serviceName.empty()) - { - process_.serviceName = span->ServiceName(); - process_.__set_tags(span->ResourceTags()); - - process_bytes_size_ = CalcSizeOfSerializedThrift(process_); - max_span_bytes -= process_bytes_size_; - } - - auto jaeger_span = std::unique_ptr(span->Span()); - jaeger_span->__set_tags(span->Tags()); - jaeger_span->__set_logs(span->Logs()); - jaeger_span->__set_references(span->References()); - - const uint32_t span_size = CalcSizeOfSerializedThrift(*jaeger_span); - if (span_size > max_span_bytes) - { - OTEL_INTERNAL_LOG_ERROR("[JAEGER TRACE Exporter] Append() failed: too large span"); - return 0; - } - - byte_buffer_size_ += span_size; - if (byte_buffer_size_ <= max_span_bytes) - { - span_buffer_.push_back(*jaeger_span); - if (byte_buffer_size_ < max_span_bytes) - { - return 0; - } - else - { - // byte buffer is full so flush it before appending new span. - return Flush(); - } - } - - const auto flushed = Flush(); - span_buffer_.push_back(*jaeger_span); - byte_buffer_size_ = span_size + process_bytes_size_; - - return flushed; -} - -int ThriftSender::Flush() -{ - if (span_buffer_.empty()) - { - return 0; - } - - thrift::Batch batch; - batch.__set_process(process_); - batch.__set_spans(span_buffer_); - - int spans_flushed = transport_->EmitBatch(batch); - - ResetBuffers(); - - return spans_flushed; -} - -void ThriftSender::Close() -{ - Flush(); -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/thrift_sender.h b/exporters/jaeger/src/thrift_sender.h deleted file mode 100644 index 687f6fac45..0000000000 --- a/exporters/jaeger/src/thrift_sender.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include - -#include - -#include -#include -#include -#include - -#include -#include - -#include "sender.h" -#include "transport.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using namespace jaegertracing; - -class ThriftSender : public Sender -{ -public: - static constexpr uint32_t kEmitBatchOverhead = 30; - - ThriftSender(std::unique_ptr &&transport); - ~ThriftSender() override { Close(); } - - int Append(std::unique_ptr &&span) noexcept override; - int Flush() override; - void Close() override; - -private: - void ResetBuffers() - { - span_buffer_.clear(); - byte_buffer_size_ = process_bytes_size_; - } - - template - uint32_t CalcSizeOfSerializedThrift(const ThriftType &base) - { - uint8_t *data = nullptr; - uint32_t size = 0; - - thrift_buffer_->resetBuffer(); - auto protocol = protocol_factory_->getProtocol(thrift_buffer_); - base.write(protocol.get()); - thrift_buffer_->getBuffer(&data, &size); - return size; - } - -private: - std::vector> spans_; - std::vector span_buffer_; - std::unique_ptr transport_; - std::unique_ptr protocol_factory_; - std::shared_ptr thrift_buffer_; - thrift::Process process_; - - // Size in bytes of the serialization buffer. - uint32_t byte_buffer_size_ = 0; - uint32_t process_bytes_size_ = 0; - uint32_t max_span_bytes_ = 0; - friend class MockThriftSender; - -protected: - ThriftSender() = default; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/transport.h b/exporters/jaeger/src/transport.h deleted file mode 100644 index d7ba8fa604..0000000000 --- a/exporters/jaeger/src/transport.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include - -#include - -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using namespace jaegertracing; - -class Transport -{ -public: - Transport() = default; - virtual ~Transport() = default; - - virtual int EmitBatch(const thrift::Batch &batch) = 0; - virtual uint32_t MaxPacketSize() const = 0; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/udp_transport.cc b/exporters/jaeger/src/udp_transport.cc deleted file mode 100644 index 9b1fe0cafb..0000000000 --- a/exporters/jaeger/src/udp_transport.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include // std::stringstream - -#include "opentelemetry/sdk_config.h" -#include "udp_transport.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -UDPTransport::UDPTransport(const std::string &addr, uint16_t port) - : max_packet_size_(kUDPPacketMaxLength) -{ - InitSocket(); - - endpoint_transport_ = std::shared_ptr(new TUDPTransport(addr, port)); - endpoint_transport_->open(); - transport_ = - std::shared_ptr(new TBufferedTransport(endpoint_transport_, max_packet_size_)); - protocol_ = std::shared_ptr(new TCompactProtocol(transport_)); - agent_ = std::unique_ptr(new AgentClient(protocol_)); -} - -UDPTransport::~UDPTransport() -{ - CleanSocket(); -} - -void UDPTransport::InitSocket() -{ -#if defined(_WIN32) - /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ - WORD wVersionRequested = MAKEWORD(2, 2); - - WSADATA wsaData; - int err = WSAStartup(wVersionRequested, &wsaData); - if (err != 0) - { - OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: WSAStartup failed with error: " << err); - return; - } - - /* Confirm that the WinSock DLL supports 2.2. */ - /* Note that if the DLL supports versions greater */ - /* than 2.2 in addition to 2.2, it will still return */ - /* 2.2 in wVersion since that is the version we */ - /* requested. */ - - if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) - { - OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: winsock " << LOBYTE(wsaData.wVersion) << "." - << HIBYTE(wsaData.wVersion) - << " is not supported."); - WSACleanup(); - - return; - } -#endif -} - -void UDPTransport::CleanSocket() -{ -#if defined(_WIN32) - WSACleanup(); -#endif -} - -int UDPTransport::EmitBatch(const thrift::Batch &batch) -{ - try - { - agent_->emitBatch(batch); - } - catch (...) - {} - - return static_cast(batch.spans.size()); -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/src/udp_transport.h b/exporters/jaeger/src/udp_transport.h deleted file mode 100644 index ce1f51e647..0000000000 --- a/exporters/jaeger/src/udp_transport.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "TUDPTransport.h" -#include "transport.h" - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -using AgentClient = jaegertracing::agent::thrift::AgentClient; -using TBinaryProtocol = apache::thrift::protocol::TBinaryProtocol; -using TCompactProtocol = apache::thrift::protocol::TCompactProtocol; -using TBufferedTransport = apache::thrift::transport::TBufferedTransport; -using TProtocol = apache::thrift::protocol::TProtocol; -using TTransport = apache::thrift::transport::TTransport; - -class UDPTransport : public Transport -{ -public: - static constexpr auto kUDPPacketMaxLength = 65000; - - UDPTransport(const std::string &addr, uint16_t port); - ~UDPTransport() override; - - int EmitBatch(const thrift::Batch &batch) override; - - uint32_t MaxPacketSize() const override { return max_packet_size_; } - - void InitSocket(); - void CleanSocket(); - -private: - std::unique_ptr agent_; - std::shared_ptr endpoint_transport_; - std::shared_ptr transport_; - std::shared_ptr protocol_; - uint32_t max_packet_size_; -}; - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/test/jaeger_exporter_test.cc b/exporters/jaeger/test/jaeger_exporter_test.cc deleted file mode 100644 index ea305267c5..0000000000 --- a/exporters/jaeger/test/jaeger_exporter_test.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "opentelemetry/exporters/jaeger/jaeger_exporter.h" -#include "opentelemetry/sdk/trace/batch_span_processor.h" -#include "opentelemetry/sdk/trace/batch_span_processor_options.h" -#include "opentelemetry/sdk/trace/tracer.h" -#include "opentelemetry/sdk/trace/tracer_provider.h" -#include "opentelemetry/trace/span_startoptions.h" - -#ifdef BAZEL_BUILD -# include "exporters/jaeger/src/thrift_sender.h" -#else -# include "thrift_sender.h" -#endif - -#include -#include "gmock/gmock.h" - -#include -#include - -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace common = opentelemetry::common; -namespace sdk_common = opentelemetry::sdk::common; - -using namespace testing; - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace jaeger -{ - -namespace trace_api = opentelemetry::trace; -namespace resource = opentelemetry::sdk::resource; - -template -static nostd::span MakeSpan(T (&array)[N]) -{ - return nostd::span(array); -} - -class JaegerExporterTestPeer : public ::testing::Test -{ -public: - std::unique_ptr GetExporter(std::unique_ptr sender) - { - return std::unique_ptr(new JaegerExporter(std::move(sender))); - } - - // Get the options associated with the given exporter. - const JaegerExporterOptions &GetOptions(std::unique_ptr &exporter) - { - return exporter->options_; - } -}; - -class MockThriftSender : public ThriftSender -{ -public: - MOCK_METHOD(int, Append, (std::unique_ptr &&), (noexcept, override)); -}; - -class MockTransport : public Transport -{ -public: - MOCK_METHOD(int, EmitBatch, (const thrift::Batch &), (override)); - MOCK_METHOD(uint32_t, MaxPacketSize, (), (const, override)); -}; - -// Create spans, let processor call Export() -TEST_F(JaegerExporterTestPeer, ExportIntegrationTest) -{ - auto mock_transport = new MockTransport; - auto mock_thrift_sender = new ThriftSender(std::unique_ptr{mock_transport}); - auto exporter = GetExporter(std::unique_ptr{mock_thrift_sender}); - - resource::ResourceAttributes resource_attributes = {{"service.name", "unit_test_service"}, - {"tenant.id", "test_user"}}; - resource_attributes["bool_value"] = true; - resource_attributes["int32_value"] = static_cast(1); - resource_attributes["uint32_value"] = static_cast(2); - resource_attributes["int64_value"] = static_cast(0x1100000000LL); - resource_attributes["double_value"] = static_cast(3.1); - auto resource = resource::Resource::Create(resource_attributes); - - auto processor_opts = sdk::trace::BatchSpanProcessorOptions(); - processor_opts.max_export_batch_size = 5; - processor_opts.max_queue_size = 5; - processor_opts.schedule_delay_millis = std::chrono::milliseconds(256); - auto processor = std::unique_ptr( - new sdk::trace::BatchSpanProcessor(std::move(exporter), processor_opts)); - auto provider = nostd::shared_ptr( - new sdk::trace::TracerProvider(std::move(processor), resource)); - - EXPECT_CALL(*mock_transport, EmitBatch(_)).Times(Exactly(1)).WillOnce(Return(1)); - - auto tracer = provider->GetTracer("test"); - auto parent_span = tracer->StartSpan("Test parent span"); - - trace_api::StartSpanOptions child_span_opts = {}; - child_span_opts.parent = parent_span->GetContext(); - auto child_span = tracer->StartSpan("Test child span", child_span_opts); - - child_span->End(); - parent_span->End(); - - auto parent_ctx = parent_span->GetContext(); - auto child_ctx = child_span->GetContext(); - EXPECT_EQ(parent_ctx.trace_id(), child_ctx.trace_id()); - EXPECT_EQ(parent_ctx.trace_state(), child_ctx.trace_state()); - ASSERT_TRUE(parent_ctx.IsValid()); - ASSERT_TRUE(child_ctx.IsValid()); -} - -TEST_F(JaegerExporterTestPeer, ShutdownTest) -{ - auto mock_thrift_sender = new MockThriftSender; - auto exporter = GetExporter(std::unique_ptr{mock_thrift_sender}); - - auto recordable_1 = exporter->MakeRecordable(); - recordable_1->SetName("Test span 1"); - auto recordable_2 = exporter->MakeRecordable(); - recordable_2->SetName("Test span 2"); - - // exporter shuold not be shutdown by default - nostd::span> batch_1(&recordable_1, 1); - EXPECT_CALL(*mock_thrift_sender, Append(_)).Times(Exactly(1)).WillOnce(Return(1)); - auto result = exporter->Export(batch_1); - EXPECT_EQ(sdk_common::ExportResult::kSuccess, result); - - exporter->Shutdown(); - - nostd::span> batch_2(&recordable_2, 1); - result = exporter->Export(batch_2); - EXPECT_EQ(sdk_common::ExportResult::kFailure, result); -} - -// Call Export() directly -TEST_F(JaegerExporterTestPeer, ExportTest) -{ - auto mock_thrift_sender = new MockThriftSender; - auto exporter = GetExporter(std::unique_ptr{mock_thrift_sender}); - - auto recordable_1 = exporter->MakeRecordable(); - recordable_1->SetName("Test span 1"); - auto recordable_2 = exporter->MakeRecordable(); - recordable_2->SetName("Test span 2"); - - // Test successful send - nostd::span> batch_1(&recordable_1, 1); - EXPECT_CALL(*mock_thrift_sender, Append(_)).Times(Exactly(1)).WillOnce(Return(1)); - auto result = exporter->Export(batch_1); - EXPECT_EQ(sdk_common::ExportResult::kSuccess, result); - - // Test failed send - nostd::span> batch_2(&recordable_2, 1); - EXPECT_CALL(*mock_thrift_sender, Append(_)).Times(Exactly(1)).WillOnce(Return(0)); - result = exporter->Export(batch_2); - EXPECT_EQ(sdk::common::ExportResult::kFailure, result); -} - -// Test exporter configuration options -TEST_F(JaegerExporterTestPeer, ConfigTest) -{ - JaegerExporterOptions opts; - opts.endpoint = "localhost"; - opts.server_port = 6851; - std::unique_ptr exporter(new JaegerExporter(opts)); - EXPECT_EQ(GetOptions(exporter).endpoint, "localhost"); - EXPECT_EQ(GetOptions(exporter).server_port, 6851); -} - -} // namespace jaeger -} // namespace exporter -OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/jaeger/test/jaeger_recordable_test.cc b/exporters/jaeger/test/jaeger_recordable_test.cc deleted file mode 100644 index bcfbd35032..0000000000 --- a/exporters/jaeger/test/jaeger_recordable_test.cc +++ /dev/null @@ -1,334 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include -#include "opentelemetry/exporters/jaeger/recordable.h" -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -#include "opentelemetry/sdk/trace/simple_processor.h" -#include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/sdk/trace/tracer_provider.h" -#include "opentelemetry/trace/provider.h" - -#include - -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace common = opentelemetry::common; - -using namespace jaegertracing; -using namespace opentelemetry::exporter::jaeger; -using namespace opentelemetry::sdk::instrumentationscope; -using std::vector; - -using Attributes = std::initializer_list>; - -TEST(JaegerSpanRecordable, SetIdentity) -{ - JaegerRecordable rec; - - int64_t trace_id_val[2] = {0x0000000000000000, 0x1000000000000000}; - int64_t span_id_val = 0x2000000000000000; - int64_t parent_span_id_val = 0x3000000000000000; - - const trace::TraceId trace_id{ - nostd::span(reinterpret_cast(trace_id_val), 16)}; - - const trace::SpanId span_id( - nostd::span(reinterpret_cast(&span_id_val), 8)); - - const trace::SpanId parent_span_id( - nostd::span(reinterpret_cast(&parent_span_id_val), 8)); - - const trace::SpanContext span_context{trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; - rec.SetIdentity(span_context, parent_span_id); - - std::unique_ptr span{rec.Span()}; - -#if JAEGER_IS_LITTLE_ENDIAN == 1 - EXPECT_EQ(span->traceIdLow, otel_bswap_64(trace_id_val[1])); - EXPECT_EQ(span->traceIdHigh, otel_bswap_64(trace_id_val[0])); - EXPECT_EQ(span->spanId, otel_bswap_64(span_id_val)); - EXPECT_EQ(span->parentSpanId, otel_bswap_64(parent_span_id_val)); -#else - EXPECT_EQ(span->traceIdLow, trace_id_val[0]); - EXPECT_EQ(span->traceIdHigh, trace_id_val[1]); - EXPECT_EQ(span->spanId, span_id_val); - EXPECT_EQ(span->parentSpanId, parent_span_id_val); -#endif -} - -TEST(JaegerSpanRecordable, SetName) -{ - JaegerRecordable rec; - - nostd::string_view name = "Test Span"; - rec.SetName(name); - - std::unique_ptr span{rec.Span()}; - - EXPECT_EQ(span->operationName, name); -} - -TEST(JaegerSpanRecordable, SetStartTime) -{ - JaegerRecordable rec; - - std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); - common::SystemTimestamp start_timestamp(start_time); - uint64_t unix_start = - std::chrono::duration_cast(start_time.time_since_epoch()).count(); - rec.SetStartTime(start_timestamp); - - std::unique_ptr span{rec.Span()}; - - EXPECT_EQ(span->startTime, unix_start); -} - -TEST(JaegerSpanRecordable, SetDuration) -{ - JaegerRecordable rec; - - common::SystemTimestamp start_timestamp; - - std::chrono::microseconds duration(10); - uint64_t unix_end = duration.count(); - - rec.SetStartTime(start_timestamp); - rec.SetDuration(duration); - - std::unique_ptr span{rec.Span()}; - - EXPECT_EQ(span->startTime, 0); - EXPECT_EQ(span->duration, unix_end); -} - -TEST(JaegerSpanRecordable, SetStatus) -{ - JaegerRecordable rec; - - const char *error_description = "Error test"; - rec.SetStatus(trace::StatusCode::kError, error_description); - - auto tags = rec.Tags(); - EXPECT_EQ(tags.size(), 3); - - EXPECT_EQ(tags[0].key, "otel.status_code"); - EXPECT_EQ(tags[0].vType, thrift::TagType::STRING); - EXPECT_EQ(tags[0].vStr, "ERROR"); - - EXPECT_EQ(tags[1].key, "error"); - EXPECT_EQ(tags[1].vType, thrift::TagType::BOOL); - EXPECT_EQ(tags[1].vBool, true); - - EXPECT_EQ(tags[2].key, "otel.status_description"); - EXPECT_EQ(tags[2].vType, thrift::TagType::STRING); - EXPECT_EQ(tags[2].vStr, error_description); -} - -TEST(JaegerSpanRecordable, AddEvent) -{ - JaegerRecordable rec; - - std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); - common::SystemTimestamp event_timestamp(event_time); - uint64_t epoch_us = - std::chrono::duration_cast(event_time.time_since_epoch()).count(); - - const int kNumAttributes = 3; - std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3"}; - int64_t values[kNumAttributes] = {4, 7, 23}; - std::map attributes = { - {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; - - rec.AddEvent("Test Event", event_timestamp, - common::KeyValueIterableView>(attributes)); - thrift::Log log = rec.Logs().at(0); - EXPECT_EQ(log.timestamp, epoch_us); - auto tags = log.fields; - size_t index = 0; - EXPECT_EQ(tags[index].key, "event"); - EXPECT_EQ(tags[index++].vStr, "Test Event"); - while (index <= kNumAttributes) - { - EXPECT_EQ(tags[index].key, keys[index - 1]); - EXPECT_EQ(tags[index].vLong, values[index - 1]); - index++; - } -} - -template -void addTag(thrift::TagType::type tag_type, - const std::string &key, - value_type value, - vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(tag_type); - if (tag_type == thrift::TagType::LONG) - { - tag.__set_vLong(static_cast(value)); - } - else if (tag_type == thrift::TagType::DOUBLE) - { - tag.__set_vDouble(static_cast(value)); - } - else if (tag_type == thrift::TagType::BOOL) - { - tag.__set_vBool(static_cast(value)); - } - - tags.push_back(tag); -} - -void addTag(const std::string &key, std::string value, vector &tags) -{ - thrift::Tag tag; - - tag.__set_key(key); - tag.__set_vType(thrift::TagType::STRING); - tag.__set_vStr(value); - - tags.push_back(tag); -} - -TEST(JaegerSpanRecordable, SetAttributes) -{ - JaegerRecordable rec; - std::string string_val{"string_val"}; - vector values{ - bool{false}, - int32_t{-32}, - int64_t{-64}, - uint32_t{32}, - double{3.14}, - string_val.c_str(), - nostd::string_view{"string_view"}, - }; - for (const auto &val : values) - { - rec.SetAttribute("key1", val); - } - rec.SetAttribute("key2", nostd::span{{false, true}}); - rec.SetAttribute("key3", nostd::span{{-320, 320}}); - rec.SetAttribute("key4", nostd::span{{-640, 640}}); - rec.SetAttribute("key5", nostd::span{{320, 322}}); - rec.SetAttribute("key6", nostd::span{{4.15, 5.15}}); - rec.SetAttribute("key7", nostd::span{{"string_v1", "string_v2"}}); - - auto tags = rec.Tags(); - EXPECT_EQ(tags.size(), values.size() + 12); - - vector expected_tags; - addTag(thrift::TagType::BOOL, "key1", bool{false}, expected_tags); - addTag(thrift::TagType::LONG, "key1", int32_t{-32}, expected_tags); - addTag(thrift::TagType::LONG, "key1", int64_t{-64}, expected_tags); - addTag(thrift::TagType::LONG, "key1", int32_t{32}, expected_tags); - addTag(thrift::TagType::DOUBLE, "key1", double{3.14}, expected_tags); - addTag("key1", string_val, expected_tags); - addTag("key1", std::string{"string_view"}, expected_tags); - - addTag(thrift::TagType::BOOL, "key2", bool{false}, expected_tags); - addTag(thrift::TagType::BOOL, "key2", bool{true}, expected_tags); - addTag(thrift::TagType::LONG, "key3", int32_t{-320}, expected_tags); - addTag(thrift::TagType::LONG, "key3", int32_t{320}, expected_tags); - addTag(thrift::TagType::LONG, "key4", int64_t{-640}, expected_tags); - addTag(thrift::TagType::LONG, "key4", int64_t{640}, expected_tags); - addTag(thrift::TagType::LONG, "key5", uint32_t{320}, expected_tags); - addTag(thrift::TagType::LONG, "key5", uint32_t{322}, expected_tags); - addTag(thrift::TagType::DOUBLE, "key6", double{4.15}, expected_tags); - addTag(thrift::TagType::DOUBLE, "key6", double{5.15}, expected_tags); - addTag("key7", std::string{"string_v1"}, expected_tags); - addTag("key7", std::string{"string_v2"}, expected_tags); - - EXPECT_EQ(tags, expected_tags); -} - -TEST(JaegerSpanRecordable, SetInstrumentationScope) -{ - JaegerRecordable rec; - - std::string library_name = "opentelemetry-cpp"; - std::string library_version = "0.1.0"; - auto instrumentation_scope = InstrumentationScope::Create(library_name, library_version); - - rec.SetInstrumentationScope(*instrumentation_scope); - - auto tags = rec.Tags(); - EXPECT_EQ(tags.size(), 2); - - EXPECT_EQ(tags[0].key, "otel.library.name"); - EXPECT_EQ(tags[0].vType, thrift::TagType::STRING); - EXPECT_EQ(tags[0].vStr, library_name); - - EXPECT_EQ(tags[1].key, "otel.library.version"); - EXPECT_EQ(tags[1].vType, thrift::TagType::STRING); - EXPECT_EQ(tags[1].vStr, library_version); -} - -TEST(JaegerSpanRecordable, SetResource) -{ - JaegerRecordable rec; - - const std::string service_name_key = "service.name"; - std::string service_name_value = "test-jaeger-service-name"; - auto resource = opentelemetry::sdk::resource::Resource::Create( - {{service_name_key, service_name_value}, {"key1", "value1"}, {"key2", "value2"}}); - rec.SetResource(resource); - - auto service_name = rec.ServiceName(); - auto resource_tags = rec.ResourceTags(); - - EXPECT_GE(resource_tags.size(), 2); - EXPECT_EQ(service_name, service_name_value); - - for (const auto &tag : resource_tags) - { - if (tag.key == "key1") - { - EXPECT_EQ(tag.vType, thrift::TagType::STRING); - EXPECT_EQ(tag.vStr, "value1"); - } - else if (tag.key == "key2") - { - EXPECT_EQ(tag.vType, thrift::TagType::STRING); - EXPECT_EQ(tag.vStr, "value2"); - } - } -} - -TEST(JaegerSpanRecordable, AddLink) -{ - JaegerRecordable rec; - - int64_t trace_id_val[2] = {0x0000000000000000, 0x1000000000000000}; - int64_t span_id_val = 0x2000000000000000; - - const trace::TraceId trace_id{ - nostd::span(reinterpret_cast(trace_id_val), 16)}; - - const trace::SpanId span_id( - nostd::span(reinterpret_cast(&span_id_val), 8)); - - const trace::SpanContext span_context{trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; - rec.AddLink(span_context, common::KeyValueIterableView({{"attr1", "string"}})); - - auto references = rec.References(); - EXPECT_EQ(references.size(), 1); - - auto reference = references.front(); - -#if JAEGER_IS_LITTLE_ENDIAN == 1 - EXPECT_EQ(reference.traceIdLow, otel_bswap_64(trace_id_val[1])); - EXPECT_EQ(reference.traceIdHigh, otel_bswap_64(trace_id_val[0])); - EXPECT_EQ(reference.spanId, otel_bswap_64(span_id_val)); -#else - EXPECT_EQ(reference.traceIdLow, trace_id_val[0]); - EXPECT_EQ(reference.traceIdHigh, trace_id_val[1]); - EXPECT_EQ(reference.spanId, span_id_val); -#endif -} diff --git a/exporters/jaeger/thrift-gen/Agent.cpp b/exporters/jaeger/thrift-gen/Agent.cpp deleted file mode 100644 index 4ff0236501..0000000000 --- a/exporters/jaeger/thrift-gen/Agent.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "Agent.h" - -namespace jaegertracing { namespace agent { namespace thrift { - - -Agent_emitZipkinBatch_args::~Agent_emitZipkinBatch_args() noexcept { -} - - -uint32_t Agent_emitZipkinBatch_args::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->spans.clear(); - uint32_t _size0; - ::apache::thrift::protocol::TType _etype3; - xfer += iprot->readListBegin(_etype3, _size0); - this->spans.resize(_size0); - uint32_t _i4; - for (_i4 = 0; _i4 < _size0; ++_i4) - { - xfer += this->spans[_i4].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.spans = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Agent_emitZipkinBatch_args::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Agent_emitZipkinBatch_args"); - - xfer += oprot->writeFieldBegin("spans", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->spans.size())); - std::vector< ::twitter::zipkin::thrift::Span> ::const_iterator _iter5; - for (_iter5 = this->spans.begin(); _iter5 != this->spans.end(); ++_iter5) - { - xfer += (*_iter5).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Agent_emitZipkinBatch_pargs::~Agent_emitZipkinBatch_pargs() noexcept { -} - - -uint32_t Agent_emitZipkinBatch_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Agent_emitZipkinBatch_pargs"); - - xfer += oprot->writeFieldBegin("spans", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast((*(this->spans)).size())); - std::vector< ::twitter::zipkin::thrift::Span> ::const_iterator _iter6; - for (_iter6 = (*(this->spans)).begin(); _iter6 != (*(this->spans)).end(); ++_iter6) - { - xfer += (*_iter6).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Agent_emitBatch_args::~Agent_emitBatch_args() noexcept { -} - - -uint32_t Agent_emitBatch_args::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->batch.read(iprot); - this->__isset.batch = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Agent_emitBatch_args::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Agent_emitBatch_args"); - - xfer += oprot->writeFieldBegin("batch", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += this->batch.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Agent_emitBatch_pargs::~Agent_emitBatch_pargs() noexcept { -} - - -uint32_t Agent_emitBatch_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Agent_emitBatch_pargs"); - - xfer += oprot->writeFieldBegin("batch", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += (*(this->batch)).write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void AgentClient::emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) -{ - send_emitZipkinBatch(spans); -} - -void AgentClient::send_emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("emitZipkinBatch", ::apache::thrift::protocol::T_ONEWAY, cseqid); - - Agent_emitZipkinBatch_pargs args; - args.spans = &spans; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); -} - -void AgentClient::emitBatch(const ::jaegertracing::thrift::Batch& batch) -{ - send_emitBatch(batch); -} - -void AgentClient::send_emitBatch(const ::jaegertracing::thrift::Batch& batch) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("emitBatch", ::apache::thrift::protocol::T_ONEWAY, cseqid); - - Agent_emitBatch_pargs args; - args.batch = &batch; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); -} - -bool AgentProcessor::dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext) { - ProcessMap::iterator pfn; - pfn = processMap_.find(fname); - if (pfn == processMap_.end()) { - iprot->skip(::apache::thrift::protocol::T_STRUCT); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - ::apache::thrift::TApplicationException x(::apache::thrift::TApplicationException::UNKNOWN_METHOD, "Invalid method name: '"+fname+"'"); - oprot->writeMessageBegin(fname, ::apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - return true; - } - (this->*(pfn->second))(seqid, iprot, oprot, callContext); - return true; -} - -void AgentProcessor::process_emitZipkinBatch(int32_t, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol*, void* callContext) -{ - void* ctx = nullptr; - if (this->eventHandler_.get() != nullptr) { - ctx = this->eventHandler_->getContext("Agent.emitZipkinBatch", callContext); - } - ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "Agent.emitZipkinBatch"); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preRead(ctx, "Agent.emitZipkinBatch"); - } - - Agent_emitZipkinBatch_args args; - args.read(iprot); - iprot->readMessageEnd(); - uint32_t bytes = iprot->getTransport()->readEnd(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postRead(ctx, "Agent.emitZipkinBatch", bytes); - } - - try { - iface_->emitZipkinBatch(args.spans); - } catch (const std::exception&) { - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->handlerError(ctx, "Agent.emitZipkinBatch"); - } - return; - } - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->asyncComplete(ctx, "Agent.emitZipkinBatch"); - } - - return; -} - -void AgentProcessor::process_emitBatch(int32_t, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol*, void* callContext) -{ - void* ctx = nullptr; - if (this->eventHandler_.get() != nullptr) { - ctx = this->eventHandler_->getContext("Agent.emitBatch", callContext); - } - ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "Agent.emitBatch"); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preRead(ctx, "Agent.emitBatch"); - } - - Agent_emitBatch_args args; - args.read(iprot); - iprot->readMessageEnd(); - uint32_t bytes = iprot->getTransport()->readEnd(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postRead(ctx, "Agent.emitBatch", bytes); - } - - try { - iface_->emitBatch(args.batch); - } catch (const std::exception&) { - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->handlerError(ctx, "Agent.emitBatch"); - } - return; - } - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->asyncComplete(ctx, "Agent.emitBatch"); - } - - return; -} - -::std::shared_ptr< ::apache::thrift::TProcessor > AgentProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) { - ::apache::thrift::ReleaseHandler< AgentIfFactory > cleanup(handlerFactory_); - ::std::shared_ptr< AgentIf > handler(handlerFactory_->getHandler(connInfo), cleanup); - ::std::shared_ptr< ::apache::thrift::TProcessor > processor(new AgentProcessor(handler)); - return processor; -} - -void AgentConcurrentClient::emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) -{ - send_emitZipkinBatch(spans); -} - -void AgentConcurrentClient::send_emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) -{ - int32_t cseqid = 0; - ::apache::thrift::async::TConcurrentSendSentry sentry(this->sync_.get()); - oprot_->writeMessageBegin("emitZipkinBatch", ::apache::thrift::protocol::T_ONEWAY, cseqid); - - Agent_emitZipkinBatch_pargs args; - args.spans = &spans; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); - - sentry.commit(); -} - -void AgentConcurrentClient::emitBatch(const ::jaegertracing::thrift::Batch& batch) -{ - send_emitBatch(batch); -} - -void AgentConcurrentClient::send_emitBatch(const ::jaegertracing::thrift::Batch& batch) -{ - int32_t cseqid = 0; - ::apache::thrift::async::TConcurrentSendSentry sentry(this->sync_.get()); - oprot_->writeMessageBegin("emitBatch", ::apache::thrift::protocol::T_ONEWAY, cseqid); - - Agent_emitBatch_pargs args; - args.batch = &batch; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); - - sentry.commit(); -} - -}}} // namespace - diff --git a/exporters/jaeger/thrift-gen/Agent.h b/exporters/jaeger/thrift-gen/Agent.h deleted file mode 100644 index 49abaf54a9..0000000000 --- a/exporters/jaeger/thrift-gen/Agent.h +++ /dev/null @@ -1,309 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef Agent_H -#define Agent_H - -#include -#include -#include -#include "agent_types.h" - -namespace jaegertracing { namespace agent { namespace thrift { - -#ifdef _MSC_VER - #pragma warning( push ) - #pragma warning (disable : 4250 ) //inheriting methods via dominance -#endif - -class AgentIf { - public: - virtual ~AgentIf() {} - virtual void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) = 0; - virtual void emitBatch(const ::jaegertracing::thrift::Batch& batch) = 0; -}; - -class AgentIfFactory { - public: - typedef AgentIf Handler; - - virtual ~AgentIfFactory() {} - - virtual AgentIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo) = 0; - virtual void releaseHandler(AgentIf* /* handler */) = 0; -}; - -class AgentIfSingletonFactory : virtual public AgentIfFactory { - public: - AgentIfSingletonFactory(const ::std::shared_ptr& iface) : iface_(iface) {} - virtual ~AgentIfSingletonFactory() {} - - virtual AgentIf* getHandler(const ::apache::thrift::TConnectionInfo&) { - return iface_.get(); - } - virtual void releaseHandler(AgentIf* /* handler */) {} - - protected: - ::std::shared_ptr iface_; -}; - -class AgentNull : virtual public AgentIf { - public: - virtual ~AgentNull() {} - void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & /* spans */) { - return; - } - void emitBatch(const ::jaegertracing::thrift::Batch& /* batch */) { - return; - } -}; - -typedef struct _Agent_emitZipkinBatch_args__isset { - _Agent_emitZipkinBatch_args__isset() : spans(false) {} - bool spans :1; -} _Agent_emitZipkinBatch_args__isset; - -class Agent_emitZipkinBatch_args { - public: - - Agent_emitZipkinBatch_args(const Agent_emitZipkinBatch_args&); - Agent_emitZipkinBatch_args& operator=(const Agent_emitZipkinBatch_args&); - Agent_emitZipkinBatch_args() { - } - - virtual ~Agent_emitZipkinBatch_args() noexcept; - std::vector< ::twitter::zipkin::thrift::Span> spans; - - _Agent_emitZipkinBatch_args__isset __isset; - - void __set_spans(const std::vector< ::twitter::zipkin::thrift::Span> & val); - - bool operator == (const Agent_emitZipkinBatch_args & rhs) const - { - if (!(spans == rhs.spans)) - return false; - return true; - } - bool operator != (const Agent_emitZipkinBatch_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Agent_emitZipkinBatch_args & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - - -class Agent_emitZipkinBatch_pargs { - public: - - - virtual ~Agent_emitZipkinBatch_pargs() noexcept; - const std::vector< ::twitter::zipkin::thrift::Span> * spans; - - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -typedef struct _Agent_emitBatch_args__isset { - _Agent_emitBatch_args__isset() : batch(false) {} - bool batch :1; -} _Agent_emitBatch_args__isset; - -class Agent_emitBatch_args { - public: - - Agent_emitBatch_args(const Agent_emitBatch_args&); - Agent_emitBatch_args& operator=(const Agent_emitBatch_args&); - Agent_emitBatch_args() { - } - - virtual ~Agent_emitBatch_args() noexcept; - ::jaegertracing::thrift::Batch batch; - - _Agent_emitBatch_args__isset __isset; - - void __set_batch(const ::jaegertracing::thrift::Batch& val); - - bool operator == (const Agent_emitBatch_args & rhs) const - { - if (!(batch == rhs.batch)) - return false; - return true; - } - bool operator != (const Agent_emitBatch_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Agent_emitBatch_args & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - - -class Agent_emitBatch_pargs { - public: - - - virtual ~Agent_emitBatch_pargs() noexcept; - const ::jaegertracing::thrift::Batch* batch; - - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class AgentClient : virtual public AgentIf { - public: - AgentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot); - } - AgentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans); - void send_emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans); - void emitBatch(const ::jaegertracing::thrift::Batch& batch); - void send_emitBatch(const ::jaegertracing::thrift::Batch& batch); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; -}; - -class AgentProcessor : public ::apache::thrift::TDispatchProcessor { - protected: - ::std::shared_ptr iface_; - virtual bool dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext); - private: - typedef void (AgentProcessor::*ProcessFunction)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*); - typedef std::map ProcessMap; - ProcessMap processMap_; - void process_emitZipkinBatch(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext); - void process_emitBatch(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext); - public: - AgentProcessor(::std::shared_ptr iface) : - iface_(iface) { - processMap_["emitZipkinBatch"] = &AgentProcessor::process_emitZipkinBatch; - processMap_["emitBatch"] = &AgentProcessor::process_emitBatch; - } - - virtual ~AgentProcessor() {} -}; - -class AgentProcessorFactory : public ::apache::thrift::TProcessorFactory { - public: - AgentProcessorFactory(const ::std::shared_ptr< AgentIfFactory >& handlerFactory) : - handlerFactory_(handlerFactory) {} - - ::std::shared_ptr< ::apache::thrift::TProcessor > getProcessor(const ::apache::thrift::TConnectionInfo& connInfo); - - protected: - ::std::shared_ptr< AgentIfFactory > handlerFactory_; -}; - -class AgentMultiface : virtual public AgentIf { - public: - AgentMultiface(std::vector >& ifaces) : ifaces_(ifaces) { - } - virtual ~AgentMultiface() {} - protected: - std::vector > ifaces_; - AgentMultiface() {} - void add(::std::shared_ptr iface) { - ifaces_.push_back(iface); - } - public: - void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) { - size_t sz = ifaces_.size(); - size_t i = 0; - for (; i < (sz - 1); ++i) { - ifaces_[i]->emitZipkinBatch(spans); - } - ifaces_[i]->emitZipkinBatch(spans); - } - - void emitBatch(const ::jaegertracing::thrift::Batch& batch) { - size_t sz = ifaces_.size(); - size_t i = 0; - for (; i < (sz - 1); ++i) { - ifaces_[i]->emitBatch(batch); - } - ifaces_[i]->emitBatch(batch); - } - -}; - -// The 'concurrent' client is a thread safe client that correctly handles -// out of order responses. It is slower than the regular client, so should -// only be used when you need to share a connection among multiple threads -class AgentConcurrentClient : virtual public AgentIf { - public: - AgentConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(prot); - } - AgentConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans); - void send_emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans); - void emitBatch(const ::jaegertracing::thrift::Batch& batch); - void send_emitBatch(const ::jaegertracing::thrift::Batch& batch); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; - std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync_; -}; - -#ifdef _MSC_VER - #pragma warning( pop ) -#endif - -}}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/Agent_server.skeleton.cpp b/exporters/jaeger/thrift-gen/Agent_server.skeleton.cpp deleted file mode 100644 index 60fdd94360..0000000000 --- a/exporters/jaeger/thrift-gen/Agent_server.skeleton.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// This autogenerated skeleton file illustrates how to build a server. -// You should copy it to another filename to avoid overwriting it. - -#include "Agent.h" -#include -#include -#include -#include - -using namespace ::apache::thrift; -using namespace ::apache::thrift::protocol; -using namespace ::apache::thrift::transport; -using namespace ::apache::thrift::server; - -using namespace ::jaegertracing::agent::thrift; - -class AgentHandler : virtual public AgentIf { - public: - AgentHandler() { - // Your initialization goes here - } - - void emitZipkinBatch(const std::vector< ::twitter::zipkin::thrift::Span> & spans) { - // Your implementation goes here - printf("emitZipkinBatch\n"); - } - - void emitBatch(const ::jaegertracing::thrift::Batch& batch) { - // Your implementation goes here - printf("emitBatch\n"); - } - -}; - -int main(int argc, char **argv) { - int port = 9090; - ::std::shared_ptr handler(new AgentHandler()); - ::std::shared_ptr processor(new AgentProcessor(handler)); - ::std::shared_ptr serverTransport(new TServerSocket(port)); - ::std::shared_ptr transportFactory(new TBufferedTransportFactory()); - ::std::shared_ptr protocolFactory(new TBinaryProtocolFactory()); - - TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory); - server.serve(); - return 0; -} - diff --git a/exporters/jaeger/thrift-gen/Collector.cpp b/exporters/jaeger/thrift-gen/Collector.cpp deleted file mode 100644 index f96b40f20a..0000000000 --- a/exporters/jaeger/thrift-gen/Collector.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "Collector.h" - -namespace jaegertracing { namespace thrift { - - -Collector_submitBatches_args::~Collector_submitBatches_args() noexcept { -} - - -uint32_t Collector_submitBatches_args::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->batches.clear(); - uint32_t _size52; - ::apache::thrift::protocol::TType _etype55; - xfer += iprot->readListBegin(_etype55, _size52); - this->batches.resize(_size52); - uint32_t _i56; - for (_i56 = 0; _i56 < _size52; ++_i56) - { - xfer += this->batches[_i56].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.batches = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Collector_submitBatches_args::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Collector_submitBatches_args"); - - xfer += oprot->writeFieldBegin("batches", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->batches.size())); - std::vector ::const_iterator _iter57; - for (_iter57 = this->batches.begin(); _iter57 != this->batches.end(); ++_iter57) - { - xfer += (*_iter57).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Collector_submitBatches_pargs::~Collector_submitBatches_pargs() noexcept { -} - - -uint32_t Collector_submitBatches_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Collector_submitBatches_pargs"); - - xfer += oprot->writeFieldBegin("batches", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast((*(this->batches)).size())); - std::vector ::const_iterator _iter58; - for (_iter58 = (*(this->batches)).begin(); _iter58 != (*(this->batches)).end(); ++_iter58) - { - xfer += (*_iter58).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Collector_submitBatches_result::~Collector_submitBatches_result() noexcept { -} - - -uint32_t Collector_submitBatches_result::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->success.clear(); - uint32_t _size59; - ::apache::thrift::protocol::TType _etype62; - xfer += iprot->readListBegin(_etype62, _size59); - this->success.resize(_size59); - uint32_t _i63; - for (_i63 = 0; _i63 < _size59; ++_i63) - { - xfer += this->success[_i63].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Collector_submitBatches_result::write(::apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("Collector_submitBatches_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_LIST, 0); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->success.size())); - std::vector ::const_iterator _iter64; - for (_iter64 = this->success.begin(); _iter64 != this->success.end(); ++_iter64) - { - xfer += (*_iter64).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -Collector_submitBatches_presult::~Collector_submitBatches_presult() noexcept { -} - - -uint32_t Collector_submitBatches_presult::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - (*(this->success)).clear(); - uint32_t _size65; - ::apache::thrift::protocol::TType _etype68; - xfer += iprot->readListBegin(_etype68, _size65); - (*(this->success)).resize(_size65); - uint32_t _i69; - for (_i69 = 0; _i69 < _size65; ++_i69) - { - xfer += (*(this->success))[_i69].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -void CollectorClient::submitBatches(std::vector & _return, const std::vector & batches) -{ - send_submitBatches(batches); - recv_submitBatches(_return); -} - -void CollectorClient::send_submitBatches(const std::vector & batches) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("submitBatches", ::apache::thrift::protocol::T_CALL, cseqid); - - Collector_submitBatches_pargs args; - args.batches = &batches; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); -} - -void CollectorClient::recv_submitBatches(std::vector & _return) -{ - - int32_t rseqid = 0; - std::string fname; - ::apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == ::apache::thrift::protocol::T_EXCEPTION) { - ::apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != ::apache::thrift::protocol::T_REPLY) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - if (fname.compare("submitBatches") != 0) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - Collector_submitBatches_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "submitBatches failed: unknown result"); -} - -bool CollectorProcessor::dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext) { - ProcessMap::iterator pfn; - pfn = processMap_.find(fname); - if (pfn == processMap_.end()) { - iprot->skip(::apache::thrift::protocol::T_STRUCT); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - ::apache::thrift::TApplicationException x(::apache::thrift::TApplicationException::UNKNOWN_METHOD, "Invalid method name: '"+fname+"'"); - oprot->writeMessageBegin(fname, ::apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - return true; - } - (this->*(pfn->second))(seqid, iprot, oprot, callContext); - return true; -} - -void CollectorProcessor::process_submitBatches(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext) -{ - void* ctx = nullptr; - if (this->eventHandler_.get() != nullptr) { - ctx = this->eventHandler_->getContext("Collector.submitBatches", callContext); - } - ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "Collector.submitBatches"); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preRead(ctx, "Collector.submitBatches"); - } - - Collector_submitBatches_args args; - args.read(iprot); - iprot->readMessageEnd(); - uint32_t bytes = iprot->getTransport()->readEnd(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postRead(ctx, "Collector.submitBatches", bytes); - } - - Collector_submitBatches_result result; - try { - iface_->submitBatches(result.success, args.batches); - result.__isset.success = true; - } catch (const std::exception& e) { - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->handlerError(ctx, "Collector.submitBatches"); - } - - ::apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("submitBatches", ::apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - return; - } - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preWrite(ctx, "Collector.submitBatches"); - } - - oprot->writeMessageBegin("submitBatches", ::apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - bytes = oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postWrite(ctx, "Collector.submitBatches", bytes); - } -} - -::std::shared_ptr< ::apache::thrift::TProcessor > CollectorProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) { - ::apache::thrift::ReleaseHandler< CollectorIfFactory > cleanup(handlerFactory_); - ::std::shared_ptr< CollectorIf > handler(handlerFactory_->getHandler(connInfo), cleanup); - ::std::shared_ptr< ::apache::thrift::TProcessor > processor(new CollectorProcessor(handler)); - return processor; -} - -void CollectorConcurrentClient::submitBatches(std::vector & _return, const std::vector & batches) -{ - int32_t seqid = send_submitBatches(batches); - recv_submitBatches(_return, seqid); -} - -int32_t CollectorConcurrentClient::send_submitBatches(const std::vector & batches) -{ - int32_t cseqid = this->sync_->generateSeqId(); - ::apache::thrift::async::TConcurrentSendSentry sentry(this->sync_.get()); - oprot_->writeMessageBegin("submitBatches", ::apache::thrift::protocol::T_CALL, cseqid); - - Collector_submitBatches_pargs args; - args.batches = &batches; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); - - sentry.commit(); - return cseqid; -} - -void CollectorConcurrentClient::recv_submitBatches(std::vector & _return, const int32_t seqid) -{ - - int32_t rseqid = 0; - std::string fname; - ::apache::thrift::protocol::TMessageType mtype; - - // the read mutex gets dropped and reacquired as part of waitForWork() - // The destructor of this sentry wakes up other clients - ::apache::thrift::async::TConcurrentRecvSentry sentry(this->sync_.get(), seqid); - - while(true) { - if(!this->sync_->getPending(fname, mtype, rseqid)) { - iprot_->readMessageBegin(fname, mtype, rseqid); - } - if(seqid == rseqid) { - if (mtype == ::apache::thrift::protocol::T_EXCEPTION) { - ::apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - sentry.commit(); - throw x; - } - if (mtype != ::apache::thrift::protocol::T_REPLY) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - if (fname.compare("submitBatches") != 0) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - // in a bad state, don't commit - using ::apache::thrift::protocol::TProtocolException; - throw TProtocolException(TProtocolException::INVALID_DATA); - } - Collector_submitBatches_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - sentry.commit(); - return; - } - // in a bad state, don't commit - throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "submitBatches failed: unknown result"); - } - // seqid != rseqid - this->sync_->updatePending(fname, mtype, rseqid); - - // this will temporarily unlock the readMutex, and let other clients get work done - this->sync_->waitForWork(seqid); - } // end while(true) -} - -}} // namespace - diff --git a/exporters/jaeger/thrift-gen/Collector.h b/exporters/jaeger/thrift-gen/Collector.h deleted file mode 100644 index 75daa69a75..0000000000 --- a/exporters/jaeger/thrift-gen/Collector.h +++ /dev/null @@ -1,299 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef Collector_H -#define Collector_H - -#include -#include -#include -#include "jaeger_types.h" - -namespace jaegertracing { namespace thrift { - -#ifdef _MSC_VER - #pragma warning( push ) - #pragma warning (disable : 4250 ) //inheriting methods via dominance -#endif - -class CollectorIf { - public: - virtual ~CollectorIf() {} - virtual void submitBatches(std::vector & _return, const std::vector & batches) = 0; -}; - -class CollectorIfFactory { - public: - typedef CollectorIf Handler; - - virtual ~CollectorIfFactory() {} - - virtual CollectorIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo) = 0; - virtual void releaseHandler(CollectorIf* /* handler */) = 0; -}; - -class CollectorIfSingletonFactory : virtual public CollectorIfFactory { - public: - CollectorIfSingletonFactory(const ::std::shared_ptr& iface) : iface_(iface) {} - virtual ~CollectorIfSingletonFactory() {} - - virtual CollectorIf* getHandler(const ::apache::thrift::TConnectionInfo&) { - return iface_.get(); - } - virtual void releaseHandler(CollectorIf* /* handler */) {} - - protected: - ::std::shared_ptr iface_; -}; - -class CollectorNull : virtual public CollectorIf { - public: - virtual ~CollectorNull() {} - void submitBatches(std::vector & /* _return */, const std::vector & /* batches */) { - return; - } -}; - -typedef struct _Collector_submitBatches_args__isset { - _Collector_submitBatches_args__isset() : batches(false) {} - bool batches :1; -} _Collector_submitBatches_args__isset; - -class Collector_submitBatches_args { - public: - - Collector_submitBatches_args(const Collector_submitBatches_args&); - Collector_submitBatches_args& operator=(const Collector_submitBatches_args&); - Collector_submitBatches_args() { - } - - virtual ~Collector_submitBatches_args() noexcept; - std::vector batches; - - _Collector_submitBatches_args__isset __isset; - - void __set_batches(const std::vector & val); - - bool operator == (const Collector_submitBatches_args & rhs) const - { - if (!(batches == rhs.batches)) - return false; - return true; - } - bool operator != (const Collector_submitBatches_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Collector_submitBatches_args & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - - -class Collector_submitBatches_pargs { - public: - - - virtual ~Collector_submitBatches_pargs() noexcept; - const std::vector * batches; - - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -typedef struct _Collector_submitBatches_result__isset { - _Collector_submitBatches_result__isset() : success(false) {} - bool success :1; -} _Collector_submitBatches_result__isset; - -class Collector_submitBatches_result { - public: - - Collector_submitBatches_result(const Collector_submitBatches_result&); - Collector_submitBatches_result& operator=(const Collector_submitBatches_result&); - Collector_submitBatches_result() { - } - - virtual ~Collector_submitBatches_result() noexcept; - std::vector success; - - _Collector_submitBatches_result__isset __isset; - - void __set_success(const std::vector & val); - - bool operator == (const Collector_submitBatches_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const Collector_submitBatches_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Collector_submitBatches_result & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -typedef struct _Collector_submitBatches_presult__isset { - _Collector_submitBatches_presult__isset() : success(false) {} - bool success :1; -} _Collector_submitBatches_presult__isset; - -class Collector_submitBatches_presult { - public: - - - virtual ~Collector_submitBatches_presult() noexcept; - std::vector * success; - - _Collector_submitBatches_presult__isset __isset; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - -}; - -class CollectorClient : virtual public CollectorIf { - public: - CollectorClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot); - } - CollectorClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void submitBatches(std::vector & _return, const std::vector & batches); - void send_submitBatches(const std::vector & batches); - void recv_submitBatches(std::vector & _return); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; -}; - -class CollectorProcessor : public ::apache::thrift::TDispatchProcessor { - protected: - ::std::shared_ptr iface_; - virtual bool dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext); - private: - typedef void (CollectorProcessor::*ProcessFunction)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*); - typedef std::map ProcessMap; - ProcessMap processMap_; - void process_submitBatches(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext); - public: - CollectorProcessor(::std::shared_ptr iface) : - iface_(iface) { - processMap_["submitBatches"] = &CollectorProcessor::process_submitBatches; - } - - virtual ~CollectorProcessor() {} -}; - -class CollectorProcessorFactory : public ::apache::thrift::TProcessorFactory { - public: - CollectorProcessorFactory(const ::std::shared_ptr< CollectorIfFactory >& handlerFactory) : - handlerFactory_(handlerFactory) {} - - ::std::shared_ptr< ::apache::thrift::TProcessor > getProcessor(const ::apache::thrift::TConnectionInfo& connInfo); - - protected: - ::std::shared_ptr< CollectorIfFactory > handlerFactory_; -}; - -class CollectorMultiface : virtual public CollectorIf { - public: - CollectorMultiface(std::vector >& ifaces) : ifaces_(ifaces) { - } - virtual ~CollectorMultiface() {} - protected: - std::vector > ifaces_; - CollectorMultiface() {} - void add(::std::shared_ptr iface) { - ifaces_.push_back(iface); - } - public: - void submitBatches(std::vector & _return, const std::vector & batches) { - size_t sz = ifaces_.size(); - size_t i = 0; - for (; i < (sz - 1); ++i) { - ifaces_[i]->submitBatches(_return, batches); - } - ifaces_[i]->submitBatches(_return, batches); - return; - } - -}; - -// The 'concurrent' client is a thread safe client that correctly handles -// out of order responses. It is slower than the regular client, so should -// only be used when you need to share a connection among multiple threads -class CollectorConcurrentClient : virtual public CollectorIf { - public: - CollectorConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(prot); - } - CollectorConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void submitBatches(std::vector & _return, const std::vector & batches); - int32_t send_submitBatches(const std::vector & batches); - void recv_submitBatches(std::vector & _return, const int32_t seqid); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; - std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync_; -}; - -#ifdef _MSC_VER - #pragma warning( pop ) -#endif - -}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/Collector_server.skeleton.cpp b/exporters/jaeger/thrift-gen/Collector_server.skeleton.cpp deleted file mode 100644 index c59c8aa49a..0000000000 --- a/exporters/jaeger/thrift-gen/Collector_server.skeleton.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// This autogenerated skeleton file illustrates how to build a server. -// You should copy it to another filename to avoid overwriting it. - -#include "Collector.h" -#include -#include -#include -#include - -using namespace ::apache::thrift; -using namespace ::apache::thrift::protocol; -using namespace ::apache::thrift::transport; -using namespace ::apache::thrift::server; - -using namespace ::jaegertracing::thrift; - -class CollectorHandler : virtual public CollectorIf { - public: - CollectorHandler() { - // Your initialization goes here - } - - void submitBatches(std::vector & _return, const std::vector & batches) { - // Your implementation goes here - printf("submitBatches\n"); - } - -}; - -int main(int argc, char **argv) { - int port = 9090; - ::std::shared_ptr handler(new CollectorHandler()); - ::std::shared_ptr processor(new CollectorProcessor(handler)); - ::std::shared_ptr serverTransport(new TServerSocket(port)); - ::std::shared_ptr transportFactory(new TBufferedTransportFactory()); - ::std::shared_ptr protocolFactory(new TBinaryProtocolFactory()); - - TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory); - server.serve(); - return 0; -} - diff --git a/exporters/jaeger/thrift-gen/ZipkinCollector.cpp b/exporters/jaeger/thrift-gen/ZipkinCollector.cpp deleted file mode 100644 index 42d813dfd4..0000000000 --- a/exporters/jaeger/thrift-gen/ZipkinCollector.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "ZipkinCollector.h" - -namespace twitter { namespace zipkin { namespace thrift { - - -ZipkinCollector_submitZipkinBatch_args::~ZipkinCollector_submitZipkinBatch_args() noexcept { -} - - -uint32_t ZipkinCollector_submitZipkinBatch_args::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->spans.clear(); - uint32_t _size23; - ::apache::thrift::protocol::TType _etype26; - xfer += iprot->readListBegin(_etype26, _size23); - this->spans.resize(_size23); - uint32_t _i27; - for (_i27 = 0; _i27 < _size23; ++_i27) - { - xfer += this->spans[_i27].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.spans = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t ZipkinCollector_submitZipkinBatch_args::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("ZipkinCollector_submitZipkinBatch_args"); - - xfer += oprot->writeFieldBegin("spans", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->spans.size())); - std::vector ::const_iterator _iter28; - for (_iter28 = this->spans.begin(); _iter28 != this->spans.end(); ++_iter28) - { - xfer += (*_iter28).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -ZipkinCollector_submitZipkinBatch_pargs::~ZipkinCollector_submitZipkinBatch_pargs() noexcept { -} - - -uint32_t ZipkinCollector_submitZipkinBatch_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("ZipkinCollector_submitZipkinBatch_pargs"); - - xfer += oprot->writeFieldBegin("spans", ::apache::thrift::protocol::T_LIST, 1); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast((*(this->spans)).size())); - std::vector ::const_iterator _iter29; - for (_iter29 = (*(this->spans)).begin(); _iter29 != (*(this->spans)).end(); ++_iter29) - { - xfer += (*_iter29).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -ZipkinCollector_submitZipkinBatch_result::~ZipkinCollector_submitZipkinBatch_result() noexcept { -} - - -uint32_t ZipkinCollector_submitZipkinBatch_result::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->success.clear(); - uint32_t _size30; - ::apache::thrift::protocol::TType _etype33; - xfer += iprot->readListBegin(_etype33, _size30); - this->success.resize(_size30); - uint32_t _i34; - for (_i34 = 0; _i34 < _size30; ++_i34) - { - xfer += this->success[_i34].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t ZipkinCollector_submitZipkinBatch_result::write(::apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("ZipkinCollector_submitZipkinBatch_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_LIST, 0); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->success.size())); - std::vector ::const_iterator _iter35; - for (_iter35 = this->success.begin(); _iter35 != this->success.end(); ++_iter35) - { - xfer += (*_iter35).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - - -ZipkinCollector_submitZipkinBatch_presult::~ZipkinCollector_submitZipkinBatch_presult() noexcept { -} - - -uint32_t ZipkinCollector_submitZipkinBatch_presult::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - (*(this->success)).clear(); - uint32_t _size36; - ::apache::thrift::protocol::TType _etype39; - xfer += iprot->readListBegin(_etype39, _size36); - (*(this->success)).resize(_size36); - uint32_t _i40; - for (_i40 = 0; _i40 < _size36; ++_i40) - { - xfer += (*(this->success))[_i40].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -void ZipkinCollectorClient::submitZipkinBatch(std::vector & _return, const std::vector & spans) -{ - send_submitZipkinBatch(spans); - recv_submitZipkinBatch(_return); -} - -void ZipkinCollectorClient::send_submitZipkinBatch(const std::vector & spans) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("submitZipkinBatch", ::apache::thrift::protocol::T_CALL, cseqid); - - ZipkinCollector_submitZipkinBatch_pargs args; - args.spans = &spans; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); -} - -void ZipkinCollectorClient::recv_submitZipkinBatch(std::vector & _return) -{ - - int32_t rseqid = 0; - std::string fname; - ::apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == ::apache::thrift::protocol::T_EXCEPTION) { - ::apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != ::apache::thrift::protocol::T_REPLY) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - if (fname.compare("submitZipkinBatch") != 0) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - ZipkinCollector_submitZipkinBatch_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "submitZipkinBatch failed: unknown result"); -} - -bool ZipkinCollectorProcessor::dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext) { - ProcessMap::iterator pfn; - pfn = processMap_.find(fname); - if (pfn == processMap_.end()) { - iprot->skip(::apache::thrift::protocol::T_STRUCT); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - ::apache::thrift::TApplicationException x(::apache::thrift::TApplicationException::UNKNOWN_METHOD, "Invalid method name: '"+fname+"'"); - oprot->writeMessageBegin(fname, ::apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - return true; - } - (this->*(pfn->second))(seqid, iprot, oprot, callContext); - return true; -} - -void ZipkinCollectorProcessor::process_submitZipkinBatch(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext) -{ - void* ctx = nullptr; - if (this->eventHandler_.get() != nullptr) { - ctx = this->eventHandler_->getContext("ZipkinCollector.submitZipkinBatch", callContext); - } - ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "ZipkinCollector.submitZipkinBatch"); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preRead(ctx, "ZipkinCollector.submitZipkinBatch"); - } - - ZipkinCollector_submitZipkinBatch_args args; - args.read(iprot); - iprot->readMessageEnd(); - uint32_t bytes = iprot->getTransport()->readEnd(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postRead(ctx, "ZipkinCollector.submitZipkinBatch", bytes); - } - - ZipkinCollector_submitZipkinBatch_result result; - try { - iface_->submitZipkinBatch(result.success, args.spans); - result.__isset.success = true; - } catch (const std::exception& e) { - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->handlerError(ctx, "ZipkinCollector.submitZipkinBatch"); - } - - ::apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("submitZipkinBatch", ::apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - return; - } - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->preWrite(ctx, "ZipkinCollector.submitZipkinBatch"); - } - - oprot->writeMessageBegin("submitZipkinBatch", ::apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - bytes = oprot->getTransport()->writeEnd(); - oprot->getTransport()->flush(); - - if (this->eventHandler_.get() != nullptr) { - this->eventHandler_->postWrite(ctx, "ZipkinCollector.submitZipkinBatch", bytes); - } -} - -::std::shared_ptr< ::apache::thrift::TProcessor > ZipkinCollectorProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) { - ::apache::thrift::ReleaseHandler< ZipkinCollectorIfFactory > cleanup(handlerFactory_); - ::std::shared_ptr< ZipkinCollectorIf > handler(handlerFactory_->getHandler(connInfo), cleanup); - ::std::shared_ptr< ::apache::thrift::TProcessor > processor(new ZipkinCollectorProcessor(handler)); - return processor; -} - -void ZipkinCollectorConcurrentClient::submitZipkinBatch(std::vector & _return, const std::vector & spans) -{ - int32_t seqid = send_submitZipkinBatch(spans); - recv_submitZipkinBatch(_return, seqid); -} - -int32_t ZipkinCollectorConcurrentClient::send_submitZipkinBatch(const std::vector & spans) -{ - int32_t cseqid = this->sync_->generateSeqId(); - ::apache::thrift::async::TConcurrentSendSentry sentry(this->sync_.get()); - oprot_->writeMessageBegin("submitZipkinBatch", ::apache::thrift::protocol::T_CALL, cseqid); - - ZipkinCollector_submitZipkinBatch_pargs args; - args.spans = &spans; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->writeEnd(); - oprot_->getTransport()->flush(); - - sentry.commit(); - return cseqid; -} - -void ZipkinCollectorConcurrentClient::recv_submitZipkinBatch(std::vector & _return, const int32_t seqid) -{ - - int32_t rseqid = 0; - std::string fname; - ::apache::thrift::protocol::TMessageType mtype; - - // the read mutex gets dropped and reacquired as part of waitForWork() - // The destructor of this sentry wakes up other clients - ::apache::thrift::async::TConcurrentRecvSentry sentry(this->sync_.get(), seqid); - - while(true) { - if(!this->sync_->getPending(fname, mtype, rseqid)) { - iprot_->readMessageBegin(fname, mtype, rseqid); - } - if(seqid == rseqid) { - if (mtype == ::apache::thrift::protocol::T_EXCEPTION) { - ::apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - sentry.commit(); - throw x; - } - if (mtype != ::apache::thrift::protocol::T_REPLY) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - } - if (fname.compare("submitZipkinBatch") != 0) { - iprot_->skip(::apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - // in a bad state, don't commit - using ::apache::thrift::protocol::TProtocolException; - throw TProtocolException(TProtocolException::INVALID_DATA); - } - ZipkinCollector_submitZipkinBatch_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - sentry.commit(); - return; - } - // in a bad state, don't commit - throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "submitZipkinBatch failed: unknown result"); - } - // seqid != rseqid - this->sync_->updatePending(fname, mtype, rseqid); - - // this will temporarily unlock the readMutex, and let other clients get work done - this->sync_->waitForWork(seqid); - } // end while(true) -} - -}}} // namespace - diff --git a/exporters/jaeger/thrift-gen/ZipkinCollector.h b/exporters/jaeger/thrift-gen/ZipkinCollector.h deleted file mode 100644 index 97e111d249..0000000000 --- a/exporters/jaeger/thrift-gen/ZipkinCollector.h +++ /dev/null @@ -1,299 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef ZipkinCollector_H -#define ZipkinCollector_H - -#include -#include -#include -#include "zipkincore_types.h" - -namespace twitter { namespace zipkin { namespace thrift { - -#ifdef _MSC_VER - #pragma warning( push ) - #pragma warning (disable : 4250 ) //inheriting methods via dominance -#endif - -class ZipkinCollectorIf { - public: - virtual ~ZipkinCollectorIf() {} - virtual void submitZipkinBatch(std::vector & _return, const std::vector & spans) = 0; -}; - -class ZipkinCollectorIfFactory { - public: - typedef ZipkinCollectorIf Handler; - - virtual ~ZipkinCollectorIfFactory() {} - - virtual ZipkinCollectorIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo) = 0; - virtual void releaseHandler(ZipkinCollectorIf* /* handler */) = 0; -}; - -class ZipkinCollectorIfSingletonFactory : virtual public ZipkinCollectorIfFactory { - public: - ZipkinCollectorIfSingletonFactory(const ::std::shared_ptr& iface) : iface_(iface) {} - virtual ~ZipkinCollectorIfSingletonFactory() {} - - virtual ZipkinCollectorIf* getHandler(const ::apache::thrift::TConnectionInfo&) { - return iface_.get(); - } - virtual void releaseHandler(ZipkinCollectorIf* /* handler */) {} - - protected: - ::std::shared_ptr iface_; -}; - -class ZipkinCollectorNull : virtual public ZipkinCollectorIf { - public: - virtual ~ZipkinCollectorNull() {} - void submitZipkinBatch(std::vector & /* _return */, const std::vector & /* spans */) { - return; - } -}; - -typedef struct _ZipkinCollector_submitZipkinBatch_args__isset { - _ZipkinCollector_submitZipkinBatch_args__isset() : spans(false) {} - bool spans :1; -} _ZipkinCollector_submitZipkinBatch_args__isset; - -class ZipkinCollector_submitZipkinBatch_args { - public: - - ZipkinCollector_submitZipkinBatch_args(const ZipkinCollector_submitZipkinBatch_args&); - ZipkinCollector_submitZipkinBatch_args& operator=(const ZipkinCollector_submitZipkinBatch_args&); - ZipkinCollector_submitZipkinBatch_args() { - } - - virtual ~ZipkinCollector_submitZipkinBatch_args() noexcept; - std::vector spans; - - _ZipkinCollector_submitZipkinBatch_args__isset __isset; - - void __set_spans(const std::vector & val); - - bool operator == (const ZipkinCollector_submitZipkinBatch_args & rhs) const - { - if (!(spans == rhs.spans)) - return false; - return true; - } - bool operator != (const ZipkinCollector_submitZipkinBatch_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const ZipkinCollector_submitZipkinBatch_args & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - - -class ZipkinCollector_submitZipkinBatch_pargs { - public: - - - virtual ~ZipkinCollector_submitZipkinBatch_pargs() noexcept; - const std::vector * spans; - - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -typedef struct _ZipkinCollector_submitZipkinBatch_result__isset { - _ZipkinCollector_submitZipkinBatch_result__isset() : success(false) {} - bool success :1; -} _ZipkinCollector_submitZipkinBatch_result__isset; - -class ZipkinCollector_submitZipkinBatch_result { - public: - - ZipkinCollector_submitZipkinBatch_result(const ZipkinCollector_submitZipkinBatch_result&); - ZipkinCollector_submitZipkinBatch_result& operator=(const ZipkinCollector_submitZipkinBatch_result&); - ZipkinCollector_submitZipkinBatch_result() { - } - - virtual ~ZipkinCollector_submitZipkinBatch_result() noexcept; - std::vector success; - - _ZipkinCollector_submitZipkinBatch_result__isset __isset; - - void __set_success(const std::vector & val); - - bool operator == (const ZipkinCollector_submitZipkinBatch_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const ZipkinCollector_submitZipkinBatch_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const ZipkinCollector_submitZipkinBatch_result & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - -}; - -typedef struct _ZipkinCollector_submitZipkinBatch_presult__isset { - _ZipkinCollector_submitZipkinBatch_presult__isset() : success(false) {} - bool success :1; -} _ZipkinCollector_submitZipkinBatch_presult__isset; - -class ZipkinCollector_submitZipkinBatch_presult { - public: - - - virtual ~ZipkinCollector_submitZipkinBatch_presult() noexcept; - std::vector * success; - - _ZipkinCollector_submitZipkinBatch_presult__isset __isset; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - -}; - -class ZipkinCollectorClient : virtual public ZipkinCollectorIf { - public: - ZipkinCollectorClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot); - } - ZipkinCollectorClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void submitZipkinBatch(std::vector & _return, const std::vector & spans); - void send_submitZipkinBatch(const std::vector & spans); - void recv_submitZipkinBatch(std::vector & _return); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; -}; - -class ZipkinCollectorProcessor : public ::apache::thrift::TDispatchProcessor { - protected: - ::std::shared_ptr iface_; - virtual bool dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext); - private: - typedef void (ZipkinCollectorProcessor::*ProcessFunction)(int32_t, ::apache::thrift::protocol::TProtocol*, ::apache::thrift::protocol::TProtocol*, void*); - typedef std::map ProcessMap; - ProcessMap processMap_; - void process_submitZipkinBatch(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext); - public: - ZipkinCollectorProcessor(::std::shared_ptr iface) : - iface_(iface) { - processMap_["submitZipkinBatch"] = &ZipkinCollectorProcessor::process_submitZipkinBatch; - } - - virtual ~ZipkinCollectorProcessor() {} -}; - -class ZipkinCollectorProcessorFactory : public ::apache::thrift::TProcessorFactory { - public: - ZipkinCollectorProcessorFactory(const ::std::shared_ptr< ZipkinCollectorIfFactory >& handlerFactory) : - handlerFactory_(handlerFactory) {} - - ::std::shared_ptr< ::apache::thrift::TProcessor > getProcessor(const ::apache::thrift::TConnectionInfo& connInfo); - - protected: - ::std::shared_ptr< ZipkinCollectorIfFactory > handlerFactory_; -}; - -class ZipkinCollectorMultiface : virtual public ZipkinCollectorIf { - public: - ZipkinCollectorMultiface(std::vector >& ifaces) : ifaces_(ifaces) { - } - virtual ~ZipkinCollectorMultiface() {} - protected: - std::vector > ifaces_; - ZipkinCollectorMultiface() {} - void add(::std::shared_ptr iface) { - ifaces_.push_back(iface); - } - public: - void submitZipkinBatch(std::vector & _return, const std::vector & spans) { - size_t sz = ifaces_.size(); - size_t i = 0; - for (; i < (sz - 1); ++i) { - ifaces_[i]->submitZipkinBatch(_return, spans); - } - ifaces_[i]->submitZipkinBatch(_return, spans); - return; - } - -}; - -// The 'concurrent' client is a thread safe client that correctly handles -// out of order responses. It is slower than the regular client, so should -// only be used when you need to share a connection among multiple threads -class ZipkinCollectorConcurrentClient : virtual public ZipkinCollectorIf { - public: - ZipkinCollectorConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(prot); - } - ZipkinCollectorConcurrentClient(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot, std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync) : sync_(sync) -{ - setProtocol(iprot,oprot); - } - private: - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) { - setProtocol(prot,prot); - } - void setProtocol(std::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, std::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) { - piprot_=iprot; - poprot_=oprot; - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - public: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() { - return piprot_; - } - std::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() { - return poprot_; - } - void submitZipkinBatch(std::vector & _return, const std::vector & spans); - int32_t send_submitZipkinBatch(const std::vector & spans); - void recv_submitZipkinBatch(std::vector & _return, const int32_t seqid); - protected: - std::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_; - std::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_; - ::apache::thrift::protocol::TProtocol* iprot_; - ::apache::thrift::protocol::TProtocol* oprot_; - std::shared_ptr<::apache::thrift::async::TConcurrentClientSyncInfo> sync_; -}; - -#ifdef _MSC_VER - #pragma warning( pop ) -#endif - -}}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/ZipkinCollector_server.skeleton.cpp b/exporters/jaeger/thrift-gen/ZipkinCollector_server.skeleton.cpp deleted file mode 100644 index cca6ef752f..0000000000 --- a/exporters/jaeger/thrift-gen/ZipkinCollector_server.skeleton.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// This autogenerated skeleton file illustrates how to build a server. -// You should copy it to another filename to avoid overwriting it. - -#include "ZipkinCollector.h" -#include -#include -#include -#include - -using namespace ::apache::thrift; -using namespace ::apache::thrift::protocol; -using namespace ::apache::thrift::transport; -using namespace ::apache::thrift::server; - -using namespace ::twitter::zipkin::thrift; - -class ZipkinCollectorHandler : virtual public ZipkinCollectorIf { - public: - ZipkinCollectorHandler() { - // Your initialization goes here - } - - void submitZipkinBatch(std::vector & _return, const std::vector & spans) { - // Your implementation goes here - printf("submitZipkinBatch\n"); - } - -}; - -int main(int argc, char **argv) { - int port = 9090; - ::std::shared_ptr handler(new ZipkinCollectorHandler()); - ::std::shared_ptr processor(new ZipkinCollectorProcessor(handler)); - ::std::shared_ptr serverTransport(new TServerSocket(port)); - ::std::shared_ptr transportFactory(new TBufferedTransportFactory()); - ::std::shared_ptr protocolFactory(new TBinaryProtocolFactory()); - - TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory); - server.serve(); - return 0; -} - diff --git a/exporters/jaeger/thrift-gen/agent_types.h b/exporters/jaeger/thrift-gen/agent_types.h deleted file mode 100644 index 0b576e34f5..0000000000 --- a/exporters/jaeger/thrift-gen/agent_types.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef agent_TYPES_H -#define agent_TYPES_H - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include "jaeger_types.h" -#include "zipkincore_types.h" - - -namespace jaegertracing { namespace agent { namespace thrift { - -}}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/jaeger_types.cpp b/exporters/jaeger/thrift-gen/jaeger_types.cpp deleted file mode 100644 index 5e4140cc96..0000000000 --- a/exporters/jaeger/thrift-gen/jaeger_types.cpp +++ /dev/null @@ -1,1354 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "jaeger_types.h" - -#include -#include - -#include - -namespace jaegertracing { namespace thrift { - -int _kTagTypeValues[] = { - TagType::STRING, - TagType::DOUBLE, - TagType::BOOL, - TagType::LONG, - TagType::BINARY -}; -const char* _kTagTypeNames[] = { - "STRING", - "DOUBLE", - "BOOL", - "LONG", - "BINARY" -}; -const std::map _TagType_VALUES_TO_NAMES(::apache::thrift::TEnumIterator(5, _kTagTypeValues, _kTagTypeNames), ::apache::thrift::TEnumIterator(-1, nullptr, nullptr)); - -std::ostream& operator<<(std::ostream& out, const TagType::type& val) { - std::map::const_iterator it = _TagType_VALUES_TO_NAMES.find(val); - if (it != _TagType_VALUES_TO_NAMES.end()) { - out << it->second; - } else { - out << static_cast(val); - } - return out; -} - -std::string to_string(const TagType::type& val) { - std::map::const_iterator it = _TagType_VALUES_TO_NAMES.find(val); - if (it != _TagType_VALUES_TO_NAMES.end()) { - return std::string(it->second); - } else { - return std::to_string(static_cast(val)); - } -} - -int _kSpanRefTypeValues[] = { - SpanRefType::CHILD_OF, - SpanRefType::FOLLOWS_FROM -}; -const char* _kSpanRefTypeNames[] = { - "CHILD_OF", - "FOLLOWS_FROM" -}; -const std::map _SpanRefType_VALUES_TO_NAMES(::apache::thrift::TEnumIterator(2, _kSpanRefTypeValues, _kSpanRefTypeNames), ::apache::thrift::TEnumIterator(-1, nullptr, nullptr)); - -std::ostream& operator<<(std::ostream& out, const SpanRefType::type& val) { - std::map::const_iterator it = _SpanRefType_VALUES_TO_NAMES.find(val); - if (it != _SpanRefType_VALUES_TO_NAMES.end()) { - out << it->second; - } else { - out << static_cast(val); - } - return out; -} - -std::string to_string(const SpanRefType::type& val) { - std::map::const_iterator it = _SpanRefType_VALUES_TO_NAMES.find(val); - if (it != _SpanRefType_VALUES_TO_NAMES.end()) { - return std::string(it->second); - } else { - return std::to_string(static_cast(val)); - } -} - - -Tag::~Tag() noexcept { -} - - -void Tag::__set_key(const std::string& val) { - this->key = val; -} - -void Tag::__set_vType(const TagType::type val) { - this->vType = val; -} - -void Tag::__set_vStr(const std::string& val) { - this->vStr = val; -__isset.vStr = true; -} - -void Tag::__set_vDouble(const double val) { - this->vDouble = val; -__isset.vDouble = true; -} - -void Tag::__set_vBool(const bool val) { - this->vBool = val; -__isset.vBool = true; -} - -void Tag::__set_vLong(const int64_t val) { - this->vLong = val; -__isset.vLong = true; -} - -void Tag::__set_vBinary(const std::string& val) { - this->vBinary = val; -__isset.vBinary = true; -} -std::ostream& operator<<(std::ostream& out, const Tag& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Tag::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_key = false; - bool isset_vType = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->key); - isset_key = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I32) { - int32_t ecast0; - xfer += iprot->readI32(ecast0); - this->vType = (TagType::type)ecast0; - isset_vType = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->vStr); - this->__isset.vStr = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_DOUBLE) { - xfer += iprot->readDouble(this->vDouble); - this->__isset.vDouble = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->vBool); - this->__isset.vBool = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 6: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->vLong); - this->__isset.vLong = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 7: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readBinary(this->vBinary); - this->__isset.vBinary = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_key) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_vType) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Tag::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Tag"); - - xfer += oprot->writeFieldBegin("key", ::apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->key); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("vType", ::apache::thrift::protocol::T_I32, 2); - xfer += oprot->writeI32((int32_t)this->vType); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.vStr) { - xfer += oprot->writeFieldBegin("vStr", ::apache::thrift::protocol::T_STRING, 3); - xfer += oprot->writeString(this->vStr); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.vDouble) { - xfer += oprot->writeFieldBegin("vDouble", ::apache::thrift::protocol::T_DOUBLE, 4); - xfer += oprot->writeDouble(this->vDouble); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.vBool) { - xfer += oprot->writeFieldBegin("vBool", ::apache::thrift::protocol::T_BOOL, 5); - xfer += oprot->writeBool(this->vBool); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.vLong) { - xfer += oprot->writeFieldBegin("vLong", ::apache::thrift::protocol::T_I64, 6); - xfer += oprot->writeI64(this->vLong); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.vBinary) { - xfer += oprot->writeFieldBegin("vBinary", ::apache::thrift::protocol::T_STRING, 7); - xfer += oprot->writeBinary(this->vBinary); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Tag &a, Tag &b) { - using ::std::swap; - swap(a.key, b.key); - swap(a.vType, b.vType); - swap(a.vStr, b.vStr); - swap(a.vDouble, b.vDouble); - swap(a.vBool, b.vBool); - swap(a.vLong, b.vLong); - swap(a.vBinary, b.vBinary); - swap(a.__isset, b.__isset); -} - -Tag::Tag(const Tag& other1) { - key = other1.key; - vType = other1.vType; - vStr = other1.vStr; - vDouble = other1.vDouble; - vBool = other1.vBool; - vLong = other1.vLong; - vBinary = other1.vBinary; - __isset = other1.__isset; -} -Tag& Tag::operator=(const Tag& other2) { - key = other2.key; - vType = other2.vType; - vStr = other2.vStr; - vDouble = other2.vDouble; - vBool = other2.vBool; - vLong = other2.vLong; - vBinary = other2.vBinary; - __isset = other2.__isset; - return *this; -} -void Tag::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Tag("; - out << "key=" << to_string(key); - out << ", " << "vType=" << to_string(vType); - out << ", " << "vStr="; (__isset.vStr ? (out << to_string(vStr)) : (out << "")); - out << ", " << "vDouble="; (__isset.vDouble ? (out << to_string(vDouble)) : (out << "")); - out << ", " << "vBool="; (__isset.vBool ? (out << to_string(vBool)) : (out << "")); - out << ", " << "vLong="; (__isset.vLong ? (out << to_string(vLong)) : (out << "")); - out << ", " << "vBinary="; (__isset.vBinary ? (out << to_string(vBinary)) : (out << "")); - out << ")"; -} - - -Log::~Log() noexcept { -} - - -void Log::__set_timestamp(const int64_t val) { - this->timestamp = val; -} - -void Log::__set_fields(const std::vector & val) { - this->fields = val; -} -std::ostream& operator<<(std::ostream& out, const Log& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Log::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_timestamp = false; - bool isset_fields = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->timestamp); - isset_timestamp = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->fields.clear(); - uint32_t _size3; - ::apache::thrift::protocol::TType _etype6; - xfer += iprot->readListBegin(_etype6, _size3); - this->fields.resize(_size3); - uint32_t _i7; - for (_i7 = 0; _i7 < _size3; ++_i7) - { - xfer += this->fields[_i7].read(iprot); - } - xfer += iprot->readListEnd(); - } - isset_fields = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_timestamp) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_fields) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Log::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Log"); - - xfer += oprot->writeFieldBegin("timestamp", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->timestamp); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("fields", ::apache::thrift::protocol::T_LIST, 2); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->fields.size())); - std::vector ::const_iterator _iter8; - for (_iter8 = this->fields.begin(); _iter8 != this->fields.end(); ++_iter8) - { - xfer += (*_iter8).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Log &a, Log &b) { - using ::std::swap; - swap(a.timestamp, b.timestamp); - swap(a.fields, b.fields); -} - -Log::Log(const Log& other9) { - timestamp = other9.timestamp; - fields = other9.fields; -} -Log& Log::operator=(const Log& other10) { - timestamp = other10.timestamp; - fields = other10.fields; - return *this; -} -void Log::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Log("; - out << "timestamp=" << to_string(timestamp); - out << ", " << "fields=" << to_string(fields); - out << ")"; -} - - -SpanRef::~SpanRef() noexcept { -} - - -void SpanRef::__set_refType(const SpanRefType::type val) { - this->refType = val; -} - -void SpanRef::__set_traceIdLow(const int64_t val) { - this->traceIdLow = val; -} - -void SpanRef::__set_traceIdHigh(const int64_t val) { - this->traceIdHigh = val; -} - -void SpanRef::__set_spanId(const int64_t val) { - this->spanId = val; -} -std::ostream& operator<<(std::ostream& out, const SpanRef& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t SpanRef::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_refType = false; - bool isset_traceIdLow = false; - bool isset_traceIdHigh = false; - bool isset_spanId = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - int32_t ecast11; - xfer += iprot->readI32(ecast11); - this->refType = (SpanRefType::type)ecast11; - isset_refType = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->traceIdLow); - isset_traceIdLow = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->traceIdHigh); - isset_traceIdHigh = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->spanId); - isset_spanId = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_refType) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_traceIdLow) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_traceIdHigh) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_spanId) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t SpanRef::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("SpanRef"); - - xfer += oprot->writeFieldBegin("refType", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32((int32_t)this->refType); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("traceIdLow", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64(this->traceIdLow); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("traceIdHigh", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->traceIdHigh); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("spanId", ::apache::thrift::protocol::T_I64, 4); - xfer += oprot->writeI64(this->spanId); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(SpanRef &a, SpanRef &b) { - using ::std::swap; - swap(a.refType, b.refType); - swap(a.traceIdLow, b.traceIdLow); - swap(a.traceIdHigh, b.traceIdHigh); - swap(a.spanId, b.spanId); -} - -SpanRef::SpanRef(const SpanRef& other12) { - refType = other12.refType; - traceIdLow = other12.traceIdLow; - traceIdHigh = other12.traceIdHigh; - spanId = other12.spanId; -} -SpanRef& SpanRef::operator=(const SpanRef& other13) { - refType = other13.refType; - traceIdLow = other13.traceIdLow; - traceIdHigh = other13.traceIdHigh; - spanId = other13.spanId; - return *this; -} -void SpanRef::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "SpanRef("; - out << "refType=" << to_string(refType); - out << ", " << "traceIdLow=" << to_string(traceIdLow); - out << ", " << "traceIdHigh=" << to_string(traceIdHigh); - out << ", " << "spanId=" << to_string(spanId); - out << ")"; -} - - -Span::~Span() noexcept { -} - - -void Span::__set_traceIdLow(const int64_t val) { - this->traceIdLow = val; -} - -void Span::__set_traceIdHigh(const int64_t val) { - this->traceIdHigh = val; -} - -void Span::__set_spanId(const int64_t val) { - this->spanId = val; -} - -void Span::__set_parentSpanId(const int64_t val) { - this->parentSpanId = val; -} - -void Span::__set_operationName(const std::string& val) { - this->operationName = val; -} - -void Span::__set_references(const std::vector & val) { - this->references = val; -__isset.references = true; -} - -void Span::__set_flags(const int32_t val) { - this->flags = val; -} - -void Span::__set_startTime(const int64_t val) { - this->startTime = val; -} - -void Span::__set_duration(const int64_t val) { - this->duration = val; -} - -void Span::__set_tags(const std::vector & val) { - this->tags = val; -__isset.tags = true; -} - -void Span::__set_logs(const std::vector & val) { - this->logs = val; -__isset.logs = true; -} -std::ostream& operator<<(std::ostream& out, const Span& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Span::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_traceIdLow = false; - bool isset_traceIdHigh = false; - bool isset_spanId = false; - bool isset_parentSpanId = false; - bool isset_operationName = false; - bool isset_flags = false; - bool isset_startTime = false; - bool isset_duration = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->traceIdLow); - isset_traceIdLow = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->traceIdHigh); - isset_traceIdHigh = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->spanId); - isset_spanId = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->parentSpanId); - isset_parentSpanId = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->operationName); - isset_operationName = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 6: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->references.clear(); - uint32_t _size14; - ::apache::thrift::protocol::TType _etype17; - xfer += iprot->readListBegin(_etype17, _size14); - this->references.resize(_size14); - uint32_t _i18; - for (_i18 = 0; _i18 < _size14; ++_i18) - { - xfer += this->references[_i18].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.references = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 7: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->flags); - isset_flags = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 8: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->startTime); - isset_startTime = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 9: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->duration); - isset_duration = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 10: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->tags.clear(); - uint32_t _size19; - ::apache::thrift::protocol::TType _etype22; - xfer += iprot->readListBegin(_etype22, _size19); - this->tags.resize(_size19); - uint32_t _i23; - for (_i23 = 0; _i23 < _size19; ++_i23) - { - xfer += this->tags[_i23].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.tags = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 11: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->logs.clear(); - uint32_t _size24; - ::apache::thrift::protocol::TType _etype27; - xfer += iprot->readListBegin(_etype27, _size24); - this->logs.resize(_size24); - uint32_t _i28; - for (_i28 = 0; _i28 < _size24; ++_i28) - { - xfer += this->logs[_i28].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.logs = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_traceIdLow) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_traceIdHigh) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_spanId) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_parentSpanId) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_operationName) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_flags) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_startTime) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_duration) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Span::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Span"); - - xfer += oprot->writeFieldBegin("traceIdLow", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->traceIdLow); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("traceIdHigh", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64(this->traceIdHigh); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("spanId", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->spanId); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("parentSpanId", ::apache::thrift::protocol::T_I64, 4); - xfer += oprot->writeI64(this->parentSpanId); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("operationName", ::apache::thrift::protocol::T_STRING, 5); - xfer += oprot->writeString(this->operationName); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.references) { - xfer += oprot->writeFieldBegin("references", ::apache::thrift::protocol::T_LIST, 6); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->references.size())); - std::vector ::const_iterator _iter29; - for (_iter29 = this->references.begin(); _iter29 != this->references.end(); ++_iter29) - { - xfer += (*_iter29).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldBegin("flags", ::apache::thrift::protocol::T_I32, 7); - xfer += oprot->writeI32(this->flags); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("startTime", ::apache::thrift::protocol::T_I64, 8); - xfer += oprot->writeI64(this->startTime); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("duration", ::apache::thrift::protocol::T_I64, 9); - xfer += oprot->writeI64(this->duration); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.tags) { - xfer += oprot->writeFieldBegin("tags", ::apache::thrift::protocol::T_LIST, 10); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->tags.size())); - std::vector ::const_iterator _iter30; - for (_iter30 = this->tags.begin(); _iter30 != this->tags.end(); ++_iter30) - { - xfer += (*_iter30).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.logs) { - xfer += oprot->writeFieldBegin("logs", ::apache::thrift::protocol::T_LIST, 11); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->logs.size())); - std::vector ::const_iterator _iter31; - for (_iter31 = this->logs.begin(); _iter31 != this->logs.end(); ++_iter31) - { - xfer += (*_iter31).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Span &a, Span &b) { - using ::std::swap; - swap(a.traceIdLow, b.traceIdLow); - swap(a.traceIdHigh, b.traceIdHigh); - swap(a.spanId, b.spanId); - swap(a.parentSpanId, b.parentSpanId); - swap(a.operationName, b.operationName); - swap(a.references, b.references); - swap(a.flags, b.flags); - swap(a.startTime, b.startTime); - swap(a.duration, b.duration); - swap(a.tags, b.tags); - swap(a.logs, b.logs); - swap(a.__isset, b.__isset); -} - -Span::Span(const Span& other32) { - traceIdLow = other32.traceIdLow; - traceIdHigh = other32.traceIdHigh; - spanId = other32.spanId; - parentSpanId = other32.parentSpanId; - operationName = other32.operationName; - references = other32.references; - flags = other32.flags; - startTime = other32.startTime; - duration = other32.duration; - tags = other32.tags; - logs = other32.logs; - __isset = other32.__isset; -} -Span& Span::operator=(const Span& other33) { - traceIdLow = other33.traceIdLow; - traceIdHigh = other33.traceIdHigh; - spanId = other33.spanId; - parentSpanId = other33.parentSpanId; - operationName = other33.operationName; - references = other33.references; - flags = other33.flags; - startTime = other33.startTime; - duration = other33.duration; - tags = other33.tags; - logs = other33.logs; - __isset = other33.__isset; - return *this; -} -void Span::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Span("; - out << "traceIdLow=" << to_string(traceIdLow); - out << ", " << "traceIdHigh=" << to_string(traceIdHigh); - out << ", " << "spanId=" << to_string(spanId); - out << ", " << "parentSpanId=" << to_string(parentSpanId); - out << ", " << "operationName=" << to_string(operationName); - out << ", " << "references="; (__isset.references ? (out << to_string(references)) : (out << "")); - out << ", " << "flags=" << to_string(flags); - out << ", " << "startTime=" << to_string(startTime); - out << ", " << "duration=" << to_string(duration); - out << ", " << "tags="; (__isset.tags ? (out << to_string(tags)) : (out << "")); - out << ", " << "logs="; (__isset.logs ? (out << to_string(logs)) : (out << "")); - out << ")"; -} - - -Process::~Process() noexcept { -} - - -void Process::__set_serviceName(const std::string& val) { - this->serviceName = val; -} - -void Process::__set_tags(const std::vector & val) { - this->tags = val; -__isset.tags = true; -} -std::ostream& operator<<(std::ostream& out, const Process& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Process::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_serviceName = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->serviceName); - isset_serviceName = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->tags.clear(); - uint32_t _size34; - ::apache::thrift::protocol::TType _etype37; - xfer += iprot->readListBegin(_etype37, _size34); - this->tags.resize(_size34); - uint32_t _i38; - for (_i38 = 0; _i38 < _size34; ++_i38) - { - xfer += this->tags[_i38].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.tags = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_serviceName) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Process::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Process"); - - xfer += oprot->writeFieldBegin("serviceName", ::apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->serviceName); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.tags) { - xfer += oprot->writeFieldBegin("tags", ::apache::thrift::protocol::T_LIST, 2); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->tags.size())); - std::vector ::const_iterator _iter39; - for (_iter39 = this->tags.begin(); _iter39 != this->tags.end(); ++_iter39) - { - xfer += (*_iter39).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Process &a, Process &b) { - using ::std::swap; - swap(a.serviceName, b.serviceName); - swap(a.tags, b.tags); - swap(a.__isset, b.__isset); -} - -Process::Process(const Process& other40) { - serviceName = other40.serviceName; - tags = other40.tags; - __isset = other40.__isset; -} -Process& Process::operator=(const Process& other41) { - serviceName = other41.serviceName; - tags = other41.tags; - __isset = other41.__isset; - return *this; -} -void Process::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Process("; - out << "serviceName=" << to_string(serviceName); - out << ", " << "tags="; (__isset.tags ? (out << to_string(tags)) : (out << "")); - out << ")"; -} - - -Batch::~Batch() noexcept { -} - - -void Batch::__set_process(const Process& val) { - this->process = val; -} - -void Batch::__set_spans(const std::vector & val) { - this->spans = val; -} -std::ostream& operator<<(std::ostream& out, const Batch& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Batch::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_process = false; - bool isset_spans = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->process.read(iprot); - isset_process = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->spans.clear(); - uint32_t _size42; - ::apache::thrift::protocol::TType _etype45; - xfer += iprot->readListBegin(_etype45, _size42); - this->spans.resize(_size42); - uint32_t _i46; - for (_i46 = 0; _i46 < _size42; ++_i46) - { - xfer += this->spans[_i46].read(iprot); - } - xfer += iprot->readListEnd(); - } - isset_spans = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_process) - throw TProtocolException(TProtocolException::INVALID_DATA); - if (!isset_spans) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Batch::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Batch"); - - xfer += oprot->writeFieldBegin("process", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += this->process.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("spans", ::apache::thrift::protocol::T_LIST, 2); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->spans.size())); - std::vector ::const_iterator _iter47; - for (_iter47 = this->spans.begin(); _iter47 != this->spans.end(); ++_iter47) - { - xfer += (*_iter47).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Batch &a, Batch &b) { - using ::std::swap; - swap(a.process, b.process); - swap(a.spans, b.spans); -} - -Batch::Batch(const Batch& other48) { - process = other48.process; - spans = other48.spans; -} -Batch& Batch::operator=(const Batch& other49) { - process = other49.process; - spans = other49.spans; - return *this; -} -void Batch::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Batch("; - out << "process=" << to_string(process); - out << ", " << "spans=" << to_string(spans); - out << ")"; -} - - -BatchSubmitResponse::~BatchSubmitResponse() noexcept { -} - - -void BatchSubmitResponse::__set_ok(const bool val) { - this->ok = val; -} -std::ostream& operator<<(std::ostream& out, const BatchSubmitResponse& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t BatchSubmitResponse::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_ok = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->ok); - isset_ok = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_ok) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t BatchSubmitResponse::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("BatchSubmitResponse"); - - xfer += oprot->writeFieldBegin("ok", ::apache::thrift::protocol::T_BOOL, 1); - xfer += oprot->writeBool(this->ok); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(BatchSubmitResponse &a, BatchSubmitResponse &b) { - using ::std::swap; - swap(a.ok, b.ok); -} - -BatchSubmitResponse::BatchSubmitResponse(const BatchSubmitResponse& other50) { - ok = other50.ok; -} -BatchSubmitResponse& BatchSubmitResponse::operator=(const BatchSubmitResponse& other51) { - ok = other51.ok; - return *this; -} -void BatchSubmitResponse::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "BatchSubmitResponse("; - out << "ok=" << to_string(ok); - out << ")"; -} - -}} // namespace diff --git a/exporters/jaeger/thrift-gen/jaeger_types.h b/exporters/jaeger/thrift-gen/jaeger_types.h deleted file mode 100644 index b30a3740b3..0000000000 --- a/exporters/jaeger/thrift-gen/jaeger_types.h +++ /dev/null @@ -1,481 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef jaeger_TYPES_H -#define jaeger_TYPES_H - -#include - -#include -#include -#include -#include -#include - -#include -#include - - -namespace jaegertracing { namespace thrift { - -struct TagType { - enum type { - STRING = 0, - DOUBLE = 1, - BOOL = 2, - LONG = 3, - BINARY = 4 - }; -}; - -extern const std::map _TagType_VALUES_TO_NAMES; - -std::ostream& operator<<(std::ostream& out, const TagType::type& val); - -std::string to_string(const TagType::type& val); - -struct SpanRefType { - enum type { - CHILD_OF = 0, - FOLLOWS_FROM = 1 - }; -}; - -extern const std::map _SpanRefType_VALUES_TO_NAMES; - -std::ostream& operator<<(std::ostream& out, const SpanRefType::type& val); - -std::string to_string(const SpanRefType::type& val); - -class Tag; - -class Log; - -class SpanRef; - -class Span; - -class Process; - -class Batch; - -class BatchSubmitResponse; - -typedef struct _Tag__isset { - _Tag__isset() : vStr(false), vDouble(false), vBool(false), vLong(false), vBinary(false) {} - bool vStr :1; - bool vDouble :1; - bool vBool :1; - bool vLong :1; - bool vBinary :1; -} _Tag__isset; - -class Tag : public virtual ::apache::thrift::TBase { - public: - - Tag(const Tag&); - Tag& operator=(const Tag&); - Tag() : key(), vType((TagType::type)0), vStr(), vDouble(0), vBool(0), vLong(0), vBinary() { - } - - virtual ~Tag() noexcept; - std::string key; - /** - * - * @see TagType - */ - TagType::type vType; - std::string vStr; - double vDouble; - bool vBool; - int64_t vLong; - std::string vBinary; - - _Tag__isset __isset; - - void __set_key(const std::string& val); - - void __set_vType(const TagType::type val); - - void __set_vStr(const std::string& val); - - void __set_vDouble(const double val); - - void __set_vBool(const bool val); - - void __set_vLong(const int64_t val); - - void __set_vBinary(const std::string& val); - - bool operator == (const Tag & rhs) const - { - if (!(key == rhs.key)) - return false; - if (!(vType == rhs.vType)) - return false; - if (__isset.vStr != rhs.__isset.vStr) - return false; - else if (__isset.vStr && !(vStr == rhs.vStr)) - return false; - if (__isset.vDouble != rhs.__isset.vDouble) - return false; - else if (__isset.vDouble && !(vDouble == rhs.vDouble)) - return false; - if (__isset.vBool != rhs.__isset.vBool) - return false; - else if (__isset.vBool && !(vBool == rhs.vBool)) - return false; - if (__isset.vLong != rhs.__isset.vLong) - return false; - else if (__isset.vLong && !(vLong == rhs.vLong)) - return false; - if (__isset.vBinary != rhs.__isset.vBinary) - return false; - else if (__isset.vBinary && !(vBinary == rhs.vBinary)) - return false; - return true; - } - bool operator != (const Tag &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Tag & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Tag &a, Tag &b); - -std::ostream& operator<<(std::ostream& out, const Tag& obj); - - -class Log : public virtual ::apache::thrift::TBase { - public: - - Log(const Log&); - Log& operator=(const Log&); - Log() : timestamp(0) { - } - - virtual ~Log() noexcept; - int64_t timestamp; - std::vector fields; - - void __set_timestamp(const int64_t val); - - void __set_fields(const std::vector & val); - - bool operator == (const Log & rhs) const - { - if (!(timestamp == rhs.timestamp)) - return false; - if (!(fields == rhs.fields)) - return false; - return true; - } - bool operator != (const Log &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Log & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Log &a, Log &b); - -std::ostream& operator<<(std::ostream& out, const Log& obj); - - -class SpanRef : public virtual ::apache::thrift::TBase { - public: - - SpanRef(const SpanRef&); - SpanRef& operator=(const SpanRef&); - SpanRef() : refType((SpanRefType::type)0), traceIdLow(0), traceIdHigh(0), spanId(0) { - } - - virtual ~SpanRef() noexcept; - /** - * - * @see SpanRefType - */ - SpanRefType::type refType; - int64_t traceIdLow; - int64_t traceIdHigh; - int64_t spanId; - - void __set_refType(const SpanRefType::type val); - - void __set_traceIdLow(const int64_t val); - - void __set_traceIdHigh(const int64_t val); - - void __set_spanId(const int64_t val); - - bool operator == (const SpanRef & rhs) const - { - if (!(refType == rhs.refType)) - return false; - if (!(traceIdLow == rhs.traceIdLow)) - return false; - if (!(traceIdHigh == rhs.traceIdHigh)) - return false; - if (!(spanId == rhs.spanId)) - return false; - return true; - } - bool operator != (const SpanRef &rhs) const { - return !(*this == rhs); - } - - bool operator < (const SpanRef & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(SpanRef &a, SpanRef &b); - -std::ostream& operator<<(std::ostream& out, const SpanRef& obj); - -typedef struct _Span__isset { - _Span__isset() : references(false), tags(false), logs(false) {} - bool references :1; - bool tags :1; - bool logs :1; -} _Span__isset; - -class Span : public virtual ::apache::thrift::TBase { - public: - - Span(const Span&); - Span& operator=(const Span&); - Span() : traceIdLow(0), traceIdHigh(0), spanId(0), parentSpanId(0), operationName(), flags(0), startTime(0), duration(0) { - } - - virtual ~Span() noexcept; - int64_t traceIdLow; - int64_t traceIdHigh; - int64_t spanId; - int64_t parentSpanId; - std::string operationName; - std::vector references; - int32_t flags; - int64_t startTime; - int64_t duration; - std::vector tags; - std::vector logs; - - _Span__isset __isset; - - void __set_traceIdLow(const int64_t val); - - void __set_traceIdHigh(const int64_t val); - - void __set_spanId(const int64_t val); - - void __set_parentSpanId(const int64_t val); - - void __set_operationName(const std::string& val); - - void __set_references(const std::vector & val); - - void __set_flags(const int32_t val); - - void __set_startTime(const int64_t val); - - void __set_duration(const int64_t val); - - void __set_tags(const std::vector & val); - - void __set_logs(const std::vector & val); - - bool operator == (const Span & rhs) const - { - if (!(traceIdLow == rhs.traceIdLow)) - return false; - if (!(traceIdHigh == rhs.traceIdHigh)) - return false; - if (!(spanId == rhs.spanId)) - return false; - if (!(parentSpanId == rhs.parentSpanId)) - return false; - if (!(operationName == rhs.operationName)) - return false; - if (__isset.references != rhs.__isset.references) - return false; - else if (__isset.references && !(references == rhs.references)) - return false; - if (!(flags == rhs.flags)) - return false; - if (!(startTime == rhs.startTime)) - return false; - if (!(duration == rhs.duration)) - return false; - if (__isset.tags != rhs.__isset.tags) - return false; - else if (__isset.tags && !(tags == rhs.tags)) - return false; - if (__isset.logs != rhs.__isset.logs) - return false; - else if (__isset.logs && !(logs == rhs.logs)) - return false; - return true; - } - bool operator != (const Span &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Span & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Span &a, Span &b); - -std::ostream& operator<<(std::ostream& out, const Span& obj); - -typedef struct _Process__isset { - _Process__isset() : tags(false) {} - bool tags :1; -} _Process__isset; - -class Process : public virtual ::apache::thrift::TBase { - public: - - Process(const Process&); - Process& operator=(const Process&); - Process() : serviceName() { - } - - virtual ~Process() noexcept; - std::string serviceName; - std::vector tags; - - _Process__isset __isset; - - void __set_serviceName(const std::string& val); - - void __set_tags(const std::vector & val); - - bool operator == (const Process & rhs) const - { - if (!(serviceName == rhs.serviceName)) - return false; - if (__isset.tags != rhs.__isset.tags) - return false; - else if (__isset.tags && !(tags == rhs.tags)) - return false; - return true; - } - bool operator != (const Process &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Process & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Process &a, Process &b); - -std::ostream& operator<<(std::ostream& out, const Process& obj); - - -class Batch : public virtual ::apache::thrift::TBase { - public: - - Batch(const Batch&); - Batch& operator=(const Batch&); - Batch() { - } - - virtual ~Batch() noexcept; - Process process; - std::vector spans; - - void __set_process(const Process& val); - - void __set_spans(const std::vector & val); - - bool operator == (const Batch & rhs) const - { - if (!(process == rhs.process)) - return false; - if (!(spans == rhs.spans)) - return false; - return true; - } - bool operator != (const Batch &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Batch & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Batch &a, Batch &b); - -std::ostream& operator<<(std::ostream& out, const Batch& obj); - - -class BatchSubmitResponse : public virtual ::apache::thrift::TBase { - public: - - BatchSubmitResponse(const BatchSubmitResponse&); - BatchSubmitResponse& operator=(const BatchSubmitResponse&); - BatchSubmitResponse() : ok(0) { - } - - virtual ~BatchSubmitResponse() noexcept; - bool ok; - - void __set_ok(const bool val); - - bool operator == (const BatchSubmitResponse & rhs) const - { - if (!(ok == rhs.ok)) - return false; - return true; - } - bool operator != (const BatchSubmitResponse &rhs) const { - return !(*this == rhs); - } - - bool operator < (const BatchSubmitResponse & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(BatchSubmitResponse &a, BatchSubmitResponse &b); - -std::ostream& operator<<(std::ostream& out, const BatchSubmitResponse& obj); - -}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/zipkincore_constants.cpp b/exporters/jaeger/thrift-gen/zipkincore_constants.cpp deleted file mode 100644 index 8dd451e483..0000000000 --- a/exporters/jaeger/thrift-gen/zipkincore_constants.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "zipkincore_constants.h" - -namespace twitter { namespace zipkin { namespace thrift { - -const zipkincoreConstants g_zipkincore_constants; - -zipkincoreConstants::zipkincoreConstants() { - CLIENT_SEND = "cs"; - - CLIENT_RECV = "cr"; - - SERVER_SEND = "ss"; - - SERVER_RECV = "sr"; - - MESSAGE_SEND = "ms"; - - MESSAGE_RECV = "mr"; - - WIRE_SEND = "ws"; - - WIRE_RECV = "wr"; - - CLIENT_SEND_FRAGMENT = "csf"; - - CLIENT_RECV_FRAGMENT = "crf"; - - SERVER_SEND_FRAGMENT = "ssf"; - - SERVER_RECV_FRAGMENT = "srf"; - - LOCAL_COMPONENT = "lc"; - - CLIENT_ADDR = "ca"; - - SERVER_ADDR = "sa"; - - MESSAGE_ADDR = "ma"; - -} - -}}} // namespace - diff --git a/exporters/jaeger/thrift-gen/zipkincore_constants.h b/exporters/jaeger/thrift-gen/zipkincore_constants.h deleted file mode 100644 index 22b4b3b67c..0000000000 --- a/exporters/jaeger/thrift-gen/zipkincore_constants.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef zipkincore_CONSTANTS_H -#define zipkincore_CONSTANTS_H - -#include "zipkincore_types.h" - -namespace twitter { namespace zipkin { namespace thrift { - -class zipkincoreConstants { - public: - zipkincoreConstants(); - - std::string CLIENT_SEND; - std::string CLIENT_RECV; - std::string SERVER_SEND; - std::string SERVER_RECV; - std::string MESSAGE_SEND; - std::string MESSAGE_RECV; - std::string WIRE_SEND; - std::string WIRE_RECV; - std::string CLIENT_SEND_FRAGMENT; - std::string CLIENT_RECV_FRAGMENT; - std::string SERVER_SEND_FRAGMENT; - std::string SERVER_RECV_FRAGMENT; - std::string LOCAL_COMPONENT; - std::string CLIENT_ADDR; - std::string SERVER_ADDR; - std::string MESSAGE_ADDR; -}; - -extern const zipkincoreConstants g_zipkincore_constants; - -}}} // namespace - -#endif diff --git a/exporters/jaeger/thrift-gen/zipkincore_types.cpp b/exporters/jaeger/thrift-gen/zipkincore_types.cpp deleted file mode 100644 index a8b52e902d..0000000000 --- a/exporters/jaeger/thrift-gen/zipkincore_types.cpp +++ /dev/null @@ -1,913 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "zipkincore_types.h" - -#include -#include - -#include - -namespace twitter { namespace zipkin { namespace thrift { - -int _kAnnotationTypeValues[] = { - AnnotationType::BOOL, - AnnotationType::BYTES, - AnnotationType::I16, - AnnotationType::I32, - AnnotationType::I64, - AnnotationType::DOUBLE, - AnnotationType::STRING -}; -const char* _kAnnotationTypeNames[] = { - "BOOL", - "BYTES", - "I16", - "I32", - "I64", - "DOUBLE", - "STRING" -}; -const std::map _AnnotationType_VALUES_TO_NAMES(::apache::thrift::TEnumIterator(7, _kAnnotationTypeValues, _kAnnotationTypeNames), ::apache::thrift::TEnumIterator(-1, nullptr, nullptr)); - -std::ostream& operator<<(std::ostream& out, const AnnotationType::type& val) { - std::map::const_iterator it = _AnnotationType_VALUES_TO_NAMES.find(val); - if (it != _AnnotationType_VALUES_TO_NAMES.end()) { - out << it->second; - } else { - out << static_cast(val); - } - return out; -} - -std::string to_string(const AnnotationType::type& val) { - std::map::const_iterator it = _AnnotationType_VALUES_TO_NAMES.find(val); - if (it != _AnnotationType_VALUES_TO_NAMES.end()) { - return std::string(it->second); - } else { - return std::to_string(static_cast(val)); - } -} - - -Endpoint::~Endpoint() noexcept { -} - - -void Endpoint::__set_ipv4(const int32_t val) { - this->ipv4 = val; -} - -void Endpoint::__set_port(const int16_t val) { - this->port = val; -} - -void Endpoint::__set_service_name(const std::string& val) { - this->service_name = val; -} - -void Endpoint::__set_ipv6(const std::string& val) { - this->ipv6 = val; -__isset.ipv6 = true; -} -std::ostream& operator<<(std::ostream& out, const Endpoint& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Endpoint::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->ipv4); - this->__isset.ipv4 = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I16) { - xfer += iprot->readI16(this->port); - this->__isset.port = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->service_name); - this->__isset.service_name = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readBinary(this->ipv6); - this->__isset.ipv6 = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Endpoint::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Endpoint"); - - xfer += oprot->writeFieldBegin("ipv4", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32(this->ipv4); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("port", ::apache::thrift::protocol::T_I16, 2); - xfer += oprot->writeI16(this->port); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("service_name", ::apache::thrift::protocol::T_STRING, 3); - xfer += oprot->writeString(this->service_name); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.ipv6) { - xfer += oprot->writeFieldBegin("ipv6", ::apache::thrift::protocol::T_STRING, 4); - xfer += oprot->writeBinary(this->ipv6); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Endpoint &a, Endpoint &b) { - using ::std::swap; - swap(a.ipv4, b.ipv4); - swap(a.port, b.port); - swap(a.service_name, b.service_name); - swap(a.ipv6, b.ipv6); - swap(a.__isset, b.__isset); -} - -Endpoint::Endpoint(const Endpoint& other0) { - ipv4 = other0.ipv4; - port = other0.port; - service_name = other0.service_name; - ipv6 = other0.ipv6; - __isset = other0.__isset; -} -Endpoint& Endpoint::operator=(const Endpoint& other1) { - ipv4 = other1.ipv4; - port = other1.port; - service_name = other1.service_name; - ipv6 = other1.ipv6; - __isset = other1.__isset; - return *this; -} -void Endpoint::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Endpoint("; - out << "ipv4=" << to_string(ipv4); - out << ", " << "port=" << to_string(port); - out << ", " << "service_name=" << to_string(service_name); - out << ", " << "ipv6="; (__isset.ipv6 ? (out << to_string(ipv6)) : (out << "")); - out << ")"; -} - - -Annotation::~Annotation() noexcept { -} - - -void Annotation::__set_timestamp(const int64_t val) { - this->timestamp = val; -} - -void Annotation::__set_value(const std::string& val) { - this->value = val; -} - -void Annotation::__set_host(const Endpoint& val) { - this->host = val; -__isset.host = true; -} -std::ostream& operator<<(std::ostream& out, const Annotation& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Annotation::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->timestamp); - this->__isset.timestamp = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->value); - this->__isset.value = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->host.read(iprot); - this->__isset.host = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Annotation::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Annotation"); - - xfer += oprot->writeFieldBegin("timestamp", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->timestamp); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("value", ::apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeString(this->value); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.host) { - xfer += oprot->writeFieldBegin("host", ::apache::thrift::protocol::T_STRUCT, 3); - xfer += this->host.write(oprot); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Annotation &a, Annotation &b) { - using ::std::swap; - swap(a.timestamp, b.timestamp); - swap(a.value, b.value); - swap(a.host, b.host); - swap(a.__isset, b.__isset); -} - -Annotation::Annotation(const Annotation& other2) { - timestamp = other2.timestamp; - value = other2.value; - host = other2.host; - __isset = other2.__isset; -} -Annotation& Annotation::operator=(const Annotation& other3) { - timestamp = other3.timestamp; - value = other3.value; - host = other3.host; - __isset = other3.__isset; - return *this; -} -void Annotation::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Annotation("; - out << "timestamp=" << to_string(timestamp); - out << ", " << "value=" << to_string(value); - out << ", " << "host="; (__isset.host ? (out << to_string(host)) : (out << "")); - out << ")"; -} - - -BinaryAnnotation::~BinaryAnnotation() noexcept { -} - - -void BinaryAnnotation::__set_key(const std::string& val) { - this->key = val; -} - -void BinaryAnnotation::__set_value(const std::string& val) { - this->value = val; -} - -void BinaryAnnotation::__set_annotation_type(const AnnotationType::type val) { - this->annotation_type = val; -} - -void BinaryAnnotation::__set_host(const Endpoint& val) { - this->host = val; -__isset.host = true; -} -std::ostream& operator<<(std::ostream& out, const BinaryAnnotation& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t BinaryAnnotation::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->key); - this->__isset.key = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readBinary(this->value); - this->__isset.value = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I32) { - int32_t ecast4; - xfer += iprot->readI32(ecast4); - this->annotation_type = (AnnotationType::type)ecast4; - this->__isset.annotation_type = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->host.read(iprot); - this->__isset.host = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t BinaryAnnotation::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("BinaryAnnotation"); - - xfer += oprot->writeFieldBegin("key", ::apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->key); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("value", ::apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeBinary(this->value); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("annotation_type", ::apache::thrift::protocol::T_I32, 3); - xfer += oprot->writeI32((int32_t)this->annotation_type); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.host) { - xfer += oprot->writeFieldBegin("host", ::apache::thrift::protocol::T_STRUCT, 4); - xfer += this->host.write(oprot); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(BinaryAnnotation &a, BinaryAnnotation &b) { - using ::std::swap; - swap(a.key, b.key); - swap(a.value, b.value); - swap(a.annotation_type, b.annotation_type); - swap(a.host, b.host); - swap(a.__isset, b.__isset); -} - -BinaryAnnotation::BinaryAnnotation(const BinaryAnnotation& other5) { - key = other5.key; - value = other5.value; - annotation_type = other5.annotation_type; - host = other5.host; - __isset = other5.__isset; -} -BinaryAnnotation& BinaryAnnotation::operator=(const BinaryAnnotation& other6) { - key = other6.key; - value = other6.value; - annotation_type = other6.annotation_type; - host = other6.host; - __isset = other6.__isset; - return *this; -} -void BinaryAnnotation::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "BinaryAnnotation("; - out << "key=" << to_string(key); - out << ", " << "value=" << to_string(value); - out << ", " << "annotation_type=" << to_string(annotation_type); - out << ", " << "host="; (__isset.host ? (out << to_string(host)) : (out << "")); - out << ")"; -} - - -Span::~Span() noexcept { -} - - -void Span::__set_trace_id(const int64_t val) { - this->trace_id = val; -} - -void Span::__set_name(const std::string& val) { - this->name = val; -} - -void Span::__set_id(const int64_t val) { - this->id = val; -} - -void Span::__set_parent_id(const int64_t val) { - this->parent_id = val; -__isset.parent_id = true; -} - -void Span::__set_annotations(const std::vector & val) { - this->annotations = val; -} - -void Span::__set_binary_annotations(const std::vector & val) { - this->binary_annotations = val; -} - -void Span::__set_debug(const bool val) { - this->debug = val; -__isset.debug = true; -} - -void Span::__set_timestamp(const int64_t val) { - this->timestamp = val; -__isset.timestamp = true; -} - -void Span::__set_duration(const int64_t val) { - this->duration = val; -__isset.duration = true; -} - -void Span::__set_trace_id_high(const int64_t val) { - this->trace_id_high = val; -__isset.trace_id_high = true; -} -std::ostream& operator<<(std::ostream& out, const Span& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Span::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->trace_id); - this->__isset.trace_id = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->name); - this->__isset.name = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->id); - this->__isset.id = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->parent_id); - this->__isset.parent_id = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 6: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->annotations.clear(); - uint32_t _size7; - ::apache::thrift::protocol::TType _etype10; - xfer += iprot->readListBegin(_etype10, _size7); - this->annotations.resize(_size7); - uint32_t _i11; - for (_i11 = 0; _i11 < _size7; ++_i11) - { - xfer += this->annotations[_i11].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.annotations = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 8: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->binary_annotations.clear(); - uint32_t _size12; - ::apache::thrift::protocol::TType _etype15; - xfer += iprot->readListBegin(_etype15, _size12); - this->binary_annotations.resize(_size12); - uint32_t _i16; - for (_i16 = 0; _i16 < _size12; ++_i16) - { - xfer += this->binary_annotations[_i16].read(iprot); - } - xfer += iprot->readListEnd(); - } - this->__isset.binary_annotations = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 9: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->debug); - this->__isset.debug = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 10: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->timestamp); - this->__isset.timestamp = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 11: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->duration); - this->__isset.duration = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 12: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->trace_id_high); - this->__isset.trace_id_high = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t Span::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Span"); - - xfer += oprot->writeFieldBegin("trace_id", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->trace_id); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("name", ::apache::thrift::protocol::T_STRING, 3); - xfer += oprot->writeString(this->name); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("id", ::apache::thrift::protocol::T_I64, 4); - xfer += oprot->writeI64(this->id); - xfer += oprot->writeFieldEnd(); - - if (this->__isset.parent_id) { - xfer += oprot->writeFieldBegin("parent_id", ::apache::thrift::protocol::T_I64, 5); - xfer += oprot->writeI64(this->parent_id); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldBegin("annotations", ::apache::thrift::protocol::T_LIST, 6); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->annotations.size())); - std::vector ::const_iterator _iter17; - for (_iter17 = this->annotations.begin(); _iter17 != this->annotations.end(); ++_iter17) - { - xfer += (*_iter17).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("binary_annotations", ::apache::thrift::protocol::T_LIST, 8); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRUCT, static_cast(this->binary_annotations.size())); - std::vector ::const_iterator _iter18; - for (_iter18 = this->binary_annotations.begin(); _iter18 != this->binary_annotations.end(); ++_iter18) - { - xfer += (*_iter18).write(oprot); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - if (this->__isset.debug) { - xfer += oprot->writeFieldBegin("debug", ::apache::thrift::protocol::T_BOOL, 9); - xfer += oprot->writeBool(this->debug); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.timestamp) { - xfer += oprot->writeFieldBegin("timestamp", ::apache::thrift::protocol::T_I64, 10); - xfer += oprot->writeI64(this->timestamp); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.duration) { - xfer += oprot->writeFieldBegin("duration", ::apache::thrift::protocol::T_I64, 11); - xfer += oprot->writeI64(this->duration); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.trace_id_high) { - xfer += oprot->writeFieldBegin("trace_id_high", ::apache::thrift::protocol::T_I64, 12); - xfer += oprot->writeI64(this->trace_id_high); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Span &a, Span &b) { - using ::std::swap; - swap(a.trace_id, b.trace_id); - swap(a.name, b.name); - swap(a.id, b.id); - swap(a.parent_id, b.parent_id); - swap(a.annotations, b.annotations); - swap(a.binary_annotations, b.binary_annotations); - swap(a.debug, b.debug); - swap(a.timestamp, b.timestamp); - swap(a.duration, b.duration); - swap(a.trace_id_high, b.trace_id_high); - swap(a.__isset, b.__isset); -} - -Span::Span(const Span& other19) { - trace_id = other19.trace_id; - name = other19.name; - id = other19.id; - parent_id = other19.parent_id; - annotations = other19.annotations; - binary_annotations = other19.binary_annotations; - debug = other19.debug; - timestamp = other19.timestamp; - duration = other19.duration; - trace_id_high = other19.trace_id_high; - __isset = other19.__isset; -} -Span& Span::operator=(const Span& other20) { - trace_id = other20.trace_id; - name = other20.name; - id = other20.id; - parent_id = other20.parent_id; - annotations = other20.annotations; - binary_annotations = other20.binary_annotations; - debug = other20.debug; - timestamp = other20.timestamp; - duration = other20.duration; - trace_id_high = other20.trace_id_high; - __isset = other20.__isset; - return *this; -} -void Span::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Span("; - out << "trace_id=" << to_string(trace_id); - out << ", " << "name=" << to_string(name); - out << ", " << "id=" << to_string(id); - out << ", " << "parent_id="; (__isset.parent_id ? (out << to_string(parent_id)) : (out << "")); - out << ", " << "annotations=" << to_string(annotations); - out << ", " << "binary_annotations=" << to_string(binary_annotations); - out << ", " << "debug="; (__isset.debug ? (out << to_string(debug)) : (out << "")); - out << ", " << "timestamp="; (__isset.timestamp ? (out << to_string(timestamp)) : (out << "")); - out << ", " << "duration="; (__isset.duration ? (out << to_string(duration)) : (out << "")); - out << ", " << "trace_id_high="; (__isset.trace_id_high ? (out << to_string(trace_id_high)) : (out << "")); - out << ")"; -} - - -Response::~Response() noexcept { -} - - -void Response::__set_ok(const bool val) { - this->ok = val; -} -std::ostream& operator<<(std::ostream& out, const Response& obj) -{ - obj.printTo(out); - return out; -} - - -uint32_t Response::read(::apache::thrift::protocol::TProtocol* iprot) { - - ::apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - bool isset_ok = false; - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->ok); - isset_ok = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - if (!isset_ok) - throw TProtocolException(TProtocolException::INVALID_DATA); - return xfer; -} - -uint32_t Response::write(::apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("Response"); - - xfer += oprot->writeFieldBegin("ok", ::apache::thrift::protocol::T_BOOL, 1); - xfer += oprot->writeBool(this->ok); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(Response &a, Response &b) { - using ::std::swap; - swap(a.ok, b.ok); -} - -Response::Response(const Response& other21) { - ok = other21.ok; -} -Response& Response::operator=(const Response& other22) { - ok = other22.ok; - return *this; -} -void Response::printTo(std::ostream& out) const { - using ::apache::thrift::to_string; - out << "Response("; - out << "ok=" << to_string(ok); - out << ")"; -} - -}}} // namespace diff --git a/exporters/jaeger/thrift-gen/zipkincore_types.h b/exporters/jaeger/thrift-gen/zipkincore_types.h deleted file mode 100644 index c03421f434..0000000000 --- a/exporters/jaeger/thrift-gen/zipkincore_types.h +++ /dev/null @@ -1,493 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.14.0) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef zipkincore_TYPES_H -#define zipkincore_TYPES_H - -#include - -#include -#include -#include -#include -#include - -#include -#include - - -namespace twitter { namespace zipkin { namespace thrift { - -struct AnnotationType { - enum type { - BOOL = 0, - BYTES = 1, - I16 = 2, - I32 = 3, - I64 = 4, - DOUBLE = 5, - STRING = 6 - }; -}; - -extern const std::map _AnnotationType_VALUES_TO_NAMES; - -std::ostream& operator<<(std::ostream& out, const AnnotationType::type& val); - -std::string to_string(const AnnotationType::type& val); - -class Endpoint; - -class Annotation; - -class BinaryAnnotation; - -class Span; - -class Response; - -typedef struct _Endpoint__isset { - _Endpoint__isset() : ipv4(false), port(false), service_name(false), ipv6(false) {} - bool ipv4 :1; - bool port :1; - bool service_name :1; - bool ipv6 :1; -} _Endpoint__isset; - -/** - * Indicates the network context of a service recording an annotation with two - * exceptions. - * - * When a BinaryAnnotation, and key is CLIENT_ADDR or SERVER_ADDR, - * the endpoint indicates the source or destination of an RPC. This exception - * allows zipkin to display network context of uninstrumented services, or - * clients such as web browsers. - */ -class Endpoint : public virtual ::apache::thrift::TBase { - public: - - Endpoint(const Endpoint&); - Endpoint& operator=(const Endpoint&); - Endpoint() : ipv4(0), port(0), service_name(), ipv6() { - } - - virtual ~Endpoint() noexcept; - /** - * IPv4 host address packed into 4 bytes. - * - * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 - */ - int32_t ipv4; - /** - * IPv4 port - * - * Note: this is to be treated as an unsigned integer, so watch for negatives. - * - * Conventionally, when the port isn't known, port = 0. - */ - int16_t port; - /** - * Service name in lowercase, such as "memcache" or "zipkin-web" - * - * Conventionally, when the service name isn't known, service_name = "unknown". - */ - std::string service_name; - /** - * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() - */ - std::string ipv6; - - _Endpoint__isset __isset; - - void __set_ipv4(const int32_t val); - - void __set_port(const int16_t val); - - void __set_service_name(const std::string& val); - - void __set_ipv6(const std::string& val); - - bool operator == (const Endpoint & rhs) const - { - if (!(ipv4 == rhs.ipv4)) - return false; - if (!(port == rhs.port)) - return false; - if (!(service_name == rhs.service_name)) - return false; - if (__isset.ipv6 != rhs.__isset.ipv6) - return false; - else if (__isset.ipv6 && !(ipv6 == rhs.ipv6)) - return false; - return true; - } - bool operator != (const Endpoint &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Endpoint & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Endpoint &a, Endpoint &b); - -std::ostream& operator<<(std::ostream& out, const Endpoint& obj); - -typedef struct _Annotation__isset { - _Annotation__isset() : timestamp(false), value(false), host(false) {} - bool timestamp :1; - bool value :1; - bool host :1; -} _Annotation__isset; - -/** - * An annotation is similar to a log statement. It includes a host field which - * allows these events to be attributed properly, and also aggregatable. - */ -class Annotation : public virtual ::apache::thrift::TBase { - public: - - Annotation(const Annotation&); - Annotation& operator=(const Annotation&); - Annotation() : timestamp(0), value() { - } - - virtual ~Annotation() noexcept; - /** - * Microseconds from epoch. - * - * This value should use the most precise value possible. For example, - * gettimeofday or syncing nanoTime against a tick of currentTimeMillis. - */ - int64_t timestamp; - std::string value; - /** - * Always the host that recorded the event. By specifying the host you allow - * rollup of all events (such as client requests to a service) by IP address. - */ - Endpoint host; - - _Annotation__isset __isset; - - void __set_timestamp(const int64_t val); - - void __set_value(const std::string& val); - - void __set_host(const Endpoint& val); - - bool operator == (const Annotation & rhs) const - { - if (!(timestamp == rhs.timestamp)) - return false; - if (!(value == rhs.value)) - return false; - if (__isset.host != rhs.__isset.host) - return false; - else if (__isset.host && !(host == rhs.host)) - return false; - return true; - } - bool operator != (const Annotation &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Annotation & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Annotation &a, Annotation &b); - -std::ostream& operator<<(std::ostream& out, const Annotation& obj); - -typedef struct _BinaryAnnotation__isset { - _BinaryAnnotation__isset() : key(false), value(false), annotation_type(false), host(false) {} - bool key :1; - bool value :1; - bool annotation_type :1; - bool host :1; -} _BinaryAnnotation__isset; - -/** - * Binary annotations are tags applied to a Span to give it context. For - * example, a binary annotation of "http.uri" could the path to a resource in a - * RPC call. - * - * Binary annotations of type STRING are always queryable, though more a - * historical implementation detail than a structural concern. - * - * Binary annotations can repeat, and vary on the host. Similar to Annotation, - * the host indicates who logged the event. This allows you to tell the - * difference between the client and server side of the same key. For example, - * the key "http.uri" might be different on the client and server side due to - * rewriting, like "/api/v1/myresource" vs "/myresource. Via the host field, - * you can see the different points of view, which often help in debugging. - */ -class BinaryAnnotation : public virtual ::apache::thrift::TBase { - public: - - BinaryAnnotation(const BinaryAnnotation&); - BinaryAnnotation& operator=(const BinaryAnnotation&); - BinaryAnnotation() : key(), value(), annotation_type((AnnotationType::type)0) { - } - - virtual ~BinaryAnnotation() noexcept; - std::string key; - std::string value; - /** - * - * @see AnnotationType - */ - AnnotationType::type annotation_type; - /** - * The host that recorded tag, which allows you to differentiate between - * multiple tags with the same key. There are two exceptions to this. - * - * When the key is CLIENT_ADDR or SERVER_ADDR, host indicates the source or - * destination of an RPC. This exception allows zipkin to display network - * context of uninstrumented services, or clients such as web browsers. - */ - Endpoint host; - - _BinaryAnnotation__isset __isset; - - void __set_key(const std::string& val); - - void __set_value(const std::string& val); - - void __set_annotation_type(const AnnotationType::type val); - - void __set_host(const Endpoint& val); - - bool operator == (const BinaryAnnotation & rhs) const - { - if (!(key == rhs.key)) - return false; - if (!(value == rhs.value)) - return false; - if (!(annotation_type == rhs.annotation_type)) - return false; - if (__isset.host != rhs.__isset.host) - return false; - else if (__isset.host && !(host == rhs.host)) - return false; - return true; - } - bool operator != (const BinaryAnnotation &rhs) const { - return !(*this == rhs); - } - - bool operator < (const BinaryAnnotation & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(BinaryAnnotation &a, BinaryAnnotation &b); - -std::ostream& operator<<(std::ostream& out, const BinaryAnnotation& obj); - -typedef struct _Span__isset { - _Span__isset() : trace_id(false), name(false), id(false), parent_id(false), annotations(false), binary_annotations(false), debug(true), timestamp(false), duration(false), trace_id_high(false) {} - bool trace_id :1; - bool name :1; - bool id :1; - bool parent_id :1; - bool annotations :1; - bool binary_annotations :1; - bool debug :1; - bool timestamp :1; - bool duration :1; - bool trace_id_high :1; -} _Span__isset; - -/** - * A trace is a series of spans (often RPC calls) which form a latency tree. - * - * The root span is where trace_id = id and parent_id = Nil. The root span is - * usually the longest interval in the trace, starting with a SERVER_RECV - * annotation and ending with a SERVER_SEND. - */ -class Span : public virtual ::apache::thrift::TBase { - public: - - Span(const Span&); - Span& operator=(const Span&); - Span() : trace_id(0), name(), id(0), parent_id(0), debug(false), timestamp(0), duration(0), trace_id_high(0) { - } - - virtual ~Span() noexcept; - int64_t trace_id; - /** - * Span name in lowercase, rpc method for example - * - * Conventionally, when the span name isn't known, name = "unknown". - */ - std::string name; - int64_t id; - int64_t parent_id; - std::vector annotations; - std::vector binary_annotations; - bool debug; - /** - * Microseconds from epoch of the creation of this span. - * - * This value should be set directly by instrumentation, using the most - * precise value possible. For example, gettimeofday or syncing nanoTime - * against a tick of currentTimeMillis. - * - * For compatibility with instrumentation that precede this field, collectors - * or span stores can derive this via Annotation.timestamp. - * For example, SERVER_RECV.timestamp or CLIENT_SEND.timestamp. - * - * This field is optional for compatibility with old data: first-party span - * stores are expected to support this at time of introduction. - */ - int64_t timestamp; - /** - * Measurement of duration in microseconds, used to support queries. - * - * This value should be set directly, where possible. Doing so encourages - * precise measurement decoupled from problems of clocks, such as skew or NTP - * updates causing time to move backwards. - * - * For compatibility with instrumentation that precede this field, collectors - * or span stores can derive this by subtracting Annotation.timestamp. - * For example, SERVER_SEND.timestamp - SERVER_RECV.timestamp. - * - * If this field is persisted as unset, zipkin will continue to work, except - * duration query support will be implementation-specific. Similarly, setting - * this field non-atomically is implementation-specific. - * - * This field is i64 vs i32 to support spans longer than 35 minutes. - */ - int64_t duration; - /** - * Optional unique 8-byte additional identifier for a trace. If non zero, this - * means the trace uses 128 bit traceIds instead of 64 bit. - */ - int64_t trace_id_high; - - _Span__isset __isset; - - void __set_trace_id(const int64_t val); - - void __set_name(const std::string& val); - - void __set_id(const int64_t val); - - void __set_parent_id(const int64_t val); - - void __set_annotations(const std::vector & val); - - void __set_binary_annotations(const std::vector & val); - - void __set_debug(const bool val); - - void __set_timestamp(const int64_t val); - - void __set_duration(const int64_t val); - - void __set_trace_id_high(const int64_t val); - - bool operator == (const Span & rhs) const - { - if (!(trace_id == rhs.trace_id)) - return false; - if (!(name == rhs.name)) - return false; - if (!(id == rhs.id)) - return false; - if (__isset.parent_id != rhs.__isset.parent_id) - return false; - else if (__isset.parent_id && !(parent_id == rhs.parent_id)) - return false; - if (!(annotations == rhs.annotations)) - return false; - if (!(binary_annotations == rhs.binary_annotations)) - return false; - if (__isset.debug != rhs.__isset.debug) - return false; - else if (__isset.debug && !(debug == rhs.debug)) - return false; - if (__isset.timestamp != rhs.__isset.timestamp) - return false; - else if (__isset.timestamp && !(timestamp == rhs.timestamp)) - return false; - if (__isset.duration != rhs.__isset.duration) - return false; - else if (__isset.duration && !(duration == rhs.duration)) - return false; - if (__isset.trace_id_high != rhs.__isset.trace_id_high) - return false; - else if (__isset.trace_id_high && !(trace_id_high == rhs.trace_id_high)) - return false; - return true; - } - bool operator != (const Span &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Span & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Span &a, Span &b); - -std::ostream& operator<<(std::ostream& out, const Span& obj); - - -class Response : public virtual ::apache::thrift::TBase { - public: - - Response(const Response&); - Response& operator=(const Response&); - Response() : ok(0) { - } - - virtual ~Response() noexcept; - bool ok; - - void __set_ok(const bool val); - - bool operator == (const Response & rhs) const - { - if (!(ok == rhs.ok)) - return false; - return true; - } - bool operator != (const Response &rhs) const { - return !(*this == rhs); - } - - bool operator < (const Response & ) const; - - uint32_t read(::apache::thrift::protocol::TProtocol* iprot); - uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; - - virtual void printTo(std::ostream& out) const; -}; - -void swap(Response &a, Response &b); - -std::ostream& operator<<(std::ostream& out, const Response& obj); - -}}} // namespace - -#endif diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 8c66a251a4..2bf12b3a35 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -78,7 +78,7 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter // For testing friend class ZipkinExporterTestPeer; /** - * Create an ZipkinExporter using the specified thrift sender. + * Create an ZipkinExporter using the specified http client. * Only tests can call this constructor directly. * @param http_client the http client to be used for exporting */ diff --git a/third_party/boost/LICENSE.md b/third_party/boost/LICENSE.md deleted file mode 100644 index 44da875b02..0000000000 --- a/third_party/boost/LICENSE.md +++ /dev/null @@ -1,23 +0,0 @@ -# Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/third_party_release b/third_party_release index 53ef723721..0864c60471 100644 --- a/third_party_release +++ b/third_party_release @@ -14,7 +14,6 @@ # gRPC=v1.49.2 -thrift=0.14.1 abseil=20220623.1 benchmark=v1.7.1 googletest=release-1.12.1 diff --git a/tools/format.sh b/tools/format.sh index 2c16204acb..5b4e91277d 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -10,7 +10,7 @@ fi set -e -FIND="find . -name third_party -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name .build -prune -o -name out -prune -o -name .vs -prune -o -name opentelemetry_logo.png -prune -o -name TraceLoggingDynamic.h -prune -o -name thrift-gen -prune -o" +FIND="find . -name third_party -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name .build -prune -o -name out -prune -o -name .vs -prune -o -name opentelemetry_logo.png -prune -o -name TraceLoggingDynamic.h -prune -o" # GNU syntax. SED=(sed -i) From ebbcd48a881c7e5e7939645be50570e48a226244 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Jul 2023 09:00:02 +0200 Subject: [PATCH 029/119] [TEST] Expand api singleton test to cover explicit dlopen(). (#2164) --- api/test/singleton/BUILD | 49 +++++++++++++ api/test/singleton/CMakeLists.txt | 10 +++ api/test/singleton/component_c.h | 2 +- api/test/singleton/component_d.h | 2 +- api/test/singleton/component_e.h | 2 +- api/test/singleton/component_f.h | 2 +- api/test/singleton/component_g.cc | 42 +++++++++++ api/test/singleton/component_h.cc | 48 +++++++++++++ api/test/singleton/singleton_test.cc | 104 ++++++++++++++++++++++++++- 9 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 api/test/singleton/component_g.cc create mode 100644 api/test/singleton/component_h.cc diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index 5522284509..cdd1ed7cf4 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -117,11 +117,60 @@ cc_library( ], ) +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_g", + srcs = [ + "component_g.cc", + ], + copts = select({ + "//bazel:windows": DEFAULT_WIN_COPTS, + "//conditions:default": DEFAULT_NOWIN_COPTS, + }), + linkshared = True, + deps = [ + "//api", + ], +) + +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_h", + srcs = [ + "component_h.cc", + ], + copts = select({ + "//bazel:windows": HIDDEN_WIN_COPTS, + "//conditions:default": HIDDEN_NOWIN_COPTS, + }), + linkshared = True, + deps = [ + "//api", + ], +) + +# +# To build this test alone: +# - bazel build //api/test/singleton:singleton_test +# - bazel build //api/test/singleton:component_g +# - bazel build //api/test/singleton:component_h +# +# Note that singleton_test does not depend on +# component_g and component_h, on purpose. +# +# To run this test: +# bazel test //api/test/singleton:singleton_test +# + cc_test( name = "singleton_test", srcs = [ "singleton_test.cc", ], + defines = ["BAZEL_BUILD"], + linkopts = [ + "-ldl", + ], linkstatic = False, tags = [ "api", diff --git a/api/test/singleton/CMakeLists.txt b/api/test/singleton/CMakeLists.txt index a92233fca3..450308cd82 100644 --- a/api/test/singleton/CMakeLists.txt +++ b/api/test/singleton/CMakeLists.txt @@ -29,8 +29,17 @@ if(NOT WIN32) set_target_properties(component_f PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(component_f opentelemetry_api) + add_library(component_g SHARED component_g.cc) + set_target_properties(component_g PROPERTIES CXX_VISIBILITY_PRESET default) + target_link_libraries(component_g opentelemetry_api) + + add_library(component_h SHARED component_h.cc) + set_target_properties(component_h PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_link_libraries(component_h opentelemetry_api) + add_executable(singleton_test singleton_test.cc) + # Not linking with component_g and component_h on purpose target_link_libraries( singleton_test component_a @@ -41,6 +50,7 @@ if(NOT WIN32) component_f ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} opentelemetry_api) gtest_add_tests( diff --git a/api/test/singleton/component_c.h b/api/test/singleton/component_c.h index 31193da2df..11b8c96223 100644 --- a/api/test/singleton/component_c.h +++ b/api/test/singleton/component_c.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #if defined(_MSC_VER) -// component_c is a DDL +// component_c is a DLL # ifdef BUILD_COMPONENT_C __declspec(dllexport) diff --git a/api/test/singleton/component_d.h b/api/test/singleton/component_d.h index be65f4b5ac..1090014c2d 100644 --- a/api/test/singleton/component_d.h +++ b/api/test/singleton/component_d.h @@ -4,7 +4,7 @@ // Make the entry point visible, loaded dynamically #if defined(_MSC_VER) -// component_d is a DDL +// component_d is a DLL # ifdef BUILD_COMPONENT_D __declspec(dllexport) diff --git a/api/test/singleton/component_e.h b/api/test/singleton/component_e.h index 53782d76f7..223a1f3a8a 100644 --- a/api/test/singleton/component_e.h +++ b/api/test/singleton/component_e.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #if defined(_MSC_VER) -// component_e is a DDL +// component_e is a DLL # ifdef BUILD_COMPONENT_E __declspec(dllexport) diff --git a/api/test/singleton/component_f.h b/api/test/singleton/component_f.h index e042ba5bb3..80334de5aa 100644 --- a/api/test/singleton/component_f.h +++ b/api/test/singleton/component_f.h @@ -4,7 +4,7 @@ // Make the entry point visible, loaded dynamically #if defined(_MSC_VER) -// component_f is a DDL +// component_f is a DLL # ifdef BUILD_COMPONENT_F __declspec(dllexport) diff --git a/api/test/singleton/component_g.cc b/api/test/singleton/component_g.cc new file mode 100644 index 0000000000..49732d9b1f --- /dev/null +++ b/api/test/singleton/component_g.cc @@ -0,0 +1,42 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("G", "70.7"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f2")); + + f1(); + f1(); +} + +extern "C" + +#if defined(_MSC_VER) + // component_g is a DLL + __declspec(dllexport) +#endif + + void do_something_in_g() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::library")); + + f2(); +} diff --git a/api/test/singleton/component_h.cc b/api/test/singleton/component_h.cc new file mode 100644 index 0000000000..b486536fc2 --- /dev/null +++ b/api/test/singleton/component_h.cc @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("H", "80.8"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f2")); + + f1(); + f1(); +} + +extern "C" + +#if defined(_MSC_VER) + // component_h is a DLL + + __declspec(dllexport) + +#else +// component_h is a shared library (*.so) +// component_h is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + + void do_something_in_h() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::library")); + + f2(); +} diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 20a956d4a8..44a445e5bd 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -3,7 +3,15 @@ #include -#include +/* + TODO: + Once singleton are supported for windows, + expand this test to use ::LoadLibrary, ::GetProcAddress, ::FreeLibrary +*/ +#ifndef _WIN32 +# include +#endif + #include #include "component_a.h" @@ -30,6 +38,42 @@ void do_something() do_something_in_d(); do_something_in_e(); do_something_in_f(); + + /* + See https://github.com/bazelbuild/bazel/issues/4218 + + There is no way to set LD_LIBRARY_PATH in bazel, + for dlopen() to find the library. + + Verified manually that dlopen("/full/path/to/libcomponent_g.so") works, + and that the test passes in this case. + */ + +#ifndef BAZEL_BUILD + /* Call do_something_in_g() */ + + void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); + EXPECT_NE(component_g, nullptr); + + auto *func_g = (void (*)())dlsym(component_g, "do_something_in_g"); + EXPECT_NE(func_g, nullptr); + + (*func_g)(); + + dlclose(component_g); + + /* Call do_something_in_h() */ + + void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); + EXPECT_NE(component_h, nullptr); + + auto *func_h = (void (*)())dlsym(component_h, "do_something_in_h"); + EXPECT_NE(func_h, nullptr); + + (*func_h)(); + + dlclose(component_h); +#endif } int span_a_lib_count = 0; @@ -50,6 +94,12 @@ int span_e_f2_count = 0; int span_f_lib_count = 0; int span_f_f1_count = 0; int span_f_f2_count = 0; +int span_g_lib_count = 0; +int span_g_f1_count = 0; +int span_g_f2_count = 0; +int span_h_lib_count = 0; +int span_h_f1_count = 0; +int span_h_f2_count = 0; int unknown_span_count = 0; void reset_counts() @@ -72,6 +122,12 @@ void reset_counts() span_f_lib_count = 0; span_f_f1_count = 0; span_f_f2_count = 0; + span_g_lib_count = 0; + span_g_f1_count = 0; + span_g_f2_count = 0; + span_h_lib_count = 0; + span_h_f1_count = 0; + span_h_f2_count = 0; unknown_span_count = 0; } @@ -162,6 +218,30 @@ class MyTracer : public trace::Tracer { span_f_f2_count++; } + else if (name == "G::library") + { + span_g_lib_count++; + } + else if (name == "G::f1") + { + span_g_f1_count++; + } + else if (name == "G::f2") + { + span_g_f2_count++; + } + else if (name == "H::library") + { + span_h_lib_count++; + } + else if (name == "H::f1") + { + span_h_f1_count++; + } + else if (name == "H::f2") + { + span_h_f2_count++; + } else { unknown_span_count++; @@ -236,6 +316,12 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 0); EXPECT_EQ(span_f_f1_count, 0); EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); EXPECT_EQ(unknown_span_count, 0); reset_counts(); @@ -261,6 +347,16 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 1); EXPECT_EQ(span_f_f1_count, 2); EXPECT_EQ(span_f_f2_count, 1); + +#ifndef BAZEL_BUILD + EXPECT_EQ(span_g_lib_count, 1); + EXPECT_EQ(span_g_f1_count, 2); + EXPECT_EQ(span_g_f2_count, 1); + EXPECT_EQ(span_h_lib_count, 1); + EXPECT_EQ(span_h_f1_count, 2); + EXPECT_EQ(span_h_f2_count, 1); +#endif + EXPECT_EQ(unknown_span_count, 0); reset_counts(); @@ -286,5 +382,11 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 0); EXPECT_EQ(span_f_f1_count, 0); EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); EXPECT_EQ(unknown_span_count, 0); } From 31f218c1e24531c0471f8f6c0b5a8337c2d83d9d Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Wed, 5 Jul 2023 14:53:59 +0800 Subject: [PATCH 030/119] [BUILD] Add `OPENTELEMETRY_CPP_FOUND` into cmake CONFIG file. (#2215) --- cmake/opentelemetry-cpp-config.cmake.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 38b3a91259..5c450c1df6 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -116,3 +116,12 @@ find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME} FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES) + +if(${CMAKE_FIND_PACKAGE_NAME}_FOUND) + set(OPENTELEMETRY_CPP_FOUND + ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} + CACHE BOOL "whether opentelemetry-cpp is found" FORCE) +else() + unset(OPENTELEMETRY_CPP_FOUND) + unset(OPENTELEMETRY_CPP_FOUND CACHE) +endif() From 60794ac79f438945811a7a3b47454712aff28cfe Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 5 Jul 2023 17:08:31 +0200 Subject: [PATCH 031/119] [BUILD] Upgrade opentelemetry-proto to 1.0.0 (#2216) --- bazel/repository.bzl | 6 +++--- cmake/opentelemetry-proto.cmake | 2 +- third_party/opentelemetry-proto | 2 +- third_party_release | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 0cf8a2d8b2..6831af9aa7 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -100,10 +100,10 @@ def opentelemetry_cpp_deps(): http_archive, name = "com_github_opentelemetry_proto", build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", - sha256 = "6ab267cf82832ed60ad075d574c78da736193eecb9693e8a8d02f65d6d3f3520", - strip_prefix = "opentelemetry-proto-0.20.0", + sha256 = "a13a1a7b76a1f22a0ca2e6c293e176ffef031413ab8ba653a82a1dbc286a3a33", + strip_prefix = "opentelemetry-proto-1.0.0", urls = [ - "https://github.com/open-telemetry/opentelemetry-proto/archive/v0.20.0.tar.gz", + "https://github.com/open-telemetry/opentelemetry-proto/archive/v1.0.0.tar.gz", ], ) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index c3ea5a65ce..07238ba041 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -43,7 +43,7 @@ else() message( STATUS "opentelemetry-proto dependency satisfied by: github download") if("${opentelemetry-proto}" STREQUAL "") - set(opentelemetry-proto "v0.20.0") + set(opentelemetry-proto "v1.0.0") endif() include(ExternalProject) ExternalProject_Add( diff --git a/third_party/opentelemetry-proto b/third_party/opentelemetry-proto index 1608f92cf0..c4dfbc51f3 160000 --- a/third_party/opentelemetry-proto +++ b/third_party/opentelemetry-proto @@ -1 +1 @@ -Subproject commit 1608f92cf08119f9aec237c910b200d1317ec696 +Subproject commit c4dfbc51f3cd4089778555a2ac5d9bc093ed2956 diff --git a/third_party_release b/third_party_release index 0864c60471..2120898cd9 100644 --- a/third_party_release +++ b/third_party_release @@ -19,7 +19,7 @@ benchmark=v1.7.1 googletest=release-1.12.1 ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.11.2 -opentelemetry-proto=v0.20.0 +opentelemetry-proto=v1.0.0 opentracing-cpp=v1.6.0 prometheus-cpp=v1.1.0 vcpkg=2022.08.15 From 5466c5be26ad00207e0c572d08286908d401576a Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:30:43 +0200 Subject: [PATCH 032/119] Add Include what you use (#2214) --- ci/do_ci.sh | 22 ++++++++++++++++++---- ci/setup_ci_environment.sh | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index e4e4807c82..42bf3df416 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -59,6 +59,16 @@ mkdir -p "${BUILD_DIR}" [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin mkdir -p "${PLUGIN_DIR}" +IWYU="" +MAKE_COMMAND="make -k -j \$(nproc)" +if [[ "${CXX}" == *clang* ]]; then + MAKE_COMMAND="make -k CXX=include-what-you-use CXXFLAGS=\"-Xiwyu --error_always\" -j \$(nproc)" + IWYU="-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=iwyu" +fi + +echo "make command: ${MAKE_COMMAND}" +echo "IWYU option: ${IWYU}" + BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT" @@ -107,8 +117,9 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ + ${IWYU} \ "${SRC_DIR}" - make -k + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.maintainer.async.test" ]]; then @@ -129,8 +140,9 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ + ${IWYU} \ "${SRC_DIR}" - make -k -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then @@ -201,8 +213,9 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DCMAKE_CXX_STANDARD=20 \ + ${IWYU} \ "${SRC_DIR}" - make -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.c++20.stl.test" ]]; then @@ -214,8 +227,9 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_STL=ON \ + ${IWYU} \ "${SRC_DIR}" - make -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.legacy.test" ]]; then diff --git a/ci/setup_ci_environment.sh b/ci/setup_ci_environment.sh index f995ed75b5..8e93b8d5b5 100755 --- a/ci/setup_ci_environment.sh +++ b/ci/setup_ci_environment.sh @@ -11,4 +11,5 @@ apt-get install --no-install-recommends --no-install-suggests -y \ wget \ git \ valgrind \ - lcov + lcov \ + iwyu From 6ecd201f95b4e813c71c8552b31c3ebcb29702f8 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 6 Jul 2023 22:46:53 +0200 Subject: [PATCH 033/119] [SDK] MeterProvider should own MeterContext, not share it (#2218) --- CHANGELOG.md | 9 +++++++++ examples/otlp/grpc_metric_main.cc | 4 +--- examples/otlp/http_metric_main.cc | 4 +--- sdk/include/opentelemetry/sdk/metrics/meter_provider.h | 4 ++-- .../opentelemetry/sdk/metrics/meter_provider_factory.h | 2 +- sdk/src/metrics/meter_provider.cc | 4 +++- sdk/src/metrics/meter_provider_factory.cc | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a9e19f26..83814e8c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ Increment the: * [API] Remove include_trace_context [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) +* [SDK] MeterProvider should own MeterContext, not share it + [#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218) + Important changes: * [REMOVAL] Remove the jaeger exporter @@ -28,6 +31,12 @@ Important changes: * The CMake `WITH_JAEGER` option has been removed * Please remove usage of `WITH_JAEGER` from user scripts and makefiles. +* [SDK] MeterProvider should own MeterContext, not share it + [#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218) + * The `MeterProvider` constructor now takes a `unique_ptr` on + `MeterContext`, instead of a `shared_ptr`. + * Please adjust SDK configuration code accordingly. + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/examples/otlp/grpc_metric_main.cc b/examples/otlp/grpc_metric_main.cc index 40d9777776..60d59d1e28 100644 --- a/examples/otlp/grpc_metric_main.cc +++ b/examples/otlp/grpc_metric_main.cc @@ -48,9 +48,7 @@ void InitMetrics() auto context = metric_sdk::MeterContextFactory::Create(); context->AddMetricReader(std::move(reader)); - std::shared_ptr s_context(std::move(context)); - - auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context); + auto u_provider = metric_sdk::MeterProviderFactory::Create(std::move(context)); std::shared_ptr provider(std::move(u_provider)); metrics_api::Provider::SetMeterProvider(provider); diff --git a/examples/otlp/http_metric_main.cc b/examples/otlp/http_metric_main.cc index a361285fed..f33d57772f 100644 --- a/examples/otlp/http_metric_main.cc +++ b/examples/otlp/http_metric_main.cc @@ -52,9 +52,7 @@ void InitMetrics() auto context = metric_sdk::MeterContextFactory::Create(); context->AddMetricReader(std::move(reader)); - std::shared_ptr s_context(std::move(context)); - - auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context); + auto u_provider = metric_sdk::MeterProviderFactory::Create(std::move(context)); std::shared_ptr provider(std::move(u_provider)); metrics_api::Provider::SetMeterProvider(provider); diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index fedf6aac61..b27fcfb969 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -44,9 +44,9 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider /** * Initialize a new meter provider with a specified context - * @param context The shared meter configuration/pipeline for this provider. + * @param context The owned meter configuration/pipeline for this provider. */ - explicit MeterProvider(std::shared_ptr context) noexcept; + explicit MeterProvider(std::unique_ptr context) noexcept; nostd::shared_ptr GetMeter( nostd::string_view name, diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h index 7a1343980c..6c0375ad9d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h @@ -69,7 +69,7 @@ class MeterProviderFactory const opentelemetry::sdk::resource::Resource &resource); static std::unique_ptr Create( - std::shared_ptr context); + std::unique_ptr context); }; } // namespace metrics diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 1e9dc5f434..a36260e201 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -21,7 +21,9 @@ namespace metrics namespace resource = opentelemetry::sdk::resource; namespace metrics_api = opentelemetry::metrics; -MeterProvider::MeterProvider(std::shared_ptr context) noexcept : context_{context} {} +MeterProvider::MeterProvider(std::unique_ptr context) noexcept + : context_(std::move(context)) +{} MeterProvider::MeterProvider(std::unique_ptr views, sdk::resource::Resource resource) noexcept diff --git a/sdk/src/metrics/meter_provider_factory.cc b/sdk/src/metrics/meter_provider_factory.cc index 38527c90d8..bd6bbe932c 100644 --- a/sdk/src/metrics/meter_provider_factory.cc +++ b/sdk/src/metrics/meter_provider_factory.cc @@ -46,7 +46,7 @@ std::unique_ptr MeterProviderFactory::Cre } std::unique_ptr MeterProviderFactory::Create( - std::shared_ptr context) + std::unique_ptr context) { std::unique_ptr provider( new metrics_sdk::MeterProvider(std::move(context))); From d6cebe140444101f3dd1e366a161288782ce04c1 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 6 Jul 2023 23:39:37 -0700 Subject: [PATCH 034/119] Include nostd/string_view which is used severity.h (#2219) --- api/include/opentelemetry/logs/severity.h | 1 + 1 file changed, 1 insertion(+) diff --git a/api/include/opentelemetry/logs/severity.h b/api/include/opentelemetry/logs/severity.h index 8534ce7508..6a435f38fc 100644 --- a/api/include/opentelemetry/logs/severity.h +++ b/api/include/opentelemetry/logs/severity.h @@ -4,6 +4,7 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/nostd/string_view.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE From 8b613188a3a20e1ad2603040bb959be9386014b7 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 8 Jul 2023 16:07:38 +0200 Subject: [PATCH 035/119] [SDK] TracerProvider should own TracerContext, not share it (#2221) --- CHANGELOG.md | 13 ++++++++++++- examples/grpc/tracer_common.h | 4 ++-- examples/http/tracer_common.h | 4 ++-- ext/test/w3c_tracecontext_test/main.cc | 7 ++++--- .../opentelemetry/sdk/logs/logger_context.h | 6 +++--- .../opentelemetry/sdk/logs/logger_provider.h | 6 +++--- .../sdk/logs/logger_provider_factory.h | 2 +- .../opentelemetry/sdk/trace/tracer_provider.h | 4 ++-- .../sdk/trace/tracer_provider_factory.h | 2 +- sdk/src/logs/logger_provider.cc | 14 ++++++-------- sdk/src/logs/logger_provider_factory.cc | 6 ++++-- sdk/src/trace/tracer_provider.cc | 4 ++-- sdk/src/trace/tracer_provider_factory.cc | 6 ++++-- sdk/test/logs/logger_provider_sdk_test.cc | 6 ++++-- sdk/test/trace/tracer_provider_test.cc | 16 ++++++++++------ 15 files changed, 60 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83814e8c59..4849ece1ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,10 @@ Increment the: * [SDK] MeterProvider should own MeterContext, not share it [#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218) -Important changes: +* [SDK] TracerProvider should own TracerContext, not share it + [#2221](https://github.com/open-telemetry/opentelemetry-cpp/pull/2221) + +Breaking changes: * [REMOVAL] Remove the jaeger exporter [#2031](https://github.com/open-telemetry/opentelemetry-cpp/pull/2031) @@ -37,6 +40,14 @@ Important changes: `MeterContext`, instead of a `shared_ptr`. * Please adjust SDK configuration code accordingly. +* [SDK] TracerProvider should own TracerContext, not share it + [#2221](https://github.com/open-telemetry/opentelemetry-cpp/pull/2221) + * The `TracerProvider` constructor now takes a `unique_ptr` on + `TracerContext`, instead of a `shared_ptr`. + * The `LoggerProvider` constructor now takes a `unique_ptr` on + `LoggerContext`, instead of a `shared_ptr`. + * Please adjust SDK configuration code accordingly. + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index 347e7a8184..e26f6bd2c6 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -80,10 +80,10 @@ void InitTracer() std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - std::shared_ptr context = + std::unique_ptr context = opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors)); std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(context); + opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); diff --git a/examples/http/tracer_common.h b/examples/http/tracer_common.h index 7d9f1ca571..8b61e7bec3 100644 --- a/examples/http/tracer_common.h +++ b/examples/http/tracer_common.h @@ -70,10 +70,10 @@ void InitTracer() std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - std::shared_ptr context = + std::unique_ptr context = opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors)); std::shared_ptr provider = - opentelemetry::sdk::trace::TracerProviderFactory::Create(context); + opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 92807dd8ad..349626e219 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -55,9 +55,10 @@ void initTracer() new trace_sdk::SimpleSpanProcessor(std::move(exporter))); std::vector> processors; processors.push_back(std::move(processor)); - auto context = std::make_shared(std::move(processors)); - auto provider = - nostd::shared_ptr(new trace_sdk::TracerProvider(context)); + auto context = std::unique_ptr( + new trace_sdk::TracerContext(std::move(processors))); + auto provider = nostd::shared_ptr( + new trace_sdk::TracerProvider(std::move(context))); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); } diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context.h b/sdk/include/opentelemetry/sdk/logs/logger_context.h index 0b2de9bc15..196ecd545f 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context.h @@ -9,6 +9,7 @@ # include # include +# include "opentelemetry/sdk/logs/processor.h" # include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/version.h" @@ -17,7 +18,6 @@ namespace sdk { namespace logs { -class LogRecordProcessor; /** * A class which stores the LoggerContext context. @@ -40,10 +40,10 @@ class LoggerContext opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** - * Attaches a log processor to list of configured processors to this tracer context. + * Attaches a log processor to list of configured processors to this logger context. * Processor once attached can't be removed. * @param processor The new log processor for this tracer. This must not be - * a nullptr. Ownership is given to the `TracerContext`. + * a nullptr. Ownership is given to the `LoggerContext`. * * Note: This method is not thread safe. */ diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index 3c9211cc36..01dc241470 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -56,9 +56,9 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider /** * Initialize a new logger provider with a specified context - * @param context The shared logger configuration/pipeline for this provider. + * @param context The owned logger configuration/pipeline for this provider. */ - explicit LoggerProvider(std::shared_ptr context) noexcept; + explicit LoggerProvider(std::unique_ptr context) noexcept; ~LoggerProvider() override; @@ -106,7 +106,7 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider private: // order of declaration is important here - loggers should destroy only after context. std::vector> loggers_; - std::shared_ptr context_; + std::shared_ptr context_; std::mutex lock_; }; } // 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 bbd715dc89..5d74d7918d 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -64,7 +64,7 @@ class OPENTELEMETRY_EXPORT LoggerProviderFactory * Create a LoggerProvider. */ static std::unique_ptr Create( - std::shared_ptr context); + std::unique_ptr context); }; } // namespace logs diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index e15f686898..092db1eaf8 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -57,9 +57,9 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider /** * Initialize a new tracer provider with a specified context - * @param context The shared tracer configuration/pipeline for this provider. + * @param context The owned tracer configuration/pipeline for this provider. */ - explicit TracerProvider(std::shared_ptr context) noexcept; + explicit TracerProvider(std::unique_ptr context) noexcept; ~TracerProvider() override; diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h index 93bd1085ac..e9dfa82edb 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h @@ -78,7 +78,7 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory /* Create with a tracer context. */ static std::unique_ptr Create( - std::shared_ptr context); + std::unique_ptr context); }; } // namespace trace diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 1e1b83c7de..638ece3802 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -24,29 +24,27 @@ 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), std::move(resource)); OTEL_INTERNAL_LOG_DEBUG("[LoggerProvider] LoggerProvider created."); } LoggerProvider::LoggerProvider(std::vector> &&processors, opentelemetry::sdk::resource::Resource resource) noexcept - : context_{ - std::make_shared(std::move(processors), std::move(resource))} + : context_{std::make_shared(std::move(processors), std::move(resource))} {} LoggerProvider::LoggerProvider() noexcept - : context_{std::make_shared( - std::vector>{})} + : context_{std::make_shared(std::vector>{})} {} -LoggerProvider::LoggerProvider(std::shared_ptr context) noexcept - : context_{context} +LoggerProvider::LoggerProvider(std::unique_ptr context) noexcept + : context_(std::move(context)) {} LoggerProvider::~LoggerProvider() { // Logger hold the shared pointer to the context. So we can not use destructor of LoggerContext to - // Shutdown and flush all pending recordables when we hasve more than one loggers.These + // Shutdown and flush all pending recordables when we have more than one loggers. These // recordables may use the raw pointer of instrumentation_scope_ in Logger if (context_) { diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc index 3177b9180e..167d6cbf65 100644 --- a/sdk/src/logs/logger_provider_factory.cc +++ b/sdk/src/logs/logger_provider_factory.cc @@ -4,6 +4,7 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/logger_context.h" # include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/resource/resource.h" @@ -46,9 +47,10 @@ std::unique_ptr LoggerProviderFactory::Crea } std::unique_ptr LoggerProviderFactory::Create( - std::shared_ptr context) + std::unique_ptr context) { - std::unique_ptr provider(new LoggerProvider(context)); + std::unique_ptr provider( + new LoggerProvider(std::move(context))); return provider; } diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 7ac66ed6db..13d56f9966 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -16,8 +16,8 @@ namespace trace namespace resource = opentelemetry::sdk::resource; namespace trace_api = opentelemetry::trace; -TracerProvider::TracerProvider(std::shared_ptr context) noexcept - : context_{context} +TracerProvider::TracerProvider(std::unique_ptr context) noexcept + : context_(std::move(context)) { OTEL_INTERNAL_LOG_DEBUG("[TracerProvider] TracerProvider created."); } diff --git a/sdk/src/trace/tracer_provider_factory.cc b/sdk/src/trace/tracer_provider_factory.cc index 158ae949ea..c9b02a13ad 100644 --- a/sdk/src/trace/tracer_provider_factory.cc +++ b/sdk/src/trace/tracer_provider_factory.cc @@ -5,6 +5,7 @@ #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/random_id_generator_factory.h" #include "opentelemetry/sdk/trace/samplers/always_on_factory.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/sdk/trace/tracer_provider.h" namespace trace_api = opentelemetry::trace; @@ -87,9 +88,10 @@ std::unique_ptr TracerProviderFactory::Cre } std::unique_ptr TracerProviderFactory::Create( - std::shared_ptr context) + std::unique_ptr context) { - std::unique_ptr provider(new trace_sdk::TracerProvider(context)); + std::unique_ptr provider( + new trace_sdk::TracerProvider(std::move(context))); return provider; } diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index e9bc897745..c6b8dec372 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -170,7 +170,8 @@ TEST(LoggerProviderSDK, Shutdown) std::vector> processors; processors.push_back(std::move(processor)); - LoggerProvider lp(std::make_shared(std::move(processors))); + std::unique_ptr context(new LoggerContext(std::move(processors))); + LoggerProvider lp(std::move(context)); EXPECT_TRUE(lp.Shutdown()); EXPECT_TRUE(processor_ptr->IsShutdown()); @@ -185,7 +186,8 @@ TEST(LoggerProviderSDK, ForceFlush) std::vector> processors; processors.push_back(std::move(processor)); - LoggerProvider lp(std::make_shared(std::move(processors))); + std::unique_ptr context(new LoggerContext(std::move(processors))); + LoggerProvider lp(std::move(context)); EXPECT_TRUE(lp.ForceFlush()); } diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 641fc72c54..364efc0208 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -20,7 +20,9 @@ TEST(TracerProvider, GetTracer) std::unique_ptr processor(new SimpleSpanProcessor(nullptr)); std::vector> processors; processors.push_back(std::move(processor)); - TracerProvider tp1(std::make_shared(std::move(processors), Resource::Create({}))); + std::unique_ptr context1( + new TracerContext(std::move(processors), Resource::Create({}))); + TracerProvider tp1(std::move(context1)); auto t1 = tp1.GetTracer("test"); auto t2 = tp1.GetTracer("test"); auto t3 = tp1.GetTracer("different", "1.0.0"); @@ -49,10 +51,11 @@ TEST(TracerProvider, GetTracer) std::unique_ptr processor2(new SimpleSpanProcessor(nullptr)); std::vector> processors2; processors2.push_back(std::move(processor2)); - TracerProvider tp2( - std::make_shared(std::move(processors2), Resource::Create({}), - std::unique_ptr(new AlwaysOffSampler()), - std::unique_ptr(new RandomIdGenerator))); + std::unique_ptr context2( + new TracerContext(std::move(processors2), Resource::Create({}), + std::unique_ptr(new AlwaysOffSampler()), + std::unique_ptr(new RandomIdGenerator))); + TracerProvider tp2(std::move(context2)); #ifdef OPENTELEMETRY_RTTI_ENABLED auto sdkTracer2 = dynamic_cast(tp2.GetTracer("test").get()); #else @@ -81,7 +84,8 @@ TEST(TracerProvider, Shutdown) std::vector> processors; processors.push_back(std::move(processor)); - TracerProvider tp1(std::make_shared(std::move(processors))); + std::unique_ptr context1(new TracerContext(std::move(processors))); + TracerProvider tp1(std::move(context1)); EXPECT_TRUE(tp1.Shutdown()); From 1111f3409fa469f68b413dd97fa2e1ee7f29c97d Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 10 Jul 2023 10:48:57 +0200 Subject: [PATCH 036/119] [API] Remove Meters (#2205) --- CHANGELOG.md | 11 ++++++ CMakeLists.txt | 8 ++++ api/CMakeLists.txt | 5 +++ .../opentelemetry/metrics/meter_provider.h | 5 +++ api/include/opentelemetry/metrics/noop.h | 7 ++++ ci/do_ci.sh | 3 ++ .../otlp_grpc_log_record_exporter_test.cc | 6 +-- .../opentelemetry/sdk/metrics/meter_context.h | 4 ++ .../sdk/metrics/meter_provider.h | 6 +++ sdk/src/metrics/meter_context.cc | 27 ++++++++++++++ sdk/src/metrics/meter_provider.cc | 17 +++++++++ sdk/test/logs/log_record_test.cc | 4 +- sdk/test/metrics/meter_provider_sdk_test.cc | 37 ++++++++++++++++++- 13 files changed, 134 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4849ece1ef..5c5d9d9b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,12 +21,23 @@ Increment the: * [API] Remove include_trace_context [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) +* [API] Remove Meters + [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) + * [SDK] MeterProvider should own MeterContext, not share it [#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218) * [SDK] TracerProvider should own TracerContext, not share it [#2221](https://github.com/open-telemetry/opentelemetry-cpp/pull/2221) +Important changes: + +* [API] Remove Meters + [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) + * The CMake option `WITH_REMOVE_METER_PREVIEW` was added. + * This option is experimental, and may change in the future. + * Enabling it is an ABI breaking change. + Breaking changes: * [REMOVAL] Remove the jaeger exporter diff --git a/CMakeLists.txt b/CMakeLists.txt index fb483f5a58..997c9440e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,14 @@ option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF) option(OTELCPP_VERSIONED_LIBS "Whether to generate the versioned shared libs" OFF) +# +# This option is experimental, subject to change in the spec: +# +# * https://github.com/open-telemetry/opentelemetry-specification/issues/2232 +# +option(WITH_REMOVE_METER_PREVIEW + "EXPERIMENTAL, ABI BREAKING: Allow to remove a meter" OFF) + if(OTELCPP_VERSIONED_LIBS AND NOT BUILD_SHARED_LIBS) message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires BUILD_SHARED_LIBS=ON") endif() diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 91d129e179..d1a6a77fa3 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -98,6 +98,11 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() +if(WITH_REMOVE_METER_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_REMOVE_METER_PREVIEW) +endif() + # A better place should be in sdk, not api if(WITH_OTLP_HTTP_SSL_PREVIEW) target_compile_definitions(opentelemetry_api diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index 654c4022ea..e0b0285ef4 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -29,6 +29,11 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; +#ifdef ENABLE_REMOVE_METER_PREVIEW + virtual void RemoveMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 3a754a6e00..c5802f3dd3 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -203,6 +203,13 @@ class NoopMeterProvider final : public MeterProvider return meter_; } +#ifdef ENABLE_REMOVE_METER_PREVIEW + void RemoveMeter(nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */) noexcept override + {} +#endif + private: nostd::shared_ptr meter_; }; diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 42bf3df416..69a6eef0c9 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -106,6 +106,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -129,6 +130,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -153,6 +155,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ 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 f2ed416327..518caaba5e 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -154,7 +154,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) std::unique_ptr trace_stub_interface( trace_mock_stub); - auto trace_provider = opentelemetry::nostd::shared_ptr( + auto trace_provider = opentelemetry::nostd::shared_ptr( opentelemetry::sdk::trace::TracerProviderFactory::Create( opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create( GetExporter(trace_stub_interface)))); @@ -174,7 +174,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); - std::unordered_map attributes; + std::unordered_map attributes; attributes["service.name"] = "unit_test_service"; attributes["tenant.id"] = "test_user"; attributes["bool_value"] = true; @@ -197,7 +197,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) opentelemetry::trace::Provider::SetTracerProvider( opentelemetry::nostd::shared_ptr( new opentelemetry::trace::NoopTracerProvider())); - trace_provider = opentelemetry::nostd::shared_ptr(); + trace_provider = opentelemetry::nostd::shared_ptr(); } } // namespace otlp diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index 8155b4da9f..336f5da7a0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -115,6 +115,10 @@ class MeterContext : public std::enable_shared_from_this */ void AddMeter(std::shared_ptr meter); + void RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url); + /** * Force all active Collectors to flush any buffered meter data * within the given timeout. diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index b27fcfb969..c74c37f8a4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -53,6 +53,12 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider nostd::string_view version = "", nostd::string_view schema_url = "") noexcept override; +#ifdef ENABLE_REMOVE_METER_PREVIEW + void RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) noexcept override; +#endif + /** * Obtain the resource associated with this meter provider. * @return The resource for this meter provider. diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index eaf82232d6..7a299bfc63 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -3,6 +3,7 @@ #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/state/metric_collector.h" #include "opentelemetry/sdk_config.h" @@ -79,6 +80,32 @@ void MeterContext::AddMeter(std::shared_ptr meter) meters_.push_back(meter); } +void MeterContext::RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) +{ + std::lock_guard guard(meter_lock_); + + std::vector> filtered_meters; + + for (auto &meter : meters_) + { + auto scope = meter->GetInstrumentationScope(); + if (scope->equal(name, version, schema_url)) + { + OTEL_INTERNAL_LOG_INFO("[MeterContext::RemoveMeter] removing meter name <" + << name << ">, version <" << version << ">, URL <" << schema_url + << ">"); + } + else + { + filtered_meters.push_back(meter); + } + } + + meters_.swap(filtered_meters); +} + bool MeterContext::Shutdown() noexcept { bool result = true; diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index a36260e201..84ab58c4cf 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -59,6 +59,23 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } +#ifdef ENABLE_REMOVE_METER_PREVIEW +void MeterProvider::RemoveMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url) noexcept +{ + if (name.data() == nullptr || name == "") + { + OTEL_INTERNAL_LOG_WARN("[MeterProvider::RemoveMeter] Library name is empty."); + name = ""; + } + + const std::lock_guard guard(lock_); + + context_->RemoveMeter(name, version, schema_url); +} +#endif + const resource::Resource &MeterProvider::GetResource() const noexcept { return context_->GetResource(); diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 0e5de03050..4f7deb06d0 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -99,13 +99,13 @@ class TestBodyLogger : public opentelemetry::logs::Logger } } - const opentelemetry::v1::common::AttributeValue &GetLastLogRecord() const noexcept + const opentelemetry::common::AttributeValue &GetLastLogRecord() const noexcept { return last_body_; } private: - opentelemetry::v1::common::AttributeValue last_body_; + opentelemetry::common::AttributeValue last_body_; }; // Define a basic LoggerProvider class that returns an instance of the logger class defined above diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index bcdc6c4b79..da75916555 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -16,7 +16,6 @@ using namespace opentelemetry::sdk::metrics; TEST(MeterProvider, GetMeter) { - MeterProvider mp1; // std::unique_ptr view{std::unique_ptr()}; // MeterProvider mp1(std::move(exporters), std::move(readers), std::move(views); @@ -59,3 +58,39 @@ TEST(MeterProvider, GetMeter) mp1.ForceFlush(); mp1.Shutdown(); } + +#ifdef ENABLE_REMOVE_METER_PREVIEW +TEST(MeterProvider, RemoveMeter) +{ + MeterProvider mp; + + auto m1 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m1); + + // Will return the same meter + auto m2 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m2); + ASSERT_EQ(m1, m2); + + mp.RemoveMeter("unknown", "0", ""); + + // Will decrease use_count() on m1 and m2 + mp.RemoveMeter("test", "1", "URL"); + + // Will create a different meter + auto m3 = mp.GetMeter("test", "1", "URL"); + ASSERT_NE(nullptr, m3); + ASSERT_NE(m1, m3); + ASSERT_NE(m2, m3); + + // Will decrease use_count() on m3 + mp.RemoveMeter("test", "1", "URL"); + + // Will do nothing + mp.RemoveMeter("test", "1", "URL"); + + // cleanup properly without crash + mp.ForceFlush(); + mp.Shutdown(); +} +#endif From 556139396c4467500098be26551859f10c3449a8 Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:04:22 +0200 Subject: [PATCH 037/119] opentelemetry-cpp project CI (#2071) --- .../workflows/project_management_comment.yml | 20 +++++++++++++++ .../project_management_issue_open.yml | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/workflows/project_management_comment.yml create mode 100644 .github/workflows/project_management_issue_open.yml diff --git a/.github/workflows/project_management_comment.yml b/.github/workflows/project_management_comment.yml new file mode 100644 index 0000000000..417202b410 --- /dev/null +++ b/.github/workflows/project_management_comment.yml @@ -0,0 +1,20 @@ + +name: Add comment +on: + issues: + types: + - labeled +jobs: + add-comment: + if: github.event.label.name == 'help wanted' + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Add comment + uses: peter-evans/create-or-update-comment@a35cf36e5301d70b76f316e867e7788a55a31dae + with: + issue-number: ${{ github.event.issue.number }} + body: | + This issue is available for anyone to work on. **Make sure to reference this issue in your pull request.** + :sparkles: Thank you for your contribution! :sparkles: diff --git a/.github/workflows/project_management_issue_open.yml b/.github/workflows/project_management_issue_open.yml new file mode 100644 index 0000000000..d9c1b3893f --- /dev/null +++ b/.github/workflows/project_management_issue_open.yml @@ -0,0 +1,25 @@ +name: OpenTelemetry-cpp project +on: + issues: + types: + - reopened + - opened + pull_request: + types: + - reopened + - opened +jobs: + label_issues: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/github-script@v6 + with: + script: | + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ["needs-triage"] + }) From f5426ce8cfbe54f99ac0c9f6022049fb4ee4c90a Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 11 Jul 2023 11:37:26 +0200 Subject: [PATCH 038/119] [CI] Do not tag pull_request with the "need-triage" label. (#2228) --- .github/workflows/project_management_issue_open.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/project_management_issue_open.yml b/.github/workflows/project_management_issue_open.yml index d9c1b3893f..e68e9ab152 100644 --- a/.github/workflows/project_management_issue_open.yml +++ b/.github/workflows/project_management_issue_open.yml @@ -4,10 +4,6 @@ on: types: - reopened - opened - pull_request: - types: - - reopened - - opened jobs: label_issues: runs-on: ubuntu-latest From 7b95f5b2af2b4213692fd1e24d1866ccbdd3c77f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 12:28:40 +0200 Subject: [PATCH 039/119] Bump peter-evans/create-or-update-comment from 1.4.5 to 3.0.2 (#2226) Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 1.4.5 to 3.0.2. - [Release notes](https://github.com/peter-evans/create-or-update-comment/releases) - [Commits](https://github.com/peter-evans/create-or-update-comment/compare/a35cf36e5301d70b76f316e867e7788a55a31dae...c6c9a1a66007646a28c153e2a8580a5bad27bcfa) --- updated-dependencies: - dependency-name: peter-evans/create-or-update-comment 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/project_management_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/project_management_comment.yml b/.github/workflows/project_management_comment.yml index 417202b410..c3ddd0034f 100644 --- a/.github/workflows/project_management_comment.yml +++ b/.github/workflows/project_management_comment.yml @@ -12,7 +12,7 @@ jobs: issues: write steps: - name: Add comment - uses: peter-evans/create-or-update-comment@a35cf36e5301d70b76f316e867e7788a55a31dae + uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa with: issue-number: ${{ github.event.issue.number }} body: | From ca8c23481ae10c1569858cee19fa076c27b8f261 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 11 Jul 2023 21:45:24 +0200 Subject: [PATCH 040/119] Prepare release 1.10.0 (#2227) --- CHANGELOG.md | 102 ++++++++++++++++++ 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, 112 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5d9d9b04..2746663232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,21 +15,123 @@ Increment the: ## [Unreleased] +## [1.10.0] 2023-07-11 + * [REMOVAL] Remove the jaeger exporter [#2031](https://github.com/open-telemetry/opentelemetry-cpp/pull/2031) +* [CI] Add a C++11 build + [#2152](https://github.com/open-telemetry/opentelemetry-cpp/pull/2152) + +* [CI] Add Include what you use + [#2214](https://github.com/open-telemetry/opentelemetry-cpp/pull/2214) + +* [CI] opentelemetry-cpp project CI + [#2071](https://github.com/open-telemetry/opentelemetry-cpp/pull/2071) + +* [CI] Do not tag pull_request with the "need-triage" label + [#2228](https://github.com/open-telemetry/opentelemetry-cpp/pull/2228) + +* [BUILD] Fixing CMake to build GTest on Windows + [#1887](https://github.com/open-telemetry/opentelemetry-cpp/pull/1887) + +* [BUILD] Remove option WITH_OTLP + [#2161](https://github.com/open-telemetry/opentelemetry-cpp/pull/2161) + +* [BUILD] Link to opentelemetry_logs even without OTLP + [#2177](https://github.com/open-telemetry/opentelemetry-cpp/pull/2177) + +* [BUILD] Avoid dependency on protobuf from the OTLP HTTP metrics exporter header + [#2179](https://github.com/open-telemetry/opentelemetry-cpp/pull/2179) + +* [BUILD] Add ctime header to metrics_exporter.cc + [#2187](https://github.com/open-telemetry/opentelemetry-cpp/pull/2187) + +* [BUILD] Fix the exported symbol name for 32-bit win32 DLL + [#2190](https://github.com/open-telemetry/opentelemetry-cpp/pull/2190) + +* [BUILD] Upgrade to opentelemetry-proto 0.20.0 + [#2195](https://github.com/open-telemetry/opentelemetry-cpp/pull/2195) + +* [BUILD] SDK Header files cleanup, use forward declarations + [#2182](https://github.com/open-telemetry/opentelemetry-cpp/pull/2182) + +* [BUILD] Enable building otel-cpp extensions from main repo + [#1937](https://github.com/open-telemetry/opentelemetry-cpp/pull/1937) + +* [BUILD] Fix if check on environment variable and add CMake variable + [#2207](https://github.com/open-telemetry/opentelemetry-cpp/pull/2207) + +* [BUILD] Add `OPENTELEMETRY_CPP_FOUND` into cmake CONFIG file + [#2215](https://github.com/open-telemetry/opentelemetry-cpp/pull/2215) + +* [BUILD] Upgrade opentelemetry-proto to 1.0.0 + [#2216](https://github.com/open-telemetry/opentelemetry-cpp/pull/2216) + +* [BUILD] Include nostd/string_view which is used in severity.h + [#2219](https://github.com/open-telemetry/opentelemetry-cpp/pull/2219) + +* [TEST] Expand api singleton test to cover explicit dlopen() + [#2164](https://github.com/open-telemetry/opentelemetry-cpp/pull/2164) + * [API] Remove include_trace_context [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) * [API] Remove Meters [#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205) +* [SDK] Add AdaptingCircularBufferCounter for exponential histograms + [#2158](https://github.com/open-telemetry/opentelemetry-cpp/pull/2158) + +* [SDK] Add base2 exponential histogram indexer + [#2173](https://github.com/open-telemetry/opentelemetry-cpp/pull/2173) + +* [SDK] Simplify SDK version + [#2180](https://github.com/open-telemetry/opentelemetry-cpp/pull/2180) + +* [SDK] Add benchmark for base2 exponential histogram indexer + [#2181](https://github.com/open-telemetry/opentelemetry-cpp/pull/2181) + +* [SDK] Provide builders to avoid exposing Metrics SDK internals + [#2189](https://github.com/open-telemetry/opentelemetry-cpp/pull/2189) + * [SDK] MeterProvider should own MeterContext, not share it [#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218) * [SDK] TracerProvider should own TracerContext, not share it [#2221](https://github.com/open-telemetry/opentelemetry-cpp/pull/2221) +* [EXPORTER] Change OTLP Json field name to camelCase + [#2162](https://github.com/open-telemetry/opentelemetry-cpp/pull/2162) + +* [EXPORTER] Support empty arrays in `OtlpRecordable` attributes + [#2166](https://github.com/open-telemetry/opentelemetry-cpp/pull/2166) + +* [EXPORTER] set is_monotonic only for instrument type kCounter + [#2171](https://github.com/open-telemetry/opentelemetry-cpp/pull/2171) + +* [EXPORTER] Fixed HTTP CURL for 32bits platforms + [#2178](https://github.com/open-telemetry/opentelemetry-cpp/pull/2178) + +* [EXPORTER] Fix OTLP HTTP exporting in sync mode + [#2193](https://github.com/open-telemetry/opentelemetry-cpp/pull/2193) + +* [EXPORTER] Prometheus exporter sanitizes invalid characters + [#1934](https://github.com/open-telemetry/opentelemetry-cpp/pull/1934) + +* [EXPORTER] Prometheus: Error on ingesting samples + with different value but same timestamp + [#2200](https://github.com/open-telemetry/opentelemetry-cpp/pull/2200) + +* [EXPORTER] OTLP GRPC mTLS support + [#2120](https://github.com/open-telemetry/opentelemetry-cpp/pull/2120) + +* [DOC] Small fix for Histogram documentation + [#2156](https://github.com/open-telemetry/opentelemetry-cpp/pull/2156) + +* [DOC] Move Reiley Yang to emeritus + [#2198](https://github.com/open-telemetry/opentelemetry-cpp/pull/2198) + Important changes: * [API] Remove Meters diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 2178591728..f3c2978cf0 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -7,10 +7,10 @@ #include "opentelemetry/detail/preprocessor.h" #define OPENTELEMETRY_ABI_VERSION_NO 1 -#define OPENTELEMETRY_VERSION "1.9.1" +#define OPENTELEMETRY_VERSION "1.10.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 9 -#define OPENTELEMETRY_VERSION_PATCH 1 +#define OPENTELEMETRY_VERSION_MINOR 10 +#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 53ec43b82a..b6d552218b 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.9.1" +release = "1.10.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 1c9c285f90..da4c682c72 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -5,7 +5,7 @@ #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_SDK_VERSION "1.9.1" +#define OPENTELEMETRY_SDK_VERSION "1.10.0" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index a658331f27..efd64a14e3 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 = 9; -const int patch_version = 1; +const int minor_version = 10; +const int patch_version = 0; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.9.1"; -const char *full_version = "1.9.1-NONE-NONE"; -const char *build_date = "Fri 26 May 2023 07:14:07 AM UTC"; +const char *short_version = "1.10.0"; +const char *full_version = "1.10.0-NONE-NONE"; +const char *build_date = "Tue 11 Jul 2023 07:54:39 AM UTC"; } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From d99cbab06cbbb2bac19e740811ab3c38a60d6e3b Mon Sep 17 00:00:00 2001 From: Darren Bolduc Date: Wed, 12 Jul 2023 03:24:21 -0400 Subject: [PATCH 041/119] [BUILD] include (#2230) --- sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h index 1608a3a011..26f272f837 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/circular_buffer.h @@ -5,6 +5,7 @@ #include "opentelemetry/nostd/variant.h" +#include #include #include From b3d547c2057c3ed787bb299b3aa18f9d4b18d0d4 Mon Sep 17 00:00:00 2001 From: Cengizhan Pasaoglu Date: Wed, 12 Jul 2023 22:18:18 +0300 Subject: [PATCH 042/119] [CI] Upgrade GoogleTest version from 1.12.1 to 1.13.0 (#2114) --- .github/workflows/benchmark.yml | 4 +- .github/workflows/ci.yml | 35 ++++++----- .github/workflows/codeql-analysis.yml | 8 ++- CMakeLists.txt | 4 +- bazel/repository.bzl | 6 +- ci/do_ci.sh | 16 +++++- ci/setup_cmake.sh | 83 ++++++++++++++++----------- third_party_release | 2 +- 8 files changed, 95 insertions(+), 63 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 1826603214..cc63677a24 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -25,8 +25,8 @@ jobs: key: bazel_benchmark - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: Run benchmark id: run_benchmarks run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1666dabbb..ff33aa46e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,6 @@ jobs: env: CC: /usr/bin/gcc-12 CXX: /usr/bin/g++-12 - GOOGLETEST_VERSION: 1.12.1 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -109,7 +108,6 @@ jobs: env: CC: /usr/bin/gcc-12 CXX: /usr/bin/g++-12 - GOOGLETEST_VERSION: 1.12.1 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -142,7 +140,6 @@ jobs: env: CC: /usr/bin/clang-14 CXX: /usr/bin/clang++-14 - GOOGLETEST_VERSION: 1.12.1 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -175,7 +172,6 @@ jobs: env: CC: /usr/bin/clang-14 CXX: /usr/bin/clang++-14 - GOOGLETEST_VERSION: 1.12.1 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -241,8 +237,8 @@ jobs: submodules: 'recursive' - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: run cmake tests (enable abseil-cpp) run: | sudo ./ci/install_abseil.sh @@ -257,8 +253,8 @@ jobs: submodules: 'recursive' - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: run cmake tests (enable opentracing-shim) run: ./ci/do_ci.sh cmake.opentracing_shim.test @@ -281,8 +277,9 @@ jobs: env: CC: /usr/bin/gcc-4.8 CXX: /usr/bin/g++-4.8 - GOOGLETEST_VERSION: "1.10.0" - run: sudo -E ./ci/setup_cmake.sh + GOOGLETEST_VERSION: 1.10.0 + run: | + sudo -E ./ci/setup_cmake.sh - name: run tests env: CC: /usr/bin/gcc-4.8 @@ -308,7 +305,7 @@ jobs: env: CC: /usr/bin/gcc-4.8 CXX: /usr/bin/g++-4.8 - GOOGLETEST_VERSION: "1.10.0" + GOOGLETEST_VERSION: 1.10.0 run: | sudo -E ./ci/setup_cmake.sh sudo -E ./ci/setup_grpc.sh -v 4.8 @@ -327,7 +324,7 @@ jobs: submodules: 'recursive' - name: setup env: - CMAKE_VERSION: "3.20.6" + CMAKE_VERSION: 3.20.6 run: | sudo -E ./ci/setup_ci_environment.sh sudo -E ./ci/setup_cmake.sh @@ -348,7 +345,7 @@ jobs: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" - CMAKE_VERSION: "3.20.6" + CMAKE_VERSION: 3.20.6 run: | sudo -E ./ci/setup_ci_environment.sh sudo -E ./ci/setup_cmake.sh @@ -374,8 +371,8 @@ jobs: submodules: 'recursive' - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: run otlp exporter tests run: | sudo ./ci/setup_grpc.sh @@ -390,8 +387,8 @@ jobs: submodules: 'recursive' - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: run otlp exporter tests run: | sudo ./ci/setup_grpc.sh @@ -406,8 +403,8 @@ jobs: submodules: 'recursive' - name: setup run: | - sudo ./ci/setup_cmake.sh - sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: run otlp exporter tests run: | sudo ./ci/setup_grpc.sh -T diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d86e1d55d2..15187cb39b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,9 +19,13 @@ jobs: run: | rm -rf third_party - name: Setup + env: + CC: /usr/bin/gcc-10 + CXX: /usr/bin/g++-10 + GOOGLETEST_VERSION: 1.12.1 run: | - sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh - sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 997c9440e8..321cf839ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,8 +216,8 @@ set(OTELCPP_PROTO_PATH if(WIN32) if(BUILD_TESTING) if(MSVC) - # GTest bug: https://github.com/google/googletest/issues/860 - add_compile_options(/wd4275) + # Warning as error: warning STL4036: is removed in C++20 + add_compile_options(/wd4996) endif() endif() option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 6831af9aa7..dd02fc98fc 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -46,10 +46,10 @@ def opentelemetry_cpp_deps(): maybe( http_archive, name = "com_google_googletest", - sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2", - strip_prefix = "googletest-release-1.12.1", + sha256 = "ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363", + strip_prefix = "googletest-1.13.0", urls = [ - "https://github.com/google/googletest/archive/release-1.12.1.tar.gz", + "https://github.com/google/googletest/archive/v1.13.0.tar.gz", ], ) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 69a6eef0c9..013a9f0ec8 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -89,6 +89,7 @@ if [[ "$1" == "cmake.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ @@ -103,6 +104,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -127,6 +129,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -175,6 +178,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ @@ -190,6 +194,7 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ @@ -203,6 +208,7 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \ -DWITH_OPENTRACING=ON \ "${SRC_DIR}" @@ -213,9 +219,9 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=20 \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ - -DCMAKE_CXX_STANDARD=20 \ ${IWYU} \ "${SRC_DIR}" eval "$MAKE_COMMAND" @@ -225,6 +231,7 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=20 \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ @@ -241,8 +248,8 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then export BUILD_ROOT="${BUILD_DIR}" ${SRC_DIR}/tools/build-benchmark.sh cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DCMAKE_CXX_STANDARD=11 \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ "${SRC_DIR}" make -j $(nproc) make test @@ -268,6 +275,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \ @@ -282,6 +290,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]] cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DBUILD_SHARED_LIBS=ON \ @@ -296,6 +305,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -310,6 +320,7 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -436,6 +447,7 @@ elif [[ "$1" == "code.coverage" ]]; then cd "${BUILD_DIR}" rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_STANDARD=14 \ -DCMAKE_CXX_FLAGS="-Werror --coverage $CXXFLAGS" \ "${SRC_DIR}" make diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh index cdce76b38d..9684aa1d55 100755 --- a/ci/setup_cmake.sh +++ b/ci/setup_cmake.sh @@ -9,50 +9,69 @@ export DEBIAN_FRONTEND=noninteractive apt-get update if [ "x$CMAKE_VERSION" = "x" ]; then + # By default, CMake version set the following version. export CMAKE_VERSION=3.15.2 fi -if [ "x$GOOGLETEST_VERSION" = "x" ]; then - export GOOGLETEST_VERSION=1.12.1 +# This variable not set on CI pipeline for only legacy environment(GCC 4.8). +# With 1.13.0 version, C++14 must be set which does not supported by legacy environment anymore. +# Also with this version, release version path needs to be adapted. +if [ -z "${GOOGLETEST_VERSION}" ]; then + # By default, GoogleTest version set the following version. + export GOOGLETEST_VERSION=1.13.0 fi -cmake_install() { - tmp_dir=$(mktemp -d) - pushd $tmp_dir - wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh - chmod +x cmake-${CMAKE_VERSION}-Linux-x86_64.sh - ./cmake-${CMAKE_VERSION}-Linux-x86_64.sh --prefix=/usr/local --skip-license - rm cmake-${CMAKE_VERSION}-Linux-x86_64.sh - popd +OLD_GOOGLETEST_VERSION_REGEXP="^1\.([0-9]|10|11|12)(\..*)?$" + +# If GoogleTest version less than ${GOOGLETEST_LATEST_VERSION} +# Else otherwise +if [[ ${GOOGLETEST_VERSION} =~ ${OLD_GOOGLETEST_VERSION_REGEXP} ]]; then + GOOGLETEST_VERSION_PATH="release-${GOOGLETEST_VERSION}" + GOOGLETEST_FOLDER_PATH="googletest-release-${GOOGLETEST_VERSION}" +else + GOOGLETEST_VERSION_PATH="v${GOOGLETEST_VERSION}" + GOOGLETEST_FOLDER_PATH="googletest-${GOOGLETEST_VERSION}" +fi + +cmake_install() +{ + tmp_dir=$(mktemp -d) + pushd $tmp_dir + wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh + chmod +x cmake-${CMAKE_VERSION}-Linux-x86_64.sh + ./cmake-${CMAKE_VERSION}-Linux-x86_64.sh --prefix=/usr/local --skip-license + rm cmake-${CMAKE_VERSION}-Linux-x86_64.sh + popd } -googletest_install() { - # Follows these instructions - # https://gist.github.com/dlime/313f74fd23e4267c4a915086b84c7d3d - tmp_dir=$(mktemp -d) - pushd $tmp_dir - wget https://github.com/google/googletest/archive/release-${GOOGLETEST_VERSION}.tar.gz - tar -xf release-${GOOGLETEST_VERSION}.tar.gz - cd googletest-release-${GOOGLETEST_VERSION}/ - mkdir build && cd build - cmake .. -DBUILD_SHARED_LIBS=ON -DINSTALL_GTEST=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr - make -j $(nproc) - make install - ldconfig - popd +googletest_install() +{ + # Follows these instructions + # https://gist.github.com/dlime/313f74fd23e4267c4a915086b84c7d3d + tmp_dir=$(mktemp -d) + pushd $tmp_dir + wget https://github.com/google/googletest/archive/${GOOGLETEST_VERSION_PATH}.tar.gz + tar -xf ${GOOGLETEST_VERSION_PATH}.tar.gz + cd ${GOOGLETEST_FOLDER_PATH}/ + mkdir build && cd build + cmake .. -DBUILD_SHARED_LIBS=ON -DINSTALL_GTEST=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr + make -j $(nproc) + make install + ldconfig + popd } cmake_install set +e -echo \ - libbenchmark-dev \ - zlib1g-dev \ - sudo \ - libcurl4-openssl-dev \ - nlohmann-json-dev \ - nlohmann-json3 \ - nlohmann-json3-dev | xargs -n 1 apt-get install --ignore-missing --no-install-recommends --no-install-suggests -y +echo \ + libbenchmark-dev \ + zlib1g-dev \ + sudo \ + libcurl4-openssl-dev \ + nlohmann-json-dev \ + nlohmann-json3 \ + nlohmann-json3-dev | xargs -n 1 apt-get install --ignore-missing --no-install-recommends --no-install-suggests -y set -e googletest_install diff --git a/third_party_release b/third_party_release index 2120898cd9..9fae12fc31 100644 --- a/third_party_release +++ b/third_party_release @@ -16,7 +16,7 @@ gRPC=v1.49.2 abseil=20220623.1 benchmark=v1.7.1 -googletest=release-1.12.1 +googletest=release-1.13.0 ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.11.2 opentelemetry-proto=v1.0.0 From bc23e6a43f0c48a6e41602f1ec6d98c6438f031d Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 13 Jul 2023 00:13:08 +0200 Subject: [PATCH 043/119] [CI] Misc build scripts cleanup (#2232) --- CMakeLists.txt | 6 ------ ci/setup_cmake.sh | 9 +++------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 321cf839ac..4c8c126888 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,12 +214,6 @@ set(OTELCPP_PROTO_PATH CACHE PATH "Path to opentelemetry-proto") if(WIN32) - if(BUILD_TESTING) - if(MSVC) - # Warning as error: warning STL4036: is removed in C++20 - add_compile_options(/wd4996) - endif() - endif() option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON) endif(WIN32) diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh index 9684aa1d55..7194286b86 100755 --- a/ci/setup_cmake.sh +++ b/ci/setup_cmake.sh @@ -13,22 +13,19 @@ if [ "x$CMAKE_VERSION" = "x" ]; then export CMAKE_VERSION=3.15.2 fi -# This variable not set on CI pipeline for only legacy environment(GCC 4.8). -# With 1.13.0 version, C++14 must be set which does not supported by legacy environment anymore. -# Also with this version, release version path needs to be adapted. if [ -z "${GOOGLETEST_VERSION}" ]; then - # By default, GoogleTest version set the following version. + # Version by default. Requires C++14. export GOOGLETEST_VERSION=1.13.0 fi OLD_GOOGLETEST_VERSION_REGEXP="^1\.([0-9]|10|11|12)(\..*)?$" -# If GoogleTest version less than ${GOOGLETEST_LATEST_VERSION} -# Else otherwise if [[ ${GOOGLETEST_VERSION} =~ ${OLD_GOOGLETEST_VERSION_REGEXP} ]]; then + # Old (up to 1.12.x included) download URL format. GOOGLETEST_VERSION_PATH="release-${GOOGLETEST_VERSION}" GOOGLETEST_FOLDER_PATH="googletest-release-${GOOGLETEST_VERSION}" else + # New (since 1.13.0) download URL format. GOOGLETEST_VERSION_PATH="v${GOOGLETEST_VERSION}" GOOGLETEST_FOLDER_PATH="googletest-${GOOGLETEST_VERSION}" fi From 038e65d7f25424f9a6e52caf88a85316f20959cc Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 13 Jul 2023 13:59:43 -0700 Subject: [PATCH 044/119] Add support for LowMemory metrics temporality (#2234) --- exporters/otlp/BUILD | 1 + .../otlp/otlp_grpc_metric_exporter_options.h | 5 +- .../otlp/otlp_http_metric_exporter_options.h | 6 +- .../exporters/otlp/otlp_metric_utils.h | 5 +- .../otlp/otlp_preferred_temporality.h | 23 ++++++ exporters/otlp/src/otlp_metric_utils.cc | 26 ++++++- .../test/otlp_http_metric_exporter_test.cc | 73 +++++++++++++++++++ 7 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 01dc83f00b..5e52bfd393 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -20,6 +20,7 @@ cc_library( "include/opentelemetry/exporters/otlp/otlp_log_recordable.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/exporters/otlp/otlp_recordable.h", "include/opentelemetry/exporters/otlp/otlp_recordable_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h index b3d5f9b9a7..a56cf8cb55 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" #include "opentelemetry/sdk/metrics/instruments.h" #include @@ -21,8 +22,8 @@ struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions { // Preferred Aggregation Temporality - sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kCumulative; + PreferredAggregationTemporality aggregation_temporality = + PreferredAggregationTemporality::kCumulative; }; } // namespace otlp 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 e37e123097..8aa0ccad21 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 @@ -5,7 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" -#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" #include #include @@ -50,8 +50,8 @@ struct OtlpHttpMetricExporterOptions OtlpHeaders http_headers = GetOtlpDefaultMetricsHeaders(); // Preferred Aggregation Temporality - sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kCumulative; + PreferredAggregationTemporality aggregation_temporality = + PreferredAggregationTemporality::kCumulative; #ifdef ENABLE_ASYNC_EXPORT // Concurrent requests 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 8efbad2453..1adca861d8 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h @@ -9,6 +9,7 @@ #include "opentelemetry/proto/metrics/v1/metrics.pb.h" #include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" @@ -52,11 +53,13 @@ class OtlpMetricUtils proto::collector::metrics::v1::ExportMetricsServiceRequest *request) noexcept; static sdk::metrics::AggregationTemporalitySelector ChooseTemporalitySelector( - sdk::metrics::AggregationTemporality preferred_aggregation_temporality) noexcept; + PreferredAggregationTemporality preferred_aggregation_temporality) noexcept; static sdk::metrics::AggregationTemporality DeltaTemporalitySelector( sdk::metrics::InstrumentType instrument_type) noexcept; static sdk::metrics::AggregationTemporality CumulativeTemporalitySelector( sdk::metrics::InstrumentType instrument_type) noexcept; + static sdk::metrics::AggregationTemporality LowMemoryTemporalitySelector( + sdk::metrics::InstrumentType instrument_type) noexcept; }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h new file mode 100644 index 0000000000..d9e4013fd5 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h @@ -0,0 +1,23 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +enum class PreferredAggregationTemporality +{ + kUnspecified, + kDelta, + kCumulative, + kLowMemory, +}; + +} +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index f642bbf85e..50c5fdd9cc 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -247,13 +247,17 @@ void OtlpMetricUtils::PopulateRequest( } sdk::metrics::AggregationTemporalitySelector OtlpMetricUtils::ChooseTemporalitySelector( - sdk::metrics::AggregationTemporality preferred_aggregation_temporality) noexcept + PreferredAggregationTemporality preferred_aggregation_temporality) noexcept { - if (preferred_aggregation_temporality == sdk::metrics::AggregationTemporality::kDelta) + if (preferred_aggregation_temporality == PreferredAggregationTemporality::kDelta) { return DeltaTemporalitySelector; } - return CumulativeTemporalitySelector; + else if (preferred_aggregation_temporality == PreferredAggregationTemporality::kCumulative) + { + return CumulativeTemporalitySelector; + } + return LowMemoryTemporalitySelector; } sdk::metrics::AggregationTemporality OtlpMetricUtils::DeltaTemporalitySelector( @@ -279,6 +283,22 @@ sdk::metrics::AggregationTemporality OtlpMetricUtils::CumulativeTemporalitySelec return sdk::metrics::AggregationTemporality::kCumulative; } +sdk::metrics::AggregationTemporality OtlpMetricUtils::LowMemoryTemporalitySelector( + sdk::metrics::InstrumentType instrument_type) noexcept +{ + switch (instrument_type) + { + case sdk::metrics::InstrumentType::kCounter: + case sdk::metrics::InstrumentType::kHistogram: + return sdk::metrics::AggregationTemporality::kDelta; + case sdk::metrics::InstrumentType::kObservableCounter: + case sdk::metrics::InstrumentType::kObservableGauge: + case sdk::metrics::InstrumentType::kUpDownCounter: + case sdk::metrics::InstrumentType::kObservableUpDownCounter: + return sdk::metrics::AggregationTemporality::kCumulative; + } + return sdk::metrics::AggregationTemporality::kUnspecified; +} } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 97586b101c..ed7c4dba30 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -11,6 +11,7 @@ #include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" +#include "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" #include "opentelemetry/common/key_value_iterable_view.h" @@ -976,6 +977,78 @@ TEST_F(OtlpHttpMetricExporterTestPeer, CheckDefaultTemporality) } #endif +// Test Preferred aggregtion temporality selection +TEST_F(OtlpHttpMetricExporterTestPeer, PreferredAggergationTemporality) +{ + // Cummulative aggregation selector : use cummulative aggregation for all instruments. + std::unique_ptr exporter(new OtlpHttpMetricExporter()); + EXPECT_EQ(GetOptions(exporter).aggregation_temporality, + PreferredAggregationTemporality::kCumulative); + auto cumm_selector = + OtlpMetricUtils::ChooseTemporalitySelector(GetOptions(exporter).aggregation_temporality); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kHistogram), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableGauge), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(cumm_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + + // LowMemory aggregation selector use: + // - cummulative aggregtion for Counter and Histogram + // - delta aggregation for up-down counter, observable counter, observable gauge, observable + // up-down counter + OtlpHttpMetricExporterOptions opts2; + opts2.aggregation_temporality = PreferredAggregationTemporality::kLowMemory; + std::unique_ptr exporter2(new OtlpHttpMetricExporter(opts2)); + EXPECT_EQ(GetOptions(exporter2).aggregation_temporality, + PreferredAggregationTemporality::kLowMemory); + auto lowmemory_selector = + OtlpMetricUtils::ChooseTemporalitySelector(GetOptions(exporter2).aggregation_temporality); + EXPECT_EQ(lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + EXPECT_EQ(lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kHistogram), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + + EXPECT_EQ(lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableGauge), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ( + lowmemory_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + + // Delta aggregation selector use: + // - delta aggregtion for Counter, Histogram, Observable Counter, Observable Gauge + // - cummulative aggregation for up-down counter, observable up-down counter + OtlpHttpMetricExporterOptions opts3; + opts3.aggregation_temporality = PreferredAggregationTemporality::kDelta; + std::unique_ptr exporter3(new OtlpHttpMetricExporter(opts3)); + EXPECT_EQ(GetOptions(exporter3).aggregation_temporality, PreferredAggregationTemporality::kDelta); + auto delta_selector = + OtlpMetricUtils::ChooseTemporalitySelector(GetOptions(exporter3).aggregation_temporality); + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kHistogram), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableGauge), + opentelemetry::sdk::metrics::AggregationTemporality::kDelta); + + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); + EXPECT_EQ(delta_selector(opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter), + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE From 2974eb8eefff4d1ef6e0ce134ee77325f17accd8 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 21 Jul 2023 02:05:02 +0800 Subject: [PATCH 045/119] Add OStreamLogRecordExporterFactory (#2240) --- exporters/ostream/BUILD | 2 + exporters/ostream/CMakeLists.txt | 12 +++-- .../ostream/log_record_exporter_factory.h | 46 +++++++++++++++++++ .../src/log_record_exporter_factory.cc | 31 +++++++++++++ exporters/ostream/test/ostream_log_test.cc | 8 ++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h create mode 100644 exporters/ostream/src/log_record_exporter_factory.cc diff --git a/exporters/ostream/BUILD b/exporters/ostream/BUILD index a8af2e6c28..177bf6a968 100644 --- a/exporters/ostream/BUILD +++ b/exporters/ostream/BUILD @@ -7,10 +7,12 @@ cc_library( name = "ostream_log_record_exporter", srcs = [ "src/log_record_exporter.cc", + "src/log_record_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/ostream/common_utils.h", "include/opentelemetry/exporters/ostream/log_record_exporter.h", + "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h", ], strip_include_prefix = "include", tags = ["ostream"], diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index 10e0792de8..478c6b7ec2 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -27,7 +27,7 @@ if(OPENTELEMETRY_INSTALL) DIRECTORY include/opentelemetry/exporters/ostream DESTINATION include/opentelemetry/exporters PATTERN "*.h" - PATTERN "log_Exporter.h" EXCLUDE) + PATTERN "log_record_exporter.h" EXCLUDE) endif() if(BUILD_TESTING) @@ -77,7 +77,8 @@ if(BUILD_TESTING) endif() if(WITH_LOGS_PREVIEW) - add_library(opentelemetry_exporter_ostream_logs src/log_record_exporter.cc) + add_library(opentelemetry_exporter_ostream_logs + src/log_record_exporter.cc src/log_record_exporter_factory.cc) set_target_properties(opentelemetry_exporter_ostream_logs PROPERTIES EXPORT_NAME ostream_log_record_exporter) set_target_version(opentelemetry_exporter_ostream_logs) @@ -96,9 +97,10 @@ if(WITH_LOGS_PREVIEW) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( - DIRECTORY include/opentelemetry/exporters/ostream - DESTINATION include/opentelemetry/exporters - PATTERN "log_record_exporter.h") + FILES + "include/opentelemetry/exporters/ostream/log_record_exporter.h" + "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" + DESTINATION include/opentelemetry/exporters/ostream) endif() if(BUILD_TESTING) 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 new file mode 100644 index 0000000000..4c7d403d41 --- /dev/null +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter_factory.h @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW +# include +# include + +# include "opentelemetry/sdk/version/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ +class LogRecordExporter; +} // namespace logs +} // namespace sdk + +namespace exporter +{ +namespace logs +{ + +/** + * Factory class for OStreamLogRecordExporter. + */ +class OPENTELEMETRY_EXPORT OStreamLogRecordExporterFactory +{ +public: + /** + * Creates an OStreamLogRecordExporter writing to the default location. + */ + static std::unique_ptr Create(); + + /** + * Creates an OStreamLogRecordExporter writing to the given location. + */ + static std::unique_ptr Create(std::ostream &sout); +}; + +} // namespace logs +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/ostream/src/log_record_exporter_factory.cc b/exporters/ostream/src/log_record_exporter_factory.cc new file mode 100644 index 0000000000..884f59a9a1 --- /dev/null +++ b/exporters/ostream/src/log_record_exporter_factory.cc @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" +# include "opentelemetry/exporters/ostream/log_record_exporter.h" + +namespace logs_sdk = opentelemetry::sdk::logs; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace logs +{ + +std::unique_ptr OStreamLogRecordExporterFactory::Create() +{ + return Create(std::cout); +} + +std::unique_ptr OStreamLogRecordExporterFactory::Create( + std::ostream &sout) +{ + std::unique_ptr exporter(new OStreamLogRecordExporter(sout)); + return exporter; +} + +} // namespace logs +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 92ff3ece76..c092ec01c3 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -4,6 +4,7 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/ostream/log_record_exporter.h" +# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/nostd/span.h" # include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" @@ -507,6 +508,13 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) } } +// Test using the factory to create the ostream exporter +TEST(OStreamLogRecordExporter, Factory) +{ + auto exporter = OStreamLogRecordExporterFactory::Create(); + ASSERT_NE(exporter, nullptr); +} + } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE From a15a9b81012cea615125f17cd0d5f1fdc16a849a Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 20 Jul 2023 11:53:32 -0700 Subject: [PATCH 046/119] [Metrics SDK] Add unit to Instrument selection criteria (#2236) --- CHANGELOG.md | 8 ++++++ examples/metrics_simple/metrics_ostream.cc | 16 ++++++----- examples/prometheus/main.cc | 12 ++++---- .../sdk/metrics/view/instrument_selector.h | 8 ++++-- .../view/instrument_selector_factory.h | 3 +- .../opentelemetry/sdk/metrics/view/view.h | 3 ++ .../sdk/metrics/view/view_factory.h | 7 +++++ .../sdk/metrics/view/view_registry.h | 1 + .../view/instrument_selector_factory.cc | 5 ++-- sdk/src/metrics/view/view_factory.cc | 18 +++++++++--- .../metrics/histogram_aggregation_test.cc | 7 +++-- sdk/test/metrics/histogram_test.cc | 22 +++++++++------ sdk/test/metrics/meter_provider_sdk_test.cc | 2 +- sdk/test/metrics/sum_aggregation_test.cc | 28 ++++++++++++------- sdk/test/metrics/view_registry_test.cc | 5 ++-- 15 files changed, 100 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2746663232..12bdc28c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,14 @@ Increment the: ## [Unreleased] +Breaking changes: + +* [SDK] Add unit to Instrument selection criteria + [#2236](https://github.com/open-telemetry/opentelemetry-cpp/pull/2236) + * The `View` constructor and `ViewFactory::Create` method now takes a + `unit` criteria as optional third argument. + * Please adjust SDK configuration code accordingly. + ## [1.10.0] 2023-07-11 * [REMOVAL] Remove the jaeger exporter diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index a81937099d..7248bc9148 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -53,14 +53,15 @@ void InitMetrics(const std::string &name) // counter view std::string counter_name = name + "_counter"; + std::string unit = "counter-unit"; auto instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( - metrics_sdk::InstrumentType::kCounter, counter_name); + metrics_sdk::InstrumentType::kCounter, counter_name, unit); auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); - auto sum_view = - metrics_sdk::ViewFactory::Create(name, "description", metrics_sdk::AggregationType::kSum); + auto sum_view = metrics_sdk::ViewFactory::Create(name, "description", unit, + metrics_sdk::AggregationType::kSum); p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); @@ -68,11 +69,11 @@ void InitMetrics(const std::string &name) std::string observable_counter_name = name + "_observable_counter"; auto observable_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( - metrics_sdk::InstrumentType::kObservableCounter, observable_counter_name); + metrics_sdk::InstrumentType::kObservableCounter, observable_counter_name, unit); auto observable_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); - auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description", + auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description", unit, metrics_sdk::AggregationType::kSum); p->AddView(std::move(observable_instrument_selector), std::move(observable_meter_selector), @@ -80,9 +81,10 @@ void InitMetrics(const std::string &name) // histogram view std::string histogram_name = name + "_histogram"; + unit = "histogram-unit"; auto histogram_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( - metrics_sdk::InstrumentType::kHistogram, histogram_name); + metrics_sdk::InstrumentType::kHistogram, histogram_name, unit); auto histogram_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); @@ -96,7 +98,7 @@ void InitMetrics(const std::string &name) std::move(histogram_aggregation_config)); auto histogram_view = metrics_sdk::ViewFactory::Create( - name, "description", metrics_sdk::AggregationType::kHistogram, aggregation_config); + name, "description", unit, metrics_sdk::AggregationType::kHistogram, aggregation_config); p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); diff --git a/examples/prometheus/main.cc b/examples/prometheus/main.cc index 6902a6b3e0..27fd8bced7 100644 --- a/examples/prometheus/main.cc +++ b/examples/prometheus/main.cc @@ -52,27 +52,29 @@ void InitMetrics(const std::string &name, const std::string &addr) // counter view std::string counter_name = name + "_counter"; + std::string counter_unit = "unit"; auto instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( - metrics_sdk::InstrumentType::kCounter, counter_name); + metrics_sdk::InstrumentType::kCounter, counter_name, counter_unit); auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); - auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description", + auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description", counter_unit, metrics_sdk::AggregationType::kSum); p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); // histogram view std::string histogram_name = name + "_histogram"; + std::string histogram_unit = "unit"; auto histogram_instrument_selector = metrics_sdk::InstrumentSelectorFactory::Create( - metrics_sdk::InstrumentType::kHistogram, histogram_name); + metrics_sdk::InstrumentType::kHistogram, histogram_name, histogram_unit); auto histogram_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema); - auto histogram_view = metrics_sdk::ViewFactory::Create(histogram_name, "description", - metrics_sdk::AggregationType::kHistogram); + auto histogram_view = metrics_sdk::ViewFactory::Create( + histogram_name, "description", histogram_unit, metrics_sdk::AggregationType::kHistogram); p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h index 2055ed96fa..67c8592bb6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h @@ -19,19 +19,23 @@ class InstrumentSelector { public: InstrumentSelector(opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name) + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view units) : name_filter_{PredicateFactory::GetPredicate(name, PredicateType::kPattern)}, + unit_filter_{PredicateFactory::GetPredicate(units, PredicateType::kExact)}, instrument_type_{instrument_type} {} // Returns name filter predicate. This shouldn't be deleted const opentelemetry::sdk::metrics::Predicate *GetNameFilter() const { return name_filter_.get(); } - + // Returns unit filter predicate. This shouldn't be deleted + const opentelemetry::sdk::metrics::Predicate *GetUnitFilter() const { return unit_filter_.get(); } // Returns instrument filter. InstrumentType GetInstrumentType() { return instrument_type_; } private: std::unique_ptr name_filter_; + std::unique_ptr unit_filter_; opentelemetry::sdk::metrics::InstrumentType instrument_type_; }; } // namespace metrics 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 e5b8b83704..f30b1e27c1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h @@ -19,7 +19,8 @@ class InstrumentSelectorFactory public: static std::unique_ptr Create( opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name); + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view unit); }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index 2d3edcee0e..dc0888f47d 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -26,6 +26,7 @@ class View public: View(const std::string &name, const std::string &description = "", + const std::string &unit = "", AggregationType aggregation_type = AggregationType::kDefault, std::shared_ptr aggregation_config = nullptr, std::unique_ptr attributes_processor = @@ -33,6 +34,7 @@ class View new opentelemetry::sdk::metrics::DefaultAttributesProcessor())) : name_(name), description_(description), + unit_(unit), aggregation_type_{aggregation_type}, aggregation_config_{aggregation_config}, attributes_processor_{std::move(attributes_processor)} @@ -60,6 +62,7 @@ class View private: std::string name_; std::string description_; + std::string unit_; AggregationType aggregation_type_; std::shared_ptr aggregation_config_; std::unique_ptr attributes_processor_; diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h index 5e7da2ea62..22d34bf506 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_factory.h @@ -30,15 +30,22 @@ class OPENTELEMETRY_EXPORT ViewFactory static std::unique_ptr Create(const std::string &name, const std::string &description, + const std::string &unit); + + static std::unique_ptr Create(const std::string &name, + const std::string &description, + const std::string &unit, AggregationType aggregation_type); static std::unique_ptr Create(const std::string &name, const std::string &description, + const std::string &unit, AggregationType aggregation_type, std::shared_ptr aggregation_config); static std::unique_ptr Create(const std::string &name, const std::string &description, + const std::string &unit, AggregationType aggregation_type, std::shared_ptr aggregation_config, std::unique_ptr attributes_processor); diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index d017bd7107..40343c28de 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -99,6 +99,7 @@ class ViewRegistry const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor) { return selector->GetNameFilter()->Match(instrument_descriptor.name_) && + selector->GetUnitFilter()->Match(instrument_descriptor.unit_) && (selector->GetInstrumentType() == instrument_descriptor.type_); } }; diff --git a/sdk/src/metrics/view/instrument_selector_factory.cc b/sdk/src/metrics/view/instrument_selector_factory.cc index 24542a57cd..98a587ea62 100644 --- a/sdk/src/metrics/view/instrument_selector_factory.cc +++ b/sdk/src/metrics/view/instrument_selector_factory.cc @@ -13,10 +13,11 @@ namespace metrics std::unique_ptr InstrumentSelectorFactory::Create( opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name) + opentelemetry::nostd::string_view name, + opentelemetry::nostd::string_view unit) { std::unique_ptr instrument_selector( - new InstrumentSelector(instrument_type, name)); + new InstrumentSelector(instrument_type, name, unit)); return instrument_selector; } diff --git a/sdk/src/metrics/view/view_factory.cc b/sdk/src/metrics/view/view_factory.cc index 2e410accc6..24d87769f9 100644 --- a/sdk/src/metrics/view/view_factory.cc +++ b/sdk/src/metrics/view/view_factory.cc @@ -18,36 +18,46 @@ std::unique_ptr ViewFactory::Create(const std::string &name) std::unique_ptr ViewFactory::Create(const std::string &name, const std::string &description) { - return Create(name, description, AggregationType::kDefault); + return Create(name, description, "", AggregationType::kDefault); } std::unique_ptr ViewFactory::Create(const std::string &name, const std::string &description, + const std::string &unit) +{ + return Create(name, description, unit, AggregationType::kDefault); +} + +std::unique_ptr ViewFactory::Create(const std::string &name, + const std::string &description, + const std::string &unit, AggregationType aggregation_type) { std::shared_ptr aggregation_config(nullptr); - return Create(name, description, aggregation_type, aggregation_config); + return Create(name, description, unit, aggregation_type, aggregation_config); } std::unique_ptr ViewFactory::Create(const std::string &name, const std::string &description, + const std::string &unit, AggregationType aggregation_type, std::shared_ptr aggregation_config) { auto attributes_processor = std::unique_ptr(new DefaultAttributesProcessor()); - return Create(name, description, aggregation_type, aggregation_config, + return Create(name, description, unit, aggregation_type, aggregation_config, std::move(attributes_processor)); } std::unique_ptr ViewFactory::Create(const std::string &name, const std::string &description, + const std::string &unit, AggregationType aggregation_type, std::shared_ptr aggregation_config, std::unique_ptr attributes_processor) { - std::unique_ptr view(new View(name, description, aggregation_type, aggregation_config, + std::unique_ptr view(new View(name, description, unit, aggregation_type, aggregation_config, std::move(attributes_processor))); return view; } diff --git a/sdk/test/metrics/histogram_aggregation_test.cc b/sdk/test/metrics/histogram_aggregation_test.cc index fada036747..6fd13c902c 100644 --- a/sdk/test/metrics/histogram_aggregation_test.cc +++ b/sdk/test/metrics/histogram_aggregation_test.cc @@ -72,13 +72,14 @@ TEST(CounterToHistogram, Double) std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; mp.AddMetricReader(reader); - std::unique_ptr view{new View("view1", "view1_description", AggregationType::kHistogram)}; + std::unique_ptr view{ + new View("view1", "view1_description", "unit", AggregationType::kHistogram)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kCounter, "counter1")}; + new InstrumentSelector(InstrumentType::kCounter, "counter1", "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->CreateDoubleCounter("counter1", "counter1_description", "counter1_unit"); + auto h = m->CreateDoubleCounter("counter1", "counter1_description", "unit"); h->Add(5, {}); h->Add(10, {}); diff --git a/sdk/test/metrics/histogram_test.cc b/sdk/test/metrics/histogram_test.cc index ef2d023c92..a11a9c1f59 100644 --- a/sdk/test/metrics/histogram_test.cc +++ b/sdk/test/metrics/histogram_test.cc @@ -78,7 +78,10 @@ TEST(Histogram, Double) TEST(Histogram, DoubleCustomBuckets) { MeterProvider mp; - auto m = mp.GetMeter("meter1", "version1", "schema1"); + 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))}; @@ -87,13 +90,13 @@ TEST(Histogram, DoubleCustomBuckets) std::shared_ptr config(new HistogramAggregationConfig()); config->boundaries_ = {10, 20, 30, 40}; std::unique_ptr view{ - new View("view1", "view1_description", AggregationType::kHistogram, config)}; + new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kHistogram, "histogram1")}; + 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("histogram1", "histogram1_description", "histogram1_unit"); + auto h = m->CreateDoubleHistogram(instrument_name, instrument_desc, instrument_unit); h->Record(5, {}); h->Record(10, {}); @@ -190,7 +193,10 @@ TEST(Histogram, UInt64) TEST(Histogram, UInt64CustomBuckets) { MeterProvider mp; - auto m = mp.GetMeter("meter1", "version1", "schema1"); + 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))}; @@ -199,13 +205,13 @@ TEST(Histogram, UInt64CustomBuckets) std::shared_ptr config(new HistogramAggregationConfig()); config->boundaries_ = {10, 20, 30, 40}; std::unique_ptr view{ - new View("view1", "view1_description", AggregationType::kHistogram, config)}; + new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kHistogram, "histogram1")}; + 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("histogram1", "histogram1_description", "histogram1_unit"); + auto h = m->CreateUInt64Histogram(instrument_name, instrument_desc, instrument_unit); h->Record(5, {}); h->Record(10, {}); diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index da75916555..a1ca8de330 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -49,7 +49,7 @@ TEST(MeterProvider, GetMeter) std::unique_ptr view{std::unique_ptr()}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kCounter, "instru1")}; + new InstrumentSelector(InstrumentType::kCounter, "instru1", "unit1")}; std::unique_ptr meter_selector{new MeterSelector("name1", "version1", "schema1")}; mp1.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index 9fb1804022..b355f134ed 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -22,19 +22,23 @@ using namespace opentelemetry::sdk::metrics; TEST(HistogramToSum, Double) { MeterProvider mp; - auto m = mp.GetMeter("meter1", "version1", "schema1"); + 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::unique_ptr view{new View("view1", "view1_description", AggregationType::kSum)}; + std::unique_ptr view{ + new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kHistogram, "histogram1")}; + 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("histogram1", "histogram1_description", "histogram1_unit"); + auto h = m->CreateDoubleHistogram(instrument_name, instrument_desc, instrument_unit); h->Record(5, {}); h->Record(10, {}); @@ -77,9 +81,9 @@ TEST(CounterToSum, Double) std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; mp.AddMetricReader(reader); - std::unique_ptr view{new View("view1", "view1_description", AggregationType::kSum)}; + std::unique_ptr view{new View("view1", "view1_description", "ms", AggregationType::kSum)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kCounter, "counter1")}; + new InstrumentSelector(InstrumentType::kCounter, "counter1", "ms")}; std::unique_ptr meter_selector{new MeterSelector("meter1", "version1", "schema1")}; mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); @@ -120,19 +124,23 @@ TEST(CounterToSum, Double) TEST(UpDownCounterToSum, Double) { MeterProvider mp; - auto m = mp.GetMeter("meter1", "version1", "schema1"); + auto m = mp.GetMeter("meter1", "version1", "schema1"); + std::string instrument_name = "updowncounter1"; + std::string instrument_desc = "updowncounter desc"; + std::string instrument_unit = "ms"; std::unique_ptr exporter(new MockMetricExporter()); std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; mp.AddMetricReader(reader); - std::unique_ptr view{new View("view1", "view1_description", AggregationType::kSum)}; + std::unique_ptr view{ + new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kUpDownCounter, "counter1")}; + new InstrumentSelector(InstrumentType::kUpDownCounter, 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->CreateDoubleUpDownCounter("counter1", "counter1_description", "counter1_unit"); + auto h = m->CreateDoubleUpDownCounter(instrument_name, instrument_desc, instrument_unit); h->Add(5, {}); h->Add(10, {}); diff --git a/sdk/test/metrics/view_registry_test.cc b/sdk/test/metrics/view_registry_test.cc index 59899dedb0..49e475a9f1 100644 --- a/sdk/test/metrics/view_registry_test.cc +++ b/sdk/test/metrics/view_registry_test.cc @@ -55,9 +55,10 @@ TEST(ViewRegistry, FindNonExistingView) const std::string instrumentation_schema = "schema1"; const std::string instrument_name = "testname"; const InstrumentType instrument_type = InstrumentType::kCounter; + const std::string instrument_unit = "ms"; std::unique_ptr instrument_selector{ - new InstrumentSelector(instrument_type, instrument_name)}; + new InstrumentSelector(instrument_type, instrument_name, instrument_unit)}; std::unique_ptr meter_selector{ new MeterSelector(instrumentation_name, instrumentation_version, instrumentation_schema)}; std::unique_ptr view = std::unique_ptr(new View(view_name, view_description)); @@ -66,7 +67,7 @@ TEST(ViewRegistry, FindNonExistingView) registry.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); InstrumentDescriptor default_instrument_descriptor = {instrument_name, // name "test_descr", // description - "1", // unit + instrument_unit, // unit instrument_type, // instrument type InstrumentValueType::kLong}; From 92a8a54c6f51ab501f789894cfde1a416f670e64 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Fri, 21 Jul 2023 15:54:24 +0800 Subject: [PATCH 047/119] [BUILD] Fix compile with clang 16 and libc++ (#2242) --- .../opentelemetry/sdk/logs/simple_log_record_processor.h | 2 +- sdk/src/logs/simple_log_record_processor.cc | 2 ++ sdk/src/metrics/data/circular_buffer.cc | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) 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 4bb3dab2de..8b273c6bb2 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h @@ -33,7 +33,7 @@ class SimpleLogRecordProcessor : public LogRecordProcessor public: explicit SimpleLogRecordProcessor(std::unique_ptr &&exporter); - ~SimpleLogRecordProcessor() override = default; + ~SimpleLogRecordProcessor() override; std::unique_ptr MakeRecordable() noexcept override; diff --git a/sdk/src/logs/simple_log_record_processor.cc b/sdk/src/logs/simple_log_record_processor.cc index 6514c7acff..2c33739bef 100644 --- a/sdk/src/logs/simple_log_record_processor.cc +++ b/sdk/src/logs/simple_log_record_processor.cc @@ -23,6 +23,8 @@ SimpleLogRecordProcessor::SimpleLogRecordProcessor(std::unique_ptr SimpleLogRecordProcessor::MakeRecordable() noexcept { return exporter_->MakeRecordable(); diff --git a/sdk/src/metrics/data/circular_buffer.cc b/sdk/src/metrics/data/circular_buffer.cc index 9117e67ae5..93d8fd6eeb 100644 --- a/sdk/src/metrics/data/circular_buffer.cc +++ b/sdk/src/metrics/data/circular_buffer.cc @@ -55,7 +55,7 @@ struct AdaptingIntegerArrayClear template void operator()(std::vector &backing) { - std::fill(backing.begin(), backing.end(), static_cast(0)); + backing.assign(backing.size(), static_cast(0)); } }; From 0c5f90dea5147461df4ff7d32cbb5d42e5011daa Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 22 Jul 2023 16:51:57 +0200 Subject: [PATCH 048/119] [SDK] Valgrind errors on std::atomic variables (#2244) --- .../elasticsearch/es_log_record_exporter.h | 4 ++-- exporters/otlp/src/otlp_http_client.cc | 8 +++----- .../ext/http/client/curl/http_client_curl.h | 6 +++--- .../ext/http/client/curl/http_operation_curl.h | 12 ++++++------ .../ext/zpages/tracez_data_aggregator.h | 2 +- ext/test/http/curl_http_test.cc | 4 ++-- .../sdk/logs/batch_log_record_processor.h | 10 +++++----- .../sdk/logs/simple_log_record_processor.h | 2 +- .../export/periodic_exporting_metric_reader.h | 6 +++--- .../sdk/trace/batch_span_processor.h | 10 +++++----- sdk/src/logs/batch_log_record_processor.cc | 15 ++------------- sdk/src/trace/batch_span_processor.cc | 8 +------- 12 files changed, 34 insertions(+), 53 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 06b4c3b727..63e096ff97 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 @@ -125,8 +125,8 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo # ifdef ENABLE_ASYNC_EXPORT struct SynchronizationData { - std::atomic session_counter_; - std::atomic finished_session_counter_; + std::atomic session_counter_{0}; + std::atomic finished_session_counter_{0}; std::condition_variable force_flush_cv; std::mutex force_flush_cv_m; std::recursive_mutex force_flush_m; diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 44c154f725..a249a842ad 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -64,7 +64,7 @@ namespace { /** - * This class handles the response message from the Elasticsearch request + * This class handles the response message from the HTTP request */ class ResponseHandler : public http_client::EventHandler { @@ -75,9 +75,7 @@ class ResponseHandler : public http_client::EventHandler ResponseHandler(std::function &&callback, bool console_debug = false) : result_callback_{std::move(callback)}, console_debug_{console_debug} - { - stopping_.store(false); - } + {} std::string BuildResponseLogMessage(http_client::Response &response, const std::string &body) noexcept @@ -356,7 +354,7 @@ class ResponseHandler : public http_client::EventHandler const opentelemetry::ext::http::client::Session *session_ = nullptr; // Whether notify has been called - std::atomic stopping_; + std::atomic stopping_{false}; // A string to store the response body std::string body_ = ""; 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 900c5b6e81..876d9fab4f 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 @@ -159,7 +159,7 @@ class Session : public opentelemetry::ext::http::client::Session, std::string scheme = "http", const std::string &host = "", uint16_t port = 80) - : http_client_(http_client), is_session_active_(false) + : http_client_(http_client) { host_ = scheme + "://" + host + ":" + std::to_string(port) + "/"; } @@ -216,7 +216,7 @@ class Session : public opentelemetry::ext::http::client::Session, std::unique_ptr curl_operation_; uint64_t session_id_; HttpClient &http_client_; - std::atomic is_session_active_; + std::atomic is_session_active_{false}; }; class HttpClientSync : public opentelemetry::ext::http::client::HttpClientSync @@ -352,7 +352,7 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient std::mutex multi_handle_m_; CURLM *multi_handle_; - std::atomic next_session_id_; + std::atomic next_session_id_{0}; uint64_t max_sessions_per_connection_; std::mutex sessions_m_; 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 b711ac8445..48ce11123c 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 @@ -273,11 +273,11 @@ class HttpOperation const char *GetCurlErrorMessage(CURLcode code); - std::atomic is_aborted_; // Set to 'true' when async callback is aborted - std::atomic is_finished_; // Set to 'true' when async callback is finished. - std::atomic is_cleaned_; // Set to 'true' when async callback is cleaned. - const bool is_raw_response_; // Do not split response headers from response body - const bool reuse_connection_; // Reuse connection + std::atomic is_aborted_{false}; // Set to 'true' when async callback is aborted + std::atomic is_finished_{false}; // Set to 'true' when async callback is finished. + std::atomic is_cleaned_{false}; // Set to 'true' when async callback is cleaned. + const bool is_raw_response_; // Do not split response headers from response body + const bool reuse_connection_; // Reuse connection const std::chrono::milliseconds http_conn_timeout_; // Timeout for connect. Default: 5000ms char curl_error_message_[CURL_ERROR_SIZE]; @@ -311,7 +311,7 @@ class HttpOperation std::thread::id callback_thread; std::function callback; - std::atomic is_promise_running; + std::atomic is_promise_running{false}; std::promise result_promise; std::future result_future; }; diff --git a/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h b/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h index 28236b60f5..62c944b704 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h @@ -155,7 +155,7 @@ class TracezDataAggregator /** A boolean that is set to true in the constructor and false in the * destructor to start and end execution of aggregate spans **/ - std::atomic execute_; + std::atomic execute_{false}; /** Thread that executes aggregate spans at regurlar intervals during this object's lifetime**/ diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 1b9539c5f8..78ecd92a6f 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -99,8 +99,8 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe protected: HTTP_SERVER_NS::HttpServer server_; std::string server_address_; - std::atomic is_setup_; - std::atomic is_running_; + std::atomic is_setup_{false}; + std::atomic is_running_{false}; std::vector received_requests_; std::mutex mtx_requests; std::condition_variable cv_got_events; 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 23a1d947aa..d1cd045a58 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h @@ -115,11 +115,11 @@ class BatchLogRecordProcessor : public LogRecordProcessor std::mutex cv_m, force_flush_cv_m, shutdown_m; /* Important boolean flags to handle the workflow of the processor */ - std::atomic is_force_wakeup_background_worker; - std::atomic is_force_flush_pending; - std::atomic is_force_flush_notified; - std::atomic force_flush_timeout_us; - std::atomic is_shutdown; + std::atomic is_force_wakeup_background_worker{false}; + std::atomic is_force_flush_pending{false}; + std::atomic is_force_flush_notified{false}; + std::atomic force_flush_timeout_us{0}; + std::atomic is_shutdown{false}; }; /** 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 8b273c6bb2..de9cecdd84 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h @@ -53,7 +53,7 @@ class SimpleLogRecordProcessor : public LogRecordProcessor // The lock used to ensure the exporter is not called concurrently opentelemetry::common::SpinLockMutex lock_; // The atomic boolean to ensure the ShutDown() function is only called once - std::atomic is_shutdown_; + std::atomic is_shutdown_{false}; }; } // namespace logs } // 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 323727c873..b9221193fb 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 @@ -50,9 +50,9 @@ class PeriodicExportingMetricReader : public MetricReader std::thread worker_thread_; /* Synchronization primitives */ - std::atomic is_force_flush_pending_; - std::atomic is_force_wakeup_background_worker_; - std::atomic is_force_flush_notified_; + std::atomic is_force_flush_pending_{false}; + std::atomic is_force_wakeup_background_worker_{false}; + std::atomic is_force_flush_notified_{false}; std::condition_variable cv_, force_flush_cv_; std::mutex cv_m_, force_flush_m_; }; diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h index 34d499a2ef..b93631eafa 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h @@ -114,11 +114,11 @@ class BatchSpanProcessor : public SpanProcessor std::mutex cv_m, force_flush_cv_m, shutdown_m; /* Important boolean flags to handle the workflow of the processor */ - std::atomic is_force_wakeup_background_worker; - std::atomic is_force_flush_pending; - std::atomic is_force_flush_notified; - std::atomic force_flush_timeout_us; - std::atomic is_shutdown; + std::atomic is_force_wakeup_background_worker{false}; + std::atomic is_force_flush_pending{false}; + std::atomic is_force_flush_notified{false}; + std::atomic force_flush_timeout_us{0}; + std::atomic is_shutdown{false}; }; /** diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index 5487d70e80..c4cede1a53 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -30,12 +30,7 @@ BatchLogRecordProcessor::BatchLogRecordProcessor( buffer_(max_queue_size_), synchronization_data_(std::make_shared()), worker_thread_(&BatchLogRecordProcessor::DoBackgroundWork, this) -{ - synchronization_data_->is_force_wakeup_background_worker.store(false); - synchronization_data_->is_force_flush_pending.store(false); - synchronization_data_->is_force_flush_notified.store(false); - synchronization_data_->is_shutdown.store(false); -} +{} BatchLogRecordProcessor::BatchLogRecordProcessor(std::unique_ptr &&exporter, const BatchLogRecordProcessorOptions &options) @@ -46,13 +41,7 @@ BatchLogRecordProcessor::BatchLogRecordProcessor(std::unique_ptr()), worker_thread_(&BatchLogRecordProcessor::DoBackgroundWork, this) -{ - synchronization_data_->is_force_wakeup_background_worker.store(false); - synchronization_data_->is_force_flush_pending.store(false); - synchronization_data_->is_force_flush_notified.store(false); - synchronization_data_->force_flush_timeout_us.store(0); - synchronization_data_->is_shutdown.store(false); -} +{} std::unique_ptr BatchLogRecordProcessor::MakeRecordable() noexcept { diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index dd69eaa68f..719a072e64 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -31,13 +31,7 @@ BatchSpanProcessor::BatchSpanProcessor(std::unique_ptr &&exporter, buffer_(max_queue_size_), synchronization_data_(std::make_shared()), worker_thread_(&BatchSpanProcessor::DoBackgroundWork, this) -{ - synchronization_data_->is_force_wakeup_background_worker.store(false); - synchronization_data_->is_force_flush_pending.store(false); - synchronization_data_->is_force_flush_notified.store(false); - synchronization_data_->force_flush_timeout_us.store(0); - synchronization_data_->is_shutdown.store(false); -} +{} std::unique_ptr BatchSpanProcessor::MakeRecordable() noexcept { From 8f97cab6860bae6afb9e2ba073ca35c7dd606b52 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 29 Jul 2023 00:06:57 +0200 Subject: [PATCH 049/119] [SEMANTIC CONVENTIONS] Upgrade to 1.21.0 (#2248) --- .gitignore | 2 +- .../trace/semantic_conventions.h | 623 ++++++++++++------ buildscripts/semantic-convention/generate.sh | 21 +- examples/grpc/client.cc | 4 +- examples/http/client.cc | 8 +- examples/http/server.cc | 12 +- .../sdk/resource/semantic_conventions.h | 152 ++++- 7 files changed, 581 insertions(+), 241 deletions(-) diff --git a/.gitignore b/.gitignore index ce59c1a2e6..dc26aa2f82 100644 --- a/.gitignore +++ b/.gitignore @@ -57,7 +57,7 @@ tags .cache/clangd/* # Temporary dir used when generating semconv -./buildscripts/semantic-convention/opentelemetry-specification +buildscripts/semantic-convention/tmp-semconv/ # Generated cert keys in functional tests functional/cert/ca.csr diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index ecada99a41..42cf57d0ec 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -21,7 +21,159 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.20.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.21.0"; + +/** + * Client address - unix domain socket name, IPv4 or IPv6 address. + * + *

Notes: +

  • When observed from the server side, and when communicating through an intermediary, + {@code client.address} SHOULD represent client address behind any intermediaries (e.g. proxies) if + it's available.
+ */ +static constexpr const char *kClientAddress = "client.address"; + +/** + * Client port number + * + *

Notes: +

  • When observed from the server side, and when communicating through an intermediary, + {@code client.port} SHOULD represent client port behind any intermediaries (e.g. proxies) if it's + available.
+ */ +static constexpr const char *kClientPort = "client.port"; + +/** + * Immediate client peer address - unix domain socket name, IPv4 or IPv6 address. + */ +static constexpr const char *kClientSocketAddress = "client.socket.address"; + +/** + * Immediate client peer port number + */ +static constexpr const char *kClientSocketPort = "client.socket.port"; + +/** + * Deprecated, use {@code http.request.method} instead. + */ +static constexpr const char *kHttpMethod = "http.method"; + +/** + * Deprecated, use {@code http.response.status_code} instead. + */ +static constexpr const char *kHttpStatusCode = "http.status_code"; + +/** + * Deprecated, use {@code url.scheme} instead. + */ +static constexpr const char *kHttpScheme = "http.scheme"; + +/** + * Deprecated, use {@code url.full} instead. + */ +static constexpr const char *kHttpUrl = "http.url"; + +/** + * Deprecated, use {@code url.path} and {@code url.query} instead. + */ +static constexpr const char *kHttpTarget = "http.target"; + +/** + * Deprecated, use {@code http.request.body.size} instead. + */ +static constexpr const char *kHttpRequestContentLength = "http.request_content_length"; + +/** + * Deprecated, use {@code http.response.body.size} instead. + */ +static constexpr const char *kHttpResponseContentLength = "http.response_content_length"; + +/** + * Deprecated, use {@code server.socket.domain} on client spans. + */ +static constexpr const char *kNetSockPeerName = "net.sock.peer.name"; + +/** + * Deprecated, use {@code server.socket.address} on client spans and {@code client.socket.address} + * on server spans. + */ +static constexpr const char *kNetSockPeerAddr = "net.sock.peer.addr"; + +/** + * Deprecated, use {@code server.socket.port} on client spans and {@code client.socket.port} on + * server spans. + */ +static constexpr const char *kNetSockPeerPort = "net.sock.peer.port"; + +/** + * Deprecated, use {@code server.address} on client spans and {@code client.address} on server + * spans. + */ +static constexpr const char *kNetPeerName = "net.peer.name"; + +/** + * Deprecated, use {@code server.port} on client spans and {@code client.port} on server spans. + */ +static constexpr const char *kNetPeerPort = "net.peer.port"; + +/** + * Deprecated, use {@code server.address}. + */ +static constexpr const char *kNetHostName = "net.host.name"; + +/** + * Deprecated, use {@code server.port}. + */ +static constexpr const char *kNetHostPort = "net.host.port"; + +/** + * Deprecated, use {@code server.socket.address}. + */ +static constexpr const char *kNetSockHostAddr = "net.sock.host.addr"; + +/** + * Deprecated, use {@code server.socket.port}. + */ +static constexpr const char *kNetSockHostPort = "net.sock.host.port"; + +/** + * Deprecated, use {@code network.transport}. + */ +static constexpr const char *kNetTransport = "net.transport"; + +/** + * Deprecated, use {@code network.protocol.name}. + */ +static constexpr const char *kNetProtocolName = "net.protocol.name"; + +/** + * Deprecated, use {@code network.protocol.version}. + */ +static constexpr const char *kNetProtocolVersion = "net.protocol.version"; + +/** + * Deprecated, use {@code network.transport} and {@code network.type}. + */ +static constexpr const char *kNetSockFamily = "net.sock.family"; + +/** + * The domain name of the destination system. + * + *

Notes: +

  • This value may be a host name, a fully qualified domain name, or another host naming + format.
+ */ +static constexpr const char *kDestinationDomain = "destination.domain"; + +/** + * Peer address, for example IP address or UNIX socket name. + */ +static constexpr const char *kDestinationAddress = "destination.address"; + +/** + * Peer port number + */ +static constexpr const char *kDestinationPort = "destination.port"; /** * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of @@ -42,18 +194,32 @@ static constexpr const char *kExceptionStacktrace = "exception.stacktrace"; /** * HTTP request method. - */ -static constexpr const char *kHttpMethod = "http.method"; + * + *

Notes: +

  • HTTP request method value SHOULD be "known" to the instrumentation. +By default, this convention defines "known" methods as the ones listed in RFC9110 and the PATCH method +defined in RFC5789.
  • If the HTTP +request method is not known to instrumentation, it MUST set the {@code http.request.method} +attribute to {@code _OTHER} and, except if reporting a metric, MUST set the exact method received in +the request line as value of the {@code http.request.method_original} attribute.
  • If the HTTP +instrumentation could end up converting valid HTTP request methods to {@code _OTHER}, then it MUST +provide a way to override the list of known HTTP methods. If this override is done via environment +variable, then the environment variable MUST be named OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and +support a comma-separated list of case-sensitive known HTTP methods (this list MUST be a full +override of the default known method, it is not a list of known methods in addition to the +defaults).
  • HTTP method names are case-sensitive and {@code http.request.method} attribute +value MUST match a known HTTP method name exactly. Instrumentations for specific web frameworks that +consider HTTP methods to be case insensitive, SHOULD populate a canonical equivalent. Tracing +instrumentations that do so, MUST also set {@code http.request.method_original} to the original +value.
+ */ +static constexpr const char *kHttpRequestMethod = "http.request.method"; /** * HTTP response status code. */ -static constexpr const char *kHttpStatusCode = "http.status_code"; - -/** - * The URI scheme identifying the used protocol. - */ -static constexpr const char *kHttpScheme = "http.scheme"; +static constexpr const char *kHttpResponseStatusCode = "http.response.status_code"; /** * The matched route (path template in the format used by the respective server framework). See note @@ -62,8 +228,8 @@ below *

Notes:

  • MUST NOT be populated when this is not supported by the HTTP server framework as the route attribute should have low-cardinality and the URI path can NOT substitute it. SHOULD include -the application -root if there is one.
+the application root if there is +one. */ static constexpr const char *kHttpRoute = "http.route"; @@ -92,6 +258,97 @@ Sortable Identifier (ULID), but other identifiers (e.g. UUID) may be used as */ static constexpr const char *kLogRecordUid = "log.record.uid"; +/** + * The stream associated with the log. See below for a list of well-known values. + */ +static constexpr const char *kLogIostream = "log.iostream"; + +/** + * The basename of the file. + */ +static constexpr const char *kLogFileName = "log.file.name"; + +/** + * The full path to the file. + */ +static constexpr const char *kLogFilePath = "log.file.path"; + +/** + * The basename of the file, with symlinks resolved. + */ +static constexpr const char *kLogFileNameResolved = "log.file.name_resolved"; + +/** + * The full path to the file, with symlinks resolved. + */ +static constexpr const char *kLogFilePathResolved = "log.file.path_resolved"; + +/** + * The type of memory. + */ +static constexpr const char *kType = "type"; + +/** + * Name of the memory pool. + * + *

Notes: +

+ */ +static constexpr const char *kPool = "pool"; + +/** + * Logical server hostname, matches server FQDN if available, and IP or socket address if FQDN is + * not known. + */ +static constexpr const char *kServerAddress = "server.address"; + +/** + * Logical server port number + */ +static constexpr const char *kServerPort = "server.port"; + +/** + * The domain name of an immediate peer. + * + *

Notes: +

  • Typically observed from the client side, and represents a proxy or other intermediary + domain name.
+ */ +static constexpr const char *kServerSocketDomain = "server.socket.domain"; + +/** + * Physical server IP address or Unix socket address. If set from the client, should simply use the + * socket's peer address, and not attempt to find any actual server IP (i.e., if set from client, + * this may represent some proxy server instead of the logical server). + */ +static constexpr const char *kServerSocketAddress = "server.socket.address"; + +/** + * Physical server port. + */ +static constexpr const char *kServerSocketPort = "server.socket.port"; + +/** + * The domain name of the source system. + * + *

Notes: +

  • This value may be a host name, a fully qualified domain name, or another host naming + format.
+ */ +static constexpr const char *kSourceDomain = "source.domain"; + +/** + * Source address, for example IP address or Unix socket name. + */ +static constexpr const char *kSourceAddress = "source.address"; + +/** + * Source port number + */ +static constexpr const char *kSourcePort = "source.port"; + /** * The full invoked ARN as provided on the {@code Context} passed to the function ({@code Lambda-Runtime-Invoked-Function-Arn} header on the {@code /runtime/invocation/next} applicable). @@ -203,7 +460,7 @@ static constexpr const char *kDbOperation = "db.operation"; name connecting to. This name is used to determine the port of a named instance. * *

Notes: -

  • If setting a {@code db.mssql.instance_name}, {@code net.peer.port} is no longer required +
    • If setting a {@code db.mssql.instance_name}, {@code server.port} is no longer required (but still recommended if non-standard).
    */ static constexpr const char *kDbMssqlInstanceName = "db.mssql.instance_name"; @@ -443,117 +700,70 @@ unavailable. String representation of the value should be determined by the impl static constexpr const char *kFeatureFlagVariant = "feature_flag.variant"; /** - * Transport protocol used. See note below. + * OSI Transport Layer or Inter-process Communication + * method. The value SHOULD be normalized to lowercase. */ -static constexpr const char *kNetTransport = "net.transport"; +static constexpr const char *kNetworkTransport = "network.transport"; /** - * Application layer protocol used. The value SHOULD be normalized to lowercase. + * OSI Network Layer or non-OSI equivalent. The + * value SHOULD be normalized to lowercase. */ -static constexpr const char *kNetProtocolName = "net.protocol.name"; +static constexpr const char *kNetworkType = "network.type"; + +/** + * OSI Application Layer or non-OSI + * equivalent. The value SHOULD be normalized to lowercase. + */ +static constexpr const char *kNetworkProtocolName = "network.protocol.name"; /** * Version of the application layer protocol used. See note below. * *

    Notes: -

    • {@code net.protocol.version} refers to the version of the protocol used and might be +
      • {@code network.protocol.version} refers to the version of the protocol used and might be different from the protocol client's version. If the HTTP client used has a version of {@code 0.27.2}, but sends HTTP version {@code 1.1}, this attribute should be set to {@code 1.1}.
      */ -static constexpr const char *kNetProtocolVersion = "net.protocol.version"; - -/** - * Remote socket peer name. - */ -static constexpr const char *kNetSockPeerName = "net.sock.peer.name"; - -/** - * Remote socket peer address: IPv4 or IPv6 for internet protocols, path for local communication, etc. - */ -static constexpr const char *kNetSockPeerAddr = "net.sock.peer.addr"; - -/** - * Remote socket peer port. - */ -static constexpr const char *kNetSockPeerPort = "net.sock.peer.port"; - -/** - * Protocol address - * family which is used for communication. - */ -static constexpr const char *kNetSockFamily = "net.sock.family"; +static constexpr const char *kNetworkProtocolVersion = "network.protocol.version"; /** - * Logical remote hostname, see note below. - * - *

      Notes: -

      • {@code net.peer.name} SHOULD NOT be set if capturing it would require an extra DNS - lookup.
      + * The internet connection type. */ -static constexpr const char *kNetPeerName = "net.peer.name"; - -/** - * Logical remote port number - */ -static constexpr const char *kNetPeerPort = "net.peer.port"; - -/** - * Logical local hostname or similar, see note below. - */ -static constexpr const char *kNetHostName = "net.host.name"; - -/** - * Logical local port number, preferably the one that the peer used to connect - */ -static constexpr const char *kNetHostPort = "net.host.port"; - -/** - * Local socket address. Useful in case of a multi-IP host. - */ -static constexpr const char *kNetSockHostAddr = "net.sock.host.addr"; - -/** - * Local socket port number. - */ -static constexpr const char *kNetSockHostPort = "net.sock.host.port"; - -/** - * The internet connection type currently being used by the host. - */ -static constexpr const char *kNetHostConnectionType = "net.host.connection.type"; +static constexpr const char *kNetworkConnectionType = "network.connection.type"; /** * This describes more details regarding the connection.type. It may be the type of cell technology * connection, but it could be used for describing details about a wifi connection. */ -static constexpr const char *kNetHostConnectionSubtype = "net.host.connection.subtype"; +static constexpr const char *kNetworkConnectionSubtype = "network.connection.subtype"; /** * The name of the mobile carrier. */ -static constexpr const char *kNetHostCarrierName = "net.host.carrier.name"; +static constexpr const char *kNetworkCarrierName = "network.carrier.name"; /** * The mobile carrier country code. */ -static constexpr const char *kNetHostCarrierMcc = "net.host.carrier.mcc"; +static constexpr const char *kNetworkCarrierMcc = "network.carrier.mcc"; /** * The mobile carrier network code. */ -static constexpr const char *kNetHostCarrierMnc = "net.host.carrier.mnc"; +static constexpr const char *kNetworkCarrierMnc = "network.carrier.mnc"; /** * The ISO 3166-1 alpha-2 2-character country code associated with the mobile carrier network. */ -static constexpr const char *kNetHostCarrierIcc = "net.host.carrier.icc"; +static constexpr const char *kNetworkCarrierIcc = "network.carrier.icc"; /** - * The {@code service.name} of - * the remote service. SHOULD be equal to the actual {@code service.name} resource attribute of the - * remote service if any. + * The {@code service.name} of the remote service. + * SHOULD be equal to the actual {@code service.name} resource attribute of the remote service if + * any. */ static constexpr const char *kPeerService = "peer.service"; @@ -620,13 +830,18 @@ static constexpr const char *kCodeLineno = "code.lineno"; */ static constexpr const char *kCodeColumn = "code.column"; +/** + * Original HTTP method sent by the client in the request line. + */ +static constexpr const char *kHttpRequestMethodOriginal = "http.request.method_original"; + /** * The size of the request payload body in bytes. This is the number of bytes transferred excluding * headers and is often, but not always, present as the Content-Length * header. For requests using transport encoding, this should be the compressed size. */ -static constexpr const char *kHttpRequestContentLength = "http.request_content_length"; +static constexpr const char *kHttpRequestBodySize = "http.request.body.size"; /** * The size of the response payload body in bytes. This is the number of bytes transferred excluding @@ -634,18 +849,7 @@ static constexpr const char *kHttpRequestContentLength = "http.request_content_l * href="https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length">Content-Length * header. For requests using transport encoding, this should be the compressed size. */ -static constexpr const char *kHttpResponseContentLength = "http.response_content_length"; - -/** - * Full HTTP request URL in the form {@code scheme://host[:port]/path?query[#fragment]}. Usually the - fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. - * - *

      Notes: -

      • {@code http.url} MUST NOT contain credentials passed via URL in form of {@code - https://username:password@www.example.com/}. In such case the attribute's value should be {@code - https://www.example.com/}.
      - */ -static constexpr const char *kHttpUrl = "http.url"; +static constexpr const char *kHttpResponseBodySize = "http.response.body.size"; /** * The ordinal number of request resending attempt (for any reason, including redirects). @@ -657,28 +861,6 @@ static constexpr const char *kHttpUrl = "http.url"; */ static constexpr const char *kHttpResendCount = "http.resend_count"; -/** - * The full request target as passed in a HTTP request line or equivalent. - */ -static constexpr const char *kHttpTarget = "http.target"; - -/** - * The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For). - * - *

      Notes: -

      • This is not necessarily the same as {@code net.sock.peer.addr}, which would -identify the network-level peer, which may be a proxy.
      • This attribute should be set when a -source of information different from the one used for {@code net.sock.peer.addr}, is available even -if that other source just confirms the same value as {@code net.sock.peer.addr}. Rationale: For -{@code net.sock.peer.addr}, one typically does not know if it comes from a proxy, reverse proxy, or -the actual client. Setting -{@code http.client_ip} when it's the same as {@code net.sock.peer.addr} means that -one is at least somewhat confident that the address is not that of -the closest proxy.
      - */ -static constexpr const char *kHttpClientIp = "http.client_ip"; - /** * The AWS request ID as returned in the response headers {@code x-amz-request-id} or {@code * x-amz-requestid}. @@ -989,39 +1171,6 @@ static constexpr const char *kMessagingDestinationTemporary = "messaging.destina */ static constexpr const char *kMessagingDestinationAnonymous = "messaging.destination.anonymous"; -/** - * The message source name - * - *

      Notes: -

      • Source name SHOULD uniquely identify a specific queue, topic, or other entity within the -broker. If the broker does not have such notion, the source name SHOULD uniquely identify the -broker.
      - */ -static constexpr const char *kMessagingSourceName = "messaging.source.name"; - -/** - * Low cardinality representation of the messaging source name - * - *

      Notes: -

      • Source names could be constructed from templates. An example would be a source name - involving a user name or product id. Although the source name in this case is of high cardinality, - the underlying template is of low cardinality and can be effectively used for grouping and - aggregation.
      - */ -static constexpr const char *kMessagingSourceTemplate = "messaging.source.template"; - -/** - * A boolean that is true if the message source is temporary and might not exist anymore after - * messages are processed. - */ -static constexpr const char *kMessagingSourceTemporary = "messaging.source.temporary"; - -/** - * A boolean that is true if the message source is anonymous (could be unnamed or have - * auto-generated name). - */ -static constexpr const char *kMessagingSourceAnonymous = "messaging.source.anonymous"; - /** * A string identifying the messaging system. */ @@ -1049,12 +1198,9 @@ static constexpr const char *kMessagingOperation = "messaging.operation"; static constexpr const char *kMessagingBatchMessageCount = "messaging.batch.message_count"; /** - * The identifier for the consumer receiving a message. For Kafka, set it to {@code - * {messaging.kafka.consumer.group} - {messaging.kafka.client_id}}, if both are present, or only - * {@code messaging.kafka.consumer.group}. For brokers, such as RabbitMQ and Artemis, set it to the - * {@code client_id} of the client consuming the message. + * A unique identifier for the client that consumes or produces a message. */ -static constexpr const char *kMessagingConsumerId = "messaging.consumer.id"; +static constexpr const char *kMessagingClientId = "messaging.client_id"; /** * RabbitMQ message routing key. @@ -1080,22 +1226,12 @@ static constexpr const char *kMessagingKafkaMessageKey = "messaging.kafka.messag */ static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.consumer.group"; -/** - * Client Id for the Consumer or Producer that is handling the message. - */ -static constexpr const char *kMessagingKafkaClientId = "messaging.kafka.client_id"; - /** * Partition the message is sent to. */ static constexpr const char *kMessagingKafkaDestinationPartition = "messaging.kafka.destination.partition"; -/** - * Partition the message is received from. - */ -static constexpr const char *kMessagingKafkaSourcePartition = "messaging.kafka.source.partition"; - /** * The offset of a record in the corresponding Kafka partition. */ @@ -1117,11 +1253,6 @@ static constexpr const char *kMessagingRocketmqNamespace = "messaging.rocketmq.n */ static constexpr const char *kMessagingRocketmqClientGroup = "messaging.rocketmq.client_group"; -/** - * The unique identifier for each client. - */ -static constexpr const char *kMessagingRocketmqClientId = "messaging.rocketmq.client_id"; - /** * The timestamp in milliseconds that the delay message is expected to be delivered to consumer. */ @@ -1269,6 +1400,50 @@ recorded at a time where it was not clear whether the exception will escape.
    • URI scheme component + * identifying the used protocol. + */ +static constexpr const char *kUrlScheme = "url.scheme"; + +/** + * Absolute URL describing a network resource according to RFC3986 + * + *

      Notes: +

      • For network calls, URL usually has {@code scheme://host[:port][path][?query][#fragment]} +format, where the fragment is not transmitted over HTTP, but if it is known, it should be included +nevertheless. +{@code url.full} MUST NOT contain credentials passed via URL in form of {@code +https://username:password@www.example.com/}. In such case username and password should be redacted +and attribute's value should be {@code https://REDACTED:REDACTED@www.example.com/}. +{@code url.full} SHOULD capture the absolute URL when it is available (or can be reconstructed) and +SHOULD NOT be validated or modified except for sanitizing purposes.
      + */ +static constexpr const char *kUrlFull = "url.full"; + +/** + * The URI path component + * + *

      Notes: +

      • When missing, the value is assumed to be {@code /}
      + */ +static constexpr const char *kUrlPath = "url.path"; + +/** + * The URI query component + * + *

      Notes: +

      • Sensitive content provided in query string SHOULD be scrubbed when instrumentations can + identify it.
      + */ +static constexpr const char *kUrlQuery = "url.query"; + +/** + * The URI fragment component + */ +static constexpr const char *kUrlFragment = "url.fragment"; + /** * Value of the HTTP * User-Agent header sent by the client. @@ -1276,6 +1451,54 @@ static constexpr const char *kExceptionEscaped = "exception.escaped"; static constexpr const char *kUserAgentOriginal = "user_agent.original"; // Enum definitions +namespace NetTransportValues +{ +/** ip_tcp. */ +static constexpr const char *kIpTcp = "ip_tcp"; +/** ip_udp. */ +static constexpr const char *kIpUdp = "ip_udp"; +/** Named or anonymous pipe. */ +static constexpr const char *kPipe = "pipe"; +/** In-process communication. */ +static constexpr const char *kInproc = "inproc"; +/** Something else (non IP-based). */ +static constexpr const char *kOther = "other"; +} // namespace NetTransportValues + +namespace NetSockFamilyValues +{ +/** IPv4 address. */ +static constexpr const char *kInet = "inet"; +/** IPv6 address. */ +static constexpr const char *kInet6 = "inet6"; +/** Unix domain socket path. */ +static constexpr const char *kUnix = "unix"; +} // namespace NetSockFamilyValues + +namespace HttpRequestMethodValues +{ +/** CONNECT method. */ +static constexpr const char *kConnect = "CONNECT"; +/** DELETE method. */ +static constexpr const char *kDelete = "DELETE"; +/** GET method. */ +static constexpr const char *kGet = "GET"; +/** HEAD method. */ +static constexpr const char *kHead = "HEAD"; +/** OPTIONS method. */ +static constexpr const char *kOptions = "OPTIONS"; +/** PATCH method. */ +static constexpr const char *kPatch = "PATCH"; +/** POST method. */ +static constexpr const char *kPost = "POST"; +/** PUT method. */ +static constexpr const char *kPut = "PUT"; +/** TRACE method. */ +static constexpr const char *kTrace = "TRACE"; +/** Any HTTP method that the instrumentation has no prior knowledge of. */ +static constexpr const char *kOther = "_OTHER"; +} // namespace HttpRequestMethodValues + namespace EventDomainValues { /** Events from browser apps. */ @@ -1286,6 +1509,22 @@ static constexpr const char *kDevice = "device"; static constexpr const char *kK8s = "k8s"; } // namespace EventDomainValues +namespace LogIostreamValues +{ +/** Logs from stdout stream. */ +static constexpr const char *kStdout = "stdout"; +/** Events from stderr stream. */ +static constexpr const char *kStderr = "stderr"; +} // namespace LogIostreamValues + +namespace TypeValues +{ +/** Heap memory. */ +static constexpr const char *kHeap = "heap"; +/** Non-heap memory. */ +static constexpr const char *kNonHeap = "non_heap"; +} // namespace TypeValues + namespace OpentracingRefTypeValues { /** The parent Span depends on the child Span in some capacity. */ @@ -1517,31 +1756,27 @@ static constexpr const char *kGcp = "gcp"; static constexpr const char *kTencentCloud = "tencent_cloud"; } // namespace FaasInvokedProviderValues -namespace NetTransportValues +namespace NetworkTransportValues { -/** ip_tcp. */ -static constexpr const char *kIpTcp = "ip_tcp"; -/** ip_udp. */ -static constexpr const char *kIpUdp = "ip_udp"; +/** TCP. */ +static constexpr const char *kTcp = "tcp"; +/** UDP. */ +static constexpr const char *kUdp = "udp"; /** Named or anonymous pipe. See note below. */ static constexpr const char *kPipe = "pipe"; -/** In-process communication. */ -static constexpr const char *kInproc = "inproc"; -/** Something else (non IP-based). */ -static constexpr const char *kOther = "other"; -} // namespace NetTransportValues +/** Unix domain socket. */ +static constexpr const char *kUnix = "unix"; +} // namespace NetworkTransportValues -namespace NetSockFamilyValues +namespace NetworkTypeValues { -/** IPv4 address. */ -static constexpr const char *kInet = "inet"; -/** IPv6 address. */ -static constexpr const char *kInet6 = "inet6"; -/** Unix domain socket path. */ -static constexpr const char *kUnix = "unix"; -} // namespace NetSockFamilyValues +/** IPv4. */ +static constexpr const char *kIpv4 = "ipv4"; +/** IPv6. */ +static constexpr const char *kIpv6 = "ipv6"; +} // namespace NetworkTypeValues -namespace NetHostConnectionTypeValues +namespace NetworkConnectionTypeValues { /** wifi. */ static constexpr const char *kWifi = "wifi"; @@ -1553,9 +1788,9 @@ static constexpr const char *kCell = "cell"; static constexpr const char *kUnavailable = "unavailable"; /** unknown. */ static constexpr const char *kUnknown = "unknown"; -} // namespace NetHostConnectionTypeValues +} // namespace NetworkConnectionTypeValues -namespace NetHostConnectionSubtypeValues +namespace NetworkConnectionSubtypeValues { /** GPRS. */ static constexpr const char *kGprs = "gprs"; @@ -1599,7 +1834,7 @@ static constexpr const char *kNr = "nr"; static constexpr const char *kNrnsa = "nrnsa"; /** LTE CA. */ static constexpr const char *kLteCa = "lte_ca"; -} // namespace NetHostConnectionSubtypeValues +} // namespace NetworkConnectionSubtypeValues namespace GraphqlOperationTypeValues { diff --git a/buildscripts/semantic-convention/generate.sh b/buildscripts/semantic-convention/generate.sh index 2fd203013f..2a6634baa4 100755 --- a/buildscripts/semantic-convention/generate.sh +++ b/buildscripts/semantic-convention/generate.sh @@ -14,23 +14,26 @@ ROOT_DIR="${SCRIPT_DIR}/../../" # freeze the spec & generator tools versions to make SemanticAttributes generation reproducible -# repository: https://github.com/open-telemetry/opentelemetry-specification -SEMCONV_VERSION=1.20.0 +# Repository up to 1.20.0: +# https://github.com/open-telemetry/opentelemetry-specification +# Repository from 1.21.0: +# https://github.com/open-telemetry/semantic-conventions +SEMCONV_VERSION=1.21.0 # repository: https://github.com/open-telemetry/build-tools -GENERATOR_VERSION=0.18.0 +GENERATOR_VERSION=0.19.0 SPEC_VERSION=v$SEMCONV_VERSION SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION cd ${SCRIPT_DIR} -rm -rf opentelemetry-specification || true -mkdir opentelemetry-specification -cd opentelemetry-specification +rm -rf tmp-semconv || true +mkdir tmp-semconv +cd tmp-semconv git init -git remote add origin https://github.com/open-telemetry/opentelemetry-specification.git +git remote add origin https://github.com/open-telemetry/semantic-conventions.git git fetch origin "$SPEC_VERSION" git reset --hard FETCH_HEAD cd ${SCRIPT_DIR} @@ -42,7 +45,7 @@ cd ${SCRIPT_DIR} echo "Generating semantic conventions for traces ..." docker run --rm \ - -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \ + -v ${SCRIPT_DIR}/tmp-semconv/model:/source \ -v ${SCRIPT_DIR}/templates:/templates \ -v ${ROOT_DIR}/api/include/opentelemetry/trace/:/output \ otel/semconvgen:$GENERATOR_VERSION \ @@ -59,7 +62,7 @@ docker run --rm \ echo "Generating semantic conventions for resources ..." docker run --rm \ - -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \ + -v ${SCRIPT_DIR}/tmp-semconv/model:/source \ -v ${SCRIPT_DIR}/templates:/templates \ -v ${ROOT_DIR}/sdk/include/opentelemetry/sdk/resource/:/output \ otel/semconvgen:$GENERATOR_VERSION \ diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index 11fde192b3..92088c12f6 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -53,8 +53,8 @@ class GreeterClient {{SemanticConventions::kRpcSystem, "grpc"}, {SemanticConventions::kRpcService, "grpc-example.GreetService"}, {SemanticConventions::kRpcMethod, "Greet"}, - {SemanticConventions::kNetSockPeerAddr, ip}, - {SemanticConventions::kNetPeerPort, port}}, + {SemanticConventions::kServerSocketAddress, ip}, + {SemanticConventions::kServerPort, port}}, options); auto scope = get_tracer("grpc-client")->WithActiveSpan(span); diff --git a/examples/http/client.cc b/examples/http/client.cc index 46be83bf2e..433f51a64f 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -26,9 +26,9 @@ void sendRequest(const std::string &url) std::string span_name = url_parser.path_; auto span = get_tracer("http-client") ->StartSpan(span_name, - {{SemanticConventions::kHttpUrl, url_parser.url_}, - {SemanticConventions::kHttpScheme, url_parser.scheme_}, - {SemanticConventions::kHttpMethod, "GET"}}, + {{SemanticConventions::kUrlFull, url_parser.url_}, + {SemanticConventions::kUrlScheme, url_parser.scheme_}, + {SemanticConventions::kHttpRequestMethod, "GET"}}, options); auto scope = get_tracer("http-client")->WithActiveSpan(span); @@ -44,7 +44,7 @@ void sendRequest(const std::string &url) { // set span attributes auto status_code = result.GetResponse().GetStatusCode(); - span->SetAttribute(SemanticConventions::kHttpStatusCode, status_code); + span->SetAttribute(SemanticConventions::kHttpResponseStatusCode, status_code); result.GetResponse().ForEachHeader( [&span](nostd::string_view header_name, nostd::string_view header_value) { span->SetAttribute("http.header." + std::string(header_name.data()), header_value); diff --git a/examples/http/server.cc b/examples/http/server.cc index 13f250684e..c2d7a2c5a3 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -40,13 +40,13 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback // start span with parent context extracted from http header auto span = get_tracer("http-server") ->StartSpan(span_name, - {{SemanticConventions::kNetHostName, server_name}, - {SemanticConventions::kNetHostPort, server_port}, - {SemanticConventions::kHttpMethod, request.method}, - {SemanticConventions::kHttpScheme, "http"}, - {SemanticConventions::kHttpRequestContentLength, + {{SemanticConventions::kServerAddress, server_name}, + {SemanticConventions::kServerPort, server_port}, + {SemanticConventions::kHttpRequestMethod, request.method}, + {SemanticConventions::kUrlScheme, "http"}, + {SemanticConventions::kHttpRequestBodySize, static_cast(request.content.length())}, - {SemanticConventions::kHttpClientIp, request.client}}, + {SemanticConventions::kClientAddress, request.client}}, options); auto scope = get_tracer("http_server")->WithActiveSpan(span); diff --git a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h index f1315d9262..e96f052caf 100644 --- a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h +++ b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h @@ -23,7 +23,7 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.20.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.21.0"; /** * Array of brand name and version separated by a space @@ -221,6 +221,37 @@ static constexpr const char *kAwsLogStreamNames = "aws.log.stream.names"; */ static constexpr const char *kAwsLogStreamArns = "aws.log.stream.arns"; +/** + * The name of the Cloud Run execution being run for the + * Job, as set by the {@code + * CLOUD_RUN_EXECUTION} environment variable. + */ +static constexpr const char *kGcpCloudRunJobExecution = "gcp.cloud_run.job.execution"; + +/** + * The index for a task within an execution as provided by the {@code + * CLOUD_RUN_TASK_INDEX} environment variable. + */ +static constexpr const char *kGcpCloudRunJobTaskIndex = "gcp.cloud_run.job.task_index"; + +/** + * The instance name of a GCE instance. This is the value provided by {@code host.name}, the visible + * name of the instance in the Cloud Console UI, and the prefix for the default hostname of the + * instance as defined by the default + * internal DNS name. + */ +static constexpr const char *kGcpGceInstanceName = "gcp.gce.instance.name"; + +/** + * The hostname of a GCE instance. This is the full value of the default or custom hostname. + */ +static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostname"; + /** * Time and date the release was created */ @@ -263,6 +294,39 @@ static constexpr const char *kContainerImageName = "container.image.name"; */ static constexpr const char *kContainerImageTag = "container.image.tag"; +/** + * Runtime specific image identifier. Usually a hash algorithm followed by a UUID. + * + *

      Notes: +

      • Docker defines a sha256 of the image id; {@code container.image.id} corresponds to the +{@code Image} field from the Docker container inspect API +endpoint. K8s defines a link to the container registry repository with digest {@code "imageID": +"registry.azurecr.io +/namespace/service/dockerfile@sha256:bdeabd40c3a8a492eaf9e8e44d0ebbb84bac7ee25ac0cf8a7159d25f62555625"}. +OCI defines a digest of manifest.
      + */ +static constexpr const char *kContainerImageId = "container.image.id"; + +/** + * The command used to run the container (i.e. the command name). + * + *

      Notes: +

      • If using embedded credentials or sensitive data, it is recommended to remove them to + prevent potential leakage.
      + */ +static constexpr const char *kContainerCommand = "container.command"; + +/** + * The full command run by the container as a single string representing the full command. [2] + */ +static constexpr const char *kContainerCommandLine = "container.command_line"; + +/** + * All the command arguments (including the command/executable itself) run by the container. [2] + */ +static constexpr const char *kContainerCommandArgs = "container.command_args"; + /** * Name of the deployment * environment (aka deployment tier). @@ -322,15 +386,14 @@ static constexpr const char *kDeviceManufacturer = "device.manufacturer";
      • This is the name of the function as configured/deployed on the FaaS platform and is usually different from the name of the callback function (which may be stored in the -{@code -code.namespace}/{@code code.function} span attributes).
      • For some cloud providers, the -above definition is ambiguous. The following definition of function name MUST be used for this -attribute (and consequently the span name) for the listed cloud -providers/products:
      • Azure: The full name {@code /}, i.e., -function app name followed by a forward slash followed by the function name (this form can also be -seen in the resource JSON for the function). This means that a span attribute MUST be used, as an -Azure function app can host multiple functions that would usually share a TracerProvider (see also -the {@code cloud.resource_id} attribute).
      • +{@code code.namespace}/{@code +code.function} span attributes).
      • For some cloud providers, the above definition is +ambiguous. The following definition of function name MUST be used for this attribute (and +consequently the span name) for the listed cloud providers/products:
      • Azure: +The full name {@code /}, i.e., function app name followed by a forward slash followed +by the function name (this form can also be seen in the resource JSON for the function). This means +that a span attribute MUST be used, as an Azure function app can host multiple functions that would +usually share a TracerProvider (see also the {@code cloud.resource_id} attribute).
      */ static constexpr const char *kFaasName = "faas.name"; @@ -341,10 +404,11 @@ static constexpr const char *kFaasName = "faas.name"; *

      Notes:

      • Depending on the cloud provider and platform, use:
      • AWS Lambda: The function -version (an integer represented as a decimal string).
      • Google Cloud -Run: The revision (i.e., -the function name plus the revision suffix).
      • Google Cloud Functions: The -value of the (an integer represented as a decimal string).
      • Google Cloud Run +(Services): The revision +(i.e., the function name plus the revision suffix).
      • +
      • Google Cloud Functions: The value of the +{@code K_REVISION} environment variable.
      • Azure Functions: Not applicable. Do not set this attribute.
      • @@ -402,13 +466,13 @@ static constexpr const char *kHostArch = "host.arch"; static constexpr const char *kHostImageName = "host.image.name"; /** - * VM image ID. For Cloud, this value is from the provider. + * VM image ID or host OS image ID. For Cloud, this value is from the provider. */ static constexpr const char *kHostImageId = "host.image.id"; /** - * The version string of the VM image as defined in Version - * Attributes. + * The version string of the VM image or host OS as defined in Version Attributes. */ static constexpr const char *kHostImageVersion = "host.image.version"; @@ -417,6 +481,30 @@ static constexpr const char *kHostImageVersion = "host.image.version"; */ static constexpr const char *kK8sClusterName = "k8s.cluster.name"; +/** + * A pseudo-ID for the cluster, set to the UID of the {@code kube-system} namespace. + * + *

        Notes: +

        • K8s does not have support for obtaining a cluster ID. If this is ever +added, we will recommend collecting the {@code k8s.cluster.uid} through the +official APIs. In the meantime, we are able to use the {@code uid} of the +{@code kube-system} namespace as a proxy for cluster ID. Read on for the +rationale.
        • Every object created in a K8s cluster is assigned a distinct UID. The +{@code kube-system} namespace is used by Kubernetes itself and will exist +for the lifetime of the cluster. Using the {@code uid} of the {@code kube-system} +namespace is a reasonable proxy for the K8s ClusterID as it will only +change if the cluster is rebuilt. Furthermore, Kubernetes UIDs are +UUIDs as standardized by +ISO/IEC 9834-8 and ITU-T X.667. +Which states:
        • +
        • If generated according to one of the mechanisms defined in Rec.
        • +
        • ITU-T X.667 | ISO/IEC 9834-8, a UUID is either guaranteed to be + different from all other UUIDs generated before 3603 A.D., or is + extremely likely to be different (depending on the mechanism chosen).
        • Therefore, UIDs +between clusters should be extremely unlikely to conflict.
        + */ +static constexpr const char *kK8sClusterUid = "k8s.cluster.uid"; + /** * The name of the Node. */ @@ -532,7 +620,7 @@ static constexpr const char *kOsName = "os.name"; /** * The version string of the operating system as defined in Version Attributes. + * href="/docs/resource/README.md#version-attributes">Version Attributes. */ static constexpr const char *kOsVersion = "os.version"; @@ -615,6 +703,12 @@ static constexpr const char *kProcessRuntimeDescription = "process.runtime.descr */ static constexpr const char *kServiceName = "service.name"; +/** + * The version string of the service API or implementation. The format is not defined by these + * conventions. + */ +static constexpr const char *kServiceVersion = "service.version"; + /** * A namespace for {@code service.name}. * @@ -644,13 +738,17 @@ static constexpr const char *kServiceNamespace = "service.namespace"; */ static constexpr const char *kServiceInstanceId = "service.instance.id"; -/** - * The version string of the service API or implementation. - */ -static constexpr const char *kServiceVersion = "service.version"; - /** * The name of the telemetry SDK as defined above. + * + *

        Notes: +

        • The OpenTelemetry SDK MUST set the {@code telemetry.sdk.name} attribute to {@code +opentelemetry}. If another SDK, like a fork or a vendor-provided implementation, is used, this SDK +MUST set the +{@code telemetry.sdk.name} attribute to the fully-qualified class or module name of this SDK's main +entry point or another suitable identifier depending on the language. The identifier {@code +opentelemetry} is reserved and MUST NOT be used in this case. All custom identifiers SHOULD be +stable across different versions of an implementation.
        */ static constexpr const char *kTelemetrySdkName = "telemetry.sdk.name"; @@ -757,6 +855,8 @@ static constexpr const char *kAzureFunctions = "azure_functions"; static constexpr const char *kAzureAppService = "azure_app_service"; /** Azure Red Hat OpenShift. */ static constexpr const char *kAzureOpenshift = "azure_openshift"; +/** Google Bare Metal Solution (BMS). */ +static constexpr const char *kGcpBareMetalSolution = "gcp_bare_metal_solution"; /** Google Cloud Compute Engine (GCE). */ static constexpr const char *kGcpComputeEngine = "gcp_compute_engine"; /** Google Cloud Run. */ @@ -853,10 +953,12 @@ static constexpr const char *kPhp = "php"; static constexpr const char *kPython = "python"; /** ruby. */ static constexpr const char *kRuby = "ruby"; -/** webjs. */ -static constexpr const char *kWebjs = "webjs"; +/** rust. */ +static constexpr const char *kRust = "rust"; /** swift. */ static constexpr const char *kSwift = "swift"; +/** webjs. */ +static constexpr const char *kWebjs = "webjs"; } // namespace TelemetrySdkLanguageValues } // namespace SemanticConventions From 8c82d24c2073dbe01f38988a226e2e24a6a49fa4 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 1 Aug 2023 00:18:57 -0700 Subject: [PATCH 050/119] Mark logs signal as stable API/SDK (#2229) --- CHANGELOG.md | 3 + CMakeLists.txt | 5 +- README.md | 7 +- api/CMakeLists.txt | 12 +- api/include/opentelemetry/logs/event_id.h | 11 +- api/include/opentelemetry/logs/event_logger.h | 17 +- .../logs/event_logger_provider.h | 8 +- api/include/opentelemetry/logs/log_record.h | 8 +- api/include/opentelemetry/logs/logger.h | 13 +- .../opentelemetry/logs/logger_provider.h | 18 +-- .../opentelemetry/logs/logger_type_traits.h | 37 ++--- api/include/opentelemetry/logs/noop.h | 18 +-- api/include/opentelemetry/logs/provider.h | 14 +- api/include/opentelemetry/logs/severity.h | 6 +- api/test/CMakeLists.txt | 4 +- api/test/logs/logger_benchmark.cc | 26 ++- api/test/logs/logger_test.cc | 17 +- api/test/logs/provider_test.cc | 12 +- ci/do_ci.ps1 | 2 +- ci/do_ci.sh | 9 +- ci/setup_cmake.sh | 2 +- ci/setup_windows_cmake.ps1 | 2 +- examples/CMakeLists.txt | 4 +- examples/common/CMakeLists.txt | 4 +- .../common/logs_foo_library/foo_library.cc | 13 +- examples/logs_simple/CMakeLists.txt | 20 ++- examples/logs_simple/main.cc | 39 ++--- examples/otlp/CMakeLists.txt | 48 +++--- examples/otlp/grpc_log_main.cc | 47 +++--- examples/otlp/http_log_main.cc | 49 +++--- exporters/CMakeLists.txt | 2 +- .../elasticsearch/es_log_record_exporter.h | 36 ++--- .../elasticsearch/es_log_recordable.h | 20 ++- .../src/es_log_record_exporter.cc | 39 +++-- .../elasticsearch/src/es_log_recordable.cc | 17 +- .../test/es_log_record_exporter_test.cc | 21 ++- exporters/etw/CMakeLists.txt | 4 +- .../opentelemetry/exporters/etw/etw_logger.h | 64 ++++---- .../exporters/etw/etw_logger_exporter.h | 35 ++-- exporters/etw/test/etw_logger_test.cc | 16 +- exporters/ostream/CMakeLists.txt | 64 ++++---- .../exporters/ostream/log_record_exporter.h | 20 ++- .../ostream/log_record_exporter_factory.h | 8 +- exporters/ostream/src/log_record_exporter.cc | 22 ++- .../src/log_record_exporter_factory.cc | 6 +- exporters/ostream/test/ostream_log_test.cc | 40 +++-- exporters/otlp/CMakeLists.txt | 153 ++++++++---------- .../exporters/otlp/otlp_grpc_client.h | 9 +- .../otlp/otlp_grpc_log_record_exporter.h | 17 +- .../otlp_grpc_log_record_exporter_factory.h | 8 +- .../exporters/otlp/otlp_http_exporter.h | 2 +- .../otlp/otlp_http_log_record_exporter.h | 18 +-- .../otlp_http_log_record_exporter_factory.h | 8 +- .../otlp_http_log_record_exporter_options.h | 28 ++-- .../exporters/otlp/otlp_log_recordable.h | 21 ++- .../exporters/otlp/otlp_recordable_utils.h | 6 +- exporters/otlp/src/otlp_grpc_client.cc | 4 - .../otlp/src/otlp_grpc_log_record_exporter.cc | 26 ++- .../otlp_grpc_log_record_exporter_factory.cc | 10 +- .../otlp/src/otlp_http_log_record_exporter.cc | 40 +++-- .../otlp_http_log_record_exporter_factory.cc | 10 +- exporters/otlp/src/otlp_log_recordable.cc | 14 +- exporters/otlp/src/otlp_recordable_utils.cc | 2 - ...p_grpc_log_record_exporter_factory_test.cc | 16 +- .../otlp_grpc_log_record_exporter_test.cc | 48 +++--- ...p_http_log_record_exporter_factory_test.cc | 22 ++- .../otlp_http_log_record_exporter_test.cc | 82 +++++----- .../otlp/test/otlp_log_recordable_test.cc | 44 ++--- ext/src/dll/CMakeLists.txt | 24 +-- ext/src/dll/dllmain.cc | 5 +- ext/src/dll/opentelemetry_cpp.src | 21 ++- sdk/CMakeLists.txt | 8 +- .../sdk/common/empty_attributes.h | 5 +- .../sdk/logs/batch_log_record_processor.h | 22 ++- .../logs/batch_log_record_processor_factory.h | 7 +- .../logs/batch_log_record_processor_options.h | 9 +- .../opentelemetry/sdk/logs/event_logger.h | 14 +- .../sdk/logs/event_logger_provider.h | 12 +- .../sdk/logs/event_logger_provider_factory.h | 7 +- sdk/include/opentelemetry/sdk/logs/exporter.h | 12 +- sdk/include/opentelemetry/sdk/logs/logger.h | 20 ++- .../opentelemetry/sdk/logs/logger_context.h | 15 +- .../sdk/logs/logger_context_factory.h | 9 +- .../opentelemetry/sdk/logs/logger_provider.h | 20 ++- .../sdk/logs/logger_provider_factory.h | 9 +- .../sdk/logs/multi_log_record_processor.h | 13 +- .../logs/multi_log_record_processor_factory.h | 9 +- .../opentelemetry/sdk/logs/multi_recordable.h | 18 +-- .../opentelemetry/sdk/logs/processor.h | 8 +- .../sdk/logs/read_write_log_record.h | 37 ++--- .../sdk/logs/readable_log_record.h | 18 +-- .../opentelemetry/sdk/logs/recordable.h | 6 +- .../sdk/logs/simple_log_record_processor.h | 14 +- .../simple_log_record_processor_factory.h | 7 +- sdk/src/CMakeLists.txt | 4 +- sdk/src/logs/batch_log_record_processor.cc | 13 +- .../batch_log_record_processor_factory.cc | 7 +- sdk/src/logs/event_logger.cc | 8 +- sdk/src/logs/event_logger_provider.cc | 19 +-- sdk/src/logs/event_logger_provider_factory.cc | 9 +- sdk/src/logs/exporter.cc | 5 +- sdk/src/logs/logger.cc | 15 +- sdk/src/logs/logger_context.cc | 11 +- sdk/src/logs/logger_context_factory.cc | 15 +- sdk/src/logs/logger_provider.cc | 15 +- sdk/src/logs/logger_provider_factory.cc | 11 +- sdk/src/logs/multi_log_record_processor.cc | 9 +- .../multi_log_record_processor_factory.cc | 13 +- sdk/src/logs/multi_recordable.cc | 11 +- sdk/src/logs/read_write_log_record.cc | 9 +- sdk/src/logs/readable_log_record.cc | 15 +- sdk/src/logs/simple_log_record_processor.cc | 13 +- .../simple_log_record_processor_factory.cc | 7 +- sdk/test/CMakeLists.txt | 4 +- .../logs/batch_log_record_processor_test.cc | 17 +- sdk/test/logs/log_record_test.cc | 28 ++-- sdk/test/logs/logger_provider_sdk_test.cc | 28 ++-- sdk/test/logs/logger_sdk_test.cc | 40 +++-- .../logs/simple_log_record_processor_test.cc | 18 +-- 119 files changed, 920 insertions(+), 1250 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12bdc28c18..9e95bd0fb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [SDK] Mark logs signal as stable API/SDK + [#2229](https://github.com/open-telemetry/opentelemetry-cpp/pull/2229) + Breaking changes: * [SDK] Add unit to Instrument selection criteria diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c8c126888..3cd71503cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,7 +236,10 @@ option( option(WITH_FUNC_TESTS "Whether to build functional tests" ON) -option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF) +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) # EXPERIMENTAL diff --git a/README.md b/README.md index 6dd56949fd..25b9cd8170 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,7 @@ The C++ [OpenTelemetry](https://opentelemetry.io/) client. | ------- | ----------------------- | ------------------------------------------------------------------------ | | Traces | Public Release | N/A | | Metrics | Public Release | N/A | -| Logs | Experimental [1] | [Release Milestone](https://github.com/open-telemetry/opentelemetry-cpp/milestone/18)| - -* [1]: The current Log Signal Implementation is Experimental, and will change as - the current OpenTelemetry Log specification matures. The current - implementation can be included in build by setting `ENABLE_LOGS_PREVIEW` - preprocessor macro. +| Logs | Public Release | N/A | ## Supported C++ Versions diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index d1a6a77fa3..8a2788ed17 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -17,11 +17,6 @@ if(OPENTELEMETRY_INSTALL) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - set(LOGS_EXCLUDE_PATTERN "") - if(NOT WITH_LOGS_PREVIEW) - set(LOGS_EXCLUDE_PATTERN "logs") - endif() - install( DIRECTORY include/opentelemetry DESTINATION include @@ -33,8 +28,7 @@ if(OPENTELEMETRY_INSTALL) DIRECTORY include/opentelemetry DESTINATION include FILES_MATCHING - PATTERN "*.h" - PATTERN "${LOGS_EXCLUDE_PATTERN}" EXCLUDE) + PATTERN "*.h") endif() if(BUILD_TESTING) @@ -79,10 +73,6 @@ if(WITH_GSL) endif() endif() -if(WITH_LOGS_PREVIEW) - target_compile_definitions(opentelemetry_api INTERFACE ENABLE_LOGS_PREVIEW) -endif() - if(WITH_NO_GETENV) target_compile_definitions(opentelemetry_api INTERFACE NO_GETENV) endif() diff --git a/api/include/opentelemetry/logs/event_id.h b/api/include/opentelemetry/logs/event_id.h index 60d020827c..dc07484d09 100644 --- a/api/include/opentelemetry/logs/event_id.h +++ b/api/include/opentelemetry/logs/event_id.h @@ -3,13 +3,11 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include -# include - -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/version.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -37,4 +35,3 @@ class EventId } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/logs/event_logger.h b/api/include/opentelemetry/logs/event_logger.h index c87997816b..2ede6f3fa1 100644 --- a/api/include/opentelemetry/logs/event_logger.h +++ b/api/include/opentelemetry/logs/event_logger.h @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/logs/log_record.h" -# include "opentelemetry/logs/logger.h" -# include "opentelemetry/logs/logger_type_traits.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/logger_type_traits.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -84,5 +83,3 @@ class EventLogger }; } // namespace logs OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/api/include/opentelemetry/logs/event_logger_provider.h b/api/include/opentelemetry/logs/event_logger_provider.h index 06170dccab..8fba83c759 100644 --- a/api/include/opentelemetry/logs/event_logger_provider.h +++ b/api/include/opentelemetry/logs/event_logger_provider.h @@ -2,11 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/version.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -34,4 +33,3 @@ class EventLoggerProvider }; } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/logs/log_record.h b/api/include/opentelemetry/logs/log_record.h index 1014a880bc..81dec568e5 100644 --- a/api/include/opentelemetry/logs/log_record.h +++ b/api/include/opentelemetry/logs/log_record.h @@ -2,11 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -91,4 +90,3 @@ class LogRecord }; } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/logs/logger.h b/api/include/opentelemetry/logs/logger.h index d991a13d88..a2bd2c0bcf 100644 --- a/api/include/opentelemetry/logs/logger.h +++ b/api/include/opentelemetry/logs/logger.h @@ -2,13 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/logs/logger_type_traits.h" -# include "opentelemetry/logs/severity.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/logger_type_traits.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace common @@ -475,5 +474,3 @@ class Logger }; } // namespace logs OPENTELEMETRY_END_NAMESPACE - -#endif // end of ENABLE_LOGS_PREVIEW diff --git a/api/include/opentelemetry/logs/logger_provider.h b/api/include/opentelemetry/logs/logger_provider.h index e2a72bcc54..ab1493c5cd 100644 --- a/api/include/opentelemetry/logs/logger_provider.h +++ b/api/include/opentelemetry/logs/logger_provider.h @@ -3,15 +3,13 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/common/key_value_iterable.h" -# include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/span.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/type_traits.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -71,5 +69,3 @@ class OPENTELEMETRY_EXPORT LoggerProvider }; } // namespace logs OPENTELEMETRY_END_NAMESPACE - -#endif // ENABLE_LOGS_PREVIEW diff --git a/api/include/opentelemetry/logs/logger_type_traits.h b/api/include/opentelemetry/logs/logger_type_traits.h index b1e5e560d3..aea2173689 100644 --- a/api/include/opentelemetry/logs/logger_type_traits.h +++ b/api/include/opentelemetry/logs/logger_type_traits.h @@ -2,24 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# 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/severity.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/type_traits.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/version.h" + +#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/severity.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/type_traits.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/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -198,5 +197,3 @@ struct LogRecordHasType } // namespace logs OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/api/include/opentelemetry/logs/noop.h b/api/include/opentelemetry/logs/noop.h index 5303b2e77f..b4590c987f 100644 --- a/api/include/opentelemetry/logs/noop.h +++ b/api/include/opentelemetry/logs/noop.h @@ -2,21 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW // Please refer to provider.h for documentation on how to obtain a Logger object. // // This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be // used directly. Please refer to logger.h for documentation on these interfaces. -# 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/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/version.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/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace common @@ -100,4 +99,3 @@ class NoopEventLoggerProvider final : public EventLoggerProvider } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/logs/provider.h b/api/include/opentelemetry/logs/provider.h index a33b26dbac..bced5c97ea 100644 --- a/api/include/opentelemetry/logs/provider.h +++ b/api/include/opentelemetry/logs/provider.h @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include +#include -# include "opentelemetry/common/macros.h" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/logs/noop.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/logs/noop.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -90,4 +89,3 @@ class OPENTELEMETRY_EXPORT Provider } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/logs/severity.h b/api/include/opentelemetry/logs/severity.h index 6a435f38fc..5247d30be8 100644 --- a/api/include/opentelemetry/logs/severity.h +++ b/api/include/opentelemetry/logs/severity.h @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/version.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -64,4 +63,3 @@ const nostd::string_view SeverityNumToText[25] = { } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 2d051cc726..20c9f4e949 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -7,9 +7,7 @@ add_subdirectory(plugin) add_subdirectory(nostd) add_subdirectory(trace) add_subdirectory(metrics) -if(WITH_LOGS_PREVIEW) - add_subdirectory(logs) -endif() +add_subdirectory(logs) add_subdirectory(common) add_subdirectory(baggage) add_subdirectory(singleton) diff --git a/api/test/logs/logger_benchmark.cc b/api/test/logs/logger_benchmark.cc index fa5ad2b0c6..098b9c7df8 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -1,21 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" -# 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 - -# include +#include using opentelemetry::logs::EventId; using opentelemetry::logs::Logger; @@ -256,5 +254,3 @@ int main(int argc, char **argv) benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); } - -#endif diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 789ffd1259..a9567a6d3f 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -1,16 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include +#include -# include -# include -# include - -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/logs/logger.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" using opentelemetry::logs::EventId; using opentelemetry::logs::Logger; @@ -221,4 +219,3 @@ TEST(Logger, PushLoggerImplementation) auto logger = lp->GetLogger("TestLogger", "opentelelemtry_library", "", schema_url); ASSERT_EQ("test logger", logger->GetName()); } -#endif diff --git a/api/test/logs/provider_test.cc b/api/test/logs/provider_test.cc index 27af9b0c43..92c589ef7e 100644 --- a/api/test/logs/provider_test.cc +++ b/api/test/logs/provider_test.cc @@ -1,13 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" using opentelemetry::logs::EventLogger; using opentelemetry::logs::EventLoggerProvider; @@ -108,5 +106,3 @@ TEST(Provider, CreateEventLogger) EXPECT_EQ(nullptr, logger); } - -#endif diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index a91ebc0255..e55cf8e536 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -10,7 +10,7 @@ $nproc = (Get-ComputerInfo).CsNumberOfLogicalProcessors $SRC_DIR = (Get-Item -Path ".\").FullName -$BAZEL_OPTIONS = "--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_ASYNC_EXPORT" +$BAZEL_OPTIONS = "--copt=-DENABLE_ASYNC_EXPORT" $BAZEL_TEST_OPTIONS = "$BAZEL_OPTIONS --test_output=errors" if (!(test-path build)) { diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 013a9f0ec8..fce868e37f 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -69,7 +69,7 @@ fi echo "make command: ${MAKE_COMMAND}" echo "IWYU option: ${IWYU}" -BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" +BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT" BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" @@ -94,7 +94,6 @@ if [[ "$1" == "cmake.test" ]]; then -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ "${SRC_DIR}" make -j $(nproc) @@ -115,7 +114,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_ZIPKIN=ON \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ -DOTELCPP_MAINTAINER_MODE=ON \ @@ -140,7 +138,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_ZIPKIN=ON \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ @@ -165,7 +162,6 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_ZIPKIN=ON \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_ELASTICSEARCH=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ @@ -183,7 +179,6 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ "${SRC_DIR}" @@ -196,7 +191,6 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_STANDARD=14 \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_ABSEIL=ON \ @@ -233,7 +227,6 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_STANDARD=20 \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_LOGS_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_STL=ON \ diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh index 7194286b86..0eda07c0ec 100755 --- a/ci/setup_cmake.sh +++ b/ci/setup_cmake.sh @@ -10,7 +10,7 @@ apt-get update if [ "x$CMAKE_VERSION" = "x" ]; then # By default, CMake version set the following version. - export CMAKE_VERSION=3.15.2 + export CMAKE_VERSION=3.16.3 fi if [ -z "${GOOGLETEST_VERSION}" ]; then diff --git a/ci/setup_windows_cmake.ps1 b/ci/setup_windows_cmake.ps1 index 172b126aaa..619a9b7e82 100755 --- a/ci/setup_windows_cmake.ps1 +++ b/ci/setup_windows_cmake.ps1 @@ -4,7 +4,7 @@ $ErrorActionPreference = "Stop" trap { $host.SetShouldExit(1) } -$CMAKE_VERSION="3.15.2" +$CMAKE_VERSION="3.16.3" $CWD=(Get-Item -Path ".\").FullName (new-object System.Net.WebClient). ` DownloadFile("https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-win64-x64.zip", ` diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fb64ed21c0..6a237af982 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,9 +18,7 @@ endif() if(WITH_PROMETHEUS) add_subdirectory(prometheus) endif() -if(WITH_LOGS_PREVIEW) - add_subdirectory(logs_simple) -endif() +add_subdirectory(logs_simple) add_subdirectory(plugin) add_subdirectory(simple) add_subdirectory(batch) diff --git a/examples/common/CMakeLists.txt b/examples/common/CMakeLists.txt index f1e02f8e2d..834980ae4f 100644 --- a/examples/common/CMakeLists.txt +++ b/examples/common/CMakeLists.txt @@ -2,7 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory(foo_library) -if(WITH_LOGS_PREVIEW) - add_subdirectory(logs_foo_library) -endif() +add_subdirectory(logs_foo_library) add_subdirectory(metrics_foo_library) diff --git a/examples/common/logs_foo_library/foo_library.cc b/examples/common/logs_foo_library/foo_library.cc index e952220108..5fd274193c 100644 --- a/examples/common/logs_foo_library/foo_library.cc +++ b/examples/common/logs_foo_library/foo_library.cc @@ -1,11 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/version/version.h" -# include "opentelemetry/trace/provider.h" + +#include +#include +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/trace/provider.h" namespace logs = opentelemetry::logs; namespace trace = opentelemetry::trace; @@ -36,4 +36,3 @@ void foo_library() ctx.span_id(), ctx.trace_flags(), opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); } -#endif diff --git a/examples/logs_simple/CMakeLists.txt b/examples/logs_simple/CMakeLists.txt index 7b4548ec52..3e62745ccc 100644 --- a/examples/logs_simple/CMakeLists.txt +++ b/examples/logs_simple/CMakeLists.txt @@ -7,16 +7,14 @@ endif() include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) -if(WITH_LOGS_PREVIEW) - add_executable(example_logs_simple main.cc) - target_link_libraries(example_logs_simple ${CMAKE_THREAD_LIBS_INIT} - common_logs_foo_library) +add_executable(example_logs_simple main.cc) +target_link_libraries(example_logs_simple ${CMAKE_THREAD_LIBS_INIT} + common_logs_foo_library) - if(DEFINED OPENTELEMETRY_BUILD_DLL) - target_link_libraries(example_logs_simple opentelemetry_cpp) - else() - target_link_libraries( - example_logs_simple opentelemetry_trace opentelemetry_logs - opentelemetry_exporter_ostream_span opentelemetry_exporter_ostream_logs) - endif() +if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_logs_simple opentelemetry_cpp) +else() + target_link_libraries( + example_logs_simple opentelemetry_trace opentelemetry_logs + opentelemetry_exporter_ostream_span opentelemetry_exporter_ostream_logs) endif() diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index c12733d4c3..54a872ad0e 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -1,25 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/ostream/span_exporter_factory.h" -# include "opentelemetry/sdk/trace/exporter.h" -# include "opentelemetry/sdk/trace/processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/trace/provider.h" +#include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/provider.h" -# include "opentelemetry/exporters/ostream/log_record_exporter.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/logger_provider_factory.h" -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" -# ifdef BAZEL_BUILD -# include "examples/common/logs_foo_library/foo_library.h" -# else -# include "logs_foo_library/foo_library.h" -# endif +#ifdef BAZEL_BUILD +# include "examples/common/logs_foo_library/foo_library.h" +#else +# include "logs_foo_library/foo_library.h" +#endif namespace logs_api = opentelemetry::logs; namespace logs_sdk = opentelemetry::sdk::logs; @@ -78,9 +77,3 @@ int main() CleanupTracer(); CleanupLogger(); } -#else -int main() -{ - return 0; -} -#endif // ENABLE_LOGS_PREVIEW diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index dd8cc054c2..398300ab36 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -35,18 +35,16 @@ if(WITH_OTLP_GRPC) # LOG - if(WITH_LOGS_PREVIEW) - add_executable(example_otlp_grpc_log grpc_log_main.cc) - - target_link_libraries(example_otlp_grpc_log ${CMAKE_THREAD_LIBS_INIT} - common_logs_foo_library) - if(DEFINED OPENTELEMETRY_BUILD_DLL) - target_link_libraries(example_otlp_grpc_log opentelemetry_cpp) - else() - target_link_libraries( - example_otlp_grpc_log opentelemetry_trace opentelemetry_logs - opentelemetry_exporter_otlp_grpc opentelemetry_exporter_otlp_grpc_log) - endif() + add_executable(example_otlp_grpc_log grpc_log_main.cc) + + target_link_libraries(example_otlp_grpc_log ${CMAKE_THREAD_LIBS_INIT} + common_logs_foo_library) + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_grpc_log opentelemetry_cpp) + else() + target_link_libraries( + example_otlp_grpc_log opentelemetry_trace opentelemetry_logs + opentelemetry_exporter_otlp_grpc opentelemetry_exporter_otlp_grpc_log) endif() endif() @@ -75,20 +73,18 @@ if(WITH_OTLP_HTTP) # LOG - if(WITH_LOGS_PREVIEW) - add_executable(example_otlp_http_log http_log_main.cc) - target_link_libraries(example_otlp_http_log ${CMAKE_THREAD_LIBS_INIT} - common_logs_foo_library) - - if(DEFINED OPENTELEMETRY_BUILD_DLL) - target_link_libraries(example_otlp_http_log opentelemetry_cpp - opentelemetry_common) - else() - target_link_libraries( - example_otlp_http_log common_logs_foo_library opentelemetry_trace - opentelemetry_logs opentelemetry_exporter_otlp_http - opentelemetry_exporter_otlp_http_log) - endif() + add_executable(example_otlp_http_log http_log_main.cc) + target_link_libraries(example_otlp_http_log ${CMAKE_THREAD_LIBS_INIT} + common_logs_foo_library) + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_http_log opentelemetry_cpp + opentelemetry_common) + else() + target_link_libraries( + example_otlp_http_log common_logs_foo_library opentelemetry_trace + opentelemetry_logs opentelemetry_exporter_otlp_http + opentelemetry_exporter_otlp_http_log) endif() + endif() diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index f6f6685922..b1726de358 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -1,32 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider_factory.h" -# include "opentelemetry/sdk/logs/processor.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/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/trace/provider.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/processor.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/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/provider.h" // sdk::TracerProvider and sdk::LoggerProvider is just used to call ForceFlush and prevent to cancel // running exportings when destroy and shutdown exporters.It's optional to users. -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" -# include +#include -# ifdef BAZEL_BUILD -# include "examples/common/logs_foo_library/foo_library.h" -# else -# include "logs_foo_library/foo_library.h" -# endif +#ifdef BAZEL_BUILD +# include "examples/common/logs_foo_library/foo_library.h" +#else +# include "logs_foo_library/foo_library.h" +#endif namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; @@ -106,9 +105,3 @@ int main(int argc, char *argv[]) CleanupTracer(); CleanupLogger(); } -#else -int main() -{ - return 0; -} -#endif diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 5a5eeb599a..7b68ad44c7 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -1,33 +1,32 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.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/provider.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/logs/logger_provider_factory.h" -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" -# include "opentelemetry/sdk/trace/processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/trace/provider.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.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/provider.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/provider.h" // sdk::TracerProvider and sdk::LoggerProvider is just used to call ForceFlush and prevent to cancel // running exportings when destroy and shutdown exporters.It's optional to users. -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" -# include -# include +#include +#include -# ifdef BAZEL_BUILD -# include "examples/common/logs_foo_library/foo_library.h" -# else -# include "logs_foo_library/foo_library.h" -# endif +#ifdef BAZEL_BUILD +# include "examples/common/logs_foo_library/foo_library.h" +#else +# include "logs_foo_library/foo_library.h" +#endif namespace trace = opentelemetry::trace; namespace otlp = opentelemetry::exporter::otlp; @@ -154,9 +153,3 @@ int main(int argc, char *argv[]) CleanupTracer(); CleanupLogger(); } -#else -int main() -{ - return 0; -} -#endif diff --git a/exporters/CMakeLists.txt b/exporters/CMakeLists.txt index 78f845aadf..c40ff48654 100644 --- a/exporters/CMakeLists.txt +++ b/exporters/CMakeLists.txt @@ -16,7 +16,7 @@ if(WITH_ZIPKIN) add_subdirectory(zipkin) endif() -if(WITH_ELASTICSEARCH AND WITH_LOGS_PREVIEW) +if(WITH_ELASTICSEARCH) add_subdirectory(elasticsearch) endif() 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 63e096ff97..8579c99138 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 @@ -2,22 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# include "nlohmann/json.hpp" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/type_traits.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/recordable.h" - -# include -# include -# include -# include -# include -# include + +#include "nlohmann/json.hpp" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" + +#include +#include +#include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -122,7 +121,7 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo mutable opentelemetry::common::SpinLockMutex lock_; bool isShutdown() const noexcept; -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT struct SynchronizationData { std::atomic session_counter_{0}; @@ -132,9 +131,8 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo std::recursive_mutex force_flush_m; }; nostd::shared_ptr synchronization_data_; -# endif +#endif }; } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif 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 c5be2a2cd8..feb68f7f9c 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include -# include +#include +#include +#include +#include -# include "nlohmann/json.hpp" -# include "opentelemetry/common/macros.h" -# include "opentelemetry/sdk/common/attribute_utils.h" -# include "opentelemetry/sdk/logs/recordable.h" -# include "opentelemetry/version.h" +#include "nlohmann/json.hpp" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -128,4 +127,3 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index 14fd87d600..c90072e4e4 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include // std::stringstream -# include // std::stringstream - -# include -# include -# include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h" -# include "opentelemetry/exporters/elasticsearch/es_log_recordable.h" -# include "opentelemetry/sdk_config.h" +#include +#include +#include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h" +#include "opentelemetry/exporters/elasticsearch/es_log_recordable.h" +#include "opentelemetry/sdk_config.h" namespace nostd = opentelemetry::nostd; namespace sdklogs = opentelemetry::sdk::logs; @@ -182,7 +180,7 @@ class ResponseHandler : public http_client::EventHandler bool console_debug_ = false; }; -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT /** * This class handles the async response message from the Elasticsearch request */ @@ -287,21 +285,21 @@ class AsyncResponseHandler : public http_client::EventHandler // Whether to print the results from the callback bool console_debug_ = false; }; -# endif +#endif ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter() : options_{ElasticsearchExporterOptions()}, http_client_ { ext::http::client::HttpClientFactory::Create() } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , synchronization_data_(new SynchronizationData()) -# endif +#endif { -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT synchronization_data_->finished_session_counter_.store(0); synchronization_data_->session_counter_.store(0); -# endif +#endif } ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( @@ -351,7 +349,7 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export( std::vector body_vec(body.begin(), body.end()); request->SetBody(body_vec); -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT // Send the request synchronization_data_->session_counter_.fetch_add(1, std::memory_order_release); std::size_t span_count = records.size(); @@ -378,7 +376,7 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export( options_.console_debug_); session->SendRequest(handler); return sdk::common::ExportResult::kSuccess; -# else +#else // Send the request auto handler = std::make_shared(options_.console_debug_); session->SendRequest(handler); @@ -413,13 +411,13 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export( } return sdk::common::ExportResult::kSuccess; -# endif +#endif } bool ElasticsearchLogRecordExporter::ForceFlush( std::chrono::microseconds timeout OPENTELEMETRY_MAYBE_UNUSED) noexcept { -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT std::lock_guard lock_guard{synchronization_data_->force_flush_m}; std::size_t running_counter = synchronization_data_->session_counter_.load(std::memory_order_acquire); @@ -455,9 +453,9 @@ bool ElasticsearchLogRecordExporter::ForceFlush( } return timeout_steady > std::chrono::steady_clock::duration::zero(); -# else +#else return true; -# endif +#endif } bool ElasticsearchLogRecordExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept @@ -480,4 +478,3 @@ bool ElasticsearchLogRecordExporter::isShutdown() const noexcept } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index e3f60be0a9..139d22e863 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/exporters/elasticsearch/es_log_recordable.h" -# include "opentelemetry/logs/severity.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.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/exporters/elasticsearch/es_log_recordable.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.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" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -299,4 +297,3 @@ void ElasticSearchRecordable::SetInstrumentationScope( } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/elasticsearch/test/es_log_record_exporter_test.cc b/exporters/elasticsearch/test/es_log_record_exporter_test.cc index cc9af2ee2d..8a1c81da48 100644 --- a/exporters/elasticsearch/test/es_log_record_exporter_test.cc +++ b/exporters/elasticsearch/test/es_log_record_exporter_test.cc @@ -1,17 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h" +#include "opentelemetry/ext/http/server/http_server.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" -# include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h" -# include "opentelemetry/ext/http/server/http_server.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor.h" - -# include -# include +#include +#include namespace sdklogs = opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; @@ -23,7 +21,7 @@ TEST(ElasticsearchLogsExporterTests, Dummy) // to enable linking } -# if 0 +#if 0 // Attempt to write a log to an invalid host/port, test that the Export() returns failure TEST(ElasticsearchLogsExporterTests, InvalidEndpoint) { @@ -81,5 +79,4 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation) exporter->Export(nostd::span>(&record, 1)); } -# endif #endif diff --git a/exporters/etw/CMakeLists.txt b/exporters/etw/CMakeLists.txt index b74a1b2cb5..947e390dd9 100644 --- a/exporters/etw/CMakeLists.txt +++ b/exporters/etw/CMakeLists.txt @@ -14,9 +14,7 @@ set_target_properties(opentelemetry_exporter_etw PROPERTIES EXPORT_NAME target_link_libraries( opentelemetry_exporter_etw INTERFACE opentelemetry_api opentelemetry_trace nlohmann_json::nlohmann_json) -if(WITH_LOGS_PREVIEW) - target_link_libraries(opentelemetry_exporter_etw INTERFACE opentelemetry_logs) -endif() +target_link_libraries(opentelemetry_exporter_etw INTERFACE opentelemetry_logs) if(nlohmann_json_clone) add_dependencies(opentelemetry_exporter_etw nlohmann_json::nlohmann_json) endif() diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index 8040032597..819caf7105 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -2,39 +2,40 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include -# include +#include -# include -# include +#include +#include -# 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/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/variant.h" -# include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/logs/log_record.h" -# include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/trace/span_id.h" -# include "opentelemetry/trace/trace_id.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/trace/span_id.h" +#include "opentelemetry/trace/trace_id.h" -# include "opentelemetry/exporters/etw/etw_config.h" -# include "opentelemetry/exporters/etw/etw_fields.h" -# include "opentelemetry/exporters/etw/etw_properties.h" -# include "opentelemetry/exporters/etw/etw_provider.h" -# include "opentelemetry/exporters/etw/utils.h" +#include "opentelemetry/exporters/etw/etw_config.h" +#include "opentelemetry/exporters/etw/etw_fields.h" +#include "opentelemetry/exporters/etw/etw_properties.h" +#include "opentelemetry/exporters/etw/etw_provider.h" +#include "opentelemetry/exporters/etw/utils.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -86,6 +87,8 @@ class LogRecord : public opentelemetry::logs::LogRecord attributes_map_[static_cast(key)] = value; } + void SetEventId(int64_t /* id */, nostd::string_view /* name */) noexcept override {} + const std::unordered_map &GetAttributes() const noexcept { @@ -230,7 +233,7 @@ class Logger : public opentelemetry::logs::Logger { UNREFERENCED_PARAMETER(trace_flags); -# if defined(ENABLE_ENV_PROPERTIES) +#if defined(ENABLE_ENV_PROPERTIES) Properties env_properties_env = {}; bool has_customer_attribute = false; @@ -261,22 +264,22 @@ class Logger : public opentelemetry::logs::Logger Properties &evt = has_customer_attribute ? env_properties_env : input_evt; -# else +#else Properties &evt = input_evt; -# endif // defined(ENABLE_ENV_PROPERTIES) +#endif // defined(ENABLE_ENV_PROPERTIES) // Populate Etw.EventName attribute at envelope level evt[ETW_FIELD_NAME] = ETW_VALUE_LOG; -# ifdef HAVE_FIELD_TIME +#ifdef HAVE_FIELD_TIME { auto timeNow = std::chrono::system_clock::now().time_since_epoch(); auto nanos = std::chrono::duration_cast(timeNow).count(); evt[ETW_FIELD_TIME] = utils::formatUtcTimestampNsAsISO8601(nanos); } -# endif +#endif const auto &cfg = GetConfiguration(loggerProvider_); if (cfg.enableSpanId) { @@ -374,4 +377,3 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider } // namespace etw } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif // ENABLE_LOGS_PREVIEW diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h index 9b96cb27a5..d9f8ec2309 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h @@ -2,29 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include +#include +#include +#include -# include +#include -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/trace/span_id.h" -# include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_id.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/exporters/etw/etw_config.h" -# include "opentelemetry/exporters/etw/etw_logger.h" -# include "opentelemetry/exporters/etw/etw_provider.h" +#include "opentelemetry/exporters/etw/etw_config.h" +#include "opentelemetry/exporters/etw/etw_logger.h" +#include "opentelemetry/exporters/etw/etw_provider.h" -# include "opentelemetry/exporters/etw/utils.h" - -#endif // ENABLE_LOGS_PREVIEW +#include "opentelemetry/exporters/etw/utils.h" diff --git a/exporters/etw/test/etw_logger_test.cc b/exporters/etw/test/etw_logger_test.cc index 2c17dc846e..f27d47880b 100644 --- a/exporters/etw/test/etw_logger_test.cc +++ b/exporters/etw/test/etw_logger_test.cc @@ -1,15 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# ifdef _WIN32 +#ifdef _WIN32 -# include -# include -# include +# include +# include +# include -# include "opentelemetry/exporters/etw/etw_logger_exporter.h" -# include "opentelemetry/sdk/trace/simple_processor.h" +# include "opentelemetry/exporters/etw/etw_logger_exporter.h" +# include "opentelemetry/sdk/trace/simple_processor.h" using namespace OPENTELEMETRY_NAMESPACE; @@ -99,5 +98,4 @@ TEST(ETWLogger, LoggerCheckWithAttributes) opentelemetry::common::MakeAttributes(attribs))); } -# endif // _WIN32 -#endif // ENABLE_LOGS_PREVIEW +#endif // _WIN32 diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index 478c6b7ec2..e08d6592a3 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -76,40 +76,38 @@ if(BUILD_TESTING) TEST_LIST ostream_metric_test) endif() -if(WITH_LOGS_PREVIEW) - add_library(opentelemetry_exporter_ostream_logs - src/log_record_exporter.cc src/log_record_exporter_factory.cc) - set_target_properties(opentelemetry_exporter_ostream_logs - PROPERTIES EXPORT_NAME ostream_log_record_exporter) - set_target_version(opentelemetry_exporter_ostream_logs) +add_library(opentelemetry_exporter_ostream_logs + src/log_record_exporter.cc src/log_record_exporter_factory.cc) +set_target_properties(opentelemetry_exporter_ostream_logs + PROPERTIES EXPORT_NAME ostream_log_record_exporter) +set_target_version(opentelemetry_exporter_ostream_logs) - target_include_directories( - opentelemetry_exporter_ostream_logs - PUBLIC "$") - target_link_libraries(opentelemetry_exporter_ostream_logs - PUBLIC opentelemetry_logs) +target_include_directories( + opentelemetry_exporter_ostream_logs + PUBLIC "$") +target_link_libraries(opentelemetry_exporter_ostream_logs + PUBLIC opentelemetry_logs) - if(OPENTELEMETRY_INSTALL) - install( - TARGETS opentelemetry_exporter_ostream_logs - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install( - FILES - "include/opentelemetry/exporters/ostream/log_record_exporter.h" - "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" - DESTINATION include/opentelemetry/exporters/ostream) - endif() +if(OPENTELEMETRY_INSTALL) + install( + TARGETS opentelemetry_exporter_ostream_logs + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install( + FILES + "include/opentelemetry/exporters/ostream/log_record_exporter.h" + "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h" + DESTINATION include/opentelemetry/exporters/ostream) +endif() - if(BUILD_TESTING) - add_executable(ostream_log_test test/ostream_log_test.cc) - target_link_libraries(ostream_log_test ${GTEST_BOTH_LIBRARIES} - opentelemetry_exporter_ostream_logs) - gtest_add_tests( - TARGET ostream_log_test - TEST_PREFIX exporter. - TEST_LIST ostream_log_test) - endif() +if(BUILD_TESTING) + add_executable(ostream_log_test test/ostream_log_test.cc) + target_link_libraries(ostream_log_test ${GTEST_BOTH_LIBRARIES} + opentelemetry_exporter_ostream_logs) + gtest_add_tests( + TARGET ostream_log_test + TEST_PREFIX exporter. + TEST_LIST ostream_log_test) endif() 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 54dae898d2..7b196ec9e8 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/nostd/type_traits.h" -# include "opentelemetry/sdk/common/attribute_utils.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" -# include -# include -# include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -73,4 +72,3 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif 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 4c7d403d41..143a481801 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 @@ -3,11 +3,10 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include +#include +#include -# include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/sdk/version/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -43,4 +42,3 @@ class OPENTELEMETRY_EXPORT OStreamLogRecordExporterFactory } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 611a749184..7edae02b43 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -1,17 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/ostream/log_record_exporter.h" -# include "opentelemetry/exporters/ostream/common_utils.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/sdk_config.h" - -# include -# include -# include +#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/exporters/ostream/common_utils.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/sdk_config.h" + +#include +#include +#include namespace nostd = opentelemetry::nostd; namespace sdklogs = opentelemetry::sdk::logs; @@ -163,4 +162,3 @@ void OStreamLogRecordExporter::printAttributes( } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/ostream/src/log_record_exporter_factory.cc b/exporters/ostream/src/log_record_exporter_factory.cc index 884f59a9a1..66ea1a0232 100644 --- a/exporters/ostream/src/log_record_exporter_factory.cc +++ b/exporters/ostream/src/log_record_exporter_factory.cc @@ -1,9 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" -# include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" +#include "opentelemetry/exporters/ostream/log_record_exporter.h" namespace logs_sdk = opentelemetry::sdk::logs; @@ -28,4 +27,3 @@ std::unique_ptr OStreamLogRecordExporterFactory::Cr } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index c092ec01c3..064cd1103a 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -1,22 +1,29 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/exporters/ostream/log_record_exporter.h" -# include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/nostd/span.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/read_write_log_record.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor.h" -# include "opentelemetry/sdk/version/version.h" - -# include - -# include -# include +#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include "opentelemetry/sdk/version/version.h" + +#include "opentelemetry/exporters/ostream/log_record_exporter.h" +#include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include "opentelemetry/sdk/version/version.h" + +#include +#include + +#include namespace sdklogs = opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; @@ -518,4 +525,3 @@ TEST(OStreamLogRecordExporter, Factory) } // namespace logs } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index e05b0e24f4..44715c1753 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -17,9 +17,7 @@ target_include_directories( set(OPENTELEMETRY_OTLP_TARGETS opentelemetry_otlp_recordable) -if(WITH_LOGS_PREVIEW) - target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs) -endif() +target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs) target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_metrics) @@ -142,24 +140,22 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http) - if(WITH_LOGS_PREVIEW) - add_library( - opentelemetry_exporter_otlp_http_log - src/otlp_http_log_record_exporter.cc - src/otlp_http_log_record_exporter_factory.cc) + add_library( + opentelemetry_exporter_otlp_http_log + src/otlp_http_log_record_exporter.cc + src/otlp_http_log_record_exporter_factory.cc) - set_target_properties(opentelemetry_exporter_otlp_http_log - PROPERTIES EXPORT_NAME otlp_http_log_record_exporter) - set_target_version(opentelemetry_exporter_otlp_http_log) + set_target_properties(opentelemetry_exporter_otlp_http_log + PROPERTIES EXPORT_NAME otlp_http_log_record_exporter) + set_target_version(opentelemetry_exporter_otlp_http_log) - target_link_libraries( - opentelemetry_exporter_otlp_http_log - PUBLIC opentelemetry_otlp_recordable - opentelemetry_exporter_otlp_http_client) + target_link_libraries( + opentelemetry_exporter_otlp_http_log + PUBLIC opentelemetry_otlp_recordable + opentelemetry_exporter_otlp_http_client) - list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log) + list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log) - endif() add_library( opentelemetry_exporter_otlp_http_metric src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc) @@ -206,16 +202,13 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_recordable_test) - if(WITH_LOGS_PREVIEW) - add_executable(otlp_log_recordable_test test/otlp_log_recordable_test.cc) - target_link_libraries( - otlp_log_recordable_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_otlp_recordable) - gtest_add_tests( - TARGET otlp_log_recordable_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_log_recordable_test) - endif() + add_executable(otlp_log_recordable_test test/otlp_log_recordable_test.cc) + target_link_libraries(otlp_log_recordable_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_otlp_recordable) + gtest_add_tests( + TARGET otlp_log_recordable_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_log_recordable_test) add_executable(otlp_metrics_serialization_test test/otlp_metrics_serialization_test.cc) @@ -267,34 +260,32 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_exporter_factory_test) - if(WITH_LOGS_PREVIEW) - add_executable(otlp_grpc_log_record_exporter_test - test/otlp_grpc_log_record_exporter_test.cc) - target_link_libraries( - otlp_grpc_log_record_exporter_test - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIB} - opentelemetry_exporter_otlp_grpc - opentelemetry_exporter_otlp_grpc_log - opentelemetry_trace - opentelemetry_logs) - gtest_add_tests( - TARGET otlp_grpc_log_record_exporter_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_grpc_log_record_exporter_test) - - add_executable(otlp_grpc_log_record_exporter_factory_test - test/otlp_grpc_log_record_exporter_factory_test.cc) - target_link_libraries( - otlp_grpc_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} - opentelemetry_exporter_otlp_grpc_log opentelemetry_logs) - gtest_add_tests( - TARGET otlp_grpc_log_record_exporter_factory_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_grpc_log_record_exporter_factory_test) - endif() + add_executable(otlp_grpc_log_record_exporter_test + test/otlp_grpc_log_record_exporter_test.cc) + target_link_libraries( + otlp_grpc_log_record_exporter_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIB} + opentelemetry_exporter_otlp_grpc + opentelemetry_exporter_otlp_grpc_log + opentelemetry_trace + opentelemetry_logs) + gtest_add_tests( + TARGET otlp_grpc_log_record_exporter_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_log_record_exporter_test) + + add_executable(otlp_grpc_log_record_exporter_factory_test + test/otlp_grpc_log_record_exporter_factory_test.cc) + target_link_libraries( + otlp_grpc_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_grpc_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_grpc_log_record_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_log_record_exporter_factory_test) add_executable(otlp_grpc_metric_exporter_factory_test test/otlp_grpc_metric_exporter_factory_test.cc) @@ -334,33 +325,31 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_exporter_factory_test) - if(WITH_LOGS_PREVIEW) - add_executable(otlp_http_log_record_exporter_test - test/otlp_http_log_record_exporter_test.cc) - target_link_libraries( - otlp_http_log_record_exporter_test - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIB} - opentelemetry_exporter_otlp_http_log - opentelemetry_logs - opentelemetry_http_client_nosend) - gtest_add_tests( - TARGET otlp_http_log_record_exporter_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_http_log_record_exporter_test) - - add_executable(otlp_http_log_record_exporter_factory_test - test/otlp_http_log_record_exporter_factory_test.cc) - target_link_libraries( - otlp_http_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} - opentelemetry_exporter_otlp_http_log opentelemetry_logs) - gtest_add_tests( - TARGET otlp_http_log_record_exporter_factory_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_http_log_record_exporter_factory_test) - endif() + add_executable(otlp_http_log_record_exporter_test + test/otlp_http_log_record_exporter_test.cc) + target_link_libraries( + otlp_http_log_record_exporter_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_log + opentelemetry_logs + opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_log_record_exporter_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_record_exporter_test) + + add_executable(otlp_http_log_record_exporter_factory_test + test/otlp_http_log_record_exporter_factory_test.cc) + target_link_libraries( + otlp_http_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_http_log_record_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_record_exporter_factory_test) add_executable(otlp_http_metric_exporter_test test/otlp_http_metric_exporter_test.cc) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h index 75defd6b42..7998bd2646 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -11,13 +11,10 @@ #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" #include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" #include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" -#endif - #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -60,13 +57,11 @@ class OtlpGrpcClient static std::unique_ptr MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options); -#ifdef ENABLE_LOGS_PREVIEW /** * Create logs service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr MakeLogsServiceStub(const OtlpGrpcExporterOptions &options); -#endif static grpc::Status DelegateExport( proto::collector::trace::v1::TraceService::StubInterface *stub, @@ -80,13 +75,11 @@ class OtlpGrpcClient const proto::collector::metrics::v1::ExportMetricsServiceRequest &request, proto::collector::metrics::v1::ExportMetricsServiceResponse *response); -#ifdef ENABLE_LOGS_PREVIEW static grpc::Status DelegateExport( proto::collector::logs::v1::LogsService::StubInterface *stub, grpc::ClientContext *context, const proto::collector::logs::v1::ExportLogsServiceRequest &request, proto::collector::logs::v1::ExportLogsServiceResponse *response); -#endif }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h index becb308ca2..33476297cb 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h @@ -2,20 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW // clang-format off -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on -# include "opentelemetry/exporters/otlp/otlp_environment.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -95,5 +94,3 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h index a6fa8e50d6..5f81e60f2e 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h @@ -3,10 +3,8 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -35,5 +33,3 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif /* ENABLE_LOGS_PREVIEW */ 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 9188858fc1..1adbbc70b9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -26,7 +26,7 @@ namespace otlp /** * The OTLP exporter exports span data in OpenTelemetry Protocol (OTLP) format. */ -class OtlpHttpExporter final : public opentelemetry::sdk::trace::SpanExporter +class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::trace::SpanExporter { public: /** 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 035b046b72..4393345dfd 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 @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/exporters/otlp/otlp_http_client.h" +#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 "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" -# include -# include -# include -# include +#include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -86,4 +85,3 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif 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 152a394574..f4c90d5b0c 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 @@ -2,12 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/sdk/logs/exporter.h" -# include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -36,4 +35,3 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif 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 e785170329..65fd2b9b63 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 @@ -2,16 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/otlp/otlp_environment.h" -# include "opentelemetry/exporters/otlp/otlp_http.h" -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/sdk/logs/exporter.h" -# include -# include -# include -# include +#include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -49,16 +48,16 @@ struct OtlpHttpLogRecordExporterOptions // Additional HTTP headers OtlpHeaders http_headers = GetOtlpDefaultLogsHeaders(); -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT // Concurrent requests // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests std::size_t max_concurrent_requests = 64; // Requests per connections std::size_t max_requests_per_connection = 8; -# endif +#endif -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW bool ssl_insecure_skip_verify{false}; std::string ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); @@ -69,9 +68,9 @@ struct OtlpHttpLogRecordExporterOptions std::string ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); std::string ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ std::string ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); /** Maximum TLS version. */ @@ -80,10 +79,9 @@ struct OtlpHttpLogRecordExporterOptions std::string ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); /** TLS cipher suite. */ std::string ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h index 0648fe3308..1fa1dad096 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h @@ -2,22 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW // clang-format off -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/proto/logs/v1/logs.pb.h" -# include "opentelemetry/proto/resource/v1/resource.pb.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/proto/resource/v1/resource.pb.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on -# include "opentelemetry/common/macros.h" -# include "opentelemetry/sdk/common/attribute_utils.h" -# include "opentelemetry/sdk/logs/read_write_log_record.h" -# include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/sdk/common/attribute_utils.h" +#include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -126,5 +125,3 @@ class OtlpLogRecordable final : public opentelemetry::sdk::logs::Recordable } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif 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 1ad9514aa9..74a4cd9aeb 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable_utils.h @@ -16,9 +16,7 @@ #include "opentelemetry/sdk/trace/recordable.h" -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/sdk/logs/recordable.h" -#endif +#include "opentelemetry/sdk/logs/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -35,11 +33,9 @@ class OtlpRecordableUtils const nostd::span> &spans, proto::collector::trace::v1::ExportTraceServiceRequest *request) noexcept; -#ifdef ENABLE_LOGS_PREVIEW static void PopulateRequest( const nostd::span> &logs, proto::collector::logs::v1::ExportLogsServiceRequest *request) noexcept; -#endif }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 5a94c66b59..625781025e 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -132,13 +132,11 @@ OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options) return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options)); } -#ifdef ENABLE_LOGS_PREVIEW std::unique_ptr OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcExporterOptions &options) { return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options)); } -#endif grpc::Status OtlpGrpcClient::DelegateExport( proto::collector::trace::v1::TraceService::StubInterface *stub, @@ -158,7 +156,6 @@ grpc::Status OtlpGrpcClient::DelegateExport( return stub->Export(context, request, response); } -#ifdef ENABLE_LOGS_PREVIEW grpc::Status OtlpGrpcClient::DelegateExport( proto::collector::logs::v1::LogsService::StubInterface *stub, grpc::ClientContext *context, @@ -167,7 +164,6 @@ grpc::Status OtlpGrpcClient::DelegateExport( { return stub->Export(context, request, response); } -#endif } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index 6cef1d07b6..01367da886 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -1,28 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/exporters/otlp/otlp_grpc_client.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_log_recordable.h" -# include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_log_recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" // clang-format off -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on -# include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/common/global_log_handler.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -106,5 +104,3 @@ bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc index d52a6269ba..b36eefa6cb 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -1,13 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - // MUST be first (absl) -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -33,5 +31,3 @@ OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcExporterOptions &options) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index f0d410f6f2..9414e2fd76 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -1,19 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_log_recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_log_recordable.h" -# include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/common/global_log_handler.h" namespace nostd = opentelemetry::nostd; @@ -31,7 +29,7 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( const OtlpHttpLogRecordExporterOptions &options) : options_(options), http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW options.ssl_insecure_skip_verify, options.ssl_ca_cert_path, options.ssl_ca_cert_string, @@ -39,24 +37,24 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( options.ssl_client_key_string, options.ssl_client_cert_path, options.ssl_client_cert_string, -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW options.ssl_min_tls, options.ssl_max_tls, options.ssl_cipher, options.ssl_cipher_suite, -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ options.content_type, options.json_bytes_mapping, options.use_json_name, options.console_debug, options.timeout, options.http_headers -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT , options.max_concurrent_requests, options.max_requests_per_connection -# endif +#endif ))) {} @@ -72,10 +70,10 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptrGetOptions().console_debug; options.timeout = http_client_->GetOptions().timeout; options.http_headers = http_client_->GetOptions().http_headers; -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests; options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection; -# endif +#endif } // ----------------------------- Exporter methods ------------------------------ @@ -103,7 +101,7 @@ opentelemetry::sdk::common::ExportResult OtlpHttpLogRecordExporter::Export( proto::collector::logs::v1::ExportLogsServiceRequest service_request; OtlpRecordableUtils::PopulateRequest(logs, &service_request); std::size_t log_count = logs.size(); -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT http_client_->Export( service_request, [log_count](opentelemetry::sdk::common::ExportResult result) { if (result != opentelemetry::sdk::common::ExportResult::kSuccess) @@ -118,7 +116,7 @@ opentelemetry::sdk::common::ExportResult OtlpHttpLogRecordExporter::Export( return true; }); return opentelemetry::sdk::common::ExportResult::kSuccess; -# else +#else opentelemetry::sdk::common::ExportResult result = http_client_->Export(service_request); if (result != opentelemetry::sdk::common::ExportResult::kSuccess) { @@ -130,7 +128,7 @@ opentelemetry::sdk::common::ExportResult OtlpHttpLogRecordExporter::Export( OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Client] Export " << log_count << " log(s) success"); } return opentelemetry::sdk::common::ExportResult::kSuccess; -# endif +#endif } bool OtlpHttpLogRecordExporter::ForceFlush(std::chrono::microseconds timeout) noexcept @@ -146,5 +144,3 @@ bool OtlpHttpLogRecordExporter::Shutdown(std::chrono::microseconds timeout) noex } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index d05d68ce26..c224acc053 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -1,11 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.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_http_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -31,5 +29,3 @@ OtlpHttpLogRecordExporterFactory::Create(const OtlpHttpLogRecordExporterOptions } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/src/otlp_log_recordable.cc b/exporters/otlp/src/otlp_log_recordable.cc index cc4d712795..7b86839dff 100644 --- a/exporters/otlp/src/otlp_log_recordable.cc +++ b/exporters/otlp/src/otlp_log_recordable.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/common/macros.h" -# include "opentelemetry/common/macros.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/sdk/logs/readable_log_record.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/sdk/logs/readable_log_record.h" namespace nostd = opentelemetry::nostd; @@ -233,5 +231,3 @@ void OtlpLogRecordable::SetInstrumentationScope( } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 81859ba070..1b1da94e08 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -72,7 +72,6 @@ void OtlpRecordableUtils::PopulateRequest( } } -#ifdef ENABLE_LOGS_PREVIEW void OtlpRecordableUtils::PopulateRequest( const nostd::span> &logs, proto::collector::logs::v1::ExportLogsServiceRequest *request) noexcept @@ -137,7 +136,6 @@ void OtlpRecordableUtils::PopulateRequest( } } } -#endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc index 5219d22d14..2cc534277d 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc @@ -1,20 +1,18 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include -# include - -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" /* Make sure OtlpGrpcLogRecordExporterFactory does not require, even indirectly, protobuf headers. */ -# ifdef GOOGLE_PROTOBUF_VERSION -# error "protobuf should not be included" -# endif +#ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +#endif OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -36,5 +34,3 @@ TEST(OtlpGrpcLogRecordExporterFactoryTest, BuildTest) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // ENABLE_LOGS_PREVIEW 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 518caaba5e..547d21d056 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -1,39 +1,37 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include -# include +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service_mock.grpc.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service_mock.grpc.pb.h" -# include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/provider.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/batch_log_record_processor.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/recordable.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/sdk/trace/exporter.h" -# include "opentelemetry/sdk/trace/processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/trace/provider.h" +#include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -203,5 +201,3 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // ENABLE_LOGS_PREVIEW diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_factory_test.cc index 34b408d8a2..1f3275e1c3 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_factory_test.cc @@ -1,28 +1,26 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include -# include - -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" -# include "opentelemetry/exporters/otlp/otlp_http_log_record_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" /* Make sure OtlpHttpExporterFactory does not require, even indirectly, nlohmann/json headers. */ -# ifdef NLOHMANN_JSON_VERSION_MAJOR -# error "nlohmann/json should not be included" -# endif /* NLOHMANN_JSON_VERSION_MAJOR */ +#ifdef NLOHMANN_JSON_VERSION_MAJOR +# error "nlohmann/json should not be included" +#endif /* NLOHMANN_JSON_VERSION_MAJOR */ /* Make sure OtlpHttpExporterFactory does not require, even indirectly, protobuf headers. */ -# ifdef GOOGLE_PROTOBUF_VERSION -# error "protobuf should not be included" -# endif +#ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +#endif OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -44,5 +42,3 @@ TEST(OtlpHttpLogRecordExporterFactoryTest, BuildTest) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // ENABLE_LOGS_PREVIEW 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 7720b6e5d8..4dc3b5829d 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -2,40 +2,39 @@ // SPDX-License-Identifier: Apache-2.0 #ifndef HAVE_CPP_STDLIB -# ifdef ENABLE_LOGS_PREVIEW -# include -# include +# include +# include -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -# include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/ext/http/server/http_server.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/batch_log_record_processor.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +# include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/ext/http/client/http_client_factory.h" +# include "opentelemetry/ext/http/server/http_server.h" +# include "opentelemetry/logs/provider.h" +# include "opentelemetry/sdk/logs/batch_log_record_processor.h" +# include "opentelemetry/sdk/logs/exporter.h" +# include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" -# include -# include -# include "gmock/gmock.h" +# include +# include +# include "gmock/gmock.h" -# include "nlohmann/json.hpp" +# include "nlohmann/json.hpp" -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +# if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +# endif using namespace testing; @@ -61,19 +60,19 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, -# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW +# ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ "", /* ssl_client_key_path */ "", /* ssl_client_key_string */ "", /* ssl_client_cert_path */ "", /* ssl_client_cert_string */ -# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ -# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW - "", /* ssl_min_tls */ - "", /* ssl_max_tls */ - "", /* ssl_cipher */ - "", /* ssl_cipher_suite */ -# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +# endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ +# ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + "", /* ssl_min_tls */ + "", /* ssl_max_tls */ + "", /* ssl_cipher */ + "", /* ssl_cipher_suite */ +# endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ options.content_type, options.json_bytes_mapping, options.use_json_name, options.console_debug, options.timeout, options.http_headers); if (!async_mode) @@ -222,7 +221,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -349,7 +348,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# endif +# endif void ExportBinaryIntegrationTest() { @@ -462,7 +461,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -578,7 +577,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test provider->ForceFlush(); } -# endif +# endif }; TEST(OtlpHttpLogRecordExporterTest, Shutdown) @@ -599,13 +598,13 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); google::protobuf::ShutdownProtobufLibrary(); } -# endif +# endif // Create log records, let processor call Export() TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -613,12 +612,12 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +# ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +# endif // Test exporter configuration options TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigTest) @@ -647,7 +646,7 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigJsonBytesMappingTest) EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex); } -# ifndef NO_GETENV +# ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigFromEnv) { @@ -736,10 +735,9 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, DefaultEndpoint) EXPECT_EQ("http://localhost:4317", GetOtlpDefaultGrpcEndpoint()); } -# endif +# endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -# endif #endif diff --git a/exporters/otlp/test/otlp_log_recordable_test.cc b/exporters/otlp/test/otlp_log_recordable_test.cc index 96c5c66b09..bcecbb8d8f 100644 --- a/exporters/otlp/test/otlp_log_recordable_test.cc +++ b/exporters/otlp/test/otlp_log_recordable_test.cc @@ -1,16 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include -# include +#include -# include - -# include "opentelemetry/exporters/otlp/otlp_log_recordable.h" -# include "opentelemetry/sdk/logs/read_write_log_record.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/sdk/resource/semantic_conventions.h" +#include "opentelemetry/exporters/otlp/otlp_log_recordable.h" +#include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/resource/semantic_conventions.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -134,30 +132,14 @@ TEST(OtlpLogRecordable, SetArrayAttribute) nostd::span str_span(str_arr); rec.SetAttribute("str_arr_attr", str_span); - const opentelemetry::proto::common::v1::ArrayValue *bool_values = nullptr; - const opentelemetry::proto::common::v1::ArrayValue *double_values = nullptr; - const opentelemetry::proto::common::v1::ArrayValue *string_values = nullptr; - for (int i = 0; i < rec.log_record().attributes_size(); i++) - { - if (rec.log_record().attributes(i).value().array_value().values(0).has_bool_value()) - { - bool_values = &rec.log_record().attributes(i).value().array_value(); - } - else if (rec.log_record().attributes(i).value().array_value().values(0).has_double_value()) - { - double_values = &rec.log_record().attributes(i).value().array_value(); - } - else if (rec.log_record().attributes(i).value().array_value().values(0).has_string_value()) - { - string_values = &rec.log_record().attributes(i).value().array_value(); - } - } - for (int i = 0; i < kArraySize; i++) { - EXPECT_EQ(bool_values->values(i).bool_value(), bool_span[i]); - EXPECT_EQ(double_values->values(i).double_value(), double_span[i]); - EXPECT_EQ(string_values->values(i).string_value(), str_span[i]); + EXPECT_EQ(rec.log_record().attributes(0).value().array_value().values(i).bool_value(), + bool_span[i]); + EXPECT_EQ(rec.log_record().attributes(1).value().array_value().values(i).double_value(), + double_span[i]); + EXPECT_EQ(rec.log_record().attributes(2).value().array_value().values(i).string_value(), + str_span[i]); } } @@ -220,5 +202,3 @@ TYPED_TEST(OtlpLogRecordableIntAttributeTest, SetIntArrayAttribute) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index d9156a5f8c..c0b6b91745 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -22,18 +22,18 @@ if(WITH_OTLP_HTTP) PRIVATE opentelemetry_exporter_otlp_http) endif() -if(WITH_LOGS_PREVIEW) - target_link_libraries(opentelemetry_cpp PRIVATE opentelemetry_logs) - - if(WITH_OTLP_GRPC) - target_link_libraries(opentelemetry_cpp - PRIVATE opentelemetry_exporter_otlp_grpc_log) - endif() - - if(WITH_OTLP_HTTP) - target_link_libraries(opentelemetry_cpp - PRIVATE opentelemetry_exporter_otlp_http_log) - endif() +target_link_libraries( + opentelemetry_cpp PRIVATE opentelemetry_logs + opentelemetry_exporter_ostream_logs) + +if(WITH_OTLP_GRPC) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_grpc_log) +endif() + +if(WITH_OTLP_HTTP) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_http_log) endif() add_custom_command( diff --git a/ext/src/dll/dllmain.cc b/ext/src/dll/dllmain.cc index 3dc5bc5c11..1812377374 100644 --- a/ext/src/dll/dllmain.cc +++ b/ext/src/dll/dllmain.cc @@ -6,9 +6,8 @@ // Include API header files here for exporting #include -#if defined(ENABLE_LOGS_PREVIEW) -# include -#endif // ENABLE_LOGS_PREVIEW +#include +#include extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 043b6a96d6..1afa635df4 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -22,7 +22,6 @@ EXPORTS // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z #endif // defined(WITH_OTLP_HTTP) -#if defined(ENABLE_LOGS_PREVIEW) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) #if defined(_WIN64) ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z @@ -45,15 +44,29 @@ EXPORTS #if defined(WIN32) ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z #else - ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z + ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z #endif + ?ForceFlush@TracerProvider@trace@sdk@v1@opentelemetry@@QEAA_NV?$duration@_JU?$ratio@$00$0PECEA@@std@@@chrono@std@@@Z + ?ForceFlush@LoggerProvider@logs@sdk@v1@opentelemetry@@QEAA_NV?$duration@_JU?$ratio@$00$0PECEA@@std@@@chrono@std@@@Z + ??0OStreamLogRecordExporter@logs@exporter@v1@opentelemetry@@QEAA@AEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z +#if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) + ?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ + ?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ + ?GetOtlpDefaultLogsTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ + ?GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ +#endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) #if defined(WITH_OTLP_GRPC) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z + ?GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ + ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_GRPC) #if defined(WITH_OTLP_HTTP) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions const & __ptr64) ?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpLogRecordExporterOptions@2345@@Z -#endif // defined(WITH_OTLP_HTTP) -#endif // defined(ENABLE_LOGS_PREVIEW) + ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +#endif // defined(WITH_OTLP_HTTP) // clang-format on diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 2e8f3bb61d..90d07a984a 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -23,17 +23,11 @@ if(OPENTELEMETRY_INSTALL) FILES_MATCHING PATTERN "*config.h") - set(LOGS_EXCLUDE_PATTERN "") - if(NOT WITH_LOGS_PREVIEW) - set(LOGS_EXCLUDE_PATTERN "logs") - endif() - install( DIRECTORY include/opentelemetry/sdk DESTINATION include/opentelemetry FILES_MATCHING - PATTERN "*.h" - PATTERN "${LOGS_EXCLUDE_PATTERN}" EXCLUDE) + PATTERN "*.h") endif() add_subdirectory(src) diff --git a/sdk/include/opentelemetry/sdk/common/empty_attributes.h b/sdk/include/opentelemetry/sdk/common/empty_attributes.h index 664f907d23..1e0a6393bd 100644 --- a/sdk/include/opentelemetry/sdk/common/empty_attributes.h +++ b/sdk/include/opentelemetry/sdk/common/empty_attributes.h @@ -14,13 +14,13 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { + /** * Maintain a static empty array of pairs that represents empty (default) attributes. * This helps to avoid constructing a new empty container every time a call is made * with default attributes. */ -OPENTELEMETRY_MAYBE_UNUSED static const opentelemetry::common::KeyValueIterableView< - std::array, 0>> +static const opentelemetry::common::KeyValueIterableView, 0>> &GetEmptyAttributes() noexcept { static const std::array, 0> array{}; @@ -30,5 +30,6 @@ OPENTELEMETRY_MAYBE_UNUSED static const opentelemetry::common::KeyValueIterableV return kEmptyAttributes; } + } // namespace sdk OPENTELEMETRY_END_NAMESPACE 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 d1cd045a58..d0b3577491 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h @@ -2,19 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# 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 "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 +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -155,4 +154,3 @@ class BatchLogRecordProcessor : public LogRecordProcessor } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif 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 83740542cb..74e0efbb59 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 @@ -3,11 +3,9 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -36,4 +34,3 @@ class OPENTELEMETRY_EXPORT BatchLogRecordProcessorFactory } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h index 05a2c48c3c..b130f947af 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h @@ -3,12 +3,10 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -41,4 +39,3 @@ struct BatchLogRecordProcessorOptions } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger.h b/sdk/include/opentelemetry/sdk/logs/event_logger.h index b15754940a..8230beeb32 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger.h @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include +#include -# include "opentelemetry/logs/event_logger.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/event_logger.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -51,4 +50,3 @@ class EventLogger final : public opentelemetry::logs::EventLogger } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h index 0eb9435f45..2f3d2a0afd 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider.h @@ -2,16 +2,15 @@ // SPDX-License-Identifier: Apache-2.0/ #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/logs/event_logger_provider.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/event_logger_provider.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" // Define the maximum number of loggers that are allowed to be registered to the loggerprovider. // TODO: Add link to logging spec once this is added to it -# define MAX_LOGGER_COUNT 100 +#define MAX_LOGGER_COUNT 100 OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -35,4 +34,3 @@ class EventLoggerProvider final : public opentelemetry::logs::EventLoggerProvide } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif 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 ecc78d1b80..0b8c066fc6 100644 --- a/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/event_logger_provider_factory.h @@ -3,10 +3,8 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# include -# include "opentelemetry/version.h" +#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -34,4 +32,3 @@ class EventLoggerProviderFactory } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/include/opentelemetry/sdk/logs/exporter.h b/sdk/include/opentelemetry/sdk/logs/exporter.h index fc0e68564c..bdddc4209c 100644 --- a/sdk/include/opentelemetry/sdk/logs/exporter.h +++ b/sdk/include/opentelemetry/sdk/logs/exporter.h @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include +#include +#include -# include "opentelemetry/nostd/span.h" -# include "opentelemetry/sdk/common/exporter_utils.h" -# include "opentelemetry/version.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -68,4 +67,3 @@ class OPENTELEMETRY_EXPORT LogRecordExporter } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index 67eafe84bc..fbbf4f28a5 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -2,18 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include +#include +#include -# include "opentelemetry/common/macros.h" -# include "opentelemetry/logs/logger.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -72,4 +71,3 @@ class Logger final : public opentelemetry::logs::Logger } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context.h b/sdk/include/opentelemetry/sdk/logs/logger_context.h index 196ecd545f..ee47c56a7f 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context.h @@ -3,15 +3,13 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include +#include -# include -# include -# include - -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/version.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -83,4 +81,3 @@ class LoggerContext } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h index 0e3502c10c..9f8a8a54ba 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -3,12 +3,10 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -47,4 +45,3 @@ class LoggerContextFactory } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index 01dc241470..0ab5683d3e 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -2,21 +2,20 @@ // SPDX-License-Identifier: Apache-2.0/ #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include +#include +#include +#include -# include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" // Define the maximum number of loggers that are allowed to be registered to the loggerprovider. // TODO: Add link to logging spec once this is added to it -# define MAX_LOGGER_COUNT 100 +#define MAX_LOGGER_COUNT 100 OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -112,4 +111,3 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h index 5d74d7918d..987a09fe16 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -3,12 +3,10 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs @@ -70,4 +68,3 @@ class OPENTELEMETRY_EXPORT LoggerProviderFactory } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif /* ENABLE_LOGS_PREVIEW */ 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 91995aa6a3..335da7f668 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor.h @@ -3,14 +3,12 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include +#include -# include -# include -# include - -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/version.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -66,4 +64,3 @@ class MultiLogRecordProcessor : public LogRecordProcessor } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif 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 c3e87c12db..26bd9152ce 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 @@ -3,12 +3,10 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -31,4 +29,3 @@ class OPENTELEMETRY_EXPORT MultiLogRecordProcessorFactory } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h index 97ae1451fc..1eb4b1a221 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h @@ -3,16 +3,14 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include +#include +#include -# include -# include -# include - -# include "opentelemetry/common/macros.h" -# include "opentelemetry/sdk/logs/recordable.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/macros.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -109,5 +107,3 @@ class MultiRecordable final : public Recordable } // namespace sdk OPENTELEMETRY_END_NAMESPACE - -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/processor.h b/sdk/include/opentelemetry/sdk/logs/processor.h index 8a409e0020..79a25ff260 100644 --- a/sdk/include/opentelemetry/sdk/logs/processor.h +++ b/sdk/include/opentelemetry/sdk/logs/processor.h @@ -2,12 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include +#include +#include -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -62,4 +61,3 @@ class LogRecordProcessor } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h b/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h index 915c8852e9..9831eaa1c9 100644 --- a/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h @@ -2,25 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW - -# include -# include -# include - -# include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/key_value_iterable.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/common/attribute_utils.h" -# include "opentelemetry/sdk/common/empty_attributes.h" -# include "opentelemetry/sdk/logs/readable_log_record.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 + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.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/common/attribute_utils.h" +#include "opentelemetry/sdk/logs/readable_log_record.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 @@ -209,4 +207,3 @@ class ReadWriteLogRecord final : public ReadableLogRecord } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h index ba20ca7949..acec5b88f9 100644 --- a/sdk/include/opentelemetry/sdk/logs/readable_log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/readable_log_record.h @@ -2,17 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# 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/logs/recordable.h" -# include "opentelemetry/version.h" +#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/logs/recordable.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -140,4 +139,3 @@ class ReadableLogRecord : public Recordable } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/logs/recordable.h b/sdk/include/opentelemetry/sdk/logs/recordable.h index ff0099af56..65f5f6ae94 100644 --- a/sdk/include/opentelemetry/sdk/logs/recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/recordable.h @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/logs/log_record.h" -# include "opentelemetry/version.h" +#include "opentelemetry/logs/log_record.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -49,4 +48,3 @@ class Recordable : public opentelemetry::logs::LogRecord } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif 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 de9cecdd84..e195f89c10 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor.h @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include +#include +#include +#include -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/version.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -58,4 +57,3 @@ class SimpleLogRecordProcessor : public LogRecordProcessor } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif 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 cd022aadd6..295addce11 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 @@ -3,11 +3,9 @@ #pragma once -#ifdef ENABLE_LOGS_PREVIEW +#include -# include - -# include "opentelemetry/version.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -32,4 +30,3 @@ class OPENTELEMETRY_EXPORT SimpleLogRecordProcessorFactory } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 9525b3f249..377d305627 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -4,8 +4,6 @@ add_subdirectory(common) add_subdirectory(trace) add_subdirectory(metrics) -if(WITH_LOGS_PREVIEW) - add_subdirectory(logs) -endif() +add_subdirectory(logs) add_subdirectory(version) add_subdirectory(resource) diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index c4cede1a53..92536d1c00 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/sdk/logs/recordable.h" -# include "opentelemetry/sdk/logs/batch_log_record_processor.h" -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/sdk/logs/recordable.h" - -# include +#include using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBufferRange; @@ -312,4 +310,3 @@ BatchLogRecordProcessor::~BatchLogRecordProcessor() } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/batch_log_record_processor_factory.cc b/sdk/src/logs/batch_log_record_processor_factory.cc index 67d0a677ab..dabd0f4ff8 100644 --- a/sdk/src/logs/batch_log_record_processor_factory.cc +++ b/sdk/src/logs/batch_log_record_processor_factory.cc @@ -1,10 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" -# 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.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -24,4 +22,3 @@ std::unique_ptr BatchLogRecordProcessorFactory::Create( } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/event_logger.cc b/sdk/src/logs/event_logger.cc index 2106ecb233..c9dd5c35b5 100644 --- a/sdk/src/logs/event_logger.cc +++ b/sdk/src/logs/event_logger.cc @@ -1,10 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/sdk/logs/event_logger.h" -# include "opentelemetry/sdk_config.h" -# include "opentelemetry/trace/provider.h" +#include "opentelemetry/sdk/logs/event_logger.h" +#include "opentelemetry/sdk_config.h" +#include "opentelemetry/trace/provider.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -53,4 +52,3 @@ void EventLogger::EmitEvent(nostd::string_view event_name, } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/event_logger_provider.cc b/sdk/src/logs/event_logger_provider.cc index 2352fca59b..28a88d82e2 100644 --- a/sdk/src/logs/event_logger_provider.cc +++ b/sdk/src/logs/event_logger_provider.cc @@ -1,17 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/event_logger_provider.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/logs/event_logger.h" -# include "opentelemetry/sdk/logs/event_logger_provider.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/logs/event_logger.h" - -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -38,4 +36,3 @@ nostd::shared_ptr EventLoggerProvider::CreateE } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/event_logger_provider_factory.cc b/sdk/src/logs/event_logger_provider_factory.cc index 966f33228a..0c9eff4570 100644 --- a/sdk/src/logs/event_logger_provider_factory.cc +++ b/sdk/src/logs/event_logger_provider_factory.cc @@ -1,11 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/event_logger_provider_factory.h" -# include "opentelemetry/sdk/logs/event_logger_provider.h" -# include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/logs/event_logger_provider_factory.h" +#include "opentelemetry/sdk/logs/event_logger_provider.h" +#include "opentelemetry/sdk/resource/resource.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -21,4 +19,3 @@ std::unique_ptr EventLoggerProviderFac } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/exporter.cc b/sdk/src/logs/exporter.cc index 20fdb6b25c..e57363ff25 100644 --- a/sdk/src/logs/exporter.cc +++ b/sdk/src/logs/exporter.cc @@ -1,9 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -24,4 +22,3 @@ OPENTELEMETRY_EXPORT bool LogRecordExporter::ForceFlush( } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index e9ebb8bdc4..7f85ddd6a3 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/logger.h" -# include "opentelemetry/context/runtime_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/sdk/logs/logger.h" +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk_config.h" +#include "opentelemetry/trace/provider.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -106,4 +104,3 @@ Logger::GetInstrumentationScope() const noexcept } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/logger_context.cc b/sdk/src/logs/logger_context.cc index 3421ad9999..357d13193d 100644 --- a/sdk/src/logs/logger_context.cc +++ b/sdk/src/logs/logger_context.cc @@ -1,13 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/multi_log_record_processor.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/multi_log_record_processor.h" - -# include -# include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -52,4 +50,3 @@ bool LoggerContext::Shutdown(std::chrono::microseconds timeout) noexcept } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/logger_context_factory.cc b/sdk/src/logs/logger_context_factory.cc index 1fc07f53e5..ff57747f80 100644 --- a/sdk/src/logs/logger_context_factory.cc +++ b/sdk/src/logs/logger_context_factory.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/logger_context_factory.h" +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/sdk/logs/logger_context_factory.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/processor.h" -# include "opentelemetry/sdk/resource/resource.h" - -# include -# include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -36,4 +34,3 @@ std::unique_ptr LoggerContextFactory::Create( } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 638ece3802..d64863ed73 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/logger_provider.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/processor.h" +#include "opentelemetry/sdk/logs/logger_provider.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/processor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -127,4 +125,3 @@ bool LoggerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc index 167d6cbf65..76e662a909 100644 --- a/sdk/src/logs/logger_provider_factory.cc +++ b/sdk/src/logs/logger_provider_factory.cc @@ -1,12 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/logger_provider_factory.h" -# include "opentelemetry/sdk/logs/logger_context.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/logger_context.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/resource/resource.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -57,4 +55,3 @@ std::unique_ptr LoggerProviderFactory::Crea } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/multi_log_record_processor.cc b/sdk/src/logs/multi_log_record_processor.cc index f6e6c2e176..c0b3eb1ec6 100644 --- a/sdk/src/logs/multi_log_record_processor.cc +++ b/sdk/src/logs/multi_log_record_processor.cc @@ -1,11 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/multi_log_record_processor.h" -# include "opentelemetry/sdk/logs/multi_recordable.h" -# include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/logs/multi_log_record_processor.h" +#include "opentelemetry/sdk/logs/multi_recordable.h" +#include "opentelemetry/sdk/logs/recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -147,4 +145,3 @@ bool MultiLogRecordProcessor::Shutdown(std::chrono::microseconds timeout) noexce } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/multi_log_record_processor_factory.cc b/sdk/src/logs/multi_log_record_processor_factory.cc index 3e0de46c32..ab49689ca0 100644 --- a/sdk/src/logs/multi_log_record_processor_factory.cc +++ b/sdk/src/logs/multi_log_record_processor_factory.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/multi_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/multi_log_record_processor.h" -# include "opentelemetry/sdk/logs/multi_log_record_processor_factory.h" -# include "opentelemetry/sdk/logs/multi_log_record_processor.h" - -# include -# include -# include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -27,4 +25,3 @@ std::unique_ptr MultiLogRecordProcessorFactory::Create( } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/multi_recordable.cc b/sdk/src/logs/multi_recordable.cc index c1e335ead2..7d80259f27 100644 --- a/sdk/src/logs/multi_recordable.cc +++ b/sdk/src/logs/multi_recordable.cc @@ -1,13 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/multi_recordable.h" -# include "opentelemetry/sdk/logs/multi_recordable.h" - -# include -# include -# include +#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -185,4 +183,3 @@ void MultiRecordable::SetInstrumentationScope( } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/read_write_log_record.cc b/sdk/src/logs/read_write_log_record.cc index f45c20adff..e6dea3d9e4 100644 --- a/sdk/src/logs/read_write_log_record.cc +++ b/sdk/src/logs/read_write_log_record.cc @@ -1,12 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include - -# include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/read_write_log_record.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -189,4 +187,3 @@ void ReadWriteLogRecord::SetInstrumentationScope( } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/readable_log_record.cc b/sdk/src/logs/readable_log_record.cc index f02d475d47..80493354e3 100644 --- a/sdk/src/logs/readable_log_record.cc +++ b/sdk/src/logs/readable_log_record.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/readable_log_record.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/version/version.h" -# include "opentelemetry/sdk/logs/readable_log_record.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/sdk/version/version.h" - -# include -# include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -51,4 +49,3 @@ const opentelemetry::sdk::resource::Resource &ReadableLogRecord::GetDefaultResou } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/simple_log_record_processor.cc b/sdk/src/logs/simple_log_record_processor.cc index 2c33739bef..68f90e83ab 100644 --- a/sdk/src/logs/simple_log_record_processor.cc +++ b/sdk/src/logs/simple_log_record_processor.cc @@ -1,14 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#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 "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 OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -76,4 +74,3 @@ bool SimpleLogRecordProcessor::IsShutdown() const noexcept } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/src/logs/simple_log_record_processor_factory.cc b/sdk/src/logs/simple_log_record_processor_factory.cc index 213f61e16c..6146efc174 100644 --- a/sdk/src/logs/simple_log_record_processor_factory.cc +++ b/sdk/src/logs/simple_log_record_processor_factory.cc @@ -1,10 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -22,4 +20,3 @@ std::unique_ptr SimpleLogRecordProcessorFactory::Create( } // namespace logs } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/test/CMakeLists.txt b/sdk/test/CMakeLists.txt index 5c2ce0d288..33dd07f81a 100644 --- a/sdk/test/CMakeLists.txt +++ b/sdk/test/CMakeLists.txt @@ -4,8 +4,6 @@ add_subdirectory(common) add_subdirectory(trace) add_subdirectory(metrics) -if(WITH_LOGS_PREVIEW) - add_subdirectory(logs) -endif() +add_subdirectory(logs) add_subdirectory(resource) add_subdirectory(instrumentationscope) diff --git a/sdk/test/logs/batch_log_record_processor_test.cc b/sdk/test/logs/batch_log_record_processor_test.cc index 41ae2c5123..33db0da479 100644 --- a/sdk/test/logs/batch_log_record_processor_test.cc +++ b/sdk/test/logs/batch_log_record_processor_test.cc @@ -1,16 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/recordable.h" -# 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 using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -341,4 +339,3 @@ TEST_F(BatchLogRecordProcessorTest, TestScheduledDelayMillis) EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetBody()); } } -#endif diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 4f7deb06d0..689ca7f8ed 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -1,22 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include +#include +#include -# include -# include -# include -# include +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/provider.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_id.h" -# include "opentelemetry/logs/logger.h" -# include "opentelemetry/logs/provider.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_id.h" - -# include +#include using opentelemetry::sdk::logs::ReadWriteLogRecord; namespace trace_api = opentelemetry::trace; @@ -322,5 +320,3 @@ TEST(LogBody, BodyConversation) } } } - -#endif diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index c6b8dec372..51f40178ba 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -1,22 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#include +#include -# include -# include +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.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_provider.h" +#include "opentelemetry/sdk/logs/recordable.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.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_provider.h" -# include "opentelemetry/sdk/logs/recordable.h" -# include "opentelemetry/sdk/logs/simple_log_record_processor.h" - -# include +#include using namespace opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; @@ -191,5 +189,3 @@ TEST(LoggerProviderSDK, ForceFlush) EXPECT_TRUE(lp.ForceFlush()); } - -#endif diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 66f9edb8c5..62d523b92a 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -1,26 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW - -# include -# include - -# include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/nostd/string_view.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/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/tracer.h" - -# include +#include +#include + +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/nostd/string_view.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/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/tracer.h" + +#include using namespace opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; @@ -288,5 +286,3 @@ TEST(LoggerSDK, EventLog) ASSERT_EQ(shared_recordable->GetEventName(), "otel-cpp.event_name"); ASSERT_EQ(shared_recordable->GetEventDomain(), "otel-cpp.event_domain"); } - -#endif diff --git a/sdk/test/logs/simple_log_record_processor_test.cc b/sdk/test/logs/simple_log_record_processor_test.cc index 7d45cc85c2..484cc63e71 100644 --- a/sdk/test/logs/simple_log_record_processor_test.cc +++ b/sdk/test/logs/simple_log_record_processor_test.cc @@ -1,17 +1,15 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_LOGS_PREVIEW +#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 "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 using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -243,5 +241,3 @@ TEST(SimpleLogRecordProcessorTest, ForceFlushFail) // Expect failure result when exporter fails to force flush EXPECT_EQ(false, processor.ForceFlush()); } - -#endif From b7fd057185c4ed2dff507b859cbe058b7609fb4a Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 1 Aug 2023 15:41:28 -0700 Subject: [PATCH 051/119] remove extra includes (#2252) --- exporters/ostream/test/ostream_log_test.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 064cd1103a..887495f892 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -1,15 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/ostream/log_record_exporter.h" -#include "opentelemetry/logs/provider.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -#include "opentelemetry/sdk/logs/logger_provider.h" -#include "opentelemetry/sdk/logs/read_write_log_record.h" -#include "opentelemetry/sdk/logs/simple_log_record_processor.h" -#include "opentelemetry/sdk/version/version.h" - #include "opentelemetry/exporters/ostream/log_record_exporter.h" #include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" #include "opentelemetry/logs/provider.h" From 0d1326a02e5ecb19f2aca0b98dfb7be266376049 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Sat, 12 Aug 2023 05:56:50 +0800 Subject: [PATCH 052/119] Support protobuf 3.22 or upper (#2163) --- .github/workflows/ci.yml | 32 ++ CHANGELOG.md | 2 + CMakeLists.txt | 55 ++- api/BUILD | 1 + api/CMakeLists.txt | 2 - ci/do_ci.sh | 60 ++- ci/install_abseil.sh | 20 +- ci/install_protobuf.sh | 45 ++- ci/setup_grpc.sh | 69 +++- cmake/opentelemetry-proto.cmake | 128 ++++--- ...{proto-options-patch.cmake => tools.cmake} | 2 +- examples/grpc/CMakeLists.txt | 17 +- exporters/otlp/BUILD | 2 + exporters/otlp/CMakeLists.txt | 18 +- exporters/otlp/src/otlp_http_client.cc | 25 +- sdk/include/opentelemetry/sdk/common/base64.h | 36 ++ sdk/src/common/BUILD | 13 + sdk/src/common/CMakeLists.txt | 7 +- sdk/src/common/base64.cc | 351 ++++++++++++++++++ sdk/test/common/BUILD | 22 ++ sdk/test/common/CMakeLists.txt | 11 + sdk/test/common/base64_benchmark.cc | 49 +++ sdk/test/common/base64_test.cc | 92 +++++ 23 files changed, 895 insertions(+), 164 deletions(-) rename cmake/{proto-options-patch.cmake => tools.cmake} (98%) create mode 100644 sdk/include/opentelemetry/sdk/common/base64.h create mode 100644 sdk/src/common/base64.cc create mode 100644 sdk/test/common/base64_benchmark.cc create mode 100644 sdk/test/common/base64_test.cc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff33aa46e3..39207e214c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -284,6 +284,7 @@ jobs: env: CC: /usr/bin/gcc-4.8 CXX: /usr/bin/g++-4.8 + CXX_STANDARD: '11' run: ./ci/do_ci.sh cmake.legacy.test cmake_gcc_48_otlp_exporter_test: @@ -329,8 +330,12 @@ jobs: sudo -E ./ci/setup_ci_environment.sh sudo -E ./ci/setup_cmake.sh - name: run tests + env: + CXX_STANDARD: '20' run: ./ci/do_ci.sh cmake.c++20.test - name: run tests (enable stl) + env: + CXX_STANDARD: '20' run: ./ci/do_ci.sh cmake.c++20.stl.test cmake_test_cxx20_clang: @@ -354,12 +359,14 @@ jobs: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" + CXX_STANDARD: '20' run: ./ci/do_ci.sh cmake.c++20.test - name: run tests (enable stl) env: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" + CXX_STANDARD: '20' run: ./ci/do_ci.sh cmake.c++20.stl.test cmake_otprotocol_test: @@ -378,6 +385,31 @@ jobs: sudo ./ci/setup_grpc.sh ./ci/do_ci.sh cmake.exporter.otprotocol.test + cmake_modern_protobuf_grpc_with_abseil_test: + name: CMake test (with modern protobuf,grpc and abseil) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + env: + PROTOBUF_VERSION: '23.3' + ABSEIL_CPP_VERSION: '20230125.3' + CXX_STANDARD: '14' + run: | + sudo ./ci/setup_cmake.sh + sudo ./ci/setup_ci_environment.sh + sudo -E ./ci/install_abseil.sh + sudo -E ./ci/install_protobuf.sh + - name: run otlp exporter tests + env: + 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_do_not_install_test: name: CMake do not install test (with otlp-exporter) runs-on: ubuntu-20.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e95bd0fb0..8b28715280 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* [EXPORTER] Support protobuf 3.22 or upper + [#2163](https://github.com/open-telemetry/opentelemetry-cpp/pull/2163) * [SDK] Mark logs signal as stable API/SDK [#2229](https://github.com/open-telemetry/opentelemetry-cpp/pull/2229) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cd71503cf..dcf1034804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ project(opentelemetry-cpp) # Mark variables as used so cmake doesn't complain about them mark_as_advanced(CMAKE_TOOLCHAIN_FILE) +# Prefer cmake CONFIG to auto resolve dependencies. +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) + # Don't use customized cmake modules if vcpkg is used to resolve dependence. if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") @@ -125,6 +128,8 @@ endif() option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets" ${OPENTELEMETRY_INSTALL_default}) +include("${PROJECT_SOURCE_DIR}/cmake/tools.cmake") + if(NOT DEFINED CMAKE_CXX_STANDARD) if(WITH_STL) # Require at least C++17. C++20 is needed to avoid gsl::span @@ -340,9 +345,21 @@ if(WITH_PROMETHEUS) endif() endif() +if(WITH_ABSEIL) + find_package(absl CONFIG REQUIRED) +endif() + if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) - set(protobuf_MODULE_COMPATIBLE ON) find_package(Protobuf) + if(Protobuf_VERSION AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0") + if(NOT WITH_ABSEIL) + message( + FATAL_ERROR + "Protobuf 3.22 or upper require abseil-cpp(Recommended version: 20230125 or upper)" + ) + endif() + endif() + if(WITH_OTLP_GRPC) find_package(gRPC) endif() @@ -372,10 +389,14 @@ if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) ) endif() endif() - # Latest Protobuf uses mixed case instead of uppercase - if(Protobuf_PROTOC_EXECUTABLE) - set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE}) - endif() + endif() + # Latest Protobuf imported targets and without legacy module support + if(TARGET protobuf::protoc) + project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE + protobuf::protoc) + elseif(Protobuf_PROTOC_EXECUTABLE) + # Some versions of FindProtobuf.cmake uses mixed case instead of uppercase + set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE}) endif() include(CMakeDependentOption) @@ -524,10 +545,14 @@ if(BUILD_TESTING) set(GTEST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googletest/include ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/googlemock/include) - set(GTEST_BOTH_LIBRARIES - ${CMAKE_BINARY_DIR}/lib/libgtest.a - ${CMAKE_BINARY_DIR}/lib/libgtest_main.a - ${CMAKE_BINARY_DIR}/lib/libgmock.a) + if(TARGET gtest) + set(GTEST_BOTH_LIBRARIES gtest gtest_main gmock) + else() + set(GTEST_BOTH_LIBRARIES + ${CMAKE_BINARY_DIR}/lib/libgtest.a + ${CMAKE_BINARY_DIR}/lib/libgtest_main.a + ${CMAKE_BINARY_DIR}/lib/libgmock.a) + endif() elseif(WIN32) # Make sure we are always bootsrapped with vcpkg on Windows find_package(GTest) @@ -540,7 +565,17 @@ if(BUILD_TESTING) # Prefer GTest installed by OS distro, brew or vcpkg package manager find_package(GTest REQUIRED) endif() - include_directories(SYSTEM ${GTEST_INCLUDE_DIRS}) + if(NOT GTEST_BOTH_LIBRARIES) + # New GTest package names + if(TARGET GTest::gtest) + set(GTEST_BOTH_LIBRARIES GTest::gtest GTest::gtest_main GTest::gmock) + elseif(TARGET GTest::GTest) + set(GTEST_BOTH_LIBRARIES GTest::GTest GTest::Main) + endif() + endif() + if(GTEST_INCLUDE_DIRS) + include_directories(SYSTEM ${GTEST_INCLUDE_DIRS}) + endif() message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}") message("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}") enable_testing() diff --git a/api/BUILD b/api/BUILD index 421d26a626..e650d5f7ce 100644 --- a/api/BUILD +++ b/api/BUILD @@ -22,6 +22,7 @@ cc_library( deps = select({ ":with_external_abseil": [ "@com_google_absl//absl/base", + "@com_google_absl//absl/strings", "@com_google_absl//absl/types:variant", ], "//conditions:default": [], diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 8a2788ed17..9e32cd24ed 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -42,8 +42,6 @@ endif() if(WITH_ABSEIL) - find_package(absl CONFIG REQUIRED) - target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) target_link_libraries( opentelemetry_api INTERFACE absl::bad_variant_access absl::any absl::base diff --git a/ci/do_ci.sh b/ci/do_ci.sh index fce868e37f..c445e0abcd 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -83,13 +83,19 @@ BAZEL_MACOS_TEST_OPTIONS="$BAZEL_MACOS_OPTIONS --test_output=errors" BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel" +CMAKE_OPTIONS=(-DCMAKE_BUILD_TYPE=Debug) +if [ ! -z "${CXX_STANDARD}" ]; then + CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +else + CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=14") +fi + export CTEST_OUTPUT_ON_FAILURE=1 if [[ "$1" == "cmake.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ @@ -102,8 +108,7 @@ if [[ "$1" == "cmake.test" ]]; then elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -126,8 +131,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then elif [[ "$1" == "cmake.maintainer.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ @@ -150,7 +154,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_STANDARD=11 \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ @@ -173,8 +177,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_PROMETHEUS=ON \ -DWITH_ZIPKIN=ON \ -DWITH_ELASTICSEARCH=ON \ @@ -188,8 +191,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then elif [[ "$1" == "cmake.abseil.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -201,8 +203,7 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \ -DWITH_OPENTRACING=ON \ "${SRC_DIR}" @@ -212,8 +213,7 @@ elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then elif [[ "$1" == "cmake.c++20.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=20 \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ ${IWYU} \ @@ -224,8 +224,7 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then elif [[ "$1" == "cmake.c++20.stl.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=20 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -240,8 +239,7 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then rm -rf * export BUILD_ROOT="${BUILD_DIR}" ${SRC_DIR}/tools/build-benchmark.sh - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=11 \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ "${SRC_DIR}" make -j $(nproc) @@ -252,7 +250,7 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then rm -rf * export BUILD_ROOT="${BUILD_DIR}" ${SRC_DIR}/tools/build-benchmark.sh - cmake -DCMAKE_BUILD_TYPE=Debug \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_STANDARD=11 \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ @@ -267,8 +265,10 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + if [[ ! -z "${WITH_ABSEIL}" ]]; then + CMAKE_OPTIONS=(${CMAKE_OPTIONS[@]} "-DWITH_ABSEIL=${WITH_ABSEIL}") + fi + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \ @@ -282,8 +282,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DBUILD_SHARED_LIBS=ON \ @@ -297,8 +296,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.shared_libs.with_static_grpc.test" ]] elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -312,8 +310,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then elif [[ "$1" == "cmake.do_not_install.test" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DWITH_OTLP_GRPC=ON \ -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ @@ -346,7 +343,7 @@ EOF -static-libgcc \ -Wl,--version-script=${PWD}/export.map \ " - cmake -DCMAKE_BUILD_TYPE=Debug \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" \ -DCMAKE_SHARED_LINKER_FLAGS="$LINKER_FLAGS" \ @@ -357,7 +354,7 @@ EOF # Verify we can load the plugin cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ "${SRC_DIR}" make load_plugin_example @@ -439,8 +436,7 @@ elif [[ "$1" == "format" ]]; then elif [[ "$1" == "code.coverage" ]]; then cd "${BUILD_DIR}" rm -rf * - cmake -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_STANDARD=14 \ + cmake ${CMAKE_OPTIONS[@]} \ -DCMAKE_CXX_FLAGS="-Werror --coverage $CXXFLAGS" \ "${SRC_DIR}" make diff --git a/ci/install_abseil.sh b/ci/install_abseil.sh index 7764b4d815..3bc69df89d 100755 --- a/ci/install_abseil.sh +++ b/ci/install_abseil.sh @@ -3,19 +3,27 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -set -e +set -ex export DEBIAN_FRONTEND=noninteractive +[ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20220623.1" BUILD_DIR=/tmp/ INSTALL_DIR=/usr/local/ -TAG=20220623.1 pushd $BUILD_DIR -git clone --depth=1 -b ${TAG} https://github.com/abseil/abseil-cpp.git +git clone --depth=1 -b ${ABSEIL_CPP_VERSION} https://github.com/abseil/abseil-cpp.git cd abseil-cpp +ABSEIL_CPP_BUILD_OPTIONS=( + "-DBUILD_TESTING=OFF" + "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" + "-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR" +) + +if [ ! -z "${CXX_STANDARD}" ]; then + ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +fi + mkdir build && pushd build -cmake -DBUILD_TESTING=OFF -DCMAKE_CXX_STANDARD=11 \ - -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ - .. +cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} .. make -j $(nproc) make install popd diff --git a/ci/install_protobuf.sh b/ci/install_protobuf.sh index dde94111e1..3fb18e7c85 100755 --- a/ci/install_protobuf.sh +++ b/ci/install_protobuf.sh @@ -31,12 +31,41 @@ set -e # when calling this script # -export CPP_PROTOBUF_VERSION="3.${PROTOBUF_VERSION}" - -cd / -wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${CPP_PROTOBUF_VERSION}.tar.gz -tar zxf protobuf-cpp-${CPP_PROTOBUF_VERSION}.tar.gz --no-same-owner -cd protobuf-${CPP_PROTOBUF_VERSION} -./configure -make -j $(nproc) && make install +CPP_PROTOBUF_BUILD_OPTIONS=( + "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" + "-Dprotobuf_BUILD_TESTS=OFF" + "-Dprotobuf_BUILD_EXAMPLES=OFF" +) + +if [ ! -z "${CXX_STANDARD}" ]; then + CPP_PROTOBUF_BUILD_OPTIONS=(${CPP_PROTOBUF_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +fi + +# After protobuf 22/4.22, protobuf depends on absl and we can use +# "-Dprotobuf_ABSL_PROVIDER=package" to tell protobuf to find absl from the +# system. Otherwise, it will build absl from source. +# 4.XX.YY and 3.XX.YY are alias of XX.YY, and source pacakges are moved into the +# tag of XX.YY and without -cpp suffix from protobuf v22. +if [[ ${PROTOBUF_VERSION/.*/} -ge 22 ]]; then + export CPP_PROTOBUF_VERSION="${PROTOBUF_VERSION}" + CPP_PROTOBUF_PACKAGE_NAME="protobuf-${CPP_PROTOBUF_VERSION}" + CPP_PROTOBUF_BUILD_OPTIONS=(${CPP_PROTOBUF_BUILD_OPTIONS[@]} "-Dprotobuf_ABSL_PROVIDER=package") +else + export CPP_PROTOBUF_VERSION="3.${PROTOBUF_VERSION}" + CPP_PROTOBUF_PACKAGE_NAME="protobuf-cpp-${CPP_PROTOBUF_VERSION}" +fi + +cd /tmp +wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${CPP_PROTOBUF_PACKAGE_NAME}.tar.gz +tar zxf ${CPP_PROTOBUF_PACKAGE_NAME}.tar.gz --no-same-owner + +mkdir protobuf-${CPP_PROTOBUF_VERSION}/build && pushd protobuf-${CPP_PROTOBUF_VERSION}/build +if [ -e "../CMakeLists.txt" ]; then + cmake .. ${CPP_PROTOBUF_BUILD_OPTIONS[@]} +else + cmake ../cmake ${CPP_PROTOBUF_BUILD_OPTIONS[@]} +fi +cmake --build . -j $(nproc) +cmake --install . +popd ldconfig diff --git a/ci/setup_grpc.sh b/ci/setup_grpc.sh index e1002b6616..9cab7e77fe 100755 --- a/ci/setup_grpc.sh +++ b/ci/setup_grpc.sh @@ -7,24 +7,57 @@ set -e export DEBIAN_FRONTEND=noninteractive old_grpc_version='v1.33.2' new_grpc_version='v1.49.2' +modern_grpc_version='v1.55.0' gcc_version_for_new_grpc='5.1' std_version='14' +if [ ! -z "${CXX_STANDARD}" ]; then + std_version="${CXX_STANDARD}" +fi install_grpc_version=${new_grpc_version} install_dir='/usr/local/' build_shared_libs='' -usage() { echo "Usage: $0 [-v ] [-i "] 1>&2; exit 1;} +build_internal_abseil_cpp=1 +GRPC_BUILD_OPTIONS=() +usage() { + echo "Usage: $0 [options...]" 1>&2; + echo "Available options:" 1>&2; + echo " -v Set GCC version" 1>&2; + echo " -h Show help message and exit" 1>&2; + echo " -i Set installation prefix" 1>&2; + echo " -m Use the modern gRPC version" 1>&2; + echo " -p Let gRPC find protobuf or abseil-cpp by CONFIG package" 1>&2; + echo " -r Specify the version of gRPC" 1>&2; + echo " -s Specify std version(CMAKE_CXX_STANDARD)" 1>&2; + echo " -T Build static libraries" 1>&2; + echo " -H Build shared libraries" 1>&2; +} -while getopts ":v:i:r:s:TH" o; do +while getopts ":v:hi:mp:r:s:TH" o; do case "${o}" in v) gcc_version=${OPTARG} ;; + h) + usage + exit 0; + ;; i) install_dir=${OPTARG} ;; + p) + if [ "${OPTARG}" == "protobuf" ]; then + GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DgRPC_PROTOBUF_PROVIDER=package") + elif [ "${OPTARG}" == "abseil-cpp" ]; then + GRPC_BUILD_OPTIONS=(${GRPC_BUILD_OPTIONS[@]} "-DgRPC_ABSL_PROVIDER=package") + build_internal_abseil_cpp=0 + fi + ;; r) install_grpc_version=${OPTARG} ;; + m) + install_grpc_version=${modern_grpc_version} + ;; s) std_version=${OPTARG} ;; @@ -36,14 +69,16 @@ while getopts ":v:i:r:s:TH" o; do ;; *) usage + exit 1; ;; esac done + if [ -z "${gcc_version}" ]; then gcc_version=`gcc --version | awk '/gcc/ {print $NF}'` fi -if [[ "${gcc_version}" < "${gcc_version_for_new_grpc}" ]]; then - echo "less" +if [[ "${gcc_version}" < "${gcc_version_for_new_grpc}" ]] && [[ "${gcc_version:1:1}" == "." ]]; then + echo "${gcc_version} less than ${gcc_version_for_new_grpc}" std_version='11' install_grpc_version=${old_grpc_version} fi @@ -59,22 +94,26 @@ git clone --depth=1 -b ${install_grpc_version} https://github.com/grpc/grpc pushd grpc git submodule init git submodule update --depth 1 -mkdir -p "third_party/abseil-cpp/build" && pushd "third_party/abseil-cpp/build" -set -x -ABSEIL_CPP_BUILD_OPTIONS=( - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE - -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -) -if [ ! -z "$build_shared_libs" ]; then - ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs") +if [[ $build_internal_abseil_cpp -ne 0 ]]; then + mkdir -p "third_party/abseil-cpp/build" && pushd "third_party/abseil-cpp/build" + set -x + + ABSEIL_CPP_BUILD_OPTIONS=( + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE + -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR + ) + if [ ! -z "$build_shared_libs" ]; then + ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs") + fi + cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} .. + cmake --build . -j${nproc} --target install && popd fi -cmake ${ABSEIL_CPP_BUILD_OPTIONS[@]} .. -cmake --build . -j${nproc} --target install && popd mkdir -p build && pushd build GRPC_BUILD_OPTIONS=( + ${GRPC_BUILD_OPTIONS[@]} -DgRPC_INSTALL=ON -DCMAKE_CXX_STANDARD=${std_version} -DgRPC_BUILD_TESTS=OFF diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 07238ba041..4d64a8479c 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -65,8 +65,6 @@ else() endif() endif() -include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake) - set(COMMON_PROTO "${PROTO_PATH}/opentelemetry/proto/common/v1/common.proto") set(RESOURCE_PROTO "${PROTO_PATH}/opentelemetry/proto/resource/v1/resource.proto") @@ -169,64 +167,76 @@ if(WITH_OTLP_GRPC) message(STATUS "gRPC_CPP_PLUGIN_EXECUTABLE=${gRPC_CPP_PLUGIN_EXECUTABLE}") endif() +set(PROTOBUF_COMMON_FLAGS "--proto_path=${PROTO_PATH}" + "--cpp_out=${GENERATED_PROTOBUF_PATH}") +# --experimental_allow_proto3_optional is available from 3.13 and be stable and +# enabled by default from 3.16 +if(Protobuf_VERSION AND Protobuf_VERSION VERSION_LESS "3.16") + list(APPEND PROTOBUF_COMMON_FLAGS "--experimental_allow_proto3_optional") +elseif(PROTOBUF_VERSION AND PROTOBUF_VERSION VERSION_LESS "3.16") + list(APPEND PROTOBUF_COMMON_FLAGS "--experimental_allow_proto3_optional") +endif() + +set(PROTOBUF_GENERATED_FILES + ${COMMON_PB_H_FILE} + ${COMMON_PB_CPP_FILE} + ${RESOURCE_PB_H_FILE} + ${RESOURCE_PB_CPP_FILE} + ${TRACE_PB_H_FILE} + ${TRACE_PB_CPP_FILE} + ${LOGS_PB_H_FILE} + ${LOGS_PB_CPP_FILE} + ${METRICS_PB_H_FILE} + ${METRICS_PB_CPP_FILE} + ${TRACE_SERVICE_PB_H_FILE} + ${TRACE_SERVICE_PB_CPP_FILE} + ${LOGS_SERVICE_PB_H_FILE} + ${LOGS_SERVICE_PB_CPP_FILE} + ${METRICS_SERVICE_PB_H_FILE} + ${METRICS_SERVICE_PB_CPP_FILE}) + if(WITH_OTLP_GRPC) - add_custom_command( - OUTPUT ${COMMON_PB_H_FILE} - ${COMMON_PB_CPP_FILE} - ${RESOURCE_PB_H_FILE} - ${RESOURCE_PB_CPP_FILE} - ${TRACE_PB_H_FILE} - ${TRACE_PB_CPP_FILE} - ${LOGS_PB_H_FILE} - ${LOGS_PB_CPP_FILE} - ${METRICS_PB_H_FILE} - ${METRICS_PB_CPP_FILE} - ${TRACE_SERVICE_PB_H_FILE} - ${TRACE_SERVICE_PB_CPP_FILE} - ${TRACE_SERVICE_GRPC_PB_H_FILE} - ${TRACE_SERVICE_GRPC_PB_CPP_FILE} - ${LOGS_SERVICE_PB_H_FILE} - ${LOGS_SERVICE_PB_CPP_FILE} - ${LOGS_SERVICE_GRPC_PB_H_FILE} - ${LOGS_SERVICE_GRPC_PB_CPP_FILE} - ${METRICS_SERVICE_PB_H_FILE} - ${METRICS_SERVICE_PB_CPP_FILE} - ${METRICS_SERVICE_GRPC_PB_H_FILE} - ${METRICS_SERVICE_GRPC_PB_CPP_FILE} - COMMAND - ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional" - "--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS} - "--cpp_out=${GENERATED_PROTOBUF_PATH}" - "--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}" - --plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${COMMON_PROTO} - ${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO} - ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO}) -else() - add_custom_command( - OUTPUT ${COMMON_PB_H_FILE} - ${COMMON_PB_CPP_FILE} - ${RESOURCE_PB_H_FILE} - ${RESOURCE_PB_CPP_FILE} - ${TRACE_PB_H_FILE} - ${TRACE_PB_CPP_FILE} - ${LOGS_PB_H_FILE} - ${LOGS_PB_CPP_FILE} - ${METRICS_PB_H_FILE} - ${METRICS_PB_CPP_FILE} - ${TRACE_SERVICE_PB_H_FILE} - ${TRACE_SERVICE_PB_CPP_FILE} - ${LOGS_SERVICE_PB_H_FILE} - ${LOGS_SERVICE_PB_CPP_FILE} - ${METRICS_SERVICE_PB_H_FILE} - ${METRICS_SERVICE_PB_CPP_FILE} - COMMAND - ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional" - "--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS} - "--cpp_out=${GENERATED_PROTOBUF_PATH}" ${COMMON_PROTO} ${RESOURCE_PROTO} - ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} - ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO}) + list(APPEND PROTOBUF_COMMON_FLAGS + "--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}" + --plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}") + + list( + APPEND + PROTOBUF_GENERATED_FILES + ${TRACE_SERVICE_GRPC_PB_H_FILE} + ${TRACE_SERVICE_GRPC_PB_CPP_FILE} + ${LOGS_SERVICE_GRPC_PB_H_FILE} + ${LOGS_SERVICE_GRPC_PB_CPP_FILE} + ${METRICS_SERVICE_GRPC_PB_H_FILE} + ${METRICS_SERVICE_GRPC_PB_CPP_FILE}) endif() +set(PROTOBUF_RUN_PROTOC_COMMAND "\"${PROTOBUF_PROTOC_EXECUTABLE}\"") +foreach( + PROTOBUF_RUN_PROTOC_ARG + ${PROTOBUF_COMMON_FLAGS} + ${PROTOBUF_INCLUDE_FLAGS} + ${COMMON_PROTO} + ${RESOURCE_PROTO} + ${TRACE_PROTO} + ${LOGS_PROTO} + ${METRICS_PROTO} + ${TRACE_SERVICE_PROTO} + ${LOGS_SERVICE_PROTO} + ${METRICS_SERVICE_PROTO}) + set(PROTOBUF_RUN_PROTOC_COMMAND + "${PROTOBUF_RUN_PROTOC_COMMAND} \"${PROTOBUF_RUN_PROTOC_ARG}\"") +endforeach() + +add_custom_command( + OUTPUT ${PROTOBUF_GENERATED_FILES} + COMMAND + ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTOBUF_COMMON_FLAGS} + ${PROTOBUF_INCLUDE_FLAGS} ${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO} + ${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} + ${METRICS_SERVICE_PROTO} + COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}") + include_directories("${GENERATED_PROTOBUF_PATH}") unset(OTELCPP_PROTO_TARGET_OPTIONS) @@ -251,6 +261,10 @@ add_library( ${LOGS_SERVICE_PB_CPP_FILE} ${METRICS_SERVICE_PB_CPP_FILE}) +if(WITH_ABSEIL) + target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access) +endif() + if(WITH_OTLP_GRPC) add_library( opentelemetry_proto_grpc diff --git a/cmake/proto-options-patch.cmake b/cmake/tools.cmake similarity index 98% rename from cmake/proto-options-patch.cmake rename to cmake/tools.cmake index 97872050c9..345fc88ff7 100644 --- a/cmake/proto-options-patch.cmake +++ b/cmake/tools.cmake @@ -14,7 +14,7 @@ endmacro() if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET) if(MSVC) unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) - set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309) + set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309 /wd4668 /wd4946 /wd6001 /wd6244 /wd6246) if(MSVC_VERSION GREATER_EQUAL 1922) # see diff --git a/examples/grpc/CMakeLists.txt b/examples/grpc/CMakeLists.txt index 1ea1c9bee5..938a009e0a 100644 --- a/examples/grpc/CMakeLists.txt +++ b/examples/grpc/CMakeLists.txt @@ -23,7 +23,6 @@ add_custom_command( add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs} ${example_proto_srcs} ${example_proto_hdrs}) -include(${PROJECT_SOURCE_DIR}/cmake/proto-options-patch.cmake) patch_protobuf_targets(example_grpc_proto) include_directories( @@ -33,16 +32,20 @@ include_directories( include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(TARGET protobuf::libprotobuf) - target_link_libraries(example_grpc_proto gRPC::grpc++ protobuf::libprotobuf) + target_link_libraries(example_grpc_proto PUBLIC gRPC::grpc++ + protobuf::libprotobuf) else() - target_include_directories(example_grpc_proto ${Protobuf_INCLUDE_DIRS}) - target_link_libraries(example_grpc_proto ${Protobuf_LIBRARIES}) + target_include_directories(example_grpc_proto PUBLIC ${Protobuf_INCLUDE_DIRS}) + target_link_libraries(example_grpc_proto PUBLIC gRPC::grpc++ + ${Protobuf_LIBRARIES}) +endif() +if(WITH_ABSEIL) + target_link_libraries(example_grpc_proto PUBLIC absl::bad_variant_access) endif() foreach(_target client server) add_executable(${_target} "${_target}.cc") - target_link_libraries( - ${_target} example_grpc_proto protobuf::libprotobuf gRPC::grpc++ - opentelemetry_trace opentelemetry_exporter_ostream_span) + target_link_libraries(${_target} example_grpc_proto opentelemetry_trace + opentelemetry_exporter_ostream_span) patch_protobuf_targets(${_target}) endforeach() diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 5e52bfd393..5099b43510 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -131,7 +131,9 @@ cc_library( "//api", "//ext/src/http/client/curl:http_client_curl", "//sdk:headers", + "//sdk/src/common:base64", "@com_github_opentelemetry_proto//:common_proto_cc", + "@com_google_absl//absl/strings", "@github_nlohmann_json//:json", ], ) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 44715c1753..8a93d34acc 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -114,6 +114,10 @@ if(WITH_OTLP_HTTP) PUBLIC opentelemetry_sdk opentelemetry_ext PRIVATE opentelemetry_proto opentelemetry_http_client_curl nlohmann_json::nlohmann_json) + if(TARGET absl::strings) + target_link_libraries(opentelemetry_exporter_otlp_http_client + PUBLIC absl::strings) + endif() if(nlohmann_json_clone) add_dependencies(opentelemetry_exporter_otlp_http_client nlohmann_json::nlohmann_json) @@ -221,7 +225,9 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_metrics_serialization_test) - if(MSVC) + if(NOT GMOCK_LIB AND TARGET GTest::gmock) + set(GMOCK_LIB GTest::gmock) + elseif(MSVC) # Explicitly specify that we consume GTest from shared library. The rest of # code logic below determines whether we link Release or Debug flavor of the # library. These flavors have different prefix on Windows, gmock and gmockd @@ -234,10 +240,12 @@ if(BUILD_TESTING) unset(GMOCK_LIB CACHE) endif() endif() - if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug") - find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib) - else() - find_library(GMOCK_LIB gmock PATH_SUFFIXES lib) + if(NOT GMOCK_LIB) + if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug") + find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib) + else() + find_library(GMOCK_LIB gmock PATH_SUFFIXES lib) + endif() endif() if(WITH_OTLP_GRPC) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index a249a842ad..c6bc1e1122 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -17,30 +17,19 @@ #include "google/protobuf/message.h" #include "google/protobuf/reflection.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/stringpiece.h" #include "nlohmann/json.hpp" -#if defined(GOOGLE_PROTOBUF_VERSION) && GOOGLE_PROTOBUF_VERSION >= 3007000 -# include "google/protobuf/stubs/strutil.h" -#else -# include "google/protobuf/stubs/port.h" -namespace google -{ -namespace protobuf -{ -LIBPROTOBUF_EXPORT void Base64Escape(StringPiece src, std::string *dest); -} // namespace protobuf -} // namespace google -#endif - #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/base64.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk_config.h" #include #include +#include #include #include #include @@ -411,16 +400,12 @@ static std::string BytesMapping(const std::string &bytes, } else { - std::string base64_value; - google::protobuf::Base64Escape(bytes, &base64_value); - return base64_value; + return opentelemetry::sdk::common::Base64Escape(bytes); } } case JsonBytesMappingKind::kBase64: { // Base64 is the default bytes mapping of protobuf - std::string base64_value; - google::protobuf::Base64Escape(bytes, &base64_value); - return base64_value; + return opentelemetry::sdk::common::Base64Escape(bytes); } case JsonBytesMappingKind::kHex: return HexEncode(bytes); diff --git a/sdk/include/opentelemetry/sdk/common/base64.h b/sdk/include/opentelemetry/sdk/common/base64.h new file mode 100644 index 0000000000..d88204675c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/common/base64.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/common/macros.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace common +{ +// Base64Escape() +// +// Encodes a `src` string into a base64-encoded 'dest' string with padding +// characters. This function conforms with RFC 4648 section 4 (base64) and RFC +// 2045. +OPENTELEMETRY_EXPORT void Base64Escape(opentelemetry::nostd::string_view src, std::string *dest); +OPENTELEMETRY_EXPORT std::string Base64Escape(opentelemetry::nostd::string_view src); + +// Base64Unescape() +// +// Converts a `src` string encoded in Base64 (RFC 4648 section 4) to its binary +// equivalent, writing it to a `dest` buffer, returning `true` on success. If +// `src` contains invalid characters, `dest` is cleared and returns `false`. +// If padding is included (note that `Base64Escape()` does produce it), it must +// be correct. In the padding, '=' are treated identically. +OPENTELEMETRY_EXPORT bool Base64Unescape(opentelemetry::nostd::string_view src, std::string *dest); + +} // namespace common +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/common/BUILD b/sdk/src/common/BUILD index cdbd1955f3..fe75f08d7c 100644 --- a/sdk/src/common/BUILD +++ b/sdk/src/common/BUILD @@ -21,6 +21,19 @@ cc_library( ], ) +cc_library( + name = "base64", + srcs = [ + "base64.cc", + ], + include_prefix = "src/common", + deps = [ + "//api", + "//sdk:headers", + "//sdk/src/common/platform:fork", + ], +) + cc_library( name = "env_variables", srcs = [ diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index 7bb645f5b7..b0f44ac139 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -1,7 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -set(COMMON_SRCS random.cc core.cc global_log_handler.cc env_variables.cc) +set(COMMON_SRCS random.cc core.cc global_log_handler.cc env_variables.cc + base64.cc) if(WIN32) list(APPEND COMMON_SRCS platform/fork_windows.cc) else() @@ -17,6 +18,10 @@ target_link_libraries( opentelemetry_common PUBLIC opentelemetry_api opentelemetry_sdk Threads::Threads) +if(WITH_ABSEIL) + target_link_libraries(opentelemetry_common PUBLIC absl::strings) +endif() + if(OPENTELEMETRY_INSTALL) install( TARGETS opentelemetry_common diff --git a/sdk/src/common/base64.cc b/sdk/src/common/base64.cc new file mode 100644 index 0000000000..04a865ffe8 --- /dev/null +++ b/sdk/src/common/base64.cc @@ -0,0 +1,351 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/common/base64.h" + +#if defined(HAVE_GSL) +# include +#else +# include +#endif +#include +#include +#include + +#if defined(HAVE_ABSEIL) +# include "absl/strings/escaping.h" +#endif + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace common +{ +#if !defined(HAVE_ABSEIL) +namespace +{ +using Base64EscapeChars = const unsigned char[64]; +using Base64UnescapeChars = const unsigned char[128]; + +static constexpr Base64EscapeChars kBase64EscapeCharsBasic = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + +static constexpr Base64UnescapeChars kBase64UnescapeCharsBasic = { + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 62, 127, 127, 127, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 127, 127, 127, 127, 127, 127, 127, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 127, 127, 127, 127, + 127, 127, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 127, 127, 127, 127, 127}; + +static int Base64EscapeInternal(unsigned char *dest, + std::size_t dlen, + std::size_t *olen, + const unsigned char *src, + std::size_t slen, + Base64EscapeChars &base64_enc_map, + unsigned char padding_char) +{ + std::size_t i, n, nopadding; + int C1, C2, C3; + unsigned char *p; + + if (slen == 0) + { + *olen = 0; + return 0; + } + + n = (slen + 2) / 3; + + if (n > (std::numeric_limits::max() - 1) / 4) + { + *olen = std::numeric_limits::max(); + return -1; + } + + n *= 4; + + // no padding + if (0 == padding_char) + { + nopadding = slen % 3; + if (0 != nopadding) + { + n -= 3 - nopadding; + } + } + + if ((dlen < n + 1) || (nullptr == dest)) + { + *olen = n + 1; + return -1; + } + + n = (slen / 3) * 3; + + for (i = 0, p = dest; i < n; i += 3) + { + C1 = *src++; + C2 = *src++; + C3 = *src++; + + *p++ = base64_enc_map[(C1 >> 2) & 0x3F]; + *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F]; + *p++ = base64_enc_map[(((C2 & 15) << 2) + (C3 >> 6)) & 0x3F]; + *p++ = base64_enc_map[C3 & 0x3F]; + } + + if (i < slen) + { + C1 = *src++; + C2 = ((i + 1) < slen) ? *src++ : 0; + + *p++ = base64_enc_map[(C1 >> 2) & 0x3F]; + *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F]; + + if ((i + 1) < slen) + { + *p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F]; + } + else if (padding_char) + { + *p++ = padding_char; + } + + if (padding_char) + { + *p++ = padding_char; + } + } + + *olen = static_cast(p - dest); + *p = 0; + + return 0; +} + +static inline int Base64EscapeInternal(std::string &dest, + const unsigned char *src, + std::size_t slen, + Base64EscapeChars &base64_enc_map, + unsigned char padding_char) +{ + std::size_t olen = 0; + Base64EscapeInternal(nullptr, 0, &olen, src, slen, base64_enc_map, padding_char); + dest.resize(olen); + + if (nullptr == src || 0 == slen) + { + return 0; + } + + int ret = Base64EscapeInternal(reinterpret_cast(&dest[0]), dest.size(), &olen, + src, slen, base64_enc_map, padding_char); +# if defined(HAVE_GSL) + Expects(0 != ret || dest.size() == olen + 1); +# else + assert(0 != ret || dest.size() == olen + 1); +# endif + // pop back last zero + if (!dest.empty() && *dest.rbegin() == 0) + { + dest.resize(dest.size() - 1); + } + return ret; +} + +static int Base64UnescapeInternal(unsigned char *dst, + std::size_t dlen, + std::size_t *olen, + const unsigned char *src, + std::size_t slen, + Base64UnescapeChars &base64_dec_map, + unsigned char padding_char) +{ + std::size_t i, n; + std::size_t j, x; + std::size_t valid_slen, line_len; + unsigned char *p; + + /* First pass: check for validity and get output length */ + for (i = n = j = valid_slen = line_len = 0; i < slen; i++) + { + /* Skip spaces before checking for EOL */ + x = 0; + while (i < slen && (src[i] == ' ' || src[i] == '\t')) + { + ++i; + ++x; + } + + /* Spaces at end of buffer are OK */ + if (i == slen) + break; + + if (src[i] == '\r' || src[i] == '\n') + { + line_len = 0; + continue; + } + + /* Space inside a line is an error */ + if (x != 0 && line_len != 0) + return -2; + + ++valid_slen; + ++line_len; + if (src[i] == padding_char) + { + if (++j > 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 + { + if (src[i] > 127 || base64_dec_map[src[i]] == 127) + return -2; + } + + if (base64_dec_map[src[i]] < 64 && j != 0) + return -2; + + n++; + } + + if (n == 0) + { + *olen = 0; + return 0; + } + + // no padding, add j to padding length + if (valid_slen & 3) + { + j += 4 - (valid_slen & 3); + n += 4 - (valid_slen & 3); + } + + /* The following expression is to calculate the following formula without + * risk of integer overflow in n: + * n = ( ( n * 6 ) + 7 ) >> 3; + */ + n = (6 * (n >> 3)) + ((6 * (n & 0x7) + 7) >> 3); + n -= j; + + if (dst == nullptr || dlen < n) + { + *olen = n; + return -1; + } + + for (n = x = 0, p = dst; i > 0; i--, src++) + { + if (*src == '\r' || *src == '\n' || *src == ' ' || *src == '\t') + continue; + if (*src == padding_char) + continue; + + x = (x << 6) | (base64_dec_map[*src] & 0x3F); + + if (++n == 4) + { + n = 0; + *p++ = (unsigned char)(x >> 16); + *p++ = (unsigned char)(x >> 8); + *p++ = (unsigned char)(x); + } + } + + // no padding, the tail code + if (n == 2) + { + *p++ = (unsigned char)(x >> 4); + } + else if (n == 3) + { + *p++ = (unsigned char)(x >> 10); + *p++ = (unsigned char)(x >> 2); + } + + *olen = static_cast(p - dst); + + return 0; +} + +} // namespace +#endif + +// Base64Escape() +// +// Encodes a `src` string into a base64-encoded 'dest' string with padding +// characters. This function conforms with RFC 4648 section 4 (base64) and RFC +// 2045. +OPENTELEMETRY_EXPORT void Base64Escape(opentelemetry::nostd::string_view src, std::string *dest) +{ + if (nullptr == dest || src.empty()) + { + return; + } + +#if defined(HAVE_ABSEIL) + absl::Base64Escape(absl::string_view{src.data(), src.size()}, dest); +#else + Base64EscapeInternal(*dest, reinterpret_cast(src.data()), src.size(), + kBase64EscapeCharsBasic, '='); +#endif +} + +OPENTELEMETRY_EXPORT std::string Base64Escape(opentelemetry::nostd::string_view src) +{ + std::string result; + + Base64Escape(src, &result); + return result; +} + +OPENTELEMETRY_EXPORT bool Base64Unescape(opentelemetry::nostd::string_view src, std::string *dest) +{ + if (nullptr == dest) + { + return false; + } + +#if defined(HAVE_ABSEIL) + return absl::Base64Unescape(absl::string_view{src.data(), src.size()}, dest); +#else + if (src.empty()) + { + return true; + } + + std::size_t olen = 0; + + if (-2 == Base64UnescapeInternal(nullptr, 0, &olen, + reinterpret_cast(src.data()), src.size(), + kBase64UnescapeCharsBasic, '=')) + { + return false; + } + + dest->resize(olen); + Base64UnescapeInternal(reinterpret_cast(&(*dest)[0]), dest->size(), &olen, + reinterpret_cast(src.data()), src.size(), + kBase64UnescapeCharsBasic, '='); + return true; +#endif +} + +} // namespace common +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/common/BUILD b/sdk/test/common/BUILD index 0f886ec569..b08bcc0976 100644 --- a/sdk/test/common/BUILD +++ b/sdk/test/common/BUILD @@ -15,6 +15,18 @@ cc_test( ], ) +cc_test( + name = "base64_test", + srcs = [ + "base64_test.cc", + ], + tags = ["test"], + deps = [ + "//sdk/src/common:base64", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "fast_random_number_generator_test", srcs = [ @@ -27,6 +39,16 @@ cc_test( ], ) +otel_cc_benchmark( + name = "base64_benchmark", + srcs = ["base64_benchmark.cc"], + tags = [ + "benchmark", + "test", + ], + deps = ["//sdk/src/common:base64"], +) + otel_cc_benchmark( name = "random_benchmark", srcs = ["random_benchmark.cc"], diff --git a/sdk/test/common/CMakeLists.txt b/sdk/test/common/CMakeLists.txt index 0205061911..00ad67a5bf 100644 --- a/sdk/test/common/CMakeLists.txt +++ b/sdk/test/common/CMakeLists.txt @@ -24,11 +24,22 @@ foreach( TEST_LIST ${testname}) endforeach() +add_executable(base64_test base64_test.cc) +target_link_libraries(base64_test ${GTEST_BOTH_LIBRARIES} opentelemetry_common) +gtest_add_tests( + TARGET base64_test + TEST_PREFIX common. + TEST_LIST base64_test) + add_executable(random_fork_test random_fork_test.cc) target_link_libraries(random_fork_test opentelemetry_common) add_test(random_fork_test random_fork_test) if(WITH_BENCHMARK) + add_executable(base64_benchmark base64_benchmark.cc) + target_link_libraries(base64_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_common) + add_executable(random_benchmark random_benchmark.cc) target_link_libraries(random_benchmark benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT} opentelemetry_common) diff --git a/sdk/test/common/base64_benchmark.cc b/sdk/test/common/base64_benchmark.cc new file mode 100644 index 0000000000..acb8b01ff4 --- /dev/null +++ b/sdk/test/common/base64_benchmark.cc @@ -0,0 +1,49 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/base64.h" + +#include "benchmark/benchmark.h" + +namespace +{ + +static const unsigned char base64_test_dec[64] = { + 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01, + 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09, 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13, + 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31, 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38, + 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B, 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97}; + +static const unsigned char base64_test_enc_rfc_2045[] = + "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK" + "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw=="; + +void BM_Base64Escape(benchmark::State &state) +{ + while (state.KeepRunning()) + { + benchmark::DoNotOptimize( + opentelemetry::sdk::common::Base64Escape(opentelemetry::nostd::string_view{ + reinterpret_cast(base64_test_dec), sizeof(base64_test_dec)})); + } +} +BENCHMARK(BM_Base64Escape); + +void BM_Base64Unescape(benchmark::State &state) +{ + std::string dest; + while (state.KeepRunning()) + { + benchmark::DoNotOptimize(opentelemetry::sdk::common::Base64Unescape( + opentelemetry::nostd::string_view{reinterpret_cast(base64_test_enc_rfc_2045), + 88}, + &dest)); + } +} +BENCHMARK(BM_Base64Unescape); + +} // namespace +BENCHMARK_MAIN(); diff --git a/sdk/test/common/base64_test.cc b/sdk/test/common/base64_test.cc new file mode 100644 index 0000000000..74ebe5cf27 --- /dev/null +++ b/sdk/test/common/base64_test.cc @@ -0,0 +1,92 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/common/base64.h" + +#include + +#include + +static const unsigned char base64_test_dec[64] = { + 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01, + 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09, 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13, + 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31, 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38, + 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B, 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97}; + +static const unsigned char base64_test_enc_rfc_2045[] = + "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK" + "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw=="; + +TEST(Base64Test, EscapeRfc2045) +{ + std::string encoded = opentelemetry::sdk::common::Base64Escape(opentelemetry::nostd::string_view{ + reinterpret_cast(base64_test_dec), sizeof(base64_test_dec)}); + opentelemetry::nostd::string_view expected{ + reinterpret_cast(base64_test_enc_rfc_2045), 88}; + + EXPECT_EQ(encoded, expected); +} + +TEST(Base64Test, UnescapeRfc2045) +{ + std::string decoded; + EXPECT_TRUE(opentelemetry::sdk::common::Base64Unescape( + opentelemetry::nostd::string_view{reinterpret_cast(base64_test_enc_rfc_2045), + 88}, + &decoded)); + opentelemetry::nostd::string_view expected{reinterpret_cast(base64_test_dec), + sizeof(base64_test_dec)}; + + EXPECT_EQ(decoded, expected); +} + +TEST(Base64Test, UnescapeRfc2045InvalidInput) +{ + std::string std_str_out; + std::string std_str_in = "="; + + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + std_str_in = "J="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JEhu="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JEhuV="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JEhuVodi="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JEhuVodiW="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " J="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JEhu="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JEhuV="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JEhuVodi="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JEhuVodiW="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + std_str_in = "JE=="; + EXPECT_TRUE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JE==huVo"; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = "JE=huVo="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + std_str_in = " JE=="; + EXPECT_TRUE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JE==huVo"; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + std_str_in = " JE=huVo="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + std_str_in = "JE==\r\n"; + EXPECT_TRUE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); + + std_str_in = "J E="; + EXPECT_FALSE(opentelemetry::sdk::common::Base64Unescape(std_str_in, &std_str_out)); +} From c0092c4c8433c112bacc2a8a3a7b96c7fbb0498d Mon Sep 17 00:00:00 2001 From: jaelrod <64549955+jaelrod@users.noreply.github.com> Date: Wed, 16 Aug 2023 18:31:53 -0400 Subject: [PATCH 053/119] fixing an apparent logging macro bug (#2265) --- sdk/include/opentelemetry/sdk/common/global_log_handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index 74dd90ccc6..a36bd4a8a3 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -186,7 +186,7 @@ OPENTELEMETRY_END_NAMESPACE OTEL_INTERNAL_LOG_WARN_1_ARGS) # define OTEL_INTERNAL_LOG_WARN(...) OTEL_INTERNAL_LOG_WARN_MACRO(__VA_ARGS__)(__VA_ARGS__) #else -# define OTEL_INTERNAL_LOG_ERROR(...) +# define OTEL_INTERNAL_LOG_WARN(...) #endif #if OTEL_INTERNAL_LOG_LEVEL >= OTEL_INTERNAL_LOG_LEVEL_DEBUG From d3799a63ff8b7ff60418cc7de71705467f61bba4 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 21 Aug 2023 13:31:07 -0700 Subject: [PATCH 054/119] use ubuntu-latest for tsan CI (#2267) --- .github/workflows/ci.yml | 2 +- ci/do_ci.sh | 3 ++- ext/test/http/curl_http_test.cc | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39207e214c..cf08af4b21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -611,7 +611,7 @@ jobs: bazel_tsan: name: Bazel tsan config - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: diff --git a/ci/do_ci.sh b/ci/do_ci.sh index c445e0abcd..3deeea4938 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -400,7 +400,8 @@ elif [[ "$1" == "bazel.asan" ]]; then elif [[ "$1" == "bazel.tsan" ]]; then # TODO - potential race condition in Civetweb server used by prometheus-cpp during shutdown # https://github.com/civetweb/civetweb/issues/861, so removing prometheus from the test - bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... +# zpages test failing with tsan. Ignoring the tests for now, as zpages will be removed soon. + bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//ext/test/zpages/... exit 0 elif [[ "$1" == "bazel.valgrind" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //... diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 78ecd92a6f..7c66d98b63 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -102,6 +102,7 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe std::atomic is_setup_{false}; std::atomic is_running_{false}; std::vector received_requests_; + std::mutex cv_mtx_requests; std::mutex mtx_requests; std::condition_variable cv_got_events; std::mutex cv_m; @@ -142,15 +143,14 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe int response_status = 404; if (request.uri == "/get/") { - - std::unique_lock lk(mtx_requests); + std::unique_lock lk1(mtx_requests); received_requests_.push_back(request); response.headers["Content-Type"] = "text/plain"; response_status = 200; } else if (request.uri == "/post/") { - std::unique_lock lk(mtx_requests); + std::unique_lock lk1(mtx_requests); received_requests_.push_back(request); response.headers["Content-Type"] = "application/json"; response.body = "{'k1':'v1', 'k2':'v2', 'k3':'v3'}"; @@ -164,9 +164,9 @@ class BasicCurlHttpTests : public ::testing::Test, public HTTP_SERVER_NS::HttpRe bool waitForRequests(unsigned timeOutSec, unsigned expected_count = 1) { - std::unique_lock lk(mtx_requests); + std::unique_lock lk(cv_mtx_requests); if (cv_got_events.wait_for(lk, std::chrono::milliseconds(1000 * timeOutSec), [&] { - // + std::unique_lock lk1(mtx_requests); return received_requests_.size() >= expected_count; })) { From 4bfddde7adc66ef185c36684db3feb1704cf5b45 Mon Sep 17 00:00:00 2001 From: Alexey Shakula Date: Mon, 21 Aug 2023 17:19:57 -0400 Subject: [PATCH 055/119] added public link of `opentelemetry_proto_grpc` against gRPC lib [only if gRPC library is shared] (#2268) --- cmake/opentelemetry-proto.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 4d64a8479c..2208235691 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -272,8 +272,14 @@ if(WITH_OTLP_GRPC) ${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE}) list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc) - target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto) + target_link_libraries(opentelemetry_proto_grpc + PUBLIC opentelemetry_proto) + get_target_property(grpc_lib_type gRPC::grpc++ TYPE) + if (grpc_lib_type STREQUAL "SHARED_LIBRARY") + target_link_libraries(opentelemetry_proto_grpc + PUBLIC gRPC::grpc++) + endif() set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME proto_grpc) patch_protobuf_targets(opentelemetry_proto_grpc) From 36fb921fe0dffce9e2e65e21d33bce442edb337f Mon Sep 17 00:00:00 2001 From: TomSvk88 <141317028+TomSvk88@users.noreply.github.com> Date: Tue, 22 Aug 2023 01:19:29 +0200 Subject: [PATCH 056/119] Fix more cases for symbol name for 32-bit win32 DLL build (#2264) --- ext/src/dll/opentelemetry_cpp.src | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 1afa635df4..5d6d5e0092 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -16,11 +16,19 @@ EXPORTS ?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VTracerProvider@trace@v1@opentelemetry@@U?$default_delete@VTracerProvider@trace@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@7@@Z #if defined(WITH_OTLP_GRPC) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) +#if defined(_WIN64) ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z +#else + ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpGrpcExporterOptions@2345@@Z +#endif // defined(_WIN64) #endif // defined(WITH_OTLP_GRPC) #if defined(WITH_OTLP_HTTP) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) +#if defined(_WIN64) ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z +#else + ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpHttpExporterOptions@2345@@Z +#endif // defined(_WIN64) #endif // defined(WITH_OTLP_HTTP) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) #if defined(_WIN64) From 11d5d9e0d8fd8ba876c8994714cc2647479b6574 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Tue, 22 Aug 2023 08:49:00 -0700 Subject: [PATCH 057/119] Prepare for releasing 1.11.0 (#2272) --- CHANGELOG.md | 35 +++++++++++++++++++ api/include/opentelemetry/version.h | 4 +-- docs/public/conf.py | 2 +- .../opentelemetry/sdk/version/version.h | 2 +- sdk/src/version/version.cc | 9 ++--- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b28715280..0c4ce6f45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,41 @@ Increment the: ## [Unreleased] +## [1.11.0] 2023-08-21 + +* [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build + [#2264](https://github.com/open-telemetry/opentelemetry-cpp/pull/2264) +* [BUILD] added public link of `opentelemetry_proto_grpc` against gRPC lib (only + if gRPC library is shared) + [#2268](https://github.com/open-telemetry/opentelemetry-cpp/pull/2268) +* [CI] use ubuntu-latest for tsan CI + [#2267](https://github.com/open-telemetry/opentelemetry-cpp/pull/2267) +* [SDK] Fixing an apparent logging macro bug + [#2265](https://github.com/open-telemetry/opentelemetry-cpp/pull/2265) +* [BUILD] Support protobuf 3.22 or upper + [#2163](https://github.com/open-telemetry/opentelemetry-cpp/pull/2163) +* [BUILD] Remove extra includes + [#2252](https://github.com/open-telemetry/opentelemetry-cpp/pull/2252) +* [LOGS API SDK] Mark logs signal as stable API/SDK + [#2229](https://github.com/open-telemetry/opentelemetry-cpp/pull/2229) +* [SEMANTIC CONVENTIONS] Upgrade to 1.21.0 + [#2248](https://github.com/open-telemetry/opentelemetry-cpp/pull/2248) +* [SDK] Valgrind errors on std::atomic variables + [#2244](https://github.com/open-telemetry/opentelemetry-cpp/pull/2244) +* [BUILD] Fix compile with clang 16 and libc++ + [#2242](https://github.com/open-telemetry/opentelemetry-cpp/pull/2242) +* [Metrics SDK] Add unit to Instrument selection criteria + [#2236](https://github.com/open-telemetry/opentelemetry-cpp/pull/2236) +* [SDK] Add OStreamLogRecordExporterFactory + [#2240](https://github.com/open-telemetry/opentelemetry-cpp/pull/2240) +* [SDK] Add support for LowMemory metrics temporality + [#2234](https://github.com/open-telemetry/opentelemetry-cpp/pull/2234) +* [CI] Misc build scripts cleanup + [#2232](https://github.com/open-telemetry/opentelemetry-cpp/pull/2232) +* [CI] Upgrade GoogleTest version from 1.12.1 to 1.13.0 + [#2114](https://github.com/open-telemetry/opentelemetry-cpp/pull/2114) +* [BUILD] include cstdint + [#2230](https://github.com/open-telemetry/opentelemetry-cpp/pull/2230) * [EXPORTER] Support protobuf 3.22 or upper [#2163](https://github.com/open-telemetry/opentelemetry-cpp/pull/2163) * [SDK] Mark logs signal as stable API/SDK diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index f3c2978cf0..c44e9a3691 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -7,9 +7,9 @@ #include "opentelemetry/detail/preprocessor.h" #define OPENTELEMETRY_ABI_VERSION_NO 1 -#define OPENTELEMETRY_VERSION "1.10.0" +#define OPENTELEMETRY_VERSION "1.11.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 10 +#define OPENTELEMETRY_VERSION_MINOR 11 #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 b6d552218b..1c090b8b35 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.10.0" +release = "1.11.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 da4c682c72..b790af4574 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -5,7 +5,7 @@ #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_SDK_VERSION "1.10.0" +#define OPENTELEMETRY_SDK_VERSION "1.11.0" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index efd64a14e3..34175bd4e4 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -12,13 +12,14 @@ namespace sdk namespace version { const int major_version = 1; -const int minor_version = 10; +const int minor_version = 11; const int patch_version = 0; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.10.0"; -const char *full_version = "1.10.0-NONE-NONE"; -const char *build_date = "Tue 11 Jul 2023 07:54:39 AM UTC"; +const char *short_version = "1.11.0"; +const char *full_version = "1.11.0-NONE-NONE"; +const char *build_date = "Mon Aug 21 22:31:07 UTC 2023"; + } // namespace version } // namespace sdk OPENTELEMETRY_END_NAMESPACE From c0f17d99b0f47c65c80bcd873179bc46a01b494d Mon Sep 17 00:00:00 2001 From: Darren Bolduc Date: Tue, 22 Aug 2023 16:28:18 -0400 Subject: [PATCH 058/119] Support `pkg-config` (#2269) --- .github/workflows/ci.yml | 21 ++++++++++++- api/CMakeLists.txt | 16 ++++++++-- ci/do_ci.sh | 12 +++++++ ci/setup_ci_environment.sh | 3 +- ci/verify_packages.sh | 12 +++++++ cmake/pkgconfig.cmake | 55 +++++++++++++++++++++++++++++++++ cmake/templates/config.pc.in | 15 +++++++++ sdk/src/common/CMakeLists.txt | 6 ++++ sdk/src/logs/CMakeLists.txt | 5 +++ sdk/src/metrics/CMakeLists.txt | 5 +++ sdk/src/resource/CMakeLists.txt | 5 +++ sdk/src/trace/CMakeLists.txt | 5 +++ sdk/src/version/CMakeLists.txt | 5 +++ 13 files changed, 161 insertions(+), 4 deletions(-) create mode 100755 ci/verify_packages.sh create mode 100644 cmake/pkgconfig.cmake create mode 100644 cmake/templates/config.pc.in diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf08af4b21..68b40058c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -228,7 +228,7 @@ jobs: run: | ./ci/do_ci.sh cmake.with_async_export.test - cmake_absel_stl_test: + cmake_abseil_stl_test: name: CMake test (with abseil) runs-on: ubuntu-20.04 steps: @@ -442,6 +442,25 @@ jobs: sudo ./ci/setup_grpc.sh -T ./ci/do_ci.sh cmake.exporter.otprotocol.shared_libs.with_static_grpc.test + cmake_install_test: + name: CMake install test (with abseil) + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + run: | + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + - name: run cmake install (with abseil) + run: | + sudo ./ci/install_abseil.sh + ./ci/do_ci.sh cmake.install.test + - name: verify packages + run: | + ./ci/verify_packages.sh + plugin_test: name: Plugin -> CMake runs-on: ubuntu-latest diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 9e32cd24ed..41b6997980 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -29,6 +29,8 @@ if(OPENTELEMETRY_INSTALL) DESTINATION include FILES_MATCHING PATTERN "*.h") + + unset(TARGET_DEPS) endif() if(BUILD_TESTING) @@ -41,12 +43,12 @@ if(WITH_NO_DEPRECATED_CODE) endif() if(WITH_ABSEIL) - target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) target_link_libraries( opentelemetry_api INTERFACE absl::bad_variant_access absl::any absl::base absl::bits absl::city) - + list(APPEND TARGET_DEPS "absl_bad_variant_access" "absl_any absl_base" + "absl_bits" "absl_city") endif() if(WITH_STL) @@ -64,6 +66,7 @@ if(WITH_GSL) find_package(Microsoft.GSL QUIET) if(TARGET Microsoft.GSL::GSL) target_link_libraries(opentelemetry_api INTERFACE Microsoft.GSL::GSL) + list(APPEND TARGET_DEPS "gsl") else() set(GSL_DIR third_party/ms-gsl) target_include_directories( @@ -115,3 +118,12 @@ if(WITH_METRICS_EXEMPLAR_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW) endif() + +include(${PROJECT_SOURCE_DIR}/cmake/pkgconfig.cmake) + +if(OPENTELEMETRY_INSTALL) + opentelemetry_add_pkgconfig( + api "OpenTelemetry API" + "A header-only library to support instrumentation with OpenTelemetry." + "${TARGET_DEPS}") +endif() diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 3deeea4938..03f0f9062e 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -322,6 +322,18 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then make -j $(nproc) cd exporters/otlp && make test exit 0 +elif [[ "$1" == "cmake.install.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_ABSEIL=ON \ + "${SRC_DIR}" + make -j $(nproc) + sudo make install + exit 0 elif [[ "$1" == "bazel.with_abseil" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC --//api:with_abseil=true //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS_ASYNC --//api:with_abseil=true //... diff --git a/ci/setup_ci_environment.sh b/ci/setup_ci_environment.sh index 8e93b8d5b5..ed4378e2d6 100755 --- a/ci/setup_ci_environment.sh +++ b/ci/setup_ci_environment.sh @@ -12,4 +12,5 @@ apt-get install --no-install-recommends --no-install-suggests -y \ git \ valgrind \ lcov \ - iwyu + iwyu \ + pkg-config diff --git a/ci/verify_packages.sh b/ci/verify_packages.sh new file mode 100755 index 0000000000..3d4e3efa4c --- /dev/null +++ b/ci/verify_packages.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -ex + +PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig:${PKG_CONFIG_PATH:-}" + +for library in api common logs metrics resources trace version; do + pkg-config --validate opentelemetry_${library} --print-errors +done diff --git a/cmake/pkgconfig.cmake b/cmake/pkgconfig.cmake new file mode 100644 index 0000000000..7bff4cb48c --- /dev/null +++ b/cmake/pkgconfig.cmake @@ -0,0 +1,55 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Unlike functions, macros do not introduce a scope. This is an advantage when +# trying to set global variables, as we do here. +macro (opentelemetry_set_pkgconfig_paths) + if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(OPENTELEMETRY_PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}") + else () + set(OPENTELEMETRY_PC_LIBDIR + "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") + endif () + + if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(OPENTELEMETRY_PC_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") + else () + set(OPENTELEMETRY_PC_INCLUDEDIR + "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif () +endmacro () + +# Create the pkgconfig configuration file (aka *.pc files) and the rules to install it. +# +# * library: the short name of the target, such as `api` or `resources`. +# * name: the displayed name of the library, such as "OpenTelemetry API". +# * description: the description of the library. +# * ARGN: the names of any pkgconfig modules the generated module depends on. +# +function (opentelemetry_add_pkgconfig library name description) + opentelemetry_set_pkgconfig_paths() + set(target "opentelemetry_${library}") + set(OPENTELEMETRY_PC_NAME "${name}") + set(OPENTELEMETRY_PC_DESCRIPTION ${description}) + string(JOIN " " OPENTELEMETRY_PC_REQUIRES ${ARGN}) + get_target_property(target_type ${target} TYPE) + if ("${target_type}" STREQUAL "INTERFACE_LIBRARY") + # Interface libraries only contain headers. They do not generate lib files + # to link against with `-l`. + set(OPENTELEMETRY_PC_LIBS "") + else () + set(OPENTELEMETRY_PC_LIBS "-l${target}") + endif () + get_target_property(target_defs ${target} INTERFACE_COMPILE_DEFINITIONS) + if (target_defs) + foreach (def ${target_defs}) + string(APPEND OPENTELEMETRY_PC_CFLAGS " -D${def}") + endforeach () + endif () + + # Create and install the pkg-config files. + configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/config.pc.in" "${target}.pc" @ONLY) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endfunction() diff --git a/cmake/templates/config.pc.in b/cmake/templates/config.pc.in new file mode 100644 index 0000000000..eac5fd9e89 --- /dev/null +++ b/cmake/templates/config.pc.in @@ -0,0 +1,15 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +prefix=${pcfiledir}/../.. +exec_prefix=${prefix} +libdir=@OPENTELEMETRY_PC_LIBDIR@ +includedir=@OPENTELEMETRY_PC_INCLUDEDIR@ + +Name: @OPENTELEMETRY_PC_NAME@ +Description: @OPENTELEMETRY_PC_DESCRIPTION@ +Requires: @OPENTELEMETRY_PC_REQUIRES@ +Version: @OPENTELEMETRY_VERSION@ + +Libs: -L${libdir} @OPENTELEMETRY_PC_LIBS@ +Cflags: -I${includedir} @OPENTELEMETRY_PC_CFLAGS@ diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index b0f44ac139..9f0e61f1e2 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -29,4 +29,10 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + common + "OpenTelemetry SDK - Common" + "Common components for the OpenTelemetry SDK, a library for exporting telemetry." + "opentelemetry_api") endif() diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index e235e50696..71679a9a48 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -39,4 +39,9 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + logs "OpenTelemetry SDK - Logs" + "Components for exporting logs in the OpenTelemetry SDK." + "opentelemetry_resources") endif() diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index f79d17dda2..a0c9aa6771 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -47,4 +47,9 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + metrics "OpenTelemetry SDK - Metrics" + "Components for exporting metrics in the OpenTelemetry SDK." + "opentelemetry_resources") endif() diff --git a/sdk/src/resource/CMakeLists.txt b/sdk/src/resource/CMakeLists.txt index 1a0510f678..7ccb9b491e 100644 --- a/sdk/src/resource/CMakeLists.txt +++ b/sdk/src/resource/CMakeLists.txt @@ -19,4 +19,9 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + resources "OpenTelemetry SDK - Resources" + "Components for resource detection in the OpenTelemetry SDK." + "opentelemetry_common") endif() diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index 52c109acb8..939a6ed2bc 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -39,4 +39,9 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + trace "OpenTelemetry SDK - Trace" + "Components for exporting traces in the OpenTelemetry SDK." + "opentelemetry_resources") endif() diff --git a/sdk/src/version/CMakeLists.txt b/sdk/src/version/CMakeLists.txt index f7be858000..4818a4ec63 100644 --- a/sdk/src/version/CMakeLists.txt +++ b/sdk/src/version/CMakeLists.txt @@ -20,4 +20,9 @@ if(OPENTELEMETRY_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + version "OpenTelemetry SDK - Version" + "A library exporting version information for OpenTelemetry." + "opentelemetry_api") endif() From 628838af8a9cb03b95cb7f949adf3ed597725f94 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 24 Aug 2023 23:06:53 +0200 Subject: [PATCH 059/119] [CI] Never close stale issues (#2277) Fixes #2276 --- .github/workflows/stale.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 534fb60743..65c084eb93 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,4 +1,4 @@ -name: "Mark and close stale issues" +name: "Mark stale issues" on: schedule: - cron: "30 1 * * *" @@ -11,4 +11,5 @@ jobs: with: stale-issue-message: "This issue was marked as stale due to lack of activity." days-before-issue-stale: 60 + days-before-close: -1 exempt-issue-labels: "do-not-stale" From 7196ec3fdae13865c43b76d35c5900fc9fdbc7d4 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 25 Aug 2023 15:23:36 +0200 Subject: [PATCH 060/119] [CI] Benchmark workflow fails, C++14 required to build grpc (#2278) --- .github/workflows/benchmark.yml | 6 +++--- ci/do_ci.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index cc63677a24..fc4ed43e7f 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -25,12 +25,12 @@ jobs: key: bazel_benchmark - name: setup run: | - sudo -E ./ci/setup_cmake.sh - sudo -E ./ci/setup_ci_environment.sh + sudo ./ci/setup_ci_environment.sh + sudo ./ci/install_bazelisk.sh - name: Run benchmark id: run_benchmarks run: | - CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ci/do_ci.sh bazel.benchmark + ./ci/do_ci.sh bazel.benchmark mkdir -p benchmarks mv api-benchmark_result.json benchmarks mv sdk-benchmark_result.json benchmarks diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 03f0f9062e..6452faa451 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -25,7 +25,7 @@ function run_benchmarks [ -z "${BENCHMARK_DIR}" ] && export BENCHMARK_DIR=$HOME/benchmark mkdir -p $BENCHMARK_DIR - bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-std=c++14 $BAZEL_OPTIONS_ASYNC -c opt -- \ + bazel $BAZEL_STARTUP_OPTIONS build --host_cxxopt=-std=c++14 --cxxopt=-std=c++14 $BAZEL_OPTIONS_ASYNC -c opt -- \ $(bazel query 'attr("tags", "benchmark_result", ...)') echo "" echo "Benchmark results in $BENCHMARK_DIR:" From f52ec6caded074437658643566bed0d83152a78a Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 31 Aug 2023 17:17:26 +0200 Subject: [PATCH 061/119] [SDK] Increase metric name maximum length from 63 to 255 characters (#2284) --- sdk/include/opentelemetry/sdk/metrics/meter.h | 1 - .../metrics/instrument_metadata_validator.cc | 8 +++--- .../instrument_metadata_validator_test.cc | 27 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 41a10f69e9..7e89d444ab 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -130,7 +130,6 @@ class Meter final : public opentelemetry::metrics::Meter std::unique_ptr RegisterAsyncMetricStorage( InstrumentDescriptor &instrument_descriptor); opentelemetry::common::SpinLockMutex storage_lock_; - const InstrumentMetaDataValidator instrument_metadata_validator; static nostd::shared_ptr GetNoopObservableInsrument() diff --git a/sdk/src/metrics/instrument_metadata_validator.cc b/sdk/src/metrics/instrument_metadata_validator.cc index 4fde7d3f26..aba6344efc 100644 --- a/sdk/src/metrics/instrument_metadata_validator.cc +++ b/sdk/src/metrics/instrument_metadata_validator.cc @@ -17,8 +17,8 @@ namespace sdk { namespace metrics { -// instrument-name = ALPHA 0*62 ("_" / "." / "-" / ALPHA / DIGIT) -const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,62}"; +// instrument-name = ALPHA 0*254 ("_" / "." / "-" / ALPHA / DIGIT) +const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,254}"; // const std::string kInstrumentUnitPattern = "[\x01-\x7F]{0,63}"; // instrument-unit = It can have a maximum length of 63 ASCII chars @@ -38,8 +38,8 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const #if OPENTELEMETRY_HAVE_WORKING_REGEX return std::regex_match(name.data(), name_reg_key_); #else - const size_t kMaxSize = 63; - // size atmost 63 chars + const size_t kMaxSize = 255; + // size atmost 255 chars if (name.size() > kMaxSize) { return false; diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 68c350747a..0f9e7134a7 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -19,13 +19,13 @@ TEST(InstrumentMetadataValidator, TestName) { opentelemetry::sdk::metrics::InstrumentMetaDataValidator validator; std::vector invalid_names = { - "", // empty string - "1sdf", // string starting with number - "123€AAA€BBB", // unicode characters - "/\\sdsd", // string starting with special character - "***sSSs", // string starting with special character - CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 charactes - CreateVeryLargeString(7), // string much bigger than 63 chars + "", // empty string + "1sdf", // string starting with number + "123€AAA€BBB", // unicode characters + "/\\sdsd", // string starting with special character + "***sSSs", // string starting with special character + CreateVeryLargeString(25) + "X", // total 256 characters + CreateVeryLargeString(26), // string much bigger than 255 characters }; for (auto const &str : invalid_names) { @@ -33,11 +33,14 @@ TEST(InstrumentMetadataValidator, TestName) } std::vector valid_names = { - "T", // single char string - "s123", // starting with char, followed by numbers - "dsdsdsd_-.", // string , and valid nonalphanumeric - "d1234_-sDSDs.sdsd344", // combination of all valid characters - CreateVeryLargeString(5) + "ABCERTYG", // total 63 charactes + "T", // single char string + "s123", // starting with char, followed by numbers + "dsdsdsd_-.", // string , and valid nonalphanumeric + "d1234_-sDSDs.sdsd344", // combination of all valid characters + CreateVeryLargeString(5) + "ABCERTYG", // total 63 characters + CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 characters + CreateVeryLargeString(24) + "ABCDEFGHI", // total 254 characters + CreateVeryLargeString(25), // total 255 characters }; for (auto const &str : valid_names) { From 01e65810b9267df34487ce6bd4ed175be6b9d51e Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 2 Sep 2023 12:09:47 +0200 Subject: [PATCH 062/119] [SEMANTIC CONVENTION] Deprecated semconv (in the spec) not deprecated (in C++) (#2285) --- .../trace/semantic_conventions.h | 64 +++++++++++++++++++ .../templates/SemanticAttributes.h.j2 | 9 +-- .../sdk/resource/semantic_conventions.h | 7 ++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index 42cf57d0ec..c46b41bc52 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -10,6 +10,7 @@ #pragma once +#include "opentelemetry/common/macros.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -55,105 +56,168 @@ static constexpr const char *kClientSocketPort = "client.socket.port"; /** * Deprecated, use {@code http.request.method} instead. + * + * @deprecated Deprecated, use `http.request.method` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpMethod = "http.method"; /** * Deprecated, use {@code http.response.status_code} instead. + * + * @deprecated Deprecated, use `http.response.status_code` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpStatusCode = "http.status_code"; /** * Deprecated, use {@code url.scheme} instead. + * + * @deprecated Deprecated, use `url.scheme` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpScheme = "http.scheme"; /** * Deprecated, use {@code url.full} instead. + * + * @deprecated Deprecated, use `url.full` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpUrl = "http.url"; /** * Deprecated, use {@code url.path} and {@code url.query} instead. + * + * @deprecated Deprecated, use `url.path` and `url.query` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpTarget = "http.target"; /** * Deprecated, use {@code http.request.body.size} instead. + * + * @deprecated Deprecated, use `http.request.body.size` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpRequestContentLength = "http.request_content_length"; /** * Deprecated, use {@code http.response.body.size} instead. + * + * @deprecated Deprecated, use `http.response.body.size` instead. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kHttpResponseContentLength = "http.response_content_length"; /** * Deprecated, use {@code server.socket.domain} on client spans. + * + * @deprecated Deprecated, use `server.socket.domain` on client spans. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockPeerName = "net.sock.peer.name"; /** * Deprecated, use {@code server.socket.address} on client spans and {@code client.socket.address} * on server spans. + * + * @deprecated Deprecated, use `server.socket.address` on client spans and `client.socket.address` + * on server spans. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockPeerAddr = "net.sock.peer.addr"; /** * Deprecated, use {@code server.socket.port} on client spans and {@code client.socket.port} on * server spans. + * + * @deprecated Deprecated, use `server.socket.port` on client spans and `client.socket.port` on + * server spans. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockPeerPort = "net.sock.peer.port"; /** * Deprecated, use {@code server.address} on client spans and {@code client.address} on server * spans. + * + * @deprecated Deprecated, use `server.address` on client spans and `client.address` on server + * spans. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetPeerName = "net.peer.name"; /** * Deprecated, use {@code server.port} on client spans and {@code client.port} on server spans. + * + * @deprecated Deprecated, use `server.port` on client spans and `client.port` on server spans. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetPeerPort = "net.peer.port"; /** * Deprecated, use {@code server.address}. + * + * @deprecated Deprecated, use `server.address`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetHostName = "net.host.name"; /** * Deprecated, use {@code server.port}. + * + * @deprecated Deprecated, use `server.port`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetHostPort = "net.host.port"; /** * Deprecated, use {@code server.socket.address}. + * + * @deprecated Deprecated, use `server.socket.address`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockHostAddr = "net.sock.host.addr"; /** * Deprecated, use {@code server.socket.port}. + * + * @deprecated Deprecated, use `server.socket.port`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockHostPort = "net.sock.host.port"; /** * Deprecated, use {@code network.transport}. + * + * @deprecated Deprecated, use `network.transport`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetTransport = "net.transport"; /** * Deprecated, use {@code network.protocol.name}. + * + * @deprecated Deprecated, use `network.protocol.name`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetProtocolName = "net.protocol.name"; /** * Deprecated, use {@code network.protocol.version}. + * + * @deprecated Deprecated, use `network.protocol.version`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetProtocolVersion = "net.protocol.version"; /** * Deprecated, use {@code network.transport} and {@code network.type}. + * + * @deprecated Deprecated, use `network.transport` and `network.type`. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockFamily = "net.sock.family"; /** diff --git a/buildscripts/semantic-convention/templates/SemanticAttributes.h.j2 b/buildscripts/semantic-convention/templates/SemanticAttributes.h.j2 index 1f0188a5e3..d35b99444e 100644 --- a/buildscripts/semantic-convention/templates/SemanticAttributes.h.j2 +++ b/buildscripts/semantic-convention/templates/SemanticAttributes.h.j2 @@ -39,6 +39,7 @@ #pragma once +#include "opentelemetry/common/macros.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -59,13 +60,13 @@ static constexpr const char *kSchemaUrl = "{{schemaUrl}}"; *

        Notes:

          {{attribute.note | render_markdown(code="{{@code {0}}}", paragraph="
        • {0}
        • ", list="{0}")}}
        {%- endif %} -{%- if attribute.deprecated %} +{%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %} * - * @deprecated {{attribute.deprecated | to_doc_brief}}. + * @deprecated {{attribute.brief | to_doc_brief}}. {%- endif %} */ - {%- if attribute.deprecated %} -@Deprecated + {%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %} +OPENTELEMETRY_DEPRECATED {%- endif %} static constexpr const char *k{{attribute.fqn | to_camelcase(True)}} = "{{attribute.fqn}}"; {%- endfor %} diff --git a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h index e96f052caf..9396a6c7f9 100644 --- a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h +++ b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h @@ -10,6 +10,7 @@ #pragma once +#include "opentelemetry/common/macros.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -794,12 +795,18 @@ static constexpr const char *kOtelScopeVersion = "otel.scope.version"; /** * Deprecated, use the {@code otel.scope.name} attribute. + * + * @deprecated Deprecated, use the `otel.scope.name` attribute. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryName = "otel.library.name"; /** * Deprecated, use the {@code otel.scope.version} attribute. + * + * @deprecated Deprecated, use the `otel.scope.version` attribute. */ +OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryVersion = "otel.library.version"; // Enum definitions From 5acaa14c2128deec18ed94350a7d185ac63555df Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sun, 3 Sep 2023 08:00:51 -0700 Subject: [PATCH 063/119] [SDK] Remove unused variables from sync storage (#2294) --- .../opentelemetry/sdk/metrics/state/sync_metric_storage.h | 5 ----- 1 file changed, 5 deletions(-) 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 37b0e06707..b450b92179 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -161,11 +161,6 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage InstrumentDescriptor instrument_descriptor_; // hashmap to maintain the metrics for delta collection (i.e, collection since last Collect call) std::unique_ptr attributes_hashmap_; - // unreported metrics stash for all the collectors - std::unordered_map>> - unreported_metrics_; - // last reported metrics stash for all the collectors. - std::unordered_map last_reported_metrics_; std::function()> create_default_aggregation_; const AttributesProcessor *attributes_processor_; #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW From 6eb09faa7c8e8628b295d4bbaa2d78a13532c01f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 08:47:56 +0200 Subject: [PATCH 064/119] Bump actions/checkout from 3 to 4 (#2295) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout 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/benchmark.yml | 4 +- .github/workflows/ci.yml | 82 ++++++++++++------------ .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/dependencies_image.yml | 2 +- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index fc4ed43e7f..92981bc8d1 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -13,7 +13,7 @@ jobs: name: Run OpenTelemetry-cpp benchmarks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -47,7 +47,7 @@ jobs: name: Store benchmark result runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/download-artifact@master with: name: benchmark_results diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68b40058c3..2d8db91364 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: name: CMake test (without otlp-exporter) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -36,7 +36,7 @@ jobs: name: CMake gcc 12 (maintainer mode, C++11, async) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -69,7 +69,7 @@ jobs: name: CMake gcc 12 (maintainer mode, sync) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -101,7 +101,7 @@ jobs: name: CMake gcc 12 (maintainer mode, async) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -133,7 +133,7 @@ jobs: name: CMake clang 14 (maintainer mode, sync) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -165,7 +165,7 @@ jobs: name: CMake clang 14 (maintainer mode, async) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -197,7 +197,7 @@ jobs: name: CMake msvc (maintainer mode) runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -211,7 +211,7 @@ jobs: name: CMake test (without otlp-exporter and with async export) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -232,7 +232,7 @@ jobs: name: CMake test (with abseil) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -248,7 +248,7 @@ jobs: name: CMake test (with opentracing-shim) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -262,7 +262,7 @@ jobs: name: CMake gcc 4.8 (without otlp exporter) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Add Ubuntu Xenial package sources @@ -291,7 +291,7 @@ jobs: name: CMake gcc 4.8 (with otlp exporter) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Add Ubuntu Xenial package sources @@ -320,7 +320,7 @@ jobs: name: CMake C++20 test(GCC) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -342,7 +342,7 @@ jobs: name: CMake C++20 test(Clang with libc++) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -373,7 +373,7 @@ jobs: name: CMake test (with otlp-exporter) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -389,7 +389,7 @@ jobs: name: CMake test (with modern protobuf,grpc and abseil) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -414,7 +414,7 @@ jobs: name: CMake do not install test (with otlp-exporter) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -430,7 +430,7 @@ jobs: name: CMake test (build shared libraries with otlp-exporter and static gRPC) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -446,7 +446,7 @@ jobs: name: CMake install test (with abseil) runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -465,7 +465,7 @@ jobs: name: Plugin -> CMake runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -485,7 +485,7 @@ jobs: name: Bazel runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -506,7 +506,7 @@ jobs: name: Bazel with async export runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -527,7 +527,7 @@ jobs: name: Bazel with external abseil runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -548,7 +548,7 @@ jobs: name: Bazel valgrind runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -569,7 +569,7 @@ jobs: name: Bazel noexcept runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -590,7 +590,7 @@ jobs: name: Bazel nortti runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -611,7 +611,7 @@ jobs: name: Bazel asan config runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -632,7 +632,7 @@ jobs: name: Bazel tsan config runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -653,7 +653,7 @@ jobs: name: Bazel on MacOS runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -670,7 +670,7 @@ jobs: name: Benchmark runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: Mount Bazel Cache @@ -698,7 +698,7 @@ jobs: name: Format runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: setup run: sudo ./ci/install_format_tools.sh - name: run tests @@ -708,7 +708,7 @@ jobs: name: Copyright runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: check copyright run: ./tools/check_copyright.sh @@ -716,7 +716,7 @@ jobs: name: CMake -> exporter proto runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -733,7 +733,7 @@ jobs: name: CMake -> exporter proto (Build as DLL) runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -750,7 +750,7 @@ jobs: name: CMake (With async export) -> exporter proto runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -767,7 +767,7 @@ jobs: name: Bazel Windows runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -780,7 +780,7 @@ jobs: name: Plugin -> CMake Windows runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -794,7 +794,7 @@ jobs: name: Code coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - name: setup @@ -819,7 +819,7 @@ jobs: steps: - name: check out code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: install markdownlint-cli run: sudo npm install -g markdownlint-cli @@ -831,7 +831,7 @@ jobs: runs-on: ubuntu-latest steps: - name: check out code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: install misspell run: | curl -L -o ./install-misspell.sh https://git.io/misspell @@ -843,7 +843,7 @@ jobs: name: DocFX check runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install docfx run: choco install docfx -y --version=2.58.5 - name: run ./ci/docfx.cmd diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 15187cb39b..2d84fcff1c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Remove Third_party Modules from Code Scan diff --git a/.github/workflows/dependencies_image.yml b/.github/workflows/dependencies_image.yml index d5a96bd432..670565a943 100644 --- a/.github/workflows/dependencies_image.yml +++ b/.github/workflows/dependencies_image.yml @@ -11,7 +11,7 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v2 From cdbc90abf3b7170f898439fd34126469c42686c6 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 5 Sep 2023 10:51:58 +0200 Subject: [PATCH 065/119] [DEPRECATION] Deprecate ZPAGES (#2291) --- CHANGELOG.md | 3 ++ CMakeLists.txt | 11 ++++++- DEPRECATED.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c4ce6f45f..f09553ce70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [DEPRECATION] Deprecate ZPAGES + [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) + ## [1.11.0] 2023-08-21 * [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build diff --git a/CMakeLists.txt b/CMakeLists.txt index dcf1034804..d1b1a384a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,8 @@ option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK" option(WITH_ELASTICSEARCH "Whether to include the Elasticsearch Client in the SDK" OFF) -option(WITH_ZPAGES "Whether to include the Zpages Server in the SDK" OFF) +option(WITH_ZPAGES + "DEPRECATED - Whether to include the Zpages Server in the SDK" OFF) option(WITH_NO_GETENV "Whether the platform supports environment variables" OFF) @@ -258,6 +259,14 @@ option(WITH_OTLP_HTTP_SSL_TLS_PREVIEW option(WITH_METRICS_EXEMPLAR_PREVIEW "Whether to enable exemplar within metrics" OFF) +if(WITH_ZPAGES) + if(WITH_NO_DEPRECATED_CODE) + message(FATAL_ERROR "WITH_ZPAGES is DEPRECATED.") + else() + message(WARNING "WITH_ZPAGES is DEPRECATED.") + endif() +endif() + # # Verify options dependencies # diff --git a/DEPRECATED.md b/DEPRECATED.md index d77c3f073e..05ba8e52d4 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -151,7 +151,89 @@ N/A ## [opentelemetry-cpp Exporter] -N/A +### ZPages exporter + +#### Announcement (ZPages) + +* Version: 1.11.0 +* Date: 2023-09-01 +* PR: [DEPRECATION] Deprecate ZPAGES + [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) + +#### Motivation (ZPages) + +The ZPages specification itself was introduced in 2020, +and has been experimental ever since, +not getting a lot of attention, and never reaching a stable status. + +Several other opentelemetry projects have implemented support for zpages, +only to later deprecate and then remove the zpages implementation (Java, +C#), abandoning the zpages feature. + +In this context, it does not make sense to continue to maintain the zpages +code in opentelemetry-cpp. + +#### Scope (ZPages) + +The following are deprecated and planned for removal: + +* all the API headers located under + `ext/include/opentelemetry/ext/zpages/`, including: + * the C++ class `ThreadsafeSpanData` + * the C++ class `TracezDataAggregator` + * the C++ class `TracezHttpServer` + * the C++ class `TracezSpanProcessor` + * the C++ class `TracezSharedData` + * the C++ class `ZPages` + * the C++ class `zPagesHttpServer` +* all the code and doc located under `ext/src/zpages/` +* all the tests located under `ext/test/zpages/` +* the zpages exporter library(`opentelemetry_zpages`) +* the zpages build options in CMake (`WITH_ZPAGES`) + +The following code is no longer considered public, will no longer be +installed, and will no longer be useable outside of +the opentelemetry-cpp implementation: + +* all the API headers located under + `ext/include/opentelemetry/ext/http/server`, including: + * the C++ class `FileHttpServer` + * the C++ class `HttpRequestCallback` + * the C++ class `HttpServer` + * the C++ class `HttpRequestHandler` + * the C++ class `SocketCallback` + +This implementation of an HTTP server is meant to be used for testing only, +it is not production ready. + +#### Mitigation (ZPages) + +Consider using a different exporter, +for example the OTLP exporter (both OTLP HTTP and OTLP GRPC are supported), +to expose trace data to a separate trace backend. + +Note that this changes the access pattern: + +* with zpages, data is only available locally (in process) +* with other exporters, data is available externally (not in process) + +Our assessment is that the zpages implementation is no longer in use, +and can be removed. + +If that assessment is incorrect (i.e., if you own a project that depends +on the zpage exporter from opentelemetry-cpp), please comment on the +removal issue +[#2292](https://github.com/open-telemetry/opentelemetry-cpp/issues/2292). + +An alternative to zpage removal is to move the code to the +opentelemetry-cpp-contrib github +[repository](https://github.com/open-telemetry/opentelemetry-cpp-contrib). + +Contributions to migrate the code, and maintain zpages, are welcome. + +#### Planned removal (ZPages) + +* Date: December, 2023 ## [Documentation] From e706b205032456ac45318e82ef89eee6723dafaa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:17:21 -0700 Subject: [PATCH 066/119] Bump docker/setup-qemu-action from 2 to 3 (#2306) --- .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 670565a943..c1fe70b308 100644 --- a/.github/workflows/dependencies_image.yml +++ b/.github/workflows/dependencies_image.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx id: buildx From 7aee911985dc36a1eb7adac65cd8e977c6dfcb30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 08:50:55 +0200 Subject: [PATCH 067/119] Bump docker/build-push-action from 4 to 5 (#2308) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v4...v5) --- 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 c1fe70b308..1e1cbdf9a4 100644 --- a/.github/workflows/dependencies_image.yml +++ b/.github/workflows/dependencies_image.yml @@ -21,7 +21,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Build Image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: builder: ${{ steps.buildx.outputs.name }} context: ci/ From f5f39343ac498fd8e4a461019ee91d0f0ca6b8d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:34:13 +0200 Subject: [PATCH 068/119] Bump docker/setup-buildx-action from 2 to 3 (#2307) Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-buildx-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 1e1cbdf9a4..2273dc66bb 100644 --- a/.github/workflows/dependencies_image.yml +++ b/.github/workflows/dependencies_image.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Build Image uses: docker/build-push-action@v5 From b9776d63d42a580941c894a8bd5c88c1a747d87d Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 14 Sep 2023 10:58:47 +0200 Subject: [PATCH 069/119] [API] Deliver ABI breaking changes (#2222) --- CMakeLists.txt | 53 ++- api/CMakeLists.txt | 4 + api/include/opentelemetry/version.h | 5 +- docs/abi-version-policy.md | 529 ++++++++++++++++++++++++++++ 4 files changed, 583 insertions(+), 8 deletions(-) create mode 100644 docs/abi-version-policy.md diff --git a/CMakeLists.txt b/CMakeLists.txt index d1b1a384a8..f579efe431 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,17 +92,54 @@ if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE) include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") endif() +option(WITH_ABI_VERSION_1 "ABI version 1" ON) +option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF) + file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" OPENTELEMETRY_CPP_HEADER_VERSION_H) -if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES - "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") - math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) -else() + +# +# We do not want to have WITH_ABI_VERSION = "1" or "2", and instead prefer two +# distinct flags, WITH_ABI_VERSION_1 and WITH_ABI_VERSION_2. +# +# This allows: +# +# * to have a specific option description for each ABI +# * to mark experimental/stable/deprecated on flags, for clarity +# * to search for exact abi usage move easily, discouraging: +# +# * cmake -DWITH_ABI_VERSION=${ARG} +# +# While not supported, having distinct WITH_ABI_VERSION_1 and WITH_ABI_VERSION_2 +# flags also opens the possibility to support multiple ABI concurrently, should +# that become necessary. +# +if(WITH_ABI_VERSION_1 AND WITH_ABI_VERSION_2) + # + # Only one ABI is supported in a build. + # message( - FATAL_ERROR - "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" - ) + FATAL_ERROR "Set either WITH_ABI_VERSION_1 or WITH_ABI_VERSION_2, not both") endif() + +if(WITH_ABI_VERSION_2) + set(OPENTELEMETRY_ABI_VERSION_NO "2") +elseif(WITH_ABI_VERSION_1) + set(OPENTELEMETRY_ABI_VERSION_NO "1") +else() + if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES + "OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?") + math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1}) + else() + message( + FATAL_ERROR + "OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" + ) + endif() +endif() + +message(STATUS "OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}") + if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES "OPENTELEMETRY_VERSION[ \t\r\n]+\"?([^\"]+)\"?") set(OPENTELEMETRY_VERSION ${CMAKE_MATCH_1}) @@ -113,6 +150,8 @@ else() ) endif() +message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}") + option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 41b6997980..f5f1fbf897 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -94,6 +94,10 @@ if(WITH_REMOVE_METER_PREVIEW) INTERFACE ENABLE_REMOVE_METER_PREVIEW) endif() +target_compile_definitions( + opentelemetry_api + INTERFACE OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}) + # A better place should be in sdk, not api if(WITH_OTLP_HTTP_SSL_PREVIEW) target_compile_definitions(opentelemetry_api diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index c44e9a3691..fd88ffb383 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -6,7 +6,10 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_ABI_VERSION_NO 1 +#ifndef OPENTELEMETRY_ABI_VERSION_NO +# define OPENTELEMETRY_ABI_VERSION_NO 1 +#endif + #define OPENTELEMETRY_VERSION "1.11.0" #define OPENTELEMETRY_VERSION_MAJOR 1 #define OPENTELEMETRY_VERSION_MINOR 11 diff --git a/docs/abi-version-policy.md b/docs/abi-version-policy.md new file mode 100644 index 0000000000..f3d66bb4f1 --- /dev/null +++ b/docs/abi-version-policy.md @@ -0,0 +1,529 @@ +# Application Binary Interface (ABI) version policy + +## Goals + +### Instrumented applications + +Once a given release of opentelemetry-cpp is published as stable, +subsequent releases are expected to provide compatibility, +to avoid disruption. + +Compatibility at the source code level (API) is expected, +so that no code change in an application already instrumented is required +to adopt a newer release. + +Also, compatibility at the binary level (ABI) is expected, +so that an instrumented application already compiled against +opentelemetry-cpp API headers from an older version, and distributed as a +binary package, can be linked against the SDK library from a newer version. + +In other words, once an application is instrumented using the +opentelemetry-cpp API, adopting a newer version: + +* should not require source code changes, +* should not require building and distributing a new package. + +### opentelemetry-cpp + +The opentelemetry-cpp project itself needs to deliver fixes and features on +a continual basis. + +Reasons to change an API can be external: + +* new APIs added in the specification, for new features +* changes in APIs in the specifications, extending existing features. + +Changes can also be caused by internal issues: + +* fix technical design issues with an API (incorrect types used, missing + parameters) + +Regardless of the root cause for a change (bug or feature), +changes to the existing APIs are unavoidable. + +For the opentelemetry-cpp project to stay healthy, +there must be a way to deliver ABI breaking fixes while preserving +compatibility for users. + +This is achieved with ABI versions. + +## Concept of ABI version + +### Inline namespaces + +For the sake of illustration, let's consider a fictitious API such as: + +```cpp +namespace opentelemetry +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + }; + } +} +``` + +An application can be instrumented to use it: + +```cpp +opentelemetry::common::OtelUtil *p = ...; +p->DoSomething(); +``` + +The problem here is that the binary package produced during the build +contains references to symbols such as: + +```cpp +opentelemetry::common::OtelUtil::DoSomething() +``` + +Because all symbols are in the same `opentelemetry::` namespace, it becomes +impossible to deliver changes (new or different symbols) while at the same +time not deliver changes (to preserve binary compatibility). + +This is resolved by the use of inline namespaces in C++, leading to +dedicated ABI versions. + +Revised example: + +```cpp +namespace opentelemetry +{ + inline namespace v1 + { + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + }; + } + } +} +``` + +```cpp +opentelemetry::common::OtelUtil *p = ...; +p->DoSomething(); +``` + +When building, the compiler translates `opentelemetry::common` to +`opentelemetry::v1::common` + +The symbols delivered by the opentelemetry library, and used by the +instrumented application, are: + +```cpp +opentelemetry::v1::common::OtelUtil::DoSomething() +``` + +With the help of the `OPENTELEMETRY_BEGIN_NAMESPACE` macro, +the source code can be abstracted to: + +```cpp +#define OPENTELEMETRY_ABI_VERSION_NO 1 + +OPENTELEMETRY_BEGIN_NAMESPACE +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + }; + } +} +OPENTELEMETRY_END_NAMESPACE +``` + +Adding a new API to the OtelUtil class is an ABI breaking change (the C++ +virtual table is different). + +This change can be delivered, but in a different namespace, which defines +a different (extended) ABI: + +```cpp +#define OPENTELEMETRY_ABI_VERSION_NO 2 + +OPENTELEMETRY_BEGIN_NAMESPACE +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + virtual void DoSomethingMore() = 0; + }; + } +} +OPENTELEMETRY_END_NAMESPACE +``` + +Compiling this declaration produce the following symbols: + +```cpp +opentelemetry::v2::common::OtelUtil::DoSomething() +opentelemetry::v2::common::OtelUtil::DoSomethingMore() +``` + +### ABI version + +By defining an inline namespace per ABI, it is possible to deliver +an ABI v2 implementation independently of ABI v1, keeping v1 unchanged. + +Code compiled against the v1 ABI can continue to link against a library +providing v1 symbols, while code compiled against the v2 ABI can link +against a library providing the v2 symbols. + +An application, when building, can choose to: + +* either build against the v1 interface +* or build against the v2 interface + +Using v1 ensures compatibility, at the API and ABI level. + +Using v2 allows to benefit from new features. + +The choice is made by the application owner when building, +and not by the opentelemetry-cpp library. + +This, in essence, describes the technical 'ABI version' building block used +to deliver breaking changes. + +How to use this versioning feature, provided by the C++ language with inline +namespaces, is described in the next section. + +## Versioning policy + +### Version scope + +Due to dependencies between classes, having an ABI version per class is not +viable. + +For example, class TracerProvider depends on +class Tracer, as it builds tracers. + +If class Tracer comes in multiple versions, +then class TracerProvider needs to also comes in multiple versions, +and these versions are correlated: + +* v1::TracerProvider creates v1::Tracer instances +* v2::TracerProvider creates v2::Tracer instances + +The next logical scope is to consider ABI versions per signal. + +This is not viable either, because of interdependencies between signals: + +* metrics can use traces in examplars +* eventually, the trace implementation can emit internal metrics +* all signals can use common utility classes + +In conclusion, the scope of a version is the entire opentelemetry-cpp project. + +### Source code + +The number of breaking change that affects an APIs is expected to be very low, +with only specific methods affected directly. + +It is very undesirable to: + +* create a different git branch per ABI version, in effect forking the + entire code base +* create a different header file per ABI version, in effect forking + the entire include headers + +just to handle a few modified APIs. + +As a result, differences between ABI versions are handled using C +preprocessor macros, in the few places where it is necessary. + +For example: + +```cpp +OPENTELEMETRY_BEGIN_NAMESPACE +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + // Added in ABI v2 + virtual void DoSomethingMore() = 0; +#endif + + }; + } +} +OPENTELEMETRY_END_NAMESPACE +``` + +The same source code, when compiled with different values of +OPENTELEMETRY_ABI_VERSION_NO, produces the proper declarations for ABI v1 or +ABI v2. + +This solution reduces the maintenance burden on the source code itself. + +## Versions lifecycle + +For a given ABI, the lifecycle is: + +* EXPERIMENTAL +* STABLE +* DEPRECATED +* REMOVED + +In the EXPERIMENTAL status, +any change to the ABI can be implemented, without notice. + +There are no compatibility guarantees. +This status is meant as a preview, until the ABI is declared STABLE. + +In the STABLE status, +changes to the ABI are forbidden, to guarantee stability. + +In the DEPRECATED status, the ABI is still functional and supported, +but instrumented applications are encouraged to migrate to a newer ABI. + +In the REMOVED status, +the given ABI is no longer available. + +The following sections describe the migration path from one ABI (v1) to the +next (v2). + +### STABLE V1 + +In this state, only one ABI version is available, and it is closed to +changes. + +Instrumented applications are built against ABI v1 by default. + +opentelemetry-cpp produces a library for ABI v1 by default. + +Fixes introducing breaking changes can __not__ be delivered. + +This is the current status as of opentelemetry-cpp version 1.11.0 + +### STABLE V1, EXPERIMENTAL V2 + +In this state, two ABI versions are available. + +CMake offers the following options: + +```cmake +option(WITH_ABI_VERSION_1 "ABI version 1" ON) +option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF) +``` + +Instrumented applications are built against ABI v1 by default, +but may ask to use ABI v2 instead. + +opentelemetry-cpp produces a library for stable ABI v1 by default, +but can be configured to provide experimental ABI v2 instead. + +Fixes introducing breaking changes can only be delivered in the experimental +ABI v2. + +### STABLE V1, STABLE V2, EXPERIMENTAL V3 + +In this state, two stable ABI versions are available, +the ABI offered by default is the conservative ABI v1. + +Fixes introducing breaking changes can no longer be delivered in ABI v2, +because it is declared stable. +An experimental ABI v3 is created. + +CMake offers the following options: + +```cmake +option(WITH_ABI_VERSION_1 "ABI version 1" ON) +option(WITH_ABI_VERSION_2 "ABI version 2" OFF) +option(WITH_ABI_VERSION_3 "EXPERIMENTAL: ABI version 3 preview" OFF) +``` + +Instrumented applications are built against stable ABI v1 by default, +but may ask to use the now stable ABI v2 instead. + +opentelemetry-cpp produces a library for ABI v1 by default, +but can be configured to provide ABI v2 instead. + +Fixes introducing breaking changes can only be delivered in the experimental +ABI v3. + +### DEPRECATED V1, STABLE V2, EXPERIMENTAL V3 + +In this state, two stable ABI versions are available, +the ABI offered by default is the newer ABI v2. + +CMake offers the following options: + +```cmake +option(WITH_ABI_VERSION_1 "DEPRECATED: ABI version 1" OFF) +option(WITH_ABI_VERSION_2 "ABI version 2" ON) +option(WITH_ABI_VERSION_3 "EXPERIMENTAL: ABI version 3 preview" OFF) +``` + +Instrumented applications are built against stable ABI v2 by default, +but may ask to use stable ABI v1 instead. + +opentelemetry-cpp produces a library for ABI v2 by default, +but can be configured to provide ABI v1 instead. + +Fixes introducing breaking changes can only be delivered in the experimental +ABI v3. + +### (REMOVED V1), STABLE V2, EXPERIMENTAL V3 + +In this state, the only stable ABI available is v2. +ABI v1 is no longer supported. + +CMake offers the following options: + +```cmake +option(WITH_ABI_VERSION_2 "ABI version 2" ON) +option(WITH_ABI_VERSION_3 "EXPERIMENTAL: ABI version 3 preview" OFF) +``` + +Instrumented applications and the opentelemetry-cpp library are build using +ABI v2. + +Now that ABI v1 no longer exists, the code: + +```cpp +OPENTELEMETRY_BEGIN_NAMESPACE +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + // Added in ABI v2 + virtual void DoSomethingMore() = 0; +#endif + + }; + } +} +OPENTELEMETRY_END_NAMESPACE +``` + +can be simplified to: + +```cpp +OPENTELEMETRY_BEGIN_NAMESPACE +{ + namespace common + { + class OtelUtil + { + virtual void DoSomething() = 0; + virtual void DoSomethingMore() = 0; + }; + } +} +OPENTELEMETRY_END_NAMESPACE +``` + +## Practical Example + +### Fixing issue #2033 + +The problem is to change the MeterProvider::GetMeter() prototype, +to follow specification changes. + +See the issue description for all details: + +* [Metrics API/SDK] + Add InstrumentationScope attributes in MeterProvider::GetMeter() #2033 + +#### API change + +In the API, class MeterProvider is changed as follows: + +```cpp +class MeterProvider +{ +public: + virtual ~MeterProvider() = default; + /** + * Gets or creates a named Meter instance. + * + * Optionally a version can be passed to create a named and versioned Meter + * instance. + */ +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "", + const common::KeyValueIterable *attributes = nullptr) noexcept = 0; +#else + virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif + + /* ... */ +}; + +``` + +Note how the ABI changes, while the API stays compatible, requiring no code +change in the caller when providing up to 3 parameters. + +#### SDK change + +In the SDK class declaration, implement the expected API. + +```cpp +class MeterProvider final : public opentelemetry::metrics::MeterProvider +{ +public: + + /* ... */ + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetMeter( + nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "", + const opentelemetry::common::KeyValueIterable *attributes = nullptr) noexcept override; +#else + nostd::shared_ptr GetMeter( + nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") noexcept override; +#endif + + /* ... */ +}; +``` + +In the SDK implementation: + +* either get the new parameters from the extended ABI v2 method +* or provide default values for the old ABI v1 method + +```cpp +nostd::shared_ptr MeterProvider::GetMeter( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + , + const opentelemetry::common::KeyValueIterable *attributes +#endif + ) noexcept +{ +#if OPENTELEMETRY_ABI_VERSION_NO < 2 + const opentelemetry::common::KeyValueIterable *attributes = nullptr; +#endif + + /* common implementation, use attributes */ +} +``` From 44096c8072ab45e8409d73931a33c87d2fbedaa3 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 14 Sep 2023 18:44:01 +0200 Subject: [PATCH 070/119] [SDK] Allow metric instrument names to contain / characters (#2310) --- sdk/src/metrics/instrument_metadata_validator.cc | 12 +++++++----- .../metrics/instrument_metadata_validator_test.cc | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sdk/src/metrics/instrument_metadata_validator.cc b/sdk/src/metrics/instrument_metadata_validator.cc index aba6344efc..ff963c3dd1 100644 --- a/sdk/src/metrics/instrument_metadata_validator.cc +++ b/sdk/src/metrics/instrument_metadata_validator.cc @@ -17,8 +17,8 @@ namespace sdk { namespace metrics { -// instrument-name = ALPHA 0*254 ("_" / "." / "-" / ALPHA / DIGIT) -const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,254}"; +// instrument-name = ALPHA 0*254 ("_" / "." / "-" / "/" / ALPHA / DIGIT) +const std::string kInstrumentNamePattern = "[a-zA-Z][-_./a-zA-Z0-9]{0,254}"; // const std::string kInstrumentUnitPattern = "[\x01-\x7F]{0,63}"; // instrument-unit = It can have a maximum length of 63 ASCII chars @@ -49,9 +49,11 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const { return false; } - // subsequent chars should be either of alphabets, digits, underscore, minus, dot - return !std::any_of(std::next(name.begin()), name.end(), - [](char c) { return !isalnum(c) && c != '-' && c != '_' && c != '.'; }); + // subsequent chars should be either of alphabets, digits, underscore, + // minus, dot, slash + return !std::any_of(std::next(name.begin()), name.end(), [](char c) { + return !isalnum(c) && (c != '-') && (c != '_') && (c != '.') && (c != '/'); + }); #endif } diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 0f9e7134a7..17b76a9419 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -24,6 +24,7 @@ TEST(InstrumentMetadataValidator, TestName) "123€AAA€BBB", // 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 }; @@ -37,6 +38,7 @@ TEST(InstrumentMetadataValidator, TestName) "s123", // starting with char, followed by numbers "dsdsdsd_-.", // string , and valid nonalphanumeric "d1234_-sDSDs.sdsd344", // combination of all valid characters + "a/path/to/some/metric", // contains forward slash CreateVeryLargeString(5) + "ABCERTYG", // total 63 characters CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 characters CreateVeryLargeString(24) + "ABCDEFGHI", // total 254 characters From f5c00160c4944f8b8812a907121a836f0f8e3bbf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:02:17 +0200 Subject: [PATCH 071/119] Bump codecov/codecov-action from 3 to 4 (#2314) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-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/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d8db91364..984fae790c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -810,7 +810,7 @@ jobs: CXX: /usr/bin/g++-10 run: ./ci/do_ci.sh code.coverage - name: upload report - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: /home/runner/build/coverage.info From 049f7e8a19bf0a0ff3e6a748f6556f2fac7bb180 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 16 Sep 2023 17:07:30 +0200 Subject: [PATCH 072/119] Revert "Bump codecov/codecov-action from 3 to 4 (#2314)" (#2315) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 984fae790c..2d8db91364 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -810,7 +810,7 @@ jobs: CXX: /usr/bin/g++-10 run: ./ci/do_ci.sh code.coverage - name: upload report - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v3 with: file: /home/runner/build/coverage.info From 0563a71ce3ea2c580f535996aeb8ce9246f2d703 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 18 Sep 2023 12:57:28 -0700 Subject: [PATCH 073/119] Fix Observable Counters/UpDownCounters (#2298) --- .../metrics/aggregation/default_aggregation.h | 47 ++++++--- sdk/test/metrics/async_metric_storage_test.cc | 95 +++++++++++++++++++ 2 files changed, 130 insertions(+), 12 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 203a2d32b9..6ae111fd85 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -28,20 +28,16 @@ class DefaultAggregation const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor, const AggregationConfig *aggregation_config) { - switch (instrument_descriptor.type_) + bool is_monotonic = true; + auto aggr_type = GetDefaultAggregationType(instrument_descriptor.type_, is_monotonic); + switch (aggr_type) { - case InstrumentType::kCounter: - case InstrumentType::kObservableCounter: + case AggregationType::kSum: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) - ? std::move(std::unique_ptr(new LongSumAggregation(true))) + ? std::move(std::unique_ptr(new LongSumAggregation(is_monotonic))) : std::move(std::unique_ptr(new DoubleSumAggregation(true))); - case InstrumentType::kUpDownCounter: - case InstrumentType::kObservableUpDownCounter: - return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) - ? std::move(std::unique_ptr(new LongSumAggregation(false))) - : std::move(std::unique_ptr(new DoubleSumAggregation(false))); break; - case InstrumentType::kHistogram: { + case AggregationType::kHistogram: { if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) { return (std::unique_ptr(new LongHistogramAggregation(aggregation_config))); @@ -53,7 +49,7 @@ class DefaultAggregation break; } - case InstrumentType::kObservableGauge: + case AggregationType::kLastValue: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) ? std::move(std::unique_ptr(new LongLastValueAggregation())) : std::move(std::unique_ptr(new DoubleLastValueAggregation())); @@ -121,6 +117,11 @@ class DefaultAggregation const Aggregation &to_copy) { const PointType point_data = to_copy.ToPoint(); + bool is_monotonic = true; + if (aggregation_type == AggregationType::kDefault) + { + aggregation_type = GetDefaultAggregationType(instrument_descriptor.type_, is_monotonic); + } switch (aggregation_type) { case AggregationType::kDrop: @@ -159,7 +160,29 @@ class DefaultAggregation new DoubleSumAggregation(nostd::get(point_data))); } default: - return DefaultAggregation::CreateAggregation(instrument_descriptor, nullptr); + return nullptr; // won't reach here + } + } + + static AggregationType GetDefaultAggregationType(InstrumentType instrument_type, + bool &is_monotonic) + { + is_monotonic = false; + switch (instrument_type) + { + case InstrumentType::kCounter: + case InstrumentType::kObservableCounter: + is_monotonic = true; + return AggregationType::kSum; + case InstrumentType::kUpDownCounter: + case InstrumentType::kObservableUpDownCounter: + return AggregationType::kSum; + case InstrumentType::kHistogram: + return AggregationType::kHistogram; + case InstrumentType::kObservableGauge: + return AggregationType::kLastValue; + default: + return AggregationType::kDrop; } } }; diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 0ce91dafe1..1fef4e9de3 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -30,6 +30,10 @@ using M = std::map; class WritableMetricStorageTestFixture : public ::testing::TestWithParam {}; +class WritableMetricStorageTestUpDownFixture + : public ::testing::TestWithParam +{}; + class WritableMetricStorageTestObservableGaugeFixture : public ::testing::TestWithParam {}; @@ -124,6 +128,97 @@ INSTANTIATE_TEST_SUITE_P(WritableMetricStorageTestLong, ::testing::Values(AggregationTemporality::kCumulative, AggregationTemporality::kDelta)); +TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation) +{ + AggregationTemporality temporality = GetParam(); + + InstrumentDescriptor instr_desc = {"name", "desc", "1unit", + InstrumentType::kObservableUpDownCounter, + InstrumentValueType::kLong}; + + auto sdk_start_ts = std::chrono::system_clock::now(); + // Some computation here + auto collection_ts = std::chrono::system_clock::now() + std::chrono::seconds(5); + + std::shared_ptr collector(new MockCollectorHandle(temporality)); + std::vector> collectors; + collectors.push_back(collector); + + opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kDefault, + nullptr); + int64_t get_count1 = 20; + int64_t put_count1 = 10; + std::unordered_map measurements1 = { + {{{"RequestType", "GET"}}, get_count1}, {{{"RequestType", "PUT"}}, put_count1}}; + storage.RecordLong(measurements1, + opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); + + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { + for (const auto &data_attr : metric_data.point_data_attr_) + { + const auto &data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count1); + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count1); + } + } + return true; + }); + // subsequent recording after collection shouldn't fail + // monotonic increasing values; + int64_t get_count2 = -50; + int64_t put_count2 = -70; + + std::unordered_map measurements2 = { + {{{"RequestType", "GET"}}, get_count2}, {{{"RequestType", "PUT"}}, put_count2}}; + 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) { + for (const auto &data_attr : metric_data.point_data_attr_) + { + const auto &data = opentelemetry::nostd::get(data_attr.point_data); + if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "GET") + { + if (temporality == AggregationTemporality::kCumulative) + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2); + } + else + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2 - get_count1); + } + } + else if (opentelemetry::nostd::get( + data_attr.attributes.find("RequestType")->second) == "PUT") + { + if (temporality == AggregationTemporality::kCumulative) + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2); + } + else + { + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2 - put_count1); + } + } + } + return true; + }); +} + +INSTANTIATE_TEST_SUITE_P(WritableMetricStorageTestUpDownLong, + WritableMetricStorageTestUpDownFixture, + ::testing::Values(AggregationTemporality::kCumulative, + AggregationTemporality::kDelta)); + TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) { AggregationTemporality temporality = GetParam(); From 13f01cae932b2f73eb9eba7631ca257d729bb66f Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 21 Sep 2023 13:41:18 -0700 Subject: [PATCH 074/119] Add exemplar reservoir to async metric storage (#2319) --- .../sdk/metrics/state/async_metric_storage.h | 14 ++++++++++++++ sdk/src/metrics/meter.cc | 3 ++- sdk/test/metrics/async_metric_storage_test.cc | 14 ++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h index aada06142a..6a01d5c7f0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -10,6 +10,7 @@ #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/common/attributemap_hash.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +#include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/observer_result.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" @@ -29,11 +30,16 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora public: AsyncMetricStorage(InstrumentDescriptor instrument_descriptor, const AggregationType aggregation_type, + nostd::shared_ptr &&exemplar_reservoir + OPENTELEMETRY_MAYBE_UNUSED, const AggregationConfig *aggregation_config) : instrument_descriptor_(instrument_descriptor), aggregation_type_{aggregation_type}, cumulative_hash_map_(new AttributesHashMap()), delta_hash_map_(new AttributesHashMap()), +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW + exemplar_reservoir_(exemplar_reservoir), +#endif temporal_metric_storage_(instrument_descriptor, aggregation_type, aggregation_config) {} @@ -47,6 +53,11 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora std::lock_guard guard(hashmap_lock_); for (auto &measurement : measurements) { +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW + exemplar_reservoir_->OfferMeasurement(measurement.second, {}, {}, + std::chrono::system_clock::now()); +#endif + auto aggr = DefaultAggregation::CreateAggregation(aggregation_type_, instrument_descriptor_); aggr->Aggregate(measurement.second); auto hash = opentelemetry::sdk::common::GetHashForAttributeMap(measurement.first); @@ -119,6 +130,9 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora std::unique_ptr cumulative_hash_map_; std::unique_ptr delta_hash_map_; opentelemetry::common::SpinLockMutex hashmap_lock_; +#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW + nostd::shared_ptr exemplar_reservoir_; +#endif TemporalMetricStorage temporal_metric_storage_; }; diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 6b8b6c8925..1abb570b43 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -368,7 +368,8 @@ std::unique_ptr Meter::RegisterAsyncMetricStorage( view_instr_desc.description_ = view.GetDescription(); } auto storage = std::shared_ptr(new AsyncMetricStorage( - view_instr_desc, view.GetAggregationType(), view.GetAggregationConfig())); + view_instr_desc, view.GetAggregationType(), ExemplarReservoir::GetNoExemplarReservoir(), + view.GetAggregationConfig())); storage_registry_[instrument_descriptor.name_] = storage; static_cast(storages.get())->AddStorage(storage); return true; diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 1fef4e9de3..7b43fea14d 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -5,6 +5,7 @@ #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/sdk/metrics/async_instruments.h" +#include "opentelemetry/sdk/metrics/exemplar/reservoir.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/meter_context.h" #include "opentelemetry/sdk/metrics/metric_reader.h" @@ -53,8 +54,8 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) std::vector> collectors; collectors.push_back(collector); - opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kSum, - nullptr); + opentelemetry::sdk::metrics::AsyncMetricStorage storage( + instr_desc, AggregationType::kSum, ExemplarReservoir::GetNoExemplarReservoir(), nullptr); int64_t get_count1 = 20; int64_t put_count1 = 10; std::unordered_map measurements1 = { @@ -144,8 +145,8 @@ TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation) std::vector> collectors; collectors.push_back(collector); - opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kDefault, - nullptr); + opentelemetry::sdk::metrics::AsyncMetricStorage storage( + instr_desc, AggregationType::kDefault, ExemplarReservoir::GetNoExemplarReservoir(), nullptr); int64_t get_count1 = 20; int64_t put_count1 = 10; std::unordered_map measurements1 = { @@ -234,8 +235,9 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) std::vector> collectors; collectors.push_back(collector); - opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kLastValue, - nullptr); + opentelemetry::sdk::metrics::AsyncMetricStorage storage( + instr_desc, AggregationType::kLastValue, ExemplarReservoir::GetNoExemplarReservoir(), + nullptr); int64_t freq_cpu0 = 3; int64_t freq_cpu1 = 5; std::unordered_map measurements1 = { From ca67af031b77c28b569747cd3ce84e4424fa7a29 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Fri, 22 Sep 2023 02:37:58 -0400 Subject: [PATCH 075/119] Fix lifetime issues in test utils (#2322) --- exporters/prometheus/test/collector_test.cc | 4 +- .../prometheus/test/exporter_utils_test.cc | 10 +- .../prometheus/test/prometheus_test_helper.h | 220 +++++++++--------- 3 files changed, 115 insertions(+), 119 deletions(-) diff --git a/exporters/prometheus/test/collector_test.cc b/exporters/prometheus/test/collector_test.cc index d422c45c5b..8947dcfd27 100644 --- a/exporters/prometheus/test/collector_test.cc +++ b/exporters/prometheus/test/collector_test.cc @@ -19,6 +19,8 @@ namespace metric_exporter = opentelemetry::exporter::metrics; class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer { + TestDataPoints test_data_points_; + public: MockMetricProducer(std::chrono::microseconds sleep_ms = std::chrono::microseconds::zero()) : sleep_ms_{sleep_ms}, data_sent_size_(0) @@ -28,7 +30,7 @@ class MockMetricProducer : public opentelemetry::sdk::metrics::MetricProducer { std::this_thread::sleep_for(sleep_ms_); data_sent_size_++; - ResourceMetrics data = CreateSumPointData(); + ResourceMetrics data = test_data_points_.CreateSumPointData(); callback(data); return true; } diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 2eac7a6d8b..2222787787 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -106,8 +106,8 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusEmptyInputReturnsEmptyCollect TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) { - - metric_sdk::ResourceMetrics metrics_data = CreateSumPointData(); + TestDataPoints dp; + metric_sdk::ResourceMetrics metrics_data = dp.CreateSumPointData(); auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); @@ -120,7 +120,8 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) { - metric_sdk::ResourceMetrics metrics_data = CreateLastValuePointData(); + TestDataPoints dp; + metric_sdk::ResourceMetrics metrics_data = dp.CreateLastValuePointData(); auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); @@ -133,7 +134,8 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) { - metric_sdk::ResourceMetrics metrics_data = CreateHistogramPointData(); + TestDataPoints dp; + metric_sdk::ResourceMetrics metrics_data = dp.CreateHistogramPointData(); auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); diff --git a/exporters/prometheus/test/prometheus_test_helper.h b/exporters/prometheus/test/prometheus_test_helper.h index 4743e032bd..d42f66c6eb 100644 --- a/exporters/prometheus/test/prometheus_test_helper.h +++ b/exporters/prometheus/test/prometheus_test_helper.h @@ -11,124 +11,116 @@ namespace exportermetrics = opentelemetry::exporter::metrics; namespace { -/** - * Helper function to create ResourceMetrics - */ -inline metric_sdk::ResourceMetrics CreateSumPointData() -{ - metric_sdk::SumPointData sum_point_data{}; - sum_point_data.value_ = 10.0; - metric_sdk::SumPointData sum_point_data2{}; - sum_point_data2.value_ = 20.0; - metric_sdk::ResourceMetrics data; - auto resource = opentelemetry::sdk::resource::Resource::Create( - opentelemetry::sdk::resource::ResourceAttributes{}); - data.resource_ = &resource; - auto instrumentation_scope = - opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", - "1.2.0"); - metric_sdk::MetricData metric_data{ - metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", - metric_sdk::InstrumentType::kCounter, - metric_sdk::InstrumentValueType::kDouble}, - metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, - opentelemetry::common::SystemTimestamp{}, - std::vector{ - {metric_sdk::PointAttributes{{"a1", "b1"}}, sum_point_data}, - {metric_sdk::PointAttributes{{"a2", "b2"}}, sum_point_data2}}}; - data.scope_metric_data_ = std::vector{ - {instrumentation_scope.get(), std::vector{metric_data}}}; - return data; -} -inline metric_sdk::ResourceMetrics CreateHistogramPointData() -{ - metric_sdk::HistogramPointData histogram_point_data{}; - histogram_point_data.boundaries_ = {10.1, 20.2, 30.2}; - histogram_point_data.count_ = 3; - histogram_point_data.counts_ = {200, 300, 400, 500}; - histogram_point_data.sum_ = 900.5; - metric_sdk::HistogramPointData histogram_point_data2{}; - histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; - histogram_point_data2.count_ = 3; - histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = (int64_t)900; - metric_sdk::ResourceMetrics data; - auto resource = opentelemetry::sdk::resource::Resource::Create( - opentelemetry::sdk::resource::ResourceAttributes{}); - data.resource_ = &resource; - auto instrumentation_scope = - opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", - "1.2.0"); - metric_sdk::MetricData metric_data{ - metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", - metric_sdk::InstrumentType::kHistogram, - metric_sdk::InstrumentValueType::kDouble}, - metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, - opentelemetry::common::SystemTimestamp{}, - std::vector{ - {metric_sdk::PointAttributes{{"a1", "b1"}}, histogram_point_data}, - {metric_sdk::PointAttributes{{"a2", "b2"}}, histogram_point_data2}}}; - data.scope_metric_data_ = std::vector{ - {instrumentation_scope.get(), std::vector{metric_data}}}; - return data; -} +using opentelemetry::sdk::instrumentationscope::InstrumentationScope; +using opentelemetry::sdk::resource::Resource; +using opentelemetry::sdk::resource::ResourceAttributes; -inline metric_sdk::ResourceMetrics CreateLastValuePointData() +struct TestDataPoints { - metric_sdk::ResourceMetrics data; - auto resource = opentelemetry::sdk::resource::Resource::Create( - opentelemetry::sdk::resource::ResourceAttributes{}); - data.resource_ = &resource; - auto instrumentation_scope = - opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", - "1.2.0"); - metric_sdk::LastValuePointData last_value_point_data{}; - last_value_point_data.value_ = 10.0; - last_value_point_data.is_lastvalue_valid_ = true; - last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; - metric_sdk::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = (int64_t)20; - last_value_point_data2.is_lastvalue_valid_ = true; - last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; - metric_sdk::MetricData metric_data{ - metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", - metric_sdk::InstrumentType::kCounter, - metric_sdk::InstrumentValueType::kDouble}, - metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, - opentelemetry::common::SystemTimestamp{}, - std::vector{ - {metric_sdk::PointAttributes{{"a1", "b1"}}, last_value_point_data}, - {metric_sdk::PointAttributes{{"a2", "b2"}}, last_value_point_data2}}}; - data.scope_metric_data_ = std::vector{ - {instrumentation_scope.get(), std::vector{metric_data}}}; - return data; -} + Resource resource = Resource::Create(ResourceAttributes{}); + nostd::unique_ptr instrumentation_scope = + InstrumentationScope::Create("library_name", "1.2.0"); -inline metric_sdk::ResourceMetrics CreateDropPointData() -{ - metric_sdk::ResourceMetrics data; - auto resource = opentelemetry::sdk::resource::Resource::Create( - opentelemetry::sdk::resource::ResourceAttributes{}); - data.resource_ = &resource; - auto instrumentation_scope = - opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", - "1.2.0"); - metric_sdk::DropPointData drop_point_data{}; - metric_sdk::DropPointData drop_point_data2{}; - metric_sdk::MetricData metric_data{ - metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", - metric_sdk::InstrumentType::kCounter, - metric_sdk::InstrumentValueType::kDouble}, - metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, - opentelemetry::common::SystemTimestamp{}, - std::vector{ - {metric_sdk::PointAttributes{{"a1", "b1"}}, drop_point_data}, - {metric_sdk::PointAttributes{{"a2", "b2"}}, drop_point_data2}}}; - data.scope_metric_data_ = std::vector{ - {instrumentation_scope.get(), std::vector{metric_data}}}; - return data; -} + /** + * Helper function to create ResourceMetrics + */ + inline metric_sdk::ResourceMetrics CreateSumPointData() + { + metric_sdk::SumPointData sum_point_data{}; + sum_point_data.value_ = 10.0; + metric_sdk::SumPointData sum_point_data2{}; + sum_point_data2.value_ = 20.0; + metric_sdk::ResourceMetrics data; + data.resource_ = &resource; + metric_sdk::MetricData metric_data{ + metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", + metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}, + metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, + opentelemetry::common::SystemTimestamp{}, + std::vector{ + {metric_sdk::PointAttributes{{"a1", "b1"}}, sum_point_data}, + {metric_sdk::PointAttributes{{"a2", "b2"}}, sum_point_data2}}}; + data.scope_metric_data_ = std::vector{ + {instrumentation_scope.get(), std::vector{metric_data}}}; + return data; + } + + inline metric_sdk::ResourceMetrics CreateHistogramPointData() + { + metric_sdk::HistogramPointData histogram_point_data{}; + histogram_point_data.boundaries_ = {10.1, 20.2, 30.2}; + histogram_point_data.count_ = 3; + histogram_point_data.counts_ = {200, 300, 400, 500}; + histogram_point_data.sum_ = 900.5; + metric_sdk::HistogramPointData histogram_point_data2{}; + histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; + histogram_point_data2.count_ = 3; + histogram_point_data2.counts_ = {200, 300, 400, 500}; + histogram_point_data2.sum_ = (int64_t)900; + metric_sdk::ResourceMetrics data; + data.resource_ = &resource; + metric_sdk::MetricData metric_data{ + metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", + metric_sdk::InstrumentType::kHistogram, + metric_sdk::InstrumentValueType::kDouble}, + metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, + opentelemetry::common::SystemTimestamp{}, + std::vector{ + {metric_sdk::PointAttributes{{"a1", "b1"}}, histogram_point_data}, + {metric_sdk::PointAttributes{{"a2", "b2"}}, histogram_point_data2}}}; + data.scope_metric_data_ = std::vector{ + {instrumentation_scope.get(), std::vector{metric_data}}}; + return data; + } + + inline metric_sdk::ResourceMetrics CreateLastValuePointData() + { + metric_sdk::ResourceMetrics data; + data.resource_ = &resource; + metric_sdk::LastValuePointData last_value_point_data{}; + last_value_point_data.value_ = 10.0; + last_value_point_data.is_lastvalue_valid_ = true; + last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; + metric_sdk::LastValuePointData last_value_point_data2{}; + last_value_point_data2.value_ = (int64_t)20; + last_value_point_data2.is_lastvalue_valid_ = true; + last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; + metric_sdk::MetricData metric_data{ + metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", + metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}, + metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, + opentelemetry::common::SystemTimestamp{}, + std::vector{ + {metric_sdk::PointAttributes{{"a1", "b1"}}, last_value_point_data}, + {metric_sdk::PointAttributes{{"a2", "b2"}}, last_value_point_data2}}}; + data.scope_metric_data_ = std::vector{ + {instrumentation_scope.get(), std::vector{metric_data}}}; + return data; + } + + inline metric_sdk::ResourceMetrics CreateDropPointData() + { + metric_sdk::ResourceMetrics data; + data.resource_ = &resource; + metric_sdk::DropPointData drop_point_data{}; + metric_sdk::DropPointData drop_point_data2{}; + metric_sdk::MetricData metric_data{ + metric_sdk::InstrumentDescriptor{"library_name", "description", "unit", + metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}, + metric_sdk::AggregationTemporality::kDelta, opentelemetry::common::SystemTimestamp{}, + opentelemetry::common::SystemTimestamp{}, + std::vector{ + {metric_sdk::PointAttributes{{"a1", "b1"}}, drop_point_data}, + {metric_sdk::PointAttributes{{"a2", "b2"}}, drop_point_data2}}}; + data.scope_metric_data_ = std::vector{ + {instrumentation_scope.get(), std::vector{metric_data}}}; + return data; + } +}; } // namespace OPENTELEMETRY_BEGIN_NAMESPACE From 41a7875ef81960a994eae557d139d54bdb54d7a7 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Sat, 23 Sep 2023 06:02:09 -0400 Subject: [PATCH 076/119] [exporters/prometheus] Remove explicit timestamps from metric points (#2324) Fixes #2316 --- CHANGELOG.md | 2 ++ .../exporters/prometheus/exporter_utils.h | 3 --- exporters/prometheus/src/exporter_utils.cc | 20 +++++++------------ .../prometheus/test/exporter_utils_test.cc | 6 ++++++ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f09553ce70..5b2e80326e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ Increment the: * [DEPRECATION] Deprecate ZPAGES [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) +* [EXPORTER] Remove explicit timestamps from metric points exported by Prometheus + [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) ## [1.11.0] 2023-08-21 diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index ce7f0a1191..cb7da0b2b5 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -58,7 +58,6 @@ class PrometheusExporterUtils static void SetData(std::vector values, const opentelemetry::sdk::metrics::PointAttributes &labels, ::prometheus::MetricType type, - std::chrono::nanoseconds time, ::prometheus::MetricFamily *metric_family); /** @@ -70,14 +69,12 @@ class PrometheusExporterUtils const std::vector &boundaries, const std::vector &counts, const opentelemetry::sdk::metrics::PointAttributes &labels, - std::chrono::nanoseconds time, ::prometheus::MetricFamily *metric_family); /** * Set time and labels to metric data */ static void SetMetricBasic(::prometheus::ClientMetric &metric, - std::chrono::nanoseconds time, const opentelemetry::sdk::metrics::PointAttributes &labels); /** diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 966d665df6..e912256e4f 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -44,7 +44,6 @@ std::vector PrometheusExporterUtils::TranslateT prometheus_client::MetricFamily metric_family; metric_family.name = sanitized + "_" + unit; metric_family.help = metric_data.instrument_descriptor.description_; - auto time = metric_data.end_ts.time_since_epoch(); for (const auto &point_data_attr : metric_data.point_data_attr_) { auto kind = getAggregationType(point_data_attr.point_data); @@ -72,7 +71,7 @@ std::vector PrometheusExporterUtils::TranslateT sum = nostd::get(histogram_point_data.sum_); } SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, - point_data_attr.attributes, time, &metric_family); + point_data_attr.attributes, &metric_family); } else if (type == prometheus_client::MetricType::Gauge) { @@ -82,14 +81,14 @@ std::vector PrometheusExporterUtils::TranslateT auto last_value_point_data = nostd::get(point_data_attr.point_data); std::vector values{last_value_point_data.value_}; - SetData(values, point_data_attr.attributes, type, time, &metric_family); + SetData(values, point_data_attr.attributes, type, &metric_family); } else if (nostd::holds_alternative(point_data_attr.point_data)) { auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, type, time, &metric_family); + SetData(values, point_data_attr.attributes, type, &metric_family); } else { @@ -105,7 +104,7 @@ std::vector PrometheusExporterUtils::TranslateT auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, type, time, &metric_family); + SetData(values, point_data_attr.attributes, type, &metric_family); } else { @@ -228,12 +227,11 @@ template void PrometheusExporterUtils::SetData(std::vector values, const metric_sdk::PointAttributes &labels, prometheus_client::MetricType type, - std::chrono::nanoseconds time, prometheus_client::MetricFamily *metric_family) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, time, labels); + SetMetricBasic(metric, labels); SetValue(values, type, &metric); } @@ -246,24 +244,20 @@ void PrometheusExporterUtils::SetData(std::vector values, const std::vector &boundaries, const std::vector &counts, const metric_sdk::PointAttributes &labels, - std::chrono::nanoseconds time, prometheus_client::MetricFamily *metric_family) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, time, labels); + SetMetricBasic(metric, labels); SetValue(values, boundaries, counts, &metric); } /** - * Set time and labels to metric data + * Set labels to metric data */ void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &metric, - std::chrono::nanoseconds time, const metric_sdk::PointAttributes &labels) { - metric.timestamp_ms = time.count() / 1000000; - // auto label_pairs = ParseLabel(labels); if (!labels.empty()) { diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 2222787787..ac9ed4545f 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -42,6 +42,12 @@ void assert_basic(prometheus_client::MetricFamily &metric, ASSERT_EQ(metric.help, description); // description not changed ASSERT_EQ(metric.type, type); // type translated + // Prometheus metric data points should not have explicit timestamps + for (const prometheus::ClientMetric &cm : metric.metric) + { + ASSERT_EQ(cm.timestamp_ms, 0); + } + auto metric_data = metric.metric[0]; ASSERT_EQ(metric_data.label.size(), label_num); From 61e7429d6362bd2dc166ca81f0cb28963eac0ee8 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Sun, 24 Sep 2023 11:27:22 -0400 Subject: [PATCH 077/119] [exporters/prometheus] Handle attribute key collisions from sanitation (#2326) Fixes #2290 --- CHANGELOG.md | 2 + exporters/prometheus/src/exporter_utils.cc | 37 ++++++++++++++---- .../prometheus/test/exporter_utils_test.cc | 38 +++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2e80326e..38a077e7d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ Increment the: [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) * [EXPORTER] Remove explicit timestamps from metric points exported by Prometheus [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) +* [EXPORTER] Handle attribute key collisions caused by sanitation + [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) ## [1.11.0] 2023-08-21 diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index e912256e4f..149d93290b 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -258,16 +258,37 @@ void PrometheusExporterUtils::SetData(std::vector values, void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &metric, const metric_sdk::PointAttributes &labels) { - // auto label_pairs = ParseLabel(labels); - if (!labels.empty()) + if (labels.empty()) { - metric.label.resize(labels.size()); - size_t i = 0; - for (auto const &label : labels) + return; + } + + // Concatenate values for keys that collide after sanitation. + // Note that attribute keys are sorted, but sanitized keys can be out-of-order. + // We could sort the sanitized keys again, but this seems too expensive to do + // in this hot code path. Instead, we ignore out-of-order keys and emit a warning. + metric.label.reserve(labels.size()); + std::string previous_key; + for (auto const &label : labels) + { + auto sanitized = SanitizeNames(label.first); + int comparison = previous_key.compare(sanitized); + if (metric.label.empty() || comparison < 0) // new key + { + previous_key = sanitized; + metric.label.push_back({sanitized, AttributeValueToString(label.second)}); + } + else if (comparison == 0) // key collision after sanitation + { + metric.label.back().value += ";" + AttributeValueToString(label.second); + } + else // order inversion introduced by sanitation { - auto sanitized = SanitizeNames(label.first); - metric.label[i].name = sanitized; - metric.label[i++].value = AttributeValueToString(label.second); + OTEL_INTERNAL_LOG_WARN( + "[Prometheus Exporter] SetMetricBase - " + "the sort order of labels has changed because of sanitization: '" + << label.first << "' became '" << sanitized << "' which is less than '" << previous_key + << "'. Ignoring this label."); } } } diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index ac9ed4545f..0c08e2ffa7 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -163,4 +163,42 @@ TEST(PrometheusExporterUtils, SanitizeName) ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name:"), "name_name:"); } +class AttributeCollisionTest : public ::testing::Test +{ + Resource resource_ = Resource::Create(ResourceAttributes{}); + nostd::unique_ptr instrumentation_scope_ = + InstrumentationScope::Create("library_name", "1.2.0"); + metric_sdk::InstrumentDescriptor instrument_descriptor_{"library_name", "description", "unit", + metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}; + +protected: + void CheckTranslation(const metric_sdk::PointAttributes &attrs, + const std::vector &expected) + { + std::vector result = PrometheusExporterUtils::TranslateToPrometheus( + {&resource_, + {{instrumentation_scope_.get(), {{instrument_descriptor_, {}, {}, {}, {{attrs, {}}}}}}}}); + EXPECT_EQ(result.begin()->metric.begin()->label, expected); + } +}; + +TEST_F(AttributeCollisionTest, SeparatesDistinctKeys) +{ + CheckTranslation({{"foo.a", "value1"}, {"foo.b", "value2"}}, + {{"foo_a", "value1"}, {"foo_b", "value2"}}); +} + +TEST_F(AttributeCollisionTest, JoinsCollidingKeys) +{ + CheckTranslation({{"foo.a", "value1"}, {"foo_a", "value2"}}, // + {{"foo_a", "value1;value2"}}); +} + +TEST_F(AttributeCollisionTest, DropsInvertedKeys) +{ + CheckTranslation({{"foo.a", "value1"}, {"foo.b", "value2"}, {"foo__a", "value3"}}, + {{"foo_a", "value1"}, {"foo_b", "value2"}}); +} + OPENTELEMETRY_END_NAMESPACE From d49ba52591b675dd7747e2a017793559c5196654 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Mon, 25 Sep 2023 11:30:48 -0400 Subject: [PATCH 078/119] [exporters/prometheus] Get rid of friend test (#2329) Instead, test using the TranslateToPrometheus public API. --- .../exporters/prometheus/exporter_utils.h | 3 -- .../prometheus/test/exporter_utils_test.cc | 48 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index cb7da0b2b5..312b641c3e 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -104,9 +104,6 @@ class PrometheusExporterUtils const std::vector &boundaries, const std::vector &counts, ::prometheus::ClientMetric *metric); - - // For testing - friend class SanitizeNameTester; }; } // namespace metrics } // namespace exporter diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 0c08e2ffa7..228b63dbcf 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -15,21 +15,6 @@ namespace prometheus_client = ::prometheus; OPENTELEMETRY_BEGIN_NAMESPACE -namespace exporter -{ -namespace metrics -{ -class SanitizeNameTester -{ -public: - static std::string sanitize(std::string name) - { - return PrometheusExporterUtils::SanitizeNames(name); - } -}; -} // namespace metrics -} // namespace exporter - template void assert_basic(prometheus_client::MetricFamily &metric, const std::string &sanitized_name, @@ -153,14 +138,33 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); } -TEST(PrometheusExporterUtils, SanitizeName) +class SanitizeNameTest : public ::testing::Test +{ + Resource resource_ = Resource::Create({}); + nostd::unique_ptr instrumentation_scope_ = + InstrumentationScope::Create("library_name", "1.2.0"); + +protected: + void CheckSanitation(const std::string &original, const std::string &sanitized) + { + metric_sdk::InstrumentDescriptor instrument_descriptor_{ + original, "description", "unit", metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}; + std::vector result = PrometheusExporterUtils::TranslateToPrometheus( + {&resource_, + {{instrumentation_scope_.get(), {{instrument_descriptor_, {}, {}, {}, {{{}, {}}}}}}}}); + EXPECT_EQ(result.begin()->name, sanitized + "_unit"); + } +}; + +TEST_F(SanitizeNameTest, All) { - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name"), "name"); - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?"), "name_"); - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name???"), "name_"); - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__"), "name_"); - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name"), "name_name"); - ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name:"), "name_name:"); + CheckSanitation("name", "name"); + CheckSanitation("name?", "name_"); + CheckSanitation("name???", "name_"); + CheckSanitation("name?__", "name_"); + CheckSanitation("name?__name", "name_name"); + CheckSanitation("name?__name:", "name_name:"); } class AttributeCollisionTest : public ::testing::Test From ab83f4f74745ffcf1e87a7411321ca51809091c8 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Mon, 25 Sep 2023 15:57:16 -0700 Subject: [PATCH 079/119] Fix minor inconsistent log message in Meter::RegisterSyncMetricStorage (#2325) --- sdk/src/metrics/meter.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 1abb570b43..4f7c4c1207 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -304,8 +304,9 @@ std::unique_ptr Meter::RegisterSyncMetricStorage( auto ctx = meter_context_.lock(); if (!ctx) { - OTEL_INTERNAL_LOG_ERROR("[Meter::RegisterMetricStorage] - Error during finding matching views." - << "The metric context is invalid"); + OTEL_INTERNAL_LOG_ERROR( + "[Meter::RegisterSyncMetricStorage] - Error during finding matching views." + << "The metric context is invalid"); return nullptr; } auto view_registry = ctx->GetViewRegistry(); @@ -335,7 +336,7 @@ std::unique_ptr Meter::RegisterSyncMetricStorage( if (!success) { OTEL_INTERNAL_LOG_ERROR( - "[Meter::RegisterMetricStorage] - Error during finding matching views." + "[Meter::RegisterSyncMetricStorage] - Error during finding matching views." << "Some of the matching view configurations mayn't be used for metric collection"); } return storages; From a4961c421c9687ea5b750c8df3374cd842b1d5a8 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Mon, 25 Sep 2023 17:25:24 -0700 Subject: [PATCH 080/119] Simplify the project status section to better communicate the intention (#2332) * Simplify the project status section to better communicate the intention * cleanup --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 25b9cd8170..37a02a84c2 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,12 @@ The C++ [OpenTelemetry](https://opentelemetry.io/) client. ## Project Status -| Signal | Status | Project | -| ------- | ----------------------- | ------------------------------------------------------------------------ | -| Traces | Public Release | N/A | -| Metrics | Public Release | N/A | -| Logs | Public Release | N/A | +**Stable** across all 3 signals i.e. `Logs`, `Metrics`, and `Traces`. + +See [Spec Compliance +Matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md) +to understand which portions of the specification has been implemented in this +repo. ## Supported C++ Versions @@ -119,8 +120,6 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma ## Release Schedule -Refer to [project status](#project-status) for current status of the project. - See the [release notes](https://github.com/open-telemetry/opentelemetry-cpp/releases) for existing releases. From a45081a83b4ec728f8db42b0aa950ca2338ef756 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Wed, 27 Sep 2023 03:04:27 -0400 Subject: [PATCH 081/119] [exporters/prometheus] Sanitize labels according to Prometheus spec (#2330) Fixes #2289 --- CHANGELOG.md | 2 + .../exporters/prometheus/exporter_utils.h | 9 -- exporters/prometheus/src/exporter_utils.cc | 129 +++++++++++------- .../prometheus/test/exporter_utils_test.cc | 44 ++++-- 4 files changed, 116 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a077e7d8..7901a35732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Increment the: [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) * [EXPORTER] Handle attribute key collisions caused by sanitation [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) +* [EXPORTER] Replace colons with underscores when converting to Prometheus label + [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) ## [1.11.0] 2023-08-21 diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index 312b641c3e..07d2c396c6 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -32,15 +32,6 @@ class PrometheusExporterUtils const sdk::metrics::ResourceMetrics &data); private: - /** - * Sanitize the given metric name or label according to Prometheus rule. - * - * This function is needed because names in OpenTelemetry can contain - * alphanumeric characters, '_', '.', and '-', whereas in Prometheus the - * name should only contain alphanumeric characters and '_'. - */ - static std::string SanitizeNames(std::string name); - static opentelemetry::sdk::metrics::AggregationType getAggregationType( const opentelemetry::sdk::metrics::PointType &point_type); diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 149d93290b..a840b087ff 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -20,6 +20,85 @@ namespace exporter { namespace metrics { +namespace +{ +/** + * Sanitize the given metric name by replacing invalid characters with _, + * ensuring that multiple consecutive _ characters are collapsed to a single _. + * + * @param valid a callable with the signature `(int pos, char ch) -> bool` that + * returns whether `ch` is valid at position `pos` in the string + * @param name the string to sanitize + */ +template +inline std::string Sanitize(std::string name, const T &valid) +{ + static_assert(std::is_convertible>::value, + "valid should be a callable with the signature " + "(int, char) -> bool"); + + constexpr const auto replacement = '_'; + constexpr const auto replacement_dup = '='; + + bool has_dup = false; + for (int i = 0; i < (int)name.size(); ++i) + { + if (valid(i, name[i]) && name[i] != replacement) + { + continue; + } + if (i > 0 && (name[i - 1] == replacement || name[i - 1] == replacement_dup)) + { + has_dup = true; + name[i] = replacement_dup; + } + else + { + name[i] = replacement; + } + } + if (has_dup) + { + auto end = std::remove(name.begin(), name.end(), replacement_dup); + return std::string{name.begin(), end}; + } + return name; +} + +/** + * Sanitize the given metric label key according to Prometheus rule. + * Prometheus metric label keys are required to match the following regex: + * [a-zA-Z_]([a-zA-Z0-9_])* + * and multiple consecutive _ characters must be collapsed to a single _. + */ +std::string SanitizeLabel(std::string label_key) +{ + return Sanitize(label_key, [](int i, char c) { + return (c >= 'a' && c <= 'z') || // + (c >= 'A' && c <= 'Z') || // + c == '_' || // + (c >= '0' && c <= '9' && i > 0); + }); +} + +/** + * Sanitize the given metric name according to Prometheus rule. + * Prometheus metric names are required to match the following regex: + * [a-zA-Z_:]([a-zA-Z0-9_:])* + * and multiple consecutive _ characters must be collapsed to a single _. + */ +std::string SanitizeName(std::string name) +{ + return Sanitize(name, [](int i, char c) { + return (c >= 'a' && c <= 'z') || // + (c >= 'A' && c <= 'Z') || // + c == '_' || // + c == ':' || // + (c >= '0' && c <= '9' && i > 0); + }); +} +} // namespace + /** * Helper function to convert OpenTelemetry metrics data collection * to Prometheus metrics data collection @@ -40,7 +119,7 @@ std::vector PrometheusExporterUtils::TranslateT { auto origin_name = metric_data.instrument_descriptor.name_; auto unit = metric_data.instrument_descriptor.unit_; - auto sanitized = SanitizeNames(origin_name); + auto sanitized = SanitizeName(origin_name); prometheus_client::MetricFamily metric_family; metric_family.name = sanitized + "_" + unit; metric_family.help = metric_data.instrument_descriptor.description_; @@ -120,52 +199,6 @@ std::vector PrometheusExporterUtils::TranslateT return output; } -/** - * Sanitize the given metric name or label according to Prometheus rule. - * - * This function is needed because names in OpenTelemetry can contain - * alphanumeric characters, '_', '.', and '-', whereas in Prometheus the - * name should only contain alphanumeric characters and '_'. - */ -std::string PrometheusExporterUtils::SanitizeNames(std::string name) -{ - constexpr const auto replacement = '_'; - constexpr const auto replacement_dup = '='; - - auto valid = [](int i, char c) { - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ':' || - (c >= '0' && c <= '9' && i > 0)) - { - return true; - } - return false; - }; - - bool has_dup = false; - for (int i = 0; i < (int)name.size(); ++i) - { - if (valid(i, name[i])) - { - continue; - } - if (i > 0 && (name[i - 1] == replacement || name[i - 1] == replacement_dup)) - { - has_dup = true; - name[i] = replacement_dup; - } - else - { - name[i] = replacement; - } - } - if (has_dup) - { - auto end = std::remove(name.begin(), name.end(), replacement_dup); - return std::string{name.begin(), end}; - } - return name; -} - metric_sdk::AggregationType PrometheusExporterUtils::getAggregationType( const metric_sdk::PointType &point_type) { @@ -271,7 +304,7 @@ void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &me std::string previous_key; for (auto const &label : labels) { - auto sanitized = SanitizeNames(label.first); + auto sanitized = SanitizeLabel(label.first); int comparison = previous_key.compare(sanitized); if (metric.label.empty() || comparison < 0) // new key { diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 228b63dbcf..c2a6273397 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -138,33 +138,55 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); } -class SanitizeNameTest : public ::testing::Test +class SanitizeTest : public ::testing::Test { Resource resource_ = Resource::Create({}); nostd::unique_ptr instrumentation_scope_ = InstrumentationScope::Create("library_name", "1.2.0"); protected: - void CheckSanitation(const std::string &original, const std::string &sanitized) + void CheckSanitizeName(const std::string &original, const std::string &sanitized) { - metric_sdk::InstrumentDescriptor instrument_descriptor_{ + metric_sdk::InstrumentDescriptor instrument_descriptor{ original, "description", "unit", metric_sdk::InstrumentType::kCounter, metric_sdk::InstrumentValueType::kDouble}; std::vector result = PrometheusExporterUtils::TranslateToPrometheus( {&resource_, - {{instrumentation_scope_.get(), {{instrument_descriptor_, {}, {}, {}, {{{}, {}}}}}}}}); + {{instrumentation_scope_.get(), {{instrument_descriptor, {}, {}, {}, {{{}, {}}}}}}}}); EXPECT_EQ(result.begin()->name, sanitized + "_unit"); } + + void CheckSanitizeLabel(const std::string &original, const std::string &sanitized) + { + metric_sdk::InstrumentDescriptor instrument_descriptor{ + "name", "description", "unit", metric_sdk::InstrumentType::kCounter, + metric_sdk::InstrumentValueType::kDouble}; + std::vector result = PrometheusExporterUtils::TranslateToPrometheus( + {&resource_, + {{instrumentation_scope_.get(), + {{instrument_descriptor, {}, {}, {}, {{{{original, "value"}}, {}}}}}}}}); + EXPECT_EQ(result.begin()->metric.begin()->label.begin()->name, sanitized); + } }; -TEST_F(SanitizeNameTest, All) +TEST_F(SanitizeTest, Name) +{ + CheckSanitizeName("name", "name"); + CheckSanitizeName("name?", "name_"); + CheckSanitizeName("name???", "name_"); + CheckSanitizeName("name?__", "name_"); + CheckSanitizeName("name?__name", "name_name"); + CheckSanitizeName("name?__name:", "name_name:"); +} + +TEST_F(SanitizeTest, Label) { - CheckSanitation("name", "name"); - CheckSanitation("name?", "name_"); - CheckSanitation("name???", "name_"); - CheckSanitation("name?__", "name_"); - CheckSanitation("name?__name", "name_name"); - CheckSanitation("name?__name:", "name_name:"); + CheckSanitizeLabel("name", "name"); + CheckSanitizeLabel("name?", "name_"); + CheckSanitizeLabel("name???", "name_"); + CheckSanitizeLabel("name?__", "name_"); + CheckSanitizeLabel("name?__name", "name_name"); + CheckSanitizeLabel("name?__name:", "name_name_"); } class AttributeCollisionTest : public ::testing::Test From 368ee792107961c6ad7c140864af276955f5dc58 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Thu, 28 Sep 2023 15:02:55 +0800 Subject: [PATCH 082/119] Fix deadlock when shuting down http client. (#2337) --- ext/src/http/client/curl/http_client_curl.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 94bbf9fa7b..287059a1c6 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -244,6 +244,7 @@ void HttpClient::CleanupSession(uint64_t session_id) } } + bool need_wakeup_background_thread = false; { std::lock_guard lock_guard{session_ids_m_}; pending_to_add_session_ids_.erase(session_id); @@ -259,10 +260,15 @@ void HttpClient::CleanupSession(uint64_t session_id) { // If this session is already running, give it to the background thread for cleanup. pending_to_abort_sessions_[session_id] = std::move(session); - wakeupBackgroundThread(); + need_wakeup_background_thread = true; } } } + + if (need_wakeup_background_thread) + { + wakeupBackgroundThread(); + } } void HttpClient::MaybeSpawnBackgroundThread() @@ -519,7 +525,8 @@ bool HttpClient::doRemoveSessions() std::lock_guard session_id_lock_guard{session_ids_m_}; pending_to_remove_session_handles_.swap(pending_to_remove_session_handles); pending_to_remove_sessions_.swap(pending_to_remove_sessions); - + } + { // If user callback do not call CancelSession or FinishSession, We still need to remove it // from sessions_ std::lock_guard session_lock_guard{sessions_m_}; From 5e96b80bc964eeb61ddfd62a61d7b746fe75a97a Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Thu, 28 Sep 2023 09:46:17 +0200 Subject: [PATCH 083/119] [Exporter] Group spans by resource and instrumentation scope in OTLP export requests (#2335) --- .../exporters/otlp/otlp_recordable.h | 3 + exporters/otlp/src/otlp_recordable.cc | 11 +++ exporters/otlp/src/otlp_recordable_utils.cc | 49 +++++++++-- exporters/otlp/test/otlp_recordable_test.cc | 88 +++++++++++++++++++ 4 files changed, 144 insertions(+), 7 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index 29bc6011f9..bc505a959b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -27,7 +27,10 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable /** Dynamically converts the resource of this span into a proto. */ proto::resource::v1::Resource ProtoResource() const noexcept; + const opentelemetry::sdk::resource::Resource *GetResource() const noexcept; const std::string GetResourceSchemaURL() const noexcept; + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *GetInstrumentationScope() + const noexcept; const std::string GetInstrumentationLibrarySchemaURL() const noexcept; proto::common::v1::InstrumentationScope GetProtoInstrumentationScope() const noexcept; diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index e0b181a452..a3ab4327f2 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -40,6 +40,11 @@ proto::resource::v1::Resource OtlpRecordable::ProtoResource() const noexcept return proto; } +const opentelemetry::sdk::resource::Resource *OtlpRecordable::GetResource() const noexcept +{ + return resource_; +} + const std::string OtlpRecordable::GetResourceSchemaURL() const noexcept { std::string schema_url; @@ -51,6 +56,12 @@ const std::string OtlpRecordable::GetResourceSchemaURL() const noexcept return schema_url; } +const opentelemetry::sdk::instrumentationscope::InstrumentationScope * +OtlpRecordable::GetInstrumentationScope() const noexcept +{ + return instrumentation_scope_; +} + const std::string OtlpRecordable::GetInstrumentationLibrarySchemaURL() const noexcept { std::string schema_url; diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 1b1da94e08..59e4aadf4e 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -56,19 +56,54 @@ void OtlpRecordableUtils::PopulateRequest( return; } + using spans_by_scope = + std::unordered_map>>; + std::unordered_map spans_index; + + // Collect spans per resource and instrumentation scope for (auto &recordable : spans) { auto rec = std::unique_ptr(static_cast(recordable.release())); - auto resource_span = request->add_resource_spans(); - auto scope_spans = resource_span->add_scope_spans(); + auto resource = rec->GetResource(); + auto instrumentation = rec->GetInstrumentationScope(); - *scope_spans->add_spans() = std::move(rec->span()); - *scope_spans->mutable_scope() = rec->GetProtoInstrumentationScope(); + spans_index[resource][instrumentation].emplace_back(std::move(rec)); + } - scope_spans->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); + // Add all resource spans + for (auto &input_resource_spans : spans_index) + { + // Add the resource + auto resource_spans = request->add_resource_spans(); + if (input_resource_spans.first) + { + proto::resource::v1::Resource resource_proto; + OtlpPopulateAttributeUtils::PopulateAttribute(&resource_proto, *input_resource_spans.first); + *resource_spans->mutable_resource() = resource_proto; + resource_spans->set_schema_url(input_resource_spans.first->GetSchemaURL()); + } - *resource_span->mutable_resource() = rec->ProtoResource(); - resource_span->set_schema_url(rec->GetResourceSchemaURL()); + // Add all scope spans + for (auto &input_scope_spans : input_resource_spans.second) + { + // Add the instrumentation scope + auto scope_spans = resource_spans->add_scope_spans(); + if (input_scope_spans.first) + { + proto::common::v1::InstrumentationScope instrumentation_scope_proto; + instrumentation_scope_proto.set_name(input_scope_spans.first->GetName()); + instrumentation_scope_proto.set_version(input_scope_spans.first->GetVersion()); + *scope_spans->mutable_scope() = instrumentation_scope_proto; + scope_spans->set_schema_url(input_scope_spans.first->GetSchemaURL()); + } + + // Add all spans to this scope spans + for (auto &input_span : input_scope_spans.second) + { + *scope_spans->add_spans() = std::move(input_span->span()); + } + } } } diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 4db58844f7..9f3ba62b16 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/sdk/resource/resource.h" #if defined(__GNUC__) @@ -285,6 +286,93 @@ TEST(OtlpRecordable, SetArrayAttribute) } } +// Test otlp resource populate request util +TEST(OtlpRecordable, PopulateRequest) +{ + auto rec1 = std::unique_ptr(new OtlpRecordable); + auto resource1 = resource::Resource::Create({{"service.name", "one"}}); + rec1->SetResource(resource1); + auto inst_lib1 = trace_sdk::InstrumentationScope::Create("one", "1"); + rec1->SetInstrumentationScope(*inst_lib1); + + auto rec2 = std::unique_ptr(new OtlpRecordable); + auto resource2 = resource::Resource::Create({{"service.name", "two"}}); + rec2->SetResource(resource2); + auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); + rec2->SetInstrumentationScope(*inst_lib2); + + // This has the same resource as rec2, but a different scope + auto rec3 = std::unique_ptr(new OtlpRecordable); + rec3->SetResource(resource2); + auto inst_lib3 = trace_sdk::InstrumentationScope::Create("three", "3"); + rec3->SetInstrumentationScope(*inst_lib3); + + proto::collector::trace::v1::ExportTraceServiceRequest req; + std::vector> spans; + spans.push_back(std::move(rec1)); + spans.push_back(std::move(rec2)); + spans.push_back(std::move(rec3)); + const nostd::span, 3> spans_span(spans.data(), 3); + OtlpRecordableUtils::PopulateRequest(spans_span, &req); + + EXPECT_EQ(req.resource_spans().size(), 2); + for (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(); + if (service_name == "one") + { + EXPECT_EQ(scope_spans_size, 1); + EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), "one"); + } + if (service_name == "two") + { + EXPECT_EQ(scope_spans_size, 2); + } + } +} + +// Test otlp resource populate request util with missing data +TEST(OtlpRecordable, PopulateRequestMissing) +{ + // Missing scope + auto rec1 = std::unique_ptr(new OtlpRecordable); + auto resource1 = resource::Resource::Create({{"service.name", "one"}}); + rec1->SetResource(resource1); + + // Missing resource + auto rec2 = std::unique_ptr(new OtlpRecordable); + auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); + rec2->SetInstrumentationScope(*inst_lib2); + + proto::collector::trace::v1::ExportTraceServiceRequest req; + std::vector> spans; + spans.push_back(std::move(rec1)); + spans.push_back(std::move(rec2)); + const nostd::span, 2> spans_span(spans.data(), 2); + OtlpRecordableUtils::PopulateRequest(spans_span, &req); + + EXPECT_EQ(req.resource_spans().size(), 2); + for (auto resource_spans : req.resource_spans()) + { + // Both should have scope spans + EXPECT_EQ(resource_spans.scope_spans().size(), 1); + auto scope = resource_spans.scope_spans(0).scope(); + // Select the one with missing scope + if (scope.name() == "") + { + // Version is also empty + EXPECT_EQ(scope.version(), ""); + } + else + { + // The other has a name and version + EXPECT_EQ(scope.name(), "two"); + EXPECT_EQ(scope.version(), "2"); + } + } +} + template struct EmptyArrayAttributeTest : public testing::Test { From ad626cec4598165e0d297b0bdb3880968c5dfe88 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Sep 2023 10:25:51 +0200 Subject: [PATCH 084/119] [BUILD] Need fine-grained HAVE_CPP_STDLIB (#2304) --- .github/workflows/ci.yml | 36 +++++++++++++++++++ CHANGELOG.md | 23 ++++++++++++ CMakeLists.txt | 22 +++--------- api/CMakeLists.txt | 33 ++++++++++++++--- api/include/opentelemetry/nostd/shared_ptr.h | 14 +++++--- api/include/opentelemetry/nostd/span.h | 36 ++++++++++--------- api/include/opentelemetry/nostd/string_view.h | 13 ++++--- api/include/opentelemetry/nostd/type_traits.h | 13 ++++--- api/include/opentelemetry/nostd/unique_ptr.h | 13 ++++--- api/include/opentelemetry/nostd/utility.h | 12 ++++--- api/include/opentelemetry/nostd/variant.h | 13 ++++--- api/include/opentelemetry/std/span.h | 16 ++++----- api/test/nostd/span_test.cc | 15 -------- api/test/nostd/string_view_test.cc | 2 +- ci/do_ci.sh | 26 ++++++++++++++ docs/building-with-stdlib.md | 14 ++++++-- docs/dependencies.md | 5 +-- exporters/etw/README.md | 2 +- .../otlp/test/otlp_grpc_exporter_test.cc | 4 +-- .../otlp/test/otlp_http_exporter_test.cc | 4 +-- .../otlp_http_log_record_exporter_test.cc | 4 +-- exporters/zipkin/test/zipkin_exporter_test.cc | 4 +-- ext/test/http/CMakeLists.txt | 2 +- 23 files changed, 225 insertions(+), 101 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d8db91364..01ea48fb86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -316,6 +316,42 @@ jobs: CXX: /usr/bin/g++-4.8 run: ./ci/do_ci.sh cmake.legacy.exporter.otprotocol.test + cmake_test_cxx14_gcc: + name: CMake C++14 test(GCC) + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CMAKE_VERSION: 3.20.6 + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + - name: run tests (enable stl) + env: + CXX_STANDARD: '14' + run: ./ci/do_ci.sh cmake.c++14.stl.test + + cmake_test_cxx17_gcc: + name: CMake C++17 test(GCC) + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CMAKE_VERSION: 3.20.6 + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + - name: run tests (enable stl) + env: + CXX_STANDARD: '17' + run: ./ci/do_ci.sh cmake.c++17.stl.test + cmake_test_cxx20_gcc: name: CMake C++20 test(GCC) runs-on: ubuntu-20.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7901a35732..b349ba8ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,29 @@ Increment the: * [EXPORTER] Replace colons with underscores when converting to Prometheus label [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) +Breaking changes: + +* [BUILD] Need fine-grained HAVE_CPP_STDLIB + [#2304](https://github.com/open-telemetry/opentelemetry-cpp/pull/2304) + * In `CMAKE`, the boolean option `WITH_STL` as changed to an option + that accepts the values `OFF`, `ON`, `CXX11`, `CXX14`, `CXX17`, + `CXX20` and `CXX23`. + * Applications makefiles that did not set WITH_STL need to use + `WITH_STL=OFF` instead (this is the default). + * Applications makefiles that did set WITH_STL need to use + `WITH_STL=ON` instead, or may choose to pick a specific value. + * In the `API` header files, the preprocessor symbol `HAVE_CPP_STDLIB` + is no longer used. + * Applications that did set `HAVE_CPP_STDLIB` before, need to set + `OPENTELEMETRY_STL_VERSION=` instead, to build with a + specific STL version (2011, 2014, 2017, 2020, 2023). + * The opentelemetry-cpp makefile no longer sets + CMAKE_CXX_STANDARD by itself. + Instead, the CMAKE_CXX_STANDARD and/or compiler options -stdc++ used + by the caller are honored. + * Applications that set neither CMAKE_CXX_STANDARD nor -stdc++ + options may need to provide a C++ standard in their makefiles. + ## [1.11.0] 2023-08-21 * [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build diff --git a/CMakeLists.txt b/CMakeLists.txt index f579efe431..10c1a0ab6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,10 @@ message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}") option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) -option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) +set(WITH_STL + "OFF" + CACHE STRING "Which version of the Standard Library for C++ to use") + option(WITH_GSL "Whether to use Guidelines Support Library for C++ latest features" OFF) @@ -169,22 +172,7 @@ option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets" include("${PROJECT_SOURCE_DIR}/cmake/tools.cmake") -if(NOT DEFINED CMAKE_CXX_STANDARD) - if(WITH_STL) - # Require at least C++17. C++20 is needed to avoid gsl::span - if(CMAKE_VERSION VERSION_GREATER 3.11.999) - # Ask for 20, may get anything below - set(CMAKE_CXX_STANDARD 20) - else() - # Ask for 17, may get anything below - set(CMAKE_CXX_STANDARD 17) - endif() - else() - set(CMAKE_CXX_STANDARD 11) - endif() -endif() - -if(WITH_STL) +if(NOT WITH_STL STREQUAL "OFF") # These definitions are needed for test projects that do not link against # opentelemetry-api library directly. We ensure that variant implementation # (absl::variant or std::variant) in variant unit test code is consistent with diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index f5f1fbf897..dd1eda3c78 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -51,11 +51,36 @@ if(WITH_ABSEIL) "absl_bits" "absl_city") endif() -if(WITH_STL) - message("Building with standard library types...") - target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB) +if(WITH_STL STREQUAL "OFF") + message(STATUS "Building WITH_STL=OFF") +elseif(WITH_STL STREQUAL "CXX11") + message(STATUS "Building WITH_STL=CXX11") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2011) +elseif(WITH_STL STREQUAL "CXX14") + message(STATUS "Building WITH_STL=CXX14") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2014) +elseif(WITH_STL STREQUAL "CXX17") + message(STATUS "Building WITH_STL=CXX17") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2017) +elseif(WITH_STL STREQUAL "CXX20") + message(STATUS "Building WITH_STL=CXX20") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2020) +elseif(WITH_STL STREQUAL "CXX23") + message(STATUS "Building WITH_STL=CXX23") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2023) +elseif(WITH_STL STREQUAL "ON") + message(STATUS "Building WITH_STL=ON") + # "ON" corresponds to "CXX23" at this time. + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2023) else() - message("Building with nostd types...") + message( + FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17, CXX20 or CXX23") endif() if(WITH_GSL) diff --git a/api/include/opentelemetry/nostd/shared_ptr.h b/api/include/opentelemetry/nostd/shared_ptr.h index 4f7dd86bb4..0222352030 100644 --- a/api/include/opentelemetry/nostd/shared_ptr.h +++ b/api/include/opentelemetry/nostd/shared_ptr.h @@ -2,9 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/shared_ptr.h" -#else + +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/shared_ptr.h" +# define OPENTELEMETRY_HAVE_STD_SHARED_PTR +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_SHARED_PTR) # include # include # include @@ -201,4 +207,4 @@ inline bool operator!=(std::nullptr_t, const shared_ptr &rhs) noexcept } } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_SHARED_PTR */ diff --git a/api/include/opentelemetry/nostd/span.h b/api/include/opentelemetry/nostd/span.h index 3022a913d9..da0f385cf0 100644 --- a/api/include/opentelemetry/nostd/span.h +++ b/api/include/opentelemetry/nostd/span.h @@ -4,32 +4,34 @@ #pragma once // Try to use either `std::span` or `gsl::span` -#ifdef HAVE_CPP_STDLIB -# include -# include -# include -# include +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2020 +# include +# include +# include +# include /** * @brief Clang 14.0.0 with libc++ do not support implicitly construct a span * for a range. We just use our fallback version. * */ -# if !defined(OPENTELEMETRY_OPTION_USE_STD_SPAN) && defined(_LIBCPP_VERSION) -# if _LIBCPP_VERSION <= 14000 -# define OPENTELEMETRY_OPTION_USE_STD_SPAN 0 +# if !defined(OPENTELEMETRY_OPTION_USE_STD_SPAN) && defined(_LIBCPP_VERSION) +# if _LIBCPP_VERSION <= 14000 +# define OPENTELEMETRY_OPTION_USE_STD_SPAN 0 +# endif # endif -# endif -# ifndef OPENTELEMETRY_OPTION_USE_STD_SPAN -# define OPENTELEMETRY_OPTION_USE_STD_SPAN 1 -# endif -# if OPENTELEMETRY_OPTION_USE_STD_SPAN -# include "opentelemetry/std/span.h" -# endif -#endif +# ifndef OPENTELEMETRY_OPTION_USE_STD_SPAN +# define OPENTELEMETRY_OPTION_USE_STD_SPAN 1 +# endif +# if OPENTELEMETRY_OPTION_USE_STD_SPAN +# include "opentelemetry/std/span.h" +# endif +# endif /* OPENTELEMETRY_STL_VERSION >= 2020 */ +#endif /* OPENTELEMETRY_STL_VERSION */ // Fallback to `nostd::span` if necessary -#if !defined(HAVE_SPAN) +#if !defined(OPENTELEMETRY_HAVE_SPAN) # include # include # include diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 4f065effa0..9f9fb42180 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -3,9 +3,14 @@ #pragma once -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/string_view.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2017 +# include "opentelemetry/std/string_view.h" +# define OPENTELEMETRY_HAVE_STD_STRING_VIEW +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_STRING_VIEW) # include # include # include @@ -216,4 +221,4 @@ struct hash } }; } // namespace std -#endif +#endif /* OPENTELEMETRY_HAVE_STD_STRING_VIEW */ diff --git a/api/include/opentelemetry/nostd/type_traits.h b/api/include/opentelemetry/nostd/type_traits.h index 3d212ea3e2..46d11c89cb 100644 --- a/api/include/opentelemetry/nostd/type_traits.h +++ b/api/include/opentelemetry/nostd/type_traits.h @@ -3,9 +3,14 @@ #pragma once -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/type_traits.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/type_traits.h" +# define OPENTELEMETRY_HAVE_STD_TYPE_TRAITS +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_TYPE_TRAITS) # include # include @@ -154,4 +159,4 @@ struct is_trivially_move_assignable # endif } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_TYPE_TRAITS */ diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h index a97111b9d0..f864eb4f04 100644 --- a/api/include/opentelemetry/nostd/unique_ptr.h +++ b/api/include/opentelemetry/nostd/unique_ptr.h @@ -3,9 +3,14 @@ #pragma once -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/unique_ptr.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/unique_ptr.h" +# define OPENTELEMETRY_HAVE_STD_UNIQUE_PTR +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_UNIQUE_PTR) # include # include # include @@ -172,4 +177,4 @@ bool operator!=(std::nullptr_t, const unique_ptr &rhs) noexcept } } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_UNIQUE_PTR */ diff --git a/api/include/opentelemetry/nostd/utility.h b/api/include/opentelemetry/nostd/utility.h index bb350594ad..e7ad2d77f0 100644 --- a/api/include/opentelemetry/nostd/utility.h +++ b/api/include/opentelemetry/nostd/utility.h @@ -3,10 +3,14 @@ #pragma once -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/utility.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2014 +# include "opentelemetry/std/utility.h" +# define OPENTELEMETRY_HAVE_STD_UTILITY +# endif +#endif +#if !defined(OPENTELEMETRY_HAVE_STD_UTILITY) # include # include # include @@ -153,4 +157,4 @@ struct in_place_type_t }; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_UTILITY */ diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index b6b2326998..d0b2d96001 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -5,9 +5,14 @@ #include "opentelemetry/version.h" -#ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/variant.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2017 +# include "opentelemetry/std/variant.h" +# define OPENTELEMETRY_HAVE_STD_VARIANT +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_VARIANT) # ifndef HAVE_ABSEIL // We use a LOCAL snapshot of Abseil that is known to compile with Visual Studio 2015. @@ -73,4 +78,4 @@ using absl::visit; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_VARIANT */ diff --git a/api/include/opentelemetry/std/span.h b/api/include/opentelemetry/std/span.h index 5fdff57fd5..2a3dc12a84 100644 --- a/api/include/opentelemetry/std/span.h +++ b/api/include/opentelemetry/std/span.h @@ -12,18 +12,18 @@ # if __has_include() // Check for __cpp_{feature} # include # if defined(__cpp_lib_span) && __cplusplus > 201703L -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # endif -# if !defined(HAVE_SPAN) +# if !defined(OPENTELEMETRY_HAVE_SPAN) # // Check for Visual Studio span # if defined(_MSVC_LANG) && _HAS_CXX20 -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # // Check for other compiler span implementation # if !defined(_MSVC_LANG) && __has_include() && __cplusplus > 201703L // This works as long as compiler standard is set to C++20 -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # endif # if !__has_include() @@ -31,7 +31,7 @@ # endif #endif -#if !defined(HAVE_SPAN) +#if !defined(OPENTELEMETRY_HAVE_SPAN) # if defined(HAVE_GSL) # include // Guidelines Support Library provides an implementation of std::span @@ -44,12 +44,12 @@ template using span = gsl::span; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # else // No `gsl::span`, no `std::span`, fallback to `nostd::span` # endif -#else // HAVE_SPAN +#else // OPENTELEMETRY_HAVE_SPAN // Using std::span (https://wg21.link/P0122R7) from Standard Library available in C++20 : // - GCC libstdc++ 10+ // - Clang libc++ 7 @@ -66,4 +66,4 @@ template using span = std::span; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif // of HAVE_SPAN +#endif // if OPENTELEMETRY_HAVE_SPAN diff --git a/api/test/nostd/span_test.cc b/api/test/nostd/span_test.cc index 98e825142d..5c13ee590e 100644 --- a/api/test/nostd/span_test.cc +++ b/api/test/nostd/span_test.cc @@ -60,11 +60,6 @@ TEST(SpanTest, PointerCountConstruction) span s2{array.data(), array.size()}; EXPECT_EQ(s2.data(), array.data()); EXPECT_EQ(s2.size(), array.size()); - -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{array.data(), array.size()}), ".*"); -#endif } TEST(SpanTest, RangeConstruction) @@ -78,11 +73,6 @@ TEST(SpanTest, RangeConstruction) span s2{std::begin(array), std::end(array)}; EXPECT_EQ(s2.data(), array); EXPECT_EQ(s2.size(), 3); - -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{std::begin(array), std::end(array)}), ".*"); -#endif } TEST(SpanTest, ArrayConstruction) @@ -122,11 +112,6 @@ TEST(SpanTest, ContainerConstruction) EXPECT_EQ(s2.data(), v.data()); EXPECT_EQ(s2.size(), v.size()); -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{v.data(), 3}), ".*"); -#endif - EXPECT_FALSE((std::is_constructible, std::vector>::value)); EXPECT_FALSE((std::is_constructible, std::list>::value)); } diff --git a/api/test/nostd/string_view_test.cc b/api/test/nostd/string_view_test.cc index fc580debc1..52c72ea4d8 100644 --- a/api/test/nostd/string_view_test.cc +++ b/api/test/nostd/string_view_test.cc @@ -71,7 +71,7 @@ TEST(StringViewTest, SubstrPortion) TEST(StringViewTest, SubstrOutOfRange) { string_view s = "abc123"; -#if __EXCEPTIONS || defined(HAVE_CPP_STDLIB) +#if __EXCEPTIONS || ((defined(OPENTELEMETRY_STL_VERSION) && (OPENTELEMETRY_STL_VERSION >= 2020))) EXPECT_THROW(s.substr(10), std::out_of_range); #else EXPECT_DEATH({ s.substr(10); }, ""); diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 6452faa451..04063eb6ba 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -221,6 +221,32 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then eval "$MAKE_COMMAND" make test exit 0 +elif [[ "$1" == "cmake.c++14.stl.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_STL=CXX14 \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 +elif [[ "$1" == "cmake.c++17.stl.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_STL=CXX17 \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 elif [[ "$1" == "cmake.c++20.stl.test" ]]; then cd "${BUILD_DIR}" rm -rf * diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index a90a14a6ed..d9c73073da 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -138,14 +138,22 @@ Visual Studio provides 1st class debug experience for the standard library. Supported build flavors: * `nostd` - OpenTelemetry backport of classes for C++11. Not using standard lib. -* `stdlib` - Standard Library. Full native experience with C++20 compiler. - C++17 works but with additional dependencies, e.g. either MS-GSL or Abseil for +* `stdlib` - Standard Library. + Native experience with C++11/C++14/C++17/C++20/C++23 compiler. + Depending on the stdlib level in effect, + C++ features are used from the standard library, + completed with `nostd` replacement implementations. + C++17 and below works but with additional dependencies, + e.g. either MS-GSL or Abseil for `std::span` implementation (`gsl::span` or `absl::Span`). * `absl` - TODO: this should allow using Abseil C++ library only (no MS-GSL). Currently only `nostd` and `stdlib` configurations are implemented in CMake build. `absl` is reserved for future use. Build systems other than CMake need to -`#define HAVE_CPP_STDLIB` to enable the Standard Library classes. +`#define OPENTELEMETRY_STL_VERSION=` to enable the Standard Library classes. + +Valid values for `OPENTELEMETRY_STL_VERSION` are `2011`, `2014`, `2017`, `2020` and +`2023`. ### Build matrix diff --git a/docs/dependencies.md b/docs/dependencies.md index 62fbefc297..d0dc09c54f 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -24,8 +24,9 @@ Both these dependencies are listed here: [SDK](/sdk): - Uses Standard C++ library for latest features (std::string_view, std::variant, std::span, std::shared_ptr, std::unique_ptr) with C++14/17/20 - compiler if `WITH_STL` cmake option is enabled or `HAVE_CPP_STDLIB` macro is - defined. License: `GNU General Public License` + compiler if cmake option `WITH_STL` is enabled + or macro `OPENTELEMETRY_STL_VERSION` is defined. + License: `GNU General Public License` - For C++11/14/17 compilers, fallback to gsl::span if [GSL C++ library](https://github.com/microsoft/GSL) is installed. License: `MIT License` diff --git a/exporters/etw/README.md b/exporters/etw/README.md index 29dc3de430..3339223fa6 100644 --- a/exporters/etw/README.md +++ b/exporters/etw/README.md @@ -121,7 +121,7 @@ compiled: | Name | Description | |---------------------|------------------------------------------------------------------------------------------------------------------------| -| HAVE_CPP_STDLIB | Use STL classes for API surface. This option requires at least C++17. 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. | +| 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. | diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index 3298e5390d..3be2bcc653 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION // Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. // Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. // @@ -284,4 +284,4 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigUnknownInsecureFromEnv) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 2ac698b0de..42258d2b45 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include # include @@ -612,4 +612,4 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigFromTracesEnv) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ 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 4dc3b5829d..df89ca17fa 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include # include @@ -740,4 +740,4 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, DefaultEndpoint) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index fab19efb65..870ff427e9 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include "opentelemetry/exporters/zipkin/zipkin_exporter.h" # include "opentelemetry/ext/http/client/curl/http_client_curl.h" @@ -246,4 +246,4 @@ TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) } // namespace zipkin } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif // HAVE_CPP_STDLIB +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index 3ce72b3b83..328f78638b 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -25,7 +25,7 @@ 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}) + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) gtest_add_tests( TARGET ${URL_PARSER_FILENAME} TEST_PREFIX ext.http.urlparser. From c3c643a5977192ad6c66a633c671745fc04b2a77 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 30 Sep 2023 10:08:02 +0200 Subject: [PATCH 085/119] [API] Add InstrumentationScope attributes in MeterProvider::GetMeter() (#2224) --- .github/workflows/ci.yml | 32 +++++ CHANGELOG.md | 12 ++ .../opentelemetry/metrics/meter_provider.h | 115 +++++++++++++-- api/include/opentelemetry/metrics/noop.h | 15 +- ci/do_ci.sh | 25 ++++ .../sdk/common/attribute_utils.h | 17 ++- .../sdk/metrics/meter_provider.h | 13 ++ sdk/src/metrics/meter_provider.cc | 20 ++- sdk/test/metrics/meter_provider_sdk_test.cc | 132 ++++++++++++++++++ 9 files changed, 366 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01ea48fb86..3674c360d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -193,6 +193,38 @@ jobs: run: | (cd ./functional/otlp; ./run_test.sh) + cmake_clang_maintainer_abiv2_test: + name: CMake clang 14 (maintainer mode, abiv2) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CC: /usr/bin/clang-14 + CXX: /usr/bin/clang++-14 + PROTOBUF_VERSION: 21.12 + run: | + sudo -E ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/install_protobuf.sh + - name: run cmake clang (maintainer mode, abiv2) + env: + CC: /usr/bin/clang-14 + CXX: /usr/bin/clang++-14 + run: | + ./ci/do_ci.sh cmake.maintainer.abiv2.test + - name: generate test cert + env: + CFSSL_VERSION: 1.6.3 + run: | + sudo -E ./tools/setup-cfssl.sh + (cd ./functional/cert; ./generate_cert.sh) + - name: run func test + run: | + (cd ./functional/otlp; ./run_test.sh) + cmake_msvc_maintainer_test: name: CMake msvc (maintainer mode) runs-on: windows-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index b349ba8ec7..a884208922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,18 @@ Increment the: [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) * [EXPORTER] Replace colons with underscores when converting to Prometheus label [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) +* [API] Add InstrumentationScope attributes in MeterProvider::GetMeter() + [#2224](https://github.com/open-telemetry/opentelemetry-cpp/pull/2224) + +Important changes: + +* [API] Add InstrumentationScope attributes in MeterProvider::GetMeter() + [#2224](https://github.com/open-telemetry/opentelemetry-cpp/pull/2224) + * MeterProvider::GetMeter() now accepts InstrumentationScope attributes. + * Because this is an `ABI` breaking change, the fix is only available + with the `CMake` option `WITH_ABI_VERSION_2=ON`. + * When building with `CMake` option `WITH_ABI_VERSION_1=ON` (by default) + the `ABI` is unchanged, and the fix is not available. Breaking changes: diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index e0b0285ef4..152e543d36 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -3,8 +3,11 @@ #pragma once +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/type_traits.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -20,19 +23,113 @@ class MeterProvider { public: virtual ~MeterProvider() = default; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + + /** + * Gets or creates a named Meter instance (ABI). + * + * @since ABI_VERSION 2 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes (optional, may be nullptr) + */ + virtual nostd::shared_ptr GetMeter( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const common::KeyValueIterable *attributes) noexcept = 0; + + /** + * Gets or creates a named Meter instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version, optional + * @param[in] schema_url Instrumentation scope schema URL, optional + */ + nostd::shared_ptr GetMeter(nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") + { + return GetMeter(name, version, schema_url, nullptr); + } + + /** + * Gets or creates a named Meter instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes + */ + nostd::shared_ptr GetMeter( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + std::initializer_list> attributes) + { + /* Build a container from std::initializer_list. */ + nostd::span> attributes_span{ + attributes.begin(), attributes.end()}; + + /* Build a view on the container. */ + common::KeyValueIterableView< + nostd::span>> + iterable_attributes{attributes_span}; + + /* Add attributes using the view. */ + return GetMeter(name, version, schema_url, &iterable_attributes); + } + + /** + * Gets or creates a named Meter instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes container + */ + template ::value> * = nullptr> + nostd::shared_ptr GetMeter(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const T &attributes) + { + /* Build a view on the container. */ + common::KeyValueIterableView iterable_attributes(attributes); + + /* Add attributes using the view. */ + return GetMeter(name, version, schema_url, &iterable_attributes); + } + +#else /** - * Gets or creates a named Meter instance. + * Gets or creates a named Meter instance (ABI) * - * Optionally a version can be passed to create a named and versioned Meter - * instance. + * @since ABI_VERSION 1 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version, optional + * @param[in] schema_url Instrumentation scope schema URL, optional */ - virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, - nostd::string_view library_version = "", - nostd::string_view schema_url = "") noexcept = 0; + virtual nostd::shared_ptr GetMeter(nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif + #ifdef ENABLE_REMOVE_METER_PREVIEW - virtual void RemoveMeter(nostd::string_view library_name, - nostd::string_view library_version = "", - nostd::string_view schema_url = "") noexcept = 0; + virtual void RemoveMeter(nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") noexcept = 0; #endif }; } // namespace metrics diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index c5802f3dd3..edbbe2c100 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -196,12 +196,23 @@ class NoopMeterProvider final : public MeterProvider public: NoopMeterProvider() : meter_{nostd::shared_ptr(new NoopMeter)} {} - nostd::shared_ptr GetMeter(nostd::string_view /* library_name */, - nostd::string_view /* library_version */, +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetMeter( + nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */, + const common::KeyValueIterable * /* attributes */) noexcept override + { + return meter_; + } +#else + nostd::shared_ptr GetMeter(nostd::string_view /* name */, + nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override { return meter_; } +#endif #ifdef ENABLE_REMOVE_METER_PREVIEW void RemoveMeter(nostd::string_view /* name */, diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 04063eb6ba..948a62b9dd 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -174,6 +174,31 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then make -k -j $(nproc) make test exit 0 +elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ + -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ + -DWITH_REMOVE_METER_PREVIEW=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ + -DWITH_ZIPKIN=ON \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ + -DOTELCPP_MAINTAINER_MODE=ON \ + -DWITH_NO_DEPRECATED_CODE=ON \ + -DWITH_ABI_VERSION_1=OFF \ + -DWITH_ABI_VERSION_2=ON \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * diff --git a/sdk/include/opentelemetry/sdk/common/attribute_utils.h b/sdk/include/opentelemetry/sdk/common/attribute_utils.h index c8afd657e2..e21649b695 100644 --- a/sdk/include/opentelemetry/sdk/common/attribute_utils.h +++ b/sdk/include/opentelemetry/sdk/common/attribute_utils.h @@ -105,10 +105,10 @@ struct AttributeConverter class AttributeMap : public std::unordered_map { public: - // Contruct empty attribute map + // Construct empty attribute map AttributeMap() : std::unordered_map() {} - // Contruct attribute map and populate with attributes + // Construct attribute map and populate with attributes AttributeMap(const opentelemetry::common::KeyValueIterable &attributes) : AttributeMap() { attributes.ForEachKeyValue( @@ -118,6 +118,19 @@ class AttributeMap : public std::unordered_map }); } + // Construct attribute map and populate with optional attributes + AttributeMap(const opentelemetry::common::KeyValueIterable *attributes) : AttributeMap() + { + if (attributes != nullptr) + { + attributes->ForEachKeyValue( + [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + SetAttribute(key, value); + return true; + }); + } + } + // Construct map from initializer list by applying `SetAttribute` transform for every attribute AttributeMap( std::initializer_list> diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index c74c37f8a4..00f9a35ac2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -48,10 +48,23 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider */ explicit MeterProvider(std::unique_ptr context) noexcept; + /* + Make sure GetMeter() helpers from the API are seen in overload resolution. + */ + using opentelemetry::metrics::MeterProvider::GetMeter; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetMeter( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const opentelemetry::common::KeyValueIterable *attributes) noexcept override; +#else nostd::shared_ptr GetMeter( nostd::string_view name, nostd::string_view version = "", nostd::string_view schema_url = "") noexcept override; +#endif #ifdef ENABLE_REMOVE_METER_PREVIEW void RemoveMeter(nostd::string_view name, diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 84ab58c4cf..23ddbc75cf 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -32,11 +32,23 @@ MeterProvider::MeterProvider(std::unique_ptr views, OTEL_INTERNAL_LOG_DEBUG("[MeterProvider] MeterProvider created."); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +nostd::shared_ptr MeterProvider::GetMeter( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const opentelemetry::common::KeyValueIterable *attributes) noexcept +#else nostd::shared_ptr MeterProvider::GetMeter( nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept +#endif { +#if OPENTELEMETRY_ABI_VERSION_NO < 2 + const opentelemetry::common::KeyValueIterable *attributes = nullptr; +#endif + if (name.data() == nullptr || name == "") { OTEL_INTERNAL_LOG_WARN("[MeterProvider::GetMeter] Library name is empty."); @@ -53,8 +65,12 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } } - auto lib = instrumentationscope::InstrumentationScope::Create(name, version, schema_url); - auto meter = std::shared_ptr(new Meter(context_, std::move(lib))); + + instrumentationscope::InstrumentationScopeAttributes attrs_map(attributes); + auto scope = + instrumentationscope::InstrumentationScope::Create(name, version, schema_url, attrs_map); + + auto meter = std::shared_ptr(new Meter(context_, std::move(scope))); context_->AddMeter(meter); return nostd::shared_ptr{meter}; } diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index a1ca8de330..1844f113d2 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -59,6 +59,138 @@ TEST(MeterProvider, GetMeter) mp1.Shutdown(); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +TEST(MeterProvider, GetMeterAbiv2) +{ + MeterProvider mp; + + auto m1 = mp.GetMeter("name1", "version1", "url1"); + ASSERT_NE(nullptr, m1); + + auto m2 = mp.GetMeter("name2", "version2", "url2", nullptr); + ASSERT_NE(nullptr, m2); + + auto m3 = mp.GetMeter("name3", "version3", "url3", {{"accept_single_attr", true}}); + ASSERT_NE(nullptr, m3); + { + auto meter = static_cast(m3.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + auto attr = attrs.find("accept_single_attr"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), true); + } + + std::pair attr4 = { + "accept_single_attr", true}; + auto m4 = mp.GetMeter("name4", "version4", "url4", {attr4}); + ASSERT_NE(nullptr, m4); + { + auto meter = static_cast(m4.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + auto attr = attrs.find("accept_single_attr"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), true); + } + + auto m5 = mp.GetMeter("name5", "version5", "url5", {{"foo", "1"}, {"bar", "2"}}); + ASSERT_NE(nullptr, m5); + { + auto meter = static_cast(m5.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("bar"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), "2"); + } + + std::initializer_list< + std::pair> + attrs6 = {{"foo", "1"}, {"bar", 42}}; + + auto m6 = mp.GetMeter("name6", "version6", "url6", attrs6); + ASSERT_NE(nullptr, m6); + { + auto meter = static_cast(m6.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("bar"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 42); + } + + typedef std::pair KV; + + std::initializer_list attrs7 = {{"foo", 3.14}, {"bar", "2"}}; + auto m7 = mp.GetMeter("name7", "version7", "url7", attrs7); + ASSERT_NE(nullptr, m7); + { + auto meter = static_cast(m7.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("foo"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 3.14); + } + + auto m8 = mp.GetMeter("name8", "version8", "url8", + {{"a", "string"}, + {"b", false}, + {"c", 314159}, + {"d", (unsigned int)314159}, + {"e", (int32_t)-20}, + {"f", (uint32_t)20}, + {"g", (int64_t)-20}, + {"h", (uint64_t)20}, + {"i", 3.1}, + {"j", "string"}}); + ASSERT_NE(nullptr, m8); + { + auto meter = static_cast(m8.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 10); + auto attr = attrs.find("e"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), -20); + } + + std::map attr9{ + {"a", "string"}, {"b", false}, {"c", 314159}, {"d", (unsigned int)314159}, + {"e", (int32_t)-20}, {"f", (uint32_t)20}, {"g", (int64_t)-20}, {"h", (uint64_t)20}, + {"i", 3.1}, {"j", "string"}}; + + auto m9 = mp.GetMeter("name9", "version9", "url9", attr9); + ASSERT_NE(nullptr, m9); + { + auto meter = static_cast(m9.get()); + auto scope = meter->GetInstrumentationScope(); + auto attrs = scope->GetAttributes(); + ASSERT_EQ(attrs.size(), 10); + auto attr = attrs.find("h"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 20); + } + + // cleanup properly without crash + mp.ForceFlush(); + mp.Shutdown(); +} +#endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ + #ifdef ENABLE_REMOVE_METER_PREVIEW TEST(MeterProvider, RemoveMeter) { From bd114349405745765e969caa6aefbb97b3845cae Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 30 Sep 2023 16:23:52 +0200 Subject: [PATCH 086/119] [REMOVAL] Drop C++11 support (#2342) --- .github/workflows/ci.yml | 95 ------------------------------------ CHANGELOG.md | 10 +++- DEPRECATED.md | 61 +---------------------- INSTALL.md | 4 +- README.md | 19 +++----- docs/building-with-stdlib.md | 6 +-- docs/dependencies.md | 2 +- docs/google-test.md | 2 +- docs/public/api/Overview.rst | 2 +- 9 files changed, 23 insertions(+), 178 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3674c360d0..30b3b3fbde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,43 +28,6 @@ jobs: run: | ./ci/do_ci.sh cmake.test - # - # This build uses the latest libraries compatible - # with C++11 - # - cmake_gcc_maintainer_cpp11_async_test: - name: CMake gcc 12 (maintainer mode, C++11, async) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: setup - env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 - GOOGLETEST_VERSION: 1.12.1 - PROTOBUF_VERSION: 21.12 - run: | - sudo -E ./ci/setup_cmake.sh - sudo -E ./ci/setup_ci_environment.sh - sudo -E ./ci/install_protobuf.sh - - name: run cmake gcc (maintainer mode, C++11, async) - env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 - run: | - ./ci/do_ci.sh cmake.maintainer.cpp11.async.test - - name: generate test cert - env: - CFSSL_VERSION: 1.6.3 - run: | - sudo -E ./tools/setup-cfssl.sh - (cd ./functional/cert; ./generate_cert.sh) - - name: run func test - run: | - (cd ./functional/otlp; ./run_test.sh) - cmake_gcc_maintainer_sync_test: name: CMake gcc 12 (maintainer mode, sync) runs-on: ubuntu-latest @@ -290,64 +253,6 @@ jobs: - name: run cmake tests (enable opentracing-shim) run: ./ci/do_ci.sh cmake.opentracing_shim.test - cmake_gcc_48_test: - name: CMake gcc 4.8 (without otlp exporter) - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: Add Ubuntu Xenial package sources - run: | - sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu/ xenial main' - sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu/ xenial universe' - - name: setup - run: | - sudo ./ci/setup_ci_environment.sh - sudo ./ci/install_gcc48.sh - - name: setup cmake - env: - CC: /usr/bin/gcc-4.8 - CXX: /usr/bin/g++-4.8 - GOOGLETEST_VERSION: 1.10.0 - run: | - sudo -E ./ci/setup_cmake.sh - - name: run tests - env: - CC: /usr/bin/gcc-4.8 - CXX: /usr/bin/g++-4.8 - CXX_STANDARD: '11' - run: ./ci/do_ci.sh cmake.legacy.test - - cmake_gcc_48_otlp_exporter_test: - name: CMake gcc 4.8 (with otlp exporter) - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: Add Ubuntu Xenial package sources - run: | - sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu/ xenial main' - sudo apt-add-repository 'deb http://archive.ubuntu.com/ubuntu/ xenial universe' - - name: setup - run: | - sudo ./ci/setup_ci_environment.sh - sudo ./ci/install_gcc48.sh - - name: setup cmake and grpc - env: - CC: /usr/bin/gcc-4.8 - CXX: /usr/bin/g++-4.8 - GOOGLETEST_VERSION: 1.10.0 - run: | - sudo -E ./ci/setup_cmake.sh - sudo -E ./ci/setup_grpc.sh -v 4.8 - - name: run tests - env: - CC: /usr/bin/gcc-4.8 - CXX: /usr/bin/g++-4.8 - run: ./ci/do_ci.sh cmake.legacy.exporter.otprotocol.test - cmake_test_cxx14_gcc: name: CMake C++14 test(GCC) runs-on: ubuntu-20.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index a884208922..5f2ce9e4d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,11 +20,13 @@ Increment the: * [EXPORTER] Remove explicit timestamps from metric points exported by Prometheus [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) * [EXPORTER] Handle attribute key collisions caused by sanitation - [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) + [#2326](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) * [EXPORTER] Replace colons with underscores when converting to Prometheus label - [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) + [#2330](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) * [API] Add InstrumentationScope attributes in MeterProvider::GetMeter() [#2224](https://github.com/open-telemetry/opentelemetry-cpp/pull/2224) +* [REMOVAL] Drop C++11 support + [#2342](https://github.com/open-telemetry/opentelemetry-cpp/pull/2342) Important changes: @@ -59,6 +61,10 @@ Breaking changes: * Applications that set neither CMAKE_CXX_STANDARD nor -stdc++ options may need to provide a C++ standard in their makefiles. +* [REMOVAL] Drop C++11 support + [#2342](https://github.com/open-telemetry/opentelemetry-cpp/pull/2342) + * Building with C++11 is no longer supported. + ## [1.11.0] 2023-08-21 * [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build diff --git a/DEPRECATED.md b/DEPRECATED.md index 05ba8e52d4..c9ad356696 100644 --- a/DEPRECATED.md +++ b/DEPRECATED.md @@ -30,66 +30,7 @@ N/A ## [Compilers] -### Drop C++11 support - -#### Announcement (C++11) - -* Date: 2022-12-01 -* Issue: [DEPRECATION] Drop C++11 support - [#1830](https://github.com/open-telemetry/opentelemetry-cpp/pull/1830) -* This announcement has been pinned, - visible in the issues pages since December 2022. - -#### Motivation (C++11) - -This repository, opentelemetry-cpp, supports a "bring your own dependency" model. - -In this model, -the build scripts can be configured to: - -* pick a given version for a third party library, -* build opentelemetry-cpp with the library given. - -The makefiles do not mandate to use a particular version, -hence the "bring your own" denomination. - -To have an up to date build, projects are encouraged to use up to date -versions of third party libraries, to benefit from bug fixes. - -Now, many libraries deliver new versions that require C++14, bug fixes -releases for C++11 are no longer available. - -In particular, the following components: - -* GRPC C++ -* abseil -* googletest - -now require C++14, per -[google support policies](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) - -As a result, to stay up to date, opentelemetry-cpp needs to upgrade its -minimum build requirements to use C++14 instead of C++11. - -#### Scope (C++11) - -Continuous Integration (CI) builds will use C++14 instead of C++11. - -The CI build for gcc 4.8 is now deprecated, to be decommissioned when C++11 -support is dropped. - -#### Mitigation (C++11) - -Building the code with recent third party libraries will require C++14 -instead of C++11. - -#### Planned end of life (C++11) - -Support for C++11 in opentelemetry-cpp will end on September 2023. - -After this date, opentelemetry-cpp may still build properly in C++11 mode, -assuming a suitable, old, version for each dependency is used, -but the C++11 build will no longer be tested for each new release. +N/A ## [Third party dependencies] diff --git a/INSTALL.md b/INSTALL.md index 48d1ee8a45..68fefff1fe 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -16,7 +16,7 @@ You can link OpenTelemetry C++ SDK with libraries provided in - A supported platform (e.g. Windows, macOS or Linux). Refer to [Platforms Supported](./README.md#supported-development-platforms) for more information. -- A compatible C++ compiler supporting at least C++11. Major compilers are +- A compatible C++ compiler supporting at least C++14. Major compilers are supported. Refer to [Supported Compilers](./README.md#supported-c-versions) for more information. - [Git](https://git-scm.com/) for fetching opentelemetry-cpp source code from @@ -158,7 +158,7 @@ path. - A supported platform (e.g. Windows, macOS or Linux). Refer to [Platforms Supported](./README.md#supported-development-platforms) for more information. -- A compatible C++ compiler supporting at least C++11. Major compilers are +- A compatible C++ compiler supporting at least C++14. Major compilers are supported. Refer to [Supported Compilers](./README.md#supported-c-versions) for more information. - [Git](https://git-scm.com/) for fetching opentelemetry-cpp source code from diff --git a/README.md b/README.md index 37a02a84c2..d6a16f3de0 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,8 @@ repo. Code shipped from this repository generally supports the following versions of C++ standards: -* ISO/IEC 14882:2011 (C++11, C++0x) -* ISO/IEC 14882:2014 (C++14, C++1y) -* ISO/IEC 14882:2017 (C++17, C++1z) +* ISO/IEC 14882:2014 (C++14) +* ISO/IEC 14882:2017 (C++17) * ISO/IEC 14882:2020 (C++20) Any exceptions to this are noted in the individual `README.md` files. @@ -39,19 +38,13 @@ of the current project. | Platform | Build type | |---------------------------------------------------------------------|---------------| -| ubuntu-22.04 (GCC - 10, 12) | CMake, Bazel | -| ubuntu-20.04 (GCC 4.8 with -std=c++11 flag) | CMake [1] | -| ubuntu-20.04 (GCC 9.4.0) | CMake, Bazel | -| ubuntu-20.04 (Default GCC Compiler - 9.4.0 with -std=c++20 flags) | CMake, Bazel | -| macOS 12.0 (Xcode 14.2) | Bazel | +| ubuntu-22.04 (GCC 10, GCC 12, Clang 14) | CMake, Bazel | +| ubuntu-20.04 (GCC 9.4.0 - default compiler) | CMake, Bazel | +| ubuntu-20.04 (GCC 9.4.0 with -std=c++14/17/20 flags) | CMake, Bazel | +| macOS 12.7 (Xcode 14.2) | Bazel | | Windows Server 2019 (Visual Studio Enterprise 2019) | CMake, Bazel | | Windows Server 2022 (Visual Studio Enterprise 2022) | CMake | -[1]: Bazel build is disabled for GCC 4.8, as gRPC library 1.38 and above - (required by OTLP exporter) don't build with this compiler. See gRPC [official - support](https://grpc.io/docs/#official-support) document. CMake build doesn't - build OTLP exporter with GCC 4.8. - In general, the code shipped from this repository should build on all platforms having C++ compiler with [supported C++ standards](#supported-c-versions). diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index d9c73073da..22b8935595 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -19,7 +19,7 @@ API surface classes with [Abseil classes](https://abseil.io/) instead of * ABI stability: scenario where different modules are compiled with different compiler and incompatible standard library. -* backport of C++17 and above features to C++11 compiler. +* backport of C++17 and above features to C++14 compiler. The need for custom `nostd` classes is significantly diminished when the SDK is compiled with C++17 or above compiler. Only `std::span` needs to be backported. @@ -137,9 +137,9 @@ Visual Studio provides 1st class debug experience for the standard library. Supported build flavors: -* `nostd` - OpenTelemetry backport of classes for C++11. Not using standard lib. +* `nostd` - OpenTelemetry backport of classes for C++14. Not using standard lib. * `stdlib` - Standard Library. - Native experience with C++11/C++14/C++17/C++20/C++23 compiler. + Native experience with C++14/C++17/C++20/C++23 compiler. Depending on the stdlib level in effect, C++ features are used from the standard library, completed with `nostd` replacement implementations. diff --git a/docs/dependencies.md b/docs/dependencies.md index d0dc09c54f..2f2f2368f6 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -27,7 +27,7 @@ Both these dependencies are listed here: compiler if cmake option `WITH_STL` is enabled or macro `OPENTELEMETRY_STL_VERSION` is defined. License: `GNU General Public License` - - For C++11/14/17 compilers, fallback to gsl::span if [GSL C++ + - For C++14/17 compilers, fallback to gsl::span if [GSL C++ library](https://github.com/microsoft/GSL) is installed. License: `MIT License` - libc++ 14.0.0 do not support construct std::span from a range or container diff --git a/docs/google-test.md b/docs/google-test.md index dadf5b1577..7f767e54e7 100644 --- a/docs/google-test.md +++ b/docs/google-test.md @@ -93,7 +93,7 @@ this, Google Test also allows us to easily integrate code coverage tools such as ## Integration and Usage One of the base requirements to build and use Google Test from a source package -are to use either Bazel or CMake; the other is a C++11-standard-compliant +are to use either Bazel or CMake; the other is a C++14-standard-compliant compiler like GCC or Clang. ### Bazel diff --git a/docs/public/api/Overview.rst b/docs/public/api/Overview.rst index cdd160ce23..6b1e826d01 100644 --- a/docs/public/api/Overview.rst +++ b/docs/public/api/Overview.rst @@ -15,7 +15,7 @@ Library design -------------- The OpenTelemetry C++ API is provided as a header-only library and -supports all recent versions of the C++ standard, down to C++11. +supports all recent versions of the C++ standard, down to C++14. A single application might dynamically or statically link to different libraries that were compiled with different compilers, while several of From 0803e6a8f26458df4c987c5fcc19823ca530cc41 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 2 Oct 2023 14:21:01 -0400 Subject: [PATCH 087/119] prometheus exporter: Add otel_scope_name and otel_scope_version labels (#2293) --- CHANGELOG.md | 3 + .../exporters/prometheus/exporter_utils.h | 8 ++- exporters/prometheus/src/exporter_utils.cc | 67 ++++++++++++++----- .../prometheus/test/exporter_utils_test.cc | 22 +++--- 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2ce9e4d0..57307f67fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ Increment the: [#2224](https://github.com/open-telemetry/opentelemetry-cpp/pull/2224) * [REMOVAL] Drop C++11 support [#2342](https://github.com/open-telemetry/opentelemetry-cpp/pull/2342) +* [EXPORTER] Add otel_scope_name and otel_scope_version labels to the prometheus + exporter. + [#2293](https://github.com/open-telemetry/opentelemetry-cpp/pull/2293) Important changes: diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index 07d2c396c6..76c62d58ba 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -48,6 +48,7 @@ class PrometheusExporterUtils template static void SetData(std::vector values, const opentelemetry::sdk::metrics::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, ::prometheus::MetricType type, ::prometheus::MetricFamily *metric_family); @@ -60,13 +61,16 @@ class PrometheusExporterUtils const std::vector &boundaries, const std::vector &counts, const opentelemetry::sdk::metrics::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, ::prometheus::MetricFamily *metric_family); /** * Set time and labels to metric data */ - static void SetMetricBasic(::prometheus::ClientMetric &metric, - const opentelemetry::sdk::metrics::PointAttributes &labels); + static void SetMetricBasic( + ::prometheus::ClientMetric &metric, + const opentelemetry::sdk::metrics::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope); /** * Convert attribute value to string diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index a840b087ff..c0f034ffe5 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -22,6 +22,10 @@ namespace metrics { namespace { + +static constexpr const char *kScopeNameKey = "otel_scope_name"; +static constexpr const char *kScopeVersionKey = "otel_scope_version"; + /** * Sanitize the given metric name by replacing invalid characters with _, * ensuring that multiple consecutive _ characters are collapsed to a single _. @@ -150,7 +154,7 @@ std::vector PrometheusExporterUtils::TranslateT sum = nostd::get(histogram_point_data.sum_); } SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, - point_data_attr.attributes, &metric_family); + point_data_attr.attributes, instrumentation_info.scope_, &metric_family); } else if (type == prometheus_client::MetricType::Gauge) { @@ -160,14 +164,16 @@ std::vector PrometheusExporterUtils::TranslateT auto last_value_point_data = nostd::get(point_data_attr.point_data); std::vector values{last_value_point_data.value_}; - SetData(values, point_data_attr.attributes, type, &metric_family); + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + &metric_family); } else if (nostd::holds_alternative(point_data_attr.point_data)) { auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, type, &metric_family); + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + &metric_family); } else { @@ -183,7 +189,8 @@ std::vector PrometheusExporterUtils::TranslateT auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, type, &metric_family); + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + &metric_family); } else { @@ -257,14 +264,16 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType( * sum => Prometheus Counter */ template -void PrometheusExporterUtils::SetData(std::vector values, - const metric_sdk::PointAttributes &labels, - prometheus_client::MetricType type, - prometheus_client::MetricFamily *metric_family) +void PrometheusExporterUtils::SetData( + std::vector values, + const metric_sdk::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + prometheus_client::MetricType type, + prometheus_client::MetricFamily *metric_family) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels); + SetMetricBasic(metric, labels, scope); SetValue(values, type, &metric); } @@ -273,23 +282,27 @@ void PrometheusExporterUtils::SetData(std::vector values, * Histogram => Prometheus Histogram */ template -void PrometheusExporterUtils::SetData(std::vector values, - const std::vector &boundaries, - const std::vector &counts, - const metric_sdk::PointAttributes &labels, - prometheus_client::MetricFamily *metric_family) +void PrometheusExporterUtils::SetData( + std::vector values, + const std::vector &boundaries, + const std::vector &counts, + const metric_sdk::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + prometheus_client::MetricFamily *metric_family) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels); + SetMetricBasic(metric, labels, scope); SetValue(values, boundaries, counts, &metric); } /** * Set labels to metric data */ -void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &metric, - const metric_sdk::PointAttributes &labels) +void PrometheusExporterUtils::SetMetricBasic( + prometheus_client::ClientMetric &metric, + const metric_sdk::PointAttributes &labels, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope) { if (labels.empty()) { @@ -300,7 +313,7 @@ void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &me // Note that attribute keys are sorted, but sanitized keys can be out-of-order. // We could sort the sanitized keys again, but this seems too expensive to do // in this hot code path. Instead, we ignore out-of-order keys and emit a warning. - metric.label.reserve(labels.size()); + metric.label.reserve(labels.size() + 2); std::string previous_key; for (auto const &label : labels) { @@ -324,6 +337,24 @@ void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &me << "'. Ignoring this label."); } } + if (!scope) + { + return; + } + auto scope_name = scope->GetName(); + if (!scope_name.empty()) + { + metric.label.emplace_back(); + metric.label.back().name = kScopeNameKey; + metric.label.back().value = std::move(scope_name); + } + auto scope_version = scope->GetVersion(); + if (!scope_version.empty()) + { + metric.label.emplace_back(); + metric.label.back().name = kScopeVersionKey; + metric.label.back().value = std::move(scope_version); + } } std::string PrometheusExporterUtils::AttributeValueToString( diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index c2a6273397..3c945c6735 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -105,7 +105,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) auto metric1 = translated[0]; std::vector vals = {10}; - assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Counter, 1, + assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Counter, 3, vals); } @@ -119,7 +119,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) auto metric1 = translated[0]; std::vector vals = {10}; - assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Gauge, 1, + assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Gauge, 3, vals); } @@ -133,7 +133,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) auto metric = translated[0]; std::vector vals = {3, 900.5, 4}; - assert_basic(metric, "library_name", "description", prometheus_client::MetricType::Histogram, 1, + assert_basic(metric, "library_name", "description", prometheus_client::MetricType::Histogram, 3, vals); assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); } @@ -211,20 +211,26 @@ class AttributeCollisionTest : public ::testing::Test TEST_F(AttributeCollisionTest, SeparatesDistinctKeys) { - CheckTranslation({{"foo.a", "value1"}, {"foo.b", "value2"}}, - {{"foo_a", "value1"}, {"foo_b", "value2"}}); + CheckTranslation({{"foo.a", "value1"}, {"foo.b", "value2"}}, {{"foo_a", "value1"}, + {"foo_b", "value2"}, + {"otel_scope_name", "library_name"}, + {"otel_scope_version", "1.2.0"}}); } TEST_F(AttributeCollisionTest, JoinsCollidingKeys) { - CheckTranslation({{"foo.a", "value1"}, {"foo_a", "value2"}}, // - {{"foo_a", "value1;value2"}}); + CheckTranslation({{"foo.a", "value1"}, {"foo_a", "value2"}}, {{"foo_a", "value1;value2"}, + {"otel_scope_name", "library_name"}, + {"otel_scope_version", "1.2.0"}}); } TEST_F(AttributeCollisionTest, DropsInvertedKeys) { CheckTranslation({{"foo.a", "value1"}, {"foo.b", "value2"}, {"foo__a", "value3"}}, - {{"foo_a", "value1"}, {"foo_b", "value2"}}); + {{"foo_a", "value1"}, + {"foo_b", "value2"}, + {"otel_scope_name", "library_name"}, + {"otel_scope_version", "1.2.0"}}); } OPENTELEMETRY_END_NAMESPACE From 0eaa7944e1f2ef407f3fea6b94f24ed16cdb1fb6 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Wed, 4 Oct 2023 03:47:27 +0800 Subject: [PATCH 088/119] Export resource for prometheus (#2301) --- CHANGELOG.md | 2 + .../exporters/prometheus/collector.h | 3 +- .../exporters/prometheus/exporter_options.h | 3 + .../exporters/prometheus/exporter_utils.h | 31 +++- exporters/prometheus/src/collector.cc | 11 +- exporters/prometheus/src/exporter.cc | 3 +- exporters/prometheus/src/exporter_utils.cc | 102 ++++++++++--- exporters/prometheus/test/collector_test.cc | 4 +- .../prometheus/test/exporter_utils_test.cc | 134 ++++++++++++++++-- .../sdk/metrics/export/metric_producer.h | 32 ++++- 10 files changed, 282 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57307f67fa..f889a287f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ Increment the: * [DEPRECATION] Deprecate ZPAGES [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) +* [EXPORTER] Prometheus exporter emit resource attributes + [#2301](https://github.com/open-telemetry/opentelemetry-cpp/pull/2301) * [EXPORTER] Remove explicit timestamps from metric points exported by Prometheus [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) * [EXPORTER] Handle attribute key collisions caused by sanitation diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.h index 46d270905b..5dfa983088 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.h @@ -31,7 +31,7 @@ class PrometheusCollector : public prometheus_client::Collectable * This constructor initializes the collection for metrics to export * in this class with default capacity */ - explicit PrometheusCollector(sdk::metrics::MetricReader *reader); + explicit PrometheusCollector(sdk::metrics::MetricReader *reader, bool populate_target_info); /** * Collects all metrics data from metricsToCollect collection. @@ -42,6 +42,7 @@ class PrometheusCollector : public prometheus_client::Collectable private: sdk::metrics::MetricReader *reader_; + bool populate_target_info_; /* * Lock when operating the metricsToCollect collection diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h index 76a08d2a4a..3f36d780ee 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h @@ -22,6 +22,9 @@ struct PrometheusExporterOptions // The endpoint the Prometheus backend can collect metrics from std::string url; + + // Populating target_info + bool populate_target_info = true; }; } // 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 76c62d58ba..96c7ac8826 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -26,12 +26,25 @@ class PrometheusExporterUtils * to Prometheus metrics data collection * * @param records a collection of metrics in OpenTelemetry + * @param populate_target_info whether to populate target_info * @return a collection of translated metrics that is acceptable by Prometheus */ static std::vector<::prometheus::MetricFamily> TranslateToPrometheus( - const sdk::metrics::ResourceMetrics &data); + const sdk::metrics::ResourceMetrics &data, + bool populate_target_info = true); private: + /** + * Append key-value pair to prometheus labels. + * + * @param name label name + * @param value label value + * @param labels target labels + */ + static void AddPrometheusLabel(std::string name, + std::string value, + std::vector<::prometheus::ClientMetric::Label> *labels); + static opentelemetry::sdk::metrics::AggregationType getAggregationType( const opentelemetry::sdk::metrics::PointType &point_type); @@ -41,6 +54,13 @@ class PrometheusExporterUtils static ::prometheus::MetricType TranslateType(opentelemetry::sdk::metrics::AggregationType kind, bool is_monotonic = true); + /** + * Add a target_info metric to collect resource attributes + */ + static void SetTarget(const sdk::metrics::ResourceMetrics &data, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + std::vector<::prometheus::MetricFamily> *output); + /** * Set metric data for: * Counter => Prometheus Counter @@ -50,7 +70,8 @@ class PrometheusExporterUtils const opentelemetry::sdk::metrics::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, ::prometheus::MetricType type, - ::prometheus::MetricFamily *metric_family); + ::prometheus::MetricFamily *metric_family, + const opentelemetry::sdk::resource::Resource *resource); /** * Set metric data for: @@ -62,7 +83,8 @@ class PrometheusExporterUtils const std::vector &counts, const opentelemetry::sdk::metrics::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, - ::prometheus::MetricFamily *metric_family); + ::prometheus::MetricFamily *metric_family, + const opentelemetry::sdk::resource::Resource *resource); /** * Set time and labels to metric data @@ -70,7 +92,8 @@ class PrometheusExporterUtils static void SetMetricBasic( ::prometheus::ClientMetric &metric, const opentelemetry::sdk::metrics::PointAttributes &labels, - const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope); + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + const opentelemetry::sdk::resource::Resource *resource); /** * Convert attribute value to string diff --git a/exporters/prometheus/src/collector.cc b/exporters/prometheus/src/collector.cc index 29c0bc8db2..33b9a9b8c8 100644 --- a/exporters/prometheus/src/collector.cc +++ b/exporters/prometheus/src/collector.cc @@ -17,7 +17,10 @@ namespace metrics * This constructor initializes the collection for metrics to export * in this class with default capacity */ -PrometheusCollector::PrometheusCollector(sdk::metrics::MetricReader *reader) : reader_(reader) {} +PrometheusCollector::PrometheusCollector(sdk::metrics::MetricReader *reader, + bool populate_target_info) + : reader_(reader), populate_target_info_(populate_target_info) +{} /** * Collects all metrics data from metricsToCollect collection. @@ -36,8 +39,10 @@ std::vector PrometheusCollector::Collect() cons collection_lock_.lock(); std::vector result; - reader_->Collect([&result](sdk::metrics::ResourceMetrics &metric_data) { - auto prometheus_metric_data = PrometheusExporterUtils::TranslateToPrometheus(metric_data); + + reader_->Collect([&result, this](sdk::metrics::ResourceMetrics &metric_data) { + auto prometheus_metric_data = + PrometheusExporterUtils::TranslateToPrometheus(metric_data, this->populate_target_info_); for (auto &data : prometheus_metric_data) result.emplace_back(data); return true; diff --git a/exporters/prometheus/src/exporter.cc b/exporters/prometheus/src/exporter.cc index 7691e32f39..6022c2c33b 100644 --- a/exporters/prometheus/src/exporter.cc +++ b/exporters/prometheus/src/exporter.cc @@ -30,7 +30,8 @@ PrometheusExporter::PrometheusExporter(const PrometheusExporterOptions &options) Shutdown(); // set MetricReader in shutdown state. return; } - collector_ = std::shared_ptr(new PrometheusCollector(this)); + collector_ = std::shared_ptr( + new PrometheusCollector(this, options_.populate_target_info)); exposer_->RegisterCollectable(collector_); } diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index c0f034ffe5..42fafc6336 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -1,14 +1,22 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include +#include +#include +#include #include #include + #include "prometheus/metric_family.h" +#include "prometheus/metric_type.h" -#include #include "opentelemetry/exporters/prometheus/exporter_utils.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/resource/semantic_conventions.h" +#include "opentelemetry/trace/semantic_conventions.h" #include "opentelemetry/sdk/common/global_log_handler.h" @@ -111,11 +119,25 @@ std::string SanitizeName(std::string name) * @return a collection of translated metrics that is acceptable by Prometheus */ std::vector PrometheusExporterUtils::TranslateToPrometheus( - const sdk::metrics::ResourceMetrics &data) + const sdk::metrics::ResourceMetrics &data, + bool populate_target_info) { // initialize output vector + std::size_t reserve_size = 1; + for (const auto &instrumentation_info : data.scope_metric_data_) + { + reserve_size += instrumentation_info.metric_data_.size(); + } + std::vector output; + output.reserve(reserve_size); + + // Append target_info as the first metric + if (populate_target_info && !data.scope_metric_data_.empty()) + { + SetTarget(data, (*data.scope_metric_data_.begin()).scope_, &output); + } for (const auto &instrumentation_info : data.scope_metric_data_) { @@ -151,10 +173,11 @@ std::vector PrometheusExporterUtils::TranslateT } else { - sum = nostd::get(histogram_point_data.sum_); + sum = static_cast(nostd::get(histogram_point_data.sum_)); } SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, - point_data_attr.attributes, instrumentation_info.scope_, &metric_family); + point_data_attr.attributes, instrumentation_info.scope_, &metric_family, + data.resource_); } else if (type == prometheus_client::MetricType::Gauge) { @@ -165,7 +188,7 @@ std::vector PrometheusExporterUtils::TranslateT nostd::get(point_data_attr.point_data); std::vector values{last_value_point_data.value_}; SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, - &metric_family); + &metric_family, data.resource_); } else if (nostd::holds_alternative(point_data_attr.point_data)) { @@ -173,7 +196,7 @@ std::vector PrometheusExporterUtils::TranslateT nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, - &metric_family); + &metric_family, data.resource_); } else { @@ -190,7 +213,7 @@ std::vector PrometheusExporterUtils::TranslateT nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, - &metric_family); + &metric_family, data.resource_); } else { @@ -206,6 +229,17 @@ std::vector PrometheusExporterUtils::TranslateT return output; } +void PrometheusExporterUtils::AddPrometheusLabel( + std::string name, + std::string value, + std::vector<::prometheus::ClientMetric::Label> *labels) +{ + prometheus_client::ClientMetric::Label prometheus_label; + prometheus_label.name = std::move(name); + prometheus_label.value = std::move(value); + labels->emplace_back(std::move(prometheus_label)); +} + metric_sdk::AggregationType PrometheusExporterUtils::getAggregationType( const metric_sdk::PointType &point_type) { @@ -259,6 +293,37 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType( } } +void PrometheusExporterUtils::SetTarget( + const sdk::metrics::ResourceMetrics &data, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + std::vector<::prometheus::MetricFamily> *output) +{ + if (output == nullptr || data.resource_ == nullptr) + { + return; + } + + prometheus_client::MetricFamily metric_family; + metric_family.name = "target"; + metric_family.help = "Target metadata"; + metric_family.type = prometheus_client::MetricType::Info; + metric_family.metric.emplace_back(); + + prometheus_client::ClientMetric &metric = metric_family.metric.back(); + metric.info.value = 1.0; + + metric_sdk::PointAttributes empty_attributes; + SetMetricBasic(metric, empty_attributes, scope, data.resource_); + + for (auto &label : data.resource_->GetAttributes()) + { + AddPrometheusLabel(SanitizeName(label.first), AttributeValueToString(label.second), + &metric.label); + } + + output->emplace_back(std::move(metric_family)); +} + /** * Set metric data for: * sum => Prometheus Counter @@ -269,11 +334,12 @@ void PrometheusExporterUtils::SetData( const metric_sdk::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, prometheus_client::MetricType type, - prometheus_client::MetricFamily *metric_family) + prometheus_client::MetricFamily *metric_family, + const opentelemetry::sdk::resource::Resource *resource) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels, scope); + SetMetricBasic(metric, labels, scope, resource); SetValue(values, type, &metric); } @@ -288,11 +354,12 @@ void PrometheusExporterUtils::SetData( const std::vector &counts, const metric_sdk::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, - prometheus_client::MetricFamily *metric_family) + prometheus_client::MetricFamily *metric_family, + const opentelemetry::sdk::resource::Resource *resource) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels, scope); + SetMetricBasic(metric, labels, scope, resource); SetValue(values, boundaries, counts, &metric); } @@ -302,9 +369,10 @@ void PrometheusExporterUtils::SetData( void PrometheusExporterUtils::SetMetricBasic( prometheus_client::ClientMetric &metric, const metric_sdk::PointAttributes &labels, - const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope) + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + const opentelemetry::sdk::resource::Resource *resource) { - if (labels.empty()) + if (labels.empty() && nullptr == resource) { return; } @@ -410,7 +478,7 @@ void PrometheusExporterUtils::SetValue(std::vector values, const auto &value_var = values[0]; if (nostd::holds_alternative(value_var)) { - value = nostd::get(value_var); + value = static_cast(nostd::get(value_var)); } else { @@ -445,9 +513,9 @@ void PrometheusExporterUtils::SetValue(std::vector values, const std::vector &counts, prometheus_client::ClientMetric *metric) { - metric->histogram.sample_sum = values[0]; - metric->histogram.sample_count = values[1]; - int cumulative = 0; + metric->histogram.sample_sum = static_cast(values[0]); + metric->histogram.sample_count = static_cast(values[1]); + std::uint64_t cumulative = 0; std::vector buckets; uint32_t idx = 0; for (const auto &boundary : boundaries) diff --git a/exporters/prometheus/test/collector_test.cc b/exporters/prometheus/test/collector_test.cc index 8947dcfd27..578e01d8f8 100644 --- a/exporters/prometheus/test/collector_test.cc +++ b/exporters/prometheus/test/collector_test.cc @@ -73,12 +73,12 @@ TEST(PrometheusCollector, BasicTests) MockMetricReader *reader = new MockMetricReader(); MockMetricProducer *producer = new MockMetricProducer(); reader->SetMetricProducer(producer); - PrometheusCollector collector(reader); + PrometheusCollector collector(reader, true); auto data = collector.Collect(); // Collection size should be the same as the size // of the records collection produced by MetricProducer. - ASSERT_EQ(data.size(), 1); + ASSERT_EQ(data.size(), 2); delete reader; delete producer; } diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 3c945c6735..8ff324d7ac 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -6,11 +6,11 @@ #include "prometheus/metric_type.h" #include "opentelemetry/exporters/prometheus/exporter_utils.h" +#include "opentelemetry/sdk/resource/resource.h" #include "prometheus_test_helper.h" using opentelemetry::exporter::metrics::PrometheusExporterUtils; namespace metric_sdk = opentelemetry::sdk::metrics; -namespace metric_api = opentelemetry::metrics; namespace prometheus_client = ::prometheus; OPENTELEMETRY_BEGIN_NAMESPACE @@ -20,7 +20,7 @@ void assert_basic(prometheus_client::MetricFamily &metric, const std::string &sanitized_name, const std::string &description, prometheus_client::MetricType type, - int label_num, + size_t label_num, std::vector vals) { ASSERT_EQ(metric.name, sanitized_name + "_unit"); // name sanitized @@ -97,45 +97,130 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusEmptyInputReturnsEmptyCollect TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) { + + opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create( + {{"service.name", "test_service"}, + {"service.namespace", "test_namespace"}, + {"service.instance.id", "localhost:8000"}, + {"custom_resource_attr", "custom_resource_value"}}); TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateSumPointData(); + metrics_data.resource_ = &resource; auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); - ASSERT_EQ(translated.size(), 1); + ASSERT_EQ(translated.size(), 2); - auto metric1 = translated[0]; + auto metric1 = translated[1]; std::vector vals = {10}; assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Counter, 3, vals); + + int checked_label_num = 0; + for (auto &label : translated[0].metric[0].label) + { + if (label.name == "service_namespace") + { + ASSERT_EQ(label.value, "test_namespace"); + checked_label_num++; + } + else if (label.name == "service_name") + { + ASSERT_EQ(label.value, "test_service"); + checked_label_num++; + } + else if (label.name == "service_instance_id") + { + ASSERT_EQ(label.value, "localhost:8000"); + checked_label_num++; + } + else if (label.name == "custom_resource_attr") + { + ASSERT_EQ(label.value, "custom_resource_value"); + checked_label_num++; + } + } + ASSERT_EQ(checked_label_num, 4); } TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) { + opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create( + {{"service.name", "test_service"}, + {"service.instance.id", "localhost:8000"}, + {"custom_resource_attr", "custom_resource_value"}}); TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateLastValuePointData(); + metrics_data.resource_ = &resource; auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); - ASSERT_EQ(translated.size(), 1); + ASSERT_EQ(translated.size(), 2); - auto metric1 = translated[0]; + auto metric1 = translated[1]; std::vector vals = {10}; assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Gauge, 3, vals); + + int checked_label_num = 0; + for (auto &label : translated[0].metric[0].label) + { + if (label.name == "service_name") + { + ASSERT_EQ(label.value, "test_service"); + checked_label_num++; + } + else if (label.name == "service_instance_id") + { + ASSERT_EQ(label.value, "localhost:8000"); + checked_label_num++; + } + else if (label.name == "custom_resource_attr") + { + ASSERT_EQ(label.value, "custom_resource_value"); + checked_label_num++; + } + } + ASSERT_EQ(checked_label_num, 3); } TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) { + opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create( + {{"service.instance.id", "localhost:8001"}, + {"custom_resource_attr", "custom_resource_value"}}); TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateHistogramPointData(); + metrics_data.resource_ = &resource; auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); - ASSERT_EQ(translated.size(), 1); + ASSERT_EQ(translated.size(), 2); - auto metric = translated[0]; + auto metric = translated[1]; std::vector vals = {3, 900.5, 4}; assert_basic(metric, "library_name", "description", prometheus_client::MetricType::Histogram, 3, vals); assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); + + int checked_label_num = 0; + for (auto &label : translated[0].metric[0].label) + { + if (label.name == "service_name") + { + // default service name is "unknown_service" + ASSERT_EQ(label.value, "unknown_service"); + checked_label_num++; + } + else if (label.name == "service_instance_id") + { + ASSERT_EQ(label.value, "localhost:8001"); + checked_label_num++; + } + else if (label.name == "custom_resource_attr") + { + ASSERT_EQ(label.value, "custom_resource_value"); + checked_label_num++; + } + } + ASSERT_EQ(checked_label_num, 3); } class SanitizeTest : public ::testing::Test @@ -152,7 +237,11 @@ class SanitizeTest : public ::testing::Test metric_sdk::InstrumentValueType::kDouble}; std::vector result = PrometheusExporterUtils::TranslateToPrometheus( {&resource_, - {{instrumentation_scope_.get(), {{instrument_descriptor, {}, {}, {}, {{{}, {}}}}}}}}); + std::vector{ + {instrumentation_scope_.get(), + std::vector{ + {{instrument_descriptor, {}, {}, {}, {{{}, {}}}}}}}}}, + false); EXPECT_EQ(result.begin()->name, sanitized + "_unit"); } @@ -163,8 +252,11 @@ class SanitizeTest : public ::testing::Test metric_sdk::InstrumentValueType::kDouble}; std::vector result = PrometheusExporterUtils::TranslateToPrometheus( {&resource_, - {{instrumentation_scope_.get(), - {{instrument_descriptor, {}, {}, {}, {{{{original, "value"}}, {}}}}}}}}); + std::vector{ + {instrumentation_scope_.get(), + std::vector{ + {instrument_descriptor, {}, {}, {}, {{{{original, "value"}}, {}}}}}}}}, + false); EXPECT_EQ(result.begin()->metric.begin()->label.begin()->name, sanitized); } }; @@ -204,8 +296,24 @@ class AttributeCollisionTest : public ::testing::Test { std::vector result = PrometheusExporterUtils::TranslateToPrometheus( {&resource_, - {{instrumentation_scope_.get(), {{instrument_descriptor_, {}, {}, {}, {{attrs, {}}}}}}}}); - EXPECT_EQ(result.begin()->metric.begin()->label, expected); + std::vector{ + {instrumentation_scope_.get(), + std::vector{ + {instrument_descriptor_, {}, {}, {}, {{attrs, {}}}}}}}}, + false); + for (auto &expected_kv : expected) + { + bool found = false; + for (auto &found_kv : result.begin()->metric.begin()->label) + { + if (found_kv.name == expected_kv.name) + { + EXPECT_EQ(found_kv.value, expected_kv.value); + found = true; + } + } + EXPECT_TRUE(found); + } } }; diff --git a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h index 2a0c87fcaa..11eb113e1e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include "opentelemetry/nostd/function_ref.h" @@ -31,14 +32,41 @@ namespace metrics */ struct ScopeMetrics { - const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope_; + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope_ = nullptr; std::vector metric_data_; + + template + inline ScopeMetrics(ScopePtr &&scope, MetricDataType &&metric) + : scope_{std::forward(scope)}, metric_data_{std::forward(metric)} + {} + + inline ScopeMetrics() {} + inline ScopeMetrics(const ScopeMetrics &) = default; + inline ScopeMetrics(ScopeMetrics &&) = default; + + inline ScopeMetrics &operator=(const ScopeMetrics &) = default; + + inline ScopeMetrics &operator=(ScopeMetrics &&) = default; }; struct ResourceMetrics { - const opentelemetry::sdk::resource::Resource *resource_; + const opentelemetry::sdk::resource::Resource *resource_ = nullptr; std::vector scope_metric_data_; + + template + inline ResourceMetrics(ResourcePtr &&resource, ScopeMetricsType &&scope_metric_data) + : resource_{std::forward(resource)}, + scope_metric_data_{std::forward(scope_metric_data)} + {} + + inline ResourceMetrics() {} + inline ResourceMetrics(const ResourceMetrics &) = default; + inline ResourceMetrics(ResourceMetrics &&) = default; + + inline ResourceMetrics &operator=(const ResourceMetrics &) = default; + + inline ResourceMetrics &operator=(ResourceMetrics &&) = default; }; /** From 05b26cae87acab7cdf3156941ece03acf8bd045f Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 10 Oct 2023 01:30:27 +0200 Subject: [PATCH 089/119] =?UTF-8?q?[BUILD]=20error:=20read-only=20referenc?= =?UTF-8?q?e=20=E2=80=98value=E2=80=99=20used=20as=20=E2=80=98asm=E2=80=99?= =?UTF-8?q?=20output=20(#2354)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/test/trace/sampler_benchmark.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index 42de190980..ec188b84a1 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -42,6 +42,11 @@ void BM_AlwaysOnSamplerConstruction(benchmark::State &state) } BENCHMARK(BM_AlwaysOnSamplerConstruction); +/* + Fails to build with GCC. + See upstream bug: https://github.com/google/benchmark/issues/1675 +*/ +#if 0 void BM_ParentBasedSamplerConstruction(benchmark::State &state) { while (state.KeepRunning()) @@ -59,6 +64,7 @@ void BM_TraceIdRatioBasedSamplerConstruction(benchmark::State &state) } } BENCHMARK(BM_TraceIdRatioBasedSamplerConstruction); +#endif // Sampler Helper Function void BenchmarkShouldSampler(Sampler &sampler, benchmark::State &state) From 18a27df365e0c347bd54db47341575e6b232dba0 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 10 Oct 2023 08:59:03 +0200 Subject: [PATCH 090/119] Fixes #2352 (#2353) --- exporters/otlp/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 8a93d34acc..adab87ff02 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -342,7 +342,8 @@ if(BUILD_TESTING) ${GMOCK_LIB} opentelemetry_exporter_otlp_http_log opentelemetry_logs - opentelemetry_http_client_nosend) + opentelemetry_http_client_nosend + nlohmann_json::nlohmann_json) gtest_add_tests( TARGET otlp_http_log_record_exporter_test TEST_PREFIX exporter.otlp. From df96b7429a635349ec5aa355716548ce4f184d90 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 11 Oct 2023 11:17:26 +0200 Subject: [PATCH 091/119] [BUILD] Upgrade libcurl to version 8.4.0 (#2358) --- bazel/repository.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index dd02fc98fc..7e09e299cf 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -145,11 +145,11 @@ def opentelemetry_cpp_deps(): http_archive, name = "curl", build_file = "@io_opentelemetry_cpp//bazel:curl.BUILD", - sha256 = "ba98332752257b47b9dea6d8c0ad25ec1745c20424f1dd3ff2c99ab59e97cf91", - strip_prefix = "curl-7.73.0", + sha256 = "816e41809c043ff285e8c0f06a75a1fa250211bbfb2dc0a037eeef39f1a9e427", + strip_prefix = "curl-8.4.0", urls = [ - "https://curl.haxx.se/download/curl-7.73.0.tar.gz", - "https://github.com/curl/curl/releases/download/curl-7_73_0/curl-7.73.0.tar.gz", + "https://curl.haxx.se/download/curl-8.4.0.tar.gz", + "https://github.com/curl/curl/releases/download/curl-8_4_0/curl-8.4.0.tar.gz", ], ) From 2c4b2a910c56ec60bcce0ba86a3296d59d121061 Mon Sep 17 00:00:00 2001 From: andremarianiello Date: Wed, 11 Oct 2023 13:18:32 -0400 Subject: [PATCH 092/119] Fix behavior of opentracing-shim when added as subdirectory of a larger project (#2356) --- opentracing-shim/CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index 5f83de5474..b77b9c1985 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -14,10 +14,13 @@ target_include_directories( "$") if(OPENTRACING_DIR) - include_directories( - "${CMAKE_BINARY_DIR}/${OPENTRACING_DIR}/include" - "${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/include" - "${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/3rd_party/include") + target_include_directories( + ${this_target} + PUBLIC + "$" + "$" + "$" + ) target_link_libraries(${this_target} opentelemetry_api opentracing) else() target_link_libraries(${this_target} opentelemetry_api From 3ff4b4c1f7e25c192ce0ebd1d27c611f7c081e04 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Sat, 14 Oct 2023 19:35:10 +0800 Subject: [PATCH 093/119] Fix protoc searching with non-imported protobuf::protoc target. (#2362) --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10c1a0ab6f..f57ce47779 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -430,6 +430,11 @@ if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) if(TARGET protobuf::protoc) project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc) + # If protobuf::protoc is not a imported target, then we use the target + # directly for fallback + if(NOT PROTOBUF_PROTOC_EXECUTABLE) + set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc) + endif() elseif(Protobuf_PROTOC_EXECUTABLE) # Some versions of FindProtobuf.cmake uses mixed case instead of uppercase set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE}) From cbee4de0ece961396742850ad426c9d9df830702 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Mon, 16 Oct 2023 15:00:24 +0800 Subject: [PATCH 094/119] [BUILD] Support to use different cmake package CONFIG of dependencies. (#2263) --- CMakeLists.txt | 1 + cmake/patch-imported-config.cmake | 141 ++++++++++++++++++++++++++++++ cmake/tools.cmake | 80 +++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 cmake/patch-imported-config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f57ce47779..4af81bf0e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -688,6 +688,7 @@ if(NOT WITH_API_ONLY) endif() include(cmake/opentelemetry-build-external-component.cmake) +include(cmake/patch-imported-config.cmake) if(OPENTELEMETRY_INSTALL) # Export cmake config and support find_packages(opentelemetry-cpp CONFIG) diff --git a/cmake/patch-imported-config.cmake b/cmake/patch-imported-config.cmake new file mode 100644 index 0000000000..ec68d74099 --- /dev/null +++ b/cmake/patch-imported-config.cmake @@ -0,0 +1,141 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Some prebuilt or installed targets may have different CONFIG settings than +# what we use to configure otel-cpp. This file applies patches to the imported +# targets in order to use compatible CONFIG settings for fallback. + +# Common dependencies +project_build_tools_patch_default_imported_config(ZLIB::ZLIB) + +# protobuf targets +if(Protobuf_FOUND OR PROTOBUF_FOUND) + project_build_tools_patch_default_imported_config( + utf8_range::utf8_range utf8_range::utf8_validity protobuf::libprotobuf-lite + protobuf::libprotobuf protobuf::libprotoc) +endif() + +# cares targets +if(TARGET c-ares::cares) + project_build_tools_patch_default_imported_config(c-ares::cares) +endif() + +# curl targets +if(TARGET CURL::libcurl) + project_build_tools_patch_default_imported_config(CURL::libcurl) +endif() + +# abseil targets +if(WITH_ABSEIL) + project_build_tools_patch_default_imported_config( + absl::bad_variant_access + absl::raw_logging_internal + absl::log_severity + absl::log_internal_check_op + absl::log_internal_nullguard + absl::strings + absl::strings_internal + absl::base + absl::spinlock_wait + absl::int128 + absl::throw_delegate + absl::log_internal_message + absl::examine_stack + absl::stacktrace + absl::debugging_internal + absl::symbolize + absl::demangle_internal + absl::malloc_internal + absl::log_internal_format + absl::log_internal_globals + absl::time + absl::civil_time + absl::time_zone + absl::str_format_internal + absl::log_internal_proto + absl::log_internal_log_sink_set + absl::log_globals + absl::hash + absl::city + absl::bad_optional_access + absl::low_level_hash + absl::log_entry + absl::log_sink + absl::synchronization + absl::graphcycles_internal + absl::strerror + absl::log_internal_conditions + absl::cord + absl::cord_internal + absl::crc_cord_state + absl::crc32c + absl::crc_cpu_detect + absl::crc_internal + absl::cordz_functions + absl::exponential_biased + absl::cordz_info + absl::cordz_handle + absl::leak_check + absl::die_if_null + absl::flags + absl::flags_commandlineflag + absl::flags_commandlineflag_internal + absl::flags_config + absl::flags_program_name + absl::flags_internal + absl::flags_marshalling + absl::flags_reflection + absl::flags_private_handle_accessor + absl::raw_hash_set + absl::hashtablez_sampler + absl::log_initialize + absl::status + absl::statusor) +endif() + +# gRPC targets +if(TARGET gRPC::grpc++) + project_build_tools_patch_default_imported_config( + gRPC::cares + gRPC::re2 + gRPC::ssl + gRPC::crypto + gRPC::zlibstatic + gRPC::address_sorting + gRPC::gpr + gRPC::grpc + gRPC::grpc_unsecure + gRPC::grpc++ + gRPC::grpc++_alts + gRPC::grpc++_error_details + gRPC::grpc++_reflection + gRPC::grpc++_unsecure + gRPC::grpc_authorization_provider + gRPC::grpc_plugin_support + gRPC::grpcpp_channelz + gRPC::upb) +endif() + +# prometheus targets +if(TARGET prometheus-cpp::core) + project_build_tools_patch_default_imported_config( + prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push) +endif() + +# civetweb targets +if(TARGET civetweb::civetweb) + project_build_tools_patch_default_imported_config( + civetweb::civetweb civetweb::server civetweb::civetweb-cpp) +endif() + +if(BUILD_TESTING) + project_build_tools_patch_default_imported_config( + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + GTest::GTest + GTest::Main + benchmark::benchmark + benchmark::benchmark_main) +endif() diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 345fc88ff7..ee191121ca 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -117,3 +117,83 @@ function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME) PARENT_SCOPE) endif() endfunction() + +#[[ +If we build third party packages with a different CONFIG setting from building +otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359) +when linking. But on some platforms, different CONFIG settings can be used when +these CONFIG settings have the same ABI. For example, on Linux, we can build +gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with +-DCMAKE_BUILD_TYPE=Debug and link these libraries together. +The properties of imported targets can be found here: +https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets +]] +function(project_build_tools_patch_default_imported_config) + set(PATCH_VARS + IMPORTED_IMPLIB + IMPORTED_LIBNAME + IMPORTED_LINK_DEPENDENT_LIBRARIES + IMPORTED_LINK_INTERFACE_LANGUAGES + IMPORTED_LINK_INTERFACE_LIBRARIES + IMPORTED_LINK_INTERFACE_MULTIPLICITY + IMPORTED_LOCATION + IMPORTED_NO_SONAME + IMPORTED_OBJECTS + IMPORTED_SONAME) + foreach(TARGET_NAME ${ARGN}) + if(TARGET ${TARGET_NAME}) + get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED) + if(NOT IS_IMPORTED_TARGET) + continue() + endif() + + if(CMAKE_VERSION VERSION_LESS "3.19.0") + get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE) + if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY") + continue() + endif() + endif() + + get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION) + if(DO_NOT_OVERWRITE) + continue() + endif() + + # MSVC's STL and debug level must match the target, so we can only move + # out IMPORTED_LOCATION_NOCONFIG + if(MSVC) + set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG") + else() + get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} + IMPORTED_CONFIGURATIONS) + endif() + + if(NOT PATCH_IMPORTED_CONFIGURATION) + continue() + endif() + + get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} + "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}") + if(NOT PATCH_TARGET_LOCATION) + continue() + endif() + + foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS) + get_target_property( + PATCH_IMPORTED_VALUE ${TARGET_NAME} + "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}") + if(PATCH_IMPORTED_VALUE) + set_target_properties( + ${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" + "${PATCH_IMPORTED_VALUE}") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message( + STATUS + "Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default." + ) + endif() + endif() + endforeach() + endif() + endforeach() +endfunction() From f2cbf02ec167729cedb177f4b85133121513a796 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 16 Oct 2023 09:38:30 +0200 Subject: [PATCH 095/119] [SEMANTIC CONVENTION] Upgrade to semconv 1.22.0 (#2368) --- .../trace/semantic_conventions.h | 1832 ++++++++++------- buildscripts/semantic-convention/generate.sh | 4 +- examples/grpc/client.cc | 4 +- .../sdk/resource/semantic_conventions.h | 496 +++-- 4 files changed, 1370 insertions(+), 966 deletions(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index c46b41bc52..16d6562ee9 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -22,285 +22,291 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.21.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.22.0"; /** - * Client address - unix domain socket name, IPv4 or IPv6 address. + * Client address - domain name if available without reverse DNS lookup, otherwise IP address or + Unix domain socket name. * *

        Notes:

        • When observed from the server side, and when communicating through an intermediary, - {@code client.address} SHOULD represent client address behind any intermediaries (e.g. proxies) if - it's available.
        + {@code client.address} SHOULD represent the client address behind any intermediaries (e.g. proxies) + if it's available.
      */ static constexpr const char *kClientAddress = "client.address"; /** - * Client port number + * Client port number. * *

      Notes:

      • When observed from the server side, and when communicating through an intermediary, - {@code client.port} SHOULD represent client port behind any intermediaries (e.g. proxies) if it's - available.
      + {@code client.port} SHOULD represent the client port behind any intermediaries (e.g. proxies) if + it's available.
    */ static constexpr const char *kClientPort = "client.port"; /** - * Immediate client peer address - unix domain socket name, IPv4 or IPv6 address. - */ -static constexpr const char *kClientSocketAddress = "client.socket.address"; - -/** - * Immediate client peer port number + * Deprecated, use {@code server.address}. + * + * @deprecated Deprecated, use `server.address`. */ -static constexpr const char *kClientSocketPort = "client.socket.port"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kNetHostName = "net.host.name"; /** - * Deprecated, use {@code http.request.method} instead. + * Deprecated, use {@code server.port}. * - * @deprecated Deprecated, use `http.request.method` instead. + * @deprecated Deprecated, use `server.port`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpMethod = "http.method"; +static constexpr const char *kNetHostPort = "net.host.port"; /** - * Deprecated, use {@code http.response.status_code} instead. + * Deprecated, use {@code server.address} on client spans and {@code client.address} on server + * spans. * - * @deprecated Deprecated, use `http.response.status_code` instead. + * @deprecated Deprecated, use `server.address` on client spans and `client.address` on server + * spans. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpStatusCode = "http.status_code"; +static constexpr const char *kNetPeerName = "net.peer.name"; /** - * Deprecated, use {@code url.scheme} instead. + * Deprecated, use {@code server.port} on client spans and {@code client.port} on server spans. * - * @deprecated Deprecated, use `url.scheme` instead. + * @deprecated Deprecated, use `server.port` on client spans and `client.port` on server spans. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpScheme = "http.scheme"; +static constexpr const char *kNetPeerPort = "net.peer.port"; /** - * Deprecated, use {@code url.full} instead. + * Deprecated, use {@code network.protocol.name}. * - * @deprecated Deprecated, use `url.full` instead. + * @deprecated Deprecated, use `network.protocol.name`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpUrl = "http.url"; +static constexpr const char *kNetProtocolName = "net.protocol.name"; /** - * Deprecated, use {@code url.path} and {@code url.query} instead. + * Deprecated, use {@code network.protocol.version}. * - * @deprecated Deprecated, use `url.path` and `url.query` instead. + * @deprecated Deprecated, use `network.protocol.version`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpTarget = "http.target"; +static constexpr const char *kNetProtocolVersion = "net.protocol.version"; /** - * Deprecated, use {@code http.request.body.size} instead. + * Deprecated, use {@code network.transport} and {@code network.type}. * - * @deprecated Deprecated, use `http.request.body.size` instead. + * @deprecated Deprecated, use `network.transport` and `network.type`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpRequestContentLength = "http.request_content_length"; +static constexpr const char *kNetSockFamily = "net.sock.family"; /** - * Deprecated, use {@code http.response.body.size} instead. + * Deprecated, use {@code network.local.address}. * - * @deprecated Deprecated, use `http.response.body.size` instead. + * @deprecated Deprecated, use `network.local.address`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kHttpResponseContentLength = "http.response_content_length"; +static constexpr const char *kNetSockHostAddr = "net.sock.host.addr"; /** - * Deprecated, use {@code server.socket.domain} on client spans. + * Deprecated, use {@code network.local.port}. * - * @deprecated Deprecated, use `server.socket.domain` on client spans. + * @deprecated Deprecated, use `network.local.port`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetSockPeerName = "net.sock.peer.name"; +static constexpr const char *kNetSockHostPort = "net.sock.host.port"; /** - * Deprecated, use {@code server.socket.address} on client spans and {@code client.socket.address} - * on server spans. + * Deprecated, use {@code network.peer.address}. * - * @deprecated Deprecated, use `server.socket.address` on client spans and `client.socket.address` - * on server spans. + * @deprecated Deprecated, use `network.peer.address`. */ OPENTELEMETRY_DEPRECATED static constexpr const char *kNetSockPeerAddr = "net.sock.peer.addr"; /** - * Deprecated, use {@code server.socket.port} on client spans and {@code client.socket.port} on - * server spans. + * Deprecated, no replacement at this time. * - * @deprecated Deprecated, use `server.socket.port` on client spans and `client.socket.port` on - * server spans. + * @deprecated Deprecated, no replacement at this time. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetSockPeerPort = "net.sock.peer.port"; +static constexpr const char *kNetSockPeerName = "net.sock.peer.name"; /** - * Deprecated, use {@code server.address} on client spans and {@code client.address} on server - * spans. + * Deprecated, use {@code network.peer.port}. * - * @deprecated Deprecated, use `server.address` on client spans and `client.address` on server - * spans. + * @deprecated Deprecated, use `network.peer.port`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetPeerName = "net.peer.name"; +static constexpr const char *kNetSockPeerPort = "net.sock.peer.port"; /** - * Deprecated, use {@code server.port} on client spans and {@code client.port} on server spans. + * Deprecated, use {@code network.transport}. * - * @deprecated Deprecated, use `server.port` on client spans and `client.port` on server spans. + * @deprecated Deprecated, use `network.transport`. */ OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetPeerPort = "net.peer.port"; +static constexpr const char *kNetTransport = "net.transport"; /** - * Deprecated, use {@code server.address}. + * Destination address - domain name if available without reverse DNS lookup, otherwise IP address + or Unix domain socket name. * - * @deprecated Deprecated, use `server.address`. + *

    Notes: +

    • When observed from the source side, and when communicating through an intermediary, + {@code destination.address} SHOULD represent the destination address behind any intermediaries + (e.g. proxies) if it's available.
    */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetHostName = "net.host.name"; +static constexpr const char *kDestinationAddress = "destination.address"; /** - * Deprecated, use {@code server.port}. - * - * @deprecated Deprecated, use `server.port`. + * Destination port number */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetHostPort = "net.host.port"; +static constexpr const char *kDestinationPort = "destination.port"; /** - * Deprecated, use {@code server.socket.address}. + * Describes a class of error the operation ended with. * - * @deprecated Deprecated, use `server.socket.address`. + *

    Notes: +

    • The {@code error.type} SHOULD be predictable and SHOULD have low cardinality. +Instrumentations SHOULD document the list of errors they report.
    • The cardinality of {@code +error.type} within one instrumentation library SHOULD be low, but telemetry consumers that aggregate +data from multiple instrumentation libraries and applications should be prepared for {@code +error.type} to have high cardinality at query time, when no additional filters are +applied.
    • If the operation has completed successfully, instrumentations SHOULD NOT set {@code +error.type}.
    • If a specific domain defines its own set of error codes (such as HTTP or gRPC +status codes), it's RECOMMENDED to use a domain-specific attribute and also set {@code error.type} +to capture all errors, regardless of whether they are defined within the domain-specific set or +not.
    */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetSockHostAddr = "net.sock.host.addr"; +static constexpr const char *kErrorType = "error.type"; /** - * Deprecated, use {@code server.socket.port}. - * - * @deprecated Deprecated, use `server.socket.port`. + * The exception message. */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetSockHostPort = "net.sock.host.port"; +static constexpr const char *kExceptionMessage = "exception.message"; /** - * Deprecated, use {@code network.transport}. - * - * @deprecated Deprecated, use `network.transport`. + * A stacktrace as a string in the natural representation for the language runtime. The + * representation is to be determined and documented by each language SIG. */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetTransport = "net.transport"; +static constexpr const char *kExceptionStacktrace = "exception.stacktrace"; /** - * Deprecated, use {@code network.protocol.name}. - * - * @deprecated Deprecated, use `network.protocol.name`. + * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of + * the exception should be preferred over the static type in languages that support it. */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetProtocolName = "net.protocol.name"; +static constexpr const char *kExceptionType = "exception.type"; /** - * Deprecated, use {@code network.protocol.version}. + * The name of the invoked function. * - * @deprecated Deprecated, use `network.protocol.version`. + *

    Notes: +

    • SHOULD be equal to the {@code faas.name} resource attribute of the invoked function.
    • +
    */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetProtocolVersion = "net.protocol.version"; +static constexpr const char *kFaasInvokedName = "faas.invoked_name"; /** - * Deprecated, use {@code network.transport} and {@code network.type}. + * The cloud provider of the invoked function. * - * @deprecated Deprecated, use `network.transport` and `network.type`. + *

    Notes: +

    • SHOULD be equal to the {@code cloud.provider} resource attribute of the invoked + function.
    */ -OPENTELEMETRY_DEPRECATED -static constexpr const char *kNetSockFamily = "net.sock.family"; +static constexpr const char *kFaasInvokedProvider = "faas.invoked_provider"; /** - * The domain name of the destination system. + * The cloud region of the invoked function. * *

    Notes: -

    • This value may be a host name, a fully qualified domain name, or another host naming - format.
    +
    • SHOULD be equal to the {@code cloud.region} resource attribute of the invoked + function.
    */ -static constexpr const char *kDestinationDomain = "destination.domain"; +static constexpr const char *kFaasInvokedRegion = "faas.invoked_region"; /** - * Peer address, for example IP address or UNIX socket name. + * Type of the trigger which caused this function invocation. */ -static constexpr const char *kDestinationAddress = "destination.address"; +static constexpr const char *kFaasTrigger = "faas.trigger"; /** - * Peer port number + * The {@code service.name} of the remote service. + * SHOULD be equal to the actual {@code service.name} resource attribute of the remote service if + * any. */ -static constexpr const char *kDestinationPort = "destination.port"; +static constexpr const char *kPeerService = "peer.service"; /** - * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of - * the exception should be preferred over the static type in languages that support it. + * Username or client_id extracted from the access token or Authorization header in the inbound + * request from outside the system. */ -static constexpr const char *kExceptionType = "exception.type"; +static constexpr const char *kEnduserId = "enduser.id"; /** - * The exception message. + * Actual/assumed role the client is making the request under extracted from token or application + * security context. */ -static constexpr const char *kExceptionMessage = "exception.message"; +static constexpr const char *kEnduserRole = "enduser.role"; /** - * A stacktrace as a string in the natural representation for the language runtime. The - * representation is to be determined and documented by each language SIG. + * 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 *kExceptionStacktrace = "exception.stacktrace"; +static constexpr const char *kEnduserScope = "enduser.scope"; /** - * HTTP request method. - * - *

    Notes: -

    • HTTP request method value SHOULD be "known" to the instrumentation. -By default, this convention defines "known" methods as the ones listed in RFC9110 and the PATCH method -defined in RFC5789.
    • If the HTTP -request method is not known to instrumentation, it MUST set the {@code http.request.method} -attribute to {@code _OTHER} and, except if reporting a metric, MUST set the exact method received in -the request line as value of the {@code http.request.method_original} attribute.
    • If the HTTP -instrumentation could end up converting valid HTTP request methods to {@code _OTHER}, then it MUST -provide a way to override the list of known HTTP methods. If this override is done via environment -variable, then the environment variable MUST be named OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and -support a comma-separated list of case-sensitive known HTTP methods (this list MUST be a full -override of the default known method, it is not a list of known methods in addition to the -defaults).
    • HTTP method names are case-sensitive and {@code http.request.method} attribute -value MUST match a known HTTP method name exactly. Instrumentations for specific web frameworks that -consider HTTP methods to be case insensitive, SHOULD populate a canonical equivalent. Tracing -instrumentations that do so, MUST also set {@code http.request.method_original} to the original -value.
    + * Whether the thread is daemon or not. */ -static constexpr const char *kHttpRequestMethod = "http.request.method"; +static constexpr const char *kThreadDaemon = "thread.daemon"; /** - * HTTP response status code. + * Current "managed" thread ID (as opposed to OS thread ID). */ -static constexpr const char *kHttpResponseStatusCode = "http.response.status_code"; +static constexpr const char *kThreadId = "thread.id"; /** - * The matched route (path template in the format used by the respective server framework). See note -below - * - *

    Notes: -

    • MUST NOT be populated when this is not supported by the HTTP server framework as the -route attribute should have low-cardinality and the URI path can NOT substitute it. SHOULD include -the application root if there is -one.
    + * Current thread name. */ -static constexpr const char *kHttpRoute = "http.route"; +static constexpr const char *kThreadName = "thread.name"; /** - * The name identifies the event. + * The column number in {@code code.filepath} best representing the operation. It SHOULD point + * within the code unit named in {@code code.function}. */ -static constexpr const char *kEventName = "event.name"; +static constexpr const char *kCodeColumn = "code.column"; + +/** + * The source code file name that identifies the code unit as uniquely as possible (preferably an + * absolute file path). + */ +static constexpr const char *kCodeFilepath = "code.filepath"; + +/** + * The method or function name, or equivalent (usually rightmost part of the code unit's name). + */ +static constexpr const char *kCodeFunction = "code.function"; + +/** + * The line number in {@code code.filepath} best representing the operation. It SHOULD point within + * the code unit named in {@code code.function}. + */ +static constexpr const char *kCodeLineno = "code.lineno"; + +/** + * The "namespace" within which {@code code.function} is defined. Usually the qualified + * class or module name, such that {@code code.namespace} + some separator + {@code code.function} + * form a unique identifier for the code unit. + */ +static constexpr const char *kCodeNamespace = "code.namespace"; /** * The domain identifies the business context for the events. @@ -311,6 +317,11 @@ unrelated events.
*/ static constexpr const char *kEventDomain = "event.domain"; +/** + * The name identifies the event. + */ +static constexpr const char *kEventName = "event.name"; + /** * A unique identifier for the Log Record. * @@ -333,14 +344,14 @@ static constexpr const char *kLogIostream = "log.iostream"; static constexpr const char *kLogFileName = "log.file.name"; /** - * The full path to the file. + * The basename of the file, with symlinks resolved. */ -static constexpr const char *kLogFilePath = "log.file.path"; +static constexpr const char *kLogFileNameResolved = "log.file.name_resolved"; /** - * The basename of the file, with symlinks resolved. + * The full path to the file. */ -static constexpr const char *kLogFileNameResolved = "log.file.name_resolved"; +static constexpr const char *kLogFilePath = "log.file.path"; /** * The full path to the file, with symlinks resolved. @@ -348,9 +359,27 @@ static constexpr const char *kLogFileNameResolved = "log.file.name_resolved"; static constexpr const char *kLogFilePathResolved = "log.file.path_resolved"; /** - * The type of memory. + * The name of the connection pool; unique within the instrumented application. In case the + * connection pool implementation does not provide a name, then the db.connection_string + * should be used + */ +static constexpr const char *kPoolName = "pool.name"; + +/** + * The state of a connection in the pool + */ +static constexpr const char *kState = "state"; + +/** + * Name of the buffer pool. + * + *

Notes: +

*/ -static constexpr const char *kType = "type"; +static constexpr const char *kJvmBufferPoolName = "jvm.buffer.pool.name"; /** * Name of the memory pool. @@ -360,570 +389,669 @@ static constexpr const char *kType = "type"; href="https://docs.oracle.com/en/java/javase/11/docs/api/java.management/java/lang/management/MemoryPoolMXBean.html#getName()">MemoryPoolMXBean#getName(). */ -static constexpr const char *kPool = "pool"; +static constexpr const char *kJvmMemoryPoolName = "jvm.memory.pool.name"; /** - * Logical server hostname, matches server FQDN if available, and IP or socket address if FQDN is - * not known. + * The type of memory. */ -static constexpr const char *kServerAddress = "server.address"; +static constexpr const char *kJvmMemoryType = "jvm.memory.type"; /** - * Logical server port number + * The device identifier */ -static constexpr const char *kServerPort = "server.port"; +static constexpr const char *kSystemDevice = "system.device"; /** - * The domain name of an immediate peer. - * - *

Notes: -

  • Typically observed from the client side, and represents a proxy or other intermediary - domain name.
+ * The logical CPU number [0..n-1] */ -static constexpr const char *kServerSocketDomain = "server.socket.domain"; +static constexpr const char *kSystemCpuLogicalNumber = "system.cpu.logical_number"; /** - * Physical server IP address or Unix socket address. If set from the client, should simply use the - * socket's peer address, and not attempt to find any actual server IP (i.e., if set from client, - * this may represent some proxy server instead of the logical server). + * The state of the CPU */ -static constexpr const char *kServerSocketAddress = "server.socket.address"; +static constexpr const char *kSystemCpuState = "system.cpu.state"; /** - * Physical server port. + * The memory state */ -static constexpr const char *kServerSocketPort = "server.socket.port"; +static constexpr const char *kSystemMemoryState = "system.memory.state"; /** - * The domain name of the source system. - * - *

Notes: -

  • This value may be a host name, a fully qualified domain name, or another host naming - format.
+ * The paging access direction */ -static constexpr const char *kSourceDomain = "source.domain"; +static constexpr const char *kSystemPagingDirection = "system.paging.direction"; /** - * Source address, for example IP address or Unix socket name. + * The memory paging state */ -static constexpr const char *kSourceAddress = "source.address"; +static constexpr const char *kSystemPagingState = "system.paging.state"; /** - * Source port number + * The memory paging type */ -static constexpr const char *kSourcePort = "source.port"; +static constexpr const char *kSystemPagingType = "system.paging.type"; /** - * The full invoked ARN as provided on the {@code Context} passed to the function ({@code - Lambda-Runtime-Invoked-Function-Arn} header on the {@code /runtime/invocation/next} applicable). - * - *

Notes: -

  • This may be different from {@code cloud.resource_id} if an alias is involved.
+ * The disk operation direction */ -static constexpr const char *kAwsLambdaInvokedArn = "aws.lambda.invoked_arn"; +static constexpr const char *kSystemDiskDirection = "system.disk.direction"; /** - * The event_id - * uniquely identifies the event. + * The filesystem mode */ -static constexpr const char *kCloudeventsEventId = "cloudevents.event_id"; +static constexpr const char *kSystemFilesystemMode = "system.filesystem.mode"; /** - * The source - * identifies the context in which an event happened. + * The filesystem mount path */ -static constexpr const char *kCloudeventsEventSource = "cloudevents.event_source"; +static constexpr const char *kSystemFilesystemMountpoint = "system.filesystem.mountpoint"; /** - * The version of - * the CloudEvents specification which the event uses. + * The filesystem state */ -static constexpr const char *kCloudeventsEventSpecVersion = "cloudevents.event_spec_version"; +static constexpr const char *kSystemFilesystemState = "system.filesystem.state"; /** - * The event_type - * contains a value describing the type of event related to the originating occurrence. + * The filesystem type */ -static constexpr const char *kCloudeventsEventType = "cloudevents.event_type"; +static constexpr const char *kSystemFilesystemType = "system.filesystem.type"; /** - * The subject of - * the event in the context of the event producer (identified by source). + * */ -static constexpr const char *kCloudeventsEventSubject = "cloudevents.event_subject"; +static constexpr const char *kSystemNetworkDirection = "system.network.direction"; /** - * Parent-child Reference type - * - *

Notes: -

  • The causal relationship between a child Span and a parent Span.
+ * A stateless protocol MUST NOT set this attribute */ -static constexpr const char *kOpentracingRefType = "opentracing.ref_type"; +static constexpr const char *kSystemNetworkState = "system.network.state"; /** - * An identifier for the database management system (DBMS) product being used. See below for a list - * of well-known identifiers. + * The process state, e.g., Linux Process State + * Codes */ -static constexpr const char *kDbSystem = "db.system"; +static constexpr const char *kSystemProcessesStatus = "system.processes.status"; /** - * The connection string used to connect to the database. It is recommended to remove embedded - * credentials. + * Local address of the network connection - IP address or Unix domain socket name. */ -static constexpr const char *kDbConnectionString = "db.connection_string"; +static constexpr const char *kNetworkLocalAddress = "network.local.address"; /** - * Username for accessing the database. + * Local port number of the network connection. */ -static constexpr const char *kDbUser = "db.user"; +static constexpr const char *kNetworkLocalPort = "network.local.port"; /** - * The fully-qualified class name of the Java Database Connectivity - * (JDBC) driver used to connect. + * Peer address of the network connection - IP address or Unix domain socket name. */ -static constexpr const char *kDbJdbcDriverClassname = "db.jdbc.driver_classname"; +static constexpr const char *kNetworkPeerAddress = "network.peer.address"; /** - * This attribute is used to report the name of the database being accessed. For commands that - switch the database, this should be set to the target database (even if the command fails). + * Peer port number of the network connection. + */ +static constexpr const char *kNetworkPeerPort = "network.peer.port"; + +/** + * OSI application layer or non-OSI + equivalent. * *

Notes: -

  • In some SQL databases, the database name to be used is called "schema name". In - case there are multiple layers that could be considered for database name (e.g. Oracle instance - name and schema name), the database name to be used is the more specific layer (e.g. Oracle schema - name).
+
  • The value SHOULD be normalized to lowercase.
*/ -static constexpr const char *kDbName = "db.name"; +static constexpr const char *kNetworkProtocolName = "network.protocol.name"; /** - * The database statement being executed. + * Version of the protocol specified in {@code network.protocol.name}. + * + *

Notes: +

  • {@code network.protocol.version} refers to the version of the protocol used and might be + different from the protocol client's version. If the HTTP client used has a version of {@code + 0.27.2}, but sends HTTP version {@code 1.1}, this attribute should be set to {@code 1.1}.
  • +
*/ -static constexpr const char *kDbStatement = "db.statement"; +static constexpr const char *kNetworkProtocolVersion = "network.protocol.version"; /** - * The name of the operation being executed, e.g. the MongoDB command - name such as {@code findAndModify}, or the SQL keyword. + * OSI transport layer or inter-process communication +method. * *

Notes: -

  • When setting this to an SQL keyword, it is not recommended to attempt any client-side - parsing of {@code db.statement} just to get this property, but it should be set if the operation - name is provided by the library being instrumented. If the SQL statement has an ambiguous - operation, or performs more than one operation, this value may be omitted.
+
  • The value SHOULD be normalized to lowercase.
  • Consider always setting the +transport when setting a port number, since a port number is ambiguous without knowing the +transport, for example different processes could be listening on TCP port 12345 and UDP port +12345.
*/ -static constexpr const char *kDbOperation = "db.operation"; +static constexpr const char *kNetworkTransport = "network.transport"; /** - * The Microsoft SQL Server instance - name connecting to. This name is used to determine the port of a named instance. + * OSI network layer or non-OSI equivalent. * *

Notes: -

  • If setting a {@code db.mssql.instance_name}, {@code server.port} is no longer required - (but still recommended if non-standard).
+
  • The value SHOULD be normalized to lowercase.
*/ -static constexpr const char *kDbMssqlInstanceName = "db.mssql.instance_name"; +static constexpr const char *kNetworkType = "network.type"; /** - * The fetch size used for paging, i.e. how many rows will be returned at once. + * The ISO 3166-1 alpha-2 2-character country code associated with the mobile carrier network. */ -static constexpr const char *kDbCassandraPageSize = "db.cassandra.page_size"; +static constexpr const char *kNetworkCarrierIcc = "network.carrier.icc"; /** - * The consistency level of the query. Based on consistency values from CQL. + * The mobile carrier country code. */ -static constexpr const char *kDbCassandraConsistencyLevel = "db.cassandra.consistency_level"; +static constexpr const char *kNetworkCarrierMcc = "network.carrier.mcc"; /** - * The name of the primary table that the operation is acting upon, including the keyspace name (if - applicable). + * The mobile carrier network code. + */ +static constexpr const char *kNetworkCarrierMnc = "network.carrier.mnc"; + +/** + * The name of the mobile carrier. + */ +static constexpr const char *kNetworkCarrierName = "network.carrier.name"; + +/** + * This describes more details regarding the connection.type. It may be the type of cell technology + * connection, but it could be used for describing details about a wifi connection. + */ +static constexpr const char *kNetworkConnectionSubtype = "network.connection.subtype"; + +/** + * The internet connection type. + */ +static constexpr const char *kNetworkConnectionType = "network.connection.type"; + +/** + * Deprecated, use {@code http.request.method} instead. * - *

Notes: -

  • This mirrors the db.sql.table attribute but references cassandra rather than sql. It is - not recommended to attempt any client-side parsing of {@code db.statement} just to get this - property, but it should be set if it is provided by the library being instrumented. If the - operation is acting upon an anonymous table, or more than one table, this value MUST NOT be - set.
+ * @deprecated Deprecated, use `http.request.method` instead. */ -static constexpr const char *kDbCassandraTable = "db.cassandra.table"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpMethod = "http.method"; /** - * Whether or not the query is idempotent. + * Deprecated, use {@code http.request.body.size} instead. + * + * @deprecated Deprecated, use `http.request.body.size` instead. */ -static constexpr const char *kDbCassandraIdempotence = "db.cassandra.idempotence"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpRequestContentLength = "http.request_content_length"; /** - * The number of times a query was speculatively executed. Not set or {@code 0} if the query was not - * executed speculatively. + * Deprecated, use {@code http.response.body.size} instead. + * + * @deprecated Deprecated, use `http.response.body.size` instead. */ -static constexpr const char *kDbCassandraSpeculativeExecutionCount = - "db.cassandra.speculative_execution_count"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpResponseContentLength = "http.response_content_length"; /** - * The ID of the coordinating node for a query. + * Deprecated, use {@code url.scheme} instead. + * + * @deprecated Deprecated, use `url.scheme` instead. */ -static constexpr const char *kDbCassandraCoordinatorId = "db.cassandra.coordinator.id"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpScheme = "http.scheme"; /** - * The data center of the coordinating node for a query. + * Deprecated, use {@code http.response.status_code} instead. + * + * @deprecated Deprecated, use `http.response.status_code` instead. */ -static constexpr const char *kDbCassandraCoordinatorDc = "db.cassandra.coordinator.dc"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpStatusCode = "http.status_code"; /** - * The index of the database being accessed as used in the {@code SELECT} command, provided as an integer. To be - * used instead of the generic {@code db.name} attribute. + * Deprecated, use {@code url.path} and {@code url.query} instead. + * + * @deprecated Deprecated, use `url.path` and `url.query` instead. */ -static constexpr const char *kDbRedisDatabaseIndex = "db.redis.database_index"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpTarget = "http.target"; /** - * The collection being accessed within the database stated in {@code db.name}. + * Deprecated, use {@code url.full} instead. + * + * @deprecated Deprecated, use `url.full` instead. */ -static constexpr const char *kDbMongodbCollection = "db.mongodb.collection"; +OPENTELEMETRY_DEPRECATED +static constexpr const char *kHttpUrl = "http.url"; /** - * The name of the primary table that the operation is acting upon, including the database name (if - applicable). + * The size of the request payload body in bytes. This is the number of bytes transferred excluding + * headers and is often, but not always, present as the Content-Length + * header. For requests using transport encoding, this should be the compressed size. + */ +static constexpr const char *kHttpRequestBodySize = "http.request.body.size"; + +/** + * HTTP request method. * *

Notes: -

  • It is not recommended to attempt any client-side parsing of {@code db.statement} just to - get this property, but it should be set if it is provided by the library being instrumented. If the - operation is acting upon an anonymous table, or more than one table, this value MUST NOT be - set.
+
  • HTTP request method value SHOULD be "known" to the instrumentation. +By default, this convention defines "known" methods as the ones listed in RFC9110 and the PATCH method +defined in RFC5789.
  • If the HTTP +request method is not known to instrumentation, it MUST set the {@code http.request.method} +attribute to {@code _OTHER}.
  • If the HTTP instrumentation could end up converting valid HTTP +request methods to {@code _OTHER}, then it MUST provide a way to override the list of known HTTP +methods. If this override is done via environment variable, then the environment variable MUST be +named OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and support a comma-separated list of case-sensitive +known HTTP methods (this list MUST be a full override of the default known method, it is not a list +of known methods in addition to the defaults).
  • HTTP method names are case-sensitive and +{@code http.request.method} attribute value MUST match a known HTTP method name exactly. +Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, +SHOULD populate a canonical equivalent. Tracing instrumentations that do so, MUST also set {@code +http.request.method_original} to the original value.
*/ -static constexpr const char *kDbSqlTable = "db.sql.table"; +static constexpr const char *kHttpRequestMethod = "http.request.method"; /** - * Unique Cosmos client instance id. + * Original HTTP method sent by the client in the request line. */ -static constexpr const char *kDbCosmosdbClientId = "db.cosmosdb.client_id"; +static constexpr const char *kHttpRequestMethodOriginal = "http.request.method_original"; /** - * CosmosDB Operation Type. + * The ordinal number of request resending attempt (for any reason, including redirects). + * + *

Notes: +

  • The resend count SHOULD be updated each time an HTTP request gets resent by the client, + regardless of what was the cause of the resending (e.g. redirection, authorization failure, 503 + Server Unavailable, network issues, or any other).
*/ -static constexpr const char *kDbCosmosdbOperationType = "db.cosmosdb.operation_type"; +static constexpr const char *kHttpResendCount = "http.resend_count"; /** - * Cosmos client connection mode. + * The size of the response payload body in bytes. This is the number of bytes transferred excluding + * headers and is often, but not always, present as the Content-Length + * header. For requests using transport encoding, this should be the compressed size. */ -static constexpr const char *kDbCosmosdbConnectionMode = "db.cosmosdb.connection_mode"; +static constexpr const char *kHttpResponseBodySize = "http.response.body.size"; /** - * Cosmos DB container name. + * HTTP response status code. */ -static constexpr const char *kDbCosmosdbContainer = "db.cosmosdb.container"; +static constexpr const char *kHttpResponseStatusCode = "http.response.status_code"; /** - * Request payload size in bytes + * The matched route (path template in the format used by the respective server framework). See note +below + * + *

Notes: +

  • MUST NOT be populated when this is not supported by the HTTP server framework as the +route attribute should have low-cardinality and the URI path can NOT substitute it. SHOULD include +the application root if there is +one.
*/ -static constexpr const char *kDbCosmosdbRequestContentLength = "db.cosmosdb.request_content_length"; +static constexpr const char *kHttpRoute = "http.route"; /** - * Cosmos DB status code. + * Server address - domain name if available without reverse DNS lookup, otherwise IP address or +Unix domain socket name. + * + *

Notes: +

  • When observed from the client side, and when communicating through an intermediary, +{@code server.address} SHOULD represent the server address behind any intermediaries (e.g. proxies) +if it's available.
*/ -static constexpr const char *kDbCosmosdbStatusCode = "db.cosmosdb.status_code"; +static constexpr const char *kServerAddress = "server.address"; /** - * Cosmos DB sub status code. + * Server port number. + * + *

Notes: +

  • When observed from the client side, and when communicating through an intermediary, + {@code server.port} SHOULD represent the server port behind any intermediaries (e.g. proxies) if + it's available.
*/ -static constexpr const char *kDbCosmosdbSubStatusCode = "db.cosmosdb.sub_status_code"; +static constexpr const char *kServerPort = "server.port"; /** - * RU consumed for that operation + * A unique id to identify a session. */ -static constexpr const char *kDbCosmosdbRequestCharge = "db.cosmosdb.request_charge"; +static constexpr const char *kSessionId = "session.id"; /** - * Name of the code, either "OK" or "ERROR". MUST NOT be set if the status code - * is UNSET. + * Source address - domain name if available without reverse DNS lookup, otherwise IP address or + Unix domain socket name. + * + *

Notes: +

  • When observed from the destination side, and when communicating through an intermediary, + {@code source.address} SHOULD represent the source address behind any intermediaries (e.g. proxies) + if it's available.
*/ -static constexpr const char *kOtelStatusCode = "otel.status_code"; +static constexpr const char *kSourceAddress = "source.address"; /** - * Description of the Status if it has a value, otherwise not set. + * Source port number */ -static constexpr const char *kOtelStatusDescription = "otel.status_description"; +static constexpr const char *kSourcePort = "source.port"; /** - * Type of the trigger which caused this function invocation. + * The full invoked ARN as provided on the {@code Context} passed to the function ({@code + Lambda-Runtime-Invoked-Function-Arn} header on the {@code /runtime/invocation/next} applicable). * *

Notes: -

  • For the server/consumer span on the incoming side, -{@code faas.trigger} MUST be set.
  • Clients invoking FaaS instances usually cannot set {@code -faas.trigger}, since they would typically need to look in the payload to determine the event type. -If clients set it, it should be the same as the trigger that corresponding incoming would have -(i.e., this has nothing to do with the underlying transport used to make the API call to invoke the -lambda, which is often HTTP).
+
  • This may be different from {@code cloud.resource_id} if an alias is involved.
*/ -static constexpr const char *kFaasTrigger = "faas.trigger"; +static constexpr const char *kAwsLambdaInvokedArn = "aws.lambda.invoked_arn"; /** - * The invocation ID of the current function invocation. + * The event_id + * uniquely identifies the event. */ -static constexpr const char *kFaasInvocationId = "faas.invocation_id"; +static constexpr const char *kCloudeventsEventId = "cloudevents.event_id"; /** - * The name of the source on which the triggering operation was performed. For example, in Cloud - * Storage or S3 corresponds to the bucket name, and in Cosmos DB to the database name. + * The source + * identifies the context in which an event happened. */ -static constexpr const char *kFaasDocumentCollection = "faas.document.collection"; +static constexpr const char *kCloudeventsEventSource = "cloudevents.event_source"; /** - * Describes the type of the operation that was performed on the data. + * The version of + * the CloudEvents specification which the event uses. */ -static constexpr const char *kFaasDocumentOperation = "faas.document.operation"; +static constexpr const char *kCloudeventsEventSpecVersion = "cloudevents.event_spec_version"; /** - * A string containing the time when the data was accessed in the ISO 8601 format expressed in UTC. + * The subject of + * the event in the context of the event producer (identified by source). */ -static constexpr const char *kFaasDocumentTime = "faas.document.time"; +static constexpr const char *kCloudeventsEventSubject = "cloudevents.event_subject"; /** - * The document name/table subjected to the operation. For example, in Cloud Storage or S3 is the - * name of the file, and in Cosmos DB the table name. + * The event_type + * contains a value describing the type of event related to the originating occurrence. */ -static constexpr const char *kFaasDocumentName = "faas.document.name"; +static constexpr const char *kCloudeventsEventType = "cloudevents.event_type"; /** - * A string containing the function invocation time in the ISO 8601 format expressed in UTC. + * Parent-child Reference type + * + *

Notes: +

  • The causal relationship between a child Span and a parent Span.
*/ -static constexpr const char *kFaasTime = "faas.time"; +static constexpr const char *kOpentracingRefType = "opentracing.ref_type"; /** - * A string containing the schedule period as Cron - * Expression. + * The connection string used to connect to the database. It is recommended to remove embedded + * credentials. */ -static constexpr const char *kFaasCron = "faas.cron"; +static constexpr const char *kDbConnectionString = "db.connection_string"; /** - * A boolean that is true if the serverless function is executed for the first time (aka - * cold-start). + * The fully-qualified class name of the Java Database Connectivity + * (JDBC) driver used to connect. */ -static constexpr const char *kFaasColdstart = "faas.coldstart"; +static constexpr const char *kDbJdbcDriverClassname = "db.jdbc.driver_classname"; /** - * The name of the invoked function. + * This attribute is used to report the name of the database being accessed. For commands that + switch the database, this should be set to the target database (even if the command fails). * *

Notes: -

  • SHOULD be equal to the {@code faas.name} resource attribute of the invoked function.
  • -
+
  • In some SQL databases, the database name to be used is called "schema name". In + case there are multiple layers that could be considered for database name (e.g. Oracle instance + name and schema name), the database name to be used is the more specific layer (e.g. Oracle schema + name).
*/ -static constexpr const char *kFaasInvokedName = "faas.invoked_name"; +static constexpr const char *kDbName = "db.name"; /** - * The cloud provider of the invoked function. + * The name of the operation being executed, e.g. the MongoDB command + name such as {@code findAndModify}, or the SQL keyword. * *

Notes: -

  • SHOULD be equal to the {@code cloud.provider} resource attribute of the invoked - function.
+
  • When setting this to an SQL keyword, it is not recommended to attempt any client-side + parsing of {@code db.statement} just to get this property, but it should be set if the operation + name is provided by the library being instrumented. If the SQL statement has an ambiguous + operation, or performs more than one operation, this value may be omitted.
*/ -static constexpr const char *kFaasInvokedProvider = "faas.invoked_provider"; +static constexpr const char *kDbOperation = "db.operation"; /** - * The cloud region of the invoked function. + * The database statement being executed. + */ +static constexpr const char *kDbStatement = "db.statement"; + +/** + * An identifier for the database management system (DBMS) product being used. See below for a list + * of well-known identifiers. + */ +static constexpr const char *kDbSystem = "db.system"; + +/** + * Username for accessing the database. + */ +static constexpr const char *kDbUser = "db.user"; + +/** + * The Microsoft SQL Server instance + name connecting to. This name is used to determine the port of a named instance. * *

Notes: -

  • SHOULD be equal to the {@code cloud.region} resource attribute of the invoked - function.
+
  • If setting a {@code db.mssql.instance_name}, {@code server.port} is no longer required + (but still recommended if non-standard).
*/ -static constexpr const char *kFaasInvokedRegion = "faas.invoked_region"; +static constexpr const char *kDbMssqlInstanceName = "db.mssql.instance_name"; /** - * The unique identifier of the feature flag. + * The consistency level of the query. Based on consistency values from CQL. */ -static constexpr const char *kFeatureFlagKey = "feature_flag.key"; +static constexpr const char *kDbCassandraConsistencyLevel = "db.cassandra.consistency_level"; /** - * The name of the service provider that performs the flag evaluation. + * The data center of the coordinating node for a query. */ -static constexpr const char *kFeatureFlagProviderName = "feature_flag.provider_name"; +static constexpr const char *kDbCassandraCoordinatorDc = "db.cassandra.coordinator.dc"; /** - * SHOULD be a semantic identifier for a value. If one is unavailable, a stringified version of the -value can be used. + * The ID of the coordinating node for a query. + */ +static constexpr const char *kDbCassandraCoordinatorId = "db.cassandra.coordinator.id"; + +/** + * Whether or not the query is idempotent. + */ +static constexpr const char *kDbCassandraIdempotence = "db.cassandra.idempotence"; + +/** + * The fetch size used for paging, i.e. how many rows will be returned at once. + */ +static constexpr const char *kDbCassandraPageSize = "db.cassandra.page_size"; + +/** + * The number of times a query was speculatively executed. Not set or {@code 0} if the query was not + * executed speculatively. + */ +static constexpr const char *kDbCassandraSpeculativeExecutionCount = + "db.cassandra.speculative_execution_count"; + +/** + * The name of the primary table that the operation is acting upon, including the keyspace name (if + applicable). * *

Notes: -

  • A semantic identifier, commonly referred to as a variant, provides a means -for referring to a value without including the value itself. This can -provide additional context for understanding the meaning behind a value. -For example, the variant {@code red} maybe be used for the value {@code #c05543}.
  • A -stringified version of the value can be used in situations where a semantic identifier is -unavailable. String representation of the value should be determined by the implementer.
+
  • This mirrors the db.sql.table attribute but references cassandra rather than sql. It is + not recommended to attempt any client-side parsing of {@code db.statement} just to get this + property, but it should be set if it is provided by the library being instrumented. If the + operation is acting upon an anonymous table, or more than one table, this value MUST NOT be + set.
*/ -static constexpr const char *kFeatureFlagVariant = "feature_flag.variant"; +static constexpr const char *kDbCassandraTable = "db.cassandra.table"; /** - * OSI Transport Layer or Inter-process Communication - * method. The value SHOULD be normalized to lowercase. + * The index of the database being accessed as used in the {@code SELECT} command, provided as an integer. To be + * used instead of the generic {@code db.name} attribute. */ -static constexpr const char *kNetworkTransport = "network.transport"; +static constexpr const char *kDbRedisDatabaseIndex = "db.redis.database_index"; /** - * OSI Network Layer or non-OSI equivalent. The - * value SHOULD be normalized to lowercase. + * The collection being accessed within the database stated in {@code db.name}. */ -static constexpr const char *kNetworkType = "network.type"; +static constexpr const char *kDbMongodbCollection = "db.mongodb.collection"; /** - * OSI Application Layer or non-OSI - * equivalent. The value SHOULD be normalized to lowercase. + * Represents the identifier of an Elasticsearch cluster. */ -static constexpr const char *kNetworkProtocolName = "network.protocol.name"; +static constexpr const char *kDbElasticsearchClusterName = "db.elasticsearch.cluster.name"; + +/** + * Represents the human-readable identifier of the node/instance to which a request was routed. + */ +static constexpr const char *kDbElasticsearchNodeName = "db.elasticsearch.node.name"; /** - * Version of the application layer protocol used. See note below. + * The name of the primary table that the operation is acting upon, including the database name (if + applicable). * *

Notes: -

  • {@code network.protocol.version} refers to the version of the protocol used and might be - different from the protocol client's version. If the HTTP client used has a version of {@code - 0.27.2}, but sends HTTP version {@code 1.1}, this attribute should be set to {@code 1.1}.
  • -
+
  • It is not recommended to attempt any client-side parsing of {@code db.statement} just to + get this property, but it should be set if it is provided by the library being instrumented. If the + operation is acting upon an anonymous table, or more than one table, this value MUST NOT be + set.
*/ -static constexpr const char *kNetworkProtocolVersion = "network.protocol.version"; +static constexpr const char *kDbSqlTable = "db.sql.table"; /** - * The internet connection type. + * Unique Cosmos client instance id. */ -static constexpr const char *kNetworkConnectionType = "network.connection.type"; +static constexpr const char *kDbCosmosdbClientId = "db.cosmosdb.client_id"; /** - * This describes more details regarding the connection.type. It may be the type of cell technology - * connection, but it could be used for describing details about a wifi connection. + * Cosmos client connection mode. */ -static constexpr const char *kNetworkConnectionSubtype = "network.connection.subtype"; +static constexpr const char *kDbCosmosdbConnectionMode = "db.cosmosdb.connection_mode"; /** - * The name of the mobile carrier. + * Cosmos DB container name. */ -static constexpr const char *kNetworkCarrierName = "network.carrier.name"; +static constexpr const char *kDbCosmosdbContainer = "db.cosmosdb.container"; /** - * The mobile carrier country code. + * CosmosDB Operation Type. */ -static constexpr const char *kNetworkCarrierMcc = "network.carrier.mcc"; +static constexpr const char *kDbCosmosdbOperationType = "db.cosmosdb.operation_type"; /** - * The mobile carrier network code. + * RU consumed for that operation */ -static constexpr const char *kNetworkCarrierMnc = "network.carrier.mnc"; +static constexpr const char *kDbCosmosdbRequestCharge = "db.cosmosdb.request_charge"; /** - * The ISO 3166-1 alpha-2 2-character country code associated with the mobile carrier network. + * Request payload size in bytes */ -static constexpr const char *kNetworkCarrierIcc = "network.carrier.icc"; +static constexpr const char *kDbCosmosdbRequestContentLength = "db.cosmosdb.request_content_length"; /** - * The {@code service.name} of the remote service. - * SHOULD be equal to the actual {@code service.name} resource attribute of the remote service if - * any. + * Cosmos DB status code. */ -static constexpr const char *kPeerService = "peer.service"; +static constexpr const char *kDbCosmosdbStatusCode = "db.cosmosdb.status_code"; /** - * Username or client_id extracted from the access token or Authorization header in the inbound - * request from outside the system. + * Cosmos DB sub status code. */ -static constexpr const char *kEnduserId = "enduser.id"; +static constexpr const char *kDbCosmosdbSubStatusCode = "db.cosmosdb.sub_status_code"; /** - * Actual/assumed role the client is making the request under extracted from token or application - * security context. + * Name of the code, either "OK" or "ERROR". MUST NOT be set if the status code + * is UNSET. */ -static constexpr const char *kEnduserRole = "enduser.role"; +static constexpr const char *kOtelStatusCode = "otel.status_code"; /** - * 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. + * Description of the Status if it has a value, otherwise not set. */ -static constexpr const char *kEnduserScope = "enduser.scope"; +static constexpr const char *kOtelStatusDescription = "otel.status_description"; /** - * Current "managed" thread ID (as opposed to OS thread ID). + * The invocation ID of the current function invocation. */ -static constexpr const char *kThreadId = "thread.id"; +static constexpr const char *kFaasInvocationId = "faas.invocation_id"; /** - * Current thread name. + * The name of the source on which the triggering operation was performed. For example, in Cloud + * Storage or S3 corresponds to the bucket name, and in Cosmos DB to the database name. */ -static constexpr const char *kThreadName = "thread.name"; +static constexpr const char *kFaasDocumentCollection = "faas.document.collection"; /** - * The method or function name, or equivalent (usually rightmost part of the code unit's name). + * The document name/table subjected to the operation. For example, in Cloud Storage or S3 is the + * name of the file, and in Cosmos DB the table name. */ -static constexpr const char *kCodeFunction = "code.function"; +static constexpr const char *kFaasDocumentName = "faas.document.name"; /** - * The "namespace" within which {@code code.function} is defined. Usually the qualified - * class or module name, such that {@code code.namespace} + some separator + {@code code.function} - * form a unique identifier for the code unit. + * Describes the type of the operation that was performed on the data. */ -static constexpr const char *kCodeNamespace = "code.namespace"; +static constexpr const char *kFaasDocumentOperation = "faas.document.operation"; /** - * The source code file name that identifies the code unit as uniquely as possible (preferably an - * absolute file path). + * A string containing the time when the data was accessed in the ISO 8601 format expressed in UTC. */ -static constexpr const char *kCodeFilepath = "code.filepath"; +static constexpr const char *kFaasDocumentTime = "faas.document.time"; /** - * The line number in {@code code.filepath} best representing the operation. It SHOULD point within - * the code unit named in {@code code.function}. + * A string containing the schedule period as Cron + * Expression. */ -static constexpr const char *kCodeLineno = "code.lineno"; +static constexpr const char *kFaasCron = "faas.cron"; /** - * The column number in {@code code.filepath} best representing the operation. It SHOULD point - * within the code unit named in {@code code.function}. + * A string containing the function invocation time in the ISO 8601 format expressed in UTC. */ -static constexpr const char *kCodeColumn = "code.column"; +static constexpr const char *kFaasTime = "faas.time"; /** - * Original HTTP method sent by the client in the request line. + * A boolean that is true if the serverless function is executed for the first time (aka + * cold-start). */ -static constexpr const char *kHttpRequestMethodOriginal = "http.request.method_original"; +static constexpr const char *kFaasColdstart = "faas.coldstart"; /** - * The size of the request payload body in bytes. This is the number of bytes transferred excluding - * headers and is often, but not always, present as the Content-Length - * header. For requests using transport encoding, this should be the compressed size. + * The unique identifier of the feature flag. */ -static constexpr const char *kHttpRequestBodySize = "http.request.body.size"; +static constexpr const char *kFeatureFlagKey = "feature_flag.key"; /** - * The size of the response payload body in bytes. This is the number of bytes transferred excluding - * headers and is often, but not always, present as the Content-Length - * header. For requests using transport encoding, this should be the compressed size. + * The name of the service provider that performs the flag evaluation. */ -static constexpr const char *kHttpResponseBodySize = "http.response.body.size"; +static constexpr const char *kFeatureFlagProviderName = "feature_flag.provider_name"; /** - * The ordinal number of request resending attempt (for any reason, including redirects). + * SHOULD be a semantic identifier for a value. If one is unavailable, a stringified version of the +value can be used. * *

Notes: -

  • The resend count SHOULD be updated each time an HTTP request gets resent by the client, - regardless of what was the cause of the resending (e.g. redirection, authorization failure, 503 - Server Unavailable, network issues, or any other).
+
  • A semantic identifier, commonly referred to as a variant, provides a means +for referring to a value without including the value itself. This can +provide additional context for understanding the meaning behind a value. +For example, the variant {@code red} maybe be used for the value {@code #c05543}.
  • A +stringified version of the value can be used in situations where a semantic identifier is +unavailable. String representation of the value should be determined by the implementer.
*/ -static constexpr const char *kHttpResendCount = "http.resend_count"; +static constexpr const char *kFeatureFlagVariant = "feature_flag.variant"; /** * The AWS request ID as returned in the response headers {@code x-amz-request-id} or {@code @@ -932,37 +1060,35 @@ static constexpr const char *kHttpResendCount = "http.resend_count"; static constexpr const char *kAwsRequestId = "aws.request_id"; /** - * The keys in the {@code RequestItems} object field. + * The value of the {@code AttributesToGet} request parameter. */ -static constexpr const char *kAwsDynamodbTableNames = "aws.dynamodb.table_names"; +static constexpr const char *kAwsDynamodbAttributesToGet = "aws.dynamodb.attributes_to_get"; /** - * The JSON-serialized value of each item in the {@code ConsumedCapacity} response field. + * The value of the {@code ConsistentRead} request parameter. */ -static constexpr const char *kAwsDynamodbConsumedCapacity = "aws.dynamodb.consumed_capacity"; +static constexpr const char *kAwsDynamodbConsistentRead = "aws.dynamodb.consistent_read"; /** - * The JSON-serialized value of the {@code ItemCollectionMetrics} response field. + * The JSON-serialized value of each item in the {@code ConsumedCapacity} response field. */ -static constexpr const char *kAwsDynamodbItemCollectionMetrics = - "aws.dynamodb.item_collection_metrics"; +static constexpr const char *kAwsDynamodbConsumedCapacity = "aws.dynamodb.consumed_capacity"; /** - * The value of the {@code ProvisionedThroughput.ReadCapacityUnits} request parameter. + * The value of the {@code IndexName} request parameter. */ -static constexpr const char *kAwsDynamodbProvisionedReadCapacity = - "aws.dynamodb.provisioned_read_capacity"; +static constexpr const char *kAwsDynamodbIndexName = "aws.dynamodb.index_name"; /** - * The value of the {@code ProvisionedThroughput.WriteCapacityUnits} request parameter. + * The JSON-serialized value of the {@code ItemCollectionMetrics} response field. */ -static constexpr const char *kAwsDynamodbProvisionedWriteCapacity = - "aws.dynamodb.provisioned_write_capacity"; +static constexpr const char *kAwsDynamodbItemCollectionMetrics = + "aws.dynamodb.item_collection_metrics"; /** - * The value of the {@code ConsistentRead} request parameter. + * The value of the {@code Limit} request parameter. */ -static constexpr const char *kAwsDynamodbConsistentRead = "aws.dynamodb.consistent_read"; +static constexpr const char *kAwsDynamodbLimit = "aws.dynamodb.limit"; /** * The value of the {@code ProjectionExpression} request parameter. @@ -970,24 +1096,26 @@ static constexpr const char *kAwsDynamodbConsistentRead = "aws.dynamodb.consiste static constexpr const char *kAwsDynamodbProjection = "aws.dynamodb.projection"; /** - * The value of the {@code Limit} request parameter. + * The value of the {@code ProvisionedThroughput.ReadCapacityUnits} request parameter. */ -static constexpr const char *kAwsDynamodbLimit = "aws.dynamodb.limit"; +static constexpr const char *kAwsDynamodbProvisionedReadCapacity = + "aws.dynamodb.provisioned_read_capacity"; /** - * The value of the {@code AttributesToGet} request parameter. + * The value of the {@code ProvisionedThroughput.WriteCapacityUnits} request parameter. */ -static constexpr const char *kAwsDynamodbAttributesToGet = "aws.dynamodb.attributes_to_get"; +static constexpr const char *kAwsDynamodbProvisionedWriteCapacity = + "aws.dynamodb.provisioned_write_capacity"; /** - * The value of the {@code IndexName} request parameter. + * The value of the {@code Select} request parameter. */ -static constexpr const char *kAwsDynamodbIndexName = "aws.dynamodb.index_name"; +static constexpr const char *kAwsDynamodbSelect = "aws.dynamodb.select"; /** - * The value of the {@code Select} request parameter. + * The keys in the {@code RequestItems} object field. */ -static constexpr const char *kAwsDynamodbSelect = "aws.dynamodb.select"; +static constexpr const char *kAwsDynamodbTableNames = "aws.dynamodb.table_names"; /** * The JSON-serialized value of each item of the {@code GlobalSecondaryIndexes} request field @@ -1017,24 +1145,24 @@ static constexpr const char *kAwsDynamodbTableCount = "aws.dynamodb.table_count" static constexpr const char *kAwsDynamodbScanForward = "aws.dynamodb.scan_forward"; /** - * The value of the {@code Segment} request parameter. + * The value of the {@code Count} response parameter. */ -static constexpr const char *kAwsDynamodbSegment = "aws.dynamodb.segment"; +static constexpr const char *kAwsDynamodbCount = "aws.dynamodb.count"; /** - * The value of the {@code TotalSegments} request parameter. + * The value of the {@code ScannedCount} response parameter. */ -static constexpr const char *kAwsDynamodbTotalSegments = "aws.dynamodb.total_segments"; +static constexpr const char *kAwsDynamodbScannedCount = "aws.dynamodb.scanned_count"; /** - * The value of the {@code Count} response parameter. + * The value of the {@code Segment} request parameter. */ -static constexpr const char *kAwsDynamodbCount = "aws.dynamodb.count"; +static constexpr const char *kAwsDynamodbSegment = "aws.dynamodb.segment"; /** - * The value of the {@code ScannedCount} response parameter. + * The value of the {@code TotalSegments} request parameter. */ -static constexpr const char *kAwsDynamodbScannedCount = "aws.dynamodb.scanned_count"; +static constexpr const char *kAwsDynamodbTotalSegments = "aws.dynamodb.total_segments"; /** * The JSON-serialized value of each item in the {@code AttributeDefinitions} request field. @@ -1060,6 +1188,33 @@ except {@code list-buckets}. */ static constexpr const char *kAwsS3Bucket = "aws.s3.bucket"; +/** + * The source object (in the form {@code bucket}/{@code key}) for the copy operation. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3CopySource = "aws.s3.copy_source"; + +/** + * The delete request container that specifies the objects to be deleted. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3Delete = "aws.s3.delete"; + /** * The S3 object key the request refers to. Corresponds to the {@code --key} parameter of the S3 API operations. @@ -1098,19 +1253,19 @@ href="https://docs.aws.amazon.com/cli/latest/reference/s3api/upload-part-copy.ht static constexpr const char *kAwsS3Key = "aws.s3.key"; /** - * The source object (in the form {@code bucket}/{@code key}) for the copy operation. + * The part number of the part being uploaded in a multipart-upload operation. This is a positive +integer between 1 and 10,000. * *

Notes: -

+ */ -static constexpr const char *kAwsS3CopySource = "aws.s3.copy_source"; +static constexpr const char *kAwsS3PartNumber = "aws.s3.part_number"; /** * Upload ID that identifies the multipart upload. @@ -1134,31 +1289,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 delete request container that specifies the objects to be deleted. - * - *

Notes: -

- */ -static constexpr const char *kAwsS3Delete = "aws.s3.delete"; - -/** - * The part number of the part being uploaded in a multipart-upload operation. This is a positive -integer between 1 and 10,000. + * The GraphQL document being executed. * *

Notes: -

+
  • The value may be sanitized to exclude sensitive information.
*/ -static constexpr const char *kAwsS3PartNumber = "aws.s3.part_number"; +static constexpr const char *kGraphqlDocument = "graphql.document"; /** * The name of the operation being executed. @@ -1171,17 +1307,13 @@ static constexpr const char *kGraphqlOperationName = "graphql.operation.name"; static constexpr const char *kGraphqlOperationType = "graphql.operation.type"; /** - * The GraphQL document being executed. + * The size of the message body in bytes. * *

Notes: -

  • The value may be sanitized to exclude sensitive information.
- */ -static constexpr const char *kGraphqlDocument = "graphql.document"; - -/** - * A value used by the messaging system as an identifier for the message, represented as a string. +
  • This can refer to both the compressed or uncompressed body size. If both sizes are known, +the uncompressed body size should be used.
*/ -static constexpr const char *kMessagingMessageId = "messaging.message.id"; +static constexpr const char *kMessagingMessageBodySize = "messaging.message.body.size"; /** * The conversation ID identifying the conversation to which the @@ -1190,17 +1322,24 @@ static constexpr const char *kMessagingMessageId = "messaging.message.id"; static constexpr const char *kMessagingMessageConversationId = "messaging.message.conversation_id"; /** - * The (uncompressed) size of the message payload in bytes. Also use this attribute if it is unknown - * whether the compressed or uncompressed payload size is reported. + * The size of the message body and metadata in bytes. + * + *

Notes: +

  • This can refer to both the compressed or uncompressed size. If both sizes are known, the +uncompressed size should be used.
+ */ +static constexpr const char *kMessagingMessageEnvelopeSize = "messaging.message.envelope.size"; + +/** + * A value used by the messaging system as an identifier for the message, represented as a string. */ -static constexpr const char *kMessagingMessagePayloadSizeBytes = - "messaging.message.payload_size_bytes"; +static constexpr const char *kMessagingMessageId = "messaging.message.id"; /** - * The compressed size of the message payload in bytes. + * A boolean that is true if the message destination is anonymous (could be unnamed or have + * auto-generated name). */ -static constexpr const char *kMessagingMessagePayloadCompressedSizeBytes = - "messaging.message.payload_compressed_size_bytes"; +static constexpr const char *kMessagingDestinationAnonymous = "messaging.destination.anonymous"; /** * The message destination name @@ -1227,27 +1366,25 @@ static constexpr const char *kMessagingDestinationTemplate = "messaging.destinat * A boolean that is true if the message destination is temporary and might not exist anymore after * messages are processed. */ -static constexpr const char *kMessagingDestinationTemporary = "messaging.destination.temporary"; - -/** - * A boolean that is true if the message destination is anonymous (could be unnamed or have - * auto-generated name). - */ -static constexpr const char *kMessagingDestinationAnonymous = "messaging.destination.anonymous"; +static constexpr const char *kMessagingDestinationTemporary = "messaging.destination.temporary"; /** - * A string identifying the messaging system. + * A boolean that is true if the publish message destination is anonymous (could be unnamed or have + * auto-generated name). */ -static constexpr const char *kMessagingSystem = "messaging.system"; +static constexpr const char *kMessagingDestinationPublishAnonymous = + "messaging.destination_publish.anonymous"; /** - * A string identifying the kind of messaging operation as defined in the Operation names section above. + * The name of the original destination the message was published to * *

Notes: -

  • If a custom value is used, it MUST be of low cardinality.
+
  • The name SHOULD uniquely identify a specific queue, topic, or other entity within the +broker. If the broker does not have such notion, the original destination name SHOULD uniquely +identify the broker.
*/ -static constexpr const char *kMessagingOperation = "messaging.operation"; +static constexpr const char *kMessagingDestinationPublishName = + "messaging.destination_publish.name"; /** * The number of messages sent, received, or processed in the scope of the batching operation. @@ -1267,22 +1404,24 @@ static constexpr const char *kMessagingBatchMessageCount = "messaging.batch.mess static constexpr const char *kMessagingClientId = "messaging.client_id"; /** - * RabbitMQ message routing key. + * A string identifying the kind of messaging operation as defined in the Operation names section above. + * + *

Notes: +

  • If a custom value is used, it MUST be of low cardinality.
*/ -static constexpr const char *kMessagingRabbitmqDestinationRoutingKey = - "messaging.rabbitmq.destination.routing_key"; +static constexpr const char *kMessagingOperation = "messaging.operation"; /** - * 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 - key is {@code null}, the attribute MUST NOT be set. - * - *

Notes: -

  • If the key type is not string, it's string representation has to be supplied for the - attribute. If the key has no unambiguous, canonical string form, don't include its value.
  • -
+ * A string identifying the messaging system. */ -static constexpr const char *kMessagingKafkaMessageKey = "messaging.kafka.message.key"; +static constexpr const char *kMessagingSystem = "messaging.system"; + +/** + * RabbitMQ message routing key. + */ +static constexpr const char *kMessagingRabbitmqDestinationRoutingKey = + "messaging.rabbitmq.destination.routing_key"; /** * Name of the Kafka Consumer Group that is handling the message. Only applies to consumers, not @@ -1296,6 +1435,18 @@ static constexpr const char *kMessagingKafkaConsumerGroup = "messaging.kafka.con static constexpr const char *kMessagingKafkaDestinationPartition = "messaging.kafka.destination.partition"; +/** + * 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 + key is {@code null}, the attribute MUST NOT be set. + * + *

Notes: +

  • If the key type is not string, it's string representation has to be supplied for the + attribute. If the key has no unambiguous, canonical string form, don't include its value.
  • +
+ */ +static constexpr const char *kMessagingKafkaMessageKey = "messaging.kafka.message.key"; + /** * The offset of a record in the corresponding Kafka partition. */ @@ -1306,11 +1457,6 @@ static constexpr const char *kMessagingKafkaMessageOffset = "messaging.kafka.mes */ static constexpr const char *kMessagingKafkaMessageTombstone = "messaging.kafka.message.tombstone"; -/** - * Namespace of RocketMQ resources, resources in different namespaces are individual. - */ -static constexpr const char *kMessagingRocketmqNamespace = "messaging.rocketmq.namespace"; - /** * Name of the RocketMQ producer/consumer group that is handling the message. The client type is * identified by the SpanKind. @@ -1318,10 +1464,10 @@ static constexpr const char *kMessagingRocketmqNamespace = "messaging.rocketmq.n static constexpr const char *kMessagingRocketmqClientGroup = "messaging.rocketmq.client_group"; /** - * The timestamp in milliseconds that the delay message is expected to be delivered to consumer. + * Model of message consumption. This only applies to consumer spans. */ -static constexpr const char *kMessagingRocketmqMessageDeliveryTimestamp = - "messaging.rocketmq.message.delivery_timestamp"; +static constexpr const char *kMessagingRocketmqConsumptionModel = + "messaging.rocketmq.consumption_model"; /** * The delay time level for delay message, which determines the message delay time. @@ -1329,6 +1475,12 @@ static constexpr const char *kMessagingRocketmqMessageDeliveryTimestamp = static constexpr const char *kMessagingRocketmqMessageDelayTimeLevel = "messaging.rocketmq.message.delay_time_level"; +/** + * The timestamp in milliseconds that the delay message is expected to be delivered to consumer. + */ +static constexpr const char *kMessagingRocketmqMessageDeliveryTimestamp = + "messaging.rocketmq.message.delivery_timestamp"; + /** * It is essential for FIFO message. Messages that belong to the same message group are always * processed one by one within the same consumer group. @@ -1336,9 +1488,9 @@ static constexpr const char *kMessagingRocketmqMessageDelayTimeLevel = static constexpr const char *kMessagingRocketmqMessageGroup = "messaging.rocketmq.message.group"; /** - * Type of message. + * Key(s) of message, another way to mark message besides message id. */ -static constexpr const char *kMessagingRocketmqMessageType = "messaging.rocketmq.message.type"; +static constexpr const char *kMessagingRocketmqMessageKeys = "messaging.rocketmq.message.keys"; /** * The secondary classifier of message besides topic. @@ -1346,20 +1498,26 @@ static constexpr const char *kMessagingRocketmqMessageType = "messaging.rocketmq static constexpr const char *kMessagingRocketmqMessageTag = "messaging.rocketmq.message.tag"; /** - * Key(s) of message, another way to mark message besides message id. + * Type of message. */ -static constexpr const char *kMessagingRocketmqMessageKeys = "messaging.rocketmq.message.keys"; +static constexpr const char *kMessagingRocketmqMessageType = "messaging.rocketmq.message.type"; /** - * Model of message consumption. This only applies to consumer spans. + * Namespace of RocketMQ resources, resources in different namespaces are individual. */ -static constexpr const char *kMessagingRocketmqConsumptionModel = - "messaging.rocketmq.consumption_model"; +static constexpr const char *kMessagingRocketmqNamespace = "messaging.rocketmq.namespace"; /** - * A string identifying the remoting system. See below for a list of well-known identifiers. + * The name of the (logical) method being called, must be equal to the $method part in the span + name. + * + *

Notes: +

  • This is the logical name of the method from the RPC interface perspective, which can be + different from the name of any implementing method/function. The {@code code.function} attribute + may be used to store the latter (e.g., method actually executing the call on the server side, RPC + client stub method on the client side).
*/ -static constexpr const char *kRpcSystem = "rpc.system"; +static constexpr const char *kRpcMethod = "rpc.method"; /** * The full (logical) name of the service being called, including its package name, if applicable. @@ -1374,16 +1532,9 @@ static constexpr const char *kRpcSystem = "rpc.system"; static constexpr const char *kRpcService = "rpc.service"; /** - * The name of the (logical) method being called, must be equal to the $method part in the span - name. - * - *

Notes: -

  • This is the logical name of the method from the RPC interface perspective, which can be - different from the name of any implementing method/function. The {@code code.function} attribute - may be used to store the latter (e.g., method actually executing the call on the server side, RPC - client stub method on the client side).
+ * A string identifying the remoting system. See below for a list of well-known identifiers. */ -static constexpr const char *kRpcMethod = "rpc.method"; +static constexpr const char *kRpcSystem = "rpc.system"; /** * The numeric status @@ -1392,10 +1543,14 @@ static constexpr const char *kRpcMethod = "rpc.method"; static constexpr const char *kRpcGrpcStatusCode = "rpc.grpc.status_code"; /** - * Protocol version as in {@code jsonrpc} property of request/response. Since JSON-RPC 1.0 does not - * specify this, the value can be omitted. + * {@code error.code} property of response if it is an error response. */ -static constexpr const char *kRpcJsonrpcVersion = "rpc.jsonrpc.version"; +static constexpr const char *kRpcJsonrpcErrorCode = "rpc.jsonrpc.error_code"; + +/** + * {@code error.message} property of response if it is an error response. + */ +static constexpr const char *kRpcJsonrpcErrorMessage = "rpc.jsonrpc.error_message"; /** * {@code id} property of request or response. Since protocol allows id to be int, string, {@code @@ -1405,19 +1560,15 @@ static constexpr const char *kRpcJsonrpcVersion = "rpc.jsonrpc.version"; static constexpr const char *kRpcJsonrpcRequestId = "rpc.jsonrpc.request_id"; /** - * {@code error.code} property of response if it is an error response. - */ -static constexpr const char *kRpcJsonrpcErrorCode = "rpc.jsonrpc.error_code"; - -/** - * {@code error.message} property of response if it is an error response. + * Protocol version as in {@code jsonrpc} property of request/response. Since JSON-RPC 1.0 does not + * specify this, the value can be omitted. */ -static constexpr const char *kRpcJsonrpcErrorMessage = "rpc.jsonrpc.error_message"; +static constexpr const char *kRpcJsonrpcVersion = "rpc.jsonrpc.version"; /** - * Whether this is a received or sent message. + * Compressed size of the message in bytes. */ -static constexpr const char *kMessageType = "message.type"; +static constexpr const char *kMessageCompressedSize = "message.compressed_size"; /** * MUST be calculated as two different counters starting from {@code 1} one for sent messages and @@ -1430,9 +1581,9 @@ static constexpr const char *kMessageType = "message.type"; static constexpr const char *kMessageId = "message.id"; /** - * Compressed size of the message in bytes. + * Whether this is a received or sent message. */ -static constexpr const char *kMessageCompressedSize = "message.compressed_size"; +static constexpr const char *kMessageType = "message.type"; /** * Uncompressed size of the message in bytes. @@ -1465,10 +1616,9 @@ recorded at a time where it was not clear whether the exception will escape.URI scheme component - * identifying the used protocol. + * The URI fragment component */ -static constexpr const char *kUrlScheme = "url.scheme"; +static constexpr const char *kUrlFragment = "url.fragment"; /** * Absolute URL describing a network resource according to URI fragment component + * The URI scheme component + * identifying the used protocol. */ -static constexpr const char *kUrlFragment = "url.fragment"; +static constexpr const char *kUrlScheme = "url.scheme"; + +/** + * Value of the HTTP + * User-Agent header sent by the client. + */ +static constexpr const char *kUserAgentOriginal = "user_agent.original"; + +// Enum definitions +namespace NetSockFamilyValues +{ +/** IPv4 address. */ +static constexpr const char *kInet = "inet"; +/** IPv6 address. */ +static constexpr const char *kInet6 = "inet6"; +/** Unix domain socket path. */ +static constexpr const char *kUnix = "unix"; +} // namespace NetSockFamilyValues + +namespace NetTransportValues +{ +/** ip_tcp. */ +static constexpr const char *kIpTcp = "ip_tcp"; +/** ip_udp. */ +static constexpr const char *kIpUdp = "ip_udp"; +/** Named or anonymous pipe. */ +static constexpr const char *kPipe = "pipe"; +/** In-process communication. */ +static constexpr const char *kInproc = "inproc"; +/** Something else (non IP-based). */ +static constexpr const char *kOther = "other"; +} // namespace NetTransportValues + +namespace ErrorTypeValues +{ +/** A fallback error value to be used when the instrumentation does not define a custom value for + * it. */ +static constexpr const char *kOther = "_OTHER"; +} // namespace ErrorTypeValues + +namespace FaasInvokedProviderValues +{ +/** Alibaba Cloud. */ +static constexpr const char *kAlibabaCloud = "alibaba_cloud"; +/** Amazon Web Services. */ +static constexpr const char *kAws = "aws"; +/** Microsoft Azure. */ +static constexpr const char *kAzure = "azure"; +/** Google Cloud Platform. */ +static constexpr const char *kGcp = "gcp"; +/** Tencent Cloud. */ +static constexpr const char *kTencentCloud = "tencent_cloud"; +} // namespace FaasInvokedProviderValues + +namespace FaasTriggerValues +{ +/** A response to some data source operation such as a database or filesystem read/write. */ +static constexpr const char *kDatasource = "datasource"; +/** To provide an answer to an inbound HTTP request. */ +static constexpr const char *kHttp = "http"; +/** A function is set to be executed when messages are sent to a messaging system. */ +static constexpr const char *kPubsub = "pubsub"; +/** A function is scheduled to be executed regularly. */ +static constexpr const char *kTimer = "timer"; +/** If none of the others apply. */ +static constexpr const char *kOther = "other"; +} // namespace FaasTriggerValues + +namespace EventDomainValues +{ +/** Events from browser apps. */ +static constexpr const char *kBrowser = "browser"; +/** Events from mobile apps. */ +static constexpr const char *kDevice = "device"; +/** Events from Kubernetes. */ +static constexpr const char *kK8s = "k8s"; +} // namespace EventDomainValues + +namespace LogIostreamValues +{ +/** Logs from stdout stream. */ +static constexpr const char *kStdout = "stdout"; +/** Events from stderr stream. */ +static constexpr const char *kStderr = "stderr"; +} // namespace LogIostreamValues + +namespace StateValues +{ +/** idle. */ +static constexpr const char *kIdle = "idle"; +/** used. */ +static constexpr const char *kUsed = "used"; +} // namespace StateValues + +namespace JvmMemoryTypeValues +{ +/** Heap memory. */ +static constexpr const char *kHeap = "heap"; +/** Non-heap memory. */ +static constexpr const char *kNonHeap = "non_heap"; +} // namespace JvmMemoryTypeValues + +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 +{ +/** total. */ +static constexpr const char *kTotal = "total"; +/** used. */ +static constexpr const char *kUsed = "used"; +/** free. */ +static constexpr const char *kFree = "free"; +/** shared. */ +static constexpr const char *kShared = "shared"; +/** buffers. */ +static constexpr const char *kBuffers = "buffers"; +/** cached. */ +static constexpr const char *kCached = "cached"; +} // namespace SystemMemoryStateValues + +namespace SystemPagingDirectionValues +{ +/** in. */ +static constexpr const char *kIn = "in"; +/** out. */ +static constexpr const char *kOut = "out"; +} // namespace SystemPagingDirectionValues + +namespace SystemPagingStateValues +{ +/** used. */ +static constexpr const char *kUsed = "used"; +/** free. */ +static constexpr const char *kFree = "free"; +} // namespace SystemPagingStateValues + +namespace SystemPagingTypeValues +{ +/** major. */ +static constexpr const char *kMajor = "major"; +/** minor. */ +static constexpr const char *kMinor = "minor"; +} // namespace SystemPagingTypeValues + +namespace SystemDiskDirectionValues +{ +/** read. */ +static constexpr const char *kRead = "read"; +/** write. */ +static constexpr const char *kWrite = "write"; +} // namespace SystemDiskDirectionValues + +namespace SystemFilesystemStateValues +{ +/** used. */ +static constexpr const char *kUsed = "used"; +/** free. */ +static constexpr const char *kFree = "free"; +/** reserved. */ +static constexpr const char *kReserved = "reserved"; +} // namespace SystemFilesystemStateValues + +namespace SystemFilesystemTypeValues +{ +/** fat32. */ +static constexpr const char *kFat32 = "fat32"; +/** exfat. */ +static constexpr const char *kExfat = "exfat"; +/** ntfs. */ +static constexpr const char *kNtfs = "ntfs"; +/** refs. */ +static constexpr const char *kRefs = "refs"; +/** hfsplus. */ +static constexpr const char *kHfsplus = "hfsplus"; +/** ext4. */ +static constexpr const char *kExt4 = "ext4"; +} // namespace SystemFilesystemTypeValues + +namespace SystemNetworkDirectionValues +{ +/** transmit. */ +static constexpr const char *kTransmit = "transmit"; +/** receive. */ +static constexpr const char *kReceive = "receive"; +} // namespace SystemNetworkDirectionValues + +namespace SystemNetworkStateValues +{ +/** close. */ +static constexpr const char *kClose = "close"; +/** close_wait. */ +static constexpr const char *kCloseWait = "close_wait"; +/** closing. */ +static constexpr const char *kClosing = "closing"; +/** delete. */ +static constexpr const char *kDelete = "delete"; +/** established. */ +static constexpr const char *kEstablished = "established"; +/** fin_wait_1. */ +static constexpr const char *kFinWait1 = "fin_wait_1"; +/** fin_wait_2. */ +static constexpr const char *kFinWait2 = "fin_wait_2"; +/** last_ack. */ +static constexpr const char *kLastAck = "last_ack"; +/** listen. */ +static constexpr const char *kListen = "listen"; +/** syn_recv. */ +static constexpr const char *kSynRecv = "syn_recv"; +/** syn_sent. */ +static constexpr const char *kSynSent = "syn_sent"; +/** time_wait. */ +static constexpr const char *kTimeWait = "time_wait"; +} // namespace SystemNetworkStateValues + +namespace SystemProcessesStatusValues +{ +/** running. */ +static constexpr const char *kRunning = "running"; +/** sleeping. */ +static constexpr const char *kSleeping = "sleeping"; +/** stopped. */ +static constexpr const char *kStopped = "stopped"; +/** defunct. */ +static constexpr const char *kDefunct = "defunct"; +} // namespace SystemProcessesStatusValues + +namespace NetworkTransportValues +{ +/** TCP. */ +static constexpr const char *kTcp = "tcp"; +/** UDP. */ +static constexpr const char *kUdp = "udp"; +/** Named or anonymous pipe. See note below. */ +static constexpr const char *kPipe = "pipe"; +/** Unix domain socket. */ +static constexpr const char *kUnix = "unix"; +} // namespace NetworkTransportValues -/** - * Value of the HTTP - * User-Agent header sent by the client. - */ -static constexpr const char *kUserAgentOriginal = "user_agent.original"; +namespace NetworkTypeValues +{ +/** IPv4. */ +static constexpr const char *kIpv4 = "ipv4"; +/** IPv6. */ +static constexpr const char *kIpv6 = "ipv6"; +} // namespace NetworkTypeValues -// Enum definitions -namespace NetTransportValues +namespace NetworkConnectionSubtypeValues { -/** ip_tcp. */ -static constexpr const char *kIpTcp = "ip_tcp"; -/** ip_udp. */ -static constexpr const char *kIpUdp = "ip_udp"; -/** Named or anonymous pipe. */ -static constexpr const char *kPipe = "pipe"; -/** In-process communication. */ -static constexpr const char *kInproc = "inproc"; -/** Something else (non IP-based). */ -static constexpr const char *kOther = "other"; -} // namespace NetTransportValues +/** GPRS. */ +static constexpr const char *kGprs = "gprs"; +/** EDGE. */ +static constexpr const char *kEdge = "edge"; +/** UMTS. */ +static constexpr const char *kUmts = "umts"; +/** CDMA. */ +static constexpr const char *kCdma = "cdma"; +/** EVDO Rel. 0. */ +static constexpr const char *kEvdo0 = "evdo_0"; +/** EVDO Rev. A. */ +static constexpr const char *kEvdoA = "evdo_a"; +/** CDMA2000 1XRTT. */ +static constexpr const char *kCdma20001xrtt = "cdma2000_1xrtt"; +/** HSDPA. */ +static constexpr const char *kHsdpa = "hsdpa"; +/** HSUPA. */ +static constexpr const char *kHsupa = "hsupa"; +/** HSPA. */ +static constexpr const char *kHspa = "hspa"; +/** IDEN. */ +static constexpr const char *kIden = "iden"; +/** EVDO Rev. B. */ +static constexpr const char *kEvdoB = "evdo_b"; +/** LTE. */ +static constexpr const char *kLte = "lte"; +/** EHRPD. */ +static constexpr const char *kEhrpd = "ehrpd"; +/** HSPAP. */ +static constexpr const char *kHspap = "hspap"; +/** GSM. */ +static constexpr const char *kGsm = "gsm"; +/** TD-SCDMA. */ +static constexpr const char *kTdScdma = "td_scdma"; +/** IWLAN. */ +static constexpr const char *kIwlan = "iwlan"; +/** 5G NR (New Radio). */ +static constexpr const char *kNr = "nr"; +/** 5G NRNSA (New Radio Non-Standalone). */ +static constexpr const char *kNrnsa = "nrnsa"; +/** LTE CA. */ +static constexpr const char *kLteCa = "lte_ca"; +} // namespace NetworkConnectionSubtypeValues -namespace NetSockFamilyValues +namespace NetworkConnectionTypeValues { -/** IPv4 address. */ -static constexpr const char *kInet = "inet"; -/** IPv6 address. */ -static constexpr const char *kInet6 = "inet6"; -/** Unix domain socket path. */ -static constexpr const char *kUnix = "unix"; -} // namespace NetSockFamilyValues +/** wifi. */ +static constexpr const char *kWifi = "wifi"; +/** wired. */ +static constexpr const char *kWired = "wired"; +/** cell. */ +static constexpr const char *kCell = "cell"; +/** unavailable. */ +static constexpr const char *kUnavailable = "unavailable"; +/** unknown. */ +static constexpr const char *kUnknown = "unknown"; +} // namespace NetworkConnectionTypeValues namespace HttpRequestMethodValues { @@ -1563,32 +2003,6 @@ static constexpr const char *kTrace = "TRACE"; static constexpr const char *kOther = "_OTHER"; } // namespace HttpRequestMethodValues -namespace EventDomainValues -{ -/** Events from browser apps. */ -static constexpr const char *kBrowser = "browser"; -/** Events from mobile apps. */ -static constexpr const char *kDevice = "device"; -/** Events from Kubernetes. */ -static constexpr const char *kK8s = "k8s"; -} // namespace EventDomainValues - -namespace LogIostreamValues -{ -/** Logs from stdout stream. */ -static constexpr const char *kStdout = "stdout"; -/** Events from stderr stream. */ -static constexpr const char *kStderr = "stderr"; -} // namespace LogIostreamValues - -namespace TypeValues -{ -/** Heap memory. */ -static constexpr const char *kHeap = "heap"; -/** Non-heap memory. */ -static constexpr const char *kNonHeap = "non_heap"; -} // namespace TypeValues - namespace OpentracingRefTypeValues { /** The parent Span depends on the child Span in some capacity. */ @@ -1731,6 +2145,14 @@ static constexpr const char *kSerial = "serial"; static constexpr const char *kLocalSerial = "local_serial"; } // namespace DbCassandraConsistencyLevelValues +namespace DbCosmosdbConnectionModeValues +{ +/** Gateway (HTTP) connections mode. */ +static constexpr const char *kGateway = "gateway"; +/** Direct connection. */ +static constexpr const char *kDirect = "direct"; +} // namespace DbCosmosdbConnectionModeValues + namespace DbCosmosdbOperationTypeValues { /** invalid. */ @@ -1765,14 +2187,6 @@ static constexpr const char *kQueryPlan = "QueryPlan"; static constexpr const char *kExecuteJavascript = "ExecuteJavaScript"; } // namespace DbCosmosdbOperationTypeValues -namespace DbCosmosdbConnectionModeValues -{ -/** Gateway (HTTP) connections mode. */ -static constexpr const char *kGateway = "gateway"; -/** Direct connection. */ -static constexpr const char *kDirect = "direct"; -} // namespace DbCosmosdbConnectionModeValues - namespace OtelStatusCodeValues { /** The operation has been validated by an Application developer or Operator to have completed @@ -1782,20 +2196,6 @@ static constexpr const char *kOk = "OK"; static constexpr const char *kError = "ERROR"; } // namespace OtelStatusCodeValues -namespace FaasTriggerValues -{ -/** A response to some data source operation such as a database or filesystem read/write. */ -static constexpr const char *kDatasource = "datasource"; -/** To provide an answer to an inbound HTTP request. */ -static constexpr const char *kHttp = "http"; -/** A function is set to be executed when messages are sent to a messaging system. */ -static constexpr const char *kPubsub = "pubsub"; -/** A function is scheduled to be executed regularly. */ -static constexpr const char *kTimer = "timer"; -/** If none of the others apply. */ -static constexpr const char *kOther = "other"; -} // namespace FaasTriggerValues - namespace FaasDocumentOperationValues { /** When a new object is created. */ @@ -1806,100 +2206,6 @@ static constexpr const char *kEdit = "edit"; static constexpr const char *kDelete = "delete"; } // namespace FaasDocumentOperationValues -namespace FaasInvokedProviderValues -{ -/** Alibaba Cloud. */ -static constexpr const char *kAlibabaCloud = "alibaba_cloud"; -/** Amazon Web Services. */ -static constexpr const char *kAws = "aws"; -/** Microsoft Azure. */ -static constexpr const char *kAzure = "azure"; -/** Google Cloud Platform. */ -static constexpr const char *kGcp = "gcp"; -/** Tencent Cloud. */ -static constexpr const char *kTencentCloud = "tencent_cloud"; -} // namespace FaasInvokedProviderValues - -namespace NetworkTransportValues -{ -/** TCP. */ -static constexpr const char *kTcp = "tcp"; -/** UDP. */ -static constexpr const char *kUdp = "udp"; -/** Named or anonymous pipe. See note below. */ -static constexpr const char *kPipe = "pipe"; -/** Unix domain socket. */ -static constexpr const char *kUnix = "unix"; -} // namespace NetworkTransportValues - -namespace NetworkTypeValues -{ -/** IPv4. */ -static constexpr const char *kIpv4 = "ipv4"; -/** IPv6. */ -static constexpr const char *kIpv6 = "ipv6"; -} // namespace NetworkTypeValues - -namespace NetworkConnectionTypeValues -{ -/** wifi. */ -static constexpr const char *kWifi = "wifi"; -/** wired. */ -static constexpr const char *kWired = "wired"; -/** cell. */ -static constexpr const char *kCell = "cell"; -/** unavailable. */ -static constexpr const char *kUnavailable = "unavailable"; -/** unknown. */ -static constexpr const char *kUnknown = "unknown"; -} // namespace NetworkConnectionTypeValues - -namespace NetworkConnectionSubtypeValues -{ -/** GPRS. */ -static constexpr const char *kGprs = "gprs"; -/** EDGE. */ -static constexpr const char *kEdge = "edge"; -/** UMTS. */ -static constexpr const char *kUmts = "umts"; -/** CDMA. */ -static constexpr const char *kCdma = "cdma"; -/** EVDO Rel. 0. */ -static constexpr const char *kEvdo0 = "evdo_0"; -/** EVDO Rev. A. */ -static constexpr const char *kEvdoA = "evdo_a"; -/** CDMA2000 1XRTT. */ -static constexpr const char *kCdma20001xrtt = "cdma2000_1xrtt"; -/** HSDPA. */ -static constexpr const char *kHsdpa = "hsdpa"; -/** HSUPA. */ -static constexpr const char *kHsupa = "hsupa"; -/** HSPA. */ -static constexpr const char *kHspa = "hspa"; -/** IDEN. */ -static constexpr const char *kIden = "iden"; -/** EVDO Rev. B. */ -static constexpr const char *kEvdoB = "evdo_b"; -/** LTE. */ -static constexpr const char *kLte = "lte"; -/** EHRPD. */ -static constexpr const char *kEhrpd = "ehrpd"; -/** HSPAP. */ -static constexpr const char *kHspap = "hspap"; -/** GSM. */ -static constexpr const char *kGsm = "gsm"; -/** TD-SCDMA. */ -static constexpr const char *kTdScdma = "td_scdma"; -/** IWLAN. */ -static constexpr const char *kIwlan = "iwlan"; -/** 5G NR (New Radio). */ -static constexpr const char *kNr = "nr"; -/** 5G NRNSA (New Radio Non-Standalone). */ -static constexpr const char *kNrnsa = "nrnsa"; -/** LTE CA. */ -static constexpr const char *kLteCa = "lte_ca"; -} // namespace NetworkConnectionSubtypeValues - namespace GraphqlOperationTypeValues { /** GraphQL query. */ @@ -1920,6 +2226,14 @@ static constexpr const char *kReceive = "receive"; static constexpr const char *kProcess = "process"; } // namespace MessagingOperationValues +namespace MessagingRocketmqConsumptionModelValues +{ +/** Clustering consumption model. */ +static constexpr const char *kClustering = "clustering"; +/** Broadcasting consumption model. */ +static constexpr const char *kBroadcasting = "broadcasting"; +} // namespace MessagingRocketmqConsumptionModelValues + namespace MessagingRocketmqMessageTypeValues { /** Normal message. */ @@ -1932,14 +2246,6 @@ static constexpr const char *kDelay = "delay"; static constexpr const char *kTransaction = "transaction"; } // namespace MessagingRocketmqMessageTypeValues -namespace MessagingRocketmqConsumptionModelValues -{ -/** Clustering consumption model. */ -static constexpr const char *kClustering = "clustering"; -/** Broadcasting consumption model. */ -static constexpr const char *kBroadcasting = "broadcasting"; -} // namespace MessagingRocketmqConsumptionModelValues - namespace RpcSystemValues { /** gRPC. */ diff --git a/buildscripts/semantic-convention/generate.sh b/buildscripts/semantic-convention/generate.sh index 2a6634baa4..daa5131dc5 100755 --- a/buildscripts/semantic-convention/generate.sh +++ b/buildscripts/semantic-convention/generate.sh @@ -18,10 +18,10 @@ ROOT_DIR="${SCRIPT_DIR}/../../" # https://github.com/open-telemetry/opentelemetry-specification # Repository from 1.21.0: # https://github.com/open-telemetry/semantic-conventions -SEMCONV_VERSION=1.21.0 +SEMCONV_VERSION=1.22.0 # repository: https://github.com/open-telemetry/build-tools -GENERATOR_VERSION=0.19.0 +GENERATOR_VERSION=0.22.0 SPEC_VERSION=v$SEMCONV_VERSION SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index 92088c12f6..3163b38986 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -53,8 +53,8 @@ class GreeterClient {{SemanticConventions::kRpcSystem, "grpc"}, {SemanticConventions::kRpcService, "grpc-example.GreetService"}, {SemanticConventions::kRpcMethod, "Greet"}, - {SemanticConventions::kServerSocketAddress, ip}, - {SemanticConventions::kServerPort, port}}, + {SemanticConventions::kNetworkPeerAddress, ip}, + {SemanticConventions::kNetworkPeerPort, port}}, options); auto scope = get_tracer("grpc-client")->WithActiveSpan(span); diff --git a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h index 9396a6c7f9..1b45f80c36 100644 --- a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h +++ b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h @@ -24,7 +24,14 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.21.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.22.0"; + +/** + * Uniquely identifies the framework API revision offered by a version ({@code os.version}) of the + * android operating system. More information can be found here. + */ +static constexpr const char *kAndroidOsApiLevel = "android.os.api_level"; /** * Array of brand name and version separated by a space @@ -36,6 +43,25 @@ static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.21 */ static constexpr const char *kBrowserBrands = "browser.brands"; +/** + * Preferred language of the user using the browser + * + *

Notes: +

  • This value is intended to be taken from the Navigator API {@code + navigator.language}.
+ */ +static constexpr const char *kBrowserLanguage = "browser.language"; + +/** + * A boolean that is true if the browser is running on a mobile device + * + *

Notes: +

  • This value is intended to be taken from the UA client hints API ({@code + navigator.userAgentData.mobile}). If unavailable, this attribute SHOULD be left unset.
+ */ +static constexpr const char *kBrowserMobile = "browser.mobile"; + /** * The platform on which the browser is running * @@ -54,34 +80,34 @@ provides. static constexpr const char *kBrowserPlatform = "browser.platform"; /** - * A boolean that is true if the browser is running on a mobile device + * The cloud account ID the resource is assigned to. + */ +static constexpr const char *kCloudAccountId = "cloud.account.id"; + +/** + * Cloud regions often have multiple, isolated locations known as zones to increase availability. + Availability zone represents the zone where the resource is running. * *

Notes: -

  • This value is intended to be taken from the UA client hints API ({@code - navigator.userAgentData.mobile}). If unavailable, this attribute SHOULD be left unset.
+
  • Availability zones are called "zones" on Alibaba Cloud and Google Cloud.
  • +
*/ -static constexpr const char *kBrowserMobile = "browser.mobile"; +static constexpr const char *kCloudAvailabilityZone = "cloud.availability_zone"; /** - * Preferred language of the user using the browser + * The cloud platform in use. * *

Notes: -

  • This value is intended to be taken from the Navigator API {@code - navigator.language}.
+
  • The prefix of the service SHOULD match the one specified in {@code cloud.provider}.
  • +
*/ -static constexpr const char *kBrowserLanguage = "browser.language"; +static constexpr const char *kCloudPlatform = "cloud.platform"; /** * Name of the cloud provider. */ static constexpr const char *kCloudProvider = "cloud.provider"; -/** - * The cloud account ID the resource is assigned to. - */ -static constexpr const char *kCloudAccountId = "cloud.account.id"; - /** * The geographical region the resource is running. * @@ -127,23 +153,10 @@ that would usually share a TracerProvider. static constexpr const char *kCloudResourceId = "cloud.resource_id"; /** - * Cloud regions often have multiple, isolated locations known as zones to increase availability. - Availability zone represents the zone where the resource is running. - * - *

Notes: -

  • Availability zones are called "zones" on Alibaba Cloud and Google Cloud.
  • -
- */ -static constexpr const char *kCloudAvailabilityZone = "cloud.availability_zone"; - -/** - * The cloud platform in use. - * - *

Notes: -

  • The prefix of the service SHOULD match the one specified in {@code cloud.provider}.
  • -
+ * The ARN of an ECS cluster. */ -static constexpr const char *kCloudPlatform = "cloud.platform"; +static constexpr const char *kAwsEcsClusterArn = "aws.ecs.cluster.arn"; /** * The Amazon Resource Name (ARN) of an ECS cluster. - */ -static constexpr const char *kAwsEcsClusterArn = "aws.ecs.cluster.arn"; - /** * The launch @@ -187,15 +194,6 @@ static constexpr const char *kAwsEcsTaskRevision = "aws.ecs.task.revision"; */ static constexpr const char *kAwsEksClusterArn = "aws.eks.cluster.arn"; -/** - * The name(s) of the AWS log group(s) an application is writing to. - * - *

Notes: -

  • Multiple log groups must be supported for cases like multi-container applications, where - a single application has sidecar containers, and each write to their own log group.
- */ -static constexpr const char *kAwsLogGroupNames = "aws.log.group.names"; - /** * The Amazon Resource Name(s) (ARN) of the AWS log group(s). * @@ -207,9 +205,13 @@ static constexpr const char *kAwsLogGroupNames = "aws.log.group.names"; static constexpr const char *kAwsLogGroupArns = "aws.log.group.arns"; /** - * The name(s) of the AWS log stream(s) an application is writing to. + * The name(s) of the AWS log group(s) an application is writing to. + * + *

Notes: +

  • Multiple log groups must be supported for cases like multi-container applications, where + a single application has sidecar containers, and each write to their own log group.
*/ -static constexpr const char *kAwsLogStreamNames = "aws.log.stream.names"; +static constexpr const char *kAwsLogGroupNames = "aws.log.group.names"; /** * The ARN(s) of the AWS log stream(s). @@ -222,6 +224,11 @@ static constexpr const char *kAwsLogStreamNames = "aws.log.stream.names"; */ static constexpr const char *kAwsLogStreamArns = "aws.log.stream.arns"; +/** + * The name(s) of the AWS log stream(s) an application is writing to. + */ +static constexpr const char *kAwsLogStreamNames = "aws.log.stream.names"; + /** * The name of the Cloud Run
execution being run for the @@ -238,6 +245,12 @@ static constexpr const char *kGcpCloudRunJobExecution = "gcp.cloud_run.job.execu */ static constexpr const char *kGcpCloudRunJobTaskIndex = "gcp.cloud_run.job.task_index"; +/** + * The hostname of a GCE instance. This is the full value of the default or custom hostname. + */ +static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostname"; + /** * The instance name of a GCE instance. This is the value provided by {@code host.name}, the visible * name of the instance in the Cloud Console UI, and the prefix for the default hostname of the @@ -248,10 +261,14 @@ static constexpr const char *kGcpCloudRunJobTaskIndex = "gcp.cloud_run.job.task_ static constexpr const char *kGcpGceInstanceName = "gcp.gce.instance.name"; /** - * The hostname of a GCE instance. This is the full value of the default or custom hostname. + * Unique identifier for the application */ -static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostname"; +static constexpr const char *kHerokuAppId = "heroku.app.id"; + +/** + * Commit hash for the current release + */ +static constexpr const char *kHerokuReleaseCommit = "heroku.release.commit"; /** * Time and date the release was created @@ -259,19 +276,23 @@ static constexpr const char *kGcpGceInstanceHostname = "gcp.gce.instance.hostnam static constexpr const char *kHerokuReleaseCreationTimestamp = "heroku.release.creation_timestamp"; /** - * Commit hash for the current release + * The command used to run the container (i.e. the command name). + * + *

Notes: +

  • If using embedded credentials or sensitive data, it is recommended to remove them to + prevent potential leakage.
*/ -static constexpr const char *kHerokuReleaseCommit = "heroku.release.commit"; +static constexpr const char *kContainerCommand = "container.command"; /** - * Unique identifier for the application + * All the command arguments (including the command/executable itself) run by the container. [2] */ -static constexpr const char *kHerokuAppId = "heroku.app.id"; +static constexpr const char *kContainerCommandArgs = "container.command_args"; /** - * Container name used by container runtime. + * The full command run by the container as a single string representing the full command. [2] */ -static constexpr const char *kContainerName = "container.name"; +static constexpr const char *kContainerCommandLine = "container.command_line"; /** * Container ID. Usually a UUID, as for example used to +The ID is assinged by the container runtime and can vary in different environments. Consider using +{@code oci.manifest.digest} if it is important to identify the same image in different +environments/runtimes. */ static constexpr const char *kContainerImageId = "container.image.id"; /** - * The command used to run the container (i.e. the command name). + * Name of the image the container was built on. + */ +static constexpr const char *kContainerImageName = "container.image.name"; + +/** + * Repo digests of the container image as provided by the container runtime. * *

Notes: -

  • If using embedded credentials or sensitive data, it is recommended to remove them to - prevent potential leakage.
+
  • Docker and CRI + report those under the {@code RepoDigests} field.
*/ -static constexpr const char *kContainerCommand = "container.command"; +static constexpr const char *kContainerImageRepoDigests = "container.image.repo_digests"; /** - * The full command run by the container as a single string representing the full command. [2] + * Container image tags. An example can be found in Docker Image + * Inspect. Should be only the {@code } section of the full name for example from {@code + * registry.example.com/my-org/my-image:}. */ -static constexpr const char *kContainerCommandLine = "container.command_line"; +static constexpr const char *kContainerImageTags = "container.image.tags"; /** - * All the command arguments (including the command/executable itself) run by the container. [2] + * Container name used by container runtime. */ -static constexpr const char *kContainerCommandArgs = "container.command_args"; +static constexpr const char *kContainerName = "container.name"; + +/** + * The container runtime managing this container. + */ +static constexpr const char *kContainerRuntime = "container.runtime"; /** * Name of the deployment @@ -352,6 +375,16 @@ static constexpr const char *kDeploymentEnvironment = "deployment.environment"; */ static constexpr const char *kDeviceId = "device.id"; +/** + * The name of the device manufacturer + * + *

Notes: +

+ */ +static constexpr const char *kDeviceManufacturer = "device.manufacturer"; + /** * The model identifier for the device * @@ -371,14 +404,25 @@ static constexpr const char *kDeviceModelIdentifier = "device.model.identifier"; static constexpr const char *kDeviceModelName = "device.model.name"; /** - * The name of the device manufacturer + * The execution environment ID as a string, that will be potentially reused for other invocations + to the same function/function version. * *

Notes: -

  • The Android OS provides this field via Build. iOS apps - SHOULD hardcode the value {@code Apple}.
+
  • AWS Lambda: Use the (full) log stream name.
  • +
*/ -static constexpr const char *kDeviceManufacturer = "device.manufacturer"; +static constexpr const char *kFaasInstance = "faas.instance"; + +/** + * The amount of memory available to the serverless function converted to Bytes. + * + *

Notes: +

  • It's recommended to set this attribute since e.g. too little memory can easily stop a + Java AWS Lambda function from working correctly. On AWS Lambda, the environment variable {@code + AWS_LAMBDA_FUNCTION_MEMORY_SIZE} provides this information (which must be multiplied by + 1,048,576).
+ */ +static constexpr const char *kFaasMaxMemory = "faas.max_memory"; /** * The name of the single function that this runtime instance executes. @@ -387,7 +431,7 @@ static constexpr const char *kDeviceManufacturer = "device.manufacturer";
  • This is the name of the function as configured/deployed on the FaaS platform and is usually different from the name of the callback function (which may be stored in the -{@code code.namespace}/{@code +{@code code.namespace}/{@code code.function} span attributes).
  • For some cloud providers, the above definition is ambiguous. The following definition of function name MUST be used for this attribute (and consequently the span name) for the listed cloud providers/products:
  • Azure: @@ -418,25 +462,9 @@ not set this attribute.
  • static constexpr const char *kFaasVersion = "faas.version"; /** - * The execution environment ID as a string, that will be potentially reused for other invocations - to the same function/function version. - * - *

    Notes: -

    • AWS Lambda: Use the (full) log stream name.
    • -
    - */ -static constexpr const char *kFaasInstance = "faas.instance"; - -/** - * The amount of memory available to the serverless function converted to Bytes. - * - *

    Notes: -

    • It's recommended to set this attribute since e.g. too little memory can easily stop a - Java AWS Lambda function from working correctly. On AWS Lambda, the environment variable {@code - AWS_LAMBDA_FUNCTION_MEMORY_SIZE} provides this information (which must be multiplied by - 1,048,576).
    + * The CPU architecture the host system is running on. */ -static constexpr const char *kFaasMaxMemory = "faas.max_memory"; +static constexpr const char *kHostArch = "host.arch"; /** * Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider. For @@ -445,6 +473,32 @@ static constexpr const char *kFaasMaxMemory = "faas.max_memory"; */ static constexpr const char *kHostId = "host.id"; +/** + * VM image ID or host OS image ID. For Cloud, this value is from the provider. + */ +static constexpr const char *kHostImageId = "host.image.id"; + +/** + * Name of the VM image or OS install the host was instantiated from. + */ +static constexpr const char *kHostImageName = "host.image.name"; + +/** + * The version string of the VM image or host OS as defined in Version Attributes. + */ +static constexpr const char *kHostImageVersion = "host.image.version"; + +/** + * Available IP addresses of the host, excluding loopback interfaces. + * + *

    Notes: +

    • IPv4 Addresses MUST be specified in dotted-quad notation. IPv6 addresses MUST be + specified in the RFC 5952 format.
    • +
    + */ +static constexpr const char *kHostIp = "host.ip"; + /** * Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully * qualified hostname, or another name specified by the user. @@ -457,25 +511,40 @@ static constexpr const char *kHostName = "host.name"; static constexpr const char *kHostType = "host.type"; /** - * The CPU architecture the host system is running on. + * The amount of level 2 memory cache available to the processor (in Bytes). */ -static constexpr const char *kHostArch = "host.arch"; +static constexpr const char *kHostCpuCacheL2Size = "host.cpu.cache.l2.size"; /** - * Name of the VM image or OS install the host was instantiated from. + * Numeric value specifying the family or generation of the CPU. */ -static constexpr const char *kHostImageName = "host.image.name"; +static constexpr const char *kHostCpuFamily = "host.cpu.family"; /** - * VM image ID or host OS image ID. For Cloud, this value is from the provider. + * Model identifier. It provides more granular information about the CPU, distinguishing it from + * other CPUs within the same family. */ -static constexpr const char *kHostImageId = "host.image.id"; +static constexpr const char *kHostCpuModelId = "host.cpu.model.id"; /** - * The version string of the VM image or host OS as defined in Version Attributes. + * Model designation of the processor. */ -static constexpr const char *kHostImageVersion = "host.image.version"; +static constexpr const char *kHostCpuModelName = "host.cpu.model.name"; + +/** + * Stepping or core revisions. + */ +static constexpr const char *kHostCpuStepping = "host.cpu.stepping"; + +/** + * Processor manufacturer identifier. A maximum 12-character string. + * + *

    Notes: +

    • CPUID command returns the vendor ID string in + EBX, EDX and ECX registers. Writing these to memory in this order results in a 12-character + string.
    + */ +static constexpr const char *kHostCpuVendorId = "host.cpu.vendor.id"; /** * The name of the cluster. @@ -522,14 +591,14 @@ static constexpr const char *kK8sNodeUid = "k8s.node.uid"; static constexpr const char *kK8sNamespaceName = "k8s.namespace.name"; /** - * The UID of the Pod. + * The name of the Pod. */ -static constexpr const char *kK8sPodUid = "k8s.pod.uid"; +static constexpr const char *kK8sPodName = "k8s.pod.name"; /** - * The name of the Pod. + * The UID of the Pod. */ -static constexpr const char *kK8sPodName = "k8s.pod.name"; +static constexpr const char *kK8sPodUid = "k8s.pod.uid"; /** * The name of the Container from Pod specification, must be unique within a Pod. Container runtime @@ -543,15 +612,20 @@ static constexpr const char *kK8sContainerName = "k8s.container.name"; */ static constexpr const char *kK8sContainerRestartCount = "k8s.container.restart_count"; +/** + * The name of the ReplicaSet. + */ +static constexpr const char *kK8sReplicasetName = "k8s.replicaset.name"; + /** * The UID of the ReplicaSet. */ static constexpr const char *kK8sReplicasetUid = "k8s.replicaset.uid"; /** - * The name of the ReplicaSet. + * The name of the Deployment. */ -static constexpr const char *kK8sReplicasetName = "k8s.replicaset.name"; +static constexpr const char *kK8sDeploymentName = "k8s.deployment.name"; /** * The UID of the Deployment. @@ -559,9 +633,9 @@ static constexpr const char *kK8sReplicasetName = "k8s.replicaset.name"; static constexpr const char *kK8sDeploymentUid = "k8s.deployment.uid"; /** - * The name of the Deployment. + * The name of the StatefulSet. */ -static constexpr const char *kK8sDeploymentName = "k8s.deployment.name"; +static constexpr const char *kK8sStatefulsetName = "k8s.statefulset.name"; /** * The UID of the StatefulSet. @@ -569,9 +643,9 @@ static constexpr const char *kK8sDeploymentName = "k8s.deployment.name"; static constexpr const char *kK8sStatefulsetUid = "k8s.statefulset.uid"; /** - * The name of the StatefulSet. + * The name of the DaemonSet. */ -static constexpr const char *kK8sStatefulsetName = "k8s.statefulset.name"; +static constexpr const char *kK8sDaemonsetName = "k8s.daemonset.name"; /** * The UID of the DaemonSet. @@ -579,9 +653,9 @@ static constexpr const char *kK8sStatefulsetName = "k8s.statefulset.name"; static constexpr const char *kK8sDaemonsetUid = "k8s.daemonset.uid"; /** - * The name of the DaemonSet. + * The name of the Job. */ -static constexpr const char *kK8sDaemonsetName = "k8s.daemonset.name"; +static constexpr const char *kK8sJobName = "k8s.job.name"; /** * The UID of the Job. @@ -589,9 +663,9 @@ static constexpr const char *kK8sDaemonsetName = "k8s.daemonset.name"; static constexpr const char *kK8sJobUid = "k8s.job.uid"; /** - * The name of the Job. + * The name of the CronJob. */ -static constexpr const char *kK8sJobName = "k8s.job.name"; +static constexpr const char *kK8sCronjobName = "k8s.cronjob.name"; /** * The UID of the CronJob. @@ -599,14 +673,23 @@ static constexpr const char *kK8sJobName = "k8s.job.name"; static constexpr const char *kK8sCronjobUid = "k8s.cronjob.uid"; /** - * The name of the CronJob. + * The digest of the OCI image manifest. For container images specifically is the digest by which +the container image is known. + * + *

    Notes: +

    */ -static constexpr const char *kK8sCronjobName = "k8s.cronjob.name"; +static constexpr const char *kOciManifestDigest = "oci.manifest.digest"; /** - * The operating system type. + * Unique identifier for a particular build or compilation of the operating system. */ -static constexpr const char *kOsType = "os.type"; +static constexpr const char *kOsBuildId = "os.build_id"; /** * Human readable (not intended to be parsed) OS version information, like e.g. reported by {@code @@ -619,6 +702,11 @@ static constexpr const char *kOsDescription = "os.description"; */ static constexpr const char *kOsName = "os.name"; +/** + * The operating system type. + */ +static constexpr const char *kOsType = "os.type"; + /** * The version string of the operating system as defined in Version Attributes. @@ -626,14 +714,26 @@ static constexpr const char *kOsName = "os.name"; static constexpr const char *kOsVersion = "os.version"; /** - * Process identifier (PID). + * The command used to launch the process (i.e. the command name). On Linux based systems, can be + * set to the zeroth string in {@code proc/[pid]/cmdline}. On Windows, can be set to the first + * parameter extracted from {@code GetCommandLineW}. */ -static constexpr const char *kProcessPid = "process.pid"; +static constexpr const char *kProcessCommand = "process.command"; /** - * Parent Process identifier (PID). + * All the command arguments (including the command/executable itself) as received by the process. + * On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according + * to the list of null-delimited strings extracted from {@code proc/[pid]/cmdline}. For libc-based + * executables, this would be the full argv vector passed to {@code main}. */ -static constexpr const char *kProcessParentPid = "process.parent_pid"; +static constexpr const char *kProcessCommandArgs = "process.command_args"; + +/** + * The full command used to launch the process as a single string representing the full command. On + * Windows, can be set to the result of {@code GetCommandLineW}. Do not set this if you have to + * assemble it just for monitoring; use {@code process.command_args} instead. + */ +static constexpr const char *kProcessCommandLine = "process.command_line"; /** * The name of the process executable. On Linux based systems, can be set to the {@code Name} in @@ -649,31 +749,25 @@ static constexpr const char *kProcessExecutableName = "process.executable.name"; static constexpr const char *kProcessExecutablePath = "process.executable.path"; /** - * The command used to launch the process (i.e. the command name). On Linux based systems, can be - * set to the zeroth string in {@code proc/[pid]/cmdline}. On Windows, can be set to the first - * parameter extracted from {@code GetCommandLineW}. + * The username of the user that owns the process. */ -static constexpr const char *kProcessCommand = "process.command"; +static constexpr const char *kProcessOwner = "process.owner"; /** - * The full command used to launch the process as a single string representing the full command. On - * Windows, can be set to the result of {@code GetCommandLineW}. Do not set this if you have to - * assemble it just for monitoring; use {@code process.command_args} instead. + * Parent Process identifier (PID). */ -static constexpr const char *kProcessCommandLine = "process.command_line"; +static constexpr const char *kProcessParentPid = "process.parent_pid"; /** - * All the command arguments (including the command/executable itself) as received by the process. - * On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according - * to the list of null-delimited strings extracted from {@code proc/[pid]/cmdline}. For libc-based - * executables, this would be the full argv vector passed to {@code main}. + * Process identifier (PID). */ -static constexpr const char *kProcessCommandArgs = "process.command_args"; +static constexpr const char *kProcessPid = "process.pid"; /** - * The username of the user that owns the process. + * An additional description about the runtime of the process, for example a specific vendor + * customization of the runtime environment. */ -static constexpr const char *kProcessOwner = "process.owner"; +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 @@ -686,12 +780,6 @@ static constexpr const char *kProcessRuntimeName = "process.runtime.name"; */ static constexpr const char *kProcessRuntimeVersion = "process.runtime.version"; -/** - * An additional description about the runtime of the process, for example a specific vendor - * customization of the runtime environment. - */ -static constexpr const char *kProcessRuntimeDescription = "process.runtime.description"; - /** * Logical name of the service. * @@ -710,19 +798,6 @@ static constexpr const char *kServiceName = "service.name"; */ static constexpr const char *kServiceVersion = "service.version"; -/** - * A namespace for {@code service.name}. - * - *

    Notes: -

    • A string value having a meaning that helps to distinguish a group of services, for - example the team name that owns a group of services. {@code service.name} is expected to be unique - within the same namespace. If {@code service.namespace} is not specified in the Resource then - {@code service.name} is expected to be unique for all services that have no explicit namespace - defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length - namespace string is assumed equal to unspecified namespace.
    - */ -static constexpr const char *kServiceNamespace = "service.namespace"; - /** * The string ID of the service instance. * @@ -739,6 +814,24 @@ static constexpr const char *kServiceNamespace = "service.namespace"; */ static constexpr const char *kServiceInstanceId = "service.instance.id"; +/** + * A namespace for {@code service.name}. + * + *

    Notes: +

    • A string value having a meaning that helps to distinguish a group of services, for + example the team name that owns a group of services. {@code service.name} is expected to be unique + within the same namespace. If {@code service.namespace} is not specified in the Resource then + {@code service.name} is expected to be unique for all services that have no explicit namespace + defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length + namespace string is assumed equal to unspecified namespace.
    + */ +static constexpr const char *kServiceNamespace = "service.namespace"; + +/** + * The language of the telemetry SDK. + */ +static constexpr const char *kTelemetrySdkLanguage = "telemetry.sdk.language"; + /** * The name of the telemetry SDK as defined above. * @@ -754,19 +847,29 @@ stable across different versions of an implementation.
static constexpr const char *kTelemetrySdkName = "telemetry.sdk.name"; /** - * The language of the telemetry SDK. + * The version string of the telemetry SDK. */ -static constexpr const char *kTelemetrySdkLanguage = "telemetry.sdk.language"; +static constexpr const char *kTelemetrySdkVersion = "telemetry.sdk.version"; /** - * The version string of the telemetry SDK. + * The name of the auto instrumentation agent or distribution, if used. + * + *

Notes: +

  • Official auto instrumentation agents and distributions SHOULD set the {@code +telemetry.distro.name} attribute to a string starting with {@code opentelemetry-}, e.g. {@code +opentelemetry-java-instrumentation}.
*/ -static constexpr const char *kTelemetrySdkVersion = "telemetry.sdk.version"; +static constexpr const char *kTelemetryDistroName = "telemetry.distro.name"; /** - * The version string of the auto instrumentation agent, if used. + * The version string of the auto instrumentation agent or distribution, if used. */ -static constexpr const char *kTelemetryAutoVersion = "telemetry.auto.version"; +static constexpr const char *kTelemetryDistroVersion = "telemetry.distro.version"; + +/** + * Additional description of the web engine (e.g. detailed version and edition information). + */ +static constexpr const char *kWebengineDescription = "webengine.description"; /** * The name of the web engine. @@ -778,11 +881,6 @@ static constexpr const char *kWebengineName = "webengine.name"; */ static constexpr const char *kWebengineVersion = "webengine.version"; -/** - * Additional description of the web engine (e.g. detailed version and edition information). - */ -static constexpr const char *kWebengineDescription = "webengine.description"; - /** * The name of the instrumentation scope - ({@code InstrumentationScope.Name} in OTLP). */ @@ -810,24 +908,6 @@ OPENTELEMETRY_DEPRECATED static constexpr const char *kOtelLibraryVersion = "otel.library.version"; // Enum definitions -namespace CloudProviderValues -{ -/** Alibaba Cloud. */ -static constexpr const char *kAlibabaCloud = "alibaba_cloud"; -/** Amazon Web Services. */ -static constexpr const char *kAws = "aws"; -/** Microsoft Azure. */ -static constexpr const char *kAzure = "azure"; -/** Google Cloud Platform. */ -static constexpr const char *kGcp = "gcp"; -/** Heroku Platform as a Service. */ -static constexpr const char *kHeroku = "heroku"; -/** IBM Cloud. */ -static constexpr const char *kIbmCloud = "ibm_cloud"; -/** Tencent Cloud. */ -static constexpr const char *kTencentCloud = "tencent_cloud"; -} // namespace CloudProviderValues - namespace CloudPlatformValues { /** Alibaba Cloud Elastic Compute Service. */ @@ -886,6 +966,24 @@ static constexpr const char *kTencentCloudEks = "tencent_cloud_eks"; static constexpr const char *kTencentCloudScf = "tencent_cloud_scf"; } // namespace CloudPlatformValues +namespace CloudProviderValues +{ +/** Alibaba Cloud. */ +static constexpr const char *kAlibabaCloud = "alibaba_cloud"; +/** Amazon Web Services. */ +static constexpr const char *kAws = "aws"; +/** Microsoft Azure. */ +static constexpr const char *kAzure = "azure"; +/** Google Cloud Platform. */ +static constexpr const char *kGcp = "gcp"; +/** Heroku Platform as a Service. */ +static constexpr const char *kHeroku = "heroku"; +/** IBM Cloud. */ +static constexpr const char *kIbmCloud = "ibm_cloud"; +/** Tencent Cloud. */ +static constexpr const char *kTencentCloud = "tencent_cloud"; +} // namespace CloudProviderValues + namespace AwsEcsLaunchtypeValues { /** ec2. */ From 46e20a42aef521b9cc1b7207310bfefcd490741a Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 16 Oct 2023 10:38:49 +0200 Subject: [PATCH 096/119] [RELEASE] Prepare release 1.12.0 (#2359) --- CHANGELOG.md | 70 +++++++++++++++++-- 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, 71 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f889a287f7..678e2d6b4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,23 +15,74 @@ Increment the: ## [Unreleased] +## [1.12.0] 2023-10-16 + +* [BUILD] Support `pkg-config` + [#2269](https://github.com/open-telemetry/opentelemetry-cpp/pull/2269) +* [CI] Do not automatically close stale issues + [#2277](https://github.com/open-telemetry/opentelemetry-cpp/pull/2277) +* [CI] Benchmark workflow fails, C++14 required to build grpc + [#2278](https://github.com/open-telemetry/opentelemetry-cpp/pull/2278) +* [SDK] Increase metric name maximum length from 63 to 255 characters + [#2284](https://github.com/open-telemetry/opentelemetry-cpp/pull/2284) +* [SEMANTIC CONVENTION] Deprecated semconv (in the spec) + not deprecated (in C++) + [#2285](https://github.com/open-telemetry/opentelemetry-cpp/pull/2285) +* [SDK] Remove unused member variables from SyncMetricStorage + [#2294](https://github.com/open-telemetry/opentelemetry-cpp/pull/2294) * [DEPRECATION] Deprecate ZPAGES [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) -* [EXPORTER] Prometheus exporter emit resource attributes - [#2301](https://github.com/open-telemetry/opentelemetry-cpp/pull/2301) -* [EXPORTER] Remove explicit timestamps from metric points exported by Prometheus +* [API] Deliver ABI breaking changes + [#2222](https://github.com/open-telemetry/opentelemetry-cpp/pull/2222) +* [SDK] Allow metric instrument names to contain / characters + [#2310](https://github.com/open-telemetry/opentelemetry-cpp/pull/2310) +* [SDK] Fix Observable Counters/UpDownCounters + [#2298](https://github.com/open-telemetry/opentelemetry-cpp/pull/2298) +* [SDK] Add exemplar reservoir to async metric storage + [#2319](https://github.com/open-telemetry/opentelemetry-cpp/pull/2319) +* [TEST] Fix lifetime issues in prometheus test utils + [#2322](https://github.com/open-telemetry/opentelemetry-cpp/pull/2322) +* [EXPORTER] Prometheus: Remove explicit timestamps from metric points [#2324](https://github.com/open-telemetry/opentelemetry-cpp/pull/2324) -* [EXPORTER] Handle attribute key collisions caused by sanitation +* [EXPORTER] Prometheus: Handle attribute key collisions from sanitation [#2326](https://github.com/open-telemetry/opentelemetry-cpp/pull/2326) -* [EXPORTER] Replace colons with underscores when converting to Prometheus label +* [EXPORTER] Prometheus cleanup, test with TranslateToPrometheus + [#2329](https://github.com/open-telemetry/opentelemetry-cpp/pull/2329) +* [SDK] Fix log message in Meter::RegisterSyncMetricStorage + [#2325](https://github.com/open-telemetry/opentelemetry-cpp/pull/2325) +* [DOC] Simplify the project status section + [#2332](https://github.com/open-telemetry/opentelemetry-cpp/pull/2332) +* [EXPORTER] Prometheus: Sanitize labels according to spec [#2330](https://github.com/open-telemetry/opentelemetry-cpp/pull/2330) +* [SDK] Fix deadlock when shuting down http client + [#2337](https://github.com/open-telemetry/opentelemetry-cpp/pull/2337) +* [Exporter] Group spans by resource and instrumentation scope + in OTLP export requests + [#2335](https://github.com/open-telemetry/opentelemetry-cpp/pull/2335) +* [BUILD] Need fine-grained HAVE_CPP_STDLIB + [#2304](https://github.com/open-telemetry/opentelemetry-cpp/pull/2304) * [API] Add InstrumentationScope attributes in MeterProvider::GetMeter() [#2224](https://github.com/open-telemetry/opentelemetry-cpp/pull/2224) * [REMOVAL] Drop C++11 support [#2342](https://github.com/open-telemetry/opentelemetry-cpp/pull/2342) -* [EXPORTER] Add otel_scope_name and otel_scope_version labels to the prometheus - exporter. +* [EXPORTER] prometheus: add otel_scope_name and otel_scope_version labels [#2293](https://github.com/open-telemetry/opentelemetry-cpp/pull/2293) +* [EXPORTER] Export resource for prometheus + [#2301](https://github.com/open-telemetry/opentelemetry-cpp/pull/2301) +* [BUILD] error: read-only reference ‘value’ used as ‘asm’ output + [#2354](https://github.com/open-telemetry/opentelemetry-cpp/pull/2354) +* [BUILD] Build break with external CMake nlohman_json package + [#2353](https://github.com/open-telemetry/opentelemetry-cpp/pull/2353) +* [BUILD] Upgrade libcurl to version 8.4.0 + [#2358](https://github.com/open-telemetry/opentelemetry-cpp/pull/2358) +* [BUILD] Fix opentracing-shim when added in super project + [#2356](https://github.com/open-telemetry/opentelemetry-cpp/pull/2356) +* [BUILD] Fix protoc searching with non-imported protobuf::protoc target + [#2362](https://github.com/open-telemetry/opentelemetry-cpp/pull/2362) +* [BUILD] Support to use different cmake package CONFIG of dependencies + [#2263](https://github.com/open-telemetry/opentelemetry-cpp/pull/2263) +* [SEMANTIC CONVENTION] Upgrade to semconv 1.22.0 + [#2368](https://github.com/open-telemetry/opentelemetry-cpp/pull/2368) Important changes: @@ -70,6 +121,11 @@ Breaking changes: [#2342](https://github.com/open-telemetry/opentelemetry-cpp/pull/2342) * Building with C++11 is no longer supported. +Deprecations: + +* [DEPRECATION] Deprecate ZPAGES + [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) + ## [1.11.0] 2023-08-21 * [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index fd88ffb383..79284c1501 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.11.0" +#define OPENTELEMETRY_VERSION "1.12.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 11 +#define OPENTELEMETRY_VERSION_MINOR 12 #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 1c090b8b35..2375c45924 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.11.0" +release = "1.12.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 b790af4574..16bd121b92 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -5,7 +5,7 @@ #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_SDK_VERSION "1.11.0" +#define OPENTELEMETRY_SDK_VERSION "1.12.0" #include "opentelemetry/version.h" diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index 34175bd4e4..fb2db64c30 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 = 11; +const int minor_version = 12; const int patch_version = 0; const char *pre_release = "NONE"; const char *build_metadata = "NONE"; -const char *short_version = "1.11.0"; -const char *full_version = "1.11.0-NONE-NONE"; -const char *build_date = "Mon Aug 21 22:31:07 UTC 2023"; +const char *short_version = "1.12.0"; +const char *full_version = "1.12.0-NONE-NONE"; +const char *build_date = "Mon 16 Oct 2023 07:42:23 AM UTC"; } // namespace version } // namespace sdk From e918960e06b45e899cd6e1f361acdb578d968334 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 16 Oct 2023 22:07:47 +0200 Subject: [PATCH 097/119] [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead (#2370) --- CHANGELOG.md | 10 ++++++++++ api/CMakeLists.txt | 5 ----- api/include/opentelemetry/metrics/meter_provider.h | 14 +++++++++++++- api/include/opentelemetry/metrics/noop.h | 2 +- ci/do_ci.sh | 4 ---- .../opentelemetry/sdk/metrics/meter_provider.h | 2 +- sdk/src/metrics/meter_provider.cc | 2 +- sdk/test/metrics/meter_provider_sdk_test.cc | 4 ++-- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 678e2d6b4f..48c379b7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,16 @@ Increment the: ## [Unreleased] +* [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead + [#2370](https://github.com/open-telemetry/opentelemetry-cpp/pull/2370) + +Breaking changes: + +* [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead + [#2370](https://github.com/open-telemetry/opentelemetry-cpp/pull/2370) + * The experimental `CMake` option `WITH_REMOVE_METER_PREVIEW` is removed, + use option `WITH_ABI_VERSION_2` instead. + ## [1.12.0] 2023-10-16 * [BUILD] Support `pkg-config` diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index dd1eda3c78..ecbb377725 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -114,11 +114,6 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() -if(WITH_REMOVE_METER_PREVIEW) - target_compile_definitions(opentelemetry_api - INTERFACE ENABLE_REMOVE_METER_PREVIEW) -endif() - target_compile_definitions( opentelemetry_api INTERFACE OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}) diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h index 152e543d36..fca960bb8e 100644 --- a/api/include/opentelemetry/metrics/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -126,7 +126,19 @@ class MeterProvider nostd::string_view schema_url = "") noexcept = 0; #endif -#ifdef ENABLE_REMOVE_METER_PREVIEW +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + /** + * Remove a named Meter instance (ABI). + * + * This API is experimental, see + * https://github.com/open-telemetry/opentelemetry-specification/issues/2232 + * + * @since ABI_VERSION 2 + * + * @param[in] name Meter instrumentation scope + * @param[in] version Instrumentation scope version, optional + * @param[in] schema_url Instrumentation scope schema URL, optional + */ virtual void RemoveMeter(nostd::string_view name, nostd::string_view version = "", nostd::string_view schema_url = "") noexcept = 0; diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index edbbe2c100..f20e855cb7 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -214,7 +214,7 @@ class NoopMeterProvider final : public MeterProvider } #endif -#ifdef ENABLE_REMOVE_METER_PREVIEW +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 void RemoveMeter(nostd::string_view /* name */, nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 948a62b9dd..d9dc0c178f 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -112,7 +112,6 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ - -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -135,7 +134,6 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ - -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -159,7 +157,6 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ - -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ @@ -181,7 +178,6 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then -DWITH_OTLP_HTTP=ON \ -DWITH_OTLP_HTTP_SSL_PREVIEW=ON \ -DWITH_OTLP_HTTP_SSL_TLS_PREVIEW=ON \ - -DWITH_REMOVE_METER_PREVIEW=ON \ -DWITH_PROMETHEUS=ON \ -DWITH_EXAMPLES=ON \ -DWITH_EXAMPLES_HTTP=ON \ diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index 00f9a35ac2..c7089844a5 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -66,7 +66,7 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider nostd::string_view schema_url = "") noexcept override; #endif -#ifdef ENABLE_REMOVE_METER_PREVIEW +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 void RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept override; diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 23ddbc75cf..63bea5ae28 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -75,7 +75,7 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } -#ifdef ENABLE_REMOVE_METER_PREVIEW +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 void MeterProvider::RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url) noexcept diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index 1844f113d2..ce79b563c1 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -191,7 +191,7 @@ TEST(MeterProvider, GetMeterAbiv2) } #endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ -#ifdef ENABLE_REMOVE_METER_PREVIEW +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 TEST(MeterProvider, RemoveMeter) { MeterProvider mp; @@ -225,4 +225,4 @@ TEST(MeterProvider, RemoveMeter) mp.ForceFlush(); mp.Shutdown(); } -#endif +#endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ From 231ca4ade18c8cf691c9520d174b518feae78f35 Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Thu, 19 Oct 2023 00:20:54 +0530 Subject: [PATCH 098/119] [SDK] Metrics ObservableRegistry Cleanup (#2376) --- .../opentelemetry/sdk/metrics/async_instruments.h | 1 + .../sdk/metrics/state/observable_registry.h | 2 ++ sdk/src/metrics/async_instruments.cc | 5 +++++ sdk/src/metrics/state/observable_registry.cc | 10 ++++++++++ 4 files changed, 18 insertions(+) diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index a22ce1f0f8..48c7d14ec5 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -25,6 +25,7 @@ class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument ObservableInstrument(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage, std::shared_ptr observable_registry); + ~ObservableInstrument() override; void AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index 5eb5b6d6ff..b584cc055f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -35,6 +35,8 @@ class ObservableRegistry void *state, opentelemetry::metrics::ObservableInstrument *instrument); + void CleanupCallback(opentelemetry::metrics::ObservableInstrument *instrument); + void Observe(opentelemetry::common::SystemTimestamp collection_ts); private: diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 082d6713b4..5ca56b3969 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -21,6 +21,11 @@ ObservableInstrument::ObservableInstrument(InstrumentDescriptor instrument_descr {} +ObservableInstrument::~ObservableInstrument() +{ + observable_registry_->CleanupCallback(this); +} + void ObservableInstrument::AddCallback(opentelemetry::metrics::ObservableCallbackPtr callback, void *state) noexcept { diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 0296167b05..41b8e86067 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -38,6 +38,16 @@ void ObservableRegistry::RemoveCallback(opentelemetry::metrics::ObservableCallba callbacks_.erase(new_end, callbacks_.end()); } +void ObservableRegistry::CleanupCallback(opentelemetry::metrics::ObservableInstrument *instrument) +{ + std::lock_guard lock_guard{callbacks_m_}; + auto iter = std::remove_if(callbacks_.begin(), callbacks_.end(), + [instrument](const std::unique_ptr &record) { + return record->instrument == instrument; + }); + callbacks_.erase(iter, callbacks_.end()); +} + void ObservableRegistry::Observe(opentelemetry::common::SystemTimestamp collection_ts) { std::lock_guard lock_guard{callbacks_m_}; From 0e6eae04668f67fb4720bedeb16d219ef837c8f5 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 19 Oct 2023 09:42:40 +0200 Subject: [PATCH 099/119] [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream (#2378) --- CHANGELOG.md | 13 +++++++++++++ CMakeLists.txt | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c379b7de..0e30d1784e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,19 @@ Increment the: * [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead [#2370](https://github.com/open-telemetry/opentelemetry-cpp/pull/2370) +* [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream + [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) + +Important changes: + +* [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream + [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) + * The experimental `CMake` option `WITH_OTLP_HTTP_SSL_PREVIEW` + is now promoted to stable. The default is changed to `ON`. + * The experimental `CMake` option `WITH_OTLP_HTTP_SSL_TLS_PREVIEW` + is now promoted to stable. The default is changed to `ON`. + * These build options are scheduled to be removed by the next release, + building without SSL/TLS will no longer be possible. Breaking changes: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4af81bf0e9..b72e58a963 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,12 +275,12 @@ endif() option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF) -# EXPERIMENTAL -option(WITH_OTLP_HTTP_SSL_PREVIEW "Whether to enable otlp http ssl export" OFF) +# STABLE +option(WITH_OTLP_HTTP_SSL_PREVIEW "Whether to enable otlp http ssl export" ON) -# EXPERIMENTAL +# STABLE option(WITH_OTLP_HTTP_SSL_TLS_PREVIEW - "Whether to enable otlp http ssl tls min/max/cipher options" OFF) + "Whether to enable otlp http ssl tls min/max/cipher options" ON) # Exemplar specs status is experimental, so behind feature flag by default option(WITH_METRICS_EXEMPLAR_PREVIEW From d9ad76f6be2b85d8685c31bbdc470a0fb555baba Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 19 Oct 2023 02:28:12 -0700 Subject: [PATCH 100/119] [SDK] Creating DoubleUpDownCounter with no matching view (#2379) --- .../metrics/aggregation/default_aggregation.h | 3 ++- sdk/test/metrics/sum_aggregation_test.cc | 26 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 6ae111fd85..4f3346707f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -35,7 +35,8 @@ class DefaultAggregation case AggregationType::kSum: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) ? std::move(std::unique_ptr(new LongSumAggregation(is_monotonic))) - : std::move(std::unique_ptr(new DoubleSumAggregation(true))); + : std::move( + std::unique_ptr(new DoubleSumAggregation(is_monotonic))); break; case AggregationType::kHistogram: { if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) diff --git a/sdk/test/metrics/sum_aggregation_test.cc b/sdk/test/metrics/sum_aggregation_test.cc index b355f134ed..403bf34b22 100644 --- a/sdk/test/metrics/sum_aggregation_test.cc +++ b/sdk/test/metrics/sum_aggregation_test.cc @@ -121,8 +121,12 @@ TEST(CounterToSum, Double) ASSERT_EQ(1000275.0, opentelemetry::nostd::get(actual.value_)); } -TEST(UpDownCounterToSum, Double) +class UpDownCounterToSumFixture : public ::testing::TestWithParam +{}; + +TEST_P(UpDownCounterToSumFixture, Double) { + bool is_matching_view = GetParam(); MeterProvider mp; auto m = mp.GetMeter("meter1", "version1", "schema1"); std::string instrument_name = "updowncounter1"; @@ -133,13 +137,16 @@ TEST(UpDownCounterToSum, Double) std::shared_ptr reader{new MockMetricReader(std::move(exporter))}; mp.AddMetricReader(reader); - std::unique_ptr view{ - new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; - std::unique_ptr instrument_selector{ - new InstrumentSelector(InstrumentType::kUpDownCounter, 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)); - + if (is_matching_view) + { + std::unique_ptr view{ + new View("view1", "view1_description", instrument_unit, AggregationType::kSum)}; + std::unique_ptr instrument_selector{ + new InstrumentSelector(InstrumentType::kUpDownCounter, 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->CreateDoubleUpDownCounter(instrument_name, instrument_desc, instrument_unit); h->Add(5, {}); @@ -168,4 +175,7 @@ TEST(UpDownCounterToSum, Double) const auto &actual = actuals.at(0); ASSERT_EQ(15.0, opentelemetry::nostd::get(actual.value_)); } +INSTANTIATE_TEST_SUITE_P(UpDownCounterToSum, + UpDownCounterToSumFixture, + ::testing::Values(true, false)); #endif From 91dd15fbdfd23b33e66e4750a8009d2f91525cb1 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 19 Oct 2023 23:34:58 +0200 Subject: [PATCH 101/119] [API] Add InstrumentationScope attributes in TracerProvider::GetTracer() (#2371) --- CHANGELOG.md | 10 ++ api/include/opentelemetry/trace/noop.h | 15 +- .../opentelemetry/trace/tracer_provider.h | 99 ++++++++++++- api/test/singleton/singleton_test.cc | 16 +- api/test/trace/provider_test.cc | 17 ++- .../opentelemetry/sdk/trace/tracer_provider.h | 19 ++- sdk/src/trace/tracer_provider.cc | 37 +++-- sdk/test/trace/tracer_provider_test.cc | 137 ++++++++++++++++++ 8 files changed, 327 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e30d1784e..01f54cf339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,9 +19,19 @@ Increment the: [#2370](https://github.com/open-telemetry/opentelemetry-cpp/pull/2370) * [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) +* [API] Add InstrumentationScope attributes in TracerProvider::GetTracer() + [#2371](https://github.com/open-telemetry/opentelemetry-cpp/pull/2371) Important changes: +* [API] Add InstrumentationScope attributes in TracerProvider::GetTracer() + [#2371](https://github.com/open-telemetry/opentelemetry-cpp/pull/2371) + * TracerProvider::GetTracer() now accepts InstrumentationScope attributes. + * Because this is an `ABI` breaking change, the fix is only available + with the `CMake` option `WITH_ABI_VERSION_2=ON`. + * When building with `CMake` option `WITH_ABI_VERSION_1=ON` (by default) + the `ABI` is unchanged, and the fix is not available. + * [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) * The experimental `CMake` option `WITH_OTLP_HTTP_SSL_PREVIEW` diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 2a2b7312ba..c6a5838867 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -108,12 +108,23 @@ class OPENTELEMETRY_EXPORT NoopTracerProvider final : public trace::TracerProvid : tracer_{nostd::shared_ptr(new trace::NoopTracer)} {} - nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, - nostd::string_view /* library_version */, +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetTracer( + nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */, + const common::KeyValueIterable * /* attributes */) noexcept override + { + return tracer_; + } +#else + nostd::shared_ptr GetTracer(nostd::string_view /* name */, + nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override { return tracer_; } +#endif private: nostd::shared_ptr tracer_; diff --git a/api/include/opentelemetry/trace/tracer_provider.h b/api/include/opentelemetry/trace/tracer_provider.h index bc8ff8da89..059298d395 100644 --- a/api/include/opentelemetry/trace/tracer_provider.h +++ b/api/include/opentelemetry/trace/tracer_provider.h @@ -3,6 +3,8 @@ #pragma once +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" @@ -20,15 +22,106 @@ class OPENTELEMETRY_EXPORT TracerProvider { public: virtual ~TracerProvider() = default; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + + /** + * Gets or creates a named Tracer instance (ABI). + * + * @since ABI_VERSION 2 + * + * @param[in] name Tracer instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes (optional, may be nullptr) + */ + virtual nostd::shared_ptr GetTracer( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const common::KeyValueIterable *attributes) noexcept = 0; + + /** + * Gets or creates a named Tracer instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Tracer instrumentation scope + * @param[in] version Instrumentation scope version, optional + * @param[in] schema_url Instrumentation scope schema URL, optional + */ + nostd::shared_ptr GetTracer(nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") + { + return GetTracer(name, version, schema_url, nullptr); + } + + /** + * Gets or creates a named Tracer instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Tracer instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes + */ + nostd::shared_ptr GetTracer( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + std::initializer_list> attributes) + { + /* Build a container from std::initializer_list. */ + nostd::span> attributes_span{ + attributes.begin(), attributes.end()}; + + /* Build a view on the container. */ + common::KeyValueIterableView< + nostd::span>> + iterable_attributes{attributes_span}; + + /* Add attributes using the view. */ + return GetTracer(name, version, schema_url, &iterable_attributes); + } + + /** + * Gets or creates a named Tracer instance (API helper). + * + * @since ABI_VERSION 2 + * + * @param[in] name Tracer instrumentation scope + * @param[in] version Instrumentation scope version + * @param[in] schema_url Instrumentation scope schema URL + * @param[in] attributes Instrumentation scope attributes container + */ + template ::value> * = nullptr> + nostd::shared_ptr GetTracer(nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const T &attributes) + { + /* Build a view on the container. */ + common::KeyValueIterableView iterable_attributes(attributes); + + /* Add attributes using the view. */ + return GetTracer(name, version, schema_url, &iterable_attributes); + } + +#else + /** * Gets or creates a named tracer instance. * * Optionally a version can be passed to create a named and versioned tracer * instance. */ - virtual nostd::shared_ptr GetTracer(nostd::string_view library_name, - nostd::string_view library_version = "", - nostd::string_view schema_url = "") noexcept = 0; + virtual nostd::shared_ptr GetTracer(nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 44a445e5bd..187e26f2b4 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -264,13 +264,25 @@ class MyTracerProvider : public trace::TracerProvider return result; } - nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, - nostd::string_view /* library_version */, +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetTracer( + nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */, + const common::KeyValueIterable * /* attributes */) noexcept override + { + nostd::shared_ptr result(new MyTracer()); + return result; + } +#else + nostd::shared_ptr GetTracer(nostd::string_view /* name */, + nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override { nostd::shared_ptr result(new MyTracer()); return result; } +#endif }; void setup_otel() diff --git a/api/test/trace/provider_test.cc b/api/test/trace/provider_test.cc index 21e3619334..be2ca2842c 100644 --- a/api/test/trace/provider_test.cc +++ b/api/test/trace/provider_test.cc @@ -3,6 +3,7 @@ #include "opentelemetry/trace/provider.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/tracer_provider.h" #include @@ -14,12 +15,24 @@ namespace nostd = opentelemetry::nostd; class TestProvider : public TracerProvider { - nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, - nostd::string_view /* library_version */, + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + nostd::shared_ptr GetTracer( + nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */, + const opentelemetry::common::KeyValueIterable * /* attributes */) noexcept override + { + return nostd::shared_ptr(nullptr); + } +#else + nostd::shared_ptr GetTracer(nostd::string_view /* name */, + nostd::string_view /* version */, nostd::string_view /* schema_url */) noexcept override { return nostd::shared_ptr(nullptr); } +#endif }; TEST(Provider, GetTracerProviderDefault) diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 092db1eaf8..ce2a6d4401 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -63,10 +63,23 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider ~TracerProvider() override; + /* + Make sure GetTracer() helpers from the API are seen in overload resolution. + */ + using opentelemetry::trace::TracerProvider::GetTracer; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + opentelemetry::nostd::shared_ptr GetTracer( + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const opentelemetry::common::KeyValueIterable *attributes) noexcept override; +#else opentelemetry::nostd::shared_ptr GetTracer( - nostd::string_view library_name, - nostd::string_view library_version = "", - nostd::string_view schema_url = "") noexcept override; + nostd::string_view name, + nostd::string_view version = "", + nostd::string_view schema_url = "") noexcept override; +#endif /** * Attaches a span processor to list of configured processors for this tracer provider. diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 13d56f9966..8569b63f23 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -53,17 +53,29 @@ TracerProvider::~TracerProvider() } } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 nostd::shared_ptr TracerProvider::GetTracer( - nostd::string_view library_name, - nostd::string_view library_version, + nostd::string_view name, + nostd::string_view version, + nostd::string_view schema_url, + const opentelemetry::common::KeyValueIterable *attributes) noexcept +#else +nostd::shared_ptr TracerProvider::GetTracer( + nostd::string_view name, + nostd::string_view version, nostd::string_view schema_url) noexcept +#endif { - if (library_name.data() == nullptr) +#if OPENTELEMETRY_ABI_VERSION_NO < 2 + const opentelemetry::common::KeyValueIterable *attributes = nullptr; +#endif + + if (name.data() == nullptr) { OTEL_INTERNAL_LOG_ERROR("[TracerProvider::GetTracer] Library name is null."); - library_name = ""; + name = ""; } - else if (library_name == "") + else if (name == "") { OTEL_INTERNAL_LOG_ERROR("[TracerProvider::GetTracer] Library name is empty."); } @@ -72,17 +84,20 @@ nostd::shared_ptr TracerProvider::GetTracer( for (auto &tracer : tracers_) { - auto &tracer_lib = tracer->GetInstrumentationScope(); - if (tracer_lib.equal(library_name, library_version, schema_url)) + auto &tracer_scope = tracer->GetInstrumentationScope(); + if (tracer_scope.equal(name, version, schema_url)) { return nostd::shared_ptr{tracer}; } } - auto lib = InstrumentationScope::Create(library_name, library_version, schema_url); - tracers_.push_back(std::shared_ptr( - new sdk::trace::Tracer(context_, std::move(lib)))); - return nostd::shared_ptr{tracers_.back()}; + instrumentationscope::InstrumentationScopeAttributes attrs_map(attributes); + auto scope = + instrumentationscope::InstrumentationScope::Create(name, version, schema_url, attrs_map); + + auto tracer = std::shared_ptr(new Tracer(context_, std::move(scope))); + tracers_.push_back(tracer); + return nostd::shared_ptr{tracer}; } void TracerProvider::AddProcessor(std::unique_ptr processor) noexcept diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 364efc0208..8e1b22fb62 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -78,6 +78,143 @@ TEST(TracerProvider, GetTracer) ASSERT_EQ(instrumentation_scope3.GetVersion(), "1.0.0"); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +TEST(TracerProvider, GetTracerAbiv2) +{ + std::unique_ptr processor(new SimpleSpanProcessor(nullptr)); + std::vector> processors; + processors.push_back(std::move(processor)); + std::unique_ptr context1( + new TracerContext(std::move(processors), Resource::Create({}))); + TracerProvider tp(std::move(context1)); + + auto t1 = tp.GetTracer("name1", "version1", "url1"); + ASSERT_NE(nullptr, t1); + + auto t2 = tp.GetTracer("name2", "version2", "url2", nullptr); + ASSERT_NE(nullptr, t2); + + auto t3 = tp.GetTracer("name3", "version3", "url3", {{"accept_single_attr", true}}); + ASSERT_NE(nullptr, t3); + { + auto tracer = static_cast(t3.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + auto attr = attrs.find("accept_single_attr"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), true); + } + + std::pair attr4 = { + "accept_single_attr", true}; + auto t4 = tp.GetTracer("name4", "version4", "url4", {attr4}); + ASSERT_NE(nullptr, t4); + { + auto tracer = static_cast(t4.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + auto attr = attrs.find("accept_single_attr"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), true); + } + + auto t5 = tp.GetTracer("name5", "version5", "url5", {{"foo", "1"}, {"bar", "2"}}); + ASSERT_NE(nullptr, t5); + { + auto tracer = static_cast(t5.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("bar"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), "2"); + } + + std::initializer_list< + std::pair> + attrs6 = {{"foo", "1"}, {"bar", 42}}; + + auto t6 = tp.GetTracer("name6", "version6", "url6", attrs6); + ASSERT_NE(nullptr, t6); + { + auto tracer = static_cast(t6.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("bar"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 42); + } + + typedef std::pair KV; + + std::initializer_list attrs7 = {{"foo", 3.14}, {"bar", "2"}}; + auto t7 = tp.GetTracer("name7", "version7", "url7", attrs7); + ASSERT_NE(nullptr, t7); + { + auto tracer = static_cast(t7.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + auto attr = attrs.find("foo"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 3.14); + } + + auto t8 = tp.GetTracer("name8", "version8", "url8", + {{"a", "string"}, + {"b", false}, + {"c", 314159}, + {"d", (unsigned int)314159}, + {"e", (int32_t)-20}, + {"f", (uint32_t)20}, + {"g", (int64_t)-20}, + {"h", (uint64_t)20}, + {"i", 3.1}, + {"j", "string"}}); + ASSERT_NE(nullptr, t8); + { + auto tracer = static_cast(t8.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 10); + auto attr = attrs.find("e"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), -20); + } + + std::map attr9{ + {"a", "string"}, {"b", false}, {"c", 314159}, {"d", (unsigned int)314159}, + {"e", (int32_t)-20}, {"f", (uint32_t)20}, {"g", (int64_t)-20}, {"h", (uint64_t)20}, + {"i", 3.1}, {"j", "string"}}; + + auto t9 = tp.GetTracer("name9", "version9", "url9", attr9); + ASSERT_NE(nullptr, t9); + { + auto tracer = static_cast(t9.get()); + auto scope = tracer->GetInstrumentationScope(); + auto attrs = scope.GetAttributes(); + ASSERT_EQ(attrs.size(), 10); + auto attr = attrs.find("h"); + ASSERT_FALSE(attr == attrs.end()); + ASSERT_TRUE(opentelemetry::nostd::holds_alternative(attr->second)); + EXPECT_EQ(opentelemetry::nostd::get(attr->second), 20); + } + + // cleanup properly without crash + tp.ForceFlush(); + tp.Shutdown(); +} +#endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ + TEST(TracerProvider, Shutdown) { std::unique_ptr processor(new SimpleSpanProcessor(nullptr)); From f16deb0740dbbbdde2e434c3d142247b43f55460 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:01:38 -0700 Subject: [PATCH 102/119] Bump peter-evans/create-or-update-comment from 3.0.2 to 3.1.0 (#2381) --- .github/workflows/project_management_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/project_management_comment.yml b/.github/workflows/project_management_comment.yml index c3ddd0034f..feba7112af 100644 --- a/.github/workflows/project_management_comment.yml +++ b/.github/workflows/project_management_comment.yml @@ -12,7 +12,7 @@ jobs: issues: write steps: - name: Add comment - uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 with: issue-number: ${{ github.event.issue.number }} body: | From 045be9c02b555545e64eff91a792cc3869a0892c Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Tue, 24 Oct 2023 03:12:28 +0530 Subject: [PATCH 103/119] [BUILD] DLL export interface for Metrics (#2344) --- ci/do_ci.ps1 | 12 +++++- .../common/metrics_foo_library/CMakeLists.txt | 8 +++- examples/metrics_simple/CMakeLists.txt | 19 ++++++++-- examples/otlp/CMakeLists.txt | 28 ++++++++++---- .../otlp/otlp_grpc_metric_exporter_factory.h | 2 +- .../otlp/otlp_http_metric_exporter_factory.h | 2 +- ext/src/dll/CMakeLists.txt | 14 +++++++ ext/src/dll/opentelemetry_cpp.src | 37 +++++++++++++++++++ ...periodic_exporting_metric_reader_factory.h | 2 +- .../sdk/metrics/meter_context_factory.h | 2 +- .../sdk/metrics/meter_provider.h | 2 +- .../sdk/metrics/meter_provider_factory.h | 2 +- .../view/instrument_selector_factory.h | 2 +- .../sdk/metrics/view/meter_selector_factory.h | 2 +- 14 files changed, 112 insertions(+), 22 deletions(-) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index e55cf8e536..b97617e96f 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -58,7 +58,7 @@ switch ($action) { cmake $SRC_DIR ` -DVCPKG_TARGET_TRIPLET=x64-windows ` -DOPENTELEMETRY_BUILD_DLL=1 ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -79,6 +79,16 @@ switch ($action) { if ($exit -ne 0) { exit $exit } + examples\metrics_simple\Debug\metrics_ostream_example.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + examples\logs_simple\Debug\example_logs_simple.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } } "cmake.maintainer.test" { cd "$BUILD_DIR" diff --git a/examples/common/metrics_foo_library/CMakeLists.txt b/examples/common/metrics_foo_library/CMakeLists.txt index a91b2595b8..abda93c3e6 100644 --- a/examples/common/metrics_foo_library/CMakeLists.txt +++ b/examples/common/metrics_foo_library/CMakeLists.txt @@ -1,6 +1,12 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + add_library(common_metrics_foo_library foo_library.h foo_library.cc) set_target_version(common_metrics_foo_library) -target_link_libraries(common_metrics_foo_library PUBLIC opentelemetry_api) + +target_link_libraries(common_metrics_foo_library + PUBLIC ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/examples/metrics_simple/CMakeLists.txt b/examples/metrics_simple/CMakeLists.txt index 2018ed808c..0fc8c24621 100644 --- a/examples/metrics_simple/CMakeLists.txt +++ b/examples/metrics_simple/CMakeLists.txt @@ -1,9 +1,20 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) + add_executable(metrics_ostream_example metrics_ostream.cc) -target_link_libraries( - metrics_ostream_example ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics - opentelemetry_exporter_ostream_metrics opentelemetry_resources - common_metrics_foo_library) +target_link_libraries(metrics_ostream_example ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library) + +if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(metrics_ostream_example opentelemetry_cpp) +else() + target_link_libraries( + metrics_ostream_example opentelemetry_metrics + opentelemetry_exporter_ostream_metrics opentelemetry_resources) +endif() diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index 398300ab36..5d051a52cc 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -28,10 +28,15 @@ if(WITH_OTLP_GRPC) add_executable(example_otlp_grpc_metric grpc_metric_main.cc) - target_link_libraries( - example_otlp_grpc_metric ${CMAKE_THREAD_LIBS_INIT} - common_metrics_foo_library opentelemetry_metrics - opentelemetry_exporter_otlp_grpc_metrics) + target_link_libraries(example_otlp_grpc_metric ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library) + + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_grpc_metric opentelemetry_cpp) + else() + target_link_libraries(example_otlp_grpc_metric opentelemetry_metrics + opentelemetry_exporter_otlp_grpc_metrics) + endif() # LOG @@ -66,10 +71,17 @@ if(WITH_OTLP_HTTP) # METRIC add_executable(example_otlp_http_metric http_metric_main.cc) - target_link_libraries( - example_otlp_http_metric ${CMAKE_THREAD_LIBS_INIT} - common_metrics_foo_library opentelemetry_metrics - opentelemetry_exporter_otlp_http_metric) + target_link_libraries(example_otlp_http_metric ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library) + + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_http_metric opentelemetry_cpp + opentelemetry_common) + else() + target_link_libraries( + example_otlp_http_metric common_metrics_foo_library opentelemetry_metrics + opentelemetry_exporter_otlp_http_metric) + endif() # LOG 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 d605100ae6..f8b3ee1fc3 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 @@ -15,7 +15,7 @@ namespace otlp /** * Factory class for OtlpGrpcMetricExporter. */ -class OtlpGrpcMetricExporterFactory +class OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterFactory { public: /** 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 2fe0476575..7fa7980470 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 @@ -17,7 +17,7 @@ namespace otlp /** * Factory class for OtlpHttpMetricExporter. */ -class OtlpHttpMetricExporterFactory +class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory { public: /** diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt index c0b6b91745..687d55e01f 100644 --- a/ext/src/dll/CMakeLists.txt +++ b/ext/src/dll/CMakeLists.txt @@ -22,6 +22,20 @@ if(WITH_OTLP_HTTP) PRIVATE opentelemetry_exporter_otlp_http) endif() +target_link_libraries( + opentelemetry_cpp PRIVATE opentelemetry_metrics + opentelemetry_exporter_ostream_metrics) + +if(WITH_OTLP_GRPC) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_grpc_metrics) +endif() + +if(WITH_OTLP_HTTP) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_http_metric) +endif() + target_link_libraries( opentelemetry_cpp PRIVATE opentelemetry_logs opentelemetry_exporter_ostream_logs) diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 5d6d5e0092..49226ec543 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -57,15 +57,48 @@ EXPORTS ?ForceFlush@TracerProvider@trace@sdk@v1@opentelemetry@@QEAA_NV?$duration@_JU?$ratio@$00$0PECEA@@std@@@chrono@std@@@Z ?ForceFlush@LoggerProvider@logs@sdk@v1@opentelemetry@@QEAA_NV?$duration@_JU?$ratio@$00$0PECEA@@std@@@chrono@std@@@Z ??0OStreamLogRecordExporter@logs@exporter@v1@opentelemetry@@QEAA@AEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z + + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::metrics::OStreamMetricExporterFactory::Create(void) + ?Create@OStreamMetricExporterFactory@metrics@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@XZ + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::PeriodicExportingMetricReaderFactory::Create(class std::unique_ptr >,struct opentelemetry::v1::sdk::metrics::PeriodicExportingMetricReaderOptions const & __ptr64) + ?Create@PeriodicExportingMetricReaderFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@7@AEBUPeriodicExportingMetricReaderOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterProviderFactory::Create(void) + ?Create@MeterProviderFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterProvider@metrics@v1@opentelemetry@@U?$default_delete@VMeterProvider@metrics@v1@opentelemetry@@@std@@@std@@XZ + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterContextFactory::Create(void) + ?Create@MeterContextFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterContext@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterContext@metrics@sdk@v1@opentelemetry@@@std@@@std@@XZ + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterProviderFactory::Create(class std::unique_ptr >) + ?Create@MeterProviderFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterProvider@metrics@v1@opentelemetry@@U?$default_delete@VMeterProvider@metrics@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VMeterContext@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterContext@metrics@sdk@v1@opentelemetry@@@std@@@7@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::ViewFactory::Create(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,enum opentelemetry::v1::sdk::metrics::AggregationType,class std::shared_ptr) + ?Create@ViewFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@00W4AggregationType@2345@V?$shared_ptr@VAggregationConfig@metrics@sdk@v1@opentelemetry@@@7@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::ViewFactory::Create(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,enum opentelemetry::v1::sdk::metrics::AggregationType) + ?Create@ViewFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@00W4AggregationType@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterSelectorFactory::Create(class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view) + ?Create@MeterSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@Vstring_view@nostd@45@00@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::InstrumentSelectorFactory::Create(enum opentelemetry::v1::sdk::metrics::InstrumentType,class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view) + ?Create@InstrumentSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@W4InstrumentType@2345@Vstring_view@nostd@45@1@Z + + // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterContext::AddMetricReader(class std::shared_ptr) + ?AddMetricReader@MeterContext@metrics@sdk@v1@opentelemetry@@QEAAXV?$shared_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@Z + // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddMetricReader(class std::shared_ptr) + ?AddMetricReader@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$shared_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@Z + // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddView(class std::unique_ptr >,class std::unique_ptr >,class std::unique_ptr >) + ?AddView@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@7@V?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@7@@Z + + #if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) ?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ ?GetOtlpDefaultLogsTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ + ?GetOtlpDefaultMetricsTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ + ?GetOtlpDefaultMetricsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ #endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) #if defined(WITH_OTLP_GRPC) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions const & __ptr64) + ?Create@OtlpGrpcMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcMetricExporterOptions@2345@@Z + ?GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ @@ -76,5 +109,9 @@ EXPORTS ?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpLogRecordExporterOptions@2345@@Z ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions const &) + ?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpMetricExporterOptions@2345@@Z + ?GetOtlpDefaultHttpMetricsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_HTTP) // clang-format on 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 c4254793f3..1c5c1a0d7b 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 @@ -16,7 +16,7 @@ namespace metrics class MetricReader; class PushMetricExporter; -class PeriodicExportingMetricReaderFactory +class OPENTELEMETRY_EXPORT PeriodicExportingMetricReaderFactory { public: static std::unique_ptr Create(std::unique_ptr exporter, diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h index d5ca16cc27..13e3a9f290 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context_factory.h @@ -21,7 +21,7 @@ class ViewRegistry; /** * Factory class for MeterContext. */ -class MeterContextFactory +class OPENTELEMETRY_EXPORT MeterContextFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index c7089844a5..8a8c04c636 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -30,7 +30,7 @@ class MeterContext; class MetricCollector; class MetricReader; -class MeterProvider final : public opentelemetry::metrics::MeterProvider +class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics::MeterProvider { public: /** diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h index 6c0375ad9d..69e77ebf5e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider_factory.h @@ -56,7 +56,7 @@ namespace metrics even if this forces, temporarily, existing applications to use a downcast. */ -class MeterProviderFactory +class OPENTELEMETRY_EXPORT MeterProviderFactory { public: static std::unique_ptr Create(); 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 f30b1e27c1..0af1efe04b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h @@ -14,7 +14,7 @@ namespace metrics class InstrumentSelector; -class InstrumentSelectorFactory +class OPENTELEMETRY_EXPORT InstrumentSelectorFactory { public: static std::unique_ptr Create( 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 f335f725f7..bd599d9c4b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h @@ -16,7 +16,7 @@ namespace metrics class MeterSelector; -class MeterSelectorFactory +class OPENTELEMETRY_EXPORT MeterSelectorFactory { public: static std::unique_ptr Create(opentelemetry::nostd::string_view name, From 0baf5015ea3b4efc1e86db6fa179ec2e3918eb80 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 24 Oct 2023 10:11:32 +0200 Subject: [PATCH 104/119] [BUILD] enum CanonicalCode names too generic... conflict with old C defines (#2385) --- CHANGELOG.md | 9 ++ .../opentelemetry/trace/canonical_code.h | 141 ------------------ api/include/opentelemetry/trace/span.h | 1 - .../exporters/ostream/span_exporter.h | 2 +- .../ext/zpages/threadsafe_span_data.h | 1 - .../opentelemetry/ext/zpages/tracez_data.h | 2 - .../ext/zpages/tracez_data_aggregator.h | 3 - 7 files changed, 10 insertions(+), 149 deletions(-) delete mode 100644 api/include/opentelemetry/trace/canonical_code.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f54cf339..536a90487a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Increment the: [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) * [API] Add InstrumentationScope attributes in TracerProvider::GetTracer() [#2371](https://github.com/open-telemetry/opentelemetry-cpp/pull/2371) +* [BUILD] enum CanonicalCode names too generic... conflict with old C defines + [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) Important changes: @@ -48,6 +50,13 @@ Breaking changes: * The experimental `CMake` option `WITH_REMOVE_METER_PREVIEW` is removed, use option `WITH_ABI_VERSION_2` instead. +* [BUILD] enum CanonicalCode names too generic... conflict with old C defines + [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) + * Header file `opentelemetry/trace/canonical_code.h` is unused, + and is now removed. + * This header should not be included directly in an application. + If this is the case, please remove any remaining include directives. + ## [1.12.0] 2023-10-16 * [BUILD] Support `pkg-config` diff --git a/api/include/opentelemetry/trace/canonical_code.h b/api/include/opentelemetry/trace/canonical_code.h deleted file mode 100644 index fd722891d6..0000000000 --- a/api/include/opentelemetry/trace/canonical_code.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include "opentelemetry/version.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace trace -{ -enum class CanonicalCode : uint8_t -{ - /** - * The operation completed successfully. - */ - OK = 0, - - /** - * The operation was cancelled (typically by the caller). - */ - CANCELLED = 1, - - /** - * Unknown error. An example of where this error may be returned is if a Status value received - * from another address space belongs to an error-space that is not known in this address space. - * Also errors raised by APIs that do not return enough error information may be converted to - * this error. - */ - UNKNOWN = 2, - - /** - * Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. - * INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the - * system (e.g., a malformed file name). - */ - INVALID_ARGUMENT = 3, - - /** - * Deadline expired before operation could complete. For operations that change the state of the - * system, this error may be returned even if the operation has completed successfully. For - * example, a successful response from a server could have been delayed long enough for the - * deadline to expire. - */ - DEADLINE_EXCEEDED = 4, - - /** - * Some requested entity (e.g., file or directory) was not found. - */ - NOT_FOUND = 5, - - /** - * Some entity that we attempted to create (e.g., file or directory) already exists. - */ - ALREADY_EXISTS = 6, - - /** - * The caller does not have permission to execute the specified operation. PERMISSION_DENIED - * must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED - * instead for those errors). PERMISSION_DENIED must not be used if the caller cannot be - * identified (use UNAUTHENTICATED instead for those errors). - */ - PERMISSION_DENIED = 7, - - /** - * Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system - * is out of space. - */ - RESOURCE_EXHAUSTED = 8, - - /** - * Operation was rejected because the system is not in a state required for the operation's - * execution. For example, directory to be deleted may be non-empty, an rmdir operation is - * applied to a non-directory, etc. - * - * A litmus test that may help a service implementor in deciding between FAILED_PRECONDITION, - * ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call. - * (b) Use ABORTED if the client should retry at a higher-level (e.g., restarting a - * read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until - * the system state has been explicitly fixed. E.g., if an "rmdir" fails because the directory - * is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless - * they have first fixed up the directory by deleting files from it. - */ - FAILED_PRECONDITION = 9, - - /** - * The operation was aborted, typically due to a concurrency issue like sequencer check - * failures, transaction aborts, etc. - * - * See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE. - */ - ABORTED = 10, - - /** - * Operation was attempted past the valid range. E.g., seeking or reading past end of file. - * - * Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system - * state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to - * read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if - * asked to read from an offset past the current file size. - * - * There is a fair bit of overlap between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend - * using OUT_OF_RANGE (the more specific error) when it applies so that callers who are - * iterating through a space can easily look for an OUT_OF_RANGE error to detect when they are - * done. - */ - OUT_OF_RANGE = 11, - - /** - * Operation is not implemented or not supported/enabled in this service. - */ - UNIMPLEMENTED = 12, - - /** - * Internal errors. Means some invariants expected by underlying system has been broken. If you - * see one of these errors, something is very broken. - */ - INTERNAL = 13, - - /** - * The service is currently unavailable. This is a most likely a transient condition and may be - * corrected by retrying with a backoff. - * - * See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE. - */ - UNAVAILABLE = 14, - - /** - * Unrecoverable data loss or corruption. - */ - DATA_LOSS = 15, - - /** - * The request does not have valid authentication credentials for the operation. - */ - UNAUTHENTICATED = 16, -}; - -} // namespace trace -OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/trace/span.h b/api/include/opentelemetry/trace/span.h index ffd145a30d..8fb371d48c 100644 --- a/api/include/opentelemetry/trace/span.h +++ b/api/include/opentelemetry/trace/span.h @@ -10,7 +10,6 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" -#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index baa4e860b1..05c8a89982 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -55,7 +55,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter mutable opentelemetry::common::SpinLockMutex lock_; bool isShutdown() const noexcept; - // Mapping status number to the string from api/include/opentelemetry/trace/canonical_code.h + // Mapping status number to the string from api/include/opentelemetry/trace/span_metadata.h std::map statusMap{{0, "Unset"}, {1, "Ok"}, {2, "Error"}}; // various print helpers diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index fdc244255b..bd1f716ad8 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -12,7 +12,6 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" diff --git a/ext/include/opentelemetry/ext/zpages/tracez_data.h b/ext/include/opentelemetry/ext/zpages/tracez_data.h index 4594fbe057..5f36a6b047 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_data.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_data.h @@ -12,13 +12,11 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/version.h" using opentelemetry::ext::zpages::ThreadsafeSpanData; -using opentelemetry::trace::CanonicalCode; using opentelemetry::trace::SpanId; using opentelemetry::trace::TraceId; diff --git a/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h b/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h index 62c944b704..5bc7e847db 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_data_aggregator.h @@ -19,9 +19,6 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/trace/canonical_code.h" - -using opentelemetry::trace::CanonicalCode; OPENTELEMETRY_BEGIN_NAMESPACE namespace ext From d3a873a673809875595aaf98615b8a1a1fc501db Mon Sep 17 00:00:00 2001 From: jafonso Date: Wed, 25 Oct 2023 20:33:21 +0200 Subject: [PATCH 105/119] [BUILD] Fix cpack broken package version (#2386) --- cmake/package.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/package.cmake b/cmake/package.cmake index ef0a879e0f..c14b38fde0 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -1,6 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +set(CPACK_PACKAGE_VERSION "${OPENTELEMETRY_VERSION}") set(CPACK_PACKAGE_DESCRIPTION "OpenTelemetry C++ for Linux") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenTelemetry C++ for Linux - C++ Implementation of OpenTelemetry Specification") set(CPACK_PACKAGE_VENDOR "OpenTelemetry") From 17da6d87c1fbd5e63260b3eb414e426e255dfebd Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 27 Oct 2023 18:27:57 +0200 Subject: [PATCH 106/119] [API] Add a new AddLink() operation to Span (#2380) --- CHANGELOG.md | 11 + api/include/opentelemetry/plugin/tracer.h | 14 + .../opentelemetry/trace/default_span.h | 8 + api/include/opentelemetry/trace/noop.h | 9 + api/include/opentelemetry/trace/span.h | 138 ++++++- .../trace/span_context_kv_iterable.h | 1 + api/test/trace/noop_test.cc | 15 + examples/plugin/plugin/tracer.cc | 8 + sdk/src/trace/span.cc | 29 ++ sdk/src/trace/span.h | 7 + sdk/test/trace/tracer_test.cc | 386 ++++++++++++++++++ 11 files changed, 623 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 536a90487a..a76b91692b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ Increment the: [#2371](https://github.com/open-telemetry/opentelemetry-cpp/pull/2371) * [BUILD] enum CanonicalCode names too generic... conflict with old C defines [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) +* [API] Add a new AddLink() operation to Span + [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) Important changes: @@ -34,6 +36,15 @@ Important changes: * When building with `CMake` option `WITH_ABI_VERSION_1=ON` (by default) the `ABI` is unchanged, and the fix is not available. +* [API] Add a new AddLink() operation to Span + [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) + * New `API` Span::AddLink() adds a single link to a span. + * New `API` Span::AddLinks() adds multiple links to a span. + * Because this is an `ABI` breaking change, the fix is only available + with the `CMake` option `WITH_ABI_VERSION_2=ON`. + * When building with `CMake` option `WITH_ABI_VERSION_1=ON` (by default) + the `ABI` is unchanged, and the fix is not available. + * [BUILD] Make WITH_OTLP_HTTP_SSL_PREVIEW mainstream [#2378](https://github.com/open-telemetry/opentelemetry-cpp/pull/2378) * The experimental `CMake` option `WITH_OTLP_HTTP_SSL_PREVIEW` diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index b87f9e889f..068b08071d 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -7,6 +7,7 @@ #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/plugin/detail/tracer_handle.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" @@ -49,6 +50,19 @@ class Span final : public trace::Span span_->AddEvent(name, timestamp, attributes); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void AddLink(const trace::SpanContext &target, + const common::KeyValueIterable &attrs) noexcept override + { + span_->AddLink(target, attrs); + } + + void AddLinks(const trace::SpanContextKeyValueIterable &links) noexcept override + { + span_->AddLinks(links); + } +#endif + void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override { span_->SetStatus(code, description); diff --git a/api/include/opentelemetry/trace/default_span.h b/api/include/opentelemetry/trace/default_span.h index cccc7951ad..7e3979501e 100644 --- a/api/include/opentelemetry/trace/default_span.h +++ b/api/include/opentelemetry/trace/default_span.h @@ -47,6 +47,14 @@ class DefaultSpan : public Span const common::KeyValueIterable & /* attributes */) noexcept override {} +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void AddLink(const SpanContext & /* target */, + const common::KeyValueIterable & /* attrs */) noexcept override + {} + + void AddLinks(const SpanContextKeyValueIterable & /* links */) noexcept override {} +#endif + void SetStatus(StatusCode /* status */, nostd::string_view /* description */) noexcept override {} void UpdateName(nostd::string_view /* name */) noexcept override {} diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index c6a5838867..407f3c1ac9 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -15,6 +15,7 @@ #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/tracer.h" #include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/version.h" @@ -58,6 +59,14 @@ class OPENTELEMETRY_EXPORT NoopSpan final : public Span const common::KeyValueIterable & /*attributes*/) noexcept override {} +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void AddLink(const SpanContext & /* target */, + const common::KeyValueIterable & /* attrs */) noexcept override + {} + + void AddLinks(const SpanContextKeyValueIterable & /* links */) noexcept override {} +#endif + void SetStatus(StatusCode /*code*/, nostd::string_view /*description*/) noexcept override {} void UpdateName(nostd::string_view /*name*/) noexcept override {} diff --git a/api/include/opentelemetry/trace/span.h b/api/include/opentelemetry/trace/span.h index 8fb371d48c..27e91ceec4 100644 --- a/api/include/opentelemetry/trace/span.h +++ b/api/include/opentelemetry/trace/span.h @@ -11,6 +11,8 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" #include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_context_kv_iterable_view.h" #include "opentelemetry/trace/span_metadata.h" #include "opentelemetry/version.h" @@ -23,6 +25,31 @@ class Tracer; /** * A Span represents a single operation within a Trace. + * + * Span attributes can be provided: + * - at span creation time, using Tracer::StartSpan(), + * - during the span lifetime, using Span::SetAttribute() + * + * Please note that head samplers, + * in the SDK (@ref opentelemetry::sdk::trace::Sampler), + * can only make sampling decisions based on data known + * at span creation time. + * + * When attributes are known early, adding attributes + * with @ref opentelemetry::trace::Tracer::StartSpan() is preferable. + * + * Attributes added or changed with Span::SetAttribute() + * can not change a sampler decision. + * + * Likewise, links can be provided: + * - at span creation time, using Tracer::StartSpan(), + * - during the span lifetime, using Span::AddLink() or Span::AddLinks(). + * + * When links are known early, adding links + * with @ref opentelemetry::trace::Tracer::StartSpan() is preferable. + * + * Links added with Span::AddLink() or Span::AddLinks() + * can not change a sampler decision. */ class Span { @@ -40,9 +67,14 @@ class Span Span &operator=(const Span &) = delete; Span &operator=(Span &&) = delete; - // Sets an attribute on the Span. If the Span previously contained a mapping - // for - // the key, the old value is replaced. + /** + * Sets an attribute on the Span (ABI). + * + * If the Span previously contained a mapping for the key, + * the old value is replaced. + * + * See comments about sampling in @ref opentelemetry::trace::Span + */ virtual void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept = 0; @@ -98,6 +130,106 @@ class Span attributes.begin(), attributes.end()}); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + + /** + * Add link (ABI). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + virtual void AddLink(const SpanContext &target, + const common::KeyValueIterable &attrs) noexcept = 0; + + /** + * Add links (ABI). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + virtual void AddLinks(const SpanContextKeyValueIterable &links) noexcept = 0; + + /** + * Add link (API helper). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + template ::value> * = nullptr> + void AddLink(const SpanContext &target, const U &attrs) + { + common::KeyValueIterableView view(attrs); + this->AddLink(target, view); + } + + /** + * Add link (API helper). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + void AddLink(const SpanContext &target, + std::initializer_list> attrs) + { + /* Build a container from std::initializer_list. */ + nostd::span> container{ + attrs.begin(), attrs.end()}; + + /* Build a view on the container. */ + common::KeyValueIterableView< + nostd::span>> + view(container); + + return this->AddLink(target, view); + } + + /** + * Add links (API helper). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + template ::value> * = nullptr> + void AddLinks(const U &links) + { + SpanContextKeyValueIterableView view(links); + this->AddLinks(view); + } + + /** + * Add links (API helper). + * + * See comments about sampling in @ref opentelemetry::trace::Span + * + * @since ABI_VERSION 2 + */ + void AddLinks( + std::initializer_list< + std::pair>>> + links) + { + /* Build a container from std::initializer_list. */ + nostd::span>>> + container{links.begin(), links.end()}; + + /* Build a view on the container. */ + SpanContextKeyValueIterableView>>>> + view(container); + + return this->AddLinks(view); + } + +#endif /* OPENTELEMETRY_ABI_VERSION_NO */ + // Sets the status of the span. The default status is Unset. Only the value of // the last call will be // recorded, and implementations are free to ignore previous calls. diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index 8f3010ce9d..aed3474272 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -6,6 +6,7 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/test/trace/noop_test.cc b/api/test/trace/noop_test.cc index 130496faf0..b47700d442 100644 --- a/api/test/trace/noop_test.cc +++ b/api/test/trace/noop_test.cc @@ -46,6 +46,21 @@ TEST(NoopTest, UseNoopTracers) s1->GetContext(); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +TEST(NoopTest, UseNoopTracersAbiv2) +{ + std::shared_ptr tracer{new trace_api::NoopTracer{}}; + auto s1 = tracer->StartSpan("abc"); + + EXPECT_EQ(s1->IsRecording(), false); + + trace_api::SpanContext target(false, false); + s1->AddLink(target, {{"noop1", 1}}); + + s1->AddLinks({{trace_api::SpanContext(false, false), {{"noop2", 2}}}}); +} +#endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ + TEST(NoopTest, StartSpan) { std::shared_ptr tracer{new trace_api::NoopTracer{}}; diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 55de64438d..14d1a746df 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -49,6 +49,14 @@ class Span final : public trace::Span const common::KeyValueIterable & /*attributes*/) noexcept override {} +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void AddLink(const trace::SpanContext & /* target */, + const common::KeyValueIterable & /* attrs */) noexcept override + {} + + void AddLinks(const trace::SpanContextKeyValueIterable & /* links */) noexcept override {} +#endif + void SetStatus(trace::StatusCode /*code*/, nostd::string_view /*description*/) noexcept override {} diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index c7524d43aa..25708cddd9 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -146,6 +146,35 @@ void Span::AddEvent(nostd::string_view name, recordable_->AddEvent(name, timestamp, attributes); } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +void Span::AddLink(const opentelemetry::trace::SpanContext &target, + const opentelemetry::common::KeyValueIterable &attrs) noexcept +{ + std::lock_guard lock_guard{mu_}; + if (recordable_ == nullptr) + { + return; + } + + recordable_->AddLink(target, attrs); +} + +void Span::AddLinks(const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept +{ + std::lock_guard lock_guard{mu_}; + if (recordable_ == nullptr) + { + return; + } + + links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, + const common::KeyValueIterable &attributes) { + recordable_->AddLink(span_context, attributes); + return true; + }); +} +#endif + void Span::SetStatus(opentelemetry::trace::StatusCode code, nostd::string_view description) noexcept { std::lock_guard lock_guard{mu_}; diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 75e31e9500..eb603b9025 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -42,6 +42,13 @@ class Span final : public opentelemetry::trace::Span opentelemetry::common::SystemTimestamp timestamp, const opentelemetry::common::KeyValueIterable &attributes) noexcept override; +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void AddLink(const opentelemetry::trace::SpanContext &target, + const opentelemetry::common::KeyValueIterable &attrs) noexcept override; + + void AddLinks(const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept override; +#endif + void SetStatus(opentelemetry::trace::StatusCode code, nostd::string_view description) noexcept override; diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 45b5fc010f..36cc135a1d 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -519,6 +519,392 @@ TEST(Tracer, SpanSetLinks) } } +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +TEST(Tracer, SpanAddLinkAbiv2) +{ + InMemorySpanExporter *exporter = new InMemorySpanExporter(); + std::shared_ptr span_data = exporter->GetData(); + auto tracer = initTracer(std::unique_ptr{exporter}); + + { + auto span = tracer->StartSpan("span"); + SpanContext target(false, false); + // Single link attribute passed through Initialization list + span->AddLink(target, {{"attr2", 2}}); + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(nostd::get(attrs.at("attr2")), 2); + } + + { + auto span = tracer->StartSpan("span"); + SpanContext target(false, false); + // Multiple link attributes passed through Initialization list + span->AddLink(target, {{"attr2", 2}, {"attr3", 3}}); + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(nostd::get(attrs.at("attr2")), 2); + ASSERT_EQ(nostd::get(attrs.at("attr3")), 3); + } + + { + std::map attrs_map = {{"attr1", "1"}, {"attr2", "2"}}; + + auto span = tracer->StartSpan("span"); + SpanContext target(false, false); + span->AddLink(target, attrs_map); + span->End(); + + auto spans = span_data->GetSpans(); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(nostd::get(attrs.at("attr1")), "1"); + ASSERT_EQ(nostd::get(attrs.at("attr2")), "2"); + } + + { + auto span = tracer->StartSpan("span"); + SpanContext target(false, false); + + // Single link attribute passed through Initialization list + span->AddLink(target, {{"attr1", 1}}); + + // Multiple link attributes passed through Initialization list + span->AddLink(target, {{"attr2", 2}, {"attr3", 3}}); + + std::map attrs_map = {{"attr4", "4"}, {"attr5", "5"}}; + span->AddLink(target, attrs_map); + + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(3, span_data_links.size()); + + { + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr1")), 1); + } + + { + auto link = span_data_links.at(1); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attr2")), 2); + ASSERT_EQ(nostd::get(attrs.at("attr3")), 3); + } + + { + auto link = span_data_links.at(2); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attr4")), "4"); + ASSERT_EQ(nostd::get(attrs.at("attr5")), "5"); + } + } +} + +TEST(Tracer, SpanAddLinksAbiv2) +{ + InMemorySpanExporter *exporter = new InMemorySpanExporter(); + std::shared_ptr span_data = exporter->GetData(); + auto tracer = initTracer(std::unique_ptr{exporter}); + + { + auto span = tracer->StartSpan("span"); + // Single span link passed through Initialization list + span->AddLinks({{SpanContext(false, false), {{"attr2", 2}}}}); + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link = span_data_links.at(0); + ASSERT_EQ(nostd::get(link.GetAttributes().at("attr2")), 2); + } + + { + auto span = tracer->StartSpan("span"); + // Multiple span links passed through Initialization list + span->AddLinks( + {{SpanContext(false, false), {{"attr2", 2}}}, {SpanContext(false, false), {{"attr3", 3}}}}); + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 2); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr3")), 3); + } + + { + auto span = tracer->StartSpan("span"); + // Multiple links, each with multiple attributes passed through Initialization list + span->AddLinks({{SpanContext(false, false), {{"attr2", 2}, {"attr3", 3}}}, + {SpanContext(false, false), {{"attr4", 4}}}}); + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 2); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr3")), 3); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr4")), 4); + } + + { + std::map attrs1 = {{"attr1", "1"}, {"attr2", "2"}}; + std::map attrs2 = {{"attr3", "3"}, {"attr4", "4"}}; + + std::vector>> links = { + {SpanContext(false, false), attrs1}, {SpanContext(false, false), attrs2}}; + + auto span = tracer->StartSpan("span"); + span->AddLinks(links); + span->End(); + + auto spans = span_data->GetSpans(); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr1")), "1"); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), "2"); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr3")), "3"); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr4")), "4"); + } + + { + auto span = tracer->StartSpan("span"); + + // Single span link passed through Initialization list + span->AddLinks({{SpanContext(false, false), {{"attr10", 10}}}}); + span->AddLinks({{SpanContext(false, false), {{"attr11", 11}}}}); + + // Multiple span links passed through Initialization list + span->AddLinks({{SpanContext(false, false), {{"attr12", 12}}}, + {SpanContext(false, false), {{"attr13", 13}}}}); + span->AddLinks({{SpanContext(false, false), {{"attr14", 14}}}, + {SpanContext(false, false), {{"attr15", 15}}}}); + + // Multiple links, each with multiple attributes passed through Initialization list + span->AddLinks({{SpanContext(false, false), {{"attr16", 16}, {"attr17", 17}}}, + {SpanContext(false, false), {{"attr18", 18}}}}); + span->AddLinks({{SpanContext(false, false), {{"attr19", 19}, {"attr20", 20}}}, + {SpanContext(false, false), {{"attr21", 21}}}}); + + std::map attrsa1 = {{"attra1", "1"}, {"attra2", "2"}}; + std::map attrsa2 = {{"attra3", "3"}, {"attra4", "4"}}; + + std::vector>> linksa = { + {SpanContext(false, false), attrsa1}, {SpanContext(false, false), attrsa2}}; + + span->AddLinks(linksa); + + std::map attrsb1 = {{"attrb1", "1"}, {"attrb2", "2"}}; + std::map attrsb2 = {{"attrb3", "3"}, {"attrb4", "4"}}; + + std::vector>> linksb = { + {SpanContext(false, false), attrsb1}, {SpanContext(false, false), attrsb2}}; + + span->AddLinks(linksb); + + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(14, span_data_links.size()); + + { + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr10")), 10); + } + + { + auto link = span_data_links.at(1); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr11")), 11); + } + + { + auto link = span_data_links.at(2); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr12")), 12); + } + + { + auto link = span_data_links.at(3); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr13")), 13); + } + + { + auto link = span_data_links.at(4); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr14")), 14); + } + + { + auto link = span_data_links.at(5); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr15")), 15); + } + + { + auto link = span_data_links.at(6); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attr16")), 16); + ASSERT_EQ(nostd::get(attrs.at("attr17")), 17); + } + + { + auto link = span_data_links.at(7); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr18")), 18); + } + + { + auto link = span_data_links.at(8); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attr19")), 19); + ASSERT_EQ(nostd::get(attrs.at("attr20")), 20); + } + + { + auto link = span_data_links.at(9); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr21")), 21); + } + + { + auto link = span_data_links.at(10); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attra1")), "1"); + ASSERT_EQ(nostd::get(attrs.at("attra2")), "2"); + } + + { + auto link = span_data_links.at(11); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attra3")), "3"); + ASSERT_EQ(nostd::get(attrs.at("attra4")), "4"); + } + + { + auto link = span_data_links.at(12); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attrb1")), "1"); + ASSERT_EQ(nostd::get(attrs.at("attrb2")), "2"); + } + + { + auto link = span_data_links.at(13); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 2); + ASSERT_EQ(nostd::get(attrs.at("attrb3")), "3"); + ASSERT_EQ(nostd::get(attrs.at("attrb4")), "4"); + } + } +} + +TEST(Tracer, SpanMixLinksAbiv2) +{ + InMemorySpanExporter *exporter = new InMemorySpanExporter(); + std::shared_ptr span_data = exporter->GetData(); + auto tracer = initTracer(std::unique_ptr{exporter}); + + { + // Link 1 added at StartSpan + auto span = + tracer->StartSpan("span", {{"attr1", 1}}, {{SpanContext(false, false), {{"attr2", 2}}}}); + + SpanContext target(false, false); + // Link 2 added with AddLink + span->AddLink(target, {{"attr3", 3}}); + + // Link 3 added with AddLinks + span->AddLinks({{SpanContext(false, false), {{"attr4", 4}}}}); + + span->End(); + + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(3, span_data_links.size()); + + { + auto link = span_data_links.at(0); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr2")), 2); + } + + { + auto link = span_data_links.at(1); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr3")), 3); + } + + { + auto link = span_data_links.at(2); + auto attrs = link.GetAttributes(); + ASSERT_EQ(attrs.size(), 1); + ASSERT_EQ(nostd::get(attrs.at("attr4")), 4); + } + } +} +#endif /* OPENTELEMETRY_ABI_VERSION_NO >= 2 */ + TEST(Tracer, TestAlwaysOnSampler) { InMemorySpanExporter *exporter = new InMemorySpanExporter(); From 758687cde41c5a4a854818585520b47305011267 Mon Sep 17 00:00:00 2001 From: Alex E <36134278+chusitoo@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:55:32 -0400 Subject: [PATCH 107/119] [opentracing-shim] Add check for sampled context (#2390) --- opentracing-shim/src/tracer_shim.cc | 21 ++++++++++++++------- opentracing-shim/test/tracer_shim_test.cc | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/opentracing-shim/src/tracer_shim.cc b/opentracing-shim/src/tracer_shim.cc index c8805d15ef..41c6404624 100644 --- a/opentracing-shim/src/tracer_shim.cc +++ b/opentracing-shim/src/tracer_shim.cc @@ -148,13 +148,20 @@ opentracing::expected> TracerShim::ext auto span_context = opentelemetry::trace::GetSpan(context)->GetContext(); auto baggage = opentelemetry::baggage::GetBaggage(context); - // If the extracted SpanContext is invalid AND the extracted Baggage is empty, - // this operation MUST return a null value, and otherwise it MUST return a - // SpanContext Shim instance with the extracted values. - SpanContextShim *context_shim = (!span_context.IsValid() && utils::isBaggageEmpty(baggage)) - ? nullptr - : new (std::nothrow) SpanContextShim(span_context, baggage); - + // The operation MUST return a `SpanContext` Shim instance with the extracted values if any of + // these conditions are met: + // * `SpanContext` is valid. + // * `SpanContext` is sampled. + // * `SpanContext` contains non-empty extracted `Baggage`. + // Otherwise, the operation MUST return null or empty value. + SpanContextShim *context_shim = + (!span_context.IsValid() && !span_context.IsSampled() && utils::isBaggageEmpty(baggage)) + ? nullptr + : new (std::nothrow) SpanContextShim(span_context, baggage); + + // Note: Invalid but sampled `SpanContext` instances are returned as a way to support + // jaeger-debug-id headers (https://github.com/jaegertracing/jaeger-client-java#via-http-headers) + // which are used to force propagation of debug information. return opentracing::make_expected(std::unique_ptr(context_shim)); } diff --git a/opentracing-shim/test/tracer_shim_test.cc b/opentracing-shim/test/tracer_shim_test.cc index 7a06175323..9d57bbcae4 100644 --- a/opentracing-shim/test/tracer_shim_test.cc +++ b/opentracing-shim/test/tracer_shim_test.cc @@ -211,6 +211,7 @@ TEST_F(TracerShimTest, ExtractOnlyBaggage) auto span_context_shim = static_cast(span_context.value().get()); ASSERT_TRUE(span_context_shim != nullptr); ASSERT_FALSE(span_context_shim->context().IsValid()); + ASSERT_FALSE(span_context_shim->context().IsSampled()); ASSERT_FALSE(shim::utils::isBaggageEmpty(span_context_shim->baggage())); std::string value; From ca08c5a34ad4af1b6b392c8bf5fc26a5210a2f2c Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:12:53 +0530 Subject: [PATCH 108/119] [BUILD] Fix exported definitions when building DLL with STL (#2387) --- CHANGELOG.md | 7 +++++++ ext/src/dll/opentelemetry_cpp.src | 10 ++++------ .../sdk/metrics/view/instrument_selector.h | 6 +++--- .../sdk/metrics/view/instrument_selector_factory.h | 7 ++++--- .../opentelemetry/sdk/metrics/view/meter_selector.h | 6 ++---- .../sdk/metrics/view/meter_selector_factory.h | 8 ++++---- sdk/src/metrics/view/instrument_selector_factory.cc | 4 ++-- sdk/src/metrics/view/meter_selector_factory.cc | 7 +++---- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a76b91692b..9acee42235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,13 @@ Breaking changes: * This header should not be included directly in an application. If this is the case, please remove any remaining include directives. +* [BUILD] Fix exported definitions when building DLL with STL + [#2387](https://github.com/open-telemetry/opentelemetry-cpp/pull/2387) + * The MeterSelector, MeterSelectorFactory, InstrumentSelector, + and InstrumentSelectorFactory APIs now use const std::string& + instead of nostd::string_view for name, version and schema to + maintain a single export definition for DLL. + ## [1.12.0] 2023-10-16 * [BUILD] Support `pkg-config` diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 49226ec543..10172dbb3f 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -72,11 +72,10 @@ EXPORTS ?Create@ViewFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@00W4AggregationType@2345@V?$shared_ptr@VAggregationConfig@metrics@sdk@v1@opentelemetry@@@7@@Z // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::ViewFactory::Create(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,enum opentelemetry::v1::sdk::metrics::AggregationType) ?Create@ViewFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@00W4AggregationType@2345@@Z - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterSelectorFactory::Create(class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view) - ?Create@MeterSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@Vstring_view@nostd@45@00@Z - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::InstrumentSelectorFactory::Create(enum opentelemetry::v1::sdk::metrics::InstrumentType,class opentelemetry::v1::nostd::string_view,class opentelemetry::v1::nostd::string_view) - ?Create@InstrumentSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@W4InstrumentType@2345@Vstring_view@nostd@45@1@Z - + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::MeterSelectorFactory::Create(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &) + ?Create@MeterSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@00@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::metrics::InstrumentSelectorFactory::Create(enum opentelemetry::v1::sdk::metrics::InstrumentType,class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &) + ?Create@InstrumentSelectorFactory@metrics@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@W4InstrumentType@2345@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@1@Z // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterContext::AddMetricReader(class std::shared_ptr) ?AddMetricReader@MeterContext@metrics@sdk@v1@opentelemetry@@QEAAXV?$shared_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@Z // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddMetricReader(class std::shared_ptr) @@ -84,7 +83,6 @@ EXPORTS // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddView(class std::unique_ptr >,class std::unique_ptr >,class std::unique_ptr >) ?AddView@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@7@V?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@7@@Z - #if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) ?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h index 67c8592bb6..690a9168d0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h @@ -4,8 +4,8 @@ #pragma once #include +#include -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/view/predicate_factory.h" #include "opentelemetry/version.h" @@ -19,8 +19,8 @@ class InstrumentSelector { public: InstrumentSelector(opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view units) + const std::string &name, + const std::string &units) : name_filter_{PredicateFactory::GetPredicate(name, PredicateType::kPattern)}, unit_filter_{PredicateFactory::GetPredicate(units, PredicateType::kExact)}, instrument_type_{instrument_type} 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 0af1efe04b..3c221f123b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector_factory.h @@ -3,7 +3,8 @@ #pragma once -#include "opentelemetry/nostd/string_view.h" +#include + #include "opentelemetry/sdk/metrics/instruments.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -19,8 +20,8 @@ class OPENTELEMETRY_EXPORT InstrumentSelectorFactory public: static std::unique_ptr Create( opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view unit); + const std::string &name, + const std::string &unit); }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h index 16d777b71f..65dba7d7b9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h @@ -4,8 +4,8 @@ #pragma once #include +#include -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/view/predicate_factory.h" #include "opentelemetry/version.h" @@ -17,9 +17,7 @@ namespace metrics class MeterSelector { public: - MeterSelector(opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view version, - opentelemetry::nostd::string_view schema) + MeterSelector(const std::string &name, const std::string &version, const std::string &schema) : name_filter_{PredicateFactory::GetPredicate(name, PredicateType::kExact)}, version_filter_{PredicateFactory::GetPredicate(version, PredicateType::kExact)}, schema_filter_{PredicateFactory::GetPredicate(schema, PredicateType::kExact)} 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 bd599d9c4b..47aa77b772 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector_factory.h @@ -4,8 +4,8 @@ #pragma once #include +#include -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -19,9 +19,9 @@ class MeterSelector; class OPENTELEMETRY_EXPORT MeterSelectorFactory { public: - static std::unique_ptr Create(opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view version, - opentelemetry::nostd::string_view schema); + static std::unique_ptr Create(const std::string &name, + const std::string &version, + const std::string &schema); }; } // namespace metrics diff --git a/sdk/src/metrics/view/instrument_selector_factory.cc b/sdk/src/metrics/view/instrument_selector_factory.cc index 98a587ea62..5cf4a5b968 100644 --- a/sdk/src/metrics/view/instrument_selector_factory.cc +++ b/sdk/src/metrics/view/instrument_selector_factory.cc @@ -13,8 +13,8 @@ namespace metrics std::unique_ptr InstrumentSelectorFactory::Create( opentelemetry::sdk::metrics::InstrumentType instrument_type, - opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view unit) + const std::string &name, + const std::string &unit) { std::unique_ptr instrument_selector( new InstrumentSelector(instrument_type, name, unit)); diff --git a/sdk/src/metrics/view/meter_selector_factory.cc b/sdk/src/metrics/view/meter_selector_factory.cc index f8f906d9ad..088dcd864e 100644 --- a/sdk/src/metrics/view/meter_selector_factory.cc +++ b/sdk/src/metrics/view/meter_selector_factory.cc @@ -11,10 +11,9 @@ namespace sdk namespace metrics { -std::unique_ptr MeterSelectorFactory::Create( - opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view version, - opentelemetry::nostd::string_view schema) +std::unique_ptr MeterSelectorFactory::Create(const std::string &name, + const std::string &version, + const std::string &schema) { std::unique_ptr meter_selector(new MeterSelector(name, version, schema)); return meter_selector; From 5bf2f8007f31cf0c0414c1c552edd1123c4cf018 Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Tue, 7 Nov 2023 01:12:59 +0530 Subject: [PATCH 109/119] [BUILD] Add missing includes to runtime_context_test (#2395) --- api/test/context/runtime_context_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/test/context/runtime_context_test.cc b/api/test/context/runtime_context_test.cc index e85fc6350d..40b11dde95 100644 --- a/api/test/context/runtime_context_test.cc +++ b/api/test/context/runtime_context_test.cc @@ -4,6 +4,9 @@ #include "opentelemetry/context/runtime_context.h" #include "opentelemetry/context/context.h" +#include +#include + #include using namespace opentelemetry; From 35a9362732216c00a24bdd4c98ebb5f9bbaab2c5 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 6 Nov 2023 23:27:16 +0100 Subject: [PATCH 110/119] [ADMIN] Add file .github/repository-settings.md (#2392) --- .github/repository-settings.md | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/repository-settings.md diff --git a/.github/repository-settings.md b/.github/repository-settings.md new file mode 100644 index 0000000000..fa86d02cfc --- /dev/null +++ b/.github/repository-settings.md @@ -0,0 +1,38 @@ +# Process + +This file documents local admin changes for opentelemetry-cpp, +per the community process: https://github.com/open-telemetry/community/blob/main/docs/how-to-configure-new-repository.md + +Please note that the EasyCLA check **MUST** stay **REQUIRED**, +it should never be disabled or bypassed, at the risk of tainting the repository. + +# Guidelines + +The best is to open a PR first that describes the change, +so it can be discussed during review (maybe it is not needed, +maybe there is an alternate solution, ...). + +The PR must add a log entry in this file, detailing: + +* the date the change is implemented +* what is changed exactly (which setting) +* a short rationale + +Admin changes are then applied only when the PR is merged. + +If for some reason a change is implemented in emergency, +before a PR can be discussed and merged, +a PR should still be prepared and pushed after the fact to +describe the settings changed. + +# Log of local changes + +## 2023-11-03 + +Created log file `.github/repository-settings.md`, since admin permissions are now granted to maintainers. + +See https://github.com/open-telemetry/community/issues/1727 + +No setting changed. + + From 86ee88615b813ea08901db029343847e77d0f38b Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Fri, 10 Nov 2023 01:53:12 -0800 Subject: [PATCH 111/119] [SDK] Fix GetLogger with empty library name (#2398) --- CHANGELOG.md | 2 ++ sdk/src/logs/logger_provider.cc | 21 +++++++++------------ sdk/test/logs/logger_provider_sdk_test.cc | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9acee42235..7317b2b5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ Increment the: [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) * [API] Add a new AddLink() operation to Span [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) +* [SDK] Fix GetLogger with empty library + name[#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398) Important changes: diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index d64863ed73..46eaa01054 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -57,6 +57,12 @@ nostd::shared_ptr LoggerProvider::GetLogger( 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 + if (library_name.empty()) + { + library_name = logger_name; + } + // Ensure only one thread can read/write from the map of loggers std::lock_guard lock_guard{lock_}; @@ -84,18 +90,9 @@ nostd::shared_ptr LoggerProvider::GetLogger( } */ - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-instrumentationscope - std::unique_ptr lib; - if (library_name.empty()) - { - lib = instrumentationscope::InstrumentationScope::Create(logger_name, library_version, - schema_url, attributes); - } - else - { - lib = instrumentationscope::InstrumentationScope::Create(library_name, library_version, - schema_url, attributes); - } + std::unique_ptr lib = + instrumentationscope::InstrumentationScope::Create(library_name, library_version, schema_url, + attributes); loggers_.push_back(std::shared_ptr( new Logger(logger_name, context_, std::move(lib)))); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 51f40178ba..ecb9ea6f9c 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -111,6 +111,20 @@ TEST(LoggerProviderSDK, EventLoggerProviderFactory) auto event_logger = elp->CreateEventLogger(logger1, "otel-cpp.test"); } +TEST(LoggerPviderSDK, LoggerEquityCheck) +{ + auto lp = std::shared_ptr(new LoggerProvider()); + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + + auto logger1 = lp->GetLogger("logger1", "opentelelemtry_library", "", schema_url); + auto logger2 = lp->GetLogger("logger1", "opentelelemtry_library", "", schema_url); + EXPECT_EQ(logger1, logger2); + + auto logger3 = lp->GetLogger("logger3"); + auto another_logger3 = lp->GetLogger("logger3"); + EXPECT_EQ(logger3, another_logger3); +} + class DummyLogRecordable final : public opentelemetry::sdk::logs::Recordable { public: From 63226075207c2807f61ae670355c1e705a4ce1d1 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Sat, 11 Nov 2023 18:20:51 +0800 Subject: [PATCH 112/119] [TEST] Fix compiling problem and removed -DENABLE_TEST (#2401) --- CMakeLists.txt | 1 - ci/do_ci.ps1 | 2 +- ci/do_ci.sh | 2 +- .../otlp/test/otlp_http_exporter_test.cc | 3 ++- .../otlp_http_log_record_exporter_test.cc | 3 ++- .../test/otlp_http_metric_exporter_test.cc | 3 ++- .../ext/http/client/curl/http_client_curl.h | 5 +--- .../ext/http/client/http_client_factory.h | 4 --- .../http/client/http_client_test_factory.h | 22 ++++++++++++++++ .../http/client/nosend/http_client_nosend.h | 26 +++++++++---------- test_common/src/http/client/nosend/BUILD | 2 +- .../src/http/client/nosend/CMakeLists.txt | 2 +- .../http/client/nosend/http_client_nosend.cc | 4 +-- ..._nosend.cc => http_client_test_factory.cc} | 10 +++---- 14 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h rename test_common/src/http/client/nosend/{http_client_factory_nosend.cc => http_client_test_factory.cc} (51%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b72e58a963..de5e714916 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -579,7 +579,6 @@ list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") include(CTest) if(BUILD_TESTING) - add_definitions(-DENABLE_TEST) if(EXISTS ${CMAKE_BINARY_DIR}/lib/libgtest.a) # Prefer GTest from build tree. GTest is not always working with # CMAKE_PREFIX_PATH diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index b97617e96f..0b6cd9513e 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -27,7 +27,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg" switch ($action) { "bazel.build" { - bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... + bazel build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit diff --git a/ci/do_ci.sh b/ci/do_ci.sh index d9dc0c178f..f679c6af04 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -69,7 +69,7 @@ fi echo "make command: ${MAKE_COMMAND}" echo "IWYU option: ${IWYU}" -BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" +BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT" BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 42258d2b45..1c76ad0d02 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -19,6 +19,7 @@ # include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include "opentelemetry/trace/provider.h" @@ -102,7 +103,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), http_client}; } 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 df89ca17fa..44fa812a35 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -22,6 +22,7 @@ # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include @@ -103,7 +104,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), http_client}; } diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index ed7c4dba30..8b7688adc0 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -24,6 +24,7 @@ #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" #include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" #include @@ -109,7 +110,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test static std::pair> GetMockOtlpHttpClient(HttpRequestContentType content_type, bool async_mode = false) { - auto http_client = http_client::HttpClientFactory::CreateNoSend(); + auto http_client = http_client::HttpClientTestFactory::Create(); return {new OtlpHttpClient(MakeOtlpHttpClientOptions(content_type, async_mode), http_client), 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 876d9fab4f..45ee13d55c 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 @@ -37,6 +37,7 @@ class HttpCurlGlobalInitializer HttpCurlGlobalInitializer(HttpCurlGlobalInitializer &&) = delete; HttpCurlGlobalInitializer &operator=(const HttpCurlGlobalInitializer &) = delete; + HttpCurlGlobalInitializer &operator=(HttpCurlGlobalInitializer &&) = delete; HttpCurlGlobalInitializer(); @@ -190,9 +191,7 @@ class Session : public opentelemetry::ext::http::client::Session, */ const std::string &GetBaseUri() const { return host_; } -#ifdef ENABLE_TEST std::shared_ptr GetRequest() { return http_request_; } -#endif inline HttpClient &GetHttpClient() noexcept { return http_client_; } inline const HttpClient &GetHttpClient() const noexcept { return http_client_; } @@ -327,7 +326,6 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient void ScheduleAbortSession(uint64_t session_id); void ScheduleRemoveSession(uint64_t session_id, HttpCurlEasyResource &&resource); -#ifdef ENABLE_TEST void WaitBackgroundThreadExit() { std::unique_ptr background_thread; @@ -341,7 +339,6 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient background_thread->join(); } } -#endif private: void wakeupBackgroundThread(); diff --git a/ext/include/opentelemetry/ext/http/client/http_client_factory.h b/ext/include/opentelemetry/ext/http/client/http_client_factory.h index 8df1e578d2..43e15cf255 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client_factory.h +++ b/ext/include/opentelemetry/ext/http/client/http_client_factory.h @@ -17,10 +17,6 @@ class HttpClientFactory static std::shared_ptr CreateSync(); static std::shared_ptr Create(); - -#ifdef ENABLE_TEST - static std::shared_ptr CreateNoSend(); -#endif }; } // namespace client } // namespace http 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 new file mode 100644 index 0000000000..51f9502bb8 --- /dev/null +++ b/test_common/include/opentelemetry/test_common/ext/http/client/http_client_test_factory.h @@ -0,0 +1,22 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#include "opentelemetry/ext/http/client/http_client.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace ext +{ +namespace http +{ +namespace client +{ +class HttpClientTestFactory +{ +public: + static std::shared_ptr Create(); +}; +} // namespace client +} // namespace http +} // namespace ext +OPENTELEMETRY_END_NAMESPACE 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 7a6fadbd11..7dddde13d4 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,17 +3,16 @@ #pragma once -#ifdef ENABLE_TEST -# include "opentelemetry/ext/http/client/http_client.h" -# include "opentelemetry/ext/http/common/url_parser.h" -# include "opentelemetry/version.h" +#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 "gmock/gmock.h" +#include +#include "gmock/gmock.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext @@ -37,12 +36,12 @@ class Request : public opentelemetry::ext::http::client::Request method_ = method; } -# ifdef ENABLE_HTTP_SSL_PREVIEW +#ifdef ENABLE_HTTP_SSL_PREVIEW void SetSslOptions(const HttpSslOptions &ssl_options) noexcept override { ssl_options_ = ssl_options; } -# endif /* ENABLE_HTTP_SSL_PREVIEW */ +#endif /* ENABLE_HTTP_SSL_PREVIEW */ void SetBody(opentelemetry::ext::http::client::Body &body) noexcept override { @@ -66,9 +65,9 @@ class Request : public opentelemetry::ext::http::client::Request public: opentelemetry::ext::http::client::Method method_; -# ifdef ENABLE_HTTP_SSL_PREVIEW +#ifdef ENABLE_HTTP_SSL_PREVIEW opentelemetry::ext::http::client::HttpSslOptions ssl_options_; -# endif /* ENABLE_HTTP_SSL_PREVIEW */ +#endif /* ENABLE_HTTP_SSL_PREVIEW */ opentelemetry::ext::http::client::Body body_; opentelemetry::ext::http::client::Headers headers_; std::string uri_; @@ -186,4 +185,3 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient } // namespace http } // namespace ext OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/test_common/src/http/client/nosend/BUILD b/test_common/src/http/client/nosend/BUILD index 7aaf2a61b5..fa7ba623ab 100644 --- a/test_common/src/http/client/nosend/BUILD +++ b/test_common/src/http/client/nosend/BUILD @@ -6,8 +6,8 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "http_client_nosend", srcs = [ - "http_client_factory_nosend.cc", "http_client_nosend.cc", + "http_client_test_factory.cc", ], include_prefix = "src/http/client/nosend", tags = [ diff --git a/test_common/src/http/client/nosend/CMakeLists.txt b/test_common/src/http/client/nosend/CMakeLists.txt index 1f32861b41..92a2c1f98c 100644 --- a/test_common/src/http/client/nosend/CMakeLists.txt +++ b/test_common/src/http/client/nosend/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 if(${BUILD_TESTING}) - add_library(opentelemetry_http_client_nosend http_client_factory_nosend.cc + add_library(opentelemetry_http_client_nosend http_client_test_factory.cc http_client_nosend.cc) set_target_properties(opentelemetry_http_client_nosend 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 dd14e4404a..98cae0476a 100644 --- a/test_common/src/http/client/nosend/http_client_nosend.cc +++ b/test_common/src/http/client/nosend/http_client_nosend.cc @@ -1,8 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_TEST -# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace ext @@ -96,4 +95,3 @@ void HttpClient::CleanupSession(uint64_t /* session_id */) {} } // namespace http } // namespace ext OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/test_common/src/http/client/nosend/http_client_factory_nosend.cc b/test_common/src/http/client/nosend/http_client_test_factory.cc similarity index 51% rename from test_common/src/http/client/nosend/http_client_factory_nosend.cc rename to test_common/src/http/client/nosend/http_client_test_factory.cc index c70d1b9578..215c173549 100644 --- a/test_common/src/http/client/nosend/http_client_factory_nosend.cc +++ b/test_common/src/http/client/nosend/http_client_test_factory.cc @@ -1,15 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifdef ENABLE_TEST -# include "opentelemetry/ext/http/client/http_client.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" +#include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" namespace http_client = opentelemetry::ext::http::client; -std::shared_ptr http_client::HttpClientFactory::CreateNoSend() +std::shared_ptr http_client::HttpClientTestFactory::Create() { return std::make_shared(); } -#endif From 5bd9c65c64e402bf17f73528693a9b4afe5aed2f Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Sun, 12 Nov 2023 12:07:11 -0800 Subject: [PATCH 113/119] [BUILD] Check windows options are not passed to non-Windows build (#2399) --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index de5e714916..f795eadbb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,10 @@ set(OTELCPP_PROTO_PATH if(WIN32) option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON) +else() + if(DEFINED (WITH_ETW)) + message(FATAL_ERROR "WITH_ETW is only supported on Windows") + endif() endif(WIN32) # Do not convert deprecated message to error @@ -628,6 +632,9 @@ endif() include(CMakePackageConfigHelpers) if(DEFINED OPENTELEMETRY_BUILD_DLL) + if(NOT WIN32) + message(FATAL_ERROR "Build DLL is only supported on Windows!") + endif() if(NOT MSVC) message(WARNING "Build DLL is supposed to work with MSVC!") endif() From 3dfcf93c41bb1d487b3d4d1291791ea21a2a38ce Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 13 Nov 2023 23:27:29 +0100 Subject: [PATCH 114/119] [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options (#2388) --- CHANGELOG.md | 28 ++- examples/otlp/grpc_log_main.cc | 14 +- exporters/otlp/BUILD | 30 ++- exporters/otlp/CMakeLists.txt | 35 ++- .../exporters/otlp/otlp_grpc_client.h | 14 +- .../exporters/otlp/otlp_grpc_client_options.h | 58 +++++ .../otlp/otlp_grpc_exporter_options.h | 44 +--- .../otlp/otlp_grpc_log_record_exporter.h | 6 +- .../otlp_grpc_log_record_exporter_factory.h | 4 +- .../otlp_grpc_log_record_exporter_options.h | 31 +++ .../otlp/otlp_grpc_metric_exporter.h | 2 +- .../otlp/otlp_grpc_metric_exporter_options.h | 21 +- .../otlp/otlp_http_exporter_options.h | 98 ++++---- .../otlp_http_log_record_exporter_options.h | 98 ++++---- .../otlp/otlp_http_metric_exporter_options.h | 100 +++++---- exporters/otlp/src/otlp_grpc_client.cc | 10 +- .../otlp/src/otlp_grpc_exporter_options.cc | 38 ++++ .../otlp/src/otlp_grpc_log_record_exporter.cc | 7 +- .../otlp_grpc_log_record_exporter_factory.cc | 6 +- .../otlp_grpc_log_record_exporter_options.cc | 36 +++ .../src/otlp_grpc_metric_exporter_options.cc | 38 ++++ .../otlp/src/otlp_http_exporter_options.cc | 54 +++++ .../otlp_http_log_record_exporter_options.cc | 54 +++++ .../src/otlp_http_metric_exporter_options.cc | 55 +++++ ...p_grpc_log_record_exporter_factory_test.cc | 4 +- .../otlp_grpc_log_record_exporter_test.cc | 3 +- .../test/otlp_grpc_metric_exporter_test.cc | 209 ++++++++++++++++++ ext/src/dll/opentelemetry_cpp.src | 70 +++--- 28 files changed, 945 insertions(+), 222 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h create mode 100644 exporters/otlp/src/otlp_grpc_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_grpc_metric_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_http_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_http_log_record_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_http_metric_exporter_options.cc create mode 100644 exporters/otlp/test/otlp_grpc_metric_exporter_test.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index 7317b2b5f1..2f89ef1505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,8 +25,10 @@ Increment the: [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) * [API] Add a new AddLink() operation to Span [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) -* [SDK] Fix GetLogger with empty library - name[#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398) +* [SDK] Fix GetLogger with empty library name + [#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398) +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) Important changes: @@ -56,6 +58,14 @@ Important changes: * These build options are scheduled to be removed by the next release, building without SSL/TLS will no longer be possible. +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) + * `OtlpGrpcMetricExporterOptions` used to honor `_TRACES_` + environment variables, instead of `_METRICS_` environment variables. + * The implementation of `OtlpGrpcMetricExporterOptions` is now fixed. + * Please check configuration variables, + to make sure `_METRICS_` variables are set as expected. + Breaking changes: * [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead @@ -77,6 +87,20 @@ Breaking changes: instead of nostd::string_view for name, version and schema to maintain a single export definition for DLL. +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) + * `OtlpGrpcLogRecordExporter` incorrectly used `OtlpGrpcExporterOptions`, + which are options for traces and not logs. + * This created a bug: the `OtlpGrpcLogRecordExporter` honors `_TRACES_` + environment variables, instead of `_LOGS_` environment variables. + * `OtlpGrpcLogRecordExporter` is changed to use + `OtlpGrpcLogRecordExporterOptions` instead, fixing the bug. + * User code that initializes the SDK with a GRPC Log exporter, + and uses exporter options, should adjust to replace + `OtlpGrpcExporterOptions` with `OtlpGrpcLogRecordExporterOptions`. + * Please check configuration variables, + to make sure `_LOGS_` variables are set as expected. + ## [1.12.0] 2023-10-16 * [BUILD] Support `pkg-config` diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index b1726de358..9d7399dbaf 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/logs/provider.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" @@ -37,6 +39,7 @@ namespace trace_sdk = opentelemetry::sdk::trace; namespace { opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; +opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterOptions log_opts; void InitTracer() { // Create OTLP exporter instance @@ -65,7 +68,7 @@ void CleanupTracer() void InitLogger() { // Create OTLP exporter instance - auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(opts); + auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(log_opts); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); nostd::shared_ptr provider( logs_sdk::LoggerProviderFactory::Create(std::move(processor))); @@ -92,11 +95,14 @@ int main(int argc, char *argv[]) { if (argc > 1) { - opts.endpoint = argv[1]; + opts.endpoint = argv[1]; + log_opts.endpoint = argv[1]; if (argc > 2) { - opts.use_ssl_credentials = true; - opts.ssl_credentials_cacert_path = argv[2]; + opts.use_ssl_credentials = true; + log_opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_path = argv[2]; + log_opts.ssl_credentials_cacert_path = argv[2]; } } InitLogger(); diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 5099b43510..a70153edd8 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -47,7 +47,7 @@ cc_library( hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", @@ -73,9 +73,11 @@ cc_library( srcs = [ "src/otlp_grpc_exporter.cc", "src/otlp_grpc_exporter_factory.cc", + "src/otlp_grpc_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", @@ -143,6 +145,7 @@ cc_library( srcs = [ "src/otlp_http_exporter.cc", "src/otlp_http_exporter_factory.cc", + "src/otlp_http_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -170,10 +173,11 @@ cc_library( srcs = [ "src/otlp_grpc_metric_exporter.cc", "src/otlp_grpc_metric_exporter_factory.cc", + "src/otlp_grpc_metric_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h", @@ -201,6 +205,7 @@ cc_library( srcs = [ "src/otlp_http_metric_exporter.cc", "src/otlp_http_metric_exporter_factory.cc", + "src/otlp_http_metric_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -228,6 +233,7 @@ cc_library( srcs = [ "src/otlp_http_log_record_exporter.cc", "src/otlp_http_log_record_exporter_factory.cc", + "src/otlp_http_log_record_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -255,12 +261,14 @@ cc_library( srcs = [ "src/otlp_grpc_log_record_exporter.cc", "src/otlp_grpc_log_record_exporter_factory.cc", + "src/otlp_grpc_log_record_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -436,6 +444,22 @@ cc_test( ], ) +cc_test( + name = "otlp_grpc_metric_exporter_test", + srcs = ["test/otlp_grpc_metric_exporter_test.cc"], + tags = [ + "otlp", + "otlp_grpc_metric", + "test", + ], + deps = [ + ":otlp_grpc_metric_exporter", + "//api", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "otlp_grpc_metric_exporter_factory_test", srcs = ["test/otlp_grpc_metric_exporter_factory_test.cc"], diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index adab87ff02..ec55211a6d 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -56,8 +56,10 @@ if(WITH_OTLP_GRPC) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_client) - add_library(opentelemetry_exporter_otlp_grpc - src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc) + add_library( + opentelemetry_exporter_otlp_grpc + src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc + src/otlp_grpc_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc PROPERTIES EXPORT_NAME otlp_grpc_exporter) @@ -73,7 +75,8 @@ if(WITH_OTLP_GRPC) add_library( opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_record_exporter.cc - src/otlp_grpc_log_record_exporter_factory.cc) + src/otlp_grpc_log_record_exporter_factory.cc + src/otlp_grpc_log_record_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_record_exporter) @@ -88,7 +91,8 @@ if(WITH_OTLP_GRPC) add_library( opentelemetry_exporter_otlp_grpc_metrics - src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc) + src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc + src/otlp_grpc_metric_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_metrics PROPERTIES EXPORT_NAME otlp_grpc_metrics_exporter) @@ -130,8 +134,10 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_client) - add_library(opentelemetry_exporter_otlp_http - src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc) + add_library( + opentelemetry_exporter_otlp_http + src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc + src/otlp_http_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http PROPERTIES EXPORT_NAME otlp_http_exporter) @@ -147,7 +153,8 @@ if(WITH_OTLP_HTTP) add_library( opentelemetry_exporter_otlp_http_log src/otlp_http_log_record_exporter.cc - src/otlp_http_log_record_exporter_factory.cc) + src/otlp_http_log_record_exporter_factory.cc + src/otlp_http_log_record_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http_log PROPERTIES EXPORT_NAME otlp_http_log_record_exporter) @@ -162,7 +169,8 @@ if(WITH_OTLP_HTTP) add_library( opentelemetry_exporter_otlp_http_metric - src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc) + src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc + src/otlp_http_metric_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http_metric PROPERTIES EXPORT_NAME otlp_http_metric_exporter) @@ -295,6 +303,17 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_record_exporter_factory_test) + add_executable(otlp_grpc_metric_exporter_test + test/otlp_grpc_metric_exporter_test.cc) + target_link_libraries( + otlp_grpc_metric_exporter_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc + opentelemetry_exporter_otlp_grpc_metrics) + gtest_add_tests( + TARGET otlp_grpc_metric_exporter_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_metric_exporter_test) + add_executable(otlp_grpc_metric_exporter_factory_test test/otlp_grpc_metric_exporter_factory_test.cc) target_link_libraries( diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h index 7998bd2646..fa1a69d619 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -7,7 +7,7 @@ #include -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" @@ -23,6 +23,8 @@ namespace exporter namespace otlp { +struct OtlpGrpcClientOptions; + /** * The OTLP gRPC client contains utility functions of gRPC. */ @@ -32,13 +34,13 @@ class OtlpGrpcClient /** * Create gRPC channel from the exporter options. */ - static std::shared_ptr MakeChannel(const OtlpGrpcExporterOptions &options); + static std::shared_ptr MakeChannel(const OtlpGrpcClientOptions &options); /** * Create gRPC client context to call RPC. */ static std::unique_ptr MakeClientContext( - const OtlpGrpcExporterOptions &options); + const OtlpGrpcClientOptions &options); /** * Create gRPC CompletionQueue to async call RPC. @@ -49,19 +51,19 @@ class OtlpGrpcClient * Create trace service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeTraceServiceStub(const OtlpGrpcExporterOptions &options); + MakeTraceServiceStub(const OtlpGrpcClientOptions &options); /** * Create metrics service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options); + MakeMetricsServiceStub(const OtlpGrpcClientOptions &options); /** * Create logs service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeLogsServiceStub(const OtlpGrpcExporterOptions &options); + MakeLogsServiceStub(const OtlpGrpcClientOptions &options); static grpc::Status DelegateExport( proto::collector::trace::v1::TraceService::StubInterface *stub, diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h new file mode 100644 index 0000000000..310fc94d4d --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/version.h" + +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +struct OtlpGrpcClientOptions +{ + /** The endpoint to export to. */ + std::string endpoint; + + /** Use SSL. */ + bool use_ssl_credentials; + + /** CA CERT, path to a file. */ + std::string ssl_credentials_cacert_path; + + /** CA CERT, as a string. */ + std::string ssl_credentials_cacert_as_string; + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; + + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; + + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; +#endif + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders metadata; + + /** User agent. */ + std::string user_agent; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h index 01ac5b43f2..b2556f1f76 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h @@ -3,9 +3,8 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_environment.h" - -#include +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -15,38 +14,17 @@ namespace otlp /** * Struct to hold OTLP GRPC traces exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpGrpcExporterOptions +struct OPENTELEMETRY_EXPORT OtlpGrpcExporterOptions : public OtlpGrpcClientOptions { - // The endpoint to export to. By default the OpenTelemetry Collector's default endpoint. - std::string endpoint = GetOtlpDefaultGrpcEndpoint(); - // By default when false, uses grpc::InsecureChannelCredentials(); If true, - // uses ssl_credentials_cacert_path if non-empty, else uses ssl_credentials_cacert_as_string - bool use_ssl_credentials = GetOtlpDefaultIsSslEnable(); - // ssl_credentials_cacert_path specifies path to .pem file to be used for SSL encryption. - std::string ssl_credentials_cacert_path = GetOtlpDefaultSslCertificatePath(); - // ssl_credentials_cacert_as_string in-memory string representation of .pem file to be used for - // SSL encryption. - std::string ssl_credentials_cacert_as_string = GetOtlpDefaultSslCertificateString(); - -#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW - // At most one of ssl_client_key_* should be non-empty. If use_ssl_credentials, they will - // be read to allow for mTLS. - std::string ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); - - // At most one of ssl_client_cert_* should be non-empty. If use_ssl_credentials, they will - // be read to allow for mTLS. - std::string ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); -#endif - - // Timeout for grpc deadline - std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout(); - // Additional HTTP headers - OtlpHeaders metadata = GetOtlpDefaultHeaders(); - // User agent - std::string user_agent = GetOtlpDefaultUserAgent(); + OtlpGrpcExporterOptions(); + ~OtlpGrpcExporterOptions(); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h index 33476297cb..29333703b1 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h @@ -13,7 +13,7 @@ // clang-format on #include "opentelemetry/exporters/otlp/otlp_environment.h" -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -37,7 +37,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo * Create an OtlpGrpcLogRecordExporter with user specified options. * @param options An object containing the user's configuration options. */ - OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options); + OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options); /** * Creates a recordable that stores the data in protobuf. @@ -71,7 +71,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo private: // Configuration options for the exporter - const OtlpGrpcExporterOptions options_; + const OtlpGrpcLogRecordExporterOptions options_; // For testing friend class OtlpGrpcLogRecordExporterTestPeer; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h index 5f81e60f2e..7a88615959 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h @@ -3,7 +3,7 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -27,7 +27,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory * Create a OtlpGrpcLogRecordExporter. */ static std::unique_ptr Create( - const OtlpGrpcExporterOptions &options); + const OtlpGrpcLogRecordExporterOptions &options); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h new file mode 100644 index 0000000000..cc1a199c4b --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Struct to hold OTLP GRPC log record exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md + */ +struct OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterOptions : public OtlpGrpcClientOptions +{ + OtlpGrpcLogRecordExporterOptions(); + ~OtlpGrpcLogRecordExporterOptions(); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 11bb64c24f..5f975c8ce3 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -63,7 +63,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_; // For testing - friend class OtlpGrpcExporterTestPeer; + friend class OtlpGrpcMetricExporterTestPeer; // Store service stub internally. Useful for testing. std::unique_ptr diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h index a56cf8cb55..22be580972 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h @@ -3,11 +3,9 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" #include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" -#include "opentelemetry/sdk/metrics/instruments.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -17,13 +15,20 @@ namespace otlp /** * Struct to hold OTLP GRPC metrics exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions +struct OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterOptions : public OtlpGrpcClientOptions { + OtlpGrpcMetricExporterOptions(); + ~OtlpGrpcMetricExporterOptions(); - // Preferred Aggregation Temporality - PreferredAggregationTemporality aggregation_temporality = - PreferredAggregationTemporality::kCumulative; + /** Preferred Aggregation Temporality. */ + PreferredAggregationTemporality aggregation_temporality; }; } // namespace otlp 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 29b4b76ec0..9200a506b8 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,9 +3,9 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_http.h" - #include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/version.h" #include #include @@ -20,65 +20,89 @@ namespace otlp /** * Struct to hold OTLP HTTP traces exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultHttpEndpoint(); + OtlpHttpExporterOptions(); + ~OtlpHttpExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultHeaders(); + /** Print debug messages. */ + bool console_debug; + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; - std::string ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString(); + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; + + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; #endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultTracesSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultTracesSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; 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 65fd2b9b63..e2a6264675 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 @@ -5,7 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" -#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" #include #include @@ -19,66 +19,90 @@ namespace otlp { /** - * Struct to hold OTLP HTTP logs exporter options. + * Struct to hold OTLP HTTP log record exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpLogRecordExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultHttpLogsEndpoint(); + OtlpHttpLogRecordExporterOptions(); + ~OtlpHttpLogRecordExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - std::chrono::system_clock::duration timeout = GetOtlpDefaultLogsTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultLogsHeaders(); + /** Print debug messages. */ + bool console_debug; + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; + + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; - std::string ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; #endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; 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 8aa0ccad21..38446be73b 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 @@ -6,6 +6,7 @@ #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 @@ -20,70 +21,91 @@ namespace otlp /** * Struct to hold OTLP HTTP metrics exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpMetricExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpMetricExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultMetricsEndpoint(); + OtlpHttpMetricExporterOptions(); + ~OtlpHttpMetricExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - // TODO: Enable/disable to verify SSL certificate - std::chrono::system_clock::duration timeout = GetOtlpDefaultMetricsTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultMetricsHeaders(); + /** Print debug messages. */ + bool console_debug; - // Preferred Aggregation Temporality - PreferredAggregationTemporality aggregation_temporality = - PreferredAggregationTemporality::kCumulative; + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; + + PreferredAggregationTemporality aggregation_temporality; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; + + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; - std::string ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; #endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultMetricsSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultMetricsSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 625781025e..c0436eddaf 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -48,7 +48,7 @@ static std::string GetFileContentsOrInMemoryContents(const std::string &file_pat } // namespace -std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporterOptions &options) +std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcClientOptions &options) { std::shared_ptr channel; @@ -94,7 +94,7 @@ std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporte } std::unique_ptr OtlpGrpcClient::MakeClientContext( - const OtlpGrpcExporterOptions &options) + const OtlpGrpcClientOptions &options) { std::unique_ptr context{new grpc::ClientContext()}; if (!context) @@ -121,19 +121,19 @@ std::unique_ptr OtlpGrpcClient::MakeCompletionQueue() } std::unique_ptr -OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::trace::v1::TraceService::NewStub(MakeChannel(options)); } std::unique_ptr -OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options)); } std::unique_ptr -OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options)); } diff --git a/exporters/otlp/src/otlp_grpc_exporter_options.cc b/exporters/otlp/src/otlp_grpc_exporter_options.cc new file mode 100644 index 0000000000..3099303ac4 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_exporter_options.cc @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcExporterOptions::OtlpGrpcExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcTracesEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcTracesIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultTracesSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultTracesSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultTracesTimeout(); + metadata = GetOtlpDefaultTracesHeaders(); + user_agent = GetOtlpDefaultUserAgent(); +} + +OtlpGrpcExporterOptions::~OtlpGrpcExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index 01367da886..2b397262b0 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -30,16 +30,17 @@ namespace otlp // -------------------------------- Constructors -------------------------------- OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter() - : OtlpGrpcLogRecordExporter(OtlpGrpcExporterOptions()) + : OtlpGrpcLogRecordExporter(OtlpGrpcLogRecordExporterOptions()) {} -OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options) +OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( + const OtlpGrpcLogRecordExporterOptions &options) : options_(options), log_service_stub_(OtlpGrpcClient::MakeLogsServiceStub(options)) {} OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( std::unique_ptr stub) - : options_(OtlpGrpcExporterOptions()), log_service_stub_(std::move(stub)) + : options_(OtlpGrpcLogRecordExporterOptions()), log_service_stub_(std::move(stub)) {} // ----------------------------- Exporter methods ------------------------------ diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc index b36eefa6cb..7229de569a 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -4,8 +4,8 @@ // MUST be first (absl) #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -16,12 +16,12 @@ namespace otlp std::unique_ptr OtlpGrpcLogRecordExporterFactory::Create() { - OtlpGrpcExporterOptions options; + OtlpGrpcLogRecordExporterOptions options; return Create(options); } std::unique_ptr -OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcExporterOptions &options) +OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions &options) { std::unique_ptr exporter( new OtlpGrpcLogRecordExporter(options)); diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc new file mode 100644 index 0000000000..697ef28f2a --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcLogRecordExporterOptions::OtlpGrpcLogRecordExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcLogsEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcLogsIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultLogsSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultLogsSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultLogsTimeout(); + metadata = GetOtlpDefaultLogsHeaders(); + user_agent = GetOtlpDefaultUserAgent(); +} + +OtlpGrpcLogRecordExporterOptions::~OtlpGrpcLogRecordExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc new file mode 100644 index 0000000000..cb99d1cc5a --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcMetricsEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcMetricsIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultMetricsSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultMetricsSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultMetricsTimeout(); + metadata = GetOtlpDefaultMetricsHeaders(); + user_agent = GetOtlpDefaultUserAgent(); + + aggregation_temporality = PreferredAggregationTemporality::kCumulative; +} + +OtlpGrpcMetricExporterOptions::~OtlpGrpcMetricExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_exporter_options.cc b/exporters/otlp/src/otlp_http_exporter_options.cc new file mode 100644 index 0000000000..91121e0c35 --- /dev/null +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -0,0 +1,54 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" + +#include +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpExporterOptions::OtlpHttpExporterOptions() +{ + url = GetOtlpDefaultHttpTracesEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultTracesTimeout(); + http_headers = GetOtlpDefaultTracesHeaders(); + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif /* ENABLE_ASYNC_EXPORT */ + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + 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(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultTracesSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultTracesSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpExporterOptions::~OtlpHttpExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc new file mode 100644 index 0000000000..bda37b9730 --- /dev/null +++ b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc @@ -0,0 +1,54 @@ +// 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 + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions() +{ + url = GetOtlpDefaultHttpLogsEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultLogsTimeout(); + http_headers = GetOtlpDefaultLogsHeaders(); + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + 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(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpLogRecordExporterOptions::~OtlpHttpLogRecordExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_metric_exporter_options.cc b/exporters/otlp/src/otlp_http_metric_exporter_options.cc new file mode 100644 index 0000000000..4dc0f40631 --- /dev/null +++ b/exporters/otlp/src/otlp_http_metric_exporter_options.cc @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" + +#include +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions() +{ + url = GetOtlpDefaultMetricsEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultMetricsTimeout(); + http_headers = GetOtlpDefaultMetricsHeaders(); + aggregation_temporality = PreferredAggregationTemporality::kCumulative; + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + 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(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultMetricsSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultMetricsSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpMetricExporterOptions::~OtlpHttpMetricExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc index 2cc534277d..cb1d1849aa 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc @@ -3,8 +3,8 @@ #include -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" /* Make sure OtlpGrpcLogRecordExporterFactory does not require, @@ -22,7 +22,7 @@ namespace otlp TEST(OtlpGrpcLogRecordExporterFactoryTest, BuildTest) { - OtlpGrpcExporterOptions opts; + OtlpGrpcLogRecordExporterOptions opts; opts.endpoint = "localhost:45454"; std::unique_ptr exporter = 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 547d21d056..6a31639219 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -59,7 +59,8 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test } // Get the options associated with the given exporter. - const OtlpGrpcExporterOptions &GetOptions(std::unique_ptr &exporter) + const OtlpGrpcLogRecordExporterOptions &GetOptions( + std::unique_ptr &exporter) { return exporter->options_; } diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc new file mode 100644 index 0000000000..dc6dde9d79 --- /dev/null +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc @@ -0,0 +1,209 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTELEMETRY_STL_VERSION +// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. +// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. +// +// Please refer to this GitHub issue for additional details: +// https://github.com/google/googletest/issues/2914 +// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f +// +// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, +// then the compilation here fails in `gmock-actions.h` from: +// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): +// error C2653: 'result_of': is not a class or namespace name +// +// That is because `std::result_of` has been removed in C++20. + +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" + +// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : +# include "opentelemetry/proto/collector/metrics/v1/metrics_service_mock.grpc.pb.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" + +# include "opentelemetry/sdk/trace/simple_processor.h" +# include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/trace/provider.h" + +# include + +# if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" +using opentelemetry::sdk::common::setenv; +using opentelemetry::sdk::common::unsetenv; +# endif + +using namespace testing; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OtlpGrpcMetricExporterTestPeer : public ::testing::Test +{ +public: + std::unique_ptr GetExporter( + std::unique_ptr &stub_interface) + { + return std::unique_ptr( + new OtlpGrpcMetricExporter(std::move(stub_interface))); + } + + // Get the options associated with the given exporter. + const OtlpGrpcMetricExporterOptions &GetOptions(std::unique_ptr &exporter) + { + return exporter->options_; + } +}; + +// Test exporter configuration options +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigTest) +{ + OtlpGrpcMetricExporterOptions opts; + opts.endpoint = "localhost:45454"; + std::unique_ptr exporter(new OtlpGrpcMetricExporter(opts)); + EXPECT_EQ(GetOptions(exporter).endpoint, "localhost:45454"); +} + +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigSslCredentialsTest) +{ + std::string cacert_str = "--begin and end fake cert--"; + OtlpGrpcMetricExporterOptions opts; + opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_as_string = cacert_str; + std::unique_ptr exporter(new OtlpGrpcMetricExporter(opts)); + EXPECT_EQ(GetOptions(exporter).ssl_credentials_cacert_as_string, cacert_str); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); +} + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigFromEnv) +{ + const std::string cacert_str = "--begin and end fake cert--"; + setenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING", cacert_str.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_SSL_ENABLE", "True", 1); + const std::string endpoint = "https://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20050ms", 1); + setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_HEADERS", "k1=v3,k1=v4", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).ssl_credentials_cacert_as_string, cacert_str); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + EXPECT_EQ(GetOptions(exporter).timeout.count(), + std::chrono::duration_cast( + std::chrono::milliseconds{20050}) + .count()); + EXPECT_EQ(GetOptions(exporter).metadata.size(), 3); + { + // Test k2 + auto range = GetOptions(exporter).metadata.equal_range("k2"); + EXPECT_TRUE(range.first != range.second); + EXPECT_EQ(range.first->second, std::string("v2")); + ++range.first; + EXPECT_TRUE(range.first == range.second); + } + { + // Test k1 + auto range = GetOptions(exporter).metadata.equal_range("k1"); + EXPECT_TRUE(range.first != range.second); + EXPECT_EQ(range.first->second, std::string("v3")); + ++range.first; + EXPECT_EQ(range.first->second, std::string("v4")); + ++range.first; + EXPECT_TRUE(range.first == range.second); + } + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING"); + unsetenv("OTEL_EXPORTER_OTLP_SSL_ENABLE"); + unsetenv("OTEL_EXPORTER_OTLP_TIMEOUT"); + unsetenv("OTEL_EXPORTER_OTLP_HEADERS"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_HEADERS"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigHttpsSecureFromEnv) +{ + // https takes precedence over insecure + const std::string endpoint = "https://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "true", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigHttpInsecureFromEnv) +{ + // http takes precedence over secure + const std::string endpoint = "http://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "false", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, false); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigUnknownSecureFromEnv) +{ + const std::string endpoint = "localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "false", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigUnknownInsecureFromEnv) +{ + const std::string endpoint = "localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "true", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, false); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 10172dbb3f..195b30640a 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -14,22 +14,6 @@ EXPORTS #endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::TracerProviderFactory::Create(class std::unique_ptr >) ?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VTracerProvider@trace@v1@opentelemetry@@U?$default_delete@VTracerProvider@trace@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@7@@Z -#if defined(WITH_OTLP_GRPC) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) -#if defined(_WIN64) - ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z -#else - ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpGrpcExporterOptions@2345@@Z -#endif // defined(_WIN64) -#endif // defined(WITH_OTLP_GRPC) -#if defined(WITH_OTLP_HTTP) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) -#if defined(_WIN64) - ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z -#else - ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpHttpExporterOptions@2345@@Z -#endif // defined(_WIN64) -#endif // defined(WITH_OTLP_HTTP) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) #if defined(_WIN64) ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z @@ -82,7 +66,6 @@ EXPORTS ?AddMetricReader@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$shared_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@Z // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddView(class std::unique_ptr >,class std::unique_ptr >,class std::unique_ptr >) ?AddView@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@7@V?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@7@@Z - #if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) ?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ @@ -90,26 +73,63 @@ EXPORTS ?GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ ?GetOtlpDefaultMetricsTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultMetricsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ + ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultMetricsSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultLogsSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultMetricsSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultLogsSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) #if defined(WITH_OTLP_GRPC) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) - ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) + ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions const & __ptr64) ?Create@OtlpGrpcMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcMetricExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions const &) + ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcLogRecordExporterOptions@2345@@Z + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions::OtlpGrpcExporterOptions(void) + ??0OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions::~OtlpGrpcExporterOptions(void) + ??1OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions(void) + ??0OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions::~OtlpGrpcMetricExporterOptions(void) + ??1OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions::OtlpGrpcLogRecordExporterOptions(void) + ??0OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions::~OtlpGrpcLogRecordExporterOptions(void) + ??1OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ ?GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcMetricsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ - ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ - ?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcMetricsIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ + ?GetOtlpDefaultGrpcLogsIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ #endif // defined(WITH_OTLP_GRPC) + #if defined(WITH_OTLP_HTTP) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) + ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions const &) + ?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpMetricExporterOptions@2345@@Z // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions const & __ptr64) ?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpLogRecordExporterOptions@2345@@Z - ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ - ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions::OtlpHttpExporterOptions(void) + ??0OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions::~OtlpHttpExporterOptions(void) + ??1OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions(void) + ??0OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions::~OtlpHttpMetricExporterOptions(void) + ??1OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions(void) + ??0OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions::~OtlpHttpLogRecordExporterOptions(void) + ??1OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions const &) - ?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpMetricExporterOptions@2345@@Z + ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultHttpMetricsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_HTTP) // clang-format on From cb603ad97f33e52340e627e1cb43ba73bb1d7ef0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Nov 2023 21:53:05 -0800 Subject: [PATCH 115/119] Bump actions/github-script from 6 to 7 (#2403) Bumps [actions/github-script](https://github.com/actions/github-script) from 6 to 7. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/github-script 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/project_management_issue_open.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/project_management_issue_open.yml b/.github/workflows/project_management_issue_open.yml index e68e9ab152..28ee771ed1 100644 --- a/.github/workflows/project_management_issue_open.yml +++ b/.github/workflows/project_management_issue_open.yml @@ -10,7 +10,7 @@ jobs: permissions: issues: write steps: - - uses: actions/github-script@v6 + - uses: actions/github-script@v7 with: script: | github.rest.issues.addLabels({ From 8cba762d0d0d2cfe5ffaa8792f0b6cf64d24c75f Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Mon, 20 Nov 2023 23:52:17 -0800 Subject: [PATCH 116/119] [BUILD] Update vcpkg to latest release (#2412) --- tools/vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/vcpkg b/tools/vcpkg index acc3bcf76b..8eb57355a4 160000 --- a/tools/vcpkg +++ b/tools/vcpkg @@ -1 +1 @@ -Subproject commit acc3bcf76b84ae5041c86ab55fe138ae7b8255c7 +Subproject commit 8eb57355a4ffb410a2e94c07b4dca2dffbee8e50 From 9b89843553d09afbae428913573d12afbb99be75 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 21 Nov 2023 01:06:06 -0800 Subject: [PATCH 117/119] [SDK] Cardinality limits for metrics streams (Sync Instruments + Delta Temporality) (#2255) --- .../sdk/metrics/state/attributes_hashmap.h | 63 ++++++++++ .../sdk/metrics/state/sync_metric_storage.h | 5 +- sdk/test/metrics/CMakeLists.txt | 1 + sdk/test/metrics/cardinality_limit_test.cc | 108 ++++++++++++++++++ 4 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 sdk/test/metrics/cardinality_limit_test.cc diff --git a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h index a4b53a37c5..85009a9fcb 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h @@ -23,6 +23,15 @@ namespace metrics using opentelemetry::sdk::common::OrderedAttributeMap; +constexpr size_t kAggregationCardinalityLimit = 2000; +const std::string kAggregationCardinalityLimitOverflowError = + "Maximum data points for metric stream exceeded. Entry added to overflow"; +const std::string kAttributesLimitOverflowKey = "otel.metrics.overflow"; +const bool kAttributesLimitOverflowValue = true; +const size_t kOverflowAttributesHash = common::GetHashForAttributeMap( + {{kAttributesLimitOverflowKey, + kAttributesLimitOverflowValue}}); // precalculated for optimization + class AttributeHashGenerator { public: @@ -35,6 +44,9 @@ class AttributeHashGenerator class AttributesHashMap { public: + AttributesHashMap(size_t attributes_limit = kAggregationCardinalityLimit) + : attributes_limit_(attributes_limit) + {} Aggregation *Get(size_t hash) const { auto it = hash_map_.find(hash); @@ -66,6 +78,11 @@ class AttributesHashMap return it->second.second.get(); } + if (IsOverflowAttributes()) + { + return GetOrSetOveflowAttributes(aggregation_callback); + } + MetricAttributes attr{attributes}; hash_map_[hash] = {attr, aggregation_callback()}; @@ -80,6 +97,12 @@ class AttributesHashMap { return it->second.second.get(); } + + if (IsOverflowAttributes()) + { + return GetOrSetOveflowAttributes(aggregation_callback); + } + MetricAttributes attr{}; hash_map_[hash] = {attr, aggregation_callback()}; return hash_map_[hash].second.get(); @@ -95,6 +118,11 @@ class AttributesHashMap return it->second.second.get(); } + if (IsOverflowAttributes()) + { + return GetOrSetOveflowAttributes(aggregation_callback); + } + MetricAttributes attr{attributes}; hash_map_[hash] = {attr, aggregation_callback()}; @@ -113,6 +141,12 @@ class AttributesHashMap { it->second.second = std::move(aggr); } + else if (IsOverflowAttributes()) + { + hash_map_[kOverflowAttributesHash] = { + MetricAttributes{{kAttributesLimitOverflowKey, kAttributesLimitOverflowValue}}, + std::move(aggr)}; + } else { MetricAttributes attr{attributes}; @@ -127,6 +161,12 @@ class AttributesHashMap { it->second.second = std::move(aggr); } + else if (IsOverflowAttributes()) + { + hash_map_[kOverflowAttributesHash] = { + MetricAttributes{{kAttributesLimitOverflowKey, kAttributesLimitOverflowValue}}, + std::move(aggr)}; + } else { MetricAttributes attr{attributes}; @@ -157,6 +197,29 @@ class AttributesHashMap private: std::unordered_map>> hash_map_; + size_t attributes_limit_; + + Aggregation *GetOrSetOveflowAttributes( + std::function()> aggregation_callback) + { + auto agg = aggregation_callback(); + return GetOrSetOveflowAttributes(std::move(agg)); + } + + Aggregation *GetOrSetOveflowAttributes(std::unique_ptr agg) + { + auto it = hash_map_.find(kOverflowAttributesHash); + if (it != hash_map_.end()) + { + return it->second.second.get(); + } + + MetricAttributes attr{{kAttributesLimitOverflowKey, kAttributesLimitOverflowValue}}; + hash_map_[kOverflowAttributesHash] = {attr, std::move(agg)}; + return hash_map_[kOverflowAttributesHash].second.get(); + } + + bool IsOverflowAttributes() const { return (hash_map_.size() + 1 >= attributes_limit_); } }; } // namespace metrics 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 b450b92179..cf249c39f2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -40,9 +40,10 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage const AttributesProcessor *attributes_processor, nostd::shared_ptr &&exemplar_reservoir OPENTELEMETRY_MAYBE_UNUSED, - const AggregationConfig *aggregation_config) + const AggregationConfig *aggregation_config, + size_t attributes_limit = kAggregationCardinalityLimit) : instrument_descriptor_(instrument_descriptor), - attributes_hashmap_(new AttributesHashMap()), + attributes_hashmap_(new AttributesHashMap(attributes_limit)), attributes_processor_(attributes_processor), #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW exemplar_reservoir_(exemplar_reservoir), diff --git a/sdk/test/metrics/CMakeLists.txt b/sdk/test/metrics/CMakeLists.txt index b30d71ae22..ccc31de689 100644 --- a/sdk/test/metrics/CMakeLists.txt +++ b/sdk/test/metrics/CMakeLists.txt @@ -16,6 +16,7 @@ foreach( attributes_hashmap_test base2_exponential_histogram_indexer_test circular_buffer_counter_test + cardinality_limit_test histogram_test sync_metric_storage_counter_test sync_metric_storage_histogram_test diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc new file mode 100644 index 0000000000..d290f889b5 --- /dev/null +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -0,0 +1,108 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "common.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" +#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" + +#include +#include + +using namespace opentelemetry::sdk::metrics; +using namespace opentelemetry::common; +namespace nostd = opentelemetry::nostd; + +TEST(CardinalityLimit, AttributesHashMapBasicTests) +{ + AttributesHashMap hash_map(10); + std::function()> aggregation_callback = + []() -> std::unique_ptr { + 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; + for (auto i = 0; i < 10; i++) + { + OrderedAttributeMap 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); + // add 5 unique metric points above limit, they all should get consolidated as single + // overflowmetric point. + for (auto i = 10; i < 15; i++) + { + OrderedAttributeMap 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); // only one more metric point should be added as overflow. + // get the overflow metric point + auto agg = hash_map.GetOrSetDefault( + OrderedAttributeMap({{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_), + record_value * 6); // 1 from previous 10, 5 from current 5. +} + +class WritableMetricStorageCardinalityLimitTestFixture + : public ::testing::TestWithParam +{}; + +TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregation) +{ + auto sdk_start_ts = std::chrono::system_clock::now(); + const size_t attributes_limit = 10; + InstrumentDescriptor instr_desc = {"name", "desc", "1unit", InstrumentType::kCounter, + InstrumentValueType::kLong}; + std::unique_ptr default_attributes_processor{ + new DefaultAttributesProcessor{}}; + SyncMetricStorage storage(instr_desc, AggregationType::kSum, default_attributes_processor.get(), + ExemplarReservoir::GetNoExemplarReservoir(), nullptr, attributes_limit); + + long record_value = 100; + // add 9 unique metric points, and 6 more above limit. + for (auto i = 0; i < 15; i++) + { + std::map attributes = {{"key", std::to_string(i)}}; + storage.RecordLong(record_value, + KeyValueIterableView>(attributes), + opentelemetry::context::Context{}); + } + AggregationTemporality temporality = GetParam(); + std::shared_ptr collector(new MockCollectorHandle(temporality)); + std::vector> collectors; + collectors.push_back(collector); + //... Some computation here + auto collection_ts = std::chrono::system_clock::now(); + size_t count_attributes = 0; + bool overflow_present = false; + storage.Collect( + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { + for (const auto &data_attr : metric_data.point_data_attr_) + { + const auto &data = opentelemetry::nostd::get(data_attr.point_data); + count_attributes++; + if (data_attr.attributes.begin()->first == kAttributesLimitOverflowKey) + { + EXPECT_EQ(nostd::get(data.value_), record_value * 6); + overflow_present = true; + } + } + return true; + }); + EXPECT_EQ(count_attributes, attributes_limit); + EXPECT_EQ(overflow_present, true); +} +INSTANTIATE_TEST_SUITE_P(All, + WritableMetricStorageCardinalityLimitTestFixture, + ::testing::Values(AggregationTemporality::kDelta)); From 71d0e50b12769375e0d84bbcfdf78f9b69a02dff Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:26:14 +0100 Subject: [PATCH 118/119] [EXPORTER] Prometheus: Add unit to names, convert to word (#2213) --- .../exporters/prometheus/exporter_utils.h | 93 +++++- exporters/prometheus/src/exporter_utils.cc | 269 +++++++++++++++--- .../prometheus/test/exporter_utils_test.cc | 167 ++++++++--- 3 files changed, 454 insertions(+), 75 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index 96c7ac8826..fa3eedd2c4 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -7,6 +7,7 @@ #include #include #include "opentelemetry/metrics/provider.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/metrics/meter.h" #include "opentelemetry/version.h" @@ -35,7 +36,17 @@ class PrometheusExporterUtils private: /** - * Append key-value pair to prometheus labels. + * Sanitize the given metric name or label according to Prometheus rule. + * + * This function is needed because names in OpenTelemetry can contain + * alphanumeric characters, '_', '.', and '-', whereas in Prometheus the + * name should only contain alphanumeric characters and '_'. + * @param name name + */ + static std::string SanitizeNames(std::string name); + + /** + * Sanitize the given metric name or label according to Prometheus rule. * * @param name label name * @param value label value @@ -45,6 +56,79 @@ class PrometheusExporterUtils std::string value, std::vector<::prometheus::ClientMetric::Label> *labels); + static std::string MapToPrometheusName(const std::string &name, + const std::string &unit, + ::prometheus::MetricType prometheus_type); + + /** + * A utility function that returns the equivalent Prometheus name for the provided OTLP metric + * unit. + * + * @param raw_metric_unitName The raw metric unit for which Prometheus metric unit needs to be + * computed. + * @return the computed Prometheus metric unit equivalent of the OTLP metric unit + */ + static std::string GetEquivalentPrometheusUnit(const std::string &raw_metric_unitName); + + /** + * This method retrieves the expanded Prometheus unit name for known abbreviations. OTLP metrics + * use the c/s notation as specified at UCUM. The list of + * mappings is adopted from OpenTelemetry + * Collector Contrib. + * + * @param unit_abbreviation The unit that name that needs to be expanded/converted to Prometheus + * units. + * @return The expanded/converted unit name if known, otherwise returns the input unit name as-is. + */ + static std::string GetPrometheusUnit(const std::string &unit_abbreviation); + + /** + * This method retrieves the expanded Prometheus unit name to be used with "per" units for known + * units. For example: s => per second (singular) + * + * @param per_unit_abbreviation The unit abbreviation used in a 'per' unit. + * @return The expanded unit equivalent to be used in 'per' unit if the input is a known unit, + * otherwise returns the input as-is. + */ + static std::string GetPrometheusPerUnit(const std::string &per_unit_abbreviation); + + /** + * Replaces all characters that are not a letter or a digit with '_' to make the resulting string + * Prometheus compliant. This method also removes leading and trailing underscores - this is done + * to keep the resulting unit similar to what is produced from the collector's implementation. + * + * @param str The string input that needs to be made Prometheus compliant. + * @return the cleaned-up Prometheus compliant string. + */ + static std::string CleanUpString(const std::string &str); + + /** + * This method is used to convert the units expressed as a rate via '/' symbol in their name to + * their expanded text equivalent. For instance, km/h => km_per_hour. The method operates on the + * input by splitting it in 2 parts - before and after '/' symbol and will attempt to expand any + * known unit abbreviation in both parts. Unknown abbreviations & unsupported characters will + * remain unchanged in the final output of this function. + * + * @param rate_expressed_unit The rate unit input that needs to be converted to its text + * equivalent. + * @return The text equivalent of unit expressed as rate. If the input does not contain '/', the + * function returns it as-is. + */ + static std::string ConvertRateExpressedToPrometheusUnit(const std::string &rate_expressed_unit); + + /** + * This method drops all characters enclosed within '{}' (including the curly braces) by replacing + * them with an empty string. Note that this method will not produce the intended effect if there + * are nested curly braces within the outer enclosure of '{}'. + * + *

For instance, {packet{s}s} => s}. + * + * @param unit The input unit from which text within curly braces needs to be removed. + * @return The resulting unit after removing the text within '{}'. + */ + static std::string RemoveUnitPortionInBraces(const std::string &unit); + static opentelemetry::sdk::metrics::AggregationType getAggregationType( const opentelemetry::sdk::metrics::PointType &point_type); @@ -58,6 +142,7 @@ class PrometheusExporterUtils * Add a target_info metric to collect resource attributes */ static void SetTarget(const sdk::metrics::ResourceMetrics &data, + std::chrono::nanoseconds time, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, std::vector<::prometheus::MetricFamily> *output); @@ -70,6 +155,7 @@ class PrometheusExporterUtils const opentelemetry::sdk::metrics::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, ::prometheus::MetricType type, + std::chrono::nanoseconds time, ::prometheus::MetricFamily *metric_family, const opentelemetry::sdk::resource::Resource *resource); @@ -83,6 +169,7 @@ class PrometheusExporterUtils const std::vector &counts, const opentelemetry::sdk::metrics::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + std::chrono::nanoseconds time, ::prometheus::MetricFamily *metric_family, const opentelemetry::sdk::resource::Resource *resource); @@ -92,6 +179,7 @@ class PrometheusExporterUtils static void SetMetricBasic( ::prometheus::ClientMetric &metric, const opentelemetry::sdk::metrics::PointAttributes &labels, + std::chrono::nanoseconds time, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, const opentelemetry::sdk::resource::Resource *resource); @@ -122,6 +210,9 @@ class PrometheusExporterUtils const std::vector &boundaries, const std::vector &counts, ::prometheus::ClientMetric *metric); + + // For testing + friend class SanitizeNameTester; }; } // namespace metrics } // namespace exporter diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 42fafc6336..4b1ee054c4 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include #include #include @@ -93,22 +94,6 @@ std::string SanitizeLabel(std::string label_key) }); } -/** - * Sanitize the given metric name according to Prometheus rule. - * Prometheus metric names are required to match the following regex: - * [a-zA-Z_:]([a-zA-Z0-9_:])* - * and multiple consecutive _ characters must be collapsed to a single _. - */ -std::string SanitizeName(std::string name) -{ - return Sanitize(name, [](int i, char c) { - return (c >= 'a' && c <= 'z') || // - (c >= 'A' && c <= 'Z') || // - c == '_' || // - c == ':' || // - (c >= '0' && c <= '9' && i > 0); - }); -} } // namespace /** @@ -132,11 +117,16 @@ std::vector PrometheusExporterUtils::TranslateT std::vector output; output.reserve(reserve_size); - + if (data.scope_metric_data_.empty()) + { + return output; + } // Append target_info as the first metric if (populate_target_info && !data.scope_metric_data_.empty()) { - SetTarget(data, (*data.scope_metric_data_.begin()).scope_, &output); + SetTarget(data, + data.scope_metric_data_.begin()->metric_data_.begin()->end_ts.time_since_epoch(), + (*data.scope_metric_data_.begin()).scope_, &output); } for (const auto &instrumentation_info : data.scope_metric_data_) @@ -145,21 +135,22 @@ std::vector PrometheusExporterUtils::TranslateT { auto origin_name = metric_data.instrument_descriptor.name_; auto unit = metric_data.instrument_descriptor.unit_; - auto sanitized = SanitizeName(origin_name); prometheus_client::MetricFamily metric_family; - metric_family.name = sanitized + "_" + unit; metric_family.help = metric_data.instrument_descriptor.description_; + auto time = metric_data.end_ts.time_since_epoch(); + auto front = metric_data.point_data_attr_.front(); + auto kind = getAggregationType(front.point_data); + bool is_monotonic = true; + if (kind == sdk::metrics::AggregationType::kSum) + { + is_monotonic = nostd::get(front.point_data).is_monotonic_; + } + 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_family.type = type; for (const auto &point_data_attr : metric_data.point_data_attr_) { - auto kind = getAggregationType(point_data_attr.point_data); - bool is_monotonic = true; - if (kind == sdk::metrics::AggregationType::kSum) - { - is_monotonic = - nostd::get(point_data_attr.point_data).is_monotonic_; - } - const prometheus_client::MetricType type = TranslateType(kind, is_monotonic); - metric_family.type = type; if (type == prometheus_client::MetricType::Histogram) // Histogram { auto histogram_point_data = @@ -176,7 +167,7 @@ std::vector PrometheusExporterUtils::TranslateT sum = static_cast(nostd::get(histogram_point_data.sum_)); } SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, - point_data_attr.attributes, instrumentation_info.scope_, &metric_family, + point_data_attr.attributes, instrumentation_info.scope_, time, &metric_family, data.resource_); } else if (type == prometheus_client::MetricType::Gauge) @@ -187,7 +178,7 @@ std::vector PrometheusExporterUtils::TranslateT auto last_value_point_data = nostd::get(point_data_attr.point_data); std::vector values{last_value_point_data.value_}; - SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, time, &metric_family, data.resource_); } else if (nostd::holds_alternative(point_data_attr.point_data)) @@ -195,7 +186,7 @@ std::vector PrometheusExporterUtils::TranslateT auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, time, &metric_family, data.resource_); } else @@ -212,7 +203,7 @@ std::vector PrometheusExporterUtils::TranslateT auto sum_point_data = nostd::get(point_data_attr.point_data); std::vector values{sum_point_data.value_}; - SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, + SetData(values, point_data_attr.attributes, instrumentation_info.scope_, type, time, &metric_family, data.resource_); } else @@ -240,6 +231,205 @@ void PrometheusExporterUtils::AddPrometheusLabel( labels->emplace_back(std::move(prometheus_label)); } +/** + * Sanitize the given metric name or label according to Prometheus rule. + * + * This function is needed because names in OpenTelemetry can contain + * alphanumeric characters, '_', '.', and '-', whereas in Prometheus the + * name should only contain alphanumeric characters and '_'. + */ +std::string PrometheusExporterUtils::SanitizeNames(std::string name) +{ + constexpr const auto replacement = '_'; + constexpr const auto replacement_dup = '='; + + auto valid = [](int i, char c) { + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ':' || + (c >= '0' && c <= '9' && i > 0)) + { + return true; + } + return false; + }; + + bool has_dup = false; + for (int i = 0; i < (int)name.size(); ++i) + { + if (valid(i, name[i])) + { + continue; + } + if (i > 0 && (name[i - 1] == replacement || name[i - 1] == replacement_dup)) + { + has_dup = true; + name[i] = replacement_dup; + } + else + { + name[i] = replacement; + } + } + if (has_dup) + { + auto end = std::remove(name.begin(), name.end(), replacement_dup); + return std::string{name.begin(), end}; + } + return name; +} + +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,}"); + +std::string PrometheusExporterUtils::GetEquivalentPrometheusUnit( + const std::string &raw_metric_unit_name) +{ + if (raw_metric_unit_name.empty()) + { + return raw_metric_unit_name; + } + + std::string converted_metric_unit_name = RemoveUnitPortionInBraces(raw_metric_unit_name); + converted_metric_unit_name = ConvertRateExpressedToPrometheusUnit(converted_metric_unit_name); + + return CleanUpString(GetPrometheusUnit(converted_metric_unit_name)); +} + +std::string PrometheusExporterUtils::GetPrometheusUnit(const std::string &unit_abbreviation) +{ + static std::unordered_map units{// Time + {"d", "days"}, + {"h", "hours"}, + {"min", "minutes"}, + {"s", "seconds"}, + {"ms", "milliseconds"}, + {"us", "microseconds"}, + {"ns", "nanoseconds"}, + // Bytes + {"By", "bytes"}, + {"KiBy", "kibibytes"}, + {"MiBy", "mebibytes"}, + {"GiBy", "gibibytes"}, + {"TiBy", "tibibytes"}, + {"KBy", "kilobytes"}, + {"MBy", "megabytes"}, + {"GBy", "gigabytes"}, + {"TBy", "terabytes"}, + {"By", "bytes"}, + {"KBy", "kilobytes"}, + {"MBy", "megabytes"}, + {"GBy", "gigabytes"}, + {"TBy", "terabytes"}, + // SI + {"m", "meters"}, + {"V", "volts"}, + {"A", "amperes"}, + {"J", "joules"}, + {"W", "watts"}, + {"g", "grams"}, + // Misc + {"Cel", "celsius"}, + {"Hz", "hertz"}, + {"1", ""}, + {"%", "percent"}}; + auto res_it = units.find(unit_abbreviation); + if (res_it == units.end()) + { + return unit_abbreviation; + } + return res_it->second; +} + +std::string PrometheusExporterUtils::GetPrometheusPerUnit(const std::string &per_unit_abbreviation) +{ + static std::unordered_map per_units{ + {"s", "second"}, {"m", "minute"}, {"h", "hour"}, {"d", "day"}, + {"w", "week"}, {"mo", "month"}, {"y", "year"}}; + auto res_it = per_units.find(per_unit_abbreviation); + if (res_it == per_units.end()) + { + return per_unit_abbreviation; + } + return res_it->second; +} + +std::string PrometheusExporterUtils::RemoveUnitPortionInBraces(const std::string &unit) +{ + return std::regex_replace(unit, CHARACTERS_BETWEEN_BRACES_PATTERN, ""); +} + +std::string PrometheusExporterUtils::ConvertRateExpressedToPrometheusUnit( + const std::string &rate_expressed_unit) +{ + size_t pos = rate_expressed_unit.find("/"); + if (pos == std::string::npos) + { + return rate_expressed_unit; + } + + std::vector rate_entities; + rate_entities.push_back(rate_expressed_unit.substr(0, pos)); + rate_entities.push_back(rate_expressed_unit.substr(pos + 1)); + + if (rate_entities[1].empty()) + { + return rate_expressed_unit; + } + + std::string prometheus_unit = GetPrometheusUnit(rate_entities[0]); + std::string prometheus_per_unit = GetPrometheusPerUnit(rate_entities[1]); + + return prometheus_unit + "_per_" + prometheus_per_unit; +} + +std::string PrometheusExporterUtils::CleanUpString(const std::string &str) +{ + std::string cleaned_string = std::regex_replace(str, INVALID_CHARACTERS_PATTERN, "_"); + cleaned_string = std::regex_replace(cleaned_string, SANITIZE_CONSECUTIVE_UNDERSCORES, "_"); + cleaned_string = std::regex_replace(cleaned_string, SANITIZE_TRAILING_UNDERSCORES, ""); + cleaned_string = std::regex_replace(cleaned_string, SANITIZE_LEADING_UNDERSCORES, ""); + + return cleaned_string; +} + +std::string PrometheusExporterUtils::MapToPrometheusName( + const std::string &name, + const std::string &unit, + prometheus_client::MetricType prometheus_type) +{ + 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) + { + sanitized_name += "_total"; + } + } + + // Special case - gauge + if (unit == "1" && prometheus_type == prometheus_client::MetricType::Gauge && + sanitized_name.find("ratio") == std::string::npos) + { + sanitized_name += "_ratio"; + } + + return CleanUpString(SanitizeNames(sanitized_name)); +} + metric_sdk::AggregationType PrometheusExporterUtils::getAggregationType( const metric_sdk::PointType &point_type) { @@ -295,6 +485,7 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType( void PrometheusExporterUtils::SetTarget( const sdk::metrics::ResourceMetrics &data, + std::chrono::nanoseconds time, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, std::vector<::prometheus::MetricFamily> *output) { @@ -313,11 +504,11 @@ void PrometheusExporterUtils::SetTarget( metric.info.value = 1.0; metric_sdk::PointAttributes empty_attributes; - SetMetricBasic(metric, empty_attributes, scope, data.resource_); + SetMetricBasic(metric, empty_attributes, time, scope, data.resource_); for (auto &label : data.resource_->GetAttributes()) { - AddPrometheusLabel(SanitizeName(label.first), AttributeValueToString(label.second), + AddPrometheusLabel(SanitizeNames(label.first), AttributeValueToString(label.second), &metric.label); } @@ -334,12 +525,13 @@ void PrometheusExporterUtils::SetData( const metric_sdk::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, prometheus_client::MetricType type, + std::chrono::nanoseconds time, prometheus_client::MetricFamily *metric_family, const opentelemetry::sdk::resource::Resource *resource) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels, scope, resource); + SetMetricBasic(metric, labels, time, scope, resource); SetValue(values, type, &metric); } @@ -354,12 +546,13 @@ void PrometheusExporterUtils::SetData( const std::vector &counts, const metric_sdk::PointAttributes &labels, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + std::chrono::nanoseconds time, prometheus_client::MetricFamily *metric_family, const opentelemetry::sdk::resource::Resource *resource) { metric_family->metric.emplace_back(); prometheus_client::ClientMetric &metric = metric_family->metric.back(); - SetMetricBasic(metric, labels, scope, resource); + SetMetricBasic(metric, labels, time, scope, resource); SetValue(values, boundaries, counts, &metric); } @@ -369,9 +562,11 @@ void PrometheusExporterUtils::SetData( void PrometheusExporterUtils::SetMetricBasic( prometheus_client::ClientMetric &metric, const metric_sdk::PointAttributes &labels, + std::chrono::nanoseconds time, const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, const opentelemetry::sdk::resource::Resource *resource) { + metric.timestamp_ms = time.count() / 1000000; if (labels.empty() && nullptr == resource) { return; diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 8ff324d7ac..b876e7369c 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -15,17 +15,62 @@ namespace prometheus_client = ::prometheus; OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ +class SanitizeNameTester +{ +public: + static std::string sanitize(std::string name) + { + return PrometheusExporterUtils::SanitizeNames(name); + } + static std::string getPrometheusUnit(const std::string &unit_abbreviation) + { + return PrometheusExporterUtils::GetPrometheusUnit(unit_abbreviation); + } + static std::string getPrometheusPerUnit(const std::string &per_unit_abbreviation) + { + return PrometheusExporterUtils::GetPrometheusPerUnit(per_unit_abbreviation); + } + static std::string removeUnitPortionInBraces(const std::string &unit) + { + return PrometheusExporterUtils::RemoveUnitPortionInBraces(unit); + } + static std::string convertRateExpressedToPrometheusUnit(const std::string &rate_expressed_unit) + { + return PrometheusExporterUtils::ConvertRateExpressedToPrometheusUnit(rate_expressed_unit); + } + static std::string cleanUpString(const std::string &str) + { + return PrometheusExporterUtils::CleanUpString(str); + } + static std::string getEquivalentPrometheusUnit(const std::string &raw_metric_unit_name) + { + return PrometheusExporterUtils::GetEquivalentPrometheusUnit(raw_metric_unit_name); + } + static std::string mapToPrometheusName(const std::string &name, + const std::string &unit, + prometheus_client::MetricType prometheus_type) + { + return PrometheusExporterUtils::MapToPrometheusName(name, unit, prometheus_type); + } +}; +} // namespace metrics +} // namespace exporter + template void assert_basic(prometheus_client::MetricFamily &metric, - const std::string &sanitized_name, + const std::string &expected_name, const std::string &description, prometheus_client::MetricType type, size_t label_num, std::vector vals) { - ASSERT_EQ(metric.name, sanitized_name + "_unit"); // name sanitized - ASSERT_EQ(metric.help, description); // description not changed - ASSERT_EQ(metric.type, type); // type translated + ASSERT_EQ(metric.name, expected_name); // name sanitized + ASSERT_EQ(metric.help, description); // description not changed + ASSERT_EQ(metric.type, type); // type translated // Prometheus metric data points should not have explicit timestamps for (const prometheus::ClientMetric &cm : metric.metric) @@ -109,12 +154,10 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 2); - auto metric1 = translated[1]; std::vector vals = {10}; - assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Counter, 3, - vals); - + assert_basic(metric1, "library_name_unit_total", "description", + prometheus_client::MetricType::Counter, 3, vals); int checked_label_num = 0; for (auto &label : translated[0].metric[0].label) { @@ -157,7 +200,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) auto metric1 = translated[1]; std::vector vals = {10}; - assert_basic(metric1, "library_name", "description", prometheus_client::MetricType::Gauge, 3, + assert_basic(metric1, "library_name_unit", "description", prometheus_client::MetricType::Gauge, 3, vals); int checked_label_num = 0; @@ -196,8 +239,8 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) auto metric = translated[1]; std::vector vals = {3, 900.5, 4}; - assert_basic(metric, "library_name", "description", prometheus_client::MetricType::Histogram, 3, - vals); + assert_basic(metric, "library_name_unit", "description", prometheus_client::MetricType::Histogram, + 3, vals); assert_histogram(metric, std::list{10.1, 20.2, 30.2}, {200, 300, 400, 500}); int checked_label_num = 0; @@ -230,27 +273,12 @@ class SanitizeTest : public ::testing::Test InstrumentationScope::Create("library_name", "1.2.0"); protected: - void CheckSanitizeName(const std::string &original, const std::string &sanitized) - { - metric_sdk::InstrumentDescriptor instrument_descriptor{ - original, "description", "unit", metric_sdk::InstrumentType::kCounter, - metric_sdk::InstrumentValueType::kDouble}; - std::vector result = PrometheusExporterUtils::TranslateToPrometheus( - {&resource_, - std::vector{ - {instrumentation_scope_.get(), - std::vector{ - {{instrument_descriptor, {}, {}, {}, {{{}, {}}}}}}}}}, - false); - EXPECT_EQ(result.begin()->name, sanitized + "_unit"); - } - void CheckSanitizeLabel(const std::string &original, const std::string &sanitized) { metric_sdk::InstrumentDescriptor instrument_descriptor{ "name", "description", "unit", metric_sdk::InstrumentType::kCounter, metric_sdk::InstrumentValueType::kDouble}; - std::vector result = PrometheusExporterUtils::TranslateToPrometheus( + auto result = PrometheusExporterUtils::TranslateToPrometheus( {&resource_, std::vector{ {instrumentation_scope_.get(), @@ -261,16 +289,6 @@ class SanitizeTest : public ::testing::Test } }; -TEST_F(SanitizeTest, Name) -{ - CheckSanitizeName("name", "name"); - CheckSanitizeName("name?", "name_"); - CheckSanitizeName("name???", "name_"); - CheckSanitizeName("name?__", "name_"); - CheckSanitizeName("name?__name", "name_name"); - CheckSanitizeName("name?__name:", "name_name:"); -} - TEST_F(SanitizeTest, Label) { CheckSanitizeLabel("name", "name"); @@ -281,6 +299,8 @@ TEST_F(SanitizeTest, Label) CheckSanitizeLabel("name?__name:", "name_name_"); } +TEST_F(SanitizeTest, Name) {} + class AttributeCollisionTest : public ::testing::Test { Resource resource_ = Resource::Create(ResourceAttributes{}); @@ -325,6 +345,79 @@ TEST_F(AttributeCollisionTest, SeparatesDistinctKeys) {"otel_scope_version", "1.2.0"}}); } +TEST(PrometheusExporterUtils, PrometheusUnit) +{ + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("d"), "days"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("h"), "hours"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("min"), "minutes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("s"), "seconds"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("ms"), "milliseconds"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("us"), "microseconds"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("ns"), "nanoseconds"); + + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("By"), "bytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("KiBy"), "kibibytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("MiBy"), "mebibytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("GiBy"), "gibibytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("TiBy"), "tibibytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("KBy"), "kilobytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("MBy"), "megabytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("GBy"), "gigabytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("TBy"), "terabytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("By"), "bytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("KBy"), "kilobytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("MBy"), "megabytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("GBy"), "gigabytes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("TBy"), "terabytes"); + + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("m"), "meters"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("V"), "volts"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("A"), "amperes"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("J"), "joules"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("W"), "watts"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("g"), "grams"); + + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("Cel"), "celsius"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("Hz"), "hertz"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("1"), ""); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusUnit("%"), "percent"); +} + +TEST(PrometheusExporterUtils, PrometheusPerUnit) +{ + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("s"), "second"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("m"), "minute"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("h"), "hour"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("d"), "day"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("w"), "week"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("mo"), "month"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::getPrometheusPerUnit("y"), "year"); +} + +TEST(PrometheusExporterUtils, RemoveUnitPortionInBraces) +{ + ASSERT_EQ(exporter::metrics::SanitizeNameTester::removeUnitPortionInBraces("{unit}"), ""); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::removeUnitPortionInBraces("unit{unit}"), "unit"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::removeUnitPortionInBraces("unit_{unit}"), + "unit_"); +} + +TEST(PrometheusExporterUtils, ConvertRateExpressedToPrometheusUnit) +{ + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("unit/d"), + "unit_per_day"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("unit/s"), + "unit_per_second"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("unit/"), + "unit/"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("unit"), + "unit"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("unit/m"), + "unit_per_minute"); + ASSERT_EQ(exporter::metrics::SanitizeNameTester::convertRateExpressedToPrometheusUnit("/m"), + "_per_minute"); +} + TEST_F(AttributeCollisionTest, JoinsCollidingKeys) { CheckTranslation({{"foo.a", "value1"}, {"foo_a", "value2"}}, {{"foo_a", "value1;value2"}, From 064fef0d871c57ffac6739d3311659a5770a9db4 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Nov 2023 09:45:09 -0800 Subject: [PATCH 119/119] [Metrics] Make context optional for histogram instruments in Metrics SDK (#2416) --- api/include/opentelemetry/metrics/noop.h | 7 + .../opentelemetry/metrics/sync_instruments.h | 99 +++++-- .../sdk/metrics/sync_instruments.h | 122 +++----- sdk/src/metrics/meter.cc | 4 +- sdk/src/metrics/sync_instruments.cc | 265 ++++++++++++++++-- sdk/test/metrics/sync_instruments_test.cc | 17 +- 6 files changed, 375 insertions(+), 139 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index f20e855cb7..d34a0e681b 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -44,6 +44,13 @@ class NoopHistogram : public Histogram const common::KeyValueIterable & /* attributes */, const context::Context & /* context */) noexcept override {} +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void Record(T /*value*/, + const opentelemetry::common::KeyValueIterable & /*attributes*/) noexcept override + {} + + void Record(T /*value*/) noexcept override {} +#endif }; template diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index b26e527c2c..4471677433 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -22,31 +22,43 @@ class SynchronousInstrument virtual ~SynchronousInstrument() = default; }; +/* A Counter instrument that adds values. */ template class Counter : public SynchronousInstrument { public: /** - * Add adds the value to the counter's sum + * Record a value * * @param value The increment amount. MUST be non-negative. */ virtual void Add(T value) noexcept = 0; + /** + * Record a value + * + * @param value The increment amount. MUST be non-negative. + * @param context The explicit context to associate with this measurement. + */ virtual void Add(T value, const context::Context &context) noexcept = 0; /** - * Add adds the value to the counter's sum. The attributes should contain - * the keys and values to be associated with this value. Counters only - * accept positive valued updates. + * Record a value with a set of attributes. * * @param value The increment amount. MUST be non-negative. - * @param attributes the set of attributes, as key-value pairs + * @param attributes A set of attributes to associate with the value. */ virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + /** + * Record a value with a set of attributes. + * + * @param value The increment amount. MUST be non-negative. + * @param attributes A set of attributes to associate with the value. + * @param context The explicit context to associate with this measurement. + */ virtual void Add(T value, const common::KeyValueIterable &attributes, const context::Context &context) noexcept = 0; @@ -55,8 +67,7 @@ class Counter : public SynchronousInstrument nostd::enable_if_t::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - auto context = context::Context{}; - this->Add(value, common::KeyValueIterableView{attributes}, context); + this->Add(value, common::KeyValueIterableView{attributes}); } template > attributes) noexcept { - auto context = context::Context{}; - this->Add(value, - nostd::span>{ - attributes.begin(), attributes.end()}, - context); + this->Add(value, nostd::span>{ + attributes.begin(), attributes.end()}); } void Add(T value, @@ -94,18 +102,54 @@ template class Histogram : public SynchronousInstrument { public: +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 /** + * @since ABI_VERSION 2 * Records a value. * * @param value The measurement value. MUST be non-negative. */ + virtual void Record(T value) noexcept = 0; + + /** + * @since ABI_VERSION 2 + * Records a value with a set of attributes. + * + * @param value The measurement value. MUST be non-negative. + * @param attribute A set of attributes to associate with the value. + */ + virtual void Record(T value, const common::KeyValueIterable &attribute) noexcept = 0; + + template ::value> * = nullptr> + void Record(T value, const U &attributes) noexcept + { + this->Record(value, common::KeyValueIterableView{attributes}); + } + + void Record(T value, + std::initializer_list> + attributes) noexcept + { + this->Record(value, nostd::span>{ + attributes.begin(), attributes.end()}); + } +#endif + + /** + * Records a value. + * + * @param value The measurement value. MUST be non-negative. + * @param context The explicit context to associate with this measurement. + */ virtual void Record(T value, const context::Context &context) noexcept = 0; /** * Records a value with a set of attributes. * * @param value The measurement value. MUST be non-negative. - * @param attributes A set of attributes to associate with the count. + * @param attributes A set of attributes to associate with the value.. + * @param context The explicit context to associate with this measurement. */ virtual void Record(T value, const common::KeyValueIterable &attributes, @@ -137,22 +181,35 @@ class UpDownCounter : public SynchronousInstrument { public: /** - * Adds a value. + * Record a value. * - * @param value The amount of the measurement. + * @param value The increment amount. May be positive, negative or zero. */ virtual void Add(T value) noexcept = 0; + /** + * Record a value. + * + * @param value The increment amount. May be positive, negative or zero. + * @param context The explicit context to associate with this measurement. + */ virtual void Add(T value, const context::Context &context) noexcept = 0; /** - * Add a value with a set of attributes. + * Record a value with a set of attributes. * * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + /** + * Record a value with a set of attributes. + * + * @param value The increment amount. May be positive, negative or zero. + * @param attributes A set of attributes to associate with the count. + * @param context The explicit context to associate with this measurement. + */ virtual void Add(T value, const common::KeyValueIterable &attributes, const context::Context &context) noexcept = 0; @@ -161,8 +218,7 @@ class UpDownCounter : public SynchronousInstrument nostd::enable_if_t::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - auto context = context::Context{}; - this->Add(value, common::KeyValueIterableView{attributes}, context); + this->Add(value, common::KeyValueIterableView{attributes}); } template > attributes) noexcept { - auto context = context::Context{}; - this->Add(value, - nostd::span>{ - attributes.begin(), attributes.end()}, - context); + this->Add(value, nostd::span>{ + attributes.begin(), attributes.end()}); } void Add(T value, diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 825547a846..f08b629fe2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -33,61 +33,22 @@ class Synchronous std::unique_ptr storage_; }; -template -class LongCounter : public Synchronous, public opentelemetry::metrics::Counter +class LongCounter : public Synchronous, public opentelemetry::metrics::Counter { public: LongCounter(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage) - : Synchronous(instrument_descriptor, std::move(storage)) - { - if (!storage_) - { - OTEL_INTERNAL_LOG_ERROR("[LongCounter::LongCounter] - Error during constructing LongCounter." - << "The metric storage is invalid" - << "No value will be added"); - } - } - - void Add(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override - { - if (!storage_) - { - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordLong(value, attributes, context); - } - - void Add(T value, + std::unique_ptr storage); + + void Add(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override; + + void Add(uint64_t value, const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override - { - if (!storage_) - { - return; - } - return storage_->RecordLong(value, attributes, context); - } - - void Add(T value) noexcept override - { - auto context = opentelemetry::context::Context{}; - if (!storage_) - { - return; - } - return storage_->RecordLong(value, context); - } - - void Add(T value, const opentelemetry::context::Context &context) noexcept override - { - if (!storage_) - { - return; - } - return storage_->RecordLong(value, context); - } + const opentelemetry::context::Context &context) noexcept override; + + void Add(uint64_t value) noexcept override; + + void Add(uint64_t value, const opentelemetry::context::Context &context) noexcept override; }; class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter @@ -139,48 +100,24 @@ class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::U void Add(double value, const opentelemetry::context::Context &context) noexcept override; }; -template -class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram +class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: LongHistogram(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage) - : Synchronous(instrument_descriptor, std::move(storage)) - { - if (!storage_) - { - OTEL_INTERNAL_LOG_ERROR( - "[LongHistogram::LongHistogram] - Error during constructing LongHistogram." - << "The metric storage is invalid" - << "No value will be added"); - } - } - - void Record(T value, + std::unique_ptr storage); + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void Record(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override; + + void Record(uint64_t value) noexcept override; +#endif + + void Record(uint64_t value, const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override - { - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN( - "[LongHistogram::Record(value, attributes)] negative value provided to histogram Name:" - << instrument_descriptor_.name_ << " Value:" << value); - return; - } - return storage_->RecordLong(value, attributes, context); - } - - void Record(T value, const opentelemetry::context::Context &context) noexcept override - { - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN( - "[LongHistogram::Record(value)] negative value provided to histogram Name:" - << instrument_descriptor_.name_ << " Value:" << value); - return; - } - return storage_->RecordLong(value, context); - } + const opentelemetry::context::Context &context) noexcept override; + + void Record(uint64_t value, const opentelemetry::context::Context &context) noexcept override; }; class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histogram @@ -189,6 +126,13 @@ class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histo DoubleHistogram(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage); +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + void Record(double value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override; + + void Record(double value) noexcept override; +#endif + void Record(double value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept override; diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 4f7c4c1207..0ae3776111 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -52,7 +52,7 @@ nostd::unique_ptr> Meter::CreateUInt64Counter( std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); return nostd::unique_ptr>( - new LongCounter(instrument_descriptor, std::move(storage))); + new LongCounter(instrument_descriptor, std::move(storage))); } nostd::unique_ptr> Meter::CreateDoubleCounter( @@ -138,7 +138,7 @@ nostd::unique_ptr> Meter::CreateUInt64Histogram( InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); return nostd::unique_ptr>{ - new LongHistogram(instrument_descriptor, std::move(storage))}; + new LongHistogram(instrument_descriptor, std::move(storage))}; } nostd::unique_ptr> Meter::CreateDoubleHistogram( diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index 6fe72b55bf..bdeff150ae 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -10,27 +10,93 @@ namespace sdk { namespace metrics { +LongCounter::LongCounter(InstrumentDescriptor instrument_descriptor, + std::unique_ptr storage) + : Synchronous(instrument_descriptor, std::move(storage)) +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_ERROR("[LongCounter::LongCounter] - Error constructing LongCounter." + << "The metric storage is invalid for " << instrument_descriptor.name_); + } +} + +void LongCounter::Add(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept +{ + auto context = opentelemetry::context::Context{}; + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongCounter::Add(V,A)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, attributes, context); +} + +void LongCounter::Add(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes, + const opentelemetry::context::Context &context) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongCounter::Add(V,A,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, attributes, context); +} + +void LongCounter::Add(uint64_t value) noexcept +{ + auto context = opentelemetry::context::Context{}; + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongCounter::Add(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, context); +} + +void LongCounter::Add(uint64_t value, const opentelemetry::context::Context &context) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongCounter::Add(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, context); +} + DoubleCounter::DoubleCounter(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { if (!storage_) { - OTEL_INTERNAL_LOG_ERROR( - "[DoubleCounter::DoubleCounter] - Error during constructing DoubleCounter." - << "The metric storage is invalid" - << "No value will be added"); + OTEL_INTERNAL_LOG_ERROR("[DoubleCounter::DoubleCounter] - Error constructing DoubleCounter." + << "The metric storage is invalid for " << instrument_descriptor.name_); } } void DoubleCounter::Add(double value, const opentelemetry::common::KeyValueIterable &attributes) noexcept { - auto context = opentelemetry::context::Context{}; + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } if (!storage_) { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } + auto context = opentelemetry::context::Context{}; return storage_->RecordDouble(value, attributes, context); } @@ -38,8 +104,16 @@ void DoubleCounter::Add(double value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept { + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A,C)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } if (!storage_) { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordDouble(value, attributes, context); @@ -47,18 +121,34 @@ void DoubleCounter::Add(double value, void DoubleCounter::Add(double value) noexcept { - auto context = opentelemetry::context::Context{}; + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } if (!storage_) { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } + auto context = opentelemetry::context::Context{}; return storage_->RecordDouble(value, context); } void DoubleCounter::Add(double value, const opentelemetry::context::Context &context) noexcept { + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } if (!storage_) { + OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordDouble(value, context); @@ -71,9 +161,8 @@ LongUpDownCounter::LongUpDownCounter(InstrumentDescriptor instrument_descriptor, if (!storage_) { OTEL_INTERNAL_LOG_ERROR( - "[LongUpDownCounter::LongUpDownCounter] - Error during constructing LongUpDownCounter." - << "The metric storage is invalid" - << "No value will be added"); + "[LongUpDownCounter::LongUpDownCounter] - Error constructing LongUpDownCounter." + << "The metric storage is invalid for " << instrument_descriptor.name_); } } @@ -83,6 +172,9 @@ void LongUpDownCounter::Add(int64_t value, auto context = opentelemetry::context::Context{}; if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[LongUpDownCounter::Add(V,A)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordLong(value, attributes, context); @@ -94,6 +186,9 @@ void LongUpDownCounter::Add(int64_t value, { if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[LongUpDownCounter::Add(V,A,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordLong(value, attributes, context); @@ -104,6 +199,8 @@ void LongUpDownCounter::Add(int64_t value) noexcept auto context = opentelemetry::context::Context{}; if (!storage_) { + OTEL_INTERNAL_LOG_WARN("[LongUpDownCounter::Add(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordLong(value, context); @@ -113,6 +210,9 @@ void LongUpDownCounter::Add(int64_t value, const opentelemetry::context::Context { if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[LongUpDownCounter::Add(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordLong(value, context); @@ -125,16 +225,20 @@ DoubleUpDownCounter::DoubleUpDownCounter(InstrumentDescriptor instrument_descrip if (!storage_) { OTEL_INTERNAL_LOG_ERROR( - "[DoubleUpDownCounter::DoubleUpDownCounter] - Error during constructing " - "DoubleUpDownCounter." - << "The metric storage is invalid" - << "No value will be added"); + "[DoubleUpDownCounter::DoubleUpDownCounter] - Error constructing DoubleUpDownCounter." + << "The metric storage is invalid for " << instrument_descriptor.name_); } } void DoubleUpDownCounter::Add(double value, const opentelemetry::common::KeyValueIterable &attributes) noexcept { + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN( + "[DoubleUpDownCounter::Add(V,A)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + } auto context = opentelemetry::context::Context{}; return storage_->RecordDouble(value, attributes, context); } @@ -145,6 +249,9 @@ void DoubleUpDownCounter::Add(double value, { if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[DoubleUpDownCounter::Add(V,A,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordDouble(value, attributes, context); @@ -154,6 +261,9 @@ void DoubleUpDownCounter::Add(double value) noexcept { if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[DoubleUpDownCounter::Add(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } auto context = opentelemetry::context::Context{}; @@ -164,11 +274,77 @@ void DoubleUpDownCounter::Add(double value, const opentelemetry::context::Contex { if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[DoubleUpDownCounter::Add(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); return; } return storage_->RecordDouble(value, context); } +LongHistogram::LongHistogram(InstrumentDescriptor instrument_descriptor, + std::unique_ptr storage) + : Synchronous(instrument_descriptor, std::move(storage)) +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_ERROR("[LongHistogram::LongHistogram] - Error constructing LongHistogram." + << "The metric storage is invalid for " << instrument_descriptor.name_); + } +} + +void LongHistogram::Record(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes, + const opentelemetry::context::Context &context) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN( + "[LongHistogram::Record(V,A,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, attributes, context); +} + +void LongHistogram::Record(uint64_t value, const opentelemetry::context::Context &context) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongHistogram::Record(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordLong(value, context); +} + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +void LongHistogram::Record(uint64_t value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongHistogram::Record(V,A)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + auto context = opentelemetry::context::Context{}; + return storage_->RecordLong(value, attributes, context); +} + +void LongHistogram::Record(uint64_t value) noexcept +{ + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[LongHistogram::Record(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + auto context = opentelemetry::context::Context{}; + return storage_->RecordLong(value, context); +} +#endif + DoubleHistogram::DoubleHistogram(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) @@ -176,9 +352,8 @@ DoubleHistogram::DoubleHistogram(InstrumentDescriptor instrument_descriptor, if (!storage_) { OTEL_INTERNAL_LOG_ERROR( - "[DoubleHistogram::DoubleHistogram] - Error during constructing DoubleHistogram." - << "The metric storage is invalid" - << "No value will be added"); + "[DoubleHistogram::DoubleHistogram] - Error constructing DoubleHistogram." + << "The metric storage is invalid for " << instrument_descriptor.name_); } } @@ -186,15 +361,17 @@ void DoubleHistogram::Record(double value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept { - if (!storage_) + if (value < 0) { + OTEL_INTERNAL_LOG_WARN( + "[DoubleHistogram::Record(V,A,C)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); return; } - if (value < 0 || std::isnan(value) || std::isinf(value)) + if (!storage_) { OTEL_INTERNAL_LOG_WARN( - "[DoubleHistogram::Record(value, attributes)] negative/nan/infinite value provided to " - "histogram Name:" + "[DoubleHistogram::Record(V,A,C)] Value not recorded - invalid storage for: " << instrument_descriptor_.name_); return; } @@ -203,19 +380,63 @@ void DoubleHistogram::Record(double value, void DoubleHistogram::Record(double value, const opentelemetry::context::Context &context) noexcept { + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN( + "[DoubleHistogram::Record(V,C)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } if (!storage_) { + OTEL_INTERNAL_LOG_WARN( + "[DoubleHistogram::Record(V,C)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + return storage_->RecordDouble(value, context); +} + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 +void DoubleHistogram::Record(double value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept +{ + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN( + "[DoubleHistogram::Record(V,A)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); return; } - if (value < 0 || std::isnan(value) || std::isinf(value)) + if (!storage_) { OTEL_INTERNAL_LOG_WARN( - "[DoubleHistogram::Record(value)] negative/nan/infinite value provided to histogram Name:" + "[DoubleHistogram::Record(V,A)] Value not recorded - invalid storage for: " << instrument_descriptor_.name_); return; } + auto context = opentelemetry::context::Context{}; + return storage_->RecordDouble(value, attributes, context); +} + +void DoubleHistogram::Record(double value) noexcept +{ + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN("[DoubleHistogram::Record(V)] Value not recorded - negative value for: " + << instrument_descriptor_.name_); + return; + } + if (!storage_) + { + OTEL_INTERNAL_LOG_WARN("[DoubleHistogram::Record(V)] Value not recorded - invalid storage for: " + << instrument_descriptor_.name_); + return; + } + auto context = opentelemetry::context::Context{}; return storage_->RecordDouble(value, context); } +#endif } // namespace metrics } // namespace sdk diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index a1ff2325e2..723d29f20e 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -24,7 +24,7 @@ TEST(SyncInstruments, LongCounter) InstrumentDescriptor instrument_descriptor = { "long_counter", "description", "1", InstrumentType::kCounter, InstrumentValueType::kLong}; std::unique_ptr metric_storage(new SyncMultiMetricStorage()); - LongCounter counter(instrument_descriptor, std::move(metric_storage)); + LongCounter counter(instrument_descriptor, std::move(metric_storage)); counter.Add(10); counter.Add(10, opentelemetry::context::Context{}); @@ -71,6 +71,18 @@ TEST(SyncInstruments, LongUpDownCounter) counter.Add(10, opentelemetry::common::KeyValueIterableView({})); counter.Add(10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); + + // negative values + counter.Add(-10); + counter.Add(-10, opentelemetry::context::Context{}); + + counter.Add(-10, + opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}})); + counter.Add(-10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{}); + counter.Add(-10, opentelemetry::common::KeyValueIterableView({})); + counter.Add(-10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{}); } TEST(SyncInstruments, DoubleUpDownCounter) @@ -98,9 +110,8 @@ TEST(SyncInstruments, LongHistogram) InstrumentDescriptor instrument_descriptor = { "long_histogram", "description", "1", InstrumentType::kHistogram, InstrumentValueType::kLong}; std::unique_ptr metric_storage(new SyncMultiMetricStorage()); - LongHistogram histogram(instrument_descriptor, std::move(metric_storage)); + LongHistogram histogram(instrument_descriptor, std::move(metric_storage)); histogram.Record(10, opentelemetry::context::Context{}); - histogram.Record(-10, opentelemetry::context::Context{}); // This is ignored histogram.Record(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}),