Skip to content

Commit 8324155

Browse files
authored
Builds off of open-telemetry#5793 Resolve open-telemetry#5668 This migrates the generation of our semconv packages from using the `semconvgen` tooling to the new [`weaver`](https://github.com/open-telemetry/weaver) project. The configuration and templating has been added in a way to generate as close as we can to what the `semconvgen` tooling already generated. There are notable differences: ### Acronym/Initialism Fixes As metioned [here](open-telemetry#5898 (comment)), the evaluated exported output of regenerating the `semconv/v1.27.0` package resulted in the following changes: | `weaver` | `semconvgen` | | --- | --- | | ASPNETCoreDiagnosticsExceptionsDescription | AspnetcoreDiagnosticsExceptionsDescription| | ASPNETCoreDiagnosticsExceptionsName | AspnetcoreDiagnosticsExceptionsName| | ASPNETCoreDiagnosticsExceptionsUnit | AspnetcoreDiagnosticsExceptionsUnit| | ASPNETCoreRateLimitingActiveRequestLeasesDescription | AspnetcoreRateLimitingActiveRequestLeasesDescription| | ASPNETCoreRateLimitingActiveRequestLeasesName | AspnetcoreRateLimitingActiveRequestLeasesName| | ASPNETCoreRateLimitingActiveRequestLeasesUnit | AspnetcoreRateLimitingActiveRequestLeasesUnit| | ASPNETCoreRateLimitingQueuedRequestsDescription | AspnetcoreRateLimitingQueuedRequestsDescription| | ASPNETCoreRateLimitingQueuedRequestsName | AspnetcoreRateLimitingQueuedRequestsName| | ASPNETCoreRateLimitingQueuedRequestsUnit | AspnetcoreRateLimitingQueuedRequestsUnit| | ASPNETCoreRateLimitingRequestLeaseDurationDescription | AspnetcoreRateLimitingRequestLeaseDurationDescription| | ASPNETCoreRateLimitingRequestLeaseDurationName | AspnetcoreRateLimitingRequestLeaseDurationName| | ASPNETCoreRateLimitingRequestLeaseDurationUnit | AspnetcoreRateLimitingRequestLeaseDurationUnit| | ASPNETCoreRateLimitingRequestTimeInQueueDescription | AspnetcoreRateLimitingRequestTimeInQueueDescription| | ASPNETCoreRateLimitingRequestTimeInQueueName | AspnetcoreRateLimitingRequestTimeInQueueName| | ASPNETCoreRateLimitingRequestTimeInQueueUnit | AspnetcoreRateLimitingRequestTimeInQueueUnit| | ASPNETCoreRateLimitingRequestsDescription | AspnetcoreRateLimitingRequestsDescription| | ASPNETCoreRateLimitingRequestsName | AspnetcoreRateLimitingRequestsName| | ASPNETCoreRateLimitingRequestsUnit | AspnetcoreRateLimitingRequestsUnit| | ASPNETCoreRoutingMatchAttemptsDescription | AspnetcoreRoutingMatchAttemptsDescription| | ASPNETCoreRoutingMatchAttemptsName | AspnetcoreRoutingMatchAttemptsName| | ASPNETCoreRoutingMatchAttemptsUnit | AspnetcoreRoutingMatchAttemptsUnit| | DBSystemDb2 | DBSystemDB2| | GenAIClientOperationDurationDescription | GenAiClientOperationDurationDescription| | GenAIClientOperationDurationName | GenAiClientOperationDurationName| | GenAIClientOperationDurationUnit | GenAiClientOperationDurationUnit| | GenAIClientTokenUsageDescription | GenAiClientTokenUsageDescription| | GenAIClientTokenUsageName | GenAiClientTokenUsageName| | GenAIClientTokenUsageUnit | GenAiClientTokenUsageUnit| | GenAIServerRequestDurationDescription | GenAiServerRequestDurationDescription| | GenAIServerRequestDurationName | GenAiServerRequestDurationName| | GenAIServerRequestDurationUnit | GenAiServerRequestDurationUnit| | GenAIServerTimePerOutputTokenDescription | GenAiServerTimePerOutputTokenDescription| | GenAIServerTimePerOutputTokenName | GenAiServerTimePerOutputTokenName| | GenAIServerTimePerOutputTokenUnit | GenAiServerTimePerOutputTokenUnit| | GenAIServerTimeToFirstTokenDescription | GenAiServerTimeToFirstTokenDescription| | GenAIServerTimeToFirstTokenName | GenAiServerTimeToFirstTokenName| | GenAIServerTimeToFirstTokenUnit | GenAiServerTimeToFirstTokenUnit| | GoMemoryGCGoalDescription | GoMemoryGcGoalDescription| | GoMemoryGCGoalName | GoMemoryGcGoalName| | GoMemoryGCGoalUnit | GoMemoryGcGoalUnit| | JVMBufferCountDescription | JvmBufferCountDescription| | JVMBufferCountName | JvmBufferCountName| | JVMBufferCountUnit | JvmBufferCountUnit| | JVMBufferMemoryLimitDescription | JvmBufferMemoryLimitDescription| | JVMBufferMemoryLimitName | JvmBufferMemoryLimitName| | JVMBufferMemoryLimitUnit | JvmBufferMemoryLimitUnit| | JVMBufferMemoryUsageDescription | JvmBufferMemoryUsageDescription| | JVMBufferMemoryUsageName | JvmBufferMemoryUsageName| | JVMBufferMemoryUsageUnit | JvmBufferMemoryUsageUnit| | JVMBufferMemoryUsedDescription | JvmBufferMemoryUsedDescription| | JVMBufferMemoryUsedName | JvmBufferMemoryUsedName| | JVMBufferMemoryUsedUnit | JvmBufferMemoryUsedUnit| | JVMCPUCountDescription | JvmCPUCountDescription| | JVMCPUCountName | JvmCPUCountName| | JVMCPUCountUnit | JvmCPUCountUnit| | JVMCPURecentUtilizationDescription | JvmCPURecentUtilizationDescription| | JVMCPURecentUtilizationName | JvmCPURecentUtilizationName| | JVMCPURecentUtilizationUnit | JvmCPURecentUtilizationUnit| | JVMCPUTimeDescription | JvmCPUTimeDescription| | JVMCPUTimeName | JvmCPUTimeName| | JVMCPUTimeUnit | JvmCPUTimeUnit| | JVMClassCountDescription | JvmClassCountDescription| | JVMClassCountName | JvmClassCountName| | JVMClassCountUnit | JvmClassCountUnit| | JVMClassLoadedDescription | JvmClassLoadedDescription| | JVMClassLoadedName | JvmClassLoadedName| | JVMClassLoadedUnit | JvmClassLoadedUnit| | JVMClassUnloadedDescription | JvmClassUnloadedDescription| | JVMClassUnloadedName | JvmClassUnloadedName| | JVMClassUnloadedUnit | JvmClassUnloadedUnit| | JVMGCDurationDescription | JvmGcDurationDescription| | JVMGCDurationName | JvmGcDurationName| | JVMGCDurationUnit | JvmGcDurationUnit| | JVMMemoryCommittedDescription | JvmMemoryCommittedDescription| | JVMMemoryCommittedName | JvmMemoryCommittedName| | JVMMemoryCommittedUnit | JvmMemoryCommittedUnit| | JVMMemoryInitDescription | JvmMemoryInitDescription| | JVMMemoryInitName | JvmMemoryInitName| | JVMMemoryInitUnit | JvmMemoryInitUnit| | JVMMemoryLimitDescription | JvmMemoryLimitDescription| | JVMMemoryLimitName | JvmMemoryLimitName| | JVMMemoryLimitUnit | JvmMemoryLimitUnit| | JVMMemoryUsedAfterLastGCDescription | JvmMemoryUsedAfterLastGcDescription| | JVMMemoryUsedAfterLastGCName | JvmMemoryUsedAfterLastGcName| | JVMMemoryUsedAfterLastGCUnit | JvmMemoryUsedAfterLastGcUnit| | JVMMemoryUsedDescription | JvmMemoryUsedDescription| | JVMMemoryUsedName | JvmMemoryUsedName| | JVMMemoryUsedUnit | JvmMemoryUsedUnit| | JVMSystemCPULoad1mDescription | JvmSystemCPULoad1mDescription| | JVMSystemCPULoad1mName | JvmSystemCPULoad1mName| | JVMSystemCPULoad1mUnit | JvmSystemCPULoad1mUnit| | JVMSystemCPUUtilizationDescription | JvmSystemCPUUtilizationDescription| | JVMSystemCPUUtilizationName | JvmSystemCPUUtilizationName| | JVMSystemCPUUtilizationUnit | JvmSystemCPUUtilizationUnit| | JVMThreadCountDescription | JvmThreadCountDescription| | JVMThreadCountName | JvmThreadCountName| | JVMThreadCountUnit | JvmThreadCountUnit| | V8JSGCDurationDescription | V8jsGcDurationDescription| | V8JSGCDurationName | V8jsGcDurationName| | V8JSGCDurationUnit | V8jsGcDurationUnit| | V8JSHeapSpaceAvailableSizeDescription | V8jsHeapSpaceAvailableSizeDescription| | V8JSHeapSpaceAvailableSizeName | V8jsHeapSpaceAvailableSizeName| | V8JSHeapSpaceAvailableSizeUnit | V8jsHeapSpaceAvailableSizeUnit| | V8JSHeapSpacePhysicalSizeDescription | V8jsHeapSpacePhysicalSizeDescription| | V8JSHeapSpacePhysicalSizeName | V8jsHeapSpacePhysicalSizeName| | V8JSHeapSpacePhysicalSizeUnit | V8jsHeapSpacePhysicalSizeUnit| | V8JSMemoryHeapLimitDescription | V8jsMemoryHeapLimitDescription| | V8JSMemoryHeapLimitName | V8jsMemoryHeapLimitName| | V8JSMemoryHeapLimitUnit | V8jsMemoryHeapLimitUnit| | V8JSMemoryHeapUsedDescription | V8jsMemoryHeapUsedDescription| | V8JSMemoryHeapUsedName | V8jsMemoryHeapUsedName| | V8JSMemoryHeapUsedUnit | V8jsMemoryHeapUsedUnit| An audit of these changes leads to the conclusion that they are appropriate fixes to things that were mis-named. ### Doc changes Also mentioned [here](open-telemetry#5898 (comment)), there documentation changes that are included. Mostly this is unavoidable based on the new format of the semconv models, and effort has spent ensuring nothing substantive is lost. See the reverted commit open-telemetry@66523cb for the details of how the `semconv/v1.27.0` changes. ## Next Steps This PR has been paired down to migrate tooling. The next steps are to generate `semconv/v1.28.0` with desired changes (i.e. maybe we don't generate `ASPCoreNet` attrs(?)). From there the missing semconv packages will be generated. - open-telemetry#6226 - open-telemetry#6227
1 parent a81250c commit 8324155

