1
1
package after_resolution
2
2
3
+ # Data structures to make checking things faster.
4
+ attribute_names := { data |
5
+ group := input.groups[_]
6
+ attr := group.attributes[_]
7
+ data := { " name" : attr.name, " const_name" : to_const_name (attr.name), " namespace_prefix" : to_namespace_prefix (attr.name) }
8
+ }
9
+
10
+
3
11
deny[attr_registry_collision (description, name)] {
4
- names := attr_names_except (excluded_const_collisions)
5
- name := names[_]
6
- const_name := to_const_name (name)
7
- collisions:= { n | n := attr_names_except (excluded_const_collisions)[_]; n != name; to_const_name (n) == const_name }
12
+ some i
13
+ name := attribute_names[i].name
14
+ const_name := attribute_names[i].const_name
15
+ not excluded_const_collisions[name]
16
+ collisions := [other.name |
17
+ other := attribute_names[_]
18
+ other.name != name
19
+ other.const_name == const_name
20
+ not excluded_const_collisions[other.name]
21
+ ]
8
22
count (collisions) > 0
9
-
10
23
# TODO (https://github.com/open-telemetry/weaver/issues/279): provide other violation properties once weaver supports it.
11
24
description := sprintf (" Attribute '%s' has the same constant name '%s' as '%s'." , [name, const_name, collisions])
12
25
}
13
26
14
27
deny[attr_registry_collision (description, name)] {
15
- names := attr_names_except (excluded_namespace_collisions)
16
- name := names[_]
17
-
18
- collisions:= { n | n := input.groups[_].attributes[_].name; startswith (n, to_namespace_prefix (name)) }
28
+ some i
29
+ name := attribute_names[i].name
30
+ prefix := attribute_names[i].namespace_prefix
31
+ not excluded_namespace_collisions[name]
32
+ collisions := [other.name |
33
+ other := attribute_names[_]
34
+ other.name != name
35
+ startswith (other.name, prefix)
36
+ ]
19
37
count (collisions) > 0
20
-
21
38
# TODO (https://github.com/open-telemetry/weaver/issues/279): provide other violation properties once weaver supports it.
22
- description := sprintf (" Attribute '%s' name is used as a namespace in the following attributes '%s'." , [name, collisions])
39
+ description := sprintf (" Attribute '%s' is used as a namespace in '%s'." , [name, collisions])
23
40
}
24
41
25
42
attr_registry_collision (description, attr_name) = violation {
@@ -40,10 +57,6 @@ to_const_name(name) = const_name {
40
57
const_name := replace (name, " ." , " _" )
41
58
}
42
59
43
- attr_names_except (excluded) = names {
44
- names := { n | n := input.groups[_].attributes[_].name } - excluded
45
- }
46
-
47
60
# These lists contain exceptions for existing collisions that were introduced unintentionally.
48
61
# We'll have a way to specify how collision resolution happens in the schema -
49
62
# see phase 2 in https://github.com/open-telemetry/semantic-conventions/issues/1118#issuecomment-2173803006
0 commit comments