diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..5abedb62fd --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,69 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +Checks: > + -*, + abseil-*, + -abseil-string-find-str-contains, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-inc-dec-in-conditions, + -bugprone-narrowing-conversions, + -bugprone-unchecked-optional-access, + -bugprone-unhandled-exception-at-new, + -bugprone-unused-local-non-trivial-variable, + -bugprone-unused-return-value, + google-*, + -google-build-using-namespace, + -google-default-arguments, + -google-explicit-constructor, + -google-readability-avoid-underscore-in-googletest-name, + -google-readability-braces-around-statements, + -google-readability-namespace-comments, + -google-readability-todo, + -google-runtime-references, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-non-private-member-variables-in-classes, + -misc-unused-alias-decls, + -misc-use-anonymous-namespace, + performance-*, + -performance-move-const-arg, + portability-* +# readability-*, +# -readability-convert-member-functions-to-static, +# -readability-else-after-return, +# -readability-function-cognitive-complexity, +# -readability-identifier-length, +# -readability-implicit-bool-conversion, +# -readability-isolate-declaration, +# -readability-magic-numbers, +# -readability-named-parameter, +# -readability-redundant-*, +# -readability-string-compare, +# cppcoreguidelines-*, +# -cppcoreguidelines-avoid-c-arrays, +# -cppcoreguidelines-avoid-magic-numbers, +# -cppcoreguidelines-init-variables, +# -cppcoreguidelines-macro-usage, +# -cppcoreguidelines-non-private-member-variables-in-classes, +# -cppcoreguidelines-pro-*, +# modernize-*, +# -modernize-use-default-member-init, +# -modernize-use-nodiscard, +# -modernize-use-trailing-return-type, +# -modernize-avoid-c-arrays, +# -modernize-use-using + +# Use existing clang-format for formatting the code +# FormatStyle: 'file' + +# TODO: include checks: readability, cppcoreguidelines, modernize , google-readability-namespace-comments, google-readability-avoid-underscore-in-googletest-name, performance-move-const-arg + + + + + + diff --git a/api/test/baggage/baggage_benchmark.cc b/api/test/baggage/baggage_benchmark.cc index 0f2efa9939..4ced142327 100644 --- a/api/test/baggage/baggage_benchmark.cc +++ b/api/test/baggage/baggage_benchmark.cc @@ -22,7 +22,7 @@ std::string header_with_custom_entries(size_t num_entries) { std::string key = "ADecentlyLargekey" + std::to_string(i); std::string value = "ADecentlyLargeValue" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != num_entries - 1) { header += ","; diff --git a/api/test/baggage/baggage_test.cc b/api/test/baggage/baggage_test.cc index 9c14fc892f..f29615c983 100644 --- a/api/test/baggage/baggage_test.cc +++ b/api/test/baggage/baggage_test.cc @@ -19,7 +19,7 @@ std::string header_with_custom_entries(size_t num_entries) { std::string key = "key" + std::to_string(i); std::string value = "value" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != num_entries - 1) { header += ","; diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index 94fe8b005b..83de75757b 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -62,7 +62,7 @@ TEST(BaggagePropagatorTest, ExtractAndInjectBaggage) {"invalid_header", ""}, // invalid header {very_large_baggage_header, ""}}; // baggage header larger than allowed size. - for (auto baggage : baggages) + for (const auto &baggage : baggages) { BaggageCarrierTest carrier1; carrier1.headers_[baggage::kBaggageHeader.data()] = baggage.first; diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index e5d9a2439e..f616664265 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -31,7 +31,7 @@ TEST(EntryTest, KeyValueConstruction) TEST(EntryTest, Copy) { KeyValueProperties::Entry e("test_key", "test_value"); - KeyValueProperties::Entry copy(e); + const KeyValueProperties::Entry ©(e); EXPECT_EQ(copy.GetKey(), e.GetKey()); EXPECT_EQ(copy.GetValue(), e.GetValue()); } diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 764dac6477..294f1cd180 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -105,8 +105,8 @@ TEST(ContextTest, ContextCopyOperator) {"foo_key", static_cast(456)}, {"other_key", static_cast(789)}}; - context::Context test_context = context::Context(test_map); - context::Context copied_context = test_context; + context::Context test_context = context::Context(test_map); + const context::Context &copied_context = test_context; EXPECT_EQ(nostd::get(copied_context.GetValue("test_key")), 123); EXPECT_EQ(nostd::get(copied_context.GetValue("foo_key")), 456); @@ -135,7 +135,7 @@ TEST(ContextTest, ContextCopyCompare) { std::map map_test = {{"test_key", static_cast(123)}}; context::Context context_test = context::Context(map_test); - context::Context copied_test = context_test; + const context::Context &copied_test = context_test; EXPECT_TRUE(context_test == copied_test); } diff --git a/api/test/context/runtime_context_test.cc b/api/test/context/runtime_context_test.cc index c2ec732fe0..cd551c599c 100644 --- a/api/test/context/runtime_context_test.cc +++ b/api/test/context/runtime_context_test.cc @@ -113,6 +113,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder) indices.push_back(3); std::vector contexts; + contexts.reserve(indices.size()); for (auto i : indices) { contexts.push_back(context::Context("index", static_cast(i))); @@ -122,6 +123,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder) { std::vector> tokens; + tokens.reserve(contexts.size()); for (auto &c : contexts) { tokens.push_back(context::RuntimeContext::Attach(c)); diff --git a/api/test/logs/logger_benchmark.cc b/api/test/logs/logger_benchmark.cc index 098b9c7df8..db225d496a 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -16,13 +16,8 @@ #include using opentelemetry::logs::EventId; -using opentelemetry::logs::Logger; -using opentelemetry::logs::LoggerProvider; using opentelemetry::logs::Provider; using opentelemetry::logs::Severity; -using opentelemetry::nostd::shared_ptr; -using opentelemetry::nostd::span; -using opentelemetry::nostd::string_view; namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; @@ -66,7 +61,7 @@ class Barrier static void ThreadRoutine(Barrier &barrier, benchmark::State &state, int thread_id, - std::function func) + const std::function &func) { barrier.Wait(); @@ -87,7 +82,7 @@ static void ThreadRoutine(Barrier &barrier, barrier.Wait(); } -void MultiThreadRunner(benchmark::State &state, std::function func) +void MultiThreadRunner(benchmark::State &state, const std::function &func) { int num_threads = std::thread::hardware_concurrency(); @@ -95,6 +90,7 @@ void MultiThreadRunner(benchmark::State &state, std::function func) std::vector threads; + threads.reserve(num_threads); for (int i = 0; i < num_threads; i++) { threads.emplace_back(ThreadRoutine, std::ref(barrier), std::ref(state), i, func); diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 43d7afc685..848f053453 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -16,7 +16,6 @@ using opentelemetry::logs::LoggerProvider; using opentelemetry::logs::Provider; using opentelemetry::logs::Severity; using opentelemetry::nostd::shared_ptr; -using opentelemetry::nostd::span; using opentelemetry::nostd::string_view; namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index 878c5e9a3b..b8fb083799 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -6,7 +6,6 @@ #include "opentelemetry/metrics/provider.h" #include "opentelemetry/nostd/shared_ptr.h" -using opentelemetry::metrics::Meter; using opentelemetry::metrics::MeterProvider; using opentelemetry::metrics::NoopMeterProvider; using opentelemetry::metrics::Provider; diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 0c79c7efd2..5c290c6284 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -63,7 +63,7 @@ TEST(SharedPtrTest, MoveConstruction) auto value = new int{123}; shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -72,7 +72,7 @@ TEST(SharedPtrTest, MoveConstructionFromDifferentType) auto value = new int{123}; shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -81,14 +81,14 @@ TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr) auto value = new int{123}; std::shared_ptr ptr1{value}; shared_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } TEST(SharedPtrTest, Destruction) { bool was_destructed; - shared_ptr{new A{was_destructed}}; + shared_ptr{new A{was_destructed}}; // NOLINT EXPECT_TRUE(was_destructed); } @@ -173,7 +173,7 @@ static void SharedPtrTest_Sort(size_t size = 10) auto nums2 = nums; std::sort(nums.begin(), nums.end(), - [](shared_ptr a, shared_ptr b) { return *a < *b; }); + [](const shared_ptr &a, const shared_ptr &b) { return *a < *b; }); EXPECT_NE(nums, nums2); diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index f3684be0b8..893525c266 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -49,7 +49,7 @@ TEST(UniquePtrTest, MoveConstruction) auto value = new int{123}; unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -58,7 +58,7 @@ TEST(UniquePtrTest, MoveConstructionFromDifferentType) auto value = new int{123}; unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } @@ -67,14 +67,14 @@ TEST(UniquePtrTest, MoveConstructionFromStdUniquePtr) auto value = new int{123}; std::unique_ptr ptr1{value}; unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); } TEST(UniquePtrTest, Destruction) { bool was_destructed; - unique_ptr{new A{was_destructed}}; + unique_ptr{new A{was_destructed}}; // NOLINT EXPECT_TRUE(was_destructed); } @@ -83,13 +83,13 @@ TEST(UniquePtrTest, StdUniquePtrConversionOperator) auto value = new int{123}; unique_ptr ptr1{value}; std::unique_ptr ptr2{std::move(ptr1)}; - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); value = new int{456}; ptr1 = unique_ptr{value}; ptr2 = std::move(ptr1); - EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr1.get(), nullptr); // NOLINT EXPECT_EQ(ptr2.get(), value); ptr2 = nullptr; diff --git a/api/test/trace/trace_state_test.cc b/api/test/trace/trace_state_test.cc index 7f5a05cfe6..e6ed73c1f4 100644 --- a/api/test/trace/trace_state_test.cc +++ b/api/test/trace/trace_state_test.cc @@ -20,7 +20,7 @@ const char *kLongString = // -------------------------- TraceState class tests --------------------------- -std::string create_ts_return_header(std::string header) +std::string create_ts_return_header(const std::string &header) { auto ts = TraceState::FromHeader(header); return ts->ToHeader(); @@ -34,7 +34,7 @@ std::string header_with_max_members() { std::string key = "key" + std::to_string(i); std::string value = "value" + std::to_string(i); - header += key + "=" + value; + header.append(key).append("=").append(value); if (i != max_members - 1) { header += ","; diff --git a/examples/etw_threads/main.cc b/examples/etw_threads/main.cc index d25883d1d1..e5b8dbac9f 100644 --- a/examples/etw_threads/main.cc +++ b/examples/etw_threads/main.cc @@ -113,7 +113,7 @@ void beep() // Max number of threads to spawn constexpr int kMaxThreads = 10; -int main(int arc, char **argv) +int main(int /*arc*/, char ** /*argv*/) { std::thread pool[kMaxThreads]; diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index b8f233dcc7..9ca41c6958 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -20,7 +20,6 @@ using grpc::Channel; using grpc::ClientContext; -using grpc::ClientReader; using grpc::Status; using grpc_example::Greeter; @@ -34,7 +33,7 @@ using namespace opentelemetry::trace; class GreeterClient { public: - GreeterClient(std::shared_ptr channel) : stub_(Greeter::NewStub(channel)) {} + GreeterClient(const std::shared_ptr &channel) : stub_(Greeter::NewStub(channel)) {} std::string Greet(std::string ip, uint16_t port) { @@ -77,7 +76,7 @@ class GreeterClient } else { - std::cout << status.error_code() << ": " << status.error_message() << std::endl; + std::cout << status.error_code() << ": " << status.error_message() << '\n'; span->SetStatus(StatusCode::kError); span->SetAttribute(SemanticConventions::kRpcGrpcStatusCode, status.error_code()); // Make sure to end your spans! @@ -95,7 +94,7 @@ void RunClient(uint16_t port) GreeterClient greeter( grpc::CreateChannel("0.0.0.0:" + std::to_string(port), grpc::InsecureChannelCredentials())); std::string response = greeter.Greet("0.0.0.0", port); - std::cout << "grpc_server says: " << response << std::endl; + std::cout << "grpc_server says: " << response << '\n'; } } // namespace diff --git a/examples/grpc/server.cc b/examples/grpc/server.cc index a8fac8b5f0..3c3fcede4f 100644 --- a/examples/grpc/server.cc +++ b/examples/grpc/server.cc @@ -27,7 +27,6 @@ using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; -using grpc::ServerWriter; using grpc::Status; using grpc_example::Greeter; @@ -49,7 +48,7 @@ class GreeterServer final : public Greeter::Service const GreetRequest *request, GreetResponse *response) override { - for (auto elem : context->client_metadata()) + for (const auto &elem : context->client_metadata()) { std::cout << "ELEM: " << elem.first << " " << elem.second << "\n"; } @@ -78,8 +77,8 @@ class GreeterServer final : public Greeter::Service // Fetch and parse whatever HTTP headers we can from the gRPC request. span->AddEvent("Processing client attributes"); - std::string req = request->request(); - std::cout << std::endl << "grpc_client says: " << req << std::endl; + const std::string &req = request->request(); + std::cout << '\n' << "grpc_client says: " << req << '\n'; std::string message = "The pleasure is mine."; // Send response to client response->set_response(message); @@ -102,7 +101,7 @@ void RunServer(uint16_t port) builder.AddListeningPort(address, grpc::InsecureServerCredentials()); std::unique_ptr server(builder.BuildAndStart()); - std::cout << "Server listening on port: " << address << std::endl; + std::cout << "Server listening on port: " << address << '\n'; server->Wait(); server->Shutdown(); } diff --git a/examples/logs_simple/main.cc b/examples/logs_simple/main.cc index 35827b6502..444775dc59 100644 --- a/examples/logs_simple/main.cc +++ b/examples/logs_simple/main.cc @@ -53,7 +53,7 @@ void InitTracer() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; trace_api::Provider::SetTracerProvider(api_provider); } @@ -79,7 +79,7 @@ void InitLogger() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global logger provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; logs_api::Provider::SetLoggerProvider(api_provider); } diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index ceb7cdfcf9..d99d77de7d 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -70,29 +70,29 @@ void dumpSpans(std::vector> &spans) char span_buf[trace_api::SpanId::kSize * 2]; char trace_buf[trace_api::TraceId::kSize * 2]; char parent_span_buf[trace_api::SpanId::kSize * 2]; - std::cout << "\nSpans from memory :" << std::endl; + std::cout << "\nSpans from memory :" << '\n'; for (auto &span : spans) { - std::cout << "\n\tSpan: " << std::endl; - std::cout << "\t\tName: " << span->GetName() << std::endl; + std::cout << "\n\tSpan: " << '\n'; + std::cout << "\t\tName: " << span->GetName() << '\n'; span->GetSpanId().ToLowerBase16(span_buf); span->GetTraceId().ToLowerBase16(trace_buf); span->GetParentSpanId().ToLowerBase16(parent_span_buf); - std::cout << "\t\tTraceId: " << std::string(trace_buf, sizeof(trace_buf)) << std::endl; - std::cout << "\t\tSpanId: " << std::string(span_buf, sizeof(span_buf)) << std::endl; + std::cout << "\t\tTraceId: " << std::string(trace_buf, sizeof(trace_buf)) << '\n'; + std::cout << "\t\tSpanId: " << std::string(span_buf, sizeof(span_buf)) << '\n'; std::cout << "\t\tParentSpanId: " << std::string(parent_span_buf, sizeof(parent_span_buf)) - << std::endl; + << '\n'; - std::cout << "\t\tDescription: " << span->GetDescription() << std::endl; + std::cout << "\t\tDescription: " << span->GetDescription() << '\n'; std::cout << "\t\tSpan kind:" << static_cast::type>( span->GetSpanKind()) - << std::endl; + << '\n'; std::cout << "\t\tSpan Status: " << static_cast::type>( span->GetStatus()) - << std::endl; + << '\n'; } } } // namespace diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index d92a4ab2ac..675a6053ec 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -55,6 +55,7 @@ void run_threads() auto thread_span = get_tracer()->StartSpan(__func__); std::vector threads; + threads.reserve(5); for (int thread_num = 0; thread_num < 5; ++thread_num) { // This shows how one can effectively use Scope objects to correctly diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 38aa009d04..37bace2b0f 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -71,7 +71,7 @@ void InitTracer() trace_opts.url = opentelemetry::exporter::otlp::GetOtlpDefaultHttpTracesEndpoint(); } } - std::cout << "Using " << trace_opts.url << " to export trace spans." << std::endl; + std::cout << "Using " << trace_opts.url << " to export trace spans." << '\n'; // Create OTLP exporter instance auto exporter = otlp::OtlpHttpExporterFactory::Create(trace_opts); @@ -110,7 +110,7 @@ std::shared_ptr logger_provider; void InitLogger() { - std::cout << "Using " << logger_opts.url << " to export log records." << std::endl; + std::cout << "Using " << logger_opts.url << " to export log records." << '\n'; logger_opts.console_debug = true; // Create OTLP exporter instance auto exporter = otlp::OtlpHttpLogRecordExporterFactory::Create(logger_opts); diff --git a/examples/simple/main.cc b/examples/simple/main.cc index a872816ba1..349aec500a 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -40,7 +40,7 @@ void InitTracer() #endif /* OPENTELEMETRY_DEPRECATED_SDK_FACTORY */ // Set the global trace provider - std::shared_ptr api_provider = provider; + const std::shared_ptr &api_provider = provider; trace_api::Provider::SetTracerProvider(api_provider); } diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h index feb68f7f9c..af4ccb16ef 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -33,13 +33,13 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable */ void WriteKeyValue(nostd::string_view key, const opentelemetry::common::AttributeValue &value, - std::string name); + const std::string &name); void WriteKeyValue(nostd::string_view key, const opentelemetry::sdk::common::OwnedAttributeValue &value, - std::string name); + const std::string &name); - void WriteValue(const opentelemetry::common::AttributeValue &value, std::string name); + void WriteValue(const opentelemetry::common::AttributeValue &value, const std::string &name); public: /** diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 139d22e863..663691273b 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -16,7 +16,7 @@ namespace logs { void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key, const opentelemetry::common::AttributeValue &value, - std::string name) + const std::string &name) { switch (value.index()) { @@ -53,7 +53,7 @@ void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key, void ElasticSearchRecordable::WriteKeyValue( nostd::string_view key, const opentelemetry::sdk::common::OwnedAttributeValue &value, - std::string name) + const std::string &name) { namespace common = opentelemetry::sdk::common; switch (value.index()) @@ -85,7 +85,7 @@ void ElasticSearchRecordable::WriteKeyValue( } void ElasticSearchRecordable::WriteValue(const opentelemetry::common::AttributeValue &value, - std::string name) + const std::string &name) { // Assert size of variant to ensure that this method gets updated if the variant diff --git a/exporters/memory/test/in_memory_span_data_test.cc b/exporters/memory/test/in_memory_span_data_test.cc index bc19550264..be013734ef 100644 --- a/exporters/memory/test/in_memory_span_data_test.cc +++ b/exporters/memory/test/in_memory_span_data_test.cc @@ -8,7 +8,6 @@ #include using opentelemetry::exporter::memory::InMemorySpanData; -using opentelemetry::sdk::trace::Recordable; using opentelemetry::sdk::trace::SpanData; TEST(InMemorySpanData, AddRecordable) diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h index 24bc8e5be7..840d7d5b8a 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -66,10 +66,10 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor bool isShutdown() const noexcept; void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); }; } // namespace logs } // namespace exporter diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h index 1ad124a9ab..f1b2cd6ef9 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h @@ -79,7 +79,7 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr void printPointData(const opentelemetry::sdk::metrics::PointType &point_data); void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes); void printAttributes(const std::map &map, - const std::string prefix); + const std::string &prefix); void printResources(const opentelemetry::sdk::resource::Resource &resources); }; } // namespace metrics diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index a7de9a5eb4..e22eb77f3e 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -69,7 +69,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter // various print helpers void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printEvents(const std::vector &events); diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 7f661276c8..26266161c3 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -75,11 +75,11 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( // Convert trace, spanid, traceflags into exportable representation constexpr int trace_id_len = 32; - constexpr int span_id__len = 16; + constexpr int span_id_len = 16; constexpr int trace_flags_len = 2; char trace_id[trace_id_len] = {0}; - char span_id[span_id__len] = {0}; + char span_id[span_id_len] = {0}; char trace_flags[trace_flags_len] = {0}; log_record->GetTraceId().ToLowerBase16(trace_id); @@ -120,7 +120,7 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( << " event_id : " << event_id << "\n" << " event_name : " << log_record->GetEventName() << "\n" << " trace_id : " << std::string(trace_id, trace_id_len) << "\n" - << " span_id : " << std::string(span_id, span_id__len) << "\n" + << " span_id : " << std::string(span_id, span_id_len) << "\n" << " trace_flags : " << std::string(trace_flags, trace_flags_len) << "\n" << " scope : \n" << " name : " << log_record->GetInstrumentationScope().GetName() << "\n" @@ -155,7 +155,7 @@ bool OStreamLogRecordExporter::isShutdown() const noexcept void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -166,7 +166,7 @@ void OStreamLogRecordExporter::printAttributes( void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 08bfe340c7..4bdd122492 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -117,7 +117,7 @@ sdk::common::ExportResult OStreamMetricExporter::Export( void OStreamMetricExporter::printAttributes( const std::map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index 9437ae561a..f41d33ae6c 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -100,7 +100,7 @@ sdk::common::ExportResult OStreamSpanExporter::Export( << "\n duration : " << span->GetDuration().count() << "\n description : " << span->GetDescription() << "\n span kind : " << span->GetSpanKind() - << "\n status : " << statusMap[int(span->GetStatus())] + << "\n status : " << statusMap[static_cast(span->GetStatus())] << "\n attributes : "; printAttributes(span->GetAttributes()); sout_ << "\n events : "; @@ -137,7 +137,7 @@ bool OStreamSpanExporter::isShutdown() const noexcept void OStreamSpanExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -177,7 +177,7 @@ void OStreamSpanExporter::printLinks(const std::vector void OStreamSpanExporter::printResources(const opentelemetry::sdk::resource::Resource &resources) { - auto attributes = resources.GetAttributes(); + const auto &attributes = resources.GetAttributes(); if (attributes.size()) { printAttributes(attributes, "\n\t"); @@ -188,7 +188,7 @@ void OStreamSpanExporter::printInstrumentationScope( const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope) { sout_ << instrumentation_scope.GetName(); - auto version = instrumentation_scope.GetVersion(); + const auto &version = instrumentation_scope.GetVersion(); if (version.size()) { sout_ << "-" << version; diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 7b22d9b3fd..b7708f3153 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -97,17 +97,17 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) std::cout.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -126,7 +126,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -167,9 +167,8 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) std::cout.rdbuf(original); std::vector expected_output{ - "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + + "{\n", + " timestamp : " + std::to_string(now.time_since_epoch().count()) + "\n" " observed_timestamp : " + std::to_string(now.time_since_epoch().count()) + @@ -182,7 +181,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -201,7 +200,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -243,10 +242,10 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) std::cerr.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -256,7 +255,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) " key1: val1\n", " attributes : \n", " a: 1\n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -275,7 +274,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -324,10 +323,10 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) std::clog.rdbuf(original); std::vector expected_output{ - "{\n" + "{\n", " timestamp : 0\n", - " severity_num : 0\n" - " severity_text : INVALID\n" + " severity_num : 0\n", + " severity_text : INVALID\n", " body : \n", " resource : \n", " service.name: unknown_service\n", @@ -337,7 +336,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) " res1: [1,2,3]\n", " attributes : \n", " attr1: [0,1,0]\n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -356,7 +355,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -398,11 +397,10 @@ TEST(OStreamLogRecordExporter, IntegrationTest) // Compare actual vs expected outputs std::vector expected_output{ - "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + "\n", - " severity_num : 5\n" - " severity_text : DEBUG\n" + "{\n", + " timestamp : " + std::to_string(now.time_since_epoch().count()) + "\n", + " severity_num : 5\n", + " severity_text : DEBUG\n", " body : Hello\n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -410,7 +408,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 0\n" + " event_id : 0\n", " event_name : \n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -429,7 +427,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } @@ -472,8 +470,8 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) // Compare actual vs expected outputs std::vector expected_output{ - " severity_num : 5\n" - " severity_text : DEBUG\n" + " severity_num : 5\n", + " severity_text : DEBUG\n", " body : Hello {key1} {key2}\n", " resource : \n", " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", @@ -481,7 +479,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", - " event_id : 12345678\n" + " event_id : 12345678\n", " event_name : test_event_id\n", " trace_id : 00000000000000000000000000000000\n", " span_id : 0000000000000000\n", @@ -500,7 +498,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) std::string::size_type result = ostream_output.find(expected); if (result == std::string::npos) { - std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << std::endl; + std::cout << "Can not find: \"" << expected << "\" in\n" << ostream_output << '\n'; } ASSERT_NE(result, std::string::npos); } diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index f92f1bbffd..cadc1b9d38 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -31,7 +31,7 @@ using Attributes = std::initializer_listEXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } \ else \ { \ - VAR = tm_obj_ptr->EXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } for (size_t i = 0; i < fmt.size() && ret < bufz && running; ++i) @@ -619,7 +619,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL FileSystemUtil } #if !defined(UTIL_FS_DISABLE_LINK) - enum class LinkOption : int32_t + enum class LinkOption : uint8_t { kDefault = 0x00, // hard link for default kSymbolicLink = 0x01, // or soft link @@ -749,6 +749,7 @@ static void ConvertListFieldToJson(nlohmann::json &value, const google::protobuf::Message &message, const google::protobuf::FieldDescriptor *field_descriptor); +// NOLINTBEGIN(misc-no-recursion) static void ConvertGenericMessageToJson(nlohmann::json &value, const google::protobuf::Message &message) { @@ -952,6 +953,8 @@ void ConvertListFieldToJson(nlohmann::json &value, } } +// NOLINTEND(misc-no-recursion) suppressing for performance as if implemented with stack needs +// Dynamic memory allocation } // namespace class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 3410726cf8..a5760bdd81 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -132,7 +132,7 @@ static std::string GetFileContentsOrInMemoryContents(const std::string &file_pat #ifdef ENABLE_ASYNC_EXPORT template static sdk::common::ExportResult InternalDelegateAsyncExport( - std::shared_ptr async_data, + const std::shared_ptr &async_data, StubType *stub, std::unique_ptr &&context, std::unique_ptr &&arena, @@ -163,8 +163,8 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( call_data->arena.swap(arena); call_data->result_callback.swap(result_callback); - call_data->request = - google::protobuf::Arena::Create(call_data->arena.get(), std::move(request)); + call_data->request = google::protobuf::Arena::Create( + call_data->arena.get(), std::forward(request)); call_data->response = google::protobuf::Arena::Create(call_data->arena.get()); if (call_data->request == nullptr || call_data->response == nullptr) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 03eb5fb434..94f02a9967 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -434,6 +434,7 @@ static void ConvertListFieldToJson(nlohmann::json &value, const google::protobuf::FieldDescriptor *field_descriptor, const OtlpHttpClientOptions &options); +// NOLINTBEGIN(misc-no-recursion) static void ConvertGenericMessageToJson(nlohmann::json &value, const google::protobuf::Message &message, const OtlpHttpClientOptions &options) @@ -654,6 +655,9 @@ void ConvertListFieldToJson(nlohmann::json &value, } } +// NOLINTEND(misc-no-recursion) suppressing for performance, if implemented iterative process needs +// Dynamic memory allocation + } // namespace OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) @@ -696,7 +700,7 @@ OtlpHttpClient::~OtlpHttpClient() OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, std::shared_ptr http_client) - : is_shutdown_(false), options_(options), http_client_(http_client) + : is_shutdown_(false), options_(options), http_client_(std::move(http_client)) { http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); } @@ -881,7 +885,7 @@ OtlpHttpClient::createSession( std::string error_message = "[OTLP HTTP Client] Export failed, invalid url: " + options_.url; if (options_.console_debug) { - std::cerr << error_message << std::endl; + std::cerr << error_message << '\n'; } OTEL_INTERNAL_LOG_ERROR(error_message.c_str()); @@ -946,7 +950,7 @@ OtlpHttpClient::createSession( const char *error_message = "[OTLP HTTP Client] Export failed, exporter is shutdown"; if (options_.console_debug) { - std::cerr << error_message << std::endl; + std::cerr << error_message << '\n'; } OTEL_INTERNAL_LOG_ERROR(error_message); diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index e4f69f502b..4c4a6dbeb2 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -58,8 +58,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t options.content_type = content_type; options.console_debug = true; options.timeout = std::chrono::system_clock::duration::zero(); - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -158,34 +157,35 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); - ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); - if (user_agent_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); - } - - // let the otlp_http_client to continue - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); + ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); + if (user_agent_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); + } + + // let the otlp_http_client to continue + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); @@ -249,38 +249,39 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); - ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); - if (user_agent_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); - } - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); + ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); + if (user_agent_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); + } + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); child_span->End(); parent_span->End(); @@ -343,25 +344,27 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto received_trace_id = + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); @@ -424,30 +427,32 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto received_trace_id = + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); child_span->End(); parent_span->End(); diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 5fbf95798f..35a0bb62e2 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -57,8 +57,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t OtlpHttpLogRecordExporterOptions options; options.content_type = content_type; options.console_debug = true; - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -151,46 +150,47 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resourceLogs"].begin(); - auto scope_logs = *resource_logs["scopeLogs"].begin(); - auto scope = scope_logs["scope"]; - auto log = *scope_logs["logRecords"].begin(); - auto received_trace_id = log["traceId"].get(); - auto received_span_id = log["spanId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log message", log["body"]["stringValue"].get()); - EXPECT_LE(15, log["attributes"].size()); - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - bool check_scope_attribute = false; - auto scope_attributes = scope["attributes"]; - for (auto &attribute : scope_attributes) - { - if (!attribute.is_object()) - { - continue; - } - if ("scope_key1" == attribute["key"]) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); - } - } - ASSERT_TRUE(check_scope_attribute); - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); + auto scope = scope_logs["scope"]; + auto log = *scope_logs["logRecords"].begin(); + auto received_trace_id = log["traceId"].get(); + auto received_span_id = log["spanId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + EXPECT_EQ(received_span_id, report_span_id); + EXPECT_EQ("Log message", log["body"]["stringValue"].get()); + EXPECT_LE(15, log["attributes"].size()); + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + bool check_scope_attribute = false; + auto scope_attributes = scope["attributes"]; + for (auto &attribute : scope_attributes) + { + if (!attribute.is_object()) + { + continue; + } + if ("scope_key1" == attribute["key"]) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); + } + } + ASSERT_TRUE(check_scope_attribute); + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -268,57 +268,58 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resourceLogs"].begin(); - auto scope_logs = *resource_logs["scopeLogs"].begin(); - auto schema_url = scope_logs["schemaUrl"].get(); - auto scope = scope_logs["scope"]; - auto scope_name = scope["name"]; - auto scope_version = scope["version"]; - auto log = *scope_logs["logRecords"].begin(); - auto received_trace_id = log["traceId"].get(); - auto received_span_id = log["spanId"].get(); - EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0"); - EXPECT_EQ(scope_name, "opentelelemtry_library"); - EXPECT_EQ(scope_version, "1.2.0"); - EXPECT_EQ(received_trace_id, report_trace_id); - EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log message", log["body"]["stringValue"].get()); - EXPECT_LE(15, log["attributes"].size()); - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - bool check_scope_attribute = false; - auto scope_attributes = scope["attributes"]; - for (auto &attribute : scope_attributes) - { - if (!attribute.is_object()) - { - continue; - } - if ("scope_key1" == attribute["key"]) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); + auto schema_url = scope_logs["schemaUrl"].get(); + auto scope = scope_logs["scope"]; + auto scope_name = scope["name"]; + auto scope_version = scope["version"]; + auto log = *scope_logs["logRecords"].begin(); + auto received_trace_id = log["traceId"].get(); + auto received_span_id = log["spanId"].get(); + EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0"); + EXPECT_EQ(scope_name, "opentelelemtry_library"); + EXPECT_EQ(scope_version, "1.2.0"); + EXPECT_EQ(received_trace_id, report_trace_id); + EXPECT_EQ(received_span_id, report_span_id); + EXPECT_EQ("Log message", log["body"]["stringValue"].get()); + EXPECT_LE(15, log["attributes"].size()); + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + bool check_scope_attribute = false; + auto scope_attributes = scope["attributes"]; + for (auto &attribute : scope_attributes) + { + if (!attribute.is_object()) + { + continue; + } + if ("scope_key1" == attribute["key"]) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -390,47 +391,49 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto scope_log = request_body.resource_logs(0).scope_logs(0); - EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); - EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); - EXPECT_EQ(scope_log.scope().version(), "1.2.0"); - auto received_log = scope_log.log_records(0); - EXPECT_EQ(received_log.trace_id(), report_trace_id); - EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log message", received_log.body().string_value()); - EXPECT_LE(15, received_log.attributes_size()); - bool check_service_name = false; - for (auto &attribute : received_log.attributes()) - { - if ("service.name" == attribute.key()) - { - check_service_name = true; - EXPECT_EQ("unit_test_service", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_service_name); - - bool check_scope_attribute = false; - for (auto &attribute : scope_log.scope().attributes()) - { - if ("scope_key1" == attribute.key()) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto scope_log = request_body.resource_logs(0).scope_logs(0); + EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); + EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); + EXPECT_EQ(scope_log.scope().version(), "1.2.0"); + const auto &received_log = scope_log.log_records(0); + EXPECT_EQ(received_log.trace_id(), report_trace_id); + EXPECT_EQ(received_log.span_id(), report_span_id); + EXPECT_EQ("Log message", received_log.body().string_value()); + EXPECT_LE(15, received_log.attributes_size()); + bool check_service_name = false; + for (auto &attribute : received_log.attributes()) + { + if ("service.name" == attribute.key()) + { + check_service_name = true; + EXPECT_EQ("unit_test_service", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_service_name); + + bool check_scope_attribute = false; + for (auto &attribute : scope_log.scope().attributes()) + { + if ("scope_key1" == attribute.key()) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -503,51 +506,53 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id, schema_url]( - std::shared_ptr callback) { - opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto &scope_log = request_body.resource_logs(0).scope_logs(0); - auto received_log = scope_log.log_records(0); - EXPECT_EQ(received_log.trace_id(), report_trace_id); - EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log message", received_log.body().string_value()); - EXPECT_LE(15, received_log.attributes_size()); - bool check_service_name = false; - for (auto &attribute : received_log.attributes()) - { - if ("service.name" == attribute.key()) - { - check_service_name = true; - EXPECT_EQ("unit_test_service", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_service_name); - - auto &scope = scope_log.scope(); - EXPECT_EQ(scope.name(), "opentelelemtry_library"); - EXPECT_EQ(scope_log.schema_url(), schema_url); - bool check_scope_attribute = false; - for (auto &attribute : scope.attributes()) - { - if ("scope_key1" == attribute.key()) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - - std::thread async_finish{[callback]() { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - http_client::nosend::Response response; - response.Finish(*callback.get()); - }}; - async_finish.detach(); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id, schema_url]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto &scope_log = request_body.resource_logs(0).scope_logs(0); + auto received_log = scope_log.log_records(0); + EXPECT_EQ(received_log.trace_id(), report_trace_id); + EXPECT_EQ(received_log.span_id(), report_span_id); + EXPECT_EQ("Log message", received_log.body().string_value()); + EXPECT_LE(15, received_log.attributes_size()); + bool check_service_name = false; + for (auto &attribute : received_log.attributes()) + { + if ("service.name" == attribute.key()) + { + check_service_name = true; + EXPECT_EQ("unit_test_service", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_service_name); + + auto &scope = scope_log.scope(); + EXPECT_EQ(scope.name(), "opentelelemtry_library"); + EXPECT_EQ(scope_log.schema_url(), schema_url); + bool check_scope_attribute = false; + for (auto &attribute : scope.attributes()) + { + if ("scope_key1" == attribute.key()) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + + std::thread async_finish{[callback]() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + http_client::nosend::Response response; + response.Finish(*callback.get()); + }}; + async_finish.detach(); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 1e5fe6469f..174597248b 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -64,8 +64,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t OtlpHttpMetricExporterOptions options; options.content_type = content_type; options.console_debug = true; - options.http_headers.insert( - std::make_pair("Custom-Header-Key", "Custom-Header-Value")); + options.http_headers.insert(std::make_pair("Custom-Header-Key", "Custom-Header-Value")); OtlpHttpClientOptions otlp_http_client_options( options.url, false, /* ssl_insecure_skip_verify */ "", /* ssl_ca_cert_path */ "", /* ssl_ca_cert_string */ @@ -154,36 +153,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["sum"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["sum"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -237,7 +237,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -335,36 +336,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["gauge"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["gauge"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -427,7 +429,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -530,71 +533,72 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["histogram"]["dataPoints"]; - EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); - EXPECT_EQ(900.5, data_points[0]["sum"].get()); - EXPECT_EQ(1.8, data_points[0]["min"].get()); - EXPECT_EQ(19, data_points[0]["max"].get()); - EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); - if (4 == data_points[0]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); - if (3 == data_points[0]["explicitBounds"].size()) - { - EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); - EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); - EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); - } - - EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); - EXPECT_EQ(900.0, data_points[1]["sum"].get()); - EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); - if (4 == data_points[1]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); - if (3 == data_points[1]["explicitBounds"].size()) - { - EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); - EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); - EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); - } - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["histogram"]["dataPoints"]; + EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); + EXPECT_EQ(900.5, data_points[0]["sum"].get()); + EXPECT_EQ(1.8, data_points[0]["min"].get()); + EXPECT_EQ(19, data_points[0]["max"].get()); + EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); + if (4 == data_points[0]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); + if (3 == data_points[0]["explicitBounds"].size()) + { + EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); + EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); + EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); + } + + EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); + EXPECT_EQ(900.0, data_points[1]["sum"].get()); + EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); + if (4 == data_points[1]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); + if (3 == data_points[1]["explicitBounds"].size()) + { + EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); + EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); + EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); + } + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -661,7 +665,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index b945cb28fe..2ad76dfd1d 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -200,7 +200,7 @@ TEST(OtlpMetricSerializationTest, Counter) EXPECT_EQ(sum.is_monotonic(), true); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = sum.data_points(i); + const auto &proto_number_point = sum.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 10.2 : 20.2); } @@ -230,7 +230,7 @@ TEST(OtlpMetricSerializationTest, Histogram) proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = histogram.data_points(i); + const auto &proto_number_point = histogram.data_points(i); EXPECT_EQ(proto_number_point.sum(), i == 0 ? 100.2 : 200.2); } @@ -244,7 +244,7 @@ TEST(OtlpMetricSerializationTest, ObservableGauge) otlp_exporter::OtlpMetricUtils::ConvertGaugeMetric(data, &gauge); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = gauge.data_points(i); + const auto &proto_number_point = gauge.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 30.2 : 50.2); } diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index caa17c8a46..537f10340d 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -216,7 +216,7 @@ TEST(OtlpRecordable, SetResource) bool found_service_name = false; for (int i = 0; i < proto_resource.attributes_size(); i++) { - auto attr = proto_resource.attributes(static_cast(i)); + const auto &attr = proto_resource.attributes(static_cast(i)); if (attr.key() == service_name_key && attr.value().string_value() == service_name) { found_service_name = true; @@ -322,7 +322,7 @@ TEST(OtlpRecordable, PopulateRequest) OtlpRecordableUtils::PopulateRequest(spans_span, &req); EXPECT_EQ(req.resource_spans().size(), 2); - for (auto resource_spans : req.resource_spans()) + for (const auto &resource_spans : req.resource_spans()) { auto service_name = resource_spans.resource().attributes(0).value().string_value(); auto scope_spans_size = resource_spans.scope_spans().size(); @@ -359,7 +359,7 @@ TEST(OtlpRecordable, PopulateRequestMissing) OtlpRecordableUtils::PopulateRequest(spans_span, &req); EXPECT_EQ(req.resource_spans().size(), 2); - for (auto resource_spans : req.resource_spans()) + for (const auto &resource_spans : req.resource_spans()) { // Both should have scope spans EXPECT_EQ(resource_spans.scope_spans().size(), 1); diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 68d8586bcc..35ee748273 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -88,7 +88,7 @@ inline std::string Sanitize(std::string name, const T &valid) */ std::string SanitizeLabel(std::string label_key) { - return Sanitize(label_key, [](int i, char c) { + return Sanitize(std::move(label_key), [](int i, char c) { return (c >= 'a' && c <= 'z') || // (c >= 'A' && c <= 'Z') || // c == '_' || // @@ -396,7 +396,7 @@ std::string PrometheusExporterUtils::RemoveUnitPortionInBraces(const std::string std::string PrometheusExporterUtils::ConvertRateExpressedToPrometheusUnit( const std::string &rate_expressed_unit) { - size_t pos = rate_expressed_unit.find("/"); + size_t pos = rate_expressed_unit.find('/'); if (pos == std::string::npos) { return rate_expressed_unit; diff --git a/exporters/prometheus/test/exporter_test.cc b/exporters/prometheus/test/exporter_test.cc index 3bda4c3d7b..b268ac8514 100644 --- a/exporters/prometheus/test/exporter_test.cc +++ b/exporters/prometheus/test/exporter_test.cc @@ -16,7 +16,6 @@ * private constructor is only to be used here for testing */ -using opentelemetry::exporter::metrics::PrometheusCollector; using opentelemetry::exporter::metrics::PrometheusExporter; using opentelemetry::exporter::metrics::PrometheusExporterOptions; using opentelemetry::sdk::metrics::AggregationTemporality; diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index b876e7369c..7ad5eee1fd 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include + +#include #include "prometheus/metric_family.h" #include "prometheus/metric_type.h" @@ -24,7 +26,7 @@ class SanitizeNameTester public: static std::string sanitize(std::string name) { - return PrometheusExporterUtils::SanitizeNames(name); + return PrometheusExporterUtils::SanitizeNames(std::move(name)); } static std::string getPrometheusUnit(const std::string &unit_abbreviation) { @@ -104,14 +106,13 @@ void assert_basic(prometheus_client::MetricFamily &metric, ASSERT_TRUE(false); break; case prometheus::MetricType::Untyped: - break; default: break; } } void assert_histogram(prometheus_client::MetricFamily &metric, - std::list boundaries, + const std::list &boundaries, std::vector correct) { int cumulative_count = 0; diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index e6d3ce8b26..a554cbf4cc 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// NOLINTNEXTLINE #define _WINSOCKAPI_ // stops including winsock.h #include @@ -105,7 +106,6 @@ sdk::common::ExportResult ZipkinExporter::Export( } return sdk::common::ExportResult::kFailure; } - return sdk::common::ExportResult::kSuccess; } void ZipkinExporter::InitializeLocalEndpoint() diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index 18c47bcab5..8e58f83d2e 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -17,6 +17,7 @@ # include "nlohmann/json.hpp" # include +# include # if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" @@ -47,7 +48,7 @@ class ZipkinExporterTestPeer : public ::testing::Test std::unique_ptr GetExporter( std::shared_ptr http_client) { - return std::unique_ptr(new ZipkinExporter(http_client)); + return std::unique_ptr(new ZipkinExporter(std::move(http_client))); } // Get the options associated with the given exporter. diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h index 58dd154bb7..b6654ce3ad 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h @@ -124,7 +124,8 @@ class HttpOperation double ulnow); #endif public: - void DispatchEvent(opentelemetry::ext::http::client::SessionState type, std::string reason = ""); + void DispatchEvent(opentelemetry::ext::http::client::SessionState type, + const std::string &reason = ""); /** * Create local CURL instance for url and body diff --git a/ext/src/dll/dllmain.cc b/ext/src/dll/dllmain.cc index 1812377374..df1d2bc70d 100644 --- a/ext/src/dll/dllmain.cc +++ b/ext/src/dll/dllmain.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include +#include // NOLINT // Include API header files here for exporting #include diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 38ca2e7348..67b0b93a54 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -562,7 +562,7 @@ bool HttpClient::doAbortSessions() } bool has_data = false; - for (auto session : pending_to_abort_sessions) + for (const auto &session : pending_to_abort_sessions) { if (!session.second) { diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index f82c17ccc5..4de014fd82 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -240,7 +240,7 @@ int HttpOperation::OnProgressCallback(void *clientp, #endif void HttpOperation::DispatchEvent(opentelemetry::ext::http::client::SessionState type, - std::string reason) + const std::string &reason) { if (event_handle_ != nullptr) { @@ -273,7 +273,7 @@ HttpOperation::HttpOperation(opentelemetry::ext::http::client::Method method, last_curl_result_(CURLE_OK), event_handle_(event_handle), method_(method), - url_(url), + url_(std::move(url)), ssl_options_(ssl_options), // Local vars request_headers_(request_headers), @@ -453,7 +453,7 @@ void HttpOperation::Cleanup() # define HAVE_TLS_VERSION #endif -static long parse_min_ssl_version(std::string version) +static long parse_min_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.2") @@ -470,7 +470,7 @@ static long parse_min_ssl_version(std::string version) return 0; } -static long parse_max_ssl_version(std::string version) +static long parse_max_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.2") diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 6e30323eeb..0dc6e5d5e8 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #define HTTP_PORT 19000 @@ -74,7 +75,9 @@ class PostEventHandler : public CustomEventHandler class FinishInCallbackHandler : public CustomEventHandler { public: - FinishInCallbackHandler(std::shared_ptr session) : session_(session) {} + FinishInCallbackHandler(std::shared_ptr session) + : session_(std::move(session)) + {} void OnResponse(http_client::Response &response) noexcept override { diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 349626e219..d9819cde0d 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -75,10 +75,10 @@ struct Uri uint16_t port; std::string path; - Uri(std::string uri) + Uri(const std::string &uri) { - size_t host_end = uri.substr(7, std::string::npos).find(":"); - size_t port_end = uri.substr(host_end + 1, std::string::npos).find("/"); + size_t host_end = uri.substr(7, std::string::npos).find(':'); + size_t port_end = uri.substr(host_end + 1, std::string::npos).find('/'); host = uri.substr(0, host_end + 7); port = std::stoi(uri.substr(7 + host_end + 1, port_end)); diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 4f6c144a43..ece1588425 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -39,7 +39,7 @@ const int TEST_FAILED = 1; Command line parameters. */ -enum test_mode +enum test_mode : std::uint8_t { MODE_NONE, MODE_HTTP, @@ -84,7 +84,7 @@ struct TestResult struct TestResult g_test_result; -void parse_error_msg(TestResult *result, std::string msg) +void parse_error_msg(TestResult *result, const std::string &msg) { static std::string connection_failed("Session state: connection failed."); @@ -129,11 +129,11 @@ void parse_error_msg(TestResult *result, std::string msg) } } -void parse_warning_msg(TestResult * /* result */, std::string /* msg */) {} +void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_info_msg(TestResult * /* result */, std::string /* msg */) {} +void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_debug_msg(TestResult *result, std::string msg) +void parse_debug_msg(TestResult *result, const std::string &msg) { static std::string export_success("Export 1 trace span(s) success"); @@ -162,19 +162,19 @@ class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandl case opentelemetry::sdk::common::internal_log::LogLevel::None: break; case opentelemetry::sdk::common::internal_log::LogLevel::Error: - std::cout << " - [E] " << msg << std::endl; + std::cout << " - [E] " << msg << '\n'; parse_error_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Warning: - std::cout << " - [W] " << msg << std::endl; + std::cout << " - [W] " << msg << '\n'; parse_warning_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Info: - std::cout << " - [I] " << msg << std::endl; + std::cout << " - [I] " << msg << '\n'; parse_info_msg(&g_test_result, msg); break; case opentelemetry::sdk::common::internal_log::LogLevel::Debug: - std::cout << " - [D] " << msg << std::endl; + std::cout << " - [D] " << msg << '\n'; parse_debug_msg(&g_test_result, msg); break; } @@ -429,12 +429,12 @@ void list_test_cases() while (current->m_func != nullptr) { - std::cout << current->m_name << std::endl; + std::cout << current->m_name << '\n'; current++; } } -int run_test_case(std::string name) +int run_test_case(const std::string &name) { const test_case *current = all_tests; @@ -448,7 +448,7 @@ int run_test_case(std::string name) current++; } - std::cerr << "Unknown test <" << name << ">" << std::endl; + std::cerr << "Unknown test <" << name << ">" << '\n'; return 1; } diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context.h b/sdk/include/opentelemetry/sdk/logs/logger_context.h index bab002b231..11eca41d16 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context.h @@ -34,7 +34,7 @@ class LoggerContext { public: explicit LoggerContext(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index 6c035ad5e9..dd2a52789d 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -38,11 +38,11 @@ class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::Lo * @param resource The resources for this logger provider. */ explicit LoggerProvider(std::unique_ptr &&processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; explicit LoggerProvider(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index 40a57a6f88..fe85fe04cc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -54,7 +54,7 @@ class MeterContext : public std::enable_shared_from_this */ MeterContext( std::unique_ptr views = std::unique_ptr(new ViewRegistry()), - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept; /** @@ -131,7 +131,7 @@ class MeterContext : public std::enable_shared_from_this * * @param meter */ - void AddMeter(std::shared_ptr meter); + void AddMeter(const std::shared_ptr &meter); void RemoveMeter(nostd::string_view name, nostd::string_view version, diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index a838f2a96a..c34f16e0a1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -39,8 +39,8 @@ class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics:: * @param resource The resources for this meter provider. */ MeterProvider( - std::unique_ptr views = std::unique_ptr(new ViewRegistry()), - sdk::resource::Resource resource = sdk::resource::Resource::Create({})) noexcept; + std::unique_ptr views = std::unique_ptr(new ViewRegistry()), + const sdk::resource::Resource &resource = sdk::resource::Resource::Create({})) noexcept; /** * Initialize a new meter provider with a specified context diff --git a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h index 2d01710e47..007b3c74cd 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -40,7 +40,7 @@ class TemporalMetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - std::shared_ptr delta_metrics, + const std::shared_ptr &delta_metrics, nostd::function_ref callback) noexcept; private: diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 1d2c5bf25f..1d5f8dbc55 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -37,7 +37,7 @@ class Synchronous class LongCounter : public Synchronous, public opentelemetry::metrics::Counter { public: - LongCounter(InstrumentDescriptor instrument_descriptor, + LongCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(uint64_t value, @@ -56,7 +56,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter { public: - DoubleCounter(InstrumentDescriptor instrument_descriptor, + DoubleCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(double value, @@ -72,7 +72,7 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter { public: - LongUpDownCounter(InstrumentDescriptor instrument_descriptor, + LongUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(int64_t value, @@ -88,7 +88,7 @@ class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpD class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter { public: - DoubleUpDownCounter(InstrumentDescriptor instrument_descriptor, + DoubleUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); void Add(double value, @@ -104,7 +104,7 @@ class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::U class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: - LongHistogram(InstrumentDescriptor instrument_descriptor, + LongHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); #if OPENTELEMETRY_ABI_VERSION_NO >= 2 @@ -124,7 +124,7 @@ class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogr class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: - DoubleHistogram(InstrumentDescriptor instrument_descriptor, + DoubleHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage); #if OPENTELEMETRY_ABI_VERSION_NO >= 2 diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h index d5054d9218..e44e9fa320 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h @@ -27,7 +27,7 @@ namespace trace class ParentBasedSampler : public Sampler { public: - explicit ParentBasedSampler(std::shared_ptr delegate_sampler) noexcept; + explicit ParentBasedSampler(const std::shared_ptr &delegate_sampler) noexcept; /** The decision either respects the parent span's sampling decision or delegates to * delegateSampler for root spans * @return Returns DROP always diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h index 68557ace79..d5cf598311 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent_factory.h @@ -23,7 +23,7 @@ class ParentBasedSamplerFactory /** * Create a ParentBasedSampler. */ - static std::unique_ptr Create(std::shared_ptr delegate_sampler); + static std::unique_ptr Create(const std::shared_ptr &delegate_sampler); }; } // namespace trace diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 73bbe4f84b..e1b2cb25d2 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -39,7 +39,7 @@ class TracerContext public: explicit TracerContext( std::vector> &&processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 0d05a94043..13a65a2d87 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -43,7 +43,7 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T */ explicit TracerProvider( std::unique_ptr processor, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = @@ -51,7 +51,7 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T explicit TracerProvider( std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource = + const opentelemetry::sdk::resource::Resource &resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr sampler = std::unique_ptr(new AlwaysOnSampler), std::unique_ptr id_generator = diff --git a/sdk/src/common/global_log_handler.cc b/sdk/src/common/global_log_handler.cc index 40968f2b7e..f60527eee8 100644 --- a/sdk/src/common/global_log_handler.cc +++ b/sdk/src/common/global_log_handler.cc @@ -31,7 +31,7 @@ void DefaultLogHandler::Handle(LogLevel level, { output_s << msg; } - output_s << std::endl; + output_s << '\n'; // TBD - print attributes switch (level) diff --git a/sdk/src/logs/event_logger.cc b/sdk/src/logs/event_logger.cc index 6b0afacfaf..df9ba44c31 100644 --- a/sdk/src/logs/event_logger.cc +++ b/sdk/src/logs/event_logger.cc @@ -21,7 +21,7 @@ namespace logs EventLogger::EventLogger( opentelemetry::nostd::shared_ptr delegate_logger, opentelemetry::nostd::string_view event_domain) noexcept - : delegate_logger_(delegate_logger), event_domain_(event_domain) + : delegate_logger_(std::move(delegate_logger)), event_domain_(event_domain) {} const opentelemetry::nostd::string_view EventLogger::GetName() noexcept diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index e9935c5107..2d57ab9faa 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -38,7 +38,7 @@ Logger::Logger( std::unique_ptr instrumentation_scope) noexcept : logger_name_(std::string(name)), instrumentation_scope_(std::move(instrumentation_scope)), - context_(context) + context_(std::move(context)) {} const opentelemetry::nostd::string_view Logger::GetName() noexcept diff --git a/sdk/src/logs/logger_context.cc b/sdk/src/logs/logger_context.cc index 2bfb89161e..a6eb063661 100644 --- a/sdk/src/logs/logger_context.cc +++ b/sdk/src/logs/logger_context.cc @@ -19,7 +19,7 @@ namespace logs { LoggerContext::LoggerContext(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : resource_(resource), processor_( std::unique_ptr(new MultiLogRecordProcessor(std::move(processors)))) diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 1eaa0d186e..fdea3eb51a 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -27,7 +27,7 @@ namespace logs { LoggerProvider::LoggerProvider(std::unique_ptr &&processor, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept { std::vector> processors; processors.emplace_back(std::move(processor)); @@ -36,7 +36,7 @@ LoggerProvider::LoggerProvider(std::unique_ptr &&processor, } LoggerProvider::LoggerProvider(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : context_{std::make_shared(std::move(processors), std::move(resource))} {} diff --git a/sdk/src/metrics/async_instruments.cc b/sdk/src/metrics/async_instruments.cc index 311efc1e7e..709957d68e 100644 --- a/sdk/src/metrics/async_instruments.cc +++ b/sdk/src/metrics/async_instruments.cc @@ -20,9 +20,9 @@ namespace metrics ObservableInstrument::ObservableInstrument(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage, std::shared_ptr observable_registry) - : instrument_descriptor_(instrument_descriptor), + : instrument_descriptor_(std::move(instrument_descriptor)), storage_(std::move(storage)), - observable_registry_{observable_registry} + observable_registry_{std::move(observable_registry)} {} diff --git a/sdk/src/metrics/exemplar/reservoir.cc b/sdk/src/metrics/exemplar/reservoir.cc index 4e7501799e..264a000828 100644 --- a/sdk/src/metrics/exemplar/reservoir.cc +++ b/sdk/src/metrics/exemplar/reservoir.cc @@ -3,9 +3,11 @@ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +# include + # include "opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" # include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" # include "opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.h" @@ -20,8 +22,8 @@ nostd::shared_ptr ExemplarReservoir::GetSimpleFixedSizeExempl std::shared_ptr reservoir_cell_selector, MapAndResetCellType map_and_reset_cell) { - return nostd::shared_ptr{ - new SimpleFixedSizeExemplarReservoir{size, reservoir_cell_selector, map_and_reset_cell}}; + return nostd::shared_ptr{new SimpleFixedSizeExemplarReservoir{ + size, std::move(reservoir_cell_selector), map_and_reset_cell}}; } nostd::shared_ptr ExemplarReservoir::GetAlignedHistogramBucketExemplarReservoir( @@ -30,7 +32,7 @@ nostd::shared_ptr ExemplarReservoir::GetAlignedHistogramBucke MapAndResetCellType map_and_reset_cell) { return nostd::shared_ptr{new AlignedHistogramBucketExemplarReservoir{ - size, reservoir_cell_selector, map_and_reset_cell}}; + size, std::move(reservoir_cell_selector), map_and_reset_cell}}; } nostd::shared_ptr ExemplarReservoir::GetNoExemplarReservoir() diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 8b4413113b..c61f3a8d31 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -53,7 +53,7 @@ Meter::Meter( std::weak_ptr meter_context, std::unique_ptr instrumentation_scope) noexcept : scope_{std::move(instrumentation_scope)}, - meter_context_{meter_context}, + meter_context_{std::move(meter_context)}, observable_registry_(new ObservableRegistry()) {} @@ -455,7 +455,7 @@ std::vector Meter::Collect(CollectorHandle *collector, for (auto &metric_storage : storage_registry_) { metric_storage.second->Collect(collector, ctx->GetCollectors(), ctx->GetSDKStartTime(), - collect_ts, [&metric_data_list](MetricData metric_data) { + collect_ts, [&metric_data_list](const MetricData &metric_data) { metric_data_list.push_back(metric_data); return true; }); diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index de32c469d8..40b9da42b2 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -36,7 +36,7 @@ namespace metrics { MeterContext::MeterContext(std::unique_ptr views, - opentelemetry::sdk::resource::Resource resource) noexcept + const opentelemetry::sdk::resource::Resource &resource) noexcept : resource_{resource}, views_(std::move(views)), sdk_start_ts_{std::chrono::system_clock::now()} {} @@ -82,7 +82,7 @@ opentelemetry::common::SystemTimestamp MeterContext::GetSDKStartTime() noexcept void MeterContext::AddMetricReader(std::shared_ptr reader) noexcept { - auto collector = std::shared_ptr{new MetricCollector(this, reader)}; + auto collector = std::shared_ptr{new MetricCollector(this, std::move(reader))}; collectors_.push_back(collector); } @@ -107,7 +107,7 @@ ExemplarFilterType MeterContext::GetExemplarFilter() const noexcept #endif // ENABLE_METRICS_EXEMPLAR_PREVIEW -void MeterContext::AddMeter(std::shared_ptr meter) +void MeterContext::AddMeter(const std::shared_ptr &meter) { std::lock_guard guard(meter_lock_); meters_.push_back(meter); diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 6ddba6aa7c..4f2ca4b44f 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -37,7 +37,7 @@ MeterProvider::MeterProvider(std::unique_ptr context) noexcept {} MeterProvider::MeterProvider(std::unique_ptr views, - sdk::resource::Resource resource) noexcept + const sdk::resource::Resource &resource) noexcept : context_(std::make_shared(std::move(views), resource)) { OTEL_INTERNAL_LOG_DEBUG("[MeterProvider] MeterProvider created."); @@ -110,7 +110,7 @@ const resource::Resource &MeterProvider::GetResource() const noexcept void MeterProvider::AddMetricReader(std::shared_ptr reader) noexcept { - context_->AddMetricReader(reader); + context_->AddMetricReader(std::move(reader)); } void MeterProvider::AddView(std::unique_ptr instrument_selector, diff --git a/sdk/src/metrics/state/metric_collector.cc b/sdk/src/metrics/state/metric_collector.cc index 5ecf41cecf..a790a6b6a1 100644 --- a/sdk/src/metrics/state/metric_collector.cc +++ b/sdk/src/metrics/state/metric_collector.cc @@ -27,7 +27,7 @@ namespace metrics MetricCollector::MetricCollector(opentelemetry::sdk::metrics::MeterContext *context, std::shared_ptr metric_reader) - : meter_context_{context}, metric_reader_{metric_reader} + : meter_context_{context}, metric_reader_{std::move(metric_reader)} { metric_reader_->SetMetricProducer(this); } @@ -48,7 +48,7 @@ bool MetricCollector::Collect( return false; } ResourceMetrics resource_metrics; - meter_context_->ForEachMeter([&](std::shared_ptr meter) noexcept { + meter_context_->ForEachMeter([&](const std::shared_ptr &meter) noexcept { auto collection_ts = std::chrono::system_clock::now(); auto metric_data = meter->Collect(this, collection_ts); if (!metric_data.empty()) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 2ba74d9213..c26339a79f 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -35,7 +35,7 @@ namespace metrics TemporalMetricStorage::TemporalMetricStorage(InstrumentDescriptor instrument_descriptor, AggregationType aggregation_type, const AggregationConfig *aggregation_config) - : instrument_descriptor_(instrument_descriptor), + : instrument_descriptor_(std::move(instrument_descriptor)), aggregation_type_(aggregation_type), aggregation_config_(aggregation_config) {} @@ -44,7 +44,7 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - std::shared_ptr delta_metrics, + const std::shared_ptr &delta_metrics, nostd::function_ref callback) noexcept { std::lock_guard guard(lock_); diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index a99fa80868..56429a079f 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -20,7 +20,7 @@ namespace sdk { namespace metrics { -LongCounter::LongCounter(InstrumentDescriptor instrument_descriptor, +LongCounter::LongCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -80,7 +80,7 @@ void LongCounter::Add(uint64_t value, const opentelemetry::context::Context &con return storage_->RecordLong(value, context); } -DoubleCounter::DoubleCounter(InstrumentDescriptor instrument_descriptor, +DoubleCounter::DoubleCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -164,7 +164,7 @@ void DoubleCounter::Add(double value, const opentelemetry::context::Context &con return storage_->RecordDouble(value, context); } -LongUpDownCounter::LongUpDownCounter(InstrumentDescriptor instrument_descriptor, +LongUpDownCounter::LongUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -228,7 +228,7 @@ void LongUpDownCounter::Add(int64_t value, const opentelemetry::context::Context return storage_->RecordLong(value, context); } -DoubleUpDownCounter::DoubleUpDownCounter(InstrumentDescriptor instrument_descriptor, +DoubleUpDownCounter::DoubleUpDownCounter(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -292,7 +292,7 @@ void DoubleUpDownCounter::Add(double value, const opentelemetry::context::Contex return storage_->RecordDouble(value, context); } -LongHistogram::LongHistogram(InstrumentDescriptor instrument_descriptor, +LongHistogram::LongHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { @@ -355,7 +355,7 @@ void LongHistogram::Record(uint64_t value) noexcept } #endif -DoubleHistogram::DoubleHistogram(InstrumentDescriptor instrument_descriptor, +DoubleHistogram::DoubleHistogram(const InstrumentDescriptor &instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) { diff --git a/sdk/src/metrics/view/view_factory.cc b/sdk/src/metrics/view/view_factory.cc index 36496f62d6..319c10b956 100644 --- a/sdk/src/metrics/view/view_factory.cc +++ b/sdk/src/metrics/view/view_factory.cc @@ -53,7 +53,7 @@ std::unique_ptr ViewFactory::Create(const std::string &name, auto attributes_processor = std::unique_ptr(new DefaultAttributesProcessor()); - return Create(name, description, unit, aggregation_type, aggregation_config, + return Create(name, description, unit, aggregation_type, std::move(aggregation_config), std::move(attributes_processor)); } @@ -64,7 +64,8 @@ std::unique_ptr ViewFactory::Create(const std::string &name, std::shared_ptr aggregation_config, std::unique_ptr attributes_processor) { - std::unique_ptr view(new View(name, description, unit, aggregation_type, aggregation_config, + std::unique_ptr view(new View(name, description, unit, aggregation_type, + std::move(aggregation_config), std::move(attributes_processor))); return view; } diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 03b79f6ebb..6aa6a49949 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -29,7 +29,6 @@ #include "opentelemetry/version.h" using opentelemetry::sdk::common::AtomicUniquePtr; -using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; using opentelemetry::trace::SpanContext; diff --git a/sdk/src/trace/samplers/parent.cc b/sdk/src/trace/samplers/parent.cc index a69ede92d4..9bffb7b030 100644 --- a/sdk/src/trace/samplers/parent.cc +++ b/sdk/src/trace/samplers/parent.cc @@ -22,7 +22,7 @@ namespace sdk { namespace trace { -ParentBasedSampler::ParentBasedSampler(std::shared_ptr delegate_sampler) noexcept +ParentBasedSampler::ParentBasedSampler(const std::shared_ptr &delegate_sampler) noexcept : delegate_sampler_(delegate_sampler), description_("ParentBased{" + std::string{delegate_sampler->GetDescription()} + "}") {} diff --git a/sdk/src/trace/samplers/parent_factory.cc b/sdk/src/trace/samplers/parent_factory.cc index 978fb75946..7f1bc088d6 100644 --- a/sdk/src/trace/samplers/parent_factory.cc +++ b/sdk/src/trace/samplers/parent_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/sdk/trace/samplers/parent_factory.h" +#include + #include "opentelemetry/sdk/trace/samplers/parent.h" +#include "opentelemetry/sdk/trace/samplers/parent_factory.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,9 +14,9 @@ namespace trace { std::unique_ptr ParentBasedSamplerFactory::Create( - std::shared_ptr delegate_sampler) + const std::shared_ptr &delegate_sampler) { - std::unique_ptr sampler(new ParentBasedSampler(delegate_sampler)); + std::unique_ptr sampler(new ParentBasedSampler(std::move(delegate_sampler))); return sampler; } diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index ca3a475707..2b9e9d2908 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -78,7 +78,7 @@ Span::Span(std::shared_ptr &&tracer, return true; }); - links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, + links.ForEachKeyValue([&](const opentelemetry::trace::SpanContext &span_context, const common::KeyValueIterable &attributes) { recordable_->AddLink(span_context, attributes); return true; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index fd02548c7b..73fc08d5dc 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -39,7 +39,7 @@ namespace trace Tracer::Tracer(std::shared_ptr context, std::unique_ptr instrumentation_scope) noexcept - : instrumentation_scope_{std::move(instrumentation_scope)}, context_{context} + : instrumentation_scope_{std::move(instrumentation_scope)}, context_{std::move(context)} {} nostd::shared_ptr Tracer::StartSpan( diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc index 0fb4fd35cf..65300d6f22 100644 --- a/sdk/src/trace/tracer_context.cc +++ b/sdk/src/trace/tracer_context.cc @@ -22,7 +22,7 @@ namespace trace namespace resource = opentelemetry::sdk::resource; TracerContext::TracerContext(std::vector> &&processors, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept : resource_(resource), diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 9440e3d469..3b5462a083 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -38,7 +38,7 @@ TracerProvider::TracerProvider(std::unique_ptr context) noexcept } TracerProvider::TracerProvider(std::unique_ptr processor, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { @@ -49,7 +49,7 @@ TracerProvider::TracerProvider(std::unique_ptr processor, } TracerProvider::TracerProvider(std::vector> &&processors, - resource::Resource resource, + const resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { diff --git a/sdk/test/common/empty_attributes_test.cc b/sdk/test/common/empty_attributes_test.cc index f37ea0a5c4..894cafc8a7 100644 --- a/sdk/test/common/empty_attributes_test.cc +++ b/sdk/test/common/empty_attributes_test.cc @@ -15,5 +15,5 @@ TEST(EmptyAttributesTest, TestMemory) { auto attributes1 = opentelemetry::sdk::GetEmptyAttributes(); auto attributes2 = opentelemetry::sdk::GetEmptyAttributes(); - EXPECT_EQ(memcmp(&attributes1, &attributes2, sizeof(attributes1)), 0); + EXPECT_EQ(memcmp(&attributes1, &attributes2, sizeof(attributes1)), 0); // NOLINT } diff --git a/sdk/test/logs/batch_log_record_processor_test.cc b/sdk/test/logs/batch_log_record_processor_test.cc index 33db0da479..3bdd849938 100644 --- a/sdk/test/logs/batch_log_record_processor_test.cc +++ b/sdk/test/logs/batch_log_record_processor_test.cc @@ -9,6 +9,7 @@ #include #include #include +#include using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -74,10 +75,10 @@ class MockLogExporter final : public LogRecordExporter std::shared_ptr> is_shutdown, std::shared_ptr> is_export_completed, const std::chrono::milliseconds export_delay = std::chrono::milliseconds(0)) - : logs_received_(logs_received), - force_flush_counter_(force_flush_counter), - is_shutdown_(is_shutdown), - is_export_completed_(is_export_completed), + : logs_received_(std::move(logs_received)), + force_flush_counter_(std::move(force_flush_counter)), + is_shutdown_(std::move(is_shutdown)), + is_export_completed_(std::move(is_export_completed)), export_delay_(export_delay) {} @@ -154,7 +155,8 @@ class BatchLogRecordProcessorTest : public testing::Test // ::testing::Test { return std::shared_ptr(new BatchLogRecordProcessor( std::unique_ptr(new MockLogExporter( - logs_received, force_flush_counter, is_shutdown, is_export_completed, export_delay)), + std::move(logs_received), std::move(force_flush_counter), std::move(is_shutdown), + std::move(is_export_completed), export_delay)), max_queue_size, scheduled_delay_millis, max_export_batch_size)); } }; diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 62d523b92a..9e63672d3c 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -3,6 +3,7 @@ #include #include +#include #include "opentelemetry/logs/logger_provider.h" #include "opentelemetry/nostd/string_view.h" @@ -172,7 +173,7 @@ class MockProcessor final : public LogRecordProcessor public: // A processor used for testing that keeps a track of the recordable it received explicit MockProcessor(std::shared_ptr record_received) noexcept - : record_received_(record_received) + : record_received_(std::move(record_received)) {} std::unique_ptr MakeRecordable() noexcept override diff --git a/sdk/test/logs/simple_log_record_processor_test.cc b/sdk/test/logs/simple_log_record_processor_test.cc index 484cc63e71..30e5771394 100644 --- a/sdk/test/logs/simple_log_record_processor_test.cc +++ b/sdk/test/logs/simple_log_record_processor_test.cc @@ -10,6 +10,7 @@ #include #include +#include using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; @@ -75,7 +76,7 @@ class TestExporter final : public LogRecordExporter size_t *batch_size_received) : force_flush_counter_(force_flush_counter), shutdown_counter_(shutdown_counter), - logs_received_(logs_received), + logs_received_(std::move(logs_received)), batch_size_received(batch_size_received) {} diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index 10c0335559..b7ad885bbd 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -12,6 +12,7 @@ using namespace opentelemetry::sdk::metrics; using M = std::map; +// NOLINTNEXTLINE void asyc_generate_measurements(opentelemetry::metrics::ObserverResult /* observer */, void * /* state */) {} diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 3b72e99d96..dcbe105418 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -262,7 +262,7 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); storage.Collect( - collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) { + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (auto data_attr : metric_data.point_data_attr_) { auto data = opentelemetry::nostd::get(data_attr.point_data); @@ -288,7 +288,7 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) storage.RecordLong(measurements2, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); storage.Collect( - collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData metric_data) { + collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData &metric_data) { for (auto data_attr : metric_data.point_data_attr_) { auto data = opentelemetry::nostd::get(data_attr.point_data); diff --git a/sdk/test/metrics/cardinality_limit_test.cc b/sdk/test/metrics/cardinality_limit_test.cc index 8c2edb4b0c..3f9483ac1c 100644 --- a/sdk/test/metrics/cardinality_limit_test.cc +++ b/sdk/test/metrics/cardinality_limit_test.cc @@ -26,7 +26,7 @@ TEST(CardinalityLimit, AttributesHashMapBasicTests) return std::unique_ptr(new LongSumAggregation(true)); }; // add 10 unique metric points. 9 should be added to hashmap, 10th should be overflow. - long record_value = 100; + int64_t record_value = 100; for (auto i = 0; i < 10; i++) { FilteredOrderedAttributeMap attributes = {{"key", std::to_string(i)}}; @@ -76,7 +76,7 @@ TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregati #endif nullptr, attributes_limit); - long record_value = 100; + int64_t record_value = 100; // add 9 unique metric points, and 6 more above limit. for (auto i = 0; i < 15; i++) { diff --git a/sdk/test/metrics/instrument_metadata_validator_test.cc b/sdk/test/metrics/instrument_metadata_validator_test.cc index 172df1af3c..28c6d4a4fd 100644 --- a/sdk/test/metrics/instrument_metadata_validator_test.cc +++ b/sdk/test/metrics/instrument_metadata_validator_test.cc @@ -19,9 +19,9 @@ TEST(InstrumentMetadataValidator, TestName) { opentelemetry::sdk::metrics::InstrumentMetaDataValidator validator; std::vector invalid_names = { - "", // empty string - "1sdf", // string starting with number - "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42" // unicode characters + "", // empty string + "1sdf", // string starting with number + "\x31\x32\x33\xe2\x82\xac\x41\x41\x41\xe2\x82\xac\x42\x42\x42", // unicode characters "/\\sdsd", // string starting with special character "***sSSs", // string starting with special character "a\\broken\\path", // contains backward slash diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index 084f50fc09..b5ed86f55a 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -18,7 +18,7 @@ using namespace opentelemetry::sdk::metrics; namespace { nostd::shared_ptr InitMeter(MetricReader **metricReaderPtr, - std::string meter_name = "meter_name") + const std::string &meter_name = "meter_name") { static std::shared_ptr provider(new MeterProvider()); std::unique_ptr metric_reader(new MockMetricReader()); diff --git a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc index 216574a587..88ae56eb3f 100644 --- a/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_up_down_counter_test.cc @@ -71,7 +71,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -105,7 +105,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(data.start_ts, sdk_start_ts); @@ -147,7 +147,7 @@ TEST_P(WritableMetricStorageTestFixture, LongUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -224,7 +224,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) auto collection_ts = std::chrono::system_clock::now(); size_t count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); @@ -259,7 +259,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { if (temporality == AggregationTemporality::kCumulative) { EXPECT_EQ(data.start_ts, sdk_start_ts); @@ -301,7 +301,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleUpDownCounterSumAggregation) collection_ts = std::chrono::system_clock::now(); count_attributes = 0; storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, - [&](const MetricData data) { + [&](const MetricData &data) { for (auto data_attr : data.point_data_attr_) { auto sum_data = opentelemetry::nostd::get(data_attr.point_data); diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index e6b56cae43..419264862c 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -25,7 +25,8 @@ namespace nostd = opentelemetry::nostd; class TestResource : public Resource { public: - TestResource(ResourceAttributes attributes = ResourceAttributes(), std::string schema_url = {}) + TestResource(const ResourceAttributes &attributes = ResourceAttributes(), + const std::string &schema_url = {}) : Resource(attributes, schema_url) {} }; @@ -122,10 +123,10 @@ TEST(ResourceTest, create_with_emptyatrributes) TEST(ResourceTest, create_with_schemaurl) { - const std::string schema_url = "https://opentelemetry.io/schemas/1.2.0"; - ResourceAttributes attributes = {}; - auto resource = Resource::Create(attributes, schema_url); - auto received_schema_url = resource.GetSchemaURL(); + const std::string schema_url = "https://opentelemetry.io/schemas/1.2.0"; + ResourceAttributes attributes = {}; + auto resource = Resource::Create(attributes, schema_url); + const auto &received_schema_url = resource.GetSchemaURL(); EXPECT_EQ(received_schema_url, schema_url); } diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index 411b4dacfe..9bb09d6e55 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -16,6 +16,7 @@ #include #include #include +#include OPENTELEMETRY_BEGIN_NAMESPACE @@ -32,10 +33,10 @@ class MockSpanExporter final : public sdk::trace::SpanExporter std::shared_ptr> is_export_completed = std::shared_ptr>(new std::atomic(false)), const std::chrono::milliseconds export_delay = std::chrono::milliseconds(0)) noexcept - : spans_received_(spans_received), - shut_down_counter_(shut_down_counter), - is_shutdown_(is_shutdown), - is_export_completed_(is_export_completed), + : spans_received_(std::move(spans_received)), + shut_down_counter_(std::move(shut_down_counter)), + is_shutdown_(std::move(is_shutdown)), + is_export_completed_(std::move(is_export_completed)), export_delay_(export_delay) {} @@ -96,7 +97,7 @@ class BatchSpanProcessorTestPeer : public testing::Test { public: std::unique_ptr>> GetTestSpans( - std::shared_ptr processor, + const std::shared_ptr &processor, const int num_spans) { std::unique_ptr>> test_spans( diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 98d00843dd..6dfc09bd12 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -96,8 +96,8 @@ TEST(SpanData, EventAttributes) TEST(SpanData, Resources) { SpanData data; - auto resource = opentelemetry::sdk::resource::Resource::Create({}); - auto input_attr = resource.GetAttributes(); + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + const auto &input_attr = resource.GetAttributes(); data.SetResource(resource); auto output_attr = data.GetResource().GetAttributes(); EXPECT_EQ(input_attr, output_attr); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 99bab95b0f..c57b638e3d 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -20,7 +20,6 @@ using opentelemetry::common::SystemTimestamp; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; namespace trace_api = opentelemetry::trace; -using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext;