From f31452286ce4742cb82a3059eaccb96ae8f1b0d2 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sat, 30 Apr 2022 06:18:49 +0530 Subject: [PATCH] Simplify SDK Configuration: Use View with default aggregation if no matching View is configured (#1358) --- .../opentelemetry/sdk/metrics/view/view.h | 2 +- .../sdk/metrics/view/view_registry.h | 2 +- sdk/test/metrics/view_registry_test.cc | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index e88e7126c6..3cd9f850e1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -23,7 +23,7 @@ class View public: View(const std::string &name, const std::string &description = "", - AggregationType aggregation_type = AggregationType::kDrop, + AggregationType aggregation_type = AggregationType::kDefault, std::unique_ptr attributes_processor = std::unique_ptr( new opentelemetry::sdk::metrics::DefaultAttributesProcessor())) diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h index 87b842e46a..795049dd9a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view_registry.h @@ -64,7 +64,7 @@ class ViewRegistry // return default view if none found; if (!found) { - static View view(""); + static View view("otel-default-view"); if (!callback(view)) { return false; diff --git a/sdk/test/metrics/view_registry_test.cc b/sdk/test/metrics/view_registry_test.cc index c3a9923c50..8151d37545 100644 --- a/sdk/test/metrics/view_registry_test.cc +++ b/sdk/test/metrics/view_registry_test.cc @@ -25,13 +25,15 @@ TEST(ViewRegistry, FindViewsEmptyRegistry) InstrumentationLibrary::Create("default", "1.0.0", "https://opentelemetry.io/schemas/1.7.0"); int count = 0; ViewRegistry registry; - auto status = registry.FindViews(default_instrument_descriptor, - *default_instrumentation_lib.get(), [&count](const View &view) { - count++; - EXPECT_EQ(view.GetName(), ""); - EXPECT_EQ(view.GetDescription(), ""); - return true; - }); + auto status = + registry.FindViews(default_instrument_descriptor, *default_instrumentation_lib.get(), + [&count](const View &view) { + count++; + EXPECT_EQ(view.GetName(), "otel-default-view"); + EXPECT_EQ(view.GetDescription(), ""); + EXPECT_EQ(view.GetAggregationType(), AggregationType::kDefault); + return true; + }); EXPECT_EQ(count, 1); EXPECT_EQ(status, true); }