Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f5c0187
fix clang-tidy performance-avoid-endl warnings
dbarker Jun 24, 2025
e7fa658
fix clang-tidy cppcoreguidelines-use-default-member-init warning
dbarker Jun 24, 2025
3285226
fix clang-tidy bugprone-forward-declaration-namespace warning
dbarker Jun 24, 2025
65a6ad9
fix clang-tidy cppcoreguidelines-rvalue-reference-param-not-moved war…
dbarker Jun 24, 2025
6092c03
fix clang-tidy performance-unnecessary-value-param warnings
dbarker Jun 24, 2025
d954e2f
fix clang-tidy misc-unused-parameters warnings
dbarker Jun 24, 2025
51aae2a
fix clang-tidy cppcoreguidelines-explicit-virtual-functions warnings
dbarker Jun 24, 2025
84030ff
fix clang-tidy performance-move-const-arg warnings
dbarker Jun 24, 2025
09ab668
fix clang-tidy bugprone-signed-char-misuse warning
dbarker Jun 24, 2025
361904c
fix clang-tidy bugprone-suspicious-missing-comma warning
dbarker Jun 24, 2025
ddd49c9
fix clang-tidy bugprone-use-after-move warning
dbarker Jun 24, 2025
6ff42dd
fix clang-tidy cppcoreguidelines-rvalue-reference-param-not-moved war…
dbarker Jun 24, 2025
aab0da2
fix iwyu warning
dbarker Jun 24, 2025
aea63d1
reduce clang-tidy warning limits
dbarker Jun 24, 2025
b4ca7f0
revert warnings fixes relate to moving the protobuf objects with the …
dbarker Jun 25, 2025
82262b0
address feedback. remove nolint comments for cppcoreguidelines-rvalue…
dbarker Jun 25, 2025
bf41c99
add changelog entry
dbarker Jun 25, 2025
efcbe1a
increase the clang-tidy warning limit after otlp grpc fix revert
dbarker Jun 25, 2025
e2cc5a4
Merge branch 'main' into fix_clang_tidy_warnings_part_2
marcalff Jun 25, 2025
22ca025
Merge branch 'main' into fix_clang_tidy_warnings_part_2
marcalff Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/plugin/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/plugin/factory.h"
#include "opentelemetry/version.h"

#ifdef _WIN32
Expand Down Expand Up @@ -42,7 +43,6 @@ namespace plugin
{

struct LoaderInfo;
class FactoryImpl;

using OpenTelemetryHook =
nostd::unique_ptr<Factory::FactoryImpl> (*)(const LoaderInfo &loader_info,
Expand Down
6 changes: 5 additions & 1 deletion api/test/logs/logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ class TestLogger : public Logger

using Logger::EmitLogRecord;

void EmitLogRecord(nostd::unique_ptr<opentelemetry::logs::LogRecord> &&) noexcept override {}
void EmitLogRecord(
nostd::unique_ptr<opentelemetry::logs::LogRecord> &&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
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_processor/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::shared_ptr<InMemorySpanData> 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;
}
Expand Down
21 changes: 10 additions & 11 deletions examples/otlp/http_instrumented_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,45 @@ 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<std::mutex> 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;
}

void BeforeWait() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "BeforeWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", waiting" << std::endl
<< ", waiting\n"
<< std::flush;
}

void AfterWait() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "AfterWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", done waiting" << std::endl
<< ", done waiting\n"
<< std::flush;
}

void BeforeLoad() override
{
std::lock_guard<std::mutex> 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;
}

void AfterLoad() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "AfterLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", done working" << std::endl
<< ", done working\n"
<< std::flush;
}

Expand Down Expand Up @@ -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;
}
24 changes: 12 additions & 12 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_file_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
{
if (file_pattern[i] == '%')
{
int checked = static_cast<int>(file_pattern[i + 1]);
int checked = static_cast<unsigned char>(file_pattern[i + 1]);
if (checked > 0 && checked < 128 && check_interval[checked] > 0)
{
if (0 == check_file_path_interval_ ||
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallData : public OtlpGrpcAsyncCal
result_callback;

OtlpGrpcAsyncCallData() {}
virtual ~OtlpGrpcAsyncCallData() {}
~OtlpGrpcAsyncCallData() override {}
};
} // namespace
#endif
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -255,15 +255,15 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test
const std::shared_ptr<OtlpGrpcClient> &client)
{
return std::unique_ptr<sdk::logs::LogRecordExporter>(
new OtlpGrpcLogRecordExporter(std::move(stub_interface), std::move(client)));
new OtlpGrpcLogRecordExporter(std::move(stub_interface), client));
}

std::unique_ptr<sdk::trace::SpanExporter> GetExporter(
std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> &stub_interface,
const std::shared_ptr<OtlpGrpcClient> &client)
{
return std::unique_ptr<sdk::trace::SpanExporter>(
new OtlpGrpcExporter(std::move(stub_interface), std::move(client)));
new OtlpGrpcExporter(std::move(stub_interface), client));
}

// Get the options associated with the given exporter.
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/common/global_log_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ namespace
struct GlobalLogHandlerData
{
nostd::shared_ptr<LogHandler> handler;
LogLevel log_level;
LogLevel log_level{LogLevel::Warning};

GlobalLogHandlerData()
: handler(nostd::shared_ptr<LogHandler>(new DefaultLogHandler)), log_level(LogLevel::Warning)
{}
GlobalLogHandlerData() : handler(nostd::shared_ptr<LogHandler>(new DefaultLogHandler)) {}
~GlobalLogHandlerData() { is_singleton_destroyed = true; }

GlobalLogHandlerData(const GlobalLogHandlerData &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions sdk/test/common/circular_buffer_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <memory>
#include <random>
#include <thread>
#include <utility>
#include <vector>
#include "benchmark/benchmark.h"

Expand All @@ -29,8 +30,10 @@ static uint64_t ConsumeBufferNumbers(BaselineCircularBuffer<uint64_t> &buffer) n
{
uint64_t result = 0;
buffer.Consume([&](std::unique_ptr<uint64_t> &&x) {
result += *x;
x.reset();
auto val = std::move(x);

result += *val;
val.reset();
});
return result;
}
Expand Down
5 changes: 4 additions & 1 deletion sdk/test/logs/logger_provider_sdk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ class DummyProcessor : public LogRecordProcessor
return std::unique_ptr<Recordable>(new DummyLogRecordable());
}

void OnEmit(std::unique_ptr<Recordable> && /* record */) noexcept override {}
void OnEmit(std::unique_ptr<Recordable> &&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; }
};
Expand Down
Loading
Loading