1
- {% - macro to_go_attr_type (type , val ) -%}
1
+ {% - macro keyval_method (type ) -%}
2
2
{% - if type == "string" -%}
3
- String("{{val}}")
3
+ String
4
+ {% - elif type == "string[]" -%}
5
+ StringSlice
4
6
{% - elif type == "int" -%}
5
- Int({{val}})
7
+ Int
8
+ {% - elif type == "int[]" -%}
9
+ IntSlice
10
+ {% - elif type == "double" -%}
11
+ Float64
12
+ {% - elif type == "double[]" -%}
13
+ Float64Slice
14
+ {% - elif type == "boolean" -%}
15
+ Bool
16
+ {% - elif type == "boolean[]" -%}
17
+ BoolSlice
6
18
{% - endif -%}
7
19
{% - endmacro -%}
20
+ {% - macro to_go_attr_type (type , val ) -%}
21
+ {{keyval_method(type)}}({% if type == "string" %} "{{val}}"{% else %} {{val}}{% endif %} )
22
+ {% - endmacro -%}
8
23
{% - macro to_go_name (fqn ) -%}
9
24
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
10
25
{% - endmacro -%}
11
- {% - macro godoc (attr ) -%}
12
- {{ attr.brief }}
13
- //
26
+ {% - macro it_reps (brief ) -%}
27
+ It represents {% if brief [:2] == "A " or brief [:3] == "An " or brief [:4] == "The " -%}
28
+ {{ brief[0] |lower }}{{ brief[1:] }}
29
+ {% - else -%}
30
+ the {{ brief[0] |lower }}{{ brief[1:] }}
31
+ {% - endif -%}
32
+ {% - endmacro -%}
33
+ {% - macro keydoc (attr ) -%}
34
+ {{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
35
+ {% - endmacro -%}
36
+ {% - macro keydetails (attr ) -%}
14
37
{% - if attr .attr_type is string %}
15
38
Type: {{ attr.attr_type }}
16
39
{% - else %}
@@ -38,6 +61,33 @@ Examples: {{ attr.examples | pprint | trim("[]") }}
38
61
Note: {{ attr.note }}
39
62
{% - endif %}
40
63
{% - endmacro -%}
64
+ {% - macro fndoc (attr ) -%}
65
+ // {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
66
+ {% - endmacro -%}
67
+ {% - macro to_go_func (type , name ) -%}
68
+ {% - if type == "string" -%}
69
+ func {{name}}(val string) attribute.KeyValue {
70
+ {% - elif type == "string[]" -%}
71
+ func {{name}}(val ...string) attribute.KeyValue {
72
+ {% - elif type == "int" -%}
73
+ func {{name}}(val int) attribute.KeyValue {
74
+ {% - elif type == "int[]" -%}
75
+ func {{name}}(val ...int) attribute.KeyValue {
76
+ {% - elif type == "double" -%}
77
+ func {{name}}(val float64) attribute.KeyValue {
78
+ {% - elif type == "double[]" -%}
79
+ func {{name}}(val ...float64) attribute.KeyValue {
80
+ {% - elif type == "boolean" -%}
81
+ func {{name}}(val bool) attribute.KeyValue {
82
+ {% - elif type == "boolean[]" -%}
83
+ func {{name}}(val ...bool) attribute.KeyValue {
84
+ {% - endif -%}
85
+ return {{name}}Key.{{keyval_method(type)}}(val)
86
+ }
87
+ {% - endmacro -%}
88
+ {% - macro sentence_case (text ) -%}
89
+ {{ text[0] |upper}}{{text[1:] }}
90
+ {% - endmacro -%}
41
91
// Copyright The OpenTelemetry Authors
42
92
//
43
93
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -60,12 +110,13 @@ import "go.opentelemetry.io/otel/attribute"
60
110
61
111
{% for semconv in semconvs -%}
62
112
{% - if semconvs [semconv ].attributes | rejectattr ("ref" ) | selectattr ("is_local" ) | sort (attribute =fqn ) | length > 0 -%}
63
- // {{ semconvs[semconv] .brief }}
113
+ // {{ sentence_case( semconvs[semconv] .brief | replace("This document defines ", "")) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
64
114
const (
65
- {% for attr in semconvs [semconv ].attributes if attr .is_local and not attr .ref -%}
66
- // {{ godoc(attr) | wordwrap | indent(3) | replace(" ", "\t// ") | replace("// //", "//") }}
67
- {{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}")
68
- {% endfor %}
115
+ {% - for attr in semconvs [semconv ].attributes if attr .is_local and not attr .ref %}
116
+ // {{ keydoc(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
117
+ // {{ keydetails(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
118
+ {{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}")
119
+ {% endfor -%}
69
120
)
70
121
{% - for attr in semconvs [semconv ].attributes if attr .is_local and not attr .ref -%}
71
122
{% - if attr .attr_type is not string %}
@@ -78,6 +129,13 @@ var (
78
129
)
79
130
{% - endif -%}
80
131
{% - endfor %}
132
+ {% - for attr in semconvs [semconv ].attributes if attr .is_local and not attr .ref -%}
133
+ {% - if attr .attr_type is string %}
134
+
135
+ {{ fndoc(attr) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
136
+ {{to_go_func(attr.attr_type, to_go_name(attr.fqn))}}
137
+ {% - endif -%}
138
+ {% - endfor %}
81
139
82
140
{% endif %}
83
141
{% endfor -%}
0 commit comments