Skip to content

Commit

Permalink
semconv: Add metric generation (#4880)
Browse files Browse the repository at this point in the history
* 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 <42@dmathieu.com>

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Sam Xie <sam@samxie.me>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
5 people authored Apr 4, 2024
1 parent 35c9570 commit 6394b02
Show file tree
Hide file tree
Showing 4 changed files with 1,123 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add support for `AddLink` to `go.opentelemetry.io/otel/bridge/opencensus`. (#5116)
- Add `String` method to `Value` and `KeyValue` in `go.opentelemetry.io/otel/log`. (#5117)
- Add Exemplar support to `go.opentelemetry.io/otel/exporters/prometheus`. (#5111)
- Add metric semantic conventions to `go.opentelemetry.io/otel/semconv/v1.24.0`. Future `semconv` packages will include metric semantic conventions as well. (#4528)

### Changed

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ semconv-generate: | $(SEMCONVGEN) $(SEMCONVKIT)
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=event -p conventionType=event -f event.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=resource -p conventionType=resource -f resource.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=metric -f metric.go -t "$(SEMCONVPKG)/metric_template.j2" -s "$(TAG)"
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"

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

.PHONY: lint-markdown
lint-markdown:
lint-markdown:
docker run -v "$(CURDIR):$(WORKDIR)" avtodev/markdown-lint:v1 -c $(WORKDIR)/.markdownlint.yaml $(WORKDIR)/**/*.md

.PHONY: verify-readmes
Expand Down
49 changes: 49 additions & 0 deletions semconv/metric_template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{%- 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(metric) -%}
{%- if metric.stability|string() == "StabilityLevel.DEPRECATED" or not metric.brief-%}
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
{%- else -%}
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
{%- endif %}
{%- endmacro -%}
{%- macro format_stability(stability) -%}
{%- if not stability -%}
Experimental
{%- else -%}
{{ stability|replace("StabilityLevel.", "")|capitalize() }}
{%- endif %}
{%- endmacro -%}
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Code generated from semantic convention specification. DO NOT EDIT.

package semconv // import [[IMPORTPATH]]

const (
{% for id in semconvs %}
{%- if semconvs[id].GROUP_TYPE_NAME == 'metric' %}{% set metric = semconvs[id] %}
// {{ keydoc(metric) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
// Instrument: {{ metric.instrument }}
// Unit: {{ metric.unit }}
// Stability: {{ format_stability(metric.stability) }}
{%- if not metric.brief %}
// NOTE: The description (brief) for this metric is not defined in the semantic-conventions repository.
{%- endif %}
{{to_go_name(metric.metric_name)}}Name = "{{metric.metric_name}}"
{{to_go_name(metric.metric_name)}}Unit = "{{metric.unit}}"
{%- if metric.brief %}
{{to_go_name(metric.metric_name)}}Description = "{{metric.brief}}"
{%- endif %}
{%- endif %}
{% endfor %}
)
Loading

0 comments on commit 6394b02

Please sign in to comment.