10 files changed

+342
-208
lines changed

Makefile

+23-4
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,32 @@ check-clean-work-tree:
269269
exit 1; \
270270
fi
271271

272+
# The weaver docker image to use for semconv-generate.
273+
WEAVER_IMAGE := $(shell awk '$$4=="weaver" {print $$2}' $(DEPENDENCIES_DOCKERFILE))
274+
272275
SEMCONVPKG ?= "semconv/"
273276
.PHONY: semconv-generate
274-
semconv-generate: $(SEMCONVGEN) $(SEMCONVKIT)
277+
semconv-generate: $(SEMCONVKIT)
275278
[ "$(TAG)" ] || ( echo "TAG unset: missing opentelemetry semantic-conventions tag"; exit 1 )
276-
[ "$(OTEL_SEMCONV_REPO)" ] || ( echo "OTEL_SEMCONV_REPO unset: missing path to opentelemetry semantic-conventions repo"; exit 1 )
277-
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -z "$(SEMCONVPKG)/capitalizations.txt" -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
278-
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=metric -f metric.go -t "$(SEMCONVPKG)/metric_template.j2" -s "$(TAG)"
279+
[ "$(SEMCONV_REPO)" ] || ( echo "SEMCONV_REPO unset: missing path to opentelemetry semantic-conventions repo"; exit 1 )
280+
# Ensure the target directory for source code is available.
281+
mkdir -p $(PWD)/$(SEMCONVPKG)/${TAG}
282+
# Note: We mount a home directory for downloading/storing the semconv repository.
283+
# Weaver will automatically clean the cache when finished, but the directories will remain.
284+
mkdir -p ~/.weaver
285+
docker run --rm \
286+
-u $(DOCKER_USER) \
287+
--env HOME=/tmp/weaver \
288+
--mount 'type=bind,source=$(SEMCONV_REPO),target=/source,readonly' \
289+
--mount 'type=bind,source=$(PWD)/semconv,target=/home/weaver/templates/registry/go,readonly' \
290+
--mount 'type=bind,source=$(PWD)/semconv/${TAG},target=/home/weaver/target' \
291+
--mount 'type=bind,source=$(HOME)/.weaver,target=/tmp/weaver/.weaver' \
292+
$(WEAVER_IMAGE) registry generate \
293+
--registry=/source/model \
294+
--templates=/home/weaver/templates \
295+
--param tag=$(TAG) \
296+
go \
297+
/home/weaver/target
279298
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"
280299

