@@ -51,3 +51,40 @@ TEST(AttributesProcessor, FilteringAllAttributesProcessor)
5151 auto filtered_attributes = attributes_processor.process (iterable);
5252 EXPECT_EQ (filter.size (), kNumFilterAttributes );
5353}
54+
55+ TEST (AttributesProcessor, FilteringExcludeAttributesProcessor)
56+ {
57+ std::unordered_map<std::string, bool > filter = {
58+ {" attr2" , true }, {" attr4" , true }, {" attr6" , true }};
59+ const int kNumAttributes = 7 ;
60+ std::string keys[kNumAttributes ] = {" attr1" , " attr2" , " attr3" , " attr4" ,
61+ " attr5" , " attr6" , " attr7" };
62+ int values[kNumAttributes ] = {10 , 20 , 30 , 40 , 50 , 60 , 70 };
63+ std::map<std::string, int > attributes = {
64+ {keys[0 ], values[0 ]}, {keys[1 ], values[1 ]}, {keys[2 ], values[2 ]}, {keys[3 ], values[3 ]},
65+ {keys[4 ], values[4 ]}, {keys[5 ], values[5 ]}, {keys[6 ], values[6 ]}};
66+ FilteringExcludeAttributesProcessor attributes_processor (filter);
67+ opentelemetry::common::KeyValueIterableView<std::map<std::string, int >> iterable (attributes);
68+ auto filtered_attributes = attributes_processor.process (iterable);
69+ for (auto &e : filtered_attributes)
70+ {
71+ EXPECT_TRUE (filter.find (e.first ) == filter.end ());
72+ }
73+ int expected_filtered_attributes_size = 4 ;
74+ EXPECT_EQ (filtered_attributes.size (), expected_filtered_attributes_size);
75+ }
76+
77+ TEST (AttributesProcessor, FilteringExcludeAllAttributesProcessor)
78+ {
79+ std::unordered_map<std::string, bool > filter = {};
80+ const int kNumAttributes = 6 ;
81+ std::string keys[kNumAttributes ] = {" attr1" , " attr2" , " attr3" , " attr4" , " attr5" , " attr6" };
82+ int values[kNumAttributes ] = {10 , 20 , 30 , 40 , 50 , 60 };
83+ std::map<std::string, int > attributes = {{keys[0 ], values[0 ]}, {keys[1 ], values[1 ]},
84+ {keys[2 ], values[2 ]}, {keys[3 ], values[3 ]},
85+ {keys[4 ], values[4 ]}, {keys[5 ], values[5 ]}};
86+ FilteringExcludeAttributesProcessor attributes_processor (filter);
87+ opentelemetry::common::KeyValueIterableView<std::map<std::string, int >> iterable (attributes);
88+ auto filtered_attributes = attributes_processor.process (iterable);
89+ EXPECT_EQ (filtered_attributes.size (), kNumAttributes );
90+ }
0 commit comments