From a9d4f9e2e57993e4aa30042719634beb8eaeddba Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 18 Oct 2024 13:28:38 -0700 Subject: [PATCH] Flatten weaver pkg into semconv --- Makefile | 2 +- .../registry/go => }/attribute_group.go.j2 | 0 semconv/{weaver/registry/go => }/helpers.j2 | 0 semconv/{weaver/registry/go => }/metric.go.j2 | 0 semconv/metric_template.j2 | 49 ------ semconv/template.j2 | 145 ------------------ semconv/{weaver/registry/go => }/weaver.yaml | 0 7 files changed, 1 insertion(+), 195 deletions(-) rename semconv/{weaver/registry/go => }/attribute_group.go.j2 (100%) rename semconv/{weaver/registry/go => }/helpers.j2 (100%) rename semconv/{weaver/registry/go => }/metric.go.j2 (100%) delete mode 100644 semconv/metric_template.j2 delete mode 100644 semconv/template.j2 rename semconv/{weaver/registry/go => }/weaver.yaml (100%) diff --git a/Makefile b/Makefile index 02ba77137f57..1d67ca1f83f5 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,7 @@ semconv-generate: $(SEMCONVKIT) docker run --rm \ -u $(DOCKER_USER) \ --env HOME=/tmp/weaver \ - --mount 'type=bind,source=$(PWD)/semconv/weaver,target=/home/weaver/templates,readonly' \ + --mount 'type=bind,source=$(PWD)/semconv,target=/home/weaver/templates/registry/go,readonly' \ --mount 'type=bind,source=$(PWD)/semconv/${TAG},target=/home/weaver/target' \ --mount 'type=bind,source=$(HOME)/.weaver,target=/tmp/weaver/.weaver' \ $(WEAVER_CONTAINER) registry generate \ diff --git a/semconv/weaver/registry/go/attribute_group.go.j2 b/semconv/attribute_group.go.j2 similarity index 100% rename from semconv/weaver/registry/go/attribute_group.go.j2 rename to semconv/attribute_group.go.j2 diff --git a/semconv/weaver/registry/go/helpers.j2 b/semconv/helpers.j2 similarity index 100% rename from semconv/weaver/registry/go/helpers.j2 rename to semconv/helpers.j2 diff --git a/semconv/weaver/registry/go/metric.go.j2 b/semconv/metric.go.j2 similarity index 100% rename from semconv/weaver/registry/go/metric.go.j2 rename to semconv/metric.go.j2 diff --git a/semconv/metric_template.j2 b/semconv/metric_template.j2 deleted file mode 100644 index 144d280a875f..000000000000 --- a/semconv/metric_template.j2 +++ /dev/null @@ -1,49 +0,0 @@ -{%- 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 %} -) diff --git a/semconv/template.j2 b/semconv/template.j2 deleted file mode 100644 index 4ee8ef559da9..000000000000 --- a/semconv/template.j2 +++ /dev/null @@ -1,145 +0,0 @@ -{%- macro keyval_method(type) -%} - {%- if type == "string" -%} - String - {%- elif type == "string[]" -%} - StringSlice - {%- elif type == "int" -%} - Int - {%- elif type == "int[]" -%} - IntSlice - {%- elif type == "double" -%} - Float64 - {%- elif type == "double[]" -%} - Float64Slice - {%- elif type == "boolean" -%} - Bool - {%- elif type == "boolean[]" -%} - BoolSlice - {%- endif -%} -{%- endmacro -%} -{%- macro to_go_attr_type(type, val) -%} -{{keyval_method(type)}}({% if type == "string" %}"{{val}}"{% else %}{{val}}{% endif %}) -{%- endmacro -%} -{%- 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(attr) -%} -{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" -%} -{{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions. -{%- else -%} -{{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }} -{%- endif %} -{%- endmacro -%} -{%- macro keydetails(attr) -%} -{%- if attr.attr_type is string %} -Type: {{ attr.attr_type }} -{%- else %} -Type: Enum -{%- endif %} -{%- if attr.requirement_level == RequirementLevel.REQUIRED %} -RequirementLevel: Required -{%- elif attr.requirement_level == RequirementLevel.CONDITIONALLY_REQUIRED %} -RequirementLevel: ConditionallyRequired - {%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %} -{%- elif attr.requirement_level == RequirementLevel.RECOMMENDED %} -RequirementLevel: Recommended - {%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %} -{%- else %} -RequirementLevel: Optional -{%- endif %} -{{ attr.stability | replace("Level.", ": ") | capitalize }} -{%- if attr.examples is iterable %} -Examples: {{ attr.examples | pprint | trim("[]") }} -{%- endif %} -{%- if attr.note %} -Note: {{ attr.note }} -{%- endif %} -{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" %} -Deprecated: {{ attr.brief | replace("Deprecated, ", "") }} -{%- endif %} -{%- endmacro -%} -{%- macro fndoc(attr) -%} -{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" -%} -// {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. - -Deprecated: {{ attr.brief | replace("Deprecated, ", "") }} -{%- else -%} -// {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }} -{%- endif %} -{%- endmacro -%} -{%- macro to_go_func(type, name) -%} -{%- if type == "string" -%} -func {{name}}(val string) attribute.KeyValue { -{%- elif type == "string[]" -%} -func {{name}}(val ...string) attribute.KeyValue { -{%- elif type == "int" -%} -func {{name}}(val int) attribute.KeyValue { -{%- elif type == "int[]" -%} -func {{name}}(val ...int) attribute.KeyValue { -{%- elif type == "double" -%} -func {{name}}(val float64) attribute.KeyValue { -{%- elif type == "double[]" -%} -func {{name}}(val ...float64) attribute.KeyValue { -{%- elif type == "boolean" -%} -func {{name}}(val bool) attribute.KeyValue { -{%- elif type == "boolean[]" -%} -func {{name}}(val ...bool) attribute.KeyValue { -{%- endif -%} - return {{name}}Key.{{keyval_method(type)}}(val) -} -{%- endmacro -%} -{%- macro sentence_case(text) -%} - {{ text[0]|upper}}{{text[1:] }} -{%- endmacro -%} -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -// Code generated from semantic convention specification. DO NOT EDIT. - -package semconv // import [[IMPORTPATH]] - -import "go.opentelemetry.io/otel/attribute" - -{% for semconv in semconvs -%} -{%- if semconvs[semconv].attributes | rejectattr("ref") | rejectattr("deprecated") | selectattr("is_local") | sort(attribute=fqn) | length > 0 -%} -// {{ sentence_case(semconvs[semconv].brief | replace("This document defines ", "")) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }} -const ( -{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated %} - // {{ keydoc(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }} - // {{ keydetails(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }} - {{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}") -{% endfor -%} -) -{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated -%} -{%- if attr.attr_type is not string %} - -var ( -{%- for val in attr.attr_type.members %} - // {{ val.brief | to_doc_brief }} -{%- if attr.stability|string() == "StabilityLevel.DEPRECATED" %} - // - // Deprecated: {{ attr.brief | replace("Deprecated, ", "") | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }} -{%- endif %} - {{to_go_name("{}.{}".format(attr.fqn, val.member_id))}} = {{to_go_name(attr.fqn)}}Key.{{to_go_attr_type(attr.attr_type.enum_type, val.value)}} -{%- endfor %} -) -{%- endif -%} -{%- endfor %} -{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated -%} -{%- if attr.attr_type is string %} - -{{ fndoc(attr) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }} -{{to_go_func(attr.attr_type, to_go_name(attr.fqn))}} -{%- endif -%} -{%- endfor %} - -{% endif %} -{% endfor -%} - diff --git a/semconv/weaver/registry/go/weaver.yaml b/semconv/weaver.yaml similarity index 100% rename from semconv/weaver/registry/go/weaver.yaml rename to semconv/weaver.yaml