281300
.PHONY: gorelease

RELEASING.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ New versions of the [OpenTelemetry Semantic Conventions] mean new versions of th
66
The `semconv-generate` make target is used for this.
77

88
1. Checkout a local copy of the [OpenTelemetry Semantic Conventions] to the desired release tag.
9-
2. Pull the latest `otel/semconvgen` image: `docker pull otel/semconvgen:latest`
10-
3. Run the `make semconv-generate ...` target from this repository.
9+
2. Run the `make semconv-generate ...` target from this repository.
1110

1211
For example,
1312

1413
```sh
1514
export TAG="v1.21.0" # Change to the release version you are generating.
1615
export OTEL_SEMCONV_REPO="/absolute/path/to/opentelemetry/semantic-conventions"
17-
docker pull otel/semconvgen:latest
1816
make semconv-generate # Uses the exported TAG and OTEL_SEMCONV_REPO.
1917
```
2018

dependencies.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# This is a renovate-friendly source of Docker images.
22
FROM python:3.13.1-slim-bullseye AS python
3+
FROM otel/weaver:v0.12.0 AS weaver

semconv/attribute_group.go.j2

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% import 'helpers.j2' as h -%}
2+
// Copyright The OpenTelemetry Authors
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Code generated from semantic convention specification. DO NOT EDIT.
6+
7+
package semconv // import "go.opentelemetry.io/otel/semconv/{{params.tag}}"
8+
9+
import "go.opentelemetry.io/otel/attribute"
10+
{%- for group in ctx %}
11+
{{- h.generate_consts(group) }}
12+
{{- h.generate_funcs(group) }}
13+
{{- h.generate_vars(group) }}
14+
{%- endfor %}

