Skip to content

Commit 6394b02

Browse files
carrbspellaredXSAMdmathieuMrAlias
authored
semconv: Add metric generation (#4880)
* Adds some basic constants for metrics utilizing a new jinja template * Updates generated comments with more explicit nomenclature; Adds Unit and Description consts for each metric; append 'Name' to metric const instead of 'Key' * Update CHANGELOG * fix overlooked merge conflict * change the types of generated consts to string; format generation to handle empty stability and descriptions * trim trailing (repeated) periods in the description * manual formatting of some proper nouns; simplify the license header * update metrics file with concise generated license header * revert special formatting logic for JVM and ASPNETCore * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Damien Mathieu <[email protected]> --------- Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Sam Xie <[email protected]> Co-authored-by: Damien Mathieu <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 35c9570 commit 6394b02

File tree

4 files changed

+1123
-1
lines changed

4 files changed

+1123
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2626
- Add support for `AddLink` to `go.opentelemetry.io/otel/bridge/opencensus`. (#5116)
2727
- Add `String` method to `Value` and `KeyValue` in `go.opentelemetry.io/otel/log`. (#5117)
2828
- Add Exemplar support to `go.opentelemetry.io/otel/exporters/prometheus`. (#5111)
29+
- Add metric semantic conventions to `go.opentelemetry.io/otel/semconv/v1.24.0`. Future `semconv` packages will include metric semantic conventions as well. (#4528)
2930

3031
### Changed
3132

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ semconv-generate: | $(SEMCONVGEN) $(SEMCONVKIT)
280280
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
281281
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=event -p conventionType=event -f event.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
282282
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=resource -p conventionType=resource -f resource.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
283+
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=metric -f metric.go -t "$(SEMCONVPKG)/metric_template.j2" -s "$(TAG)"
283284
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"
284285

285286
.PHONY: gorelease
@@ -303,7 +304,7 @@ add-tags: | $(MULTIMOD)
303304
$(MULTIMOD) verify && $(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}
304305

305306
.PHONY: lint-markdown
306-
lint-markdown:
307+
lint-markdown:
307308
docker run -v "$(CURDIR):$(WORKDIR)" avtodev/markdown-lint:v1 -c $(WORKDIR)/.markdownlint.yaml $(WORKDIR)/**/*.md
308309

309310
.PHONY: verify-readmes

semconv/metric_template.j2

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{%- macro to_go_name(fqn) -%}
2+
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
3+
{%- endmacro -%}
4+
{%- macro it_reps(brief) -%}
5+
It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
6+
{{ brief[0]|lower }}{{ brief[1:] }}
7+
{%- else -%}
8+
the {{ brief[0]|lower }}{{ brief[1:] }}
9+
{%- endif -%}
10+
{%- endmacro -%}
11+
{%- macro keydoc(metric) -%}
12+
{%- if metric.stability|string() == "StabilityLevel.DEPRECATED" or not metric.brief-%}
13+
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
14+
{%- else -%}
15+
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
16+
{%- endif %}
17+
{%- endmacro -%}
18+
{%- macro format_stability(stability) -%}
19+
{%- if not stability -%}
20+
Experimental
21+
{%- else -%}
22+
{{ stability|replace("StabilityLevel.", "")|capitalize() }}
23+
{%- endif %}
24+
{%- endmacro -%}
25+
// Copyright The OpenTelemetry Authors
26+
// SPDX-License-Identifier: Apache-2.0
27+
28+
// Code generated from semantic convention specification. DO NOT EDIT.
29+
30+
package semconv // import [[IMPORTPATH]]
31+
32+
const (
33+
{% for id in semconvs %}
34+
{%- if semconvs[id].GROUP_TYPE_NAME == 'metric' %}{% set metric = semconvs[id] %}
35+
// {{ keydoc(metric) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
36+
// Instrument: {{ metric.instrument }}
37+
// Unit: {{ metric.unit }}
38+
// Stability: {{ format_stability(metric.stability) }}
39+
{%- if not metric.brief %}
40+
// NOTE: The description (brief) for this metric is not defined in the semantic-conventions repository.
41+
{%- endif %}
42+
{{to_go_name(metric.metric_name)}}Name = "{{metric.metric_name}}"
43+
{{to_go_name(metric.metric_name)}}Unit = "{{metric.unit}}"
44+
{%- if metric.brief %}
45+
{{to_go_name(metric.metric_name)}}Description = "{{metric.brief}}"
46+
{%- endif %}
47+
{%- endif %}
48+
{% endfor %}
49+
)

0 commit comments

Comments
 (0)