Skip to content

Commit f74d413

Browse files
authored
[CodeHealth] Fix clang-tidy warnings part 2 (#3496)
1 parent 8465778 commit f74d413

File tree

16 files changed

+76
-63
lines changed

16 files changed

+76
-63
lines changed

.github/workflows/clang-tidy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
matrix:
1818
include:
1919
- cmake_options: all-options-abiv1-preview
20-
warning_limit: 172
20+
warning_limit: 109
2121
- cmake_options: all-options-abiv2-preview
22-
warning_limit: 173
22+
warning_limit: 109
2323
steps:
2424
- name: Harden the runner (Audit all outbound calls)
2525
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Increment the:
3333
* [CodeHealth] Fix clang-tidy warnings part 1
3434
[#3493](https://github.com/open-telemetry/opentelemetry-cpp/pull/3493)
3535

36+
* [CodeHealth] Fix clang-tidy warnings part 2
37+
[#3496](https://github.com/open-telemetry/opentelemetry-cpp/pull/3496)
38+
3639
Important changes:
3740

3841
* [REMOVAL] Removed deprecated semantic convention header files

api/include/opentelemetry/plugin/hook.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include "opentelemetry/nostd/unique_ptr.h"
7+
#include "opentelemetry/plugin/factory.h"
78
#include "opentelemetry/version.h"
89

910
#ifdef _WIN32
@@ -42,7 +43,6 @@ namespace plugin
4243
{
4344

4445
struct LoaderInfo;
45-
class FactoryImpl;
4646

4747
using OpenTelemetryHook =
4848
nostd::unique_ptr<Factory::FactoryImpl> (*)(const LoaderInfo &loader_info,

api/test/logs/logger_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ class TestLogger : public Logger
206206

207207
using Logger::EmitLogRecord;
208208

209-
void EmitLogRecord(nostd::unique_ptr<opentelemetry::logs::LogRecord> &&) noexcept override {}
209+
void EmitLogRecord(
210+
nostd::unique_ptr<opentelemetry::logs::LogRecord> &&log_record) noexcept override
211+
{
212+
auto log_record_ptr = std::move(log_record);
213+
}
210214
};
211215

212216
// Define a basic LoggerProvider class that returns an instance of the logger class defined above

examples/multi_processor/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::shared_ptr<InMemorySpanData> InitTracer()
5454
trace_sdk::TracerProviderFactory::Create(std::move(processors));
5555

5656
// Set the global trace provider
57-
trace_sdk::Provider::SetTracerProvider(std::move(provider));
57+
trace_sdk::Provider::SetTracerProvider(provider);
5858

5959
return data;
6060
}

examples/otlp/http_instrumented_main.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,46 +103,45 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum
103103
{
104104
std::cout << ", priority " << priority_;
105105
}
106-
std::cout << std::endl << std::flush;
106+
std::cout << "\n" << std::flush;
107107
}
108108

109109
void OnEnd() override
110110
{
111111
std::lock_guard<std::mutex> lock_guard(serialize);
112-
std::cout << "OnEnd() thread " << thread_name_ << ", id " << std::this_thread::get_id()
113-
<< std::endl
112+
std::cout << "OnEnd() thread " << thread_name_ << ", id " << std::this_thread::get_id() << "\n"
114113
<< std::flush;
115114
}
116115

117116
void BeforeWait() override
118117
{
119118
std::lock_guard<std::mutex> lock_guard(serialize);
120119
std::cout << "BeforeWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
121-
<< ", waiting" << std::endl
120+
<< ", waiting\n"
122121
<< std::flush;
123122
}
124123

125124
void AfterWait() override
126125
{
127126
std::lock_guard<std::mutex> lock_guard(serialize);
128127
std::cout << "AfterWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
129-
<< ", done waiting" << std::endl
128+
<< ", done waiting\n"
130129
<< std::flush;
131130
}
132131

133132
void BeforeLoad() override
134133
{
135134
std::lock_guard<std::mutex> lock_guard(serialize);
136135
std::cout << "BeforeLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id()
137-
<< ", about to work" << std::endl
136+
<< ", about to work\n"
138137
<< std::flush;
139138
}
140139

141140
void AfterLoad() override
142141
{
143142
std::lock_guard<std::mutex> lock_guard(serialize);
144143
std::cout << "AfterLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id()
145-
<< ", done working" << std::endl
144+
<< ", done working\n"
146145
<< std::flush;
147146
}
148147

@@ -341,25 +340,25 @@ int main(int argc, char *argv[])
341340
logger_opts.url = "http://localhost:4318/v1/logs";
342341
}
343342

344-
std::cout << "Initializing opentelemetry-cpp" << std::endl << std::flush;
343+
std::cout << "Initializing opentelemetry-cpp\n" << std::flush;
345344

346345
InitTracer();
347346
InitMetrics();
348347
InitLogger();
349348

350-
std::cout << "Application payload" << std::endl << std::flush;
349+
std::cout << "Application payload\n" << std::flush;
351350

352351
foo_library();
353352

354353
std::string name{"otlp_http_metric_example"};
355354
foo_library::observable_counter_example(name);
356355

357-
std::cout << "Shutting down opentelemetry-cpp" << std::endl << std::flush;
356+
std::cout << "Shutting down opentelemetry-cpp\n" << std::flush;
358357

359358
CleanupLogger();
360359
CleanupMetrics();
361360
CleanupTracer();
362361

363-
std::cout << "Done" << std::endl << std::flush;
362+
std::cout << "Done\n" << std::flush;
364363
return 0;
365364
}

