From 7aaca5a963562b8ecbe744cf0a24fdace2392c23 Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Wed, 3 Jul 2024 17:14:30 -0400 Subject: [PATCH] Added directories excluding tools, .git, third_party, opentelemetry_logo.png, TraceLoggingDynamic.h, Included formatting changes from tools/format.sh --- api/include/opentelemetry/context/context.h | 5 +++-- .../context/propagation/global_propagator.h | 3 ++- .../opentelemetry/context/runtime_context.h | 4 +++- api/include/opentelemetry/logs/provider.h | 5 +++-- api/include/opentelemetry/metrics/provider.h | 3 ++- .../absl/base/internal/inline_variable.h | 4 ++-- api/include/opentelemetry/plugin/tracer.h | 3 ++- .../opentelemetry/trace/default_span.h | 2 +- api/include/opentelemetry/trace/provider.h | 3 ++- .../opentelemetry/trace/span_context.h | 4 +++- .../trace/span_context_kv_iterable_view.h | 4 ++-- .../propagation/baggage_propagator_test.cc | 2 +- api/test/common/kv_properties_test.cc | 2 +- api/test/context/context_test.cc | 6 ++--- api/test/context/runtime_context_test.cc | 2 ++ api/test/logs/logger_benchmark.cc | 5 +++-- api/test/trace/trace_state_test.cc | 2 +- examples/http/server.h | 4 ++-- examples/http/tracer_common.h | 3 ++- examples/logs_simple/main.cc | 4 ++-- examples/multi_processor/main.cc | 18 +++++++-------- examples/multithreaded/main.cc | 1 + examples/otlp/http_log_main.cc | 4 ++-- examples/simple/main.cc | 2 +- .../exporters/ostream/common_utils.h | 2 +- exporters/ostream/test/ostream_log_test.cc | 12 +++++----- exporters/ostream/test/ostream_span_test.cc | 2 +- .../exporters/otlp/otlp_http_client.h | 2 +- .../ext/http/common/url_parser.h | 9 ++++---- .../ext/http/server/file_http_server.h | 4 ++-- .../ext/http/server/http_server.h | 13 ++++++----- .../ext/http/server/socket_tools.h | 2 +- functional/otlp/func_http_main.cc | 22 +++++++++---------- .../sdk/metrics/data/exemplar_data.h | 4 ++-- .../sdk/trace/samplers/parent_factory.h | 2 +- sdk/src/logs/logger_provider.cc | 4 ++-- sdk/src/metrics/state/sync_metric_storage.cc | 2 +- sdk/src/trace/samplers/parent_factory.cc | 4 ++-- .../http/client/nosend/http_client_nosend.h | 6 ++--- 39 files changed, 101 insertions(+), 84 deletions(-) diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index cf5c9cd319..b7c8f8475c 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" @@ -32,7 +33,7 @@ class Context // Creates a context object from a key and value, this will // hold a shared_ptr to the head of the DataList linked list - Context(nostd::string_view key, ContextValue value) noexcept + Context(nostd::string_view key, const ContextValue &value) noexcept { head_ = nostd::shared_ptr{new DataList(key, value)}; } @@ -58,7 +59,7 @@ class Context // exisiting list to the end of the new list. Context SetValue(nostd::string_view key, ContextValue value) noexcept { - Context context = Context(key, value); + Context context = Context(key, std::move(value)); context.head_->next_ = head_; return context; } diff --git a/api/include/opentelemetry/context/propagation/global_propagator.h b/api/include/opentelemetry/context/propagation/global_propagator.h index a62146e100..91c9deb63d 100644 --- a/api/include/opentelemetry/context/propagation/global_propagator.h +++ b/api/include/opentelemetry/context/propagation/global_propagator.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/context/propagation/noop_propagator.h" @@ -35,7 +36,7 @@ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator static void SetGlobalPropagator(nostd::shared_ptr prop) noexcept { std::lock_guard guard(GetLock()); - GetPropagator() = prop; + GetPropagator() = std::move(prop); } private: diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h index cccc71e32f..dec7bac23a 100644 --- a/api/include/opentelemetry/context/runtime_context.h +++ b/api/include/opentelemetry/context/runtime_context.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "opentelemetry/common/macros.h" #include "opentelemetry/context/context.h" #include "opentelemetry/nostd/shared_ptr.h" @@ -150,7 +152,7 @@ class OPENTELEMETRY_EXPORT RuntimeContext */ static void SetRuntimeContextStorage(nostd::shared_ptr storage) noexcept { - GetStorage() = storage; + GetStorage() = std::move(storage); } /** diff --git a/api/include/opentelemetry/logs/provider.h b/api/include/opentelemetry/logs/provider.h index 8f65a1139d..8b5e592c99 100644 --- a/api/include/opentelemetry/logs/provider.h +++ b/api/include/opentelemetry/logs/provider.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" @@ -42,7 +43,7 @@ class OPENTELEMETRY_EXPORT Provider static void SetLoggerProvider(nostd::shared_ptr tp) noexcept { std::lock_guard guard(GetLock()); - GetProvider() = tp; + GetProvider() = std::move(tp); } /** @@ -63,7 +64,7 @@ class OPENTELEMETRY_EXPORT Provider static void SetEventLoggerProvider(nostd::shared_ptr tp) noexcept { std::lock_guard guard(GetLock()); - GetEventProvider() = tp; + GetEventProvider() = std::move(tp); } private: diff --git a/api/include/opentelemetry/metrics/provider.h b/api/include/opentelemetry/metrics/provider.h index b2fa3e20e4..20b3e1bf33 100644 --- a/api/include/opentelemetry/metrics/provider.h +++ b/api/include/opentelemetry/metrics/provider.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" @@ -41,7 +42,7 @@ class Provider static void SetMeterProvider(nostd::shared_ptr tp) noexcept { std::lock_guard guard(GetLock()); - GetProvider() = tp; + GetProvider() = std::move(tp); } private: diff --git a/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h index 9d024a2d91..faaeca429a 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h @@ -68,7 +68,7 @@ // types, etc.. #if defined(__clang__) #define OTABSL_INTERNAL_EXTERN_DECL(type, name) \ - extern const ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t name; + extern const ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t (name); #else // Otherwise, just define the macro to do nothing. #define OTABSL_INTERNAL_EXTERN_DECL(type, name) #endif // defined(__clang__) @@ -76,7 +76,7 @@ // See above comment at top of file for details. #define OTABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \ OTABSL_INTERNAL_EXTERN_DECL(type, name) \ - inline constexpr ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t name = init + inline constexpr ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t (name) = init #else diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index ae78109dab..1905d500b3 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/common/key_value_iterable.h" #include "opentelemetry/plugin/detail/tracer_handle.h" // IWYU pragma: export @@ -21,7 +22,7 @@ class Span final : public trace::Span { public: Span(std::shared_ptr &&tracer, nostd::shared_ptr span) noexcept - : tracer_{std::move(tracer)}, span_{span} + : tracer_{std::move(tracer)}, span_{std::move(span)} {} // trace::Span diff --git a/api/include/opentelemetry/trace/default_span.h b/api/include/opentelemetry/trace/default_span.h index 7e3979501e..b0a57ac33b 100644 --- a/api/include/opentelemetry/trace/default_span.h +++ b/api/include/opentelemetry/trace/default_span.h @@ -63,7 +63,7 @@ class DefaultSpan : public Span nostd::string_view ToString() const noexcept { return "DefaultSpan"; } - DefaultSpan(SpanContext span_context) noexcept : span_context_(span_context) {} + DefaultSpan(const SpanContext &span_context) noexcept : span_context_(span_context) {} // movable and copiable DefaultSpan(DefaultSpan &&spn) noexcept : span_context_(spn.GetContext()) {} diff --git a/api/include/opentelemetry/trace/provider.h b/api/include/opentelemetry/trace/provider.h index d5a52a02f6..87826faaee 100644 --- a/api/include/opentelemetry/trace/provider.h +++ b/api/include/opentelemetry/trace/provider.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" @@ -41,7 +42,7 @@ class OPENTELEMETRY_EXPORT Provider static void SetTracerProvider(nostd::shared_ptr tp) noexcept { std::lock_guard guard(GetLock()); - GetProvider() = tp; + GetProvider() = std::move(tp); } private: diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index 5fcab6e7ed..888d7a8150 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_flags.h" @@ -44,7 +46,7 @@ class SpanContext final span_id_(span_id), trace_flags_(trace_flags), is_remote_(is_remote), - trace_state_(trace_state) + trace_state_(std::move(trace_state)) {} SpanContext(const SpanContext &ctx) = default; diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index 8c4584dc2e..8fc066fd42 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -32,7 +32,7 @@ inline void take_span_context_kv(SpanContext, T &) {} inline void take_span_context_kv( - SpanContext, + const SpanContext &, std::initializer_list>) {} @@ -81,7 +81,7 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable private: const T *container_; - bool do_callback(SpanContext span_context, + bool do_callback(const SpanContext &span_context, const common::KeyValueIterable &attributes, nostd::function_ref callback) const noexcept 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..683aefcc1d 100644 --- a/api/test/logs/logger_benchmark.cc +++ b/api/test/logs/logger_benchmark.cc @@ -66,7 +66,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 +87,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 +95,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/trace/trace_state_test.cc b/api/test/trace/trace_state_test.cc index 7f5a05cfe6..f2ea0e0c41 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(); diff --git a/examples/http/server.h b/examples/http/server.h index 1f73744d65..5691a6e465 100644 --- a/examples/http/server.h +++ b/examples/http/server.h @@ -19,13 +19,13 @@ class HttpServer : public HTTP_SERVER_NS::HttpRequestCallback std::atomic is_running_{false}; public: - HttpServer(std::string server_name = "test_server", uint16_t port = 8800) : port_(port) + HttpServer(const std::string &server_name = "test_server", uint16_t port = 8800) : port_(port) { server_.setServerName(server_name); server_.setKeepalive(false); } - void AddHandler(std::string path, HTTP_SERVER_NS::HttpRequestCallback *request_handler) + void AddHandler(const std::string &path, HTTP_SERVER_NS::HttpRequestCallback *request_handler) { server_.addHandler(path, *request_handler); } diff --git a/examples/http/tracer_common.h b/examples/http/tracer_common.h index 8b61e7bec3..91293c4f3c 100644 --- a/examples/http/tracer_common.h +++ b/examples/http/tracer_common.h @@ -89,7 +89,8 @@ void CleanupTracer() opentelemetry::trace::Provider::SetTracerProvider(none); } -opentelemetry::nostd::shared_ptr get_tracer(std::string tracer_name) +opentelemetry::nostd::shared_ptr get_tracer( + const std::string &tracer_name) { auto provider = opentelemetry::trace::Provider::GetTracerProvider(); return provider->GetTracer(tracer_name); 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 9dd76647c5..680c7332a5 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -58,6 +58,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 e2b219de1c..d3b81bbfce 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -61,7 +61,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); @@ -100,7 +100,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/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index ec1ee2d367..3b86f257d6 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -31,7 +31,7 @@ void print_value(const std::vector &vec, std::ostream &sout) sout << '['; size_t i = 1; size_t sz = vec.size(); - for (auto v : vec) + for (const auto &v : vec) { sout << v; if (i != sz) diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 7b22d9b3fd..274ff2da7a 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -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); } @@ -201,7 +201,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); } @@ -275,7 +275,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); } @@ -356,7 +356,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); } @@ -429,7 +429,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); } @@ -500,7 +500,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_list #include +#include #include #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" @@ -32,7 +33,7 @@ class UrlParser std::string query_; bool success_; - UrlParser(std::string url) : url_(url), success_(true) + UrlParser(std::string url) : url_(std::move(url)), success_(true) { if (url_.length() == 0) { @@ -53,8 +54,8 @@ class UrlParser } // credentials - size_t pos1 = url_.find_first_of("@", cpos); - size_t pos2 = url_.find_first_of("/", cpos); + size_t pos1 = url_.find_first_of('@', cpos); + size_t pos2 = url_.find_first_of('/', cpos); if (pos1 != std::string::npos) { // TODO - handle credentials @@ -64,7 +65,7 @@ class UrlParser cpos = pos1 + 1; } } - pos = url_.find_first_of(":", cpos); + pos = url_.find_first_of(':', cpos); bool is_port = false; if (pos == std::string::npos) { diff --git a/ext/include/opentelemetry/ext/http/server/file_http_server.h b/ext/include/opentelemetry/ext/http/server/file_http_server.h index cb28d01fa3..579de0b1e9 100644 --- a/ext/include/opentelemetry/ext/http/server/file_http_server.h +++ b/ext/include/opentelemetry/ext/http/server/file_http_server.h @@ -78,7 +78,7 @@ class FileHttpServer : public HTTP_SERVER_NS::HttpServer */ std::string GetMimeContentType(const std::string &filename) { - std::string file_ext = filename.substr(filename.find_last_of(".") + 1); + std::string file_ext = filename.substr(filename.find_last_of('.') + 1); auto file_type = mime_types_.find(file_ext); return (file_type != mime_types_.end()) ? file_type->second : HTTP_SERVER_NS::CONTENT_TYPE_TEXT; }; @@ -97,7 +97,7 @@ class FileHttpServer : public HTTP_SERVER_NS::HttpServer } // If filename appears to be a directory, serve the hypothetical index.html // file there - if (name.find(".") == std::string::npos) + if (name.find('.') == std::string::npos) name += "/index.html"; return name; diff --git a/ext/include/opentelemetry/ext/http/server/http_server.h b/ext/include/opentelemetry/ext/http/server/http_server.h index 5ea7debc43..229219ced9 100644 --- a/ext/include/opentelemetry/ext/http/server/http_server.h +++ b/ext/include/opentelemetry/ext/http/server/http_server.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "socket_tools.h" @@ -56,17 +57,17 @@ class HttpRequestCallback HttpRequestCallback() {} virtual ~HttpRequestCallback() = default; - HttpRequestCallback &operator=(HttpRequestCallback other) + HttpRequestCallback &operator=(const HttpRequestCallback &other) { callback = other.callback; return *this; } - HttpRequestCallback(CallbackFunction func) : callback(func) {} + HttpRequestCallback(CallbackFunction func) : callback(std::move(func)) {} HttpRequestCallback &operator=(CallbackFunction func) { - callback = func; + callback = std::move(func); return (*this); } @@ -122,7 +123,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback public: HttpRequestHandler(std::string key, HttpRequestCallback *value) { - first = key; + first = std::move(key); second = value; } @@ -132,7 +133,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback second = nullptr; } - HttpRequestHandler &operator=(std::pair other) + HttpRequestHandler &operator=(const std::pair &other) { first = other.first; second = other.second; @@ -168,7 +169,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback m_maxRequestContentSize(2 * 1024 * 1024) {} - HttpServer(std::string serverHost, int port = 30000) : HttpServer() + HttpServer(const std::string &serverHost, int port = 30000) : HttpServer() { std::ostringstream os; os << serverHost << ":" << port; diff --git a/ext/include/opentelemetry/ext/http/server/socket_tools.h b/ext/include/opentelemetry/ext/http/server/socket_tools.h index bad76e640a..eddc52cb49 100644 --- a/ext/include/opentelemetry/ext/http/server/socket_tools.h +++ b/ext/include/opentelemetry/ext/http/server/socket_tools.h @@ -433,7 +433,7 @@ struct SocketData SocketData() : socket(), flags(0) {} - bool operator==(Socket s) { return (socket == s); } + bool operator==(const Socket &s) { return (socket == s); } }; /// diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 9cd3585668..914528bd21 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -67,7 +67,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."); @@ -98,11 +98,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"); @@ -131,19 +131,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; } @@ -398,12 +398,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; @@ -417,7 +417,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/metrics/data/exemplar_data.h b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h index 5b91ad80df..068c455bfc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h @@ -27,11 +27,11 @@ using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMa class ExemplarData { public: - static ExemplarData Create(std::shared_ptr context, + static ExemplarData Create(const std::shared_ptr &context, const opentelemetry::common::SystemTimestamp ×tamp, const PointDataAttributes &point_data_attr) { - return ExemplarData(std::move(context), timestamp, point_data_attr); + return ExemplarData(context, timestamp, point_data_attr); } /** 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/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index ba014faa60..5a975dedcc 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -33,13 +33,13 @@ LoggerProvider::LoggerProvider(std::unique_ptr &&processor, { std::vector> processors; processors.emplace_back(std::move(processor)); - context_ = std::make_shared(std::move(processors), std::move(resource)); + context_ = std::make_shared(std::move(processors), resource); OTEL_INTERNAL_LOG_DEBUG("[LoggerProvider] LoggerProvider created."); } LoggerProvider::LoggerProvider(std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource) noexcept - : context_{std::make_shared(std::move(processors), std::move(resource))} + : context_{std::make_shared(std::move(processors), resource)} {} LoggerProvider::LoggerProvider() noexcept diff --git a/sdk/src/metrics/state/sync_metric_storage.cc b/sdk/src/metrics/state/sync_metric_storage.cc index fe736e64f3..ad6ea27821 100644 --- a/sdk/src/metrics/state/sync_metric_storage.cc +++ b/sdk/src/metrics/state/sync_metric_storage.cc @@ -39,7 +39,7 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector, } return temporal_metric_storage_.buildMetrics(collector, collectors, sdk_start_ts, collection_ts, - std::move(delta_metrics), callback); + delta_metrics, callback); } } // namespace metrics diff --git a/sdk/src/trace/samplers/parent_factory.cc b/sdk/src/trace/samplers/parent_factory.cc index 7e5265464d..63a7eff1c4 100644 --- a/sdk/src/trace/samplers/parent_factory.cc +++ b/sdk/src/trace/samplers/parent_factory.cc @@ -14,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(std::move(delegate_sampler))); + std::unique_ptr sampler(new ParentBasedSampler(delegate_sampler)); return sampler; } diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h index 3207857743..8c3514b166 100644 --- a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h +++ b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h @@ -122,9 +122,9 @@ class Session : public opentelemetry::ext::http::client::Session { public: Session(HttpClient &http_client, - std::string scheme = "http", - const std::string &host = "", - uint16_t port = 80) + const std::string &scheme = "http", + const std::string &host = "", + uint16_t port = 80) : http_client_(http_client), is_session_active_(false) { host_ = scheme + "://" + host + ":" + std::to_string(port) + "/";