Skip to content

Commit 2d4c9dc

Browse files
authored
Add semconv/v1.32.0 (#6782)
- Add the new metric API package structure prototyped in https://github.com/MrAlias/semconv-go Prototypes of new metric API use: - MrAlias/opentelemetry-go-contrib#6136 - MrAlias/opentelemetry-go-contrib#6135 - MrAlias/opentelemetry-go-contrib#6134 - Generate `semconv/v1.32.0` - Drop the `kestrel` metric namespace as this is a Java specific technology ## [`v1.32.0` semantic convention release notes](https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.32.0): <div data-pjax="true" data-test-selector="body-content" data-view-component="true" class="markdown-body my-3"><p>📣 This release is the second release candidate for the Database Semantic Conventions, with <strong>db conventions stability planned to be declared in the subsequent release</strong>.</p> <h3>🛑 Breaking changes 🛑</h3> <ul> <li><code>device</code>: Change the definition of <code>device.id</code> and make it opt-in. (<a href="open-telemetry/semantic-conventions#1874" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1874/hovercard">#1874</a>, <a href="open-telemetry/semantic-conventions#1951" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1951/hovercard">#1951</a>)</li> <li><code>feature_flag</code>: Rename <code>evaluation</code> to <code>result</code> for feature flag evaluation result attributes (<a href="open-telemetry/semantic-conventions#1989" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1989/hovercard">#1989</a>)</li> </ul> <h3>🚀 New components 🚀</h3> <ul> <li><code>app</code>: Create <code>app.installation.id</code> attribute (<a href="open-telemetry/semantic-conventions#1874" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1874/hovercard">#1874</a>, <a href="open-telemetry/semantic-conventions#1897" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1897/hovercard">#1897</a>)</li> <li><code>cpython</code>: Add CPython runtime garbage collector metrics (<a href="open-telemetry/semantic-conventions#1930" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1930/hovercard">#1930</a>)</li> </ul> <h3>💡 Enhancements 💡</h3> <ul> <li><code>vcs</code>: Add owner and provider name to VCS attribute registry (<a href="open-telemetry/semantic-conventions#1452" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1452/hovercard">#1452</a>)</li> <li><code>vcs</code>: Remove fallback value for VCS provider name attribute (<a href="open-telemetry/semantic-conventions#2020" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2020/hovercard">#2020</a>)</li> <li><code>db</code>: Truncate <code>db.query.summary</code> to 255 characters if parsed from the query (<a href="open-telemetry/semantic-conventions#1978" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1978/hovercard">#1978</a>)</li> <li><code>db</code>: Normalize spaces in <code>db.operation.name</code> (if any) (<a href="open-telemetry/semantic-conventions#2028" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2028/hovercard">#2028</a>)</li> <li><code>db</code>: <code>db.operation.parameter.&lt;key&gt;</code> should not be captured for batch operations (<a href="open-telemetry/semantic-conventions#2026" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2026/hovercard">#2026</a>)</li> <li><code>db</code>: Add <code>db.stored_procedure.name</code> (<a href="open-telemetry/semantic-conventions#1491" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1491/hovercard">#1491</a>)</li> <li><code>gcp</code>: Adds GCP AppHub labels for resource. (<a href="open-telemetry/semantic-conventions#2006" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2006/hovercard">#2006</a>)</li> <li><code>error</code>: Add <code>error.message</code> property for human-readable error message on events. (<a href="open-telemetry/semantic-conventions#1992" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1992/hovercard">#1992</a>)</li> <li><code>profile</code>: Extend the list of known frame types with a value for Go and Rust (<a href="open-telemetry/semantic-conventions#2003" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2003/hovercard">#2003</a>)</li> <li><code>otel</code>: Adds SDK self-monitoring metrics for log processing (<a href="open-telemetry/semantic-conventions#1921" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1921/hovercard">#1921</a>)</li> </ul>
1 parent fe523bd commit 2d4c9dc

File tree

30 files changed

+32583
-47
lines changed

30 files changed

+32583
-47
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2222
- Add `Values` method to `HeaderCarrier` to implement the new `ValuesGetter` interface in `go.opentelemetry.io/otel/propagation`. (#5973)
2323
- Update `Baggage` in `go.opentelemetry.io/otel/propagation` to retrieve multiple values for a key when the carrier implements `ValuesGetter`. (#5973)
2424
- Add `AssertEqual` function in `go.opentelemetry.io/otel/log/logtest`. (#6662)
25+
- The `go.opentelemetry.io/otel/semconv/v1.32.0` package.
26+
The package contains semantic conventions from the `v1.32.0` version of the OpenTelemetry Semantic Conventions.
27+
See the [migration documentation](./semconv/v1.32.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.31.0`(#6782)
2528
- Add `Transform` option in `go.opentelemetry.io/otel/log/logtest`. (#6794)
2629

2730
### Removed

semconv/helpers.j2

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
{%- endfor -%}
1414
{%- endmacro -%}
1515

16-
{%- macro to_go_name(fqn) -%}
16+
{%- macro to_go_name(fqn="", pkg="") -%}
17+
{%- if pkg != "" -%}
18+
{%- set n = pkg | length -%}
19+
{%- if pkg == fqn[:n] -%}
20+
{%- set fqn = fqn[n:] -%}
21+
{%- if fqn[0] == "." or fqn[0] == "." -%}
22+
{%- set fqn = fqn[1:] -%}
23+
{%- endif -%}
24+
{%- endif -%}
25+
{%- endif -%}
1726
{{ repl(smart_title_case(fqn | replace(" ", "") | replace("_", ".") | acronym)) }}
1827
{%- endmacro -%}
1928

@@ -49,26 +58,30 @@ Examples: {{ attr.examples | trim("[]") }}
4958
{%- endfor -%}
5059
{%- endmacro -%}
5160

52-
{%- macro it_reps(brief) -%}
61+
{%- macro prefix_brief(brief, prefix="") -%}
5362
{%- set norms = [
54-
"MUST", "REQUIRED", "SHALL",
55-
"SHOULD", "RECOMMENDED",
56-
"MAY", "OPTIONAL"
63+
"MUST", "REQUIRED", "SHALL",
64+
"SHOULD", "RECOMMENDED",
65+
"MAY", "OPTIONAL"
5766
] -%}
58-
{%- set brief = brief | trim() | trim(".") -%}
67+
{%- set brief = brief | trim() -%}
5968
{%- if first_word(brief) is in norms -%}
6069
It {{ brief }}.
6170
{%- else -%}
62-
It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
63-
{{ lower_first(brief) }}.
71+
{{ prefix }} {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
72+
{{ lower_first(brief) | trim(".") }}.
6473
{%- else -%}
65-
the {{ lower_first(brief) }}.
74+
the {{ lower_first(brief) | trim(".") }}.
6675
{%- endif -%}
6776
{%- endif -%}
6877
{%- endmacro -%}
6978

70-
{%- macro keydoc(attr) -%}
71-
{{ to_go_name(attr.name) }}Key is the attribute Key conforming to the "{{ attr.name }}" semantic conventions. {{ it_reps(attr.brief) }}
79+
{%- macro it_reps(brief) -%}
80+
{{ prefix_brief(brief, "It represents") }}
81+
{%- endmacro -%}
82+
83+
{%- macro keydoc(attr, pkg="") -%}
84+
{{ to_go_name(attr.name, pkg) }}Key is the attribute Key conforming to the "{{ attr.name }}" semantic conventions. {{ it_reps(attr.brief) }}
7285

7386
{% if attr is enum -%}
7487
Type: Enum
@@ -82,7 +95,7 @@ Stability: {{ attr.stability | title }}
8295
{{ deprecated_doc(attr) }}
8396
{%- endmacro -%}
8497

85-
{%- macro generate_consts(group) -%}
98+
{%- macro generate_consts(group, pkg="") -%}
8699
{#- TODO: generate with group docs (i.e group by registry namespace) #}
87100

88101
{{ ["Namespace: " ~ group.root_namespace] | comment(format="go") }}
@@ -91,26 +104,26 @@ const (
91104
{#- TODO: Handle template attributes. #}
92105
{%- if not attribute.type is template_type %}
93106
{{ keydoc(attribute) | comment(format="go_1tab") }}
94-
{{to_go_name(attribute.name)}}Key = attribute.Key("{{attribute.name}}")
107+
{{to_go_name(attribute.name, pkg=pkg)}}Key = attribute.Key("{{attribute.name}}")
95108
{% endif -%}
96109
{%- endfor -%}
97110
)
98111
{%- endmacro -%}
99112

100-
{%- macro generate_funcs(group) -%}
113+
{%- macro generate_funcs(group, pkg="") -%}
101114
{%- for attribute in group.attributes if not attribute is enum %}
102115
{#- TODO: Handle template attributes. #}
103116
{%- if not attribute.type is template_type %}
104117

105-
{{ [to_go_name(attribute.name) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~ "\" semantic conventions. " ~ it_reps(attribute.brief) ] | comment(format="go") }}
106-
func {{to_go_name(attribute.name)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
107-
return {{to_go_name(attribute.name)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
118+
{{ [to_go_name(attribute.name, pkg) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~ "\" semantic conventions. " ~ it_reps(attribute.brief) ] | comment(format="go") }}
119+
func {{to_go_name(attribute.name, pkg)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
120+
return {{to_go_name(attribute.name, pkg)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
108121
}
109122
{%- endif %}
110123
{%- endfor %}
111124
{%- endmacro -%}
112125

113-
{%- macro generate_vars(group) -%}
126+
{%- macro generate_vars(group, pkg="") -%}
114127
{#- Render values for enums #}
115128
{%- for attribute in group.attributes %}
116129
{%- if attribute is enum %}
@@ -123,17 +136,47 @@ var (
123136
{%- else %}
124137
{{ [value.brief or value.id, "Stability: " ~ value.stability] | comment(format="go_1tab") }}
125138
{%- endif %}
126-
{{to_go_name(attribute.name ~ "." ~ value.id)}} = {{ to_go_name(attribute.name) }}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}({{ value.value | print_member_value }})
139+
{{to_go_name(attribute.name ~ "." ~ value.id, pkg=pkg)}} = {{ to_go_name(attribute.name, pkg=pkg) }}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}({{ value.value | print_member_value }})
127140
{%- endfor %}
128141
)
129142
{%- endif %}
130143
{%- endfor %}
131144
{%- endmacro -%}
132145

133-
{%- macro metric_keydoc(metric) -%}
146+
{%- macro metric_keydoc(metric, pkg="") -%}
134147
{%- if not metric.brief -%}
135-
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
148+
{{ to_go_name(metric.metric_name, pkg=pkg) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
136149
{%- else -%}
137-
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
150+
{{ to_go_name(metric.metric_name, pkg=pkg) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
138151
{%- endif %}
139152
{%- endmacro -%}
153+
154+
{%- macro metric_typedoc(metric, pkg="") -%}
155+
{%- if not metric.brief -%}
156+
{{ to_go_name(metric.metric_name, pkg=pkg) }} is an instrument used to record metric values conforming to the "{{ metric.metric_name}}" semantic conventions.
157+
{%- else -%}
158+
{{ to_go_name(metric.metric_name, pkg=pkg) }} is an instrument used to record metric values conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
159+
{%- endif %}
160+
{%- endmacro -%}
161+
162+
{%- macro member_type(member) %}
163+
{%- if member.value is string %}string{%- endif %}
164+
{%- if member.value is boolean %}bool{%- endif %}
165+
{%- if member.value is int %}int64{%- endif %}
166+
{%- if member.value is float %}float64{%- endif %}
167+
{%- endmacro %}
168+
169+
{%- macro attr_type(attribute) %}
170+
{%- if attribute.type is mapping %}
171+
{{- member_type(attribute.type.members[0]) }}
172+
{%- elif attribute.type == "template[boolean]" %}boolean
173+
{%- elif attribute.type == "template[int]" %}int
174+
{%- elif attribute.type == "template[double]" %}double
175+
{%- elif attribute.type == "template[string]" %}string
176+
{%- elif attribute.type == "template[boolean[]]" %}boolean[]
177+
{%- elif attribute.type == "template[int[]]" %}int[]
178+
{%- elif attribute.type == "template[double[]]" %}double[]
179+
{%- elif attribute.type == "template[string[]]" %}string[]
180+
{%- else %}{{ attribute.type | trim }}
181+
{%- endif %}
182+
{%- endmacro %}

semconv/instrument.j2

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
{% import 'helpers.j2' as h -%}
2+
3+
{%- macro instrument_default(metric) -%}
4+
{%- set ns = namespace(value="Int64", inst="unknown") -%}
5+
{%- set divisible = ["s", "ms"] -%}
6+
{%- if metric.unit is in divisible -%}
7+
{%- set ns.value="Float64" -%}
8+
{%- endif -%}
9+
{%- if metric.instrument == "counter" -%}
10+
{%- set ns.inst="Counter" -%}
11+
{%- elif metric.instrument == "updowncounter" -%}
12+
{%- set ns.inst="UpDownCounter" -%}
13+
{%- elif metric.instrument == "gauge" -%}
14+
{%- set ns.inst="Gauge" -%}
15+
{%- elif metric.instrument == "histogram" -%}
16+
{%- set ns.inst="Histogram" -%}
17+
{%- endif -%}
18+
{{ ns.value ~ ns.inst }}
19+
{%- endmacro -%}
20+
21+
{%- macro instrument(metric) -%}
22+
{{ metric.metric_name | map_text("instrument", instrument_default(metric)) }}
23+
{%- endmacro -%}
24+
25+
{%- macro value_type(metric) -%}
26+
{%- if instrument(metric)[:7] == "Float64" -%}
27+
Float64
28+
{%- else -%}
29+
Int64
30+
{%- endif -%}
31+
{%- endmacro -%}
32+
33+
{%- macro param_name(raw="", pkg="") -%}
34+
{%- set reserved = [
35+
"type", "break", "default", "func", "interface", "select", "case", "defer",
36+
"go", "map", "struct", "chan", "else", "goto", "const", "fallthrough", "if",
37+
"range", "type", "continue", "for", "import", "return", "var",
38+
]-%}
39+
{%- set name = raw -%}
40+
{%- if pkg != "" -%}
41+
{%- set n = pkg | length -%}
42+
{%- if pkg == name[:n] -%}
43+
{%- set name = name[n:] -%}
44+
{%- if name[0] == "." or name[0] == "." -%}
45+
{%- set name = name[1:] -%}
46+
{%- endif -%}
47+
{%- endif -%}
48+
{%- endif -%}
49+
{%- if name | lower is in reserved -%}
50+
{{ raw | camel_case }}
51+
{%- else -%}
52+
{{ name | camel_case }}
53+
{%- endif -%}
54+
{%- endmacro -%}
55+
56+
{%- macro params_docs(attrs, pkg="") -%}
57+
{%- set ns = namespace(output='') -%}
58+
{%- for attr in attrs | required | attribute_sort -%}
59+
{%- set ns.output = ns.output ~ "\n\nThe " ~ param_name(attr.name, pkg) ~ " is the " ~ h.lower_first(attr.brief) -%}
60+
{%- endfor -%}
61+
{%- if attrs | not_required | length > 0 -%}
62+
{%- set ns.output = ns.output ~ "\n\nAll additional attrs passed are included in the recorded value." -%}
63+
{%- endif -%}
64+
{%- if ns.output != "" -%}
65+
//
66+
{{ ns.output | comment }}
67+
{%- endif -%}
68+
{%- endmacro -%}
69+
70+
{%- macro param(attr, pkg="") -%}
71+
{%- if attr.type is mapping -%}
72+
{{ param_name(attr.name, pkg) }} {{ h.to_go_name(attr.name, pkg) }}Attr,
73+
{%- else -%}
74+
{{ param_name(attr.name, pkg) }} {{ attr.type | map_text("attribute_type_value")}},
75+
{%- endif -%}
76+
{%- endmacro -%}
77+
78+
{%- macro params(attrs, type="", pkg="", prefix="") -%}
79+
{%- for attr in attrs | required | attribute_sort -%}
80+
{{ prefix ~ param(attr, pkg) }}
81+
{% endfor -%}
82+
{{ prefix ~ "attrs ...attribute.KeyValue," }}
83+
{%- endmacro -%}
84+
85+
{%- macro to_attribute(attr, pkg="") -%}
86+
{%- if attr.type is mapping -%}
87+
attribute.{{ h.attr_type(attr) | map_text("attribute_type_method")}}("{{ attr.name }}", {{ h.member_type(attr.type.members[0]) }}({{ param_name(attr.name, pkg) }})),
88+
{%- else -%}
89+
attribute.{{ attr.type | map_text("attribute_type_method")}}("{{ attr.name }}", {{ param_name(attr.name, pkg) }}),
90+
{%- endif -%}
91+
{%- endmacro -%}
92+
93+
{%- macro with_attributes_opt(attrs, pkg="", prefix="") -%}
94+
{%- if attrs | length > 0 -%}
95+
{{ prefix }}metric.WithAttributes(
96+
{%- if attrs | required | length > 0 %}
97+
{{ prefix }} append(
98+
{{ prefix }} attrs,
99+
{%- for attr in attrs | required | attribute_sort %}
100+
{{ prefix }} {{ to_attribute(attr, pkg) }}
101+
{%- endfor %}
102+
{{ prefix }} )...,
103+
{%- else %}
104+
{{ prefix }} attrs...,
105+
{%- endif %}
106+
{{ prefix }}),
107+
{%- endif -%}
108+
{%- endmacro -%}
109+
110+
{%- macro add_method_with_optional(metric, inst, pkg="") -%}
111+
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
112+
{%- set req_attr = metric.attributes | required | attribute_sort -%}
113+
func (m {{ name }}) Add(
114+
ctx context.Context,
115+
incr {{ value_type(metric) | lower }},
116+
{{ params(metric.attributes, pkg=pkg, prefix="\t") }}
117+
) {
118+
o := addOptPool.Get().(*[]metric.AddOption)
119+
defer func() {
120+
*o = (*o)[:0]
121+
addOptPool.Put(o)
122+
}()
123+
124+
*o = append(
125+
*o,
126+
{{ with_attributes_opt(metric.attributes, pkg=pkg, prefix="\t\t") }}
127+
)
128+
129+
m.{{ inst }}.Add(ctx, incr, *o...)
130+
}
131+
{%- endmacro -%}
132+
133+
{%- macro add_method(metric, inst, pkg="") -%}
134+
135+
// Add adds incr to the existing count.
136+
{%- if metric.attributes | length > 0 %}
137+
{{ params_docs(metric.attributes, pkg=pkg) }}
138+
{%- if metric.note is defined %}
139+
//
140+
{{ metric.note | comment }}
141+
{%- endif %}
142+
{{ add_method_with_optional(metric, inst, pkg) }}
143+
{%- else %}
144+
{%- if metric.note is defined %}
145+
//
146+
{{ metric.note | comment }}
147+
{%- endif %}
148+
func (m {{ h.to_go_name(metric.metric_name, pkg) }}) Add(ctx context.Context, incr {{ value_type(metric) | lower }}, attrs ...attribute.KeyValue) {
149+
if len(attrs) == 0 {
150+
m.{{ inst }}.Add(ctx, incr)
151+
return
152+
}
153+
154+
o := addOptPool.Get().(*[]metric.AddOption)
155+
defer func() {
156+
*o = (*o)[:0]
157+
addOptPool.Put(o)
158+
}()
159+
160+
*o = append(*o, metric.WithAttributes(attrs...))
161+
m.{{ inst }}.Add(ctx, incr, *o...)
162+
}
163+
{%- endif -%}
164+
{%- endmacro -%}
165+
166+
{%- macro record_method_with_optional(metric, inst, pkg="") -%}
167+
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
168+
{%- set req_attr = metric.attributes | required | attribute_sort -%}
169+
func (m {{ name }}) Record(
170+
ctx context.Context,
171+
val {{ value_type(metric) | lower }},
172+
{{ params(metric.attributes, pkg=pkg, prefix="\t") }}
173+
) {
174+
o := recOptPool.Get().(*[]metric.RecordOption)
175+
defer func() {
176+
*o = (*o)[:0]
177+
recOptPool.Put(o)
178+
}()
179+
180+
*o = append(
181+
*o,
182+
{{ with_attributes_opt(metric.attributes, pkg=pkg, prefix="\t\t") }}
183+
)
184+
185+
m.{{ inst }}.Record(ctx, val, *o...)
186+
}
187+
{%- endmacro -%}
188+
189+
{%- macro record_method(metric, inst, pkg="") -%}
190+
191+
// Record records val to the current distribution.
192+
{%- if metric.attributes | length > 0 %}
193+
{{ params_docs(metric.attributes, pkg=pkg) }}
194+
{%- if metric.note is defined %}
195+
//
196+
{{ metric.note | comment }}
197+
{%- endif %}
198+
{{ record_method_with_optional(metric, inst, pkg) }}
199+
{%- else %}
200+
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
201+
{%- if metric.note is defined %}
202+
//
203+
{{ metric.note | comment }}
204+
{%- endif %}
205+
func (m {{ name }}) Record(ctx context.Context, val {{ value_type(metric) | lower }}, attrs ...attribute.KeyValue) {
206+
if len(attrs) == 0 {
207+
m.{{ inst }}.Record(ctx, val)
208+
}
209+
210+
o := recOptPool.Get().(*[]metric.RecordOption)
211+
defer func() {
212+
*o = (*o)[:0]
213+
recOptPool.Put(o)
214+
}()
215+
216+
*o = append(*o, metric.WithAttributes(attrs...))
217+
m.{{ inst }}.Record(ctx, val, *o...)
218+
}
219+
{%- endif -%}
220+
{%- endmacro -%}

0 commit comments

Comments
 (0)