@@ -108,3 +108,39 @@ def test_matches_rule_multiple_rules(self) -> None:
108108 },
109109 ]
110110 assert not matches_rule (rules_fail , span_attrs )
111+
112+ def test_match_key_filter_with_none_value (self ) -> None :
113+ """Test that match_key_filter handles None span_value gracefully."""
114+ # None span_value should return False for all match types
115+ assert not match_key_filter (None , "foo" , "strict" )
116+ assert not match_key_filter (None , "foo" , "contains" )
117+ assert not match_key_filter (None , "foo" , "startswith" )
118+ assert not match_key_filter (None , "foo" , "endswith" )
119+ assert not match_key_filter (None , "*" , "strict" )
120+
121+ def test_matches_rule_with_none_type_in_category (self ) -> None :
122+ """Test that matches_rule handles None type when checking category."""
123+ # When type is None, category check should not match
124+ span_attrs_none_type = {"type" : None }
125+ rule_category = [{"key" : "category" , "values" : ["databases" ]}]
126+ assert not matches_rule (rule_category , span_attrs_none_type )
127+
128+ # When type is missing, category check should not match
129+ span_attrs_no_type = {}
130+ assert not matches_rule (rule_category , span_attrs_no_type )
131+
132+ def test_matches_rule_with_none_attribute_value (self ) -> None :
133+ """Test that matches_rule handles None attribute values gracefully."""
134+ # When an attribute value is None, it should not match
135+ span_attrs = {"http.url" : None , "http.method" : "GET" }
136+
137+ rule_url = [
138+ {"key" : "http.url" , "values" : ["example.com" ], "match_type" : "contains" }
139+ ]
140+ assert not matches_rule (rule_url , span_attrs )
141+
142+ # But other attributes should still match
143+ rule_method = [
144+ {"key" : "http.method" , "values" : ["GET" ], "match_type" : "strict" }
145+ ]
146+ assert matches_rule (rule_method , span_attrs )
0 commit comments