diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 5442dcc395..2234fca1a8 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -139,3 +139,43 @@ TEST(SyncInstruments, DoubleHistogram) histogram.Record(10.10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); } + +#if OPEN_TELEMETRY_ABI_VERSION_NO >= 2 +TEST(SyncInstruments, DoubleGauge) +{ + InstrumentDescriptor instrument_descriptor = { + "double_gauge", "description", "1", InstrumentType::kGauge, InstrumentValueType::kDouble}; + std::unique_ptr metric_storage(new SyncMultiMetricStorage()); + DoubleGauge gauge(instrument_descriptor, std::move(metric_storage)); + gauge.Record(10.10, opentelemetry::context::Context{}); + gauge.Record(-10.10, opentelemetry::context::Context{}); // This is ignored. + gauge.Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{}); // This is ignored too + gauge.Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{}); // This is ignored too + + gauge.Record(10.10, + opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{}); + gauge.Record(10.10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{}); +} + +TEST(SyncInstruments, LongGauge) +{ + InstrumentDescriptor instrument_descriptor = {"double_gauge", "description", "1", + InstrumentType::kGauge, InstrumentValueType::kLong}; + std::unique_ptr metric_storage(new SyncMultiMetricStorage()); + DoubleGauge gauge(instrument_descriptor, std::move(metric_storage)); + gauge.Record(10, opentelemetry::context::Context{}); + gauge.Record(std::numeric_limits::quiet_NaN(), + opentelemetry::context::Context{}); // This is ignored too + gauge.Record(std::numeric_limits::infinity(), + opentelemetry::context::Context{}); // This is ignored too + + gauge.Record(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{}); + gauge.Record(10, opentelemetry::common::KeyValueIterableView({}), + opentelemetry::context::Context{}); +} +#endif \ No newline at end of file