Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 133
warning_limit: 113
- cmake_options: all-options-abiv2-preview
warning_limit: 144
warning_limit: 124
env:
CC: /usr/bin/clang-22
CXX: /usr/bin/clang++-22
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Increment the:
in the value as-is rather than dropping the attribute.
[#1536](https://github.com/open-telemetry/opentelemetry-cpp/issues/1536)

* [CLEANUP] Replace `push_back` with `emplace_back` where applicable to
construct objects in-place, avoiding unnecessary temporaries.
[#4476](https://github.com/open-telemetry/opentelemetry-cpp/pull/4476)

* [BUG] Fix `MultiSpanProcessor` and `MultiLogRecordProcessor` not reporting
failures from `ForceFlush` and `Shutdown` when a child processor failed.
[#4472](https://github.com/open-telemetry/opentelemetry-cpp/pull/4472)
Expand Down
2 changes: 1 addition & 1 deletion api/test/baggage/propagation/baggage_propagator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST(BaggagePropagatorTest, ExtractAndInjectBaggage)

std::vector<std::string> fields;
format.Fields([&fields](nostd::string_view field) {
fields.push_back(field.data());
fields.emplace_back(field.data());
return true;
});
EXPECT_EQ(fields.size(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST_F(CompositePropagatorTest, Inject)

std::vector<std::string> fields;
composite_propagator_->Fields([&fields](nostd::string_view field) {
fields.push_back(field.data());
fields.emplace_back(field.data());
return true;
});
EXPECT_EQ(fields.size(), 3);
Expand Down
2 changes: 1 addition & 1 deletion api/test/context/runtime_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TEST(RuntimeContextTest, DetachOutOfOrder)
contexts.reserve(indices.size());
for (auto i : indices)
{
contexts.push_back(context::Context("index", static_cast<int64_t>(i)));
contexts.emplace_back("index", static_cast<int64_t>(i));
}

do
Expand Down
2 changes: 1 addition & 1 deletion api/test/nostd/shared_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static void SharedPtrTest_Sort(size_t size = 10)

for (int i = static_cast<int>(size); i > 0; i--)
{
nums.push_back(shared_ptr<int>(new int(i)));
nums.emplace_back(new int(i));
}

auto nums2 = nums;
Expand Down
2 changes: 1 addition & 1 deletion api/test/trace/propagation/http_text_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ TEST(GlobalPropagator, SetAndGet)

std::vector<std::string> fields;
propagator->Fields([&fields](nostd::string_view field) {
fields.push_back(field.data());
fields.emplace_back(field.data());
return true;
});
EXPECT_EQ(fields.size(), 2);
Expand Down
2 changes: 1 addition & 1 deletion api/test/trace/propagation/jaeger_propagation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST(JaegerPropagatorTest, InjectsContext)

std::vector<std::string> fields;
format.Fields([&fields](nostd::string_view field) {
fields.push_back(field.data());
fields.emplace_back(field.data());
return true;
});
EXPECT_EQ(fields.size(), 1);
Expand Down
4 changes: 2 additions & 2 deletions examples/multithreaded/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ void run_threads()
{
// This shows how one can effectively use Scope objects to correctly
// parent spans across threads.
threads.push_back(std::thread([=] {
threads.emplace_back([=] {
trace_api::Scope scope(thread_span);
auto thread_span_2 =
get_tracer()->StartSpan(std::string("thread ") + std::to_string(thread_num));
}));
});
}

std::for_each(threads.begin(), threads.end(), [](std::thread &th) { th.join(); });
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/src/otlp_file_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,17 @@ class OPENTELEMETRY_LOCAL_SYMBOL FileSystemUtil
}
else
{
out.push_back(token);
out.emplace_back(token);
}
}
else if (0 != std::strcmp(".", token))
{
out.push_back(token);
out.emplace_back(token);
}
}
else
{
out.push_back(token);
out.emplace_back(token);
}
}
token = SAFE_STRTOK_S(nullptr, "\\/", &saveptr);
Expand Down
6 changes: 3 additions & 3 deletions ext/include/opentelemetry/ext/http/server/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,23 @@ class HttpServer : private SocketTools::Reactor::SocketCallback
HttpRequestHandler &addHandler(const std::string &root, HttpRequestCallback &handler)
{
// No thread-safety here!
m_handlers.push_back({root, &handler});
m_handlers.emplace_back(root, &handler);
LOG_INFO("HttpServer: Added handler for %s", root.c_str());
return m_handlers.back();
}

HttpRequestHandler &operator[](const std::string &root)
{
// No thread-safety here!
m_handlers.push_back({root, nullptr});
m_handlers.emplace_back(root, nullptr);
LOG_INFO("HttpServer: Added handler for %s", root.c_str());
return m_handlers.back();
}

HttpServer &operator+=(std::pair<const std::string &, HttpRequestCallback &> other)
{
LOG_INFO("HttpServer: Added handler for %s", other.first.c_str());
m_handlers.push_back(HttpRequestHandler(other.first, &other.second));
m_handlers.emplace_back(other.first, &other.second);
return (*this);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/include/opentelemetry/ext/http/server/socket_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ struct Reactor : protected common::Thread
EV_SET(&event, event.ident, EVFILT_WRITE, EV_ADD, 0, 0, NULL);
kevent(kq, &event, 1, NULL, 0, NULL);
#endif
m_sockets.push_back(SocketData());
m_sockets.emplace_back();
m_sockets.back().socket = socket;
m_sockets.back().flags = 0;
it = m_sockets.end() - 1;
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/common/random_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(RandomTest, AtomicFlagMultiThreadTest)
threads.reserve(10);
for (int i = 0; i < 10; ++i)
{
threads.push_back(std::thread(doSomethingOnce, &count));
threads.emplace_back(doSomethingOnce, &count);
}
for (auto &t : threads)
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/metrics/attributes_hashmap_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void BM_AttributseHashMap(benchmark::State &state)
{
for (size_t i = 0; i < MAX_THREADS; i++)
{
workers.push_back(std::thread(work, i));
workers.emplace_back(work, i);
}
}

Expand Down
12 changes: 6 additions & 6 deletions sdk/test/metrics/measurements_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void BM_MeasurementsTest(benchmark::State &state)
std::atomic<size_t> cur_processed{0};
for (size_t i = 0; i < NUM_CORES; i++)
{
threads.push_back(std::thread([&h, &cur_processed, &MAX_MEASUREMENTS, &attributes]() {
threads.emplace_back([&h, &cur_processed, &MAX_MEASUREMENTS, &attributes]() {
while (cur_processed++ <= MAX_MEASUREMENTS)
{
size_t index = rand() % 1000;
Expand All @@ -105,7 +105,7 @@ void BM_MeasurementsTest(benchmark::State &state)
attributes[index]),
opentelemetry::context::Context{});
}
}));
});
}
for (auto &thread : threads)
{
Expand Down Expand Up @@ -141,7 +141,7 @@ void BM_MeasurementsThreadsShareCounterTest(benchmark::State &state)
std::atomic<size_t> cur_processed{0};
for (size_t i = 0; i < NUM_CORES; i++)
{
threads.push_back(std::thread(
threads.emplace_back(
[&h, &cur_processed, &MAX_MEASUREMENTS, &attributes](size_t /*thread_id*/) {
while (cur_processed++ <= MAX_MEASUREMENTS)
{
Expand All @@ -152,7 +152,7 @@ void BM_MeasurementsThreadsShareCounterTest(benchmark::State &state)
opentelemetry::context::Context{});
}
},
i));
i);
}
for (auto &thread : threads)
{
Expand Down Expand Up @@ -187,7 +187,7 @@ void BM_MeasurementsPerThreadCounterTest(benchmark::State &state)
std::atomic<size_t> cur_processed{0};
for (size_t i = 0; i < NUM_CORES; i++)
{
threads.push_back(std::thread(
threads.emplace_back(
[&m, &cur_processed, &MAX_MEASUREMENTS, &attributes](size_t thread_id) {
// Each thread creates its own counter with the same name but a unique description
// encoding the thread id, ensuring no shared underlying storage.
Expand All @@ -204,7 +204,7 @@ void BM_MeasurementsPerThreadCounterTest(benchmark::State &state)
opentelemetry::context::Context{});
}
},
i));
i);
}
for (auto &thread : threads)
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/metrics/meter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class TestLogHandler : public LogHandler
if (LogLevel::Warning == level)
{
std::cout << msg << "\n";
warnings.push_back(msg);
warnings.emplace_back(msg);
}
}

Expand Down
Loading