diff --git a/api/include/opentelemetry/common/kv_properties.h b/api/include/opentelemetry/common/kv_properties.h index 7ac747a733..96442021b5 100644 --- a/api/include/opentelemetry/common/kv_properties.h +++ b/api/include/opentelemetry/common/kv_properties.h @@ -270,4 +270,4 @@ class KeyValueProperties size_t Size() const noexcept { return num_entries_; } }; } // namespace common -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/context/propagation/composite_propagator.h b/api/include/opentelemetry/context/propagation/composite_propagator.h index d7a6cbda17..dedcac85ca 100644 --- a/api/include/opentelemetry/context/propagation/composite_propagator.h +++ b/api/include/opentelemetry/context/propagation/composite_propagator.h @@ -89,4 +89,4 @@ class CompositePropagator : public TextMapPropagator }; } // namespace propagation } // namespace context -OPENTELEMETRY_END_NAMESPACE; +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 289c2750ad..ce2d8e0cfd 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -58,7 +58,7 @@ class NoopUpDownCounter : public UpDownCounter nostd::string_view /* description */, nostd::string_view /* unit */) noexcept {} - ~NoopUpDownCounter() = default; + ~NoopUpDownCounter() override = default; void Add(T /* value */) noexcept override {} void Add(T /* value */, const opentelemetry::context::Context & /* context */) noexcept override {} diff --git a/api/include/opentelemetry/std/utility.h b/api/include/opentelemetry/std/utility.h index 7a8233f67d..01cdc18331 100644 --- a/api/include/opentelemetry/std/utility.h +++ b/api/include/opentelemetry/std/utility.h @@ -54,7 +54,7 @@ auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size()) } template -std::size_t size(T (&array)[N]) noexcept +std::size_t size(T (&/* array */)[N]) noexcept { return N; } diff --git a/api/include/opentelemetry/std/variant.h b/api/include/opentelemetry/std/variant.h index cb696ab397..30d38d9c63 100644 --- a/api/include/opentelemetry/std/variant.h +++ b/api/include/opentelemetry/std/variant.h @@ -146,58 +146,58 @@ template constexpr std::variant_alternative_t> &get(std::variant &v) { return std::get(v); -}; +} template constexpr std::variant_alternative_t> &&get(std::variant &&v) { return std::get(std::forward(v)); -}; +} template constexpr const std::variant_alternative_t> &get( const std::variant &v) { return std::get(v); -}; +} template constexpr const std::variant_alternative_t> &&get( const std::variant &&v) { return std::get(std::forward(v)); -}; +} template constexpr T &get(std::variant &v) { return std::get(v); -}; +} template constexpr T &&get(std::variant &&v) { return std::get(std::forward(v)); -}; +} template constexpr const T &get(const std::variant &v) { return std::get(v); -}; +} template constexpr const T &&get(const std::variant &&v) { return std::get(std::forward(v)); -}; +} template constexpr auto visit(_Callable &&_Obj, _Variants &&... _Args) { return std::visit<_Callable, _Variants...>(static_cast<_Callable &&>(_Obj), static_cast<_Variants &&>(_Args)...); -}; +} #endif diff --git a/api/include/opentelemetry/trace/context.h b/api/include/opentelemetry/trace/context.h index 963c187177..0a57e725c1 100644 --- a/api/include/opentelemetry/trace/context.h +++ b/api/include/opentelemetry/trace/context.h @@ -30,4 +30,4 @@ inline context::Context SetSpan(opentelemetry::context::Context &context, } } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/trace/span_metadata.h b/api/include/opentelemetry/trace/span_metadata.h index 977329a151..f27239c739 100644 --- a/api/include/opentelemetry/trace/span_metadata.h +++ b/api/include/opentelemetry/trace/span_metadata.h @@ -40,4 +40,4 @@ struct EndSpanOptions }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/trace/span_startoptions.h b/api/include/opentelemetry/trace/span_startoptions.h index 688b768bd0..9265574a57 100644 --- a/api/include/opentelemetry/trace/span_startoptions.h +++ b/api/include/opentelemetry/trace/span_startoptions.h @@ -42,4 +42,4 @@ struct StartSpanOptions }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/api/test/metrics/noop_sync_instrument_test.cc b/api/test/metrics/noop_sync_instrument_test.cc index 9d7c1f2fe6..05e6006854 100644 --- a/api/test/metrics/noop_sync_instrument_test.cc +++ b/api/test/metrics/noop_sync_instrument_test.cc @@ -47,4 +47,4 @@ TEST(UpDownCountr, Record) counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); } -#endif \ No newline at end of file +#endif diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index 5fd32524d2..3a323a0545 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -32,7 +32,7 @@ std::map get_random_attr() class MeasurementFetcher { public: - static void Fetcher(opentelemetry::metrics::ObserverResult observer_result, void *state) + static void Fetcher(opentelemetry::metrics::ObserverResult observer_result, void * /* state */) { std::map labels = get_random_attr(); auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; diff --git a/examples/http/server.cc b/examples/http/server.cc index b451499d58..12309cdb26 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -29,8 +29,9 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback std::string span_name = request.uri; // extract context from http header - const HttpTextMapCarrier> carrier( - (std::map &)request.headers); + std::map &request_headers = + const_cast &>(request.headers); + const HttpTextMapCarrier> carrier(request_headers); auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); auto current_ctx = context::RuntimeContext::GetCurrent(); auto new_context = prop->Extract(carrier, current_ctx); diff --git a/examples/http/server.h b/examples/http/server.h index 2b94bf3a68..1f73744d65 100644 --- a/examples/http/server.h +++ b/examples/http/server.h @@ -50,4 +50,4 @@ class HttpServer : public HTTP_SERVER_NS::HttpRequestCallback ~HttpServer() { Stop(); } }; -} // namespace \ No newline at end of file +} // namespace diff --git a/examples/plugin/plugin/factory_impl.cc b/examples/plugin/plugin/factory_impl.cc index b3bafe7053..b262facfb8 100644 --- a/examples/plugin/plugin/factory_impl.cc +++ b/examples/plugin/plugin/factory_impl.cc @@ -25,8 +25,8 @@ class FactoryImpl final : public plugin::Factory::FactoryImpl public: // opentelemetry::plugin::Factory::FactoryImpl nostd::unique_ptr MakeTracerHandle( - nostd::string_view tracer_config, - nostd::unique_ptr &error_message) const noexcept override + nostd::string_view /* tracer_config */, + nostd::unique_ptr & /* error_message */) const noexcept override { std::shared_ptr tracer{new (std::nothrow) Tracer{""}}; if (tracer == nullptr) @@ -46,4 +46,4 @@ static nostd::unique_ptr MakeFactoryImpl( return nostd::unique_ptr{new (std::nothrow) FactoryImpl{}}; } -OPENTELEMETRY_DEFINE_PLUGIN_HOOK(MakeFactoryImpl); +OPENTELEMETRY_DEFINE_PLUGIN_HOOK(MakeFactoryImpl) diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 517575c947..1c1b8678ca 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -27,7 +27,7 @@ class Span final : public trace::Span std::cout << "StartSpan: " << name << "\n"; } - ~Span() { std::cout << "~Span\n"; } + ~Span() override { std::cout << "~Span\n"; } // opentelemetry::trace::Span void SetAttribute(nostd::string_view /*name*/, diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc index c07f2f0100..9e1dac1162 100644 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ b/exporters/jaeger/src/jaeger_exporter.cc @@ -93,7 +93,7 @@ void JaegerExporter::InitializeEndpoint() assert(false); } -bool JaegerExporter::Shutdown(std::chrono::microseconds timeout) noexcept +bool JaegerExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { const std::lock_guard locked(lock_); is_shutdown_ = true; diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index b5f88780b8..d147d96553 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -191,7 +191,7 @@ void JaegerRecordable::SetInstrumentationScope( } void JaegerRecordable::AddLink(const trace::SpanContext &span_context, - const common::KeyValueIterable &attributes) noexcept + const common::KeyValueIterable & /* attributes */) noexcept { // Note: "The Link’s attributes cannot be represented in Jaeger explicitly." // -- https://opentelemetry.io/docs/reference/specification/trace/sdk_exporters/jaeger/#links diff --git a/exporters/jaeger/src/udp_transport.h b/exporters/jaeger/src/udp_transport.h index 0997a27c63..3e07992f47 100644 --- a/exporters/jaeger/src/udp_transport.h +++ b/exporters/jaeger/src/udp_transport.h @@ -35,7 +35,7 @@ class UDPTransport : public Transport static constexpr auto kUDPPacketMaxLength = 65000; UDPTransport(const std::string &addr, uint16_t port); - virtual ~UDPTransport(); + ~UDPTransport() override; int EmitBatch(const thrift::Batch &batch) override; diff --git a/exporters/memory/src/in_memory_span_exporter_factory.cc b/exporters/memory/src/in_memory_span_exporter_factory.cc index 1b858fd9c7..ff5bab9253 100644 --- a/exporters/memory/src/in_memory_span_exporter_factory.cc +++ b/exporters/memory/src/in_memory_span_exporter_factory.cc @@ -16,7 +16,7 @@ std::unique_ptr InMemorySpanExporterFac std::shared_ptr &data) { return Create(data, MAX_BUFFER_SIZE); -}; +} std::unique_ptr InMemorySpanExporterFactory::Create( std::shared_ptr &data, diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index 6712e6a9da..1e51815b23 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -78,4 +78,4 @@ inline void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &v } // namespace ostream_common } // namespace exporter -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/span_exporter_factory.cc b/exporters/ostream/src/span_exporter_factory.cc index f21a5271e3..5b3061ac3c 100644 --- a/exporters/ostream/src/span_exporter_factory.cc +++ b/exporters/ostream/src/span_exporter_factory.cc @@ -15,7 +15,7 @@ namespace trace std::unique_ptr OStreamSpanExporterFactory::Create() { return Create(std::cout); -}; +} std::unique_ptr OStreamSpanExporterFactory::Create(std::ostream &sout) { diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 643a0cd3d5..3ef0a179c3 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -84,4 +84,4 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::MetricExporte } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h index 1459fe8596..3d677c1a08 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h @@ -27,4 +27,4 @@ struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions } // namespace otlp } // namespace exporter -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/protobuf_include_suffix.h b/exporters/otlp/include/opentelemetry/exporters/otlp/protobuf_include_suffix.h index 26e7a2913e..547eb3f335 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/protobuf_include_suffix.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/protobuf_include_suffix.h @@ -13,4 +13,4 @@ #if defined(_MSC_VER) # pragma warning(pop) -#endif \ No newline at end of file +#endif diff --git a/exporters/otlp/src/otlp_populate_attribute_utils.cc b/exporters/otlp/src/otlp_populate_attribute_utils.cc index e19b6210b4..6dff7c4d01 100644 --- a/exporters/otlp/src/otlp_populate_attribute_utils.cc +++ b/exporters/otlp/src/otlp_populate_attribute_utils.cc @@ -176,7 +176,7 @@ void OtlpPopulateAttributeUtils::PopulateAttribute( } else if (nostd::holds_alternative>(value)) { - for (const auto &val : nostd::get>(value)) + for (const auto val : nostd::get>(value)) { attribute->mutable_value()->mutable_array_value()->add_values()->set_bool_value(val); } @@ -242,4 +242,4 @@ void OtlpPopulateAttributeUtils::PopulateAttribute( } // namespace otlp } // namespace exporter -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index 78ca7c99ce..e0b181a452 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -77,7 +77,7 @@ proto::common::v1::InstrumentationScope OtlpRecordable::GetProtoInstrumentationS void OtlpRecordable::SetResource(const sdk::resource::Resource &resource) noexcept { resource_ = &resource; -}; +} void OtlpRecordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept diff --git a/exporters/prometheus/src/exporter.cc b/exporters/prometheus/src/exporter.cc index 9d36cf00c9..f66dcb7d4f 100644 --- a/exporters/prometheus/src/exporter.cc +++ b/exporters/prometheus/src/exporter.cc @@ -34,7 +34,7 @@ PrometheusExporter::PrometheusExporter() : is_shutdown_(false) } sdk::metrics::AggregationTemporality PrometheusExporter::GetAggregationTemporality( - sdk::metrics::InstrumentType instrument_type) const noexcept + sdk::metrics::InstrumentType /* instrument_type */) const noexcept { // Prometheus exporter only support Cumulative return sdk::metrics::AggregationTemporality::kCumulative; @@ -69,7 +69,7 @@ sdk::common::ExportResult PrometheusExporter::Export( return sdk::common::ExportResult::kSuccess; } -bool PrometheusExporter::ForceFlush(std::chrono::microseconds timeout) noexcept +bool PrometheusExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { return true; } @@ -81,7 +81,7 @@ bool PrometheusExporter::ForceFlush(std::chrono::microseconds timeout) noexcept * collection to to client an HTTP request being sent, * so we flush the data. */ -bool PrometheusExporter::Shutdown(std::chrono::microseconds timeout) noexcept +bool PrometheusExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { is_shutdown_ = true; return true; diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 93b27f38ee..f1a27b35c5 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -230,7 +230,7 @@ void PrometheusExporterUtils::SetMetricBasic(prometheus_client::ClientMetric &me metric.label[i++].value = AttributeValueToString(label.second); } } -}; +} std::string PrometheusExporterUtils::AttributeValueToString( const opentelemetry::sdk::common::OwnedAttributeValue &value) diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 1065c01619..6985fcb1ba 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -188,8 +188,8 @@ void Recordable::AddEvent(nostd::string_view name, span_["annotations"].push_back(annotation); } -void Recordable::AddLink(const trace_api::SpanContext &span_context, - const common::KeyValueIterable &attributes) noexcept +void Recordable::AddLink(const trace_api::SpanContext & /* span_context */, + const common::KeyValueIterable & /* attributes */) noexcept { // TODO: Currently not supported by specs: // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index 240144599f..802ecccffc 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -110,7 +110,7 @@ void ZipkinExporter::InitializeLocalEndpoint() local_end_point_["port"] = url_parser_.port_; } -bool ZipkinExporter::Shutdown(std::chrono::microseconds timeout) noexcept +bool ZipkinExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { const std::lock_guard locked(lock_); is_shutdown_ = true; 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 888b7e676f..43992bbdf5 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 @@ -263,7 +263,7 @@ class HttpClientSync : public opentelemetry::ext::http::client::HttpClientSync return opentelemetry::ext::http::client::Result(std::move(response), session_state); } - ~HttpClientSync() {} + ~HttpClientSync() override {} private: nostd::shared_ptr curl_global_initializer_; @@ -274,7 +274,7 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient public: // The call (curl_global_init) is not thread safe. Ensure this is called only once. HttpClient(); - ~HttpClient(); + ~HttpClient() override; std::shared_ptr CreateSession( nostd::string_view url) noexcept override; diff --git a/ext/include/opentelemetry/ext/http/client/nosend/http_client_nosend.h b/ext/include/opentelemetry/ext/http/client/nosend/http_client_nosend.h index f32a075879..4325885a96 100644 --- a/ext/include/opentelemetry/ext/http/client/nosend/http_client_nosend.h +++ b/ext/include/opentelemetry/ext/http/client/nosend/http_client_nosend.h @@ -15,7 +15,6 @@ # include # include "gmock/gmock.h" -using namespace testing; OPENTELEMETRY_BEGIN_NAMESPACE namespace ext { diff --git a/ext/include/opentelemetry/ext/http/server/http_server.h b/ext/include/opentelemetry/ext/http/server/http_server.h index 3cbb057ab4..5ea7debc43 100644 --- a/ext/include/opentelemetry/ext/http/server/http_server.h +++ b/ext/include/opentelemetry/ext/http/server/http_server.h @@ -54,6 +54,7 @@ class HttpRequestCallback public: HttpRequestCallback() {} + virtual ~HttpRequestCallback() = default; HttpRequestCallback &operator=(HttpRequestCallback other) { @@ -175,7 +176,7 @@ class HttpServer : private SocketTools::Reactor::SocketCallback addListeningPort(port); } - ~HttpServer() + ~HttpServer() override { for (auto &sock : m_listeningSockets) { diff --git a/ext/include/opentelemetry/ext/http/server/socket_tools.h b/ext/include/opentelemetry/ext/http/server/socket_tools.h index 7b234342fd..bb6302bac8 100644 --- a/ext/include/opentelemetry/ext/http/server/socket_tools.h +++ b/ext/include/opentelemetry/ext/http/server/socket_tools.h @@ -133,7 +133,7 @@ struct Thread virtual ~Thread() noexcept {} }; -}; // namespace common +} // namespace common namespace SocketTools { @@ -447,6 +447,8 @@ struct Reactor : protected common::Thread class SocketCallback { public: + SocketCallback() = default; + virtual ~SocketCallback() = default; virtual void onSocketReadable(Socket sock) = 0; virtual void onSocketWritable(Socket sock) = 0; virtual void onSocketAcceptable(Socket sock) = 0; @@ -502,7 +504,7 @@ struct Reactor : protected common::Thread #endif } - ~Reactor() + ~Reactor() override { #ifdef __linux__ ::close(m_epollFd); diff --git a/ext/include/opentelemetry/ext/zpages/tracez_processor.h b/ext/include/opentelemetry/ext/zpages/tracez_processor.h index 5e032c4568..081dd41117 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_processor.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_processor.h @@ -64,8 +64,8 @@ class TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor * @param timeout an optional timeout. Currently, timeout does nothing. * @return return the status of the operation. */ - bool ForceFlush( - std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override + bool ForceFlush(std::chrono::microseconds timeout OPENTELEMETRY_MAYBE_UNUSED = + std::chrono::microseconds::max()) noexcept override { return true; } @@ -78,8 +78,8 @@ class TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor * timeout is applied. Currently, timeout does nothing. * @return return the status of the operation. */ - bool Shutdown( - std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override + bool Shutdown(std::chrono::microseconds timeout OPENTELEMETRY_MAYBE_UNUSED = + std::chrono::microseconds::max()) noexcept override { return true; } diff --git a/ext/src/zpages/tracez_processor.cc b/ext/src/zpages/tracez_processor.cc index 1e9115eb98..e7d68350d7 100644 --- a/ext/src/zpages/tracez_processor.cc +++ b/ext/src/zpages/tracez_processor.cc @@ -11,7 +11,8 @@ namespace zpages namespace trace_sdk = opentelemetry::sdk::trace; void TracezSpanProcessor::OnStart(trace_sdk::Recordable &span, - const opentelemetry::trace::SpanContext &parent_context) noexcept + const opentelemetry::trace::SpanContext & + /* parent_context */) noexcept { shared_data_->OnStart(static_cast(&span)); } diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 5349cc0cb9..c0ee32d713 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -44,9 +44,9 @@ class CustomEventHandler : public http_client::EventHandler } } virtual void OnConnecting(const http_client::SSLCertificate &) noexcept override {} - virtual ~CustomEventHandler() = default; - bool is_called_ = false; - bool got_response_ = false; + ~CustomEventHandler() override = default; + bool is_called_ = false; + bool got_response_ = false; }; class GetEventHandler : public CustomEventHandler diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index f96385acda..6cc3640651 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -14,6 +14,7 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; +using namespace testing; //////////////////////////////////// TEST HELPER FUNCTIONS ////////////////////////////// diff --git a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h index 573f57eb1b..c6f2c93ccc 100644 --- a/sdk/include/opentelemetry/sdk/common/attributemap_hash.h +++ b/sdk/include/opentelemetry/sdk/common/attributemap_hash.h @@ -59,4 +59,4 @@ inline size_t GetHashForAttributeMap(const OrderedAttributeMap &attribute_map) } // namespace common } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h index e70b511a10..e942564e28 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h @@ -64,7 +64,7 @@ class BatchLogProcessor : public LogProcessor * @param record the log record */ - void OnReceive(std::unique_ptr &&record) noexcept override; + void OnEmit(std::unique_ptr &&record) noexcept override; /** * Export all log records that have not been exported yet. diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_processor.h b/sdk/include/opentelemetry/sdk/logs/multi_log_processor.h index c1bda24a0b..227e2e020f 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_processor.h @@ -36,10 +36,10 @@ class MultiLogProcessor : public LogProcessor std::unique_ptr MakeRecordable() noexcept override; /** - * OnReceive is called by the SDK once a log record has been successfully created. + * OnEmit is called by the SDK once a log record has been successfully created. * @param record the log record */ - void OnReceive(std::unique_ptr &&record) noexcept override; + void OnEmit(std::unique_ptr &&record) noexcept override; /** * Exports all log records that have not yet been exported to the configured Exporter. diff --git a/sdk/include/opentelemetry/sdk/logs/processor.h b/sdk/include/opentelemetry/sdk/logs/processor.h index 36da036f31..0fdc8a422f 100644 --- a/sdk/include/opentelemetry/sdk/logs/processor.h +++ b/sdk/include/opentelemetry/sdk/logs/processor.h @@ -32,10 +32,10 @@ class LogProcessor virtual std::unique_ptr MakeRecordable() noexcept = 0; /** - * OnReceive is called by the SDK once a log record has been successfully created. + * OnEmit is called by the SDK once a log record has been successfully created. * @param record the log record */ - virtual void OnReceive(std::unique_ptr &&record) noexcept = 0; + virtual void OnEmit(std::unique_ptr &&record) noexcept = 0; /** * Exports all log records that have not yet been exported to the configured Exporter. diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h b/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h index 45f4683973..8364cedd4c 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h @@ -33,7 +33,7 @@ class SimpleLogProcessor : public LogProcessor std::unique_ptr MakeRecordable() noexcept override; - void OnReceive(std::unique_ptr &&record) noexcept override; + void OnEmit(std::unique_ptr &&record) noexcept override; bool ForceFlush( std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h index d2a07f91d2..96e5b2fa37 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h @@ -27,4 +27,4 @@ class HistogramAggregationConfig : public AggregationConfig } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif // ENABLE_METRICS_PREVIEW \ No newline at end of file +#endif // ENABLE_METRICS_PREVIEW diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index b32f68fa1f..13a059962c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -42,4 +42,4 @@ class ObservableInstrument : public opentelemetry::metrics::ObservableInstrument } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h new file mode 100644 index 0000000000..49ae1ed56c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/data/exemplar_data.h @@ -0,0 +1,84 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/context/context.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/data/metric_data.h" +# include "opentelemetry/sdk/metrics/export/metric_producer.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +using MetricAttributes = opentelemetry::sdk::common::OrderedAttributeMap; +/** + * A sample input measurement. + * + * Exemplars also hold information about the environment when the measurement was recorded, for + * example the span and trace ID of the active span when the exemplar was recorded. + */ +class ExemplarData +{ +public: + static ExemplarData Create(std::shared_ptr context, + const opentelemetry::common::SystemTimestamp ×tamp, + const PointDataAttributes &point_data_attr) + { + return ExemplarData(context, timestamp, point_data_attr); + } + + /** + * The set of key/value pairs that were filtered out by the aggregator, but recorded alongside + * the original measurement. Only key/value pairs that were filtered out by the aggregator + * should be included + */ + MetricAttributes GetFilteredAttributes() { return MetricAttributes{}; } + + /** Returns the timestamp in nanos when measurement was collected. */ + opentelemetry::common::SystemTimestamp GetEpochNanos() { return timestamp_; } + + /** + * Returns the SpanContext associated with this exemplar. If the exemplar was not recorded + * inside a sampled trace, the Context will be invalid. + */ + const trace::SpanContext &GetSpanContext() const noexcept { return context_; } + + static PointType CreateSumPointData(ValueType value) + { + SumPointData sum_point_data{}; + sum_point_data.value_ = value; + return sum_point_data; + } + + static PointType CreateLastValuePointData(ValueType value) + { + LastValuePointData last_value_point_data{}; + last_value_point_data.value_ = value; + last_value_point_data.is_lastvalue_valid_ = true; + last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; + return last_value_point_data; + } + + static PointType CreateDropPointData() { return DropPointData{}; } + +private: + ExemplarData(std::shared_ptr context, + opentelemetry::common::SystemTimestamp timestamp, + const PointDataAttributes &point_data_attr) + : context_(*context.get()), timestamp_(timestamp), point_data_attr_(point_data_attr) + {} + + trace::SpanContext context_; + opentelemetry::common::SystemTimestamp timestamp_; + PointDataAttributes point_data_attr_; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h index 3383f8d618..6b209f16d3 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/metric_data.h @@ -40,4 +40,4 @@ class MetricData } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h index c21b4cc84a..366488b2b6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h @@ -14,12 +14,6 @@ namespace metrics class AlwaysSampleFilter final : public ExemplarFilter { public: - static nostd::shared_ptr GetAlwaysSampleFilter() - { - static nostd::shared_ptr alwaysSampleFilter{new AlwaysSampleFilter{}}; - return alwaysSampleFilter; - } - bool ShouldSampleMeasurement( long /* value */, const MetricAttributes & /* attributes */, @@ -36,7 +30,6 @@ class AlwaysSampleFilter final : public ExemplarFilter return true; } -private: explicit AlwaysSampleFilter() = default; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/data.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/data.h deleted file mode 100644 index 14eac62499..0000000000 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/data.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once -#ifndef ENABLE_METRICS_PREVIEW -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/context/context.h" -# include "opentelemetry/sdk/common/attribute_utils.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace metrics -{ -using MetricAttributes = opentelemetry::sdk::common::OrderedAttributeMap; -/** - * A sample input measurement. - * - * Exemplars also hold information about the environment when the measurement was recorded, for - * example the span and trace ID of the active span when the exemplar was recorded. - */ -class ExemplarData -{ -public: - /** - * The set of key/value pairs that were filtered out by the aggregator, but recorded alongside the - * original measurement. Only key/value pairs that were filtered out by the aggregator should be - * included - */ - MetricAttributes GetFilteredAttributes(); - - /** Returns the timestamp in nanos when measurement was collected. */ - opentelemetry::common::SystemTimestamp GetEpochNanos(); - - /** - * Returns the SpanContext associated with this exemplar. If the exemplar was not recorded - * inside a sampled trace, the Context will be invalid. - */ - opentelemetry::context::Context GetSpanContext(); -}; - -} // namespace metrics -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h index 4b512e1317..87e27b81c2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h @@ -31,6 +31,10 @@ class ExemplarFilter const opentelemetry::context::Context &context) noexcept = 0; virtual ~ExemplarFilter() = default; + + static std::shared_ptr GetNeverSampleFilter() noexcept; + static std::shared_ptr GetAlwaysSampleFilter() noexcept; + static std::shared_ptr GetWithTraceSampleFilter() noexcept; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h new file mode 100644 index 0000000000..2db5532883 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h @@ -0,0 +1,65 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include "opentelemetry/context/context.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class FilteredExemplarReservoir final : public ExemplarReservoir +{ + +public: + FilteredExemplarReservoir(std::shared_ptr filter, + std::shared_ptr reservoir) + : filter_(filter), reservoir_(reservoir) + {} + + void OfferMeasurement(long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context, + const opentelemetry::common::SystemTimestamp ×tamp) noexcept override + { + if (filter_->ShouldSampleMeasurement(value, attributes, context)) + { + reservoir_->OfferMeasurement(value, attributes, context, timestamp); + } + } + + void OfferMeasurement(double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context, + const opentelemetry::common::SystemTimestamp ×tamp) noexcept override + { + if (filter_->ShouldSampleMeasurement(value, attributes, context)) + { + reservoir_->OfferMeasurement(value, attributes, context, timestamp); + } + } + + std::vector> CollectAndReset( + const MetricAttributes &pointAttributes) noexcept override + { + return reservoir_->CollectAndReset(pointAttributes); + } + +private: + explicit FilteredExemplarReservoir() = default; + std::shared_ptr filter_; + std::shared_ptr reservoir_; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h new file mode 100644 index 0000000000..1a0abeb6b6 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h @@ -0,0 +1,102 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include "opentelemetry/context/context.h" +# include "opentelemetry/nostd/function_ref.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class FixedSizeExemplarReservoir : public ExemplarReservoir +{ + +public: + FixedSizeExemplarReservoir(size_t size, + std::shared_ptr reservoir_cell_selector, + std::shared_ptr (ReservoirCell::*map_and_reset_cell)( + const common::OrderedAttributeMap &attributes)) + : storage_(size), + reservoir_cell_selector_(reservoir_cell_selector), + map_and_reset_cell_(map_and_reset_cell) + {} + + void OfferMeasurement(long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context, + const opentelemetry::common::SystemTimestamp ×tamp) noexcept override + { + if (!reservoir_cell_selector_) + { + return; + } + auto idx = + reservoir_cell_selector_->ReservoirCellIndexFor(storage_, value, attributes, context); + if (idx != -1) + { + storage_[idx].RecordDoubleMeasurement(value, attributes, context); + } + } + + void OfferMeasurement(double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context, + const opentelemetry::common::SystemTimestamp ×tamp) noexcept override + { + if (!reservoir_cell_selector_) + { + return; + } + auto idx = + reservoir_cell_selector_->ReservoirCellIndexFor(storage_, value, attributes, context); + if (idx != -1) + { + storage_[idx].RecordDoubleMeasurement(value, attributes, context); + } + } + + std::vector> CollectAndReset( + const MetricAttributes &pointAttributes) noexcept override + { + std::vector> results; + if (!reservoir_cell_selector_) + { + return results; + } + if (!map_and_reset_cell_) + { + reservoir_cell_selector_.reset(); + return results; + } + for (auto reservoirCell : storage_) + { + auto result = (reservoirCell.*(map_and_reset_cell_))(pointAttributes); + results.push_back(result); + } + reservoir_cell_selector_.reset(); + return results; + } + +private: + explicit FixedSizeExemplarReservoir() = default; + std::vector storage_; + std::shared_ptr reservoir_cell_selector_; + std::shared_ptr (ReservoirCell::*map_and_reset_cell_)( + const common::OrderedAttributeMap &attributes); +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h new file mode 100644 index 0000000000..83f410f815 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h @@ -0,0 +1,80 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include "opentelemetry/context/context.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/data/exemplar_data.h" +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class HistogramExemplarReservoir : public FixedSizeExemplarReservoir +{ + +public: + static std::shared_ptr GetHistogramCellSelector( + const std::vector &boundaries = std::vector{1.0, 2.0, 3.0, 4.0, 5.0}) + { + return std::shared_ptr{new HistogramCellSelector(boundaries)}; + } + + HistogramExemplarReservoir(size_t size, + std::shared_ptr reservoir_cell_selector, + std::shared_ptr (ReservoirCell::*map_and_reset_cell)( + const common::OrderedAttributeMap &attributes)) + : FixedSizeExemplarReservoir(size, reservoir_cell_selector, map_and_reset_cell) + {} + + class HistogramCellSelector : public ReservoirCellSelector + { + public: + HistogramCellSelector(const std::vector &boundaries) : boundaries_(boundaries) {} + + int ReservoirCellIndexFor(const std::vector &cells, + long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) override + { + return ReservoirCellIndexFor(cells, (double)value, attributes, context); + } + + int ReservoirCellIndexFor(const std::vector &cells, + double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) override + { + for (size_t i = 0; i < boundaries_.size(); ++i) + { + if (value <= boundaries_[i]) + { + return i; + } + } + return -1; + } + + private: + void reset() override + { + // Do nothing + } + std::vector boundaries_; + }; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h index 53d38142c1..844bf72e10 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h @@ -14,12 +14,6 @@ namespace metrics class NeverSampleFilter final : public ExemplarFilter { public: - static nostd::shared_ptr GetNeverSampleFilter() - { - nostd::shared_ptr neverSampleFilter{new NeverSampleFilter{}}; - return neverSampleFilter; - } - bool ShouldSampleMeasurement( long /* value */, const MetricAttributes & /* attributes */, @@ -36,7 +30,6 @@ class NeverSampleFilter final : public ExemplarFilter return false; } -private: explicit NeverSampleFilter() = default; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h index 5ea1233c10..38c6c74c60 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h @@ -18,11 +18,6 @@ class NoExemplarReservoir final : public ExemplarReservoir { public: - static nostd::shared_ptr GetNoExemplarReservoir() - { - return nostd::shared_ptr{new NoExemplarReservoir{}}; - } - void OfferMeasurement( long /* value */, const MetricAttributes & /* attributes */, @@ -41,13 +36,12 @@ class NoExemplarReservoir final : public ExemplarReservoir // Stores nothing. } - std::vector CollectAndReset( + std::vector> CollectAndReset( const MetricAttributes & /* pointAttributes */) noexcept override { - return std::vector{}; + return std::vector>{}; } -private: explicit NoExemplarReservoir() = default; }; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h index 25e8421d6b..db8a37c260 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h @@ -4,7 +4,9 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW # include -# include "opentelemetry/sdk/metrics/exemplar/data.h" +# include "opentelemetry/sdk/metrics/data/exemplar_data.h" +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -45,8 +47,20 @@ class ExemplarReservoir * @return A vector of sampled exemplars for this point. Implementers are expected to * filter out pointAttributes from the original recorded attributes. */ - virtual std::vector CollectAndReset( + virtual std::vector> CollectAndReset( const MetricAttributes &pointAttributes) noexcept = 0; + + static nostd::shared_ptr GetFilteredExemplarReservoir( + std::shared_ptr filter, + std::shared_ptr reservoir); + + static nostd::shared_ptr GetHistogramExemplarReservoir( + size_t size, + std::shared_ptr reservoir_cell_selector, + std::shared_ptr (ReservoirCell::*map_and_reset_cell)( + const common::OrderedAttributeMap &attributes)); + + static nostd::shared_ptr GetNoExemplarReservoir(); }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h new file mode 100644 index 0000000000..9a84155f2a --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h @@ -0,0 +1,152 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/context/context.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/data/exemplar_data.h" +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/trace/context.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +/** + * A Reservoir cell pre-allocated memories for Exemplar data. + */ +class ReservoirCell +{ +public: + ReservoirCell() = default; + + /** + * Record the long measurement to the cell. + */ + void RecordLongMeasurement(long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) + { + value_ = value; + offerMeasurement(attributes, context); + } + + /** + * Record the long measurement to the cell. + */ + void RecordDoubleMeasurement(double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) + { + value_ = value; + offerMeasurement(attributes, context); + } + + /** + * Retrieve the cell's {@link ExemplarData}. + * + *