exporters/ostream/test/ostream_log_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout)
125125
" severity_text : INVALID\n",
126126
" body : \n",
127127
" resource : \n",
128-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
128+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
129129
" telemetry.sdk.name: opentelemetry\n",
130130
" telemetry.sdk.language: cpp\n",
131131
" attributes : \n",
@@ -136,7 +136,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout)
136136
" trace_flags : 00\n",
137137
" scope : \n",
138138
" name : otel-cpp\n",
139-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
139+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
140140
" schema_url : https://opentelemetry.io/schemas/1.15.0\n",
141141
" attributes : \n",
142142
" scope.attr.key: scope.attr.value\n",
@@ -199,7 +199,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout)
199199
" severity_text : TRACE\n"
200200
" body : Message\n",
201201
" resource : \n",
202-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
202+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
203203
" telemetry.sdk.name: opentelemetry\n",
204204
" telemetry.sdk.language: cpp\n",
205205
" attributes : \n",
@@ -210,7 +210,7 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout)
210210
" trace_flags : 00\n",
211211
" scope : \n",
212212
" name : otel-cpp\n",
213-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
213+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
214214
" schema_url : https://opentelemetry.io/schemas/1.15.0\n",
215215
" attributes : \n",
216216
" scope.attr.key: scope.attr.value\n",
@@ -270,7 +270,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
270270
" severity_text : INVALID\n",
271271
" body : \n",
272272
" resource : \n",
273-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
273+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
274274
" telemetry.sdk.name: opentelemetry\n",
275275
" telemetry.sdk.language: cpp\n",
276276
" service.name: unknown_service\n",
@@ -284,7 +284,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
284284
" trace_flags : 00\n",
285285
" scope : \n",
286286
" name : otel-cpp\n",
287-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
287+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
288288
" schema_url : https://opentelemetry.io/schemas/1.15.0\n",
289289
" attributes : \n",
290290
" scope.attr.key: scope.attr.value\n",
@@ -352,7 +352,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
352352
" body : \n",
353353
" resource : \n",
354354
" service.name: unknown_service\n",
355-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
355+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
356356
" telemetry.sdk.name: opentelemetry\n",
357357
" telemetry.sdk.language: cpp\n",
358358
" res1: [1,2,3]\n",
@@ -365,7 +365,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
365365
" trace_flags : 00\n",
366366
" scope : \n",
367367
" name : otel-cpp\n",
368-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
368+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
369369
" schema_url : https://opentelemetry.io/schemas/1.15.0\n",
370370
" attributes : \n",
371371
" scope.attr.key: scope.attr.value\n",
@@ -425,7 +425,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest)
425425
" severity_text : DEBUG\n",
426426
" body : Hello\n",
427427
" resource : \n",
428-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
428+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
429429
" service.name: unknown_service\n",
430430
" telemetry.sdk.name: opentelemetry\n",
431431
" telemetry.sdk.language: cpp\n",
@@ -437,7 +437,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest)
437437
" trace_flags : 00\n",
438438
" scope : \n",
439439
" name : opentelelemtry_library\n",
440-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
440+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
441441
" schema_url : https://opentelemetry.io/schemas/1.11.0\n",
442442
" attributes : \n",
443443
" scope.attr.key: 123\n",
@@ -496,7 +496,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId)
496496
" severity_text : DEBUG\n",
497497
" body : Hello {key1} {key2}\n",
498498
" resource : \n",
499-
" telemetry.sdk.version: " OPENTELEMETRY_VERSION "\n",
499+
std::string{" telemetry.sdk.version: "} + OPENTELEMETRY_VERSION + "\n",
500500
" service.name: unknown_service\n",
501501
" telemetry.sdk.name: opentelemetry\n",
502502
" telemetry.sdk.language: cpp\n",
@@ -508,7 +508,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId)
508508
" trace_flags : 00\n",
509509
" scope : \n",
510510
" name : opentelelemtry_library\n",
511-
" version : " OPENTELEMETRY_SDK_VERSION "\n",
511+
std::string{" version : "} + OPENTELEMETRY_SDK_VERSION + "\n",
512512
" schema_url : https://opentelemetry.io/schemas/1.11.0\n",
513513
" attributes : \n",
514514
" scope.attr.key: 123\n",

exporters/otlp/src/otlp_file_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
12001200
{
12011201
if (file_pattern[i] == '%')
12021202
{
1203-
int checked = static_cast<int>(file_pattern[i + 1]);
1203+
int checked = static_cast<unsigned char>(file_pattern[i + 1]);
12041204
if (checked > 0 && checked < 128 && check_interval[checked] > 0)
12051205
{
12061206
if (0 == check_file_path_interval_ ||

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallData : public OtlpGrpcAsyncCal
9191
result_callback;
9292

9393
OtlpGrpcAsyncCallData() {}
94-
virtual ~OtlpGrpcAsyncCallData() {}
94+
~OtlpGrpcAsyncCallData() override {}
9595
};
9696
} // namespace
9797
#endif

exporters/otlp/src/otlp_http_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ void ConvertListFieldToJson(nlohmann::json &value,
665665
OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options)
666666
: is_shutdown_(false),
667667
options_(std::move(options)),
668-
http_client_(http_client::HttpClientFactory::Create(options.thread_instrumentation)),
668+
http_client_(http_client::HttpClientFactory::Create(options_.thread_instrumentation)),
669669
start_session_counter_(0),
670670
finished_session_counter_(0)
671671
{

0 commit comments

Comments
 (0)