-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathtemplate.j2
145 lines (136 loc) · 5.51 KB
/
template.j2
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{%- macro keyval_method(type) -%}
{%- if type == "string" -%}
String
{%- elif type == "string[]" -%}
StringSlice
{%- elif type == "int" -%}
Int
{%- elif type == "int[]" -%}
IntSlice
{%- elif type == "double" -%}
Float64
{%- elif type == "double[]" -%}
Float64Slice
{%- elif type == "boolean" -%}
Bool
{%- elif type == "boolean[]" -%}
BoolSlice
{%- endif -%}
{%- endmacro -%}
{%- macro to_go_attr_type(type, val) -%}
{{keyval_method(type)}}({% if type == "string" %}"{{val}}"{% else %}{{val}}{% endif %})
{%- endmacro -%}
{%- macro to_go_name(fqn) -%}
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
{%- endmacro -%}
{%- macro it_reps(brief) -%}
It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
{{ brief[0]|lower }}{{ brief[1:] }}
{%- else -%}
the {{ brief[0]|lower }}{{ brief[1:] }}
{%- endif -%}
{%- endmacro -%}
{%- macro keydoc(attr) -%}
{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" -%}
{{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions.
{%- else -%}
{{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
{%- endif %}
{%- endmacro -%}
{%- macro keydetails(attr) -%}
{%- if attr.attr_type is string %}
Type: {{ attr.attr_type }}
{%- else %}
Type: Enum
{%- endif %}
{%- if attr.requirement_level == RequirementLevel.REQUIRED %}
RequirementLevel: Required
{%- elif attr.requirement_level == RequirementLevel.CONDITIONALLY_REQUIRED %}
RequirementLevel: ConditionallyRequired
{%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %}
{%- elif attr.requirement_level == RequirementLevel.RECOMMENDED %}
RequirementLevel: Recommended
{%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %}
{%- else %}
RequirementLevel: Optional
{%- endif %}
{{ attr.stability | replace("Level.", ": ") | capitalize }}
{%- if attr.examples is iterable %}
Examples: {{ attr.examples | pprint | trim("[]") }}
{%- endif %}
{%- if attr.note %}
Note: {{ attr.note }}
{%- endif %}
{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" %}
Deprecated: {{ attr.brief | replace("Deprecated, ", "") }}
{%- endif %}
{%- endmacro -%}
{%- macro fndoc(attr) -%}
{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" -%}
// {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions.
Deprecated: {{ attr.brief | replace("Deprecated, ", "") }}
{%- else -%}
// {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
{%- endif %}
{%- endmacro -%}
{%- macro to_go_func(type, name) -%}
{%- if type == "string" -%}
func {{name}}(val string) attribute.KeyValue {
{%- elif type == "string[]" -%}
func {{name}}(val ...string) attribute.KeyValue {
{%- elif type == "int" -%}
func {{name}}(val int) attribute.KeyValue {
{%- elif type == "int[]" -%}
func {{name}}(val ...int) attribute.KeyValue {
{%- elif type == "double" -%}
func {{name}}(val float64) attribute.KeyValue {
{%- elif type == "double[]" -%}
func {{name}}(val ...float64) attribute.KeyValue {
{%- elif type == "boolean" -%}
func {{name}}(val bool) attribute.KeyValue {
{%- elif type == "boolean[]" -%}
func {{name}}(val ...bool) attribute.KeyValue {
{%- endif -%}
return {{name}}Key.{{keyval_method(type)}}(val)
}
{%- endmacro -%}
{%- macro sentence_case(text) -%}
{{ text[0]|upper}}{{text[1:] }}
{%- endmacro -%}
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Code generated from semantic convention specification. DO NOT EDIT.
package semconv // import [[IMPORTPATH]]
import "go.opentelemetry.io/otel/attribute"
{% for semconv in semconvs -%}
{%- if semconvs[semconv].attributes | rejectattr("ref") | rejectattr("deprecated") | selectattr("is_local") | sort(attribute=fqn) | length > 0 -%}
// {{ sentence_case(semconvs[semconv].brief | replace("This document defines ", "")) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
const (
{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated %}
// {{ keydoc(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
// {{ keydetails(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
{{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}")
{% endfor -%}
)
{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated -%}
{%- if attr.attr_type is not string %}
var (
{%- for val in attr.attr_type.members %}
// {{ val.brief | to_doc_brief }}
{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" %}
//
// Deprecated: {{ attr.brief | replace("Deprecated, ", "") | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
{%- endif %}
{{to_go_name("{}.{}".format(attr.fqn, val.member_id))}} = {{to_go_name(attr.fqn)}}Key.{{to_go_attr_type(attr.attr_type.enum_type, val.value)}}
{%- endfor %}
)
{%- endif -%}
{%- endfor %}
{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated -%}
{%- if attr.attr_type is string %}
{{ fndoc(attr) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
{{to_go_func(attr.attr_type, to_go_name(attr.fqn))}}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endfor -%}