From 488157277716cde6bf16c537b348ae1c414bc2bd Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Sat, 8 Aug 2026 18:44:34 -0400 Subject: [PATCH 1/7] [CONFIGURATION] Apply metric view attribute filters --- CHANGELOG.md | 4 ++ sdk/src/configuration/sdk_builder.cc | 41 ++++++++++++++---- sdk/test/configuration/sdk_builder_test.cc | 49 ++++++++++++++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e6379d93..6adb25c35f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ Increment the: ## [Unreleased] +* [CONFIGURATION] Apply metric view `attribute_keys` include and exclude filters + when building the SDK, with exclude entries taking precedence. + [#3546](https://github.com/open-telemetry/opentelemetry-cpp/issues/3546) + * [CONFIGURATION] Add support for the composite sampler configuration (programmatic and from yaml) ([#4366](https://github.com/open-telemetry/opentelemetry-cpp/pull/4366)) diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index de22c29f00..783e172d74 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -1891,16 +1891,43 @@ std::unique_ptr SdkBuilder::Crea std::unique_ptr SdkBuilder::CreateAttributesProcessor( - const std::unique_ptr - & /* model */) const + const std::unique_ptr &model) + const { - std::unique_ptr sdk; + using opentelemetry::sdk::metrics::DefaultAttributesProcessor; + using opentelemetry::sdk::metrics::FilterAttributeMap; + using opentelemetry::sdk::metrics::FilteringAttributesProcessor; + using opentelemetry::sdk::metrics::FilteringExcludeAttributesProcessor; - // FIXME-SDK: https://github.com/open-telemetry/opentelemetry-cpp/issues/3546 - // FIXME-SDK: Need a subclass of AttributesProcessor for IncludeExclude - OTEL_INTERNAL_LOG_WARN("IncludeExclude attribute processor not supported, ignoring"); + FilterAttributeMap excluded; + if (model->excluded != nullptr) + { + for (const auto &key : model->excluded->string_array) + { + excluded.emplace(key, true); + } + } - return sdk; + if (model->included != nullptr) + { + FilterAttributeMap included; + for (const auto &key : model->included->string_array) + { + if (excluded.find(key) == excluded.end()) + { + included.emplace(key, true); + } + } + + return std::make_unique(std::move(included)); + } + + if (model->excluded != nullptr) + { + return std::make_unique(std::move(excluded)); + } + + return std::make_unique(); } void SdkBuilder::AddView( diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index 2d8bb243da..d7dbb8466a 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -32,6 +32,7 @@ #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" #include "opentelemetry/sdk/configuration/extension_push_metric_exporter_builder.h" #include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/include_exclude_configuration.h" #include "opentelemetry/sdk/configuration/instrument_type.h" #include "opentelemetry/sdk/configuration/logger_config_configuration.h" #include "opentelemetry/sdk/configuration/logger_configurator_configuration.h" @@ -46,6 +47,7 @@ #include "opentelemetry/sdk/configuration/sdk_builder.h" #include "opentelemetry/sdk/configuration/severity_number.h" #include "opentelemetry/sdk/configuration/span_limits_configuration.h" +#include "opentelemetry/sdk/configuration/string_array_configuration.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" #include "opentelemetry/sdk/configuration/view_configuration.h" @@ -723,6 +725,53 @@ TEST(SdkBuilder, CreatePeriodicMetricReader) EXPECT_TRUE(captured->exporter != nullptr); } +TEST(SdkBuilder, CreateAttributesProcessor) +{ + std::map attributes = {{"included", 1}, {"excluded", 2}, {"unlisted", 3}}; + opentelemetry::common::KeyValueIterableView> iterable(attributes); + config_sdk::SdkBuilder builder(std::make_shared()); + + // When both lists are configured, exclusion takes precedence over inclusion. + { + auto model = std::make_unique(); + model->included = std::make_unique(); + model->included->string_array = {"included", "excluded"}; + model->excluded = std::make_unique(); + model->excluded->string_array = {"excluded"}; + + auto processor = builder.CreateAttributesProcessor(model); + ASSERT_NE(processor, nullptr); + auto filtered = processor->process(iterable); + + EXPECT_EQ(filtered.size(), 1u); + EXPECT_NE(filtered.find("included"), filtered.end()); + } + + // An exclude-only configuration retains every key that is not excluded. + { + auto model = std::make_unique(); + model->excluded = std::make_unique(); + model->excluded->string_array = {"excluded"}; + + auto processor = builder.CreateAttributesProcessor(model); + ASSERT_NE(processor, nullptr); + auto filtered = processor->process(iterable); + + EXPECT_EQ(filtered.size(), 2u); + EXPECT_EQ(filtered.find("excluded"), filtered.end()); + } + + // An empty include/exclude block leaves attributes unchanged. + { + auto model = std::make_unique(); + auto processor = builder.CreateAttributesProcessor(model); + ASSERT_NE(processor, nullptr); + auto filtered = processor->process(iterable); + + EXPECT_EQ(filtered.size(), attributes.size()); + } +} + namespace { From 5a20f7d891817469fa76945e3f81ddb9dc82b2af Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:47:07 -0400 Subject: [PATCH 2/7] [CONFIGURATION] Add direct includes for attribute filters --- sdk/src/configuration/sdk_builder.cc | 2 ++ sdk/test/configuration/sdk_builder_test.cc | 1 + 2 files changed, 3 insertions(+) diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index 783e172d74..26c63d6569 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -131,6 +132,7 @@ #include "opentelemetry/sdk/configuration/span_limits_configuration.h" #include "opentelemetry/sdk/configuration/span_processor_configuration.h" #include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/string_array_configuration.h" #include "opentelemetry/sdk/configuration/string_array_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/string_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/text_map_propagator_builder.h" diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index d7dbb8466a..005e6c2acc 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -65,6 +65,7 @@ #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" #include "opentelemetry/sdk/metrics/view/view.h" #include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/sdk/resource/resource.h" From fa3f992eca643cc78373935d5629e23e2dd25dda Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:58:25 -0400 Subject: [PATCH 3/7] [CONFIGURATION] Support attribute key patterns --- CHANGELOG.md | 4 +- sdk/src/configuration/sdk_builder.cc | 85 ++++++++++++++++------ sdk/test/configuration/sdk_builder_test.cc | 22 ++++++ 3 files changed, 86 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6adb25c35f..7896a655e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ Increment the: ## [Unreleased] -* [CONFIGURATION] Apply metric view `attribute_keys` include and exclude filters - when building the SDK, with exclude entries taking precedence. +* [CONFIGURATION] Apply metric view `attribute_keys` include and exclude patterns + when building the SDK, with exclude patterns taking precedence. [#3546](https://github.com/open-telemetry/opentelemetry-cpp/issues/3546) * [CONFIGURATION] Add support for the composite sampler configuration diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index 26c63d6569..2fa8bf9c87 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -132,8 +131,8 @@ #include "opentelemetry/sdk/configuration/span_limits_configuration.h" #include "opentelemetry/sdk/configuration/span_processor_configuration.h" #include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" -#include "opentelemetry/sdk/configuration/string_array_configuration.h" #include "opentelemetry/sdk/configuration/string_array_attribute_value_configuration.h" +#include "opentelemetry/sdk/configuration/string_array_configuration.h" #include "opentelemetry/sdk/configuration/string_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/text_map_propagator_builder.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" @@ -218,6 +217,59 @@ using common::WildcardMatch; namespace { +class IncludeExcludeAttributesProcessor final + : public opentelemetry::sdk::metrics::AttributesProcessor +{ +public: + IncludeExcludeAttributesProcessor(bool include_all, + std::vector included_patterns, + std::vector excluded_patterns) + : include_all_(include_all), + included_patterns_(std::move(included_patterns)), + excluded_patterns_(std::move(excluded_patterns)) + {} + + opentelemetry::sdk::metrics::MetricAttributes process( + const opentelemetry::common::KeyValueIterable &attributes) const noexcept override + { + opentelemetry::sdk::metrics::MetricAttributes result; + attributes.ForEachKeyValue( + [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + if (isPresent(key)) + { + result.SetAttribute(key, value); + } + return true; + }); + + result.UpdateHash(); + return result; + } + + bool isPresent(nostd::string_view key) const noexcept override + { + return (include_all_ || MatchesAny(included_patterns_, key)) && + !MatchesAny(excluded_patterns_, key); + } + +private: + static bool MatchesAny(const std::vector &patterns, nostd::string_view key) noexcept + { + for (const auto &pattern : patterns) + { + if (WildcardMatch(pattern, key)) + { + return true; + } + } + return false; + } + + bool include_all_; + std::vector included_patterns_; + std::vector excluded_patterns_; +}; + static opentelemetry::logs::Severity ToLogSeverity( opentelemetry::sdk::configuration::SeverityNumber severity_number) { @@ -1897,39 +1949,26 @@ SdkBuilder::CreateAttributesProcessor( const { using opentelemetry::sdk::metrics::DefaultAttributesProcessor; - using opentelemetry::sdk::metrics::FilterAttributeMap; - using opentelemetry::sdk::metrics::FilteringAttributesProcessor; - using opentelemetry::sdk::metrics::FilteringExcludeAttributesProcessor; - FilterAttributeMap excluded; - if (model->excluded != nullptr) + if (model->included == nullptr && model->excluded == nullptr) { - for (const auto &key : model->excluded->string_array) - { - excluded.emplace(key, true); - } + return std::make_unique(); } + std::vector included_patterns; if (model->included != nullptr) { - FilterAttributeMap included; - for (const auto &key : model->included->string_array) - { - if (excluded.find(key) == excluded.end()) - { - included.emplace(key, true); - } - } - - return std::make_unique(std::move(included)); + included_patterns = model->included->string_array; } + std::vector excluded_patterns; if (model->excluded != nullptr) { - return std::make_unique(std::move(excluded)); + excluded_patterns = model->excluded->string_array; } - return std::make_unique(); + return std::make_unique( + model->included == nullptr, std::move(included_patterns), std::move(excluded_patterns)); } void SdkBuilder::AddView( diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index 005e6c2acc..c658e4958d 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -748,6 +748,28 @@ TEST(SdkBuilder, CreateAttributesProcessor) EXPECT_NE(filtered.find("included"), filtered.end()); } + // Wildcard patterns are evaluated per key, with exclusion taking precedence. + { + std::map wildcard_attributes = { + {"foo.bar", 1}, {"foo.baz", 2}, {"question.x", 3}, {"question.xy", 4}, {"other", 5}}; + opentelemetry::common::KeyValueIterableView> wildcard_iterable( + wildcard_attributes); + + auto model = std::make_unique(); + model->included = std::make_unique(); + model->included->string_array = {"foo.*", "question.?"}; + model->excluded = std::make_unique(); + model->excluded->string_array = {"foo.bar"}; + + auto processor = builder.CreateAttributesProcessor(model); + ASSERT_NE(processor, nullptr); + auto filtered = processor->process(wildcard_iterable); + + EXPECT_EQ(filtered.size(), 2u); + EXPECT_NE(filtered.find("foo.baz"), filtered.end()); + EXPECT_NE(filtered.find("question.x"), filtered.end()); + } + // An exclude-only configuration retains every key that is not excluded. { auto model = std::make_unique(); From 2fb8fceb23b39ef016da12675d240a32afdce7a9 Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Mon, 10 Aug 2026 16:00:51 -0400 Subject: [PATCH 4/7] [CONFIGURATION] Move attribute processor to metrics view --- .../sdk/metrics/view/attributes_processor.h | 25 +++++++ sdk/src/configuration/sdk_builder.cc | 54 +-------------- sdk/src/metrics/BUILD | 1 + sdk/src/metrics/CMakeLists.txt | 1 + sdk/src/metrics/view/attributes_processor.cc | 67 +++++++++++++++++++ 5 files changed, 95 insertions(+), 53 deletions(-) create mode 100644 sdk/src/metrics/view/attributes_processor.cc diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index b4d5e61801..2a180194cd 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" @@ -162,6 +163,30 @@ class FilteringExcludeAttributesProcessor : public AttributesProcessor FilterAttributeMap exclude_list_; }; +/** + * IncludeExcludeAttributesProcessor filters attributes using wildcard include and exclude + * patterns. Exclude patterns take precedence over include patterns. + */ +class OPENTELEMETRY_EXPORT IncludeExcludeAttributesProcessor final : public AttributesProcessor +{ +public: + IncludeExcludeAttributesProcessor(bool include_all, + std::vector included_patterns, + std::vector excluded_patterns); + + MetricAttributes process( + const opentelemetry::common::KeyValueIterable &attributes) const noexcept override; + + bool isPresent(nostd::string_view key) const noexcept override; + +private: + static bool MatchesAny(const std::vector &patterns, nostd::string_view key) noexcept; + + bool include_all_; + std::vector included_patterns_; + std::vector excluded_patterns_; +}; + } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index 2fa8bf9c87..bc7b38a8c5 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -217,59 +217,6 @@ using common::WildcardMatch; namespace { -class IncludeExcludeAttributesProcessor final - : public opentelemetry::sdk::metrics::AttributesProcessor -{ -public: - IncludeExcludeAttributesProcessor(bool include_all, - std::vector included_patterns, - std::vector excluded_patterns) - : include_all_(include_all), - included_patterns_(std::move(included_patterns)), - excluded_patterns_(std::move(excluded_patterns)) - {} - - opentelemetry::sdk::metrics::MetricAttributes process( - const opentelemetry::common::KeyValueIterable &attributes) const noexcept override - { - opentelemetry::sdk::metrics::MetricAttributes result; - attributes.ForEachKeyValue( - [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { - if (isPresent(key)) - { - result.SetAttribute(key, value); - } - return true; - }); - - result.UpdateHash(); - return result; - } - - bool isPresent(nostd::string_view key) const noexcept override - { - return (include_all_ || MatchesAny(included_patterns_, key)) && - !MatchesAny(excluded_patterns_, key); - } - -private: - static bool MatchesAny(const std::vector &patterns, nostd::string_view key) noexcept - { - for (const auto &pattern : patterns) - { - if (WildcardMatch(pattern, key)) - { - return true; - } - } - return false; - } - - bool include_all_; - std::vector included_patterns_; - std::vector excluded_patterns_; -}; - static opentelemetry::logs::Severity ToLogSeverity( opentelemetry::sdk::configuration::SeverityNumber severity_number) { @@ -1949,6 +1896,7 @@ SdkBuilder::CreateAttributesProcessor( const { using opentelemetry::sdk::metrics::DefaultAttributesProcessor; + using opentelemetry::sdk::metrics::IncludeExcludeAttributesProcessor; if (model->included == nullptr && model->excluded == nullptr) { diff --git a/sdk/src/metrics/BUILD b/sdk/src/metrics/BUILD index be1bdc73de..c6c9bf1512 100644 --- a/sdk/src/metrics/BUILD +++ b/sdk/src/metrics/BUILD @@ -15,6 +15,7 @@ cc_library( "//sdk/src/common:disabled", "//sdk/src/common:global_log_handler", "//sdk/src/common:random", + "//sdk/src/common:wildcard_match", "//sdk/src/resource", ], ) diff --git a/sdk/src/metrics/CMakeLists.txt b/sdk/src/metrics/CMakeLists.txt index 1ced671f3a..588af0fcd6 100644 --- a/sdk/src/metrics/CMakeLists.txt +++ b/sdk/src/metrics/CMakeLists.txt @@ -30,6 +30,7 @@ add_library( aggregation/sum_aggregation.cc data/circular_buffer.cc exemplar/reservoir.cc + view/attributes_processor.cc view/instrument_selector_factory.cc view/meter_selector_factory.cc view/view_factory.cc diff --git a/sdk/src/metrics/view/attributes_processor.cc b/sdk/src/metrics/view/attributes_processor.cc new file mode 100644 index 0000000000..16dad4cb66 --- /dev/null +++ b/sdk/src/metrics/view/attributes_processor.cc @@ -0,0 +1,67 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" + +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" +#include "src/common/wildcard_match.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ + +IncludeExcludeAttributesProcessor::IncludeExcludeAttributesProcessor( + bool include_all, + std::vector included_patterns, + std::vector excluded_patterns) + : include_all_(include_all), + included_patterns_(std::move(included_patterns)), + excluded_patterns_(std::move(excluded_patterns)) +{} + +MetricAttributes IncludeExcludeAttributesProcessor::process( + const opentelemetry::common::KeyValueIterable &attributes) const noexcept +{ + MetricAttributes result; + attributes.ForEachKeyValue( + [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + if (isPresent(key)) + { + result.SetAttribute(key, value); + } + return true; + }); + + result.UpdateHash(); + return result; +} + +bool IncludeExcludeAttributesProcessor::isPresent(nostd::string_view key) const noexcept +{ + return (include_all_ || MatchesAny(included_patterns_, key)) && + !MatchesAny(excluded_patterns_, key); +} + +bool IncludeExcludeAttributesProcessor::MatchesAny(const std::vector &patterns, + nostd::string_view key) noexcept +{ + for (const auto &pattern : patterns) + { + if (common::WildcardMatch(pattern, key)) + { + return true; + } + } + return false; +} + +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From 918407675a344f163b999117c82594165922a875 Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Mon, 10 Aug 2026 16:41:04 -0400 Subject: [PATCH 5/7] [CONFIGURATION] Add direct include for attribute processor --- sdk/src/metrics/view/attributes_processor.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/src/metrics/view/attributes_processor.cc b/sdk/src/metrics/view/attributes_processor.cc index 16dad4cb66..fa60b0d691 100644 --- a/sdk/src/metrics/view/attributes_processor.cc +++ b/sdk/src/metrics/view/attributes_processor.cc @@ -7,6 +7,7 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" #include "src/common/wildcard_match.h" From 70480b53631a1288e402927cecbd5dd689743435 Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Mon, 10 Aug 2026 18:02:53 -0400 Subject: [PATCH 6/7] [CONFIGURATION] Preserve empty include defaults Assisted-by: Codex --- .../sdk/metrics/view/attributes_processor.h | 2 +- sdk/src/configuration/sdk_builder.cc | 2 +- sdk/test/configuration/yaml_metrics_test.cc | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index 2a180194cd..be51b28b7f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -182,7 +182,7 @@ class OPENTELEMETRY_EXPORT IncludeExcludeAttributesProcessor final : public Attr private: static bool MatchesAny(const std::vector &patterns, nostd::string_view key) noexcept; - bool include_all_; + bool include_all_{true}; std::vector included_patterns_; std::vector excluded_patterns_; }; diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index bc7b38a8c5..c759c9320b 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -1916,7 +1916,7 @@ SdkBuilder::CreateAttributesProcessor( } return std::make_unique( - model->included == nullptr, std::move(included_patterns), std::move(excluded_patterns)); + included_patterns.empty(), std::move(included_patterns), std::move(excluded_patterns)); } void SdkBuilder::AddView( diff --git a/sdk/test/configuration/yaml_metrics_test.cc b/sdk/test/configuration/yaml_metrics_test.cc index 1f7c607388..4d0b80b2d5 100644 --- a/sdk/test/configuration/yaml_metrics_test.cc +++ b/sdk/test/configuration/yaml_metrics_test.cc @@ -7,6 +7,7 @@ #include #include +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h" #include "opentelemetry/sdk/configuration/cardinality_limits_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" @@ -29,6 +30,8 @@ #include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" #include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/pull_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/sdk_builder.h" #include "opentelemetry/sdk/configuration/string_array_configuration.h" #include "opentelemetry/sdk/configuration/temporality_preference.h" #include "opentelemetry/sdk/configuration/translation_strategy.h" @@ -1225,6 +1228,48 @@ file_format: "1.0-metrics" ASSERT_EQ(view->stream->attribute_keys->excluded->string_array[1], "bar.ex"); } +class YamlMetricsEmptyIncluded : public ::testing::TestWithParam +{}; + +TEST_P(YamlMetricsEmptyIncluded, RetainsAllAttributes) +{ + std::string yaml = R"( +file_format: "1.0-metrics" +meter_provider: + readers: + - periodic: + exporter: + console: + views: + - selector: + stream: + attribute_keys: + included: )"; + yaml.append(GetParam()); + yaml.push_back('\n'); + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->meter_provider, nullptr); + ASSERT_EQ(config->meter_provider->views.size(), 1u); + auto &model = config->meter_provider->views[0]->stream->attribute_keys; + ASSERT_NE(model, nullptr); + ASSERT_NE(model->included, nullptr); + ASSERT_TRUE(model->included->string_array.empty()); + + std::map attributes = {{"first", 1}, {"second", 2}}; + opentelemetry::common::KeyValueIterableView> iterable(attributes); + opentelemetry::sdk::configuration::SdkBuilder builder( + std::make_shared()); + auto processor = builder.CreateAttributesProcessor(model); + ASSERT_NE(processor, nullptr); + + auto filtered = processor->process(iterable); + EXPECT_EQ(filtered.size(), attributes.size()); +} + +INSTANTIATE_TEST_SUITE_P(EmptyIncludedForms, YamlMetricsEmptyIncluded, ::testing::Values("[]", "")); + TEST(YamlMetrics, no_meter_configurator) { std::string yaml = R"( From ff61ccfbf26147e07c4206ca43ae714699decfdc Mon Sep 17 00:00:00 2001 From: Haseeb Nazir <36381672+iamhaseebn@users.noreply.github.com> Date: Tue, 11 Aug 2026 04:42:00 -0400 Subject: [PATCH 7/7] [CI] Fix IWYU include dependencies Assisted-by: Codex --- .../opentelemetry/sdk/metrics/view/attributes_processor.h | 2 +- sdk/test/configuration/yaml_metrics_test.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h index be51b28b7f..26294a99f2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h @@ -3,7 +3,6 @@ #pragma once -#include #include #include #include @@ -11,6 +10,7 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/custom_hash_equality.h" #include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h" diff --git a/sdk/test/configuration/yaml_metrics_test.cc b/sdk/test/configuration/yaml_metrics_test.cc index 4d0b80b2d5..89451f9fd3 100644 --- a/sdk/test/configuration/yaml_metrics_test.cc +++ b/sdk/test/configuration/yaml_metrics_test.cc @@ -8,6 +8,7 @@ #include #include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h" #include "opentelemetry/sdk/configuration/cardinality_limits_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" @@ -39,6 +40,7 @@ #include "opentelemetry/sdk/configuration/view_selector_configuration.h" #include "opentelemetry/sdk/configuration/view_stream_configuration.h" #include "opentelemetry/sdk/configuration/yaml_configuration_parser.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" static std::unique_ptr DoParse( const std::string &yaml)