-
Notifications
You must be signed in to change notification settings - Fork 19
/
semconv.jq
106 lines (94 loc) · 4.58 KB
/
semconv.jq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Groups the attributes by their root namespace and sorts them by name.
def semconv_group_attributes_by_root_namespace:
group_by(.root_namespace)
| map({ root_namespace: .[0].root_namespace, attributes: . | sort_by(.name) });
#####################
# Attribute functions
#####################
# Extracts and processes semantic convention attributes based on provided options.
# $options is an object that can contain:
# - exclude_stability: a list of stability statuses to exclude.
# - exclude_deprecated: a boolean to exclude deprecated attributes.
# - exclude_root_namespace: a list of root namespaces to exclude.
def semconv_attributes($options):
.groups
| map(select(.type == "attribute_group" and (.id | startswith("registry."))))
| map(.attributes) | add
| if ($options | has("exclude_stability")) then
map(select(.stability as $st | $options.exclude_stability | index($st) | not))
else
.
end
| if ($options | has("exclude_deprecated") and $options.exclude_deprecated == true) then
map(select(has("deprecated") | not))
else
.
end
| map(. + {root_namespace: (if .name | index(".") then .name | split(".")[0] else "other" end)})
| if ($options | has("exclude_root_namespace")) then
map(select(.root_namespace as $st | $options.exclude_root_namespace | index($st) | not))
else
.
end
| sort_by(.root_namespace, .name);
# Convenience function to extract all attributes without any filtering options.
def semconv_attributes: semconv_attributes({});
# Groups the processed attributes by their root namespace based on provided options.
# $options is an object that can contain:
# - exclude_stability: a list of stability statuses to exclude.
# - exclude_deprecated: a boolean to exclude deprecated attributes.
# - exclude_root_namespace: a list of root namespaces to exclude.
def semconv_grouped_attributes($options):
semconv_attributes($options)
| semconv_group_attributes_by_root_namespace;
# Convenience function to group all attributes by their root namespace without
# any filtering options.
def semconv_grouped_attributes: semconv_grouped_attributes({});
# Generic Signal Functions
# Extracts and processes semantic convention signals based on provided options.
# $signal is the type of signal to process.
# $options is an object that can contain:
# - exclude_stability: a list of stability statuses to exclude.
# - exclude_deprecated: a boolean to exclude deprecated signals.
# - exclude_root_namespace: a list of root namespaces to exclude.
def semconv_signal($signal; $options):
.groups
| map(select(.type == $signal))
| if ($options | has("exclude_stability")) then
map(select(.stability as $st | $options.exclude_stability | index($st) | not))
else
.
end
| if ($options | has("exclude_deprecated") and $options.exclude_deprecated == true) then
map(select(.id | endswith(".deprecated") | not))
else
.
end
| map(. + {root_namespace: (if .id | index(".") then .id | split(".") | .[1] else "other" end)})
| if ($options | has("exclude_root_namespace")) then
map(select(.root_namespace as $st | $options.exclude_root_namespace | index($st) | not))
else
.
end
| sort_by(.root_namespace);
# Metric Functions
# Groups the metrics by their root namespace and sorts metrics by metric_name.
def semconv_group_metrics_by_root_namespace:
group_by(.root_namespace)
| map({ root_namespace: .[0].root_namespace, metrics: . | sort_by(.metric_name) });
# Extracts and processes semantic convention metrics based on provided options.
# $options is an object that can contain:
# - exclude_stability: a list of stability statuses to exclude.
# - exclude_deprecated: a boolean to exclude deprecated metrics.
# - exclude_root_namespace: a list of root namespaces to exclude.
def semconv_metrics($options): semconv_signal("metric"; $options);
# Convenience function to extract all metrics without any filtering options.
def semconv_metrics: semconv_metrics({});
# Groups the processed metrics by their root namespace based on provided options.
# $options is an object that can contain:
# - exclude_stability: a list of stability statuses to exclude.
# - exclude_deprecated: a boolean to exclude deprecated metrics.
# - exclude_root_namespace: a list of root namespaces to exclude.
def semconv_grouped_metrics($options): semconv_metrics($options) | semconv_group_metrics_by_root_namespace;
# Convenience function to group all metrics by their root namespace without any filtering options.
def semconv_grouped_metrics: semconv_grouped_metrics({});