1
1
package before_resolution
2
2
3
- yaml_schema_violation (description, group, attr) = violation {
4
- violation := {
5
- " id" : description,
6
- " type" : " semconv_attribute" ,
7
- " category" : " yaml_schema_violation" ,
8
- " attr" : attr,
9
- " group" : group,
10
- }
3
+ # checks attribute name format
4
+ deny[yaml_schema_violation (description, group.id, name)] {
5
+ group := input.groups[_]
6
+ attr := group.attributes[_]
7
+ name := attr.id
8
+
9
+ not regex.match (name_regex, name)
10
+
11
+ description := sprintf (" Attribute name '%s' is invalid. Attribute name %s" , [name, invalid_name_helper])
12
+ }
13
+
14
+ # checks metric name format
15
+ deny[yaml_schema_violation (description, group.id, name)] {
16
+ group := input.groups[_]
17
+ name := group.metric_name
18
+
19
+ name != null
20
+ not regex.match (name_regex, name)
21
+
22
+ description := sprintf (" Metric name '%s' is invalid. Metric name %s'" , [name, invalid_name_helper])
23
+ }
24
+
25
+ # checks event name format
26
+ deny[yaml_schema_violation (description, group.id, name)] {
27
+ group := input.groups[_]
28
+ group.type == " event"
29
+ name := group.name
30
+
31
+ name != null
32
+ not regex.match (name_regex, name)
33
+
34
+ description := sprintf (" Event name '%s' is invalid. Event name %s'" , [name, invalid_name_helper])
35
+ }
36
+
37
+ # checks attribute member id format
38
+ deny[yaml_schema_violation (description, group.id, attr_name)] {
39
+ group := input.groups[_]
40
+ attr := group.attributes[_]
41
+ attr_name := attr.id
42
+ name := attr.type.members[_].id
43
+
44
+ not regex.match (name_regex, name)
45
+
46
+ description := sprintf (" Member id '%s' on attribute '%s' is invalid. Member id %s'" , [name, attr_name, invalid_name_helper])
11
47
}
12
48
49
+ # check that attribute is fully qualified with their id, prefix is no longer supported
13
50
deny[yaml_schema_violation (description, group.id, " " )] {
14
51
group := input.groups[_]
15
52
@@ -19,3 +56,19 @@ deny[yaml_schema_violation(description, group.id, "")] {
19
56
# TODO (https://github.com/open-telemetry/weaver/issues/279): provide other violation properties once weaver supports it.
20
57
description := sprintf (" Group '%s' uses prefix '%s'. All attribute should be fully qualified with their id, prefix is no longer supported." , [group.id, group.prefix])
21
58
}
59
+
60
+ yaml_schema_violation (description, group, attr) = violation {
61
+ violation := {
62
+ " id" : description,
63
+ " type" : " semconv_attribute" ,
64
+ " category" : " yaml_schema_violation" ,
65
+ " attr" : attr,
66
+ " group" : group,
67
+ }
68
+ }
69
+
70
+ # not valid: '1foo.bar', 'foo.bar.', 'foo.bar_', 'foo..bar', 'foo._bar' ...
71
+ # valid: 'foo.bar', 'foo.1bar', 'foo.1_bar'
72
+ name_regex := " ^[a-z][a-z0-9]*([._][a-z0-9]+)*$"
73
+
74
+ invalid_name_helper := " must consist of lowercase alphanumeric characters separated by '_' and '.'"
0 commit comments