diff --git a/.clang-tidy b/.clang-tidy index de9d30290d..c700e0f6d0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1 +1 @@ -Checks: 'clang-analyzer-*,performance-*,bugprone-*' \ No newline at end of file +Checks: 'clang-analyzer-*,performance-*,bugprone-*,google-*,concurrency-*' \ No newline at end of file diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index 6c799cda27..5634451a97 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -98,7 +98,9 @@ class OPENTELEMETRY_EXPORT Baggage kv_properties_->GetAllEntries( [&baggage, &key](nostd::string_view e_key, nostd::string_view e_value) { if (key != e_key) + { baggage->kv_properties_->AddEntry(e_key, e_value); + } return true; }); return baggage; diff --git a/api/include/opentelemetry/baggage/baggage_context.h b/api/include/opentelemetry/baggage/baggage_context.h index e5b9556d3f..a0016353ba 100644 --- a/api/include/opentelemetry/baggage/baggage_context.h +++ b/api/include/opentelemetry/baggage/baggage_context.h @@ -27,7 +27,7 @@ inline nostd::shared_ptr GetBaggage(const context::Context &context) no } inline context::Context SetBaggage(context::Context &context, - nostd::shared_ptr baggage) noexcept + const nostd::shared_ptr &baggage) noexcept { return context.SetValue(kBaggageHeader, baggage); } diff --git a/api/include/opentelemetry/context/context.h b/api/include/opentelemetry/context/context.h index b7c8f8475c..14f8cfb4fc 100644 --- a/api/include/opentelemetry/context/context.h +++ b/api/include/opentelemetry/context/context.h @@ -57,9 +57,9 @@ class Context // Accepts a new iterable and then returns a new context that // contains the new key and value data. It attaches the // exisiting list to the end of the new list. - Context SetValue(nostd::string_view key, ContextValue value) noexcept + Context SetValue(nostd::string_view key, const ContextValue &value) noexcept { - Context context = Context(key, std::move(value)); + Context context = Context(key, value); context.head_->next_ = head_; return context; } diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 5ee86dce23..53bf364cfb 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -85,7 +85,9 @@ class string_view size_type len = (std::min)(size(), v.size()); int result = Traits::compare(data(), v.data(), len); if (result == 0) + { result = size() == v.size() ? 0 : (size() < v.size() ? -1 : 1); + } return result; } diff --git a/api/include/opentelemetry/trace/context.h b/api/include/opentelemetry/trace/context.h index cd8395d768..08b1e327ca 100644 --- a/api/include/opentelemetry/trace/context.h +++ b/api/include/opentelemetry/trace/context.h @@ -34,7 +34,8 @@ inline bool IsRootSpan(const context::Context &context) noexcept } // Set Span into explicit context -inline context::Context SetSpan(context::Context &context, nostd::shared_ptr span) noexcept +inline context::Context SetSpan(context::Context &context, + const nostd::shared_ptr &span) noexcept { return context.SetValue(kSpanKey, span); } diff --git a/api/include/opentelemetry/trace/propagation/detail/hex.h b/api/include/opentelemetry/trace/propagation/detail/hex.h index 3bf66e84bc..6aa7c46de9 100644 --- a/api/include/opentelemetry/trace/propagation/detail/hex.h +++ b/api/include/opentelemetry/trace/propagation/detail/hex.h @@ -36,7 +36,7 @@ constexpr int8_t kHexDigits[256] = { inline int8_t HexToInt(char c) { - return kHexDigits[uint8_t(c)]; + return kHexDigits[static_cast(c)]; } inline bool IsValidHex(nostd::string_view s) @@ -57,8 +57,8 @@ inline bool HexToBinary(nostd::string_view hex, uint8_t *buffer, size_t buffer_s return false; } - int64_t hex_size = int64_t(hex.size()); - int64_t buffer_pos = int64_t(buffer_size) - (hex_size + 1) / 2; + int64_t hex_size = static_cast(hex.size()); + int64_t buffer_pos = static_cast(buffer_size) - (hex_size + 1) / 2; int64_t last_hex_pos = hex_size - 1; bool is_hex_size_odd = (hex_size % 2) == 1; diff --git a/api/include/opentelemetry/trace/trace_state.h b/api/include/opentelemetry/trace/trace_state.h index f51410025a..1579c4eb54 100644 --- a/api/include/opentelemetry/trace/trace_state.h +++ b/api/include/opentelemetry/trace/trace_state.h @@ -184,7 +184,9 @@ class OPENTELEMETRY_EXPORT TraceState kv_properties_->GetAllEntries( [&ts, &key](nostd::string_view e_key, nostd::string_view e_value) { if (key != e_key) + { ts->kv_properties_->AddEntry(e_key, e_value); + } return true; }); return ts; diff --git a/api/test/common/spinlock_benchmark.cc b/api/test/common/spinlock_benchmark.cc index d0fef2c41b..b58577e5f5 100644 --- a/api/test/common/spinlock_benchmark.cc +++ b/api/test/common/spinlock_benchmark.cc @@ -47,7 +47,9 @@ inline void SpinThrash(benchmark::State &s, SpinLockType &spinlock, LockF lock, } // Join threads for (auto &thread : threads) + { thread.join(); + } threads.clear(); } } diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index 0c79c7efd2..4da9db1f11 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -173,7 +173,7 @@ static void SharedPtrTest_Sort(size_t size = 10) auto nums2 = nums; std::sort(nums.begin(), nums.end(), - [](shared_ptr a, shared_ptr b) { return *a < *b; }); + [](const shared_ptr &a, const shared_ptr &b) { return *a < *b; }); EXPECT_NE(nums, nums2); diff --git a/examples/etw_threads/main.cc b/examples/etw_threads/main.cc index d25883d1d1..2edb44112e 100644 --- a/examples/etw_threads/main.cc +++ b/examples/etw_threads/main.cc @@ -139,7 +139,9 @@ int main(int arc, char **argv) try { if (th.joinable()) + { th.join(); + } } catch (...) { diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index b8f233dcc7..ec02691b28 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -36,7 +36,7 @@ class GreeterClient public: GreeterClient(std::shared_ptr channel) : stub_(Greeter::NewStub(channel)) {} - std::string Greet(std::string ip, uint16_t port) + std::string Greet(const std::string &ip, uint16_t port) { // Build gRPC Context objects and protobuf message containers GreetRequest request; diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index e26f6bd2c6..973109a9ee 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -99,7 +99,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/exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h index 3a14780d8c..f053355c93 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h @@ -158,7 +158,7 @@ class PropertyValue : public PropertyVariant * @param v * @return */ - PropertyValue() : PropertyVariant(int32_t(0)) {} + PropertyValue() : PropertyVariant(static_cast(0)) {} /** * @brief PropertyValue from array of characters as string. diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index 9071fd47d4..ad63c468e1 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -214,7 +214,7 @@ class Tracer : public opentelemetry::trace::Tracer, { size_t idx = 0; std::string linksValue; - links.ForEachKeyValue([&](opentelemetry::trace::SpanContext ctx, + links.ForEachKeyValue([&](const opentelemetry::trace::SpanContext &ctx, const opentelemetry::common::KeyValueIterable &) { if (!linksValue.empty()) { diff --git a/exporters/etw/include/opentelemetry/exporters/etw/utils.h b/exporters/etw/include/opentelemetry/exporters/etw/utils.h index f3665efc80..20afc951d1 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/utils.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/utils.h @@ -46,10 +46,10 @@ namespace utils /// static constexpr uint32_t hashCode(const char *str, uint32_t h = 0) { - return (uint32_t)(!str[h] ? 5381 : ((uint32_t)hashCode(str, h + 1) * (uint32_t)33) ^ str[h]); + return (!str[h] ? 5381 : (hashCode(str, h + 1) * static_cast(33)) ^ str[h]); } -#define CONST_UINT32_T(x) std::integral_constant::value +#define CONST_UINT32_T(x) std::integral_constant::value #define CONST_HASHCODE(name) CONST_UINT32_T(OPENTELEMETRY_NAMESPACE::utils::hashCode(#name)) diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index 3b86f257d6..b7c7f62524 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -35,7 +35,9 @@ void print_value(const std::vector &vec, std::ostream &sout) { sout << v; if (i != sz) + { sout << ','; + } i++; }; sout << ']'; @@ -51,7 +53,9 @@ void print_value(const nostd::span &vec, std::ostream &sout) { sout << v; if (i != sz) + { sout << ','; + } i++; }; sout << ']'; diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h index 24bc8e5be7..840d7d5b8a 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h @@ -66,10 +66,10 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor bool isShutdown() const noexcept; void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); }; } // namespace logs } // namespace exporter diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h index 1ad124a9ab..f1b2cd6ef9 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h @@ -79,7 +79,7 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr void printPointData(const opentelemetry::sdk::metrics::PointType &point_data); void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes); void printAttributes(const std::map &map, - const std::string prefix); + const std::string &prefix); void printResources(const opentelemetry::sdk::resource::Resource &resources); }; } // namespace metrics diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index a7de9a5eb4..e22eb77f3e 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -69,7 +69,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter // various print helpers void printAttributes( const std::unordered_map &map, - const std::string prefix = "\n\t"); + const std::string &prefix = "\n\t"); void printEvents(const std::vector &events); diff --git a/exporters/ostream/src/log_record_exporter.cc b/exporters/ostream/src/log_record_exporter.cc index 7f661276c8..26266161c3 100644 --- a/exporters/ostream/src/log_record_exporter.cc +++ b/exporters/ostream/src/log_record_exporter.cc @@ -75,11 +75,11 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( // Convert trace, spanid, traceflags into exportable representation constexpr int trace_id_len = 32; - constexpr int span_id__len = 16; + constexpr int span_id_len = 16; constexpr int trace_flags_len = 2; char trace_id[trace_id_len] = {0}; - char span_id[span_id__len] = {0}; + char span_id[span_id_len] = {0}; char trace_flags[trace_flags_len] = {0}; log_record->GetTraceId().ToLowerBase16(trace_id); @@ -120,7 +120,7 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export( << " event_id : " << event_id << "\n" << " event_name : " << log_record->GetEventName() << "\n" << " trace_id : " << std::string(trace_id, trace_id_len) << "\n" - << " span_id : " << std::string(span_id, span_id__len) << "\n" + << " span_id : " << std::string(span_id, span_id_len) << "\n" << " trace_flags : " << std::string(trace_flags, trace_flags_len) << "\n" << " scope : \n" << " name : " << log_record->GetInstrumentationScope().GetName() << "\n" @@ -155,7 +155,7 @@ bool OStreamLogRecordExporter::isShutdown() const noexcept void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -166,7 +166,7 @@ void OStreamLogRecordExporter::printAttributes( void OStreamLogRecordExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 08bfe340c7..32bb938e16 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -117,7 +117,7 @@ sdk::common::ExportResult OStreamMetricExporter::Export( void OStreamMetricExporter::printAttributes( const std::map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -135,7 +135,9 @@ void OStreamMetricExporter::printResources(const opentelemetry::sdk::resource::R // order is guaranteed. std::map attr_map; for (auto &kv : attributes) + { attr_map[kv.first] = std::move(kv.second); + } printAttributes(attr_map, "\n\t"); } } diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index d3f5093b40..1695e976f3 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -101,7 +101,7 @@ sdk::common::ExportResult OStreamSpanExporter::Export( << "\n duration : " << span->GetDuration().count() << "\n description : " << span->GetDescription() << "\n span kind : " << span->GetSpanKind() - << "\n status : " << statusMap[int(span->GetStatus())] + << "\n status : " << statusMap[static_cast(span->GetStatus())] << "\n attributes : "; printAttributes(span->GetAttributes()); sout_ << "\n events : "; @@ -138,7 +138,7 @@ bool OStreamSpanExporter::isShutdown() const noexcept void OStreamSpanExporter::printAttributes( const std::unordered_map &map, - const std::string prefix) + const std::string &prefix) { for (const auto &kv : map) { @@ -178,7 +178,7 @@ void OStreamSpanExporter::printLinks(const std::vector void OStreamSpanExporter::printResources(const opentelemetry::sdk::resource::Resource &resources) { - auto attributes = resources.GetAttributes(); + const auto &attributes = resources.GetAttributes(); if (attributes.size()) { printAttributes(attributes, "\n\t"); @@ -189,7 +189,7 @@ void OStreamSpanExporter::printInstrumentationScope( const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope) { sout_ << instrumentation_scope.GetName(); - auto version = instrumentation_scope.GetVersion(); + const auto &version = instrumentation_scope.GetVersion(); if (version.size()) { sout_ << "-" << version; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h index d9e4013fd5..561fdbf686 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_preferred_temporality.h @@ -18,6 +18,6 @@ enum class PreferredAggregationTemporality kLowMemory, }; -} +} // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index 9678b22476..7a0e98f40a 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -173,11 +173,11 @@ static std::size_t FormatPath(char *buff, { \ tm_obj_cache = GetLocalTime(); \ tm_obj_ptr = &tm_obj_cache; \ - VAR = tm_obj_ptr->EXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } \ else \ { \ - VAR = tm_obj_ptr->EXPRESS; \ + (VAR) = tm_obj_ptr->EXPRESS; \ } for (size_t i = 0; i < fmt.size() && ret < bufz && running; ++i) diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 8bada1e0e0..2e12fbdb37 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #ifdef GetMessage @@ -685,12 +686,14 @@ OtlpHttpClient::~OtlpHttpClient() // And then remove all session datas while (cleanupGCSessions()) + { ; + } } OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, std::shared_ptr http_client) - : is_shutdown_(false), options_(options), http_client_(http_client) + : is_shutdown_(false), options_(options), http_client_(std::move(http_client)) { http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); } @@ -831,7 +834,9 @@ bool OtlpHttpClient::Shutdown(std::chrono::microseconds timeout) noexcept ForceFlush(timeout); while (cleanupGCSessions()) + { ; + } return true; } diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index e75b17ddd7..6e55e0a3f5 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -17,11 +17,17 @@ proto::metrics::v1::AggregationTemporality OtlpMetricUtils::GetProtoAggregationT const opentelemetry::sdk::metrics::AggregationTemporality &aggregation_temporality) noexcept { if (aggregation_temporality == opentelemetry::sdk::metrics::AggregationTemporality::kCumulative) + { return proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE; + } else if (aggregation_temporality == opentelemetry::sdk::metrics::AggregationTemporality::kDelta) + { return proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA; + } else + { return proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_UNSPECIFIED; + } } metric_sdk::AggregationType OtlpMetricUtils::GetAggregationType( diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index e4f69f502b..360af6af46 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -158,34 +158,35 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resourceSpans"].begin(); - auto scope_span = *resource_span["scopeSpans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["traceId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); - ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); - if (user_agent_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); - } - - // let the otlp_http_client to continue - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_span = *check_json["resourceSpans"].begin(); + auto scope_span = *resource_span["scopeSpans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["traceId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + auto user_agent_header = mock_session->GetRequest()->headers_.find("User-Agent"); + ASSERT_TRUE(user_agent_header != mock_session->GetRequest()->headers_.end()); + if (user_agent_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ(GetOtlpDefaultUserAgent(), user_agent_header->second); + } + + // let the otlp_http_client to continue + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); @@ -343,25 +344,27 @@ class OtlpHttpExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); - EXPECT_EQ(received_trace_id, report_trace_id); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto received_trace_id = + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + EXPECT_EQ(received_trace_id, report_trace_id); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); child_span->End(); parent_span->End(); diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 5fbf95798f..e71085d1aa 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -151,46 +151,47 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resourceLogs"].begin(); - auto scope_logs = *resource_logs["scopeLogs"].begin(); - auto scope = scope_logs["scope"]; - auto log = *scope_logs["logRecords"].begin(); - auto received_trace_id = log["traceId"].get(); - auto received_span_id = log["spanId"].get(); - EXPECT_EQ(received_trace_id, report_trace_id); - EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log message", log["body"]["stringValue"].get()); - EXPECT_LE(15, log["attributes"].size()); - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - bool check_scope_attribute = false; - auto scope_attributes = scope["attributes"]; - for (auto &attribute : scope_attributes) - { - if (!attribute.is_object()) - { - continue; - } - if ("scope_key1" == attribute["key"]) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); - } - } - ASSERT_TRUE(check_scope_attribute); - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + auto resource_logs = *check_json["resourceLogs"].begin(); + auto scope_logs = *resource_logs["scopeLogs"].begin(); + auto scope = scope_logs["scope"]; + auto log = *scope_logs["logRecords"].begin(); + auto received_trace_id = log["traceId"].get(); + auto received_span_id = log["spanId"].get(); + EXPECT_EQ(received_trace_id, report_trace_id); + EXPECT_EQ(received_span_id, report_span_id); + EXPECT_EQ("Log message", log["body"]["stringValue"].get()); + EXPECT_LE(15, log["attributes"].size()); + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + bool check_scope_attribute = false; + auto scope_attributes = scope["attributes"]; + for (auto &attribute : scope_attributes) + { + if (!attribute.is_object()) + { + continue; + } + if ("scope_key1" == attribute["key"]) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute["value"]["stringValue"].get()); + } + } + ASSERT_TRUE(check_scope_attribute); + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", @@ -390,47 +391,49 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, report_span_id]( - std::shared_ptr callback) { - opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; - request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], - static_cast(mock_session->GetRequest()->body_.size())); - auto scope_log = request_body.resource_logs(0).scope_logs(0); - EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); - EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); - EXPECT_EQ(scope_log.scope().version(), "1.2.0"); - auto received_log = scope_log.log_records(0); - EXPECT_EQ(received_log.trace_id(), report_trace_id); - EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log message", received_log.body().string_value()); - EXPECT_LE(15, received_log.attributes_size()); - bool check_service_name = false; - for (auto &attribute : received_log.attributes()) - { - if ("service.name" == attribute.key()) - { - check_service_name = true; - EXPECT_EQ("unit_test_service", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_service_name); - - bool check_scope_attribute = false; - for (auto &attribute : scope_log.scope().attributes()) - { - if ("scope_key1" == attribute.key()) - { - check_scope_attribute = true; - EXPECT_EQ("scope_value", attribute.value().string_value()); - } - } - ASSERT_TRUE(check_scope_attribute); - - // let the otlp_http_client to continue - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session, report_trace_id, report_span_id]( + const std::shared_ptr &callback) { + opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; + request_body.ParseFromArray( + &mock_session->GetRequest()->body_[0], + static_cast(mock_session->GetRequest()->body_.size())); + auto scope_log = request_body.resource_logs(0).scope_logs(0); + EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0"); + EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library"); + EXPECT_EQ(scope_log.scope().version(), "1.2.0"); + const auto &received_log = scope_log.log_records(0); + EXPECT_EQ(received_log.trace_id(), report_trace_id); + EXPECT_EQ(received_log.span_id(), report_span_id); + EXPECT_EQ("Log message", received_log.body().string_value()); + EXPECT_LE(15, received_log.attributes_size()); + bool check_service_name = false; + for (auto &attribute : received_log.attributes()) + { + if ("service.name" == attribute.key()) + { + check_service_name = true; + EXPECT_EQ("unit_test_service", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_service_name); + + bool check_scope_attribute = false; + for (auto &attribute : scope_log.scope().attributes()) + { + if ("scope_key1" == attribute.key()) + { + check_scope_attribute = true; + EXPECT_EQ("scope_value", attribute.value().string_value()); + } + } + ASSERT_TRUE(check_scope_attribute); + + // let the otlp_http_client to continue + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); logger->EmitLogRecord( opentelemetry::logs::Severity::kInfo, "Log message", diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 1e5fe6469f..38da477cfd 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -154,36 +154,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["sum"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["sum"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20.0, data_points[1]["asDouble"].get()); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -237,7 +238,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -335,36 +337,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["gauge"]["dataPoints"]; - EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); - EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["gauge"]["dataPoints"]; + EXPECT_EQ(10.0, data_points[0]["asDouble"].get()); + EXPECT_EQ(20l, JsonToInteger(data_points[1]["asInt"])); + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -427,7 +430,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); @@ -530,71 +534,72 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session]( - std::shared_ptr callback) { - auto check_json = - nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - - auto resource_metrics = *check_json["resourceMetrics"].begin(); - auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); - auto scope = scope_metrics["scope"]; - EXPECT_EQ("library_name", scope["name"].get()); - EXPECT_EQ("1.5.0", scope["version"].get()); - - auto metric = *scope_metrics["metrics"].begin(); - EXPECT_EQ("metrics_library_name", metric["name"].get()); - EXPECT_EQ("metrics_description", metric["description"].get()); - EXPECT_EQ("metrics_unit", metric["unit"].get()); - - auto data_points = metric["histogram"]["dataPoints"]; - EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); - EXPECT_EQ(900.5, data_points[0]["sum"].get()); - EXPECT_EQ(1.8, data_points[0]["min"].get()); - EXPECT_EQ(19, data_points[0]["max"].get()); - EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); - if (4 == data_points[0]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); - if (3 == data_points[0]["explicitBounds"].size()) - { - EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); - EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); - EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); - } - - EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); - EXPECT_EQ(900.0, data_points[1]["sum"].get()); - EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); - if (4 == data_points[1]["bucketCounts"].size()) - { - EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); - EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); - EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); - EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); - } - EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); - if (3 == data_points[1]["explicitBounds"].size()) - { - EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); - EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); - EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); - } - - auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); - ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); - if (custom_header != mock_session->GetRequest()->headers_.end()) - { - EXPECT_EQ("Custom-Header-Value", custom_header->second); - } - - http_client::nosend::Response response; - response.Finish(*callback.get()); - }); + .WillOnce( + [&mock_session]( + const std::shared_ptr &callback) { + auto check_json = + nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); + + auto resource_metrics = *check_json["resourceMetrics"].begin(); + auto scope_metrics = *resource_metrics["scopeMetrics"].begin(); + auto scope = scope_metrics["scope"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + auto metric = *scope_metrics["metrics"].begin(); + EXPECT_EQ("metrics_library_name", metric["name"].get()); + EXPECT_EQ("metrics_description", metric["description"].get()); + EXPECT_EQ("metrics_unit", metric["unit"].get()); + + auto data_points = metric["histogram"]["dataPoints"]; + EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); + EXPECT_EQ(900.5, data_points[0]["sum"].get()); + EXPECT_EQ(1.8, data_points[0]["min"].get()); + EXPECT_EQ(19, data_points[0]["max"].get()); + EXPECT_EQ(4, data_points[0]["bucketCounts"].size()); + if (4 == data_points[0]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[0]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[0]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[0]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[0]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[0]["explicitBounds"].size()); + if (3 == data_points[0]["explicitBounds"].size()) + { + EXPECT_EQ(10.1, data_points[0]["explicitBounds"][0].get()); + EXPECT_EQ(20.2, data_points[0]["explicitBounds"][1].get()); + EXPECT_EQ(30.2, data_points[0]["explicitBounds"][2].get()); + } + + EXPECT_EQ(3, JsonToInteger(data_points[1]["count"])); + EXPECT_EQ(900.0, data_points[1]["sum"].get()); + EXPECT_EQ(4, data_points[1]["bucketCounts"].size()); + if (4 == data_points[1]["bucketCounts"].size()) + { + EXPECT_EQ(200, JsonToInteger(data_points[1]["bucketCounts"][0])); + EXPECT_EQ(300, JsonToInteger(data_points[1]["bucketCounts"][1])); + EXPECT_EQ(400, JsonToInteger(data_points[1]["bucketCounts"][2])); + EXPECT_EQ(500, JsonToInteger(data_points[1]["bucketCounts"][3])); + } + EXPECT_EQ(3, data_points[1]["explicitBounds"].size()); + if (3 == data_points[1]["explicitBounds"].size()) + { + EXPECT_EQ(10.0, data_points[1]["explicitBounds"][0].get()); + EXPECT_EQ(20.0, data_points[1]["explicitBounds"][1].get()); + EXPECT_EQ(30.0, data_points[1]["explicitBounds"][2].get()); + } + + auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); + ASSERT_TRUE(custom_header != mock_session->GetRequest()->headers_.end()); + if (custom_header != mock_session->GetRequest()->headers_.end()) + { + EXPECT_EQ("Custom-Header-Value", custom_header->second); + } + + http_client::nosend::Response response; + response.Finish(*callback.get()); + }); auto result = exporter->Export(data); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess); @@ -661,7 +666,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test EXPECT_CALL(*mock_session, SendRequest) .WillOnce([&mock_session]( - std::shared_ptr callback) { + const std::shared_ptr + &callback) { opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index b945cb28fe..2ad76dfd1d 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -200,7 +200,7 @@ TEST(OtlpMetricSerializationTest, Counter) EXPECT_EQ(sum.is_monotonic(), true); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = sum.data_points(i); + const auto &proto_number_point = sum.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 10.2 : 20.2); } @@ -230,7 +230,7 @@ TEST(OtlpMetricSerializationTest, Histogram) proto::metrics::v1::AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = histogram.data_points(i); + const auto &proto_number_point = histogram.data_points(i); EXPECT_EQ(proto_number_point.sum(), i == 0 ? 100.2 : 200.2); } @@ -244,7 +244,7 @@ TEST(OtlpMetricSerializationTest, ObservableGauge) otlp_exporter::OtlpMetricUtils::ConvertGaugeMetric(data, &gauge); for (size_t i = 0; i < 1; i++) { - auto proto_number_point = gauge.data_points(i); + const auto &proto_number_point = gauge.data_points(i); EXPECT_EQ(proto_number_point.as_double(), i == 0 ? 30.2 : 50.2); } diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 68d8586bcc..6460e14202 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -86,7 +86,7 @@ inline std::string Sanitize(std::string name, const T &valid) * [a-zA-Z_]([a-zA-Z0-9_])* * and multiple consecutive _ characters must be collapsed to a single _. */ -std::string SanitizeLabel(std::string label_key) +std::string SanitizeLabel(const std::string &label_key) { return Sanitize(label_key, [](int i, char c) { return (c >= 'a' && c <= 'z') || // diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index b876e7369c..c9b955edd4 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -22,7 +22,7 @@ namespace metrics class SanitizeNameTester { public: - static std::string sanitize(std::string name) + static std::string sanitize(const std::string &name) { return PrometheusExporterUtils::SanitizeNames(name); } diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h index 63702be09a..870e26460d 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h @@ -159,9 +159,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) { host_ = scheme + "://" + host + ":" + std::to_string(port) + "/"; diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h index 58dd154bb7..26900f4033 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h @@ -61,7 +61,7 @@ struct HttpCurlEasyResource other.headers_chunk = nullptr; } - HttpCurlEasyResource &operator=(HttpCurlEasyResource &&other) + HttpCurlEasyResource &operator=(HttpCurlEasyResource &&other) noexcept { using std::swap; swap(easy_handle, other.easy_handle); @@ -124,7 +124,8 @@ class HttpOperation double ulnow); #endif public: - void DispatchEvent(opentelemetry::ext::http::client::SessionState type, std::string reason = ""); + void DispatchEvent(opentelemetry::ext::http::client::SessionState type, + const std::string &reason = ""); /** * Create local CURL instance for url and body diff --git a/ext/src/http/client/curl/http_operation_curl.cc b/ext/src/http/client/curl/http_operation_curl.cc index 25f43fcb2f..3c69a52e01 100644 --- a/ext/src/http/client/curl/http_operation_curl.cc +++ b/ext/src/http/client/curl/http_operation_curl.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include "opentelemetry/ext/http/client/curl/http_operation_curl.h" @@ -223,7 +224,7 @@ int HttpOperation::OnProgressCallback(void *clientp, #endif void HttpOperation::DispatchEvent(opentelemetry::ext::http::client::SessionState type, - std::string reason) + const std::string &reason) { if (event_handle_ != nullptr) { @@ -256,7 +257,7 @@ HttpOperation::HttpOperation(opentelemetry::ext::http::client::Method method, last_curl_result_(CURLE_OK), event_handle_(event_handle), method_(method), - url_(url), + url_(std::move(url)), ssl_options_(ssl_options), // Local vars request_headers_(request_headers), @@ -436,7 +437,7 @@ void HttpOperation::Cleanup() # define HAVE_TLS_VERSION #endif -static long parse_min_ssl_version(std::string version) +static long parse_min_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.0") @@ -463,7 +464,7 @@ static long parse_min_ssl_version(std::string version) return 0; } -static long parse_max_ssl_version(std::string version) +static long parse_max_ssl_version(const std::string &version) { #ifdef HAVE_TLS_VERSION if (version == "1.0") diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 349626e219..8985780582 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -75,7 +75,7 @@ struct Uri uint16_t port; std::string path; - Uri(std::string uri) + Uri(const std::string &uri) { size_t host_end = uri.substr(7, std::string::npos).find(":"); size_t port_end = uri.substr(host_end + 1, std::string::npos).find("/");