Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate semconv codegen to weaver #5793

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use helper methods between templates.
jsuereth committed Sep 6, 2024
commit a4b887e262c65a5206ced68fb64022a09197286b
16 changes: 6 additions & 10 deletions semconv/weaver/registry/go/attribute_group.go.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{# TODO - move to built in support for language constants in weaver #}
{%- macro to_go_name(fqn) -%}
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
{%- endmacro -%}
{% import 'helpers.j2' as h %}
{# TODO - REQUIREMNET LEVEL SHOULD NOT BE USED IN ATTRIBUTE REGISTRY #}
{%- macro requirement_level_doc(attr) -%}
{%- if attr.requirement_level == "required" -%}
@@ -31,7 +28,6 @@ Examples: {{ attr.examples | pprint | trim("[]") }}
{{ attr.brief }}
Stability: {{ attr.stability | title }}
{% if attr is enum %}Type: Enum{% else %}Type: {{ attr.type }}{% endif %}
{{ requirement_level_doc(attr) }}
{{ deprecated_doc(attr) }}
{{ examples_doc(attr) }}
{{ notes_doc(attr) }}
@@ -53,18 +49,18 @@ const (
{% for attribute in group.attributes %}
{%- if not attribute.type is template_type %}{# TODO - Go does not handle template attributes yet!!! #}
{{ keydoc(attribute) | comment(indent=4) }}
{{to_go_name(attribute.name)}}Key = attribute.Key("{{attribute.name}}")
{{h.to_go_name(attribute.name)}}Key = attribute.Key("{{attribute.name}}")
{%- endif %}
{%- endfor %}
)
{# Render a construction function #}
{% for attribute in group.attributes %}
{# TODO - Go does not handle template attributes yet!!! #}
{%- if not attribute.type is template_type %}
{{ [to_go_name(attribute.name) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~"\"semantic conventions."] | comment }}
{{ [h.to_go_name(attribute.name) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~"\"semantic conventions."] | comment }}
{{ ["It represents the " ~ attribute.brief] | comment }}
func {{to_go_name(attribute.name)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
return {{to_go_name(attribute.name)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
func {{h.to_go_name(attribute.name)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
return {{h.to_go_name(attribute.name)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
}
{%- endif %}
{% endfor %}
@@ -76,7 +72,7 @@ var (
{% for value in attribute.type.members %}
{{ [value.brief or value.id, "Stability: " ~ value.stability] | comment(indent=4) }}
{%- if value.deprecated %}{{ value.deprecated | comment(indent=4) }}{% endif %}
{{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 }})
{{h.to_go_name(attribute.name ~ "." ~ value.id)}} = {{ h.to_go_name(attribute.name) }}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}({{ value.value | print_member_value }})
{%- endfor %}
)
{%- endif %}
4 changes: 4 additions & 0 deletions semconv/weaver/registry/go/helpers.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# TODO - move to built in support for language constants in weaver #}
{%- macro to_go_name(fqn) -%}
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
{%- endmacro -%}
14 changes: 6 additions & 8 deletions semconv/weaver/registry/go/metric.go.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{%- macro to_go_name(fqn) -%}
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
{%- endmacro -%}
{% import 'helpers.j2' as h %}
{%- macro it_reps(brief) -%}
It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
{{ brief[0]|lower }}{{ brief[1:] }}
@@ -10,9 +8,9 @@ It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The
{%- endmacro -%}
{%- macro keydoc(metric) -%}
{%- if not metric.brief -%}
{{ to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions.
{{ h.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(".") }}.
{{ h.to_go_name(metric.metric_name) }} is the metric conforming to the "{{ metric.metric_name}}" semantic conventions. {{ it_reps(metric.brief)|trim(".") }}.
{%- endif %}
{%- endmacro -%}
// Copyright The OpenTelemetry Authors
@@ -34,10 +32,10 @@ const (
{%- 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 }}"
{{ h.to_go_name(metric.metric_name) }}Name = "{{ metric.metric_name }}"
{{ h.to_go_name(metric.metric_name) }}Unit = "{{ metric.unit }}"
{%- if metric.brief %}
{{ to_go_name(metric.metric_name) }}Description = "{{ metric.brief | trim }}"
{{ h.to_go_name(metric.metric_name) }}Description = "{{ metric.brief | trim }}"
{%- endif %}
{% endfor %}
)