From 85b78784a5516667afe11a1b238fdbf4ac7915b0 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 20 Sep 2022 20:43:08 +0200 Subject: [PATCH] Fix more build warnings (#1616) (#1620) --- .../opentelemetry/context/runtime_context.h | 2 +- api/include/opentelemetry/logs/noop.h | 10 +++++++ .../opentelemetry/metrics/async_instruments.h | 3 ++ api/include/opentelemetry/metrics/noop.h | 1 + .../opentelemetry/metrics/observer_result.h | 2 ++ .../opentelemetry/metrics/sync_instruments.h | 6 +++- .../opentelemetry/nostd/detail/invoke.h | 23 ++++++++------- api/include/opentelemetry/plugin/tracer.h | 6 ++++ .../opentelemetry/trace/default_span.h | 29 ++++++++++--------- api/include/opentelemetry/trace/noop.h | 4 +++ api/test/logs/logger_test.cc | 10 +++++++ .../memory/in_memory_span_exporter.h | 2 +- ext/test/http/curl_http_test.cc | 2 +- ext/test/http/url_parser_test.cc | 2 +- .../opentelemetry/sdk/logs/log_record.h | 2 +- sdk/include/opentelemetry/sdk/logs/logger.h | 13 +++++++++ .../metrics/aggregation/default_aggregation.h | 4 +-- .../sdk/metrics/observer_result.h | 2 ++ .../sdk/metrics/state/attributes_hashmap.h | 2 +- .../sdk/metrics/state/metric_collector.h | 2 ++ .../sdk/metrics/state/metric_storage.h | 5 +++- .../sdk/metrics/state/sync_metric_storage.h | 5 ++-- .../sdk/metrics/view/instrument_selector.h | 6 ++-- .../sdk/metrics/view/meter_selector.h | 14 ++++----- .../sdk/metrics/view/predicate_factory.h | 10 +++---- .../opentelemetry/sdk/metrics/view/view.h | 2 ++ .../opentelemetry/sdk/trace/recordable.h | 12 ++++++++ sdk/src/trace/samplers/trace_id_ratio.cc | 2 +- sdk/src/trace/span.cc | 10 +++++++ sdk/src/trace/span.h | 3 ++ sdk/test/logs/batch_log_processor_test.cc | 2 +- sdk/test/logs/logger_provider_sdk_test.cc | 8 ++--- sdk/test/logs/logger_sdk_test.cc | 8 ++--- sdk/test/metrics/async_metric_storage_test.cc | 2 ++ .../sync_metric_storage_counter_test.cc | 2 ++ .../sync_metric_storage_histogram_test.cc | 2 ++ sdk/test/trace/sampler_benchmark.cc | 4 +-- 37 files changed, 159 insertions(+), 65 deletions(-) diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h index 1e5a713e33..6d59d9cc44 100644 --- a/api/include/opentelemetry/context/runtime_context.h +++ b/api/include/opentelemetry/context/runtime_context.h @@ -18,7 +18,7 @@ class Token public: bool operator==(const Context &other) const noexcept { return context_ == other; } - ~Token(); + ~Token() noexcept; private: friend class RuntimeContextStorage; diff --git a/api/include/opentelemetry/logs/noop.h b/api/include/opentelemetry/logs/noop.h index a29c1c95fb..4663c86c18 100644 --- a/api/include/opentelemetry/logs/noop.h +++ b/api/include/opentelemetry/logs/noop.h @@ -49,6 +49,16 @@ class NoopLogger final : public Logger trace::TraceFlags /* trace_flags */, common::SystemTimestamp /* timestamp */) noexcept override {} + + void Log(Severity /* severity */, + nostd::string_view /* name */, + nostd::string_view /* body */, + const common::KeyValueIterable & /* attributes */, + trace::TraceId /* trace_id */, + trace::SpanId /* span_id */, + trace::TraceFlags /* trace_flags */, + common::SystemTimestamp /* timestamp */) noexcept override + {} }; /** diff --git a/api/include/opentelemetry/metrics/async_instruments.h b/api/include/opentelemetry/metrics/async_instruments.h index 568ba602a3..7d3720b1d8 100644 --- a/api/include/opentelemetry/metrics/async_instruments.h +++ b/api/include/opentelemetry/metrics/async_instruments.h @@ -15,6 +15,9 @@ using ObservableCallbackPtr = void (*)(ObserverResult, void *); class ObservableInstrument { public: + ObservableInstrument() = default; + virtual ~ObservableInstrument() = default; + /** * Sets up a function that will be called whenever a metric collection is initiated. */ diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 3d7bfd8269..289c2750ad 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -58,6 +58,7 @@ class NoopUpDownCounter : public UpDownCounter nostd::string_view /* description */, nostd::string_view /* unit */) noexcept {} + ~NoopUpDownCounter() = default; void Add(T /* value */) noexcept override {} void Add(T /* value */, const opentelemetry::context::Context & /* context */) noexcept override {} diff --git a/api/include/opentelemetry/metrics/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h index 82acaf9a0e..39cf3baf7e 100644 --- a/api/include/opentelemetry/metrics/observer_result.h +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -24,6 +24,8 @@ class ObserverResultT { public: + virtual ~ObserverResultT() = default; + virtual void Observe(T value) noexcept = 0; virtual void Observe(T value, const common::KeyValueIterable &attributes) noexcept = 0; diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index e8239743a1..f8d7c96672 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -16,7 +16,11 @@ namespace metrics { class SynchronousInstrument -{}; +{ +public: + SynchronousInstrument() = default; + virtual ~SynchronousInstrument() = default; +}; template class Counter : public SynchronousInstrument diff --git a/api/include/opentelemetry/nostd/detail/invoke.h b/api/include/opentelemetry/nostd/detail/invoke.h index e713d93dbe..629fb9c966 100644 --- a/api/include/opentelemetry/nostd/detail/invoke.h +++ b/api/include/opentelemetry/nostd/detail/invoke.h @@ -95,24 +95,25 @@ inline constexpr auto invoke_impl(R T::*f, Arg &&arg, Args &&... args) #endif } // namespace detail +/* clang-format off */ template inline constexpr auto invoke(F &&f, Args &&... args) - OPENTELEMETRY_RETURN(detail::invoke_impl(std::forward(f), std::forward(args)...)); + OPENTELEMETRY_RETURN(detail::invoke_impl(std::forward(f), std::forward(args)...)) namespace detail +/* clang-format on */ { -template -struct invoke_result -{}; + template + struct invoke_result + {}; -template -struct invoke_result(), std::declval()...))>, - F, - Args...> -{ - using type = decltype(nostd::invoke(std::declval(), std::declval()...)); -}; + template + struct invoke_result(), std::declval()...))>, + F, Args...> + { + using type = decltype(nostd::invoke(std::declval(), std::declval()...)); + }; } // namespace detail diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index 149f2a93b8..df8e542c0c 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -34,6 +34,12 @@ class Span final : public trace::Span span_->AddEvent(name, timestamp); } + void AddEvent(nostd::string_view name, + const common::KeyValueIterable &attributes) noexcept override + { + span_->AddEvent(name, attributes); + } + void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept override diff --git a/api/include/opentelemetry/trace/default_span.h b/api/include/opentelemetry/trace/default_span.h index fadd92386f..dd1e5475f2 100644 --- a/api/include/opentelemetry/trace/default_span.h +++ b/api/include/opentelemetry/trace/default_span.h @@ -22,33 +22,34 @@ class DefaultSpan : public Span // Returns an invalid span. static DefaultSpan GetInvalid() { return DefaultSpan(SpanContext::GetInvalid()); } - trace::SpanContext GetContext() const noexcept { return span_context_; } + trace::SpanContext GetContext() const noexcept override { return span_context_; } - bool IsRecording() const noexcept { return false; } + bool IsRecording() const noexcept override { return false; } void SetAttribute(nostd::string_view /* key */, - const common::AttributeValue & /* value */) noexcept + const common::AttributeValue & /* value */) noexcept override {} - void AddEvent(nostd::string_view /* name */) noexcept {} + void AddEvent(nostd::string_view /* name */) noexcept override {} - void AddEvent(nostd::string_view /* name */, common::SystemTimestamp /* timestamp */) noexcept {} + void AddEvent(nostd::string_view /* name */, + common::SystemTimestamp /* timestamp */) noexcept override + {} void AddEvent(nostd::string_view /* name */, - common::SystemTimestamp /* timestamp */, - const common::KeyValueIterable & /* attributes */) noexcept + const common::KeyValueIterable & /* attributes */) noexcept override {} - void AddEvent(nostd::string_view name, const common::KeyValueIterable &attributes) noexcept - { - this->AddEvent(name, std::chrono::system_clock::now(), attributes); - } + void AddEvent(nostd::string_view /* name */, + common::SystemTimestamp /* timestamp */, + const common::KeyValueIterable & /* attributes */) noexcept override + {} - void SetStatus(StatusCode /* status */, nostd::string_view /* description */) noexcept {} + void SetStatus(StatusCode /* status */, nostd::string_view /* description */) noexcept override {} - void UpdateName(nostd::string_view /* name */) noexcept {} + void UpdateName(nostd::string_view /* name */) noexcept override {} - void End(const EndSpanOptions & /* options */ = {}) noexcept {} + void End(const EndSpanOptions & /* options */) noexcept override {} nostd::string_view ToString() const noexcept { return "DefaultSpan"; } diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 59b3f66e1c..5532aacbe6 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -49,6 +49,10 @@ class NoopSpan final : public Span common::SystemTimestamp /*timestamp*/) noexcept override {} + void AddEvent(nostd::string_view /* name */, + const common::KeyValueIterable & /* attributes */) noexcept override + {} + void AddEvent(nostd::string_view /*name*/, common::SystemTimestamp /*timestamp*/, const common::KeyValueIterable & /*attributes*/) noexcept override diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 8609e7926a..0ce3a61037 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -125,6 +125,16 @@ class TestLogger : public Logger trace::TraceFlags /* trace_flags */, common::SystemTimestamp /* timestamp */) noexcept override {} + + void Log(Severity /* severity */, + nostd::string_view /* name */, + nostd::string_view /* body */, + const common::KeyValueIterable & /* attributes */, + trace::TraceId /* trace_id */, + trace::SpanId /* span_id */, + trace::TraceFlags /* trace_flags */, + common::SystemTimestamp /* timestamp */) noexcept override + {} }; // Define a basic LoggerProvider class that returns an instance of the logger class defined above diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h index 8d2d6d6a5d..27efae379b 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h @@ -86,7 +86,7 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte std::shared_ptr data_; bool is_shutdown_ = false; mutable opentelemetry::common::SpinLockMutex lock_; - const bool isShutdown() const noexcept + bool isShutdown() const noexcept { const std::lock_guard locked(lock_); return is_shutdown_; diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 9654460faf..5349cc0cb9 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -43,7 +43,7 @@ class CustomEventHandler : public http_client::EventHandler break; } } - virtual void OnConnecting(const http_client::SSLCertificate &) noexcept {} + virtual void OnConnecting(const http_client::SSLCertificate &) noexcept override {} virtual ~CustomEventHandler() = default; bool is_called_ = false; bool got_response_ = false; diff --git a/ext/test/http/url_parser_test.cc b/ext/test/http/url_parser_test.cc index 6356efd16b..e205ff6ef7 100644 --- a/ext/test/http/url_parser_test.cc +++ b/ext/test/http/url_parser_test.cc @@ -7,7 +7,7 @@ namespace http_common = opentelemetry::ext::http::common; -inline const char *const BoolToString(bool b) +inline const char *BoolToString(bool b) { return b ? "true" : "false"; } diff --git a/sdk/include/opentelemetry/sdk/logs/log_record.h b/sdk/include/opentelemetry/sdk/logs/log_record.h index 25ab44c334..8b7ac19570 100644 --- a/sdk/include/opentelemetry/sdk/logs/log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/log_record.h @@ -177,7 +177,7 @@ class LogRecord final : public Recordable * @param instrumentation_scope the instrumentation scope to set */ void SetInstrumentationScope(const opentelemetry::sdk::instrumentationscope::InstrumentationScope - &instrumentation_scope) noexcept + &instrumentation_scope) noexcept override { instrumentation_scope_ = &instrumentation_scope; } diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index 59177ef644..7e4429e0cf 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -58,6 +58,19 @@ class Logger final : public opentelemetry::logs::Logger opentelemetry::trace::TraceFlags trace_flags, opentelemetry::common::SystemTimestamp timestamp) noexcept override; + // Deprecated + void Log(opentelemetry::logs::Severity severity, + nostd::string_view /* name */, + nostd::string_view body, + const opentelemetry::common::KeyValueIterable &attributes, + opentelemetry::trace::TraceId trace_id, + opentelemetry::trace::SpanId span_id, + opentelemetry::trace::TraceFlags trace_flags, + opentelemetry::common::SystemTimestamp timestamp) noexcept override + { + Log(severity, body, attributes, trace_id, span_id, trace_flags, timestamp); + } + /** Returns the associated instrumentation scope */ const opentelemetry::sdk::instrumentationscope::InstrumentationScope &GetInstrumentationScope() const noexcept; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 98221d9b46..eb74b2d8dc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -56,7 +56,7 @@ class DefaultAggregation : std::move(std::unique_ptr(new DoubleLastValueAggregation())); break; default: - return std::move(std::unique_ptr(new DropAggregation())); + return std::unique_ptr(new DropAggregation()); }; } @@ -154,4 +154,4 @@ class DefaultAggregation } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/observer_result.h b/sdk/include/opentelemetry/sdk/metrics/observer_result.h index f371c152d4..a8d3561f2e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/observer_result.h +++ b/sdk/include/opentelemetry/sdk/metrics/observer_result.h @@ -23,6 +23,8 @@ class ObserverResultT final : public opentelemetry::metrics::ObserverResultT : attributes_processor_(attributes_processor) {} + virtual ~ObserverResultT() = default; + void Observe(T value) noexcept override { data_.insert({{}, value}); } void Observe(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override diff --git a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h index 50d40e0ae6..be86c96826 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h @@ -72,7 +72,7 @@ class AttributesHashMap return it->second.get(); } - hash_map_[attributes] = std::move(aggregation_callback()); + hash_map_[attributes] = aggregation_callback(); return hash_map_[attributes].get(); } diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index 8134edea8a..e466fa6a4f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -33,6 +33,8 @@ class MetricCollector : public MetricProducer, public CollectorHandle public: MetricCollector(MeterContext *context, std::unique_ptr metric_reader); + virtual ~MetricCollector() = default; + AggregationTemporality GetAggregationTemporality( InstrumentType instrument_type) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h index 7ce67391ab..7e57b43ac8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h @@ -54,6 +54,9 @@ class SyncWritableMetricStorage class AsyncWritableMetricStorage { public: + AsyncWritableMetricStorage() = default; + virtual ~AsyncWritableMetricStorage() = default; + /* Records a batch of measurements */ virtual void RecordLong( const std::unordered_map &measurements, @@ -81,7 +84,7 @@ class NoopMetricStorage : public MetricStorage class NoopWritableMetricStorage : public SyncWritableMetricStorage { public: - void RecordLong(long value, const opentelemetry::context::Context &context) noexcept = 0; + void RecordLong(long value, const opentelemetry::context::Context &context) noexcept override = 0; void RecordLong(long /* value */, const opentelemetry::common::KeyValueIterable & /* attributes */, diff --git a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h index fe3be8613b..a9b0604f05 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -41,8 +41,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage { create_default_aggregation_ = [&]() -> std::unique_ptr { - return std::move( - DefaultAggregation::CreateAggregation(aggregation_type_, instrument_descriptor_)); + return DefaultAggregation::CreateAggregation(aggregation_type_, instrument_descriptor_); }; } @@ -123,4 +122,4 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h index e79a292c0b..24c347ffa9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/instrument_selector.h @@ -16,12 +16,12 @@ class InstrumentSelector public: InstrumentSelector(opentelemetry::sdk::metrics::InstrumentType instrument_type, opentelemetry::nostd::string_view name) - : name_filter_{std::move(PredicateFactory::GetPredicate(name, PredicateType::kPattern))}, + : name_filter_{PredicateFactory::GetPredicate(name, PredicateType::kPattern)}, instrument_type_{instrument_type} {} // Returns name filter predicate. This shouldn't be deleted - const opentelemetry::sdk::metrics::Predicate *const GetNameFilter() { return name_filter_.get(); } + const opentelemetry::sdk::metrics::Predicate *GetNameFilter() const { return name_filter_.get(); } // Returns instrument filter. InstrumentType GetInstrumentType() { return instrument_type_; } @@ -33,4 +33,4 @@ class InstrumentSelector } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h index d0bc07ccb8..ff3fd6afc4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/meter_selector.h @@ -16,22 +16,22 @@ class MeterSelector MeterSelector(opentelemetry::nostd::string_view name, opentelemetry::nostd::string_view version, opentelemetry::nostd::string_view schema) - : name_filter_{std::move(PredicateFactory::GetPredicate(name, PredicateType::kExact))}, - version_filter_{std::move(PredicateFactory::GetPredicate(version, PredicateType::kExact))}, - schema_filter_{std::move(PredicateFactory::GetPredicate(schema, PredicateType::kExact))} + : name_filter_{PredicateFactory::GetPredicate(name, PredicateType::kExact)}, + version_filter_{PredicateFactory::GetPredicate(version, PredicateType::kExact)}, + schema_filter_{PredicateFactory::GetPredicate(schema, PredicateType::kExact)} {} // Returns name filter predicate. This shouldn't be deleted - const opentelemetry::sdk::metrics::Predicate *const GetNameFilter() { return name_filter_.get(); } + const opentelemetry::sdk::metrics::Predicate *GetNameFilter() const { return name_filter_.get(); } // Returns version filter predicate. This shouldn't be deleted - const opentelemetry::sdk::metrics::Predicate *const GetVersionFilter() + const opentelemetry::sdk::metrics::Predicate *GetVersionFilter() const { return version_filter_.get(); } // Returns schema filter predicate. This shouldn't be deleted - const opentelemetry::sdk::metrics::Predicate *const GetSchemaFilter() + const opentelemetry::sdk::metrics::Predicate *GetSchemaFilter() const { return schema_filter_.get(); } @@ -44,4 +44,4 @@ class MeterSelector } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h b/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h index 466fa76d5b..1240d7c819 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h @@ -26,20 +26,20 @@ class PredicateFactory if ((type == PredicateType::kPattern && pattern == "*") || (type == PredicateType::kExact && pattern == "")) { - return std::move(std::unique_ptr(new MatchEverythingPattern())); + return std::unique_ptr(new MatchEverythingPattern()); } if (type == PredicateType::kPattern) { - return std::move(std::unique_ptr(new PatternPredicate(pattern))); + return std::unique_ptr(new PatternPredicate(pattern)); } if (type == PredicateType::kExact) { - return std::move(std::unique_ptr(new ExactPredicate(pattern))); + return std::unique_ptr(new ExactPredicate(pattern)); } - return std::move(std::unique_ptr(new MatchNothingPattern())); + return std::unique_ptr(new MatchNothingPattern()); } }; } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index a7f8edb8fc..733e309bb7 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -37,6 +37,8 @@ class View attributes_processor_{std::move(attributes_processor)} {} + virtual ~View() = default; + virtual std::string GetName() const noexcept { return name_; } virtual std::string GetDescription() const noexcept { return description_; } diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index 04248944e9..721e33232d 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -86,6 +86,18 @@ class Recordable AddEvent(name, timestamp, opentelemetry::sdk::GetEmptyAttributes()); } + /** + * Add an event to a span. + * @param name the name of the event + * @param attributes the attributes associated with the event + */ + void AddEvent(nostd::string_view name, + const opentelemetry::common::KeyValueIterable &attributes) noexcept + { + AddEvent(name, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()), + attributes); + } + /** * Add a link to a span. * @param span_context the span context of the linked span diff --git a/sdk/src/trace/samplers/trace_id_ratio.cc b/sdk/src/trace/samplers/trace_id_ratio.cc index 7ca436efe8..dc5091a907 100644 --- a/sdk/src/trace/samplers/trace_id_ratio.cc +++ b/sdk/src/trace/samplers/trace_id_ratio.cc @@ -62,7 +62,7 @@ uint64_t CalculateThresholdFromBuffer(const trace_api::TraceId &trace_id) noexce uint64_t res = 0; std::memcpy(&res, &trace_id, 8); - double ratio = (double)res / UINT64_MAX; + double ratio = (double)res / (double)UINT64_MAX; return CalculateThreshold(ratio); } diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index d473e49ea3..138c966af3 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -122,6 +122,16 @@ void Span::AddEvent(nostd::string_view name, SystemTimestamp timestamp) noexcept recordable_->AddEvent(name, timestamp); } +void Span::AddEvent(nostd::string_view name, const common::KeyValueIterable &attributes) noexcept +{ + std::lock_guard lock_guard{mu_}; + if (recordable_ == nullptr) + { + return; + } + recordable_->AddEvent(name, attributes); +} + void Span::AddEvent(nostd::string_view name, SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index f507afbefb..75e31e9500 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -35,6 +35,9 @@ class Span final : public opentelemetry::trace::Span void AddEvent(nostd::string_view name, opentelemetry::common::SystemTimestamp timestamp) noexcept override; + void AddEvent(nostd::string_view name, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override; + void AddEvent(nostd::string_view name, opentelemetry::common::SystemTimestamp timestamp, const opentelemetry::common::KeyValueIterable &attributes) noexcept override; diff --git a/sdk/test/logs/batch_log_processor_test.cc b/sdk/test/logs/batch_log_processor_test.cc index a07cddc9a9..18e3ee531d 100644 --- a/sdk/test/logs/batch_log_processor_test.cc +++ b/sdk/test/logs/batch_log_processor_test.cc @@ -32,7 +32,7 @@ class MockLogExporter final : public LogExporter export_delay_(export_delay) {} - std::unique_ptr MakeRecordable() noexcept + std::unique_ptr MakeRecordable() noexcept override { return std::unique_ptr(new LogRecord()); } diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 3c401af667..1488798f07 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -81,14 +81,14 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) class DummyProcessor : public LogProcessor { - std::unique_ptr MakeRecordable() noexcept + std::unique_ptr MakeRecordable() noexcept override { return std::unique_ptr(new LogRecord); } - void OnReceive(std::unique_ptr && /* record */) noexcept {} - bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept { return true; } - bool Shutdown(std::chrono::microseconds /* timeout */) noexcept { return true; } + void OnReceive(std::unique_ptr && /* record */) noexcept override {} + bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept override { return true; } + bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override { return true; } }; TEST(LoggerProviderSDK, GetResource) diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index e805f1f161..36278349ba 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -40,13 +40,13 @@ class MockProcessor final : public LogProcessor : record_received_(record_received) {} - std::unique_ptr MakeRecordable() noexcept + std::unique_ptr MakeRecordable() noexcept override { return std::unique_ptr(new LogRecord); } // OnReceive stores the record it receives into the shared_ptr recordable passed into its // constructor - void OnReceive(std::unique_ptr &&record) noexcept + void OnReceive(std::unique_ptr &&record) noexcept override { // Cast the recordable received into a concrete LogRecord type auto copy = std::shared_ptr(static_cast(record.release())); @@ -56,8 +56,8 @@ class MockProcessor final : public LogProcessor record_received_->SetSeverity(copy->GetSeverity()); record_received_->SetBody(copy->GetBody()); } - bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept { return true; } - bool Shutdown(std::chrono::microseconds /* timeout */) noexcept { return true; } + bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept override { return true; } + bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override { return true; } }; TEST(LoggerSDK, LogToAProcessor) diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index ce93f233cf..02d2734ecf 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -31,6 +31,8 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} + virtual ~MockCollectorHandle() = default; + AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override { diff --git a/sdk/test/metrics/sync_metric_storage_counter_test.cc b/sdk/test/metrics/sync_metric_storage_counter_test.cc index 0eef7abf9c..a2853f5181 100644 --- a/sdk/test/metrics/sync_metric_storage_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_counter_test.cc @@ -23,6 +23,8 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} + virtual ~MockCollectorHandle() = default; + AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override { diff --git a/sdk/test/metrics/sync_metric_storage_histogram_test.cc b/sdk/test/metrics/sync_metric_storage_histogram_test.cc index 09d7b5804a..0e0713d60a 100644 --- a/sdk/test/metrics/sync_metric_storage_histogram_test.cc +++ b/sdk/test/metrics/sync_metric_storage_histogram_test.cc @@ -23,6 +23,8 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} + virtual ~MockCollectorHandle() = default; + AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override { diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index 39bebe03fd..a5f5121e38 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -142,14 +142,14 @@ void BenchmarkSpanCreation(std::shared_ptr /* TODO: fix issue #1612 sam // Test to measure performance for span creation void BM_SpanCreation(benchmark::State &state) { - BenchmarkSpanCreation(std::move(std::make_shared()), state); + BenchmarkSpanCreation(std::make_shared(), state); } BENCHMARK(BM_SpanCreation); // Test to measure performance overhead for no-op span creation void BM_NoopSpanCreation(benchmark::State &state) { - BenchmarkSpanCreation(std::move(std::make_shared()), state); + BenchmarkSpanCreation(std::make_shared(), state); } BENCHMARK(BM_NoopSpanCreation);