diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 5a0e0084f7..ed9bcff238 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -17,9 +17,9 @@ jobs: matrix: include: - cmake_options: all-options-abiv1-preview - warning_limit: 172 + warning_limit: 109 - cmake_options: all-options-abiv2-preview - warning_limit: 173 + warning_limit: 109 steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a0ee72ab..e29ce90b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ Increment the: * [CodeHealth] Fix clang-tidy warnings part 1 [#3493](https://github.com/open-telemetry/opentelemetry-cpp/pull/3493) +* [CodeHealth] Fix clang-tidy warnings part 2 + [#3496](https://github.com/open-telemetry/opentelemetry-cpp/pull/3496) + Important changes: * [REMOVAL] Removed deprecated semantic convention header files diff --git a/api/include/opentelemetry/plugin/hook.h b/api/include/opentelemetry/plugin/hook.h index 9b18e2a6a8..ad8fdb2f49 100644 --- a/api/include/opentelemetry/plugin/hook.h +++ b/api/include/opentelemetry/plugin/hook.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/plugin/factory.h" #include "opentelemetry/version.h" #ifdef _WIN32 @@ -42,7 +43,6 @@ namespace plugin { struct LoaderInfo; -class FactoryImpl; using OpenTelemetryHook = nostd::unique_ptr (*)(const LoaderInfo &loader_info, diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 52436815fb..ee4514dda9 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -206,7 +206,11 @@ class TestLogger : public Logger using Logger::EmitLogRecord; - void EmitLogRecord(nostd::unique_ptr &&) noexcept override {} + void EmitLogRecord( + nostd::unique_ptr &&log_record) noexcept override + { + auto log_record_ptr = std::move(log_record); + } }; // Define a basic LoggerProvider class that returns an instance of the logger class defined above diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index f88863046e..6fcdba50df 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -54,7 +54,7 @@ std::shared_ptr InitTracer() trace_sdk::TracerProviderFactory::Create(std::move(processors)); // Set the global trace provider - trace_sdk::Provider::SetTracerProvider(std::move(provider)); + trace_sdk::Provider::SetTracerProvider(provider); return data; } diff --git a/examples/otlp/http_instrumented_main.cc b/examples/otlp/http_instrumented_main.cc index 17a381930c..3b126b4e62 100644 --- a/examples/otlp/http_instrumented_main.cc +++ b/examples/otlp/http_instrumented_main.cc @@ -103,14 +103,13 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum { std::cout << ", priority " << priority_; } - std::cout << std::endl << std::flush; + std::cout << "\n" << std::flush; } void OnEnd() override { std::lock_guard lock_guard(serialize); - std::cout << "OnEnd() thread " << thread_name_ << ", id " << std::this_thread::get_id() - << std::endl + std::cout << "OnEnd() thread " << thread_name_ << ", id " << std::this_thread::get_id() << "\n" << std::flush; } @@ -118,7 +117,7 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum { std::lock_guard lock_guard(serialize); std::cout << "BeforeWait() thread " << thread_name_ << ", id " << std::this_thread::get_id() - << ", waiting" << std::endl + << ", waiting\n" << std::flush; } @@ -126,7 +125,7 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum { std::lock_guard lock_guard(serialize); std::cout << "AfterWait() thread " << thread_name_ << ", id " << std::this_thread::get_id() - << ", done waiting" << std::endl + << ", done waiting\n" << std::flush; } @@ -134,7 +133,7 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum { std::lock_guard lock_guard(serialize); std::cout << "BeforeLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id() - << ", about to work" << std::endl + << ", about to work\n" << std::flush; } @@ -142,7 +141,7 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum { std::lock_guard lock_guard(serialize); std::cout << "AfterLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id() - << ", done working" << std::endl + << ", done working\n" << std::flush; } @@ -341,25 +340,25 @@ int main(int argc, char *argv[]) logger_opts.url = "http://localhost:4318/v1/logs"; } - std::cout << "Initializing opentelemetry-cpp" << std::endl << std::flush; + std::cout << "Initializing opentelemetry-cpp\n" << std::flush; InitTracer(); InitMetrics(); InitLogger(); - std::cout << "Application payload" << std::endl << std::flush; + std::cout << "Application payload\n" << std::flush; foo_library(); std::string name{"otlp_http_metric_example"}; foo_library::observable_counter_example(name); - std::cout << "Shutting down opentelemetry-cpp" << std::endl << std::flush; + std::cout << "Shutting down opentelemetry-cpp\n" << std::flush; CleanupLogger(); CleanupMetrics(); CleanupTracer(); - std::cout << "Done" << std::endl << std::flush; + std::cout << "Done\n" << std::flush; return 0; } diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index bf3af291f3..6c7028ed16 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -125,7 +125,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) " severity_text : INVALID\n", " body : \n", " resource : \n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", @@ -136,7 +136,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) " trace_flags : 00\n", " scope : \n", " name : otel-cpp\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.15.0\n", " attributes : \n", " scope.attr.key: scope.attr.value\n", @@ -199,7 +199,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) " severity_text : TRACE\n" " body : Message\n", " resource : \n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " attributes : \n", @@ -210,7 +210,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout) " trace_flags : 00\n", " scope : \n", " name : otel-cpp\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.15.0\n", " attributes : \n", " scope.attr.key: scope.attr.value\n", @@ -270,7 +270,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) " severity_text : INVALID\n", " body : \n", " resource : \n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " service.name: unknown_service\n", @@ -284,7 +284,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr) " trace_flags : 00\n", " scope : \n", " name : otel-cpp\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.15.0\n", " attributes : \n", " scope.attr.key: scope.attr.value\n", @@ -352,7 +352,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) " body : \n", " resource : \n", " service.name: unknown_service\n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", " res1: [1,2,3]\n", @@ -365,7 +365,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog) " trace_flags : 00\n", " scope : \n", " name : otel-cpp\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.15.0\n", " attributes : \n", " scope.attr.key: scope.attr.value\n", @@ -425,7 +425,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) " severity_text : DEBUG\n", " body : Hello\n", " resource : \n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " service.name: unknown_service\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", @@ -437,7 +437,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) " trace_flags : 00\n", " scope : \n", " name : opentelelemtry_library\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.11.0\n", " attributes : \n", " scope.attr.key: 123\n", @@ -496,7 +496,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) " severity_text : DEBUG\n", " body : Hello {key1} {key2}\n", " resource : \n", - " telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n", + std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n", " service.name: unknown_service\n", " telemetry.sdk.name: opentelemetry\n", " telemetry.sdk.language: cpp\n", @@ -508,7 +508,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) " trace_flags : 00\n", " scope : \n", " name : opentelelemtry_library\n", - " version : " OPENTELEMETRY_SDK_VERSION "\n", + std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n", " schema_url : https://opentelemetry.io/schemas/1.11.0\n", " attributes : \n", " scope.attr.key: 123\n", diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index c638b17662..09e97accdc 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -1200,7 +1200,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender { if (file_pattern[i] == '%') { - int checked = static_cast(file_pattern[i + 1]); + int checked = static_cast(file_pattern[i + 1]); if (checked > 0 && checked < 128 && check_interval[checked] > 0) { if (0 == check_file_path_interval_ || diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index b386b5912f..cec55ba116 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -91,7 +91,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallData : public OtlpGrpcAsyncCal result_callback; OtlpGrpcAsyncCallData() {} - virtual ~OtlpGrpcAsyncCallData() {} + ~OtlpGrpcAsyncCallData() override {} }; } // namespace #endif diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index d9f5dd6c3e..77f4df3eed 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -665,7 +665,7 @@ void ConvertListFieldToJson(nlohmann::json &value, OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) : is_shutdown_(false), options_(std::move(options)), - http_client_(http_client::HttpClientFactory::Create(options.thread_instrumentation)), + http_client_(http_client::HttpClientFactory::Create(options_.thread_instrumentation)), start_session_counter_(0), finished_session_counter_(0) { diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index 43b7831bf9..e7836a3d8e 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -125,7 +125,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe public: async_interface(OtlpMockTraceServiceStub *owner) : stub_(owner) {} - virtual ~async_interface() override = default; + ~async_interface() override = default; void Export( ::grpc::ClientContext *context, @@ -188,7 +188,7 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi public: async_interface(OtlpMockLogsServiceStub *owner) : stub_(owner) {} - virtual ~async_interface() override = default; + ~async_interface() override = default; void Export( ::grpc::ClientContext *context, @@ -255,7 +255,7 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test const std::shared_ptr &client) { return std::unique_ptr( - new OtlpGrpcLogRecordExporter(std::move(stub_interface), std::move(client))); + new OtlpGrpcLogRecordExporter(std::move(stub_interface), client)); } std::unique_ptr GetExporter( @@ -263,7 +263,7 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test const std::shared_ptr &client) { return std::unique_ptr( - new OtlpGrpcExporter(std::move(stub_interface), std::move(client))); + new OtlpGrpcExporter(std::move(stub_interface), client)); } // Get the options associated with the given exporter. diff --git a/sdk/src/common/global_log_handler.cc b/sdk/src/common/global_log_handler.cc index 0883e5dfab..bd30262ba7 100644 --- a/sdk/src/common/global_log_handler.cc +++ b/sdk/src/common/global_log_handler.cc @@ -18,11 +18,9 @@ namespace struct GlobalLogHandlerData { nostd::shared_ptr handler; - LogLevel log_level; + LogLevel log_level{LogLevel::Warning}; - GlobalLogHandlerData() - : handler(nostd::shared_ptr(new DefaultLogHandler)), log_level(LogLevel::Warning) - {} + GlobalLogHandlerData() : handler(nostd::shared_ptr(new DefaultLogHandler)) {} ~GlobalLogHandlerData() { is_singleton_destroyed = true; } GlobalLogHandlerData(const GlobalLogHandlerData &) = delete; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 9cc48bd69a..3509b164da 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -172,7 +172,7 @@ void Span::AddLinks(const opentelemetry::trace::SpanContextKeyValueIterable &lin return; } - 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/test/common/circular_buffer_benchmark.cc b/sdk/test/common/circular_buffer_benchmark.cc index 97e2bf2aaf..2470cbe059 100644 --- a/sdk/test/common/circular_buffer_benchmark.cc +++ b/sdk/test/common/circular_buffer_benchmark.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "benchmark/benchmark.h" @@ -29,8 +30,10 @@ static uint64_t ConsumeBufferNumbers(BaselineCircularBuffer &buffer) n { uint64_t result = 0; buffer.Consume([&](std::unique_ptr &&x) { - result += *x; - x.reset(); + auto val = std::move(x); + + result += *val; + val.reset(); }); return result; } diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 8483e5c55f..8b649e38f7 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -224,7 +224,10 @@ class DummyProcessor : public LogRecordProcessor return std::unique_ptr(new DummyLogRecordable()); } - void OnEmit(std::unique_ptr && /* record */) noexcept override {} + void OnEmit(std::unique_ptr &&record) noexcept override + { + auto record_ptr = std::move(record); + } bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept override { return true; } bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override { return true; } }; diff --git a/sdk/test/metrics/metric_collector_test.cc b/sdk/test/metrics/metric_collector_test.cc index c55bf77833..3fab6983dc 100644 --- a/sdk/test/metrics/metric_collector_test.cc +++ b/sdk/test/metrics/metric_collector_test.cc @@ -46,39 +46,42 @@ namespace MetricFilter::TestMetricFn AcceptAllTestMetricFn() { - return [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit) -> MetricFilter::MetricFilterResult { + return [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, + nostd::string_view /*unit*/) -> MetricFilter::MetricFilterResult { return MetricFilter::MetricFilterResult::kAccept; }; } MetricFilter::TestMetricFn DropAllTestMetricFn() { - return [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit) -> MetricFilter::MetricFilterResult { + return [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, + nostd::string_view /*unit*/) -> MetricFilter::MetricFilterResult { return MetricFilter::MetricFilterResult::kDrop; }; } MetricFilter::TestMetricFn AcceptPartialAllTestMetricFn() { - return [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit) -> MetricFilter::MetricFilterResult { + return [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, + nostd::string_view /*unit*/) -> MetricFilter::MetricFilterResult { return MetricFilter::MetricFilterResult::kAcceptPartial; }; } MetricFilter::TestAttributesFn AcceptAllTestAttributesFn() { - return [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit, - const PointAttributes &attributes) -> MetricFilter::AttributesFilterResult { + return [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, nostd::string_view /*unit*/, + const PointAttributes & /*attributes*/) -> MetricFilter::AttributesFilterResult { return MetricFilter::AttributesFilterResult::kAccept; }; } MetricFilter::TestAttributesFn DropAllTestAttributesFn() { - return [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit, - const PointAttributes &attributes) -> MetricFilter::AttributesFilterResult { + return [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, nostd::string_view /*unit*/, + const PointAttributes & /*attributes*/) -> MetricFilter::AttributesFilterResult { return MetricFilter::AttributesFilterResult::kDrop; }; } @@ -89,7 +92,7 @@ class testing::MetricCollectorTest : public Test { public: std::weak_ptr AddMetricReaderToMeterContext( - std::shared_ptr context, + const std::shared_ptr &context, std::shared_ptr reader, std::unique_ptr metric_filter = nullptr) noexcept { @@ -194,9 +197,9 @@ TEST_F(MetricCollectorTest, CollectWithMetricFilterTestMetricTest3) auto meter = std::shared_ptr(new Meter(context, std::move(scope))); context->AddMeter(meter); - auto test_metric_fn = [](const InstrumentationScope &scope, nostd::string_view name, - const InstrumentType &type, - nostd::string_view unit) -> MetricFilter::MetricFilterResult { + auto test_metric_fn = [](const InstrumentationScope & /*scope*/, nostd::string_view name, + const InstrumentType & /*type*/, + nostd::string_view /*unit*/) -> MetricFilter::MetricFilterResult { std::string name_copy = {name.begin(), name.end()}; if (name_copy.find("_accept") != std::string::npos) { @@ -249,8 +252,8 @@ TEST_F(MetricCollectorTest, CollectWithMetricFilterTestAttributesTest1) context->AddMeter(meter); auto test_attributes_fn = - [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit, + [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, nostd::string_view /*unit*/, const PointAttributes &attributes) -> MetricFilter::AttributesFilterResult { if (attributes.GetAttributes().find("stream") != attributes.GetAttributes().end()) { @@ -332,8 +335,8 @@ TEST_F(MetricCollectorTest, CollectWithMetricFilterTestAttributesTest2) context->AddMeter(meter); auto test_attributes_fn = - [](const InstrumentationScope &scope, nostd::string_view name, const InstrumentType &type, - nostd::string_view unit, + [](const InstrumentationScope & /*scope*/, nostd::string_view /*name*/, + const InstrumentType & /*type*/, nostd::string_view /*unit*/, const PointAttributes &attributes) -> MetricFilter::AttributesFilterResult { if (attributes.GetAttributes().find("stream") != attributes.GetAttributes().end()) {