Must be used in tandem with {@link #recordLongMeasurement(long, Attributes, Context)}. + */ + std::shared_ptr GetAndResetLong(const MetricAttributes &point_attributes) + { + if (!context_) + { + return nullptr; + } + auto attributes = attributes_; + PointDataAttributes point_data_attributes; + point_data_attributes.attributes = filtered(attributes, point_attributes); + if (nostd::holds_alternative(value_)) + { + point_data_attributes.point_data = ExemplarData::CreateSumPointData(nostd::get(value_)); + } + std::shared_ptr result{ + new ExemplarData{ExemplarData::Create(context_, record_time_, point_data_attributes)}}; + reset(); + return result; + } + + /** + * Retrieve the cell's {@link ExemplarData}. + * + *

Must be used in tandem with {@link #recordDoubleMeasurement(double, Attributes, Context)}. + */ + std::shared_ptr GetAndResetDouble(const MetricAttributes &point_attributes) + { + if (!context_) + { + return nullptr; + } + auto attributes = attributes_; + PointDataAttributes point_data_attributes; + point_data_attributes.attributes = filtered(attributes, point_attributes); + if (nostd::holds_alternative(value_)) + { + point_data_attributes.point_data = + ExemplarData::CreateSumPointData(nostd::get(value_)); + } + std::shared_ptr result{ + new ExemplarData{ExemplarData::Create(context_, record_time_, point_data_attributes)}}; + reset(); + return result; + } + + void reset() + { + value_ = 0.0; + record_time_ = opentelemetry::common::SystemTimestamp{}; + } + +private: + /** Returns filtered attributes for exemplars. */ + static MetricAttributes filtered(const MetricAttributes &original, + const MetricAttributes &metric_point) + { + auto res = original; + for (const auto &kv : metric_point) + { + auto it = res.find(kv.first); + if (it != res.end()) + { + res.erase(it); + } + } + return res; + } + + void offerMeasurement(const MetricAttributes &attributes, + const opentelemetry::context::Context &context) + { + attributes_ = attributes; + record_time_ = opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now()); + auto span = opentelemetry::trace::GetSpan(context); + if (span) + { + auto current_ctx = span->GetContext(); + if (current_ctx.IsValid()) + { + context_.reset(new trace::SpanContext{current_ctx}); + } + } + } + + // Cell stores either long or double values, but must not store both + std::shared_ptr context_; + nostd::variant value_; + opentelemetry::common::SystemTimestamp record_time_; + MetricAttributes attributes_; + // For testing + friend class ReservoirCellTestPeer; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h new file mode 100644 index 0000000000..13e149f0aa --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#include +#ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include "opentelemetry/context/context.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/attribute_utils.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class ReservoirCellSelector +{ + +public: + virtual ~ReservoirCellSelector() = default; + + /** Determine the index of the {@code cells} to record the measurement to. */ + virtual int ReservoirCellIndexFor(const std::vector &cells, + long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) = 0; + + /** Determine the index of the {@code cells} to record the measurement to. */ + virtual int ReservoirCellIndexFor(const std::vector &cells, + double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) = 0; + + /** Called when {@link FixedSizeExemplarReservoir#CollectAndReset(Attributes)}. */ + virtual void reset() = 0; +}; + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h new file mode 100644 index 0000000000..b81ccbccb2 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/trace/context.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +class WithTraceSampleFilter final : public ExemplarFilter +{ +public: + bool ShouldSampleMeasurement(long value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) noexcept override + { + return hasSampledTrace(context); + } + + bool ShouldSampleMeasurement(double value, + const MetricAttributes &attributes, + const opentelemetry::context::Context &context) noexcept override + { + return hasSampledTrace(context); + } + + explicit WithTraceSampleFilter() = default; + +private: + static bool hasSampledTrace(const opentelemetry::context::Context &context) + { + return opentelemetry::trace::GetSpan(context)->GetContext().IsValid() && + opentelemetry::trace::GetSpan(context)->GetContext().IsSampled(); + } +}; +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h index 7b4cf4d47f..07f4cadbd1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h @@ -40,6 +40,9 @@ struct ResourceMetrics class MetricProducer { public: + MetricProducer() = default; + virtual ~MetricProducer() = default; + /** * The callback to be called for each metric exporter. This will only be those * metrics that have been produced since the last time this method was called. diff --git a/sdk/include/opentelemetry/sdk/metrics/observer_result.h b/sdk/include/opentelemetry/sdk/metrics/observer_result.h index a8d3561f2e..e4f2a4887e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/observer_result.h +++ b/sdk/include/opentelemetry/sdk/metrics/observer_result.h @@ -23,7 +23,7 @@ class ObserverResultT final : public opentelemetry::metrics::ObserverResultT : attributes_processor_(attributes_processor) {} - virtual ~ObserverResultT() = default; + ~ObserverResultT() override = default; void Observe(T value) noexcept override { data_.insert({{}, value}); } diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index e466fa6a4f..2b6ca98201 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -18,6 +18,9 @@ class MeterContext; class CollectorHandle { public: + CollectorHandle() = default; + virtual ~CollectorHandle() = default; + virtual AggregationTemporality GetAggregationTemporality( InstrumentType instrument_type) noexcept = 0; }; @@ -33,7 +36,7 @@ class MetricCollector : public MetricProducer, public CollectorHandle public: MetricCollector(MeterContext *context, std::unique_ptr metric_reader); - virtual ~MetricCollector() = default; + ~MetricCollector() override = 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 7e57b43ac8..be097a8be0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h @@ -22,6 +22,9 @@ class CollectorHandle; class MetricStorage { public: + MetricStorage() = default; + virtual ~MetricStorage() = default; + /* collect the metrics from this storage */ virtual bool Collect(CollectorHandle *collector, nostd::span> collectors, diff --git a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h index 045b83c27b..bf76145f03 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/observable_registry.h @@ -45,4 +45,4 @@ class ObservableRegistry } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 05dae8558f..57166ee60e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -124,4 +124,4 @@ class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histo } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index ebd22b79b4..d6d536454c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -77,4 +77,4 @@ class FilteringAttributesProcessor : public AttributesProcessor } // 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_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index 41755d23bf..dedd154b1c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -96,7 +96,7 @@ class ViewRegistry (selector->GetInstrumentType() == instrument_descriptor.type_); } }; -}; // namespace metrics +} // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE #endif diff --git a/sdk/include/opentelemetry/sdk/resource/resource_detector.h b/sdk/include/opentelemetry/sdk/resource/resource_detector.h index 5f9d904aff..6447a2660d 100644 --- a/sdk/include/opentelemetry/sdk/resource/resource_detector.h +++ b/sdk/include/opentelemetry/sdk/resource/resource_detector.h @@ -20,7 +20,9 @@ class Resource; class ResourceDetector { public: - virtual Resource Detect() = 0; + ResourceDetector() = default; + virtual ~ResourceDetector() = default; + virtual Resource Detect() = 0; }; /** @@ -35,4 +37,4 @@ class OTELResourceDetector : public ResourceDetector } // namespace resource } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h index f3f26c984f..309d849bc7 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h @@ -85,7 +85,7 @@ class BatchSpanProcessor : public SpanProcessor * shared ownership of the processor, and thus doesn't call Shutdown (as the processor might be * shared with other Tracers). */ - virtual ~BatchSpanProcessor(); + ~BatchSpanProcessor() override; protected: /** diff --git a/sdk/include/opentelemetry/sdk/trace/id_generator.h b/sdk/include/opentelemetry/sdk/trace/id_generator.h index da17effaeb..559870d961 100644 --- a/sdk/include/opentelemetry/sdk/trace/id_generator.h +++ b/sdk/include/opentelemetry/sdk/trace/id_generator.h @@ -28,4 +28,4 @@ class IdGenerator } // namespace trace } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h index 3c485d8a3d..6abd39f90b 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h @@ -157,4 +157,4 @@ class MultiRecordable : public Recordable }; } // namespace trace } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h b/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h index 8463ad5209..e3b4a2031e 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_span_processor.h @@ -134,7 +134,7 @@ class MultiSpanProcessor : public SpanProcessor return result; } - ~MultiSpanProcessor() + ~MultiSpanProcessor() override { Shutdown(); Cleanup(); @@ -184,4 +184,4 @@ class MultiSpanProcessor : public SpanProcessor }; } // namespace trace } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/random_id_generator.h b/sdk/include/opentelemetry/sdk/trace/random_id_generator.h index 908f1b8506..59df91651f 100644 --- a/sdk/include/opentelemetry/sdk/trace/random_id_generator.h +++ b/sdk/include/opentelemetry/sdk/trace/random_id_generator.h @@ -19,6 +19,5 @@ class RandomIdGenerator : public IdGenerator }; } // namespace trace - } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index bdb03868ac..09ab7b5c82 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -68,7 +68,7 @@ class SimpleSpanProcessor : public SpanProcessor return true; } - ~SimpleSpanProcessor() { Shutdown(); } + ~SimpleSpanProcessor() override { Shutdown(); } private: std::unique_ptr exporter_; diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index aa0f69a2ba..06088738c2 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -59,7 +59,7 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider */ explicit TracerProvider(std::shared_ptr context) noexcept; - ~TracerProvider(); + ~TracerProvider() override; opentelemetry::nostd::shared_ptr GetTracer( nostd::string_view library_name, diff --git a/sdk/include/opentelemetry/sdk_config.h b/sdk/include/opentelemetry/sdk_config.h index 8ac72a10d5..280ccaa993 100644 --- a/sdk/include/opentelemetry/sdk_config.h +++ b/sdk/include/opentelemetry/sdk_config.h @@ -4,4 +4,4 @@ #pragma once #include "opentelemetry/config.h" -#include "opentelemetry/sdk/common/global_log_handler.h" \ No newline at end of file +#include "opentelemetry/sdk/common/global_log_handler.h" diff --git a/sdk/src/logs/batch_log_processor.cc b/sdk/src/logs/batch_log_processor.cc index ecba6d75bd..35092652cb 100644 --- a/sdk/src/logs/batch_log_processor.cc +++ b/sdk/src/logs/batch_log_processor.cc @@ -53,7 +53,7 @@ std::unique_ptr BatchLogProcessor::MakeRecordable() noexcept return exporter_->MakeRecordable(); } -void BatchLogProcessor::OnReceive(std::unique_ptr &&record) noexcept +void BatchLogProcessor::OnEmit(std::unique_ptr &&record) noexcept { if (synchronization_data_->is_shutdown.load() == true) { diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index f934107fae..d7ab485dff 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -111,7 +111,7 @@ void Logger::Log(opentelemetry::logs::Severity severity, } // Send the log record to the processor - processor.OnReceive(std::move(recordable)); + processor.OnEmit(std::move(recordable)); } const opentelemetry::sdk::instrumentationscope::InstrumentationScope & diff --git a/sdk/src/logs/multi_log_processor.cc b/sdk/src/logs/multi_log_processor.cc index 5c7fe400f9..a6b2eef1f3 100644 --- a/sdk/src/logs/multi_log_processor.cc +++ b/sdk/src/logs/multi_log_processor.cc @@ -48,7 +48,7 @@ std::unique_ptr MultiLogProcessor::MakeRecordable() noexcept return recordable; } -void MultiLogProcessor::OnReceive(std::unique_ptr &&record) noexcept +void MultiLogProcessor::OnEmit(std::unique_ptr &&record) noexcept { if (!record) { @@ -61,7 +61,7 @@ void MultiLogProcessor::OnReceive(std::unique_ptr &&record) noexcept auto recordable = multi_recordable->ReleaseRecordable(*processor); if (recordable) { - processor->OnReceive(std::move(recordable)); + processor->OnEmit(std::move(recordable)); } } } diff --git a/sdk/src/logs/simple_log_processor.cc b/sdk/src/logs/simple_log_processor.cc index f5b82c0bbc..3d5d798c0a 100644 --- a/sdk/src/logs/simple_log_processor.cc +++ b/sdk/src/logs/simple_log_processor.cc @@ -29,7 +29,7 @@ std::unique_ptr SimpleLogProcessor::MakeRecordable() noexcept * Batches the log record it receives in a batch of 1 and immediately sends it * to the configured exporter */ -void SimpleLogProcessor::OnReceive(std::unique_ptr &&record) noexcept +void SimpleLogProcessor::OnEmit(std::unique_ptr &&record) noexcept { nostd::span> batch(&record, 1); // Get lock to ensure Export() is never called concurrently diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index dbbb465183..80c1bff335 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -13,6 +13,8 @@ add_library( aggregation/histogram_aggregation.cc aggregation/lastvalue_aggregation.cc aggregation/sum_aggregation.cc + exemplar/filter.cc + exemplar/reservoir.cc sync_instruments.cc) set_target_properties(opentelemetry_metrics PROPERTIES EXPORT_NAME metrics) diff --git a/sdk/src/metrics/exemplar/filter.cc b/sdk/src/metrics/exemplar/filter.cc new file mode 100644 index 0000000000..89d89b37a3 --- /dev/null +++ b/sdk/src/metrics/exemplar/filter.cc @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/filter.h" +# include "opentelemetry/sdk/metrics/exemplar/always_sample_filter.h" +# include "opentelemetry/sdk/metrics/exemplar/never_sample_filter.h" +# include "opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +std::shared_ptr ExemplarFilter::GetNeverSampleFilter() noexcept +{ + static std::shared_ptr neverSampleFilter{new NeverSampleFilter{}}; + return neverSampleFilter; +} + +std::shared_ptr ExemplarFilter::GetAlwaysSampleFilter() noexcept +{ + static std::shared_ptr alwaysSampleFilter{new AlwaysSampleFilter{}}; + return alwaysSampleFilter; +} + +std::shared_ptr ExemplarFilter::GetWithTraceSampleFilter() noexcept +{ + std::shared_ptr withTraceSampleFilter{new WithTraceSampleFilter{}}; + return withTraceSampleFilter; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/metrics/exemplar/reservoir.cc b/sdk/src/metrics/exemplar/reservoir.cc new file mode 100644 index 0000000000..6209d91e80 --- /dev/null +++ b/sdk/src/metrics/exemplar/reservoir.cc @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/reservoir.h" +# include +# include "opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +nostd::shared_ptr ExemplarReservoir::GetFilteredExemplarReservoir( + std::shared_ptr filter, + std::shared_ptr reservoir) +{ + return nostd::shared_ptr{new FilteredExemplarReservoir{filter, reservoir}}; +} + +nostd::shared_ptr ExemplarReservoir::GetHistogramExemplarReservoir( + size_t size, + std::shared_ptr reservoir_cell_selector, + std::shared_ptr (ReservoirCell::*map_and_reset_cell)( + const common::OrderedAttributeMap &attributes)) +{ + return nostd::shared_ptr{ + new HistogramExemplarReservoir{size, reservoir_cell_selector, map_and_reset_cell}}; +} + +nostd::shared_ptr ExemplarReservoir::GetNoExemplarReservoir() +{ + return nostd::shared_ptr{new NoExemplarReservoir{}}; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 0174be87ec..ed653be0ed 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -101,4 +101,4 @@ bool PeriodicExportingMetricReader::OnShutDown(std::chrono::microseconds timeout } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 4d6595dd7f..27b8044cdb 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -6,7 +6,7 @@ # include "opentelemetry/metrics/noop.h" # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/async_instruments.h" -# include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" # include "opentelemetry/sdk/metrics/state/observable_registry.h" # include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" @@ -233,7 +233,7 @@ std::unique_ptr Meter::RegisterSyncMetricStorage( auto storage = std::shared_ptr(new SyncMetricStorage( view_instr_desc, view.GetAggregationType(), &view.GetAttributesProcessor(), - NoExemplarReservoir::GetNoExemplarReservoir(), view.GetAggregationConfig())); + ExemplarReservoir::GetNoExemplarReservoir(), view.GetAggregationConfig())); storage_registry_[instrument_descriptor.name_] = storage; multi_storage->AddStorage(storage); return true; diff --git a/sdk/src/trace/batch_span_processor_factory.cc b/sdk/src/trace/batch_span_processor_factory.cc index 18c3f955f5..b2b23857a1 100644 --- a/sdk/src/trace/batch_span_processor_factory.cc +++ b/sdk/src/trace/batch_span_processor_factory.cc @@ -16,7 +16,7 @@ std::unique_ptr BatchSpanProcessorFactory::Create( { std::unique_ptr processor(new BatchSpanProcessor(std::move(exporter), options)); return processor; -}; +} } // namespace trace } // namespace sdk diff --git a/sdk/src/trace/simple_processor_factory.cc b/sdk/src/trace/simple_processor_factory.cc index 92e7b4dbee..59e3ea92f1 100644 --- a/sdk/src/trace/simple_processor_factory.cc +++ b/sdk/src/trace/simple_processor_factory.cc @@ -14,7 +14,7 @@ std::unique_ptr SimpleSpanProcessorFactory::Create( { std::unique_ptr processor(new SimpleSpanProcessor(std::move(exporter))); return processor; -}; +} } // namespace trace } // namespace sdk diff --git a/sdk/test/common/attributemap_hash_test.cc b/sdk/test/common/attributemap_hash_test.cc index 7d2748670d..49e53361ba 100644 --- a/sdk/test/common/attributemap_hash_test.cc +++ b/sdk/test/common/attributemap_hash_test.cc @@ -29,4 +29,4 @@ TEST(AttributeMapHashTest, BasicTests) OrderedAttributeMap map1 = {}; EXPECT_TRUE(GetHashForAttributeMap(map1) == 0); } -} \ No newline at end of file +} diff --git a/sdk/test/logs/batch_log_processor_test.cc b/sdk/test/logs/batch_log_processor_test.cc index 18e3ee531d..b6fb240ee5 100644 --- a/sdk/test/logs/batch_log_processor_test.cc +++ b/sdk/test/logs/batch_log_processor_test.cc @@ -111,7 +111,7 @@ TEST_F(BatchLogProcessorTest, TestShutdown) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } // Test that shutting down the processor will first wait for the @@ -146,7 +146,7 @@ TEST_F(BatchLogProcessorTest, TestForceFlush) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } EXPECT_TRUE(batch_processor->ForceFlush()); @@ -162,7 +162,7 @@ TEST_F(BatchLogProcessorTest, TestForceFlush) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } EXPECT_TRUE(batch_processor->ForceFlush()); @@ -191,7 +191,7 @@ TEST_F(BatchLogProcessorTest, TestManyLogsLoss) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } EXPECT_TRUE(batch_processor->ForceFlush()); @@ -215,7 +215,7 @@ TEST_F(BatchLogProcessorTest, TestManyLogsLossLess) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } EXPECT_TRUE(batch_processor->ForceFlush()); @@ -248,7 +248,7 @@ TEST_F(BatchLogProcessorTest, TestScheduledDelayMillis) { auto log = batch_processor->MakeRecordable(); log->SetBody("Log" + std::to_string(i)); - batch_processor->OnReceive(std::move(log)); + batch_processor->OnEmit(std::move(log)); } // Sleep for scheduled_delay_millis milliseconds std::this_thread::sleep_for(scheduled_delay_millis); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 1488798f07..6bf738e812 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -86,7 +86,7 @@ class DummyProcessor : public LogProcessor return std::unique_ptr(new LogRecord); } - void OnReceive(std::unique_ptr && /* record */) noexcept override {} + void OnEmit(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; } }; diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 36278349ba..91279341c6 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -15,7 +15,7 @@ TEST(LoggerSDK, LogToNullProcessor) { // Confirm Logger::Log() does not have undefined behavior // even when there is no processor set - // since it calls Processor::OnReceive() + // since it calls Processor::OnEmit() auto lp = std::shared_ptr(new LoggerProvider()); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; @@ -44,9 +44,10 @@ class MockProcessor final : public LogProcessor { return std::unique_ptr(new LogRecord); } - // OnReceive stores the record it receives into the shared_ptr recordable passed into its + + // OnEmit stores the record it receives into the shared_ptr recordable passed into its // constructor - void OnReceive(std::unique_ptr &&record) noexcept override + void OnEmit(std::unique_ptr &&record) noexcept override { // Cast the recordable received into a concrete LogRecord type auto copy = std::shared_ptr(static_cast(record.release())); diff --git a/sdk/test/logs/simple_log_processor_test.cc b/sdk/test/logs/simple_log_processor_test.cc index 1e77b2a858..008ca7c522 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -86,7 +86,7 @@ TEST(SimpleLogProcessorTest, SendReceivedLogsToExporter) { auto recordable = processor.MakeRecordable(); recordable->SetBody("Log Body"); - processor.OnReceive(std::move(recordable)); + processor.OnEmit(std::move(recordable)); // Verify that the batch of 1 log record sent by processor matches what exporter received EXPECT_EQ(1, batch_size_received); diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 823f55f264..74fff4661d 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -31,7 +31,7 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} - virtual ~MockCollectorHandle() = default; + ~MockCollectorHandle() override = default; AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override @@ -72,7 +72,6 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) std::shared_ptr{}); long get_count1 = 20l; long put_count1 = 10l; - size_t attribute_count = 2; std::unordered_map measurements1 = { {{{"RequestType", "GET"}}, get_count1}, {{{"RequestType", "PUT"}}, put_count1}}; storage.RecordLong(measurements1, diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index 92035809e0..af7ead0778 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -54,4 +54,4 @@ void BM_AttributseHashMap(benchmark::State &state) BENCHMARK(BM_AttributseHashMap); } // namespace #endif -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); diff --git a/sdk/test/metrics/exemplar/BUILD b/sdk/test/metrics/exemplar/BUILD index 6481f679d2..1009999d02 100644 --- a/sdk/test/metrics/exemplar/BUILD +++ b/sdk/test/metrics/exemplar/BUILD @@ -10,6 +10,24 @@ cc_test( deps = [ "//api", "//sdk:headers", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "with_trace_sample_filter_test", + srcs = [ + "with_trace_sample_filter_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//api", + "//sdk:headers", + "//sdk/src/metrics", "@com_google_googletest//:gtest_main", ], ) @@ -26,6 +44,7 @@ cc_test( deps = [ "//api", "//sdk:headers", + "//sdk/src/metrics", "@com_google_googletest//:gtest_main", ], ) @@ -42,6 +61,41 @@ cc_test( deps = [ "//api", "//sdk:headers", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "reservoir_cell_test", + srcs = [ + "reservoir_cell_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//api", + "//sdk:headers", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "histogram_exemplar_reservoir_test", + srcs = [ + "histogram_exemplar_reservoir_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//api", + "//sdk:headers", + "//sdk/src/metrics", "@com_google_googletest//:gtest_main", ], ) diff --git a/sdk/test/metrics/exemplar/CMakeLists.txt b/sdk/test/metrics/exemplar/CMakeLists.txt index 303294761a..33d04e913c 100644 --- a/sdk/test/metrics/exemplar/CMakeLists.txt +++ b/sdk/test/metrics/exemplar/CMakeLists.txt @@ -1,8 +1,12 @@ -foreach(testname no_exemplar_reservoir_test never_sample_filter_test - always_sample_filter_test) +foreach( + testname + no_exemplar_reservoir_test never_sample_filter_test always_sample_filter_test + histogram_exemplar_reservoir_test reservoir_cell_test + with_trace_sample_filter_test) add_executable(${testname} "${testname}.cc") - target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics) + target_link_libraries( + ${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_metrics opentelemetry_metrics) gtest_add_tests( TARGET ${testname} TEST_PREFIX metrics. diff --git a/sdk/test/metrics/exemplar/always_sample_filter_test.cc b/sdk/test/metrics/exemplar/always_sample_filter_test.cc index cf4e449957..5f9716f60d 100644 --- a/sdk/test/metrics/exemplar/always_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/always_sample_filter_test.cc @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #ifndef ENABLE_METRICS_PREVIEW -# include "opentelemetry/sdk/metrics/exemplar/always_sample_filter.h" # include +# include "opentelemetry/sdk/metrics/exemplar/filter.h" using namespace opentelemetry::sdk::metrics; TEST(AlwaysSampleFilter, SampleMeasurement) { - auto filter = opentelemetry::sdk::metrics::AlwaysSampleFilter::GetAlwaysSampleFilter(); + auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetAlwaysSampleFilter(); ASSERT_TRUE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); ASSERT_TRUE( diff --git a/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc new file mode 100644 index 0000000000..1f7b3100ea --- /dev/null +++ b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#ifndef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class HistogramExemplarReservoirTestPeer : public ::testing::Test +{ +public: +}; + +TEST_F(HistogramExemplarReservoirTestPeer, OfferMeasurement) +{ + std::vector boundaries{1, 5.0, 10, 15, 20}; + auto histogram_exemplar_reservoir = ExemplarReservoir::GetHistogramExemplarReservoir( + boundaries.size(), HistogramExemplarReservoir::GetHistogramCellSelector(boundaries), nullptr); + histogram_exemplar_reservoir->OfferMeasurement( + 1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); + histogram_exemplar_reservoir->OfferMeasurement( + 1l, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); + auto exemplar_data = histogram_exemplar_reservoir->CollectAndReset(MetricAttributes{}); + ASSERT_TRUE(exemplar_data.empty()); +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/exemplar/never_sample_filter_test.cc b/sdk/test/metrics/exemplar/never_sample_filter_test.cc index 930c572205..4e40015e8f 100644 --- a/sdk/test/metrics/exemplar/never_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/never_sample_filter_test.cc @@ -4,13 +4,13 @@ #include "opentelemetry/context/context.h" #ifndef ENABLE_METRICS_PREVIEW # include -# include "opentelemetry/sdk/metrics/exemplar/never_sample_filter.h" +# include "opentelemetry/sdk/metrics/exemplar/filter.h" using namespace opentelemetry::sdk::metrics; TEST(NeverSampleFilter, SampleMeasurement) { - auto filter = opentelemetry::sdk::metrics::NeverSampleFilter::GetNeverSampleFilter(); + auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetNeverSampleFilter(); ASSERT_FALSE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); ASSERT_FALSE( diff --git a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc index 72341de9de..a0f645fee1 100644 --- a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc +++ b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc @@ -9,7 +9,7 @@ using namespace opentelemetry::sdk::metrics; TEST(NoExemplarReservoir, OfferMeasurement) { - auto reservoir = opentelemetry::sdk::metrics::NoExemplarReservoir::GetNoExemplarReservoir(); + auto reservoir = opentelemetry::sdk::metrics::ExemplarReservoir::GetNoExemplarReservoir(); reservoir->OfferMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); reservoir->OfferMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{}, diff --git a/sdk/test/metrics/exemplar/reservoir_cell_test.cc b/sdk/test/metrics/exemplar/reservoir_cell_test.cc new file mode 100644 index 0000000000..a42f11151a --- /dev/null +++ b/sdk/test/metrics/exemplar/reservoir_cell_test.cc @@ -0,0 +1,73 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h" +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class ReservoirCellTestPeer : public ::testing::Test +{ +public: + long GetLongVal(const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) + { + return nostd::get(reservoir_cell.value_); + } + + double GetDoubleVal(const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) + { + return nostd::get(reservoir_cell.value_); + } + + opentelemetry::common::SystemTimestamp GetRecordTime( + const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) + { + return reservoir_cell.record_time_; + } + + void FilteredTest() + { + MetricAttributes original{{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; + MetricAttributes metric_point{{"k2", "v2"}, {"k4", "v4"}}; + MetricAttributes expected_result{{"k1", "v1"}, {"k3", "v3"}}; + auto result = opentelemetry::sdk::metrics::ReservoirCell::filtered(original, metric_point); + ASSERT_TRUE(result == expected_result); + } +}; + +TEST_F(ReservoirCellTestPeer, recordMeasurement) +{ + opentelemetry::sdk::metrics::ReservoirCell reservoir_cell; + reservoir_cell.RecordLongMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{}); + ASSERT_TRUE(GetLongVal(reservoir_cell) == 1); + + reservoir_cell.RecordDoubleMeasurement(1.5, MetricAttributes{}, + opentelemetry::context::Context{}); + ASSERT_TRUE(GetDoubleVal(reservoir_cell) == 1.5); +} + +TEST_F(ReservoirCellTestPeer, GetAndReset) +{ + opentelemetry::sdk::metrics::ReservoirCell reservoir_cell; + auto double_data = reservoir_cell.GetAndResetDouble(MetricAttributes{}); + ASSERT_TRUE(GetRecordTime(reservoir_cell) == opentelemetry::common::SystemTimestamp{}); + ASSERT_TRUE(double_data == nullptr); + + auto long_data = reservoir_cell.GetAndResetLong(MetricAttributes{}); + ASSERT_TRUE(GetRecordTime(reservoir_cell) == opentelemetry::common::SystemTimestamp{}); + ASSERT_TRUE(long_data == nullptr); +} + +TEST_F(ReservoirCellTestPeer, Filtered) +{ + FilteredTest(); +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc new file mode 100644 index 0000000000..1c46dcddd6 --- /dev/null +++ b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/context/context.h" +#ifndef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/sdk/metrics/exemplar/filter.h" + +using namespace opentelemetry::sdk::metrics; + +TEST(WithTraceSampleFilter, SampleMeasurement) +{ + auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetWithTraceSampleFilter(); + ASSERT_FALSE( + filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); + ASSERT_FALSE( + filter->ShouldSampleMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{})); +} + +#endif diff --git a/sdk/test/metrics/observable_registry_test.cc b/sdk/test/metrics/observable_registry_test.cc index 77b5fc13fa..bfbb83fe9d 100644 --- a/sdk/test/metrics/observable_registry_test.cc +++ b/sdk/test/metrics/observable_registry_test.cc @@ -74,4 +74,4 @@ TEST(ObservableRegistry, BasicTests) ObservableRegistry registry; EXPECT_EQ(1, 1); } -#endif \ No newline at end of file +#endif diff --git a/sdk/test/metrics/observer_result_test.cc b/sdk/test/metrics/observer_result_test.cc index 55197a3cbf..7dea4195f4 100644 --- a/sdk/test/metrics/observer_result_test.cc +++ b/sdk/test/metrics/observer_result_test.cc @@ -35,4 +35,4 @@ TEST(ObserverResult, BasicTests) delete attributes_processor; } -#endif \ No newline at end of file +#endif diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 1c276c046f..696bf7ae49 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -133,4 +133,4 @@ TEST(SyncInstruments, DoubleHistogram) opentelemetry::context::Context{}); } -#endif \ No newline at end of file +#endif diff --git a/sdk/test/metrics/sync_metric_storage_counter_test.cc b/sdk/test/metrics/sync_metric_storage_counter_test.cc index a2853f5181..555ae8ce09 100644 --- a/sdk/test/metrics/sync_metric_storage_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_counter_test.cc @@ -5,7 +5,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/key_value_iterable_view.h" # include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" # include "opentelemetry/sdk/metrics/view/attributes_processor.h" @@ -23,7 +23,7 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} - virtual ~MockCollectorHandle() = default; + ~MockCollectorHandle() override = default; AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override @@ -53,7 +53,7 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir(), + ExemplarReservoir::GetNoExemplarReservoir(), std::shared_ptr{}); storage.RecordLong(10l, KeyValueIterableView>(attributes_get), @@ -188,7 +188,7 @@ TEST_P(WritableMetricStorageTestFixture, DoubleSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir(), + ExemplarReservoir::GetNoExemplarReservoir(), std::shared_ptr{}); storage.RecordDouble(10.0, diff --git a/sdk/test/metrics/sync_metric_storage_histogram_test.cc b/sdk/test/metrics/sync_metric_storage_histogram_test.cc index 0e0713d60a..865fcf7125 100644 --- a/sdk/test/metrics/sync_metric_storage_histogram_test.cc +++ b/sdk/test/metrics/sync_metric_storage_histogram_test.cc @@ -23,7 +23,7 @@ class MockCollectorHandle : public CollectorHandle public: MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {} - virtual ~MockCollectorHandle() = default; + ~MockCollectorHandle() override = default; AggregationTemporality GetAggregationTemporality( InstrumentType /* instrument_type */) noexcept override diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 15a7566b9b..16be43fa6f 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -48,13 +48,17 @@ class MockSampler final : public Sampler return {Decision::RECORD_AND_SAMPLE, nostd::unique_ptr>( new const std::map( - {{"sampling_attr1", 123}, {"sampling_attr2", "string"}}))}; + {{"sampling_attr1", 123}, {"sampling_attr2", "string"}})), + nostd::shared_ptr(nullptr)}; } else { // we should never reach here assert(false); - return {Decision::DROP}; + return {Decision::DROP, + nostd::unique_ptr>( + nullptr), + nostd::shared_ptr(nullptr)}; } }