semconv/capitalizations.txt

-7
This file was deleted.

semconv/helpers.j2

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{%- macro repl(text) -%}
2+
{#- Copied from semconvgen: https://github.com/open-telemetry/opentelemetry-go-build-tools/blob/3e69152c51c56213b65c0fc6e5954293b522103c/semconvgen/generator.go#L419-L426 -#}
3+
{{ text | replace("RedisDatabase", "RedisDB") | replace("IPTCP", "TCP") | replace("IPUDP", "UDP") | replace("Lineno", "LineNumber") }}
4+
{%- endmacro -%}
5+
6+
{%- macro smart_title_case(text) -%}
7+
{%- for i in range(0, text | length) -%}
8+
{%- if i == 0 or text[i-1] in ['.', '_'] -%}
9+
{{ text[i] | upper }}
10+
{%- elif not text[i] in ['.', '_'] -%}
11+
{{ text[i] }}
12+
{%- endif -%}
13+
{%- endfor -%}
14+
{%- endmacro -%}
15+
16+
{%- macro to_go_name(fqn) -%}
17+
{{ repl(smart_title_case(fqn | replace(" ", "") | replace("_", ".") | acronym)) }}
18+
{%- endmacro -%}
19+
20+
{%- macro deprecated_doc(attr) -%}
21+
{% if attr is deprecated %}Deprecated: {{ attr.deprecated }}{% endif %}
22+
{%- endmacro -%}
23+
24+
{%- macro notes_doc(attr) -%}
25+
{% if attr.note %}Note: {{ attr.note }}{% endif %}
26+
{%- endmacro -%}
27+
28+
{%- macro examples_doc(attr) -%}
29+
{%- if attr.examples is iterable %}
30+
Examples: {{ attr.examples | trim("[]") }}
31+
{%- endif %}
32+
{%- endmacro -%}
33+
34+
{%- macro it_reps(brief) -%}
35+
{%- set brief = brief | trim() -%}
36+
It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
37+
{{ brief[0]|lower }}{{ brief[1:] | trim(".") }}.
38+
{%- else -%}
39+
the {{ brief[0]|lower }}{{ brief[1:] | trim(".") }}.
40+
{%- endif -%}
41+
{%- endmacro -%}
42+
43+
{%- macro keydoc(attr) -%}
44+
{{ to_go_name(attr.name) }}Key is the attribute Key conforming to the "{{ attr.name }}" semantic conventions. {{ it_reps(attr.brief) }}
45+
46+
{% if attr is enum -%}
47+
Type: Enum
48+
{%- else -%}
49+
Type: {{ attr.type }}
50+
{%- endif %}
51+
RequirementLevel: {{ attr.requirement_level | title }}
52+
Stability: {{ attr.stability | title }}
53+
{{ examples_doc(attr) }}
54+
{{ notes_doc(attr) }}
55+
{{ deprecated_doc(attr) }}
56+
{%- endmacro -%}
57+
58+
{%- macro generate_consts(group) -%}
59+
{#- TODO: generate with group docs (i.e group by registry namespace) #}
60+
61+
{{ ["Namespace: " ~ group.root_namespace] | comment(format="go") }}
62+
const (
63+
{%- for attribute in group.attributes if not attribute.deprecated %}
64+
{#- TODO: Handle template attributes. #}
65+
{%- if not attribute.type is template_type %}
66+
{{ keydoc(attribute) | comment(format="go_1tab") }}
67+
{{to_go_name(attribute.name)}}Key = attribute.Key("{{attribute.name}}")
68+
{% endif -%}
69+
{%- endfor -%}
70+
)
71+
{%- endmacro -%}
72+
73+
{%- macro generate_funcs(group) -%}
74+
{%- for attribute in group.attributes if not attribute is enum %}
75+
{#- TODO: Handle template attributes. #}
76+
{%- if not attribute.type is template_type %}
77+
78+
{{ [to_go_name(attribute.name) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~ "\" semantic conventions. " ~ it_reps(attribute.brief) ] | comment(format="go") }}
79+
func {{to_go_name(attribute.name)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
80+
return {{to_go_name(attribute.name)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
81+
}
82+
{%- endif %}
83+
{%- endfor %}
84+
{%- endmacro -%}
85+
86+
{%- macro generate_vars(group) -%}
87+
{#- Render values for enums #}
88+
{%- for attribute in group.attributes %}
89+
{%- if attribute is enum %}
90+
91+
{{ ["Enum values for " ~ attribute.name] | comment(format="go") }}
92+
var (
93+
{%- for value in attribute.type.members %}
94+
{%- if value.deprecated %}
95+
{{ ["Deprecated: " ~ value.deprecated | trim(".") ~ "." ] | comment(format="go_1tab") }}
96+
{%- else %}
97+
{{ [value.brief or value.id, "Stability: " ~ value.stability] | comment(format="go_1tab") }}
98+
{%- endif %}
99+
{{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 }})
100+
{%- endfor %}
101+
)
102+
{%- endif %}
103+
{%- endfor %}
104+
{%- endmacro -%}
105+
106+
{%- macro metric_keydoc(metric) -%}
107+
{%- if not metric.brief -%}
108+
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
109+
{%- else -%}
110+
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
111+
{%- endif %}
112+
{%- endmacro -%}

semconv/metric.go.j2

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% import 'helpers.j2' as h -%}
2+
// Copyright The OpenTelemetry Authors
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Code generated from semantic convention specification. DO NOT EDIT.
6+
7+
package semconv // import "go.opentelemetry.io/otel/semconv/{{params.tag}}"
8+
9+
const (
10+
{%- for metric in ctx %}
11+
{{ h.metric_keydoc(metric) | comment(indent=2) }}
12+
// Instrument: {{ metric.instrument }}
13+
// Unit: {{ metric.unit }}
14+
// Stability: {{ metric.stability }}
15+
{%- if metric is deprecated %}
16+
// Deprecated: {{ metric.deprecated }}
17+
{%- endif %}
18+
{%- if not metric.brief %}
19+
// NOTE: The description (brief) for this metric is not defined in the semantic-conventions repository.
20+
{%- endif %}
21+
{{ h.to_go_name(metric.metric_name) }}Name = "{{ metric.metric_name }}"
22+
{{ h.to_go_name(metric.metric_name) }}Unit = "{{ metric.unit }}"
23+
{%- if metric.brief %}
24+
{{ h.to_go_name(metric.metric_name) }}Description = "{{ metric.brief | trim }}"
25+
{%- endif %}
26+
{%- endfor %}
27+
)

semconv/metric_template.j2

-49
This file was deleted.

0 commit comments

Comments
 (0)