Skip to content

Commit

Permalink
[chore] Use group name for generating snippets (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
trisch-me authored May 21, 2024
1 parent 6f39cae commit ab96615
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion templates/registry/markdown/attribute_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
{% macro name(attribute) %}{%- if attribute.type is startingwith("template[") %}`{{ attribute.name }}.<key>`
{%- else %}`{{ attribute.name }}`{%- endif %}{% endmacro %}

{% macro name_with_link(attribute, attribute_registry_base_url) %}[{{name(attribute)}}]({{attribute_registry_base_url}}/{{ attribute.name | split_id | list | first | kebab_case }}.md){% endmacro %}
{% macro find_lineage(attr_id, lineage) %}{% if attr_id in lineage %}{{lineage[attr_id].source_group}}{% endif %}{% endmacro %}

{% macro name_with_link(attribute, attribute_registry_base_url, lineage_attributes) %}[{{name(attribute)}}]({{attribute_registry_base_url}}/{{ find_lineage(attribute.name, lineage_attributes) | split_id | list | reject("eq", "registry")| first | kebab_case }}.md){% endmacro %}

{% macro examples(attribute) %}{%- if attribute.examples %}
{%- if attribute.examples is sequence %}
Expand Down
6 changes: 3 additions & 3 deletions templates/registry/markdown/attribute_table.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{% import 'enum_macros.j2' as enums %}
{% import 'sampling_macros.j2' as sampling %}
{#- Macro for creating attribute table -#}
{% macro generate(attributes, tag_filter, attribute_registry_base_url) %}{% if (tag_filter | length == 0) %}{% set filtered_attributes = attributes %}{% else %}{% set filtered_attributes = attributes | selectattr("tag", "in", tag_filter) %}{% endif %}{% if filtered_attributes | length > 0 %}| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
{% macro generate(attributes, tag_filter, attribute_registry_base_url, lineage_attributes) %}{% if (tag_filter | length == 0) %}{% set filtered_attributes = attributes %}{% else %}{% set filtered_attributes = attributes | selectattr("tag", "in", tag_filter) %}{% endif %}{% if filtered_attributes | length > 0 %}| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
|---|---|---|---|---|---|
{% for attribute in filtered_attributes | attribute_sort %}| {{ attrs.name_with_link(attribute, attribute_registry_base_url) }} | {{ attrs.type(attribute) }} | {{ attribute.brief | trim }}{{ notes.add(attribute.note) }} | {{ attrs.examples(attribute) | trim }} | {{ requirement.render(attribute.requirement_level, notes) | trim }} | {{ stability.badge(attribute.stability, attribute.deprecated) | trim }} |
{% endfor %}{{ notes.render() }}{{ sampling.snippet(filtered_attributes, attribute_registry_base_url) }}{{ enums.tables(filtered_attributes | selectattr("type", "mapping"), notes) }}
{% for attribute in filtered_attributes | attribute_sort %}| {{ attrs.name_with_link(attribute, attribute_registry_base_url, lineage_attributes) }} | {{ attrs.type(attribute) }} | {{ attribute.brief | trim }}{{ notes.add(attribute.note) }} | {{ attrs.examples(attribute) | trim }} | {{ requirement.render(attribute.requirement_level, notes) | trim }} | {{ stability.badge(attribute.stability, attribute.deprecated) | trim }} |
{% endfor %}{{ notes.render() }}{{ sampling.snippet(filtered_attributes, attribute_registry_base_url, lineage_attributes) }}{{ enums.tables(filtered_attributes | selectattr("type", "mapping"), notes) }}
{% endif %}{% endmacro %}
4 changes: 2 additions & 2 deletions templates/registry/markdown/sampling_macros.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% import 'attribute_macros.j2' as attrs %}
{% macro snippet(attributes, attribute_registry_base_url) %}{% set sampling_attributes = attributes | selectattr("sampling_relevant", "true") %}{% if sampling_attributes | length > 0 %}
{% macro snippet(attributes, attribute_registry_base_url, lineage_attributes) %}{% set sampling_attributes = attributes | selectattr("sampling_relevant", "true") %}{% if sampling_attributes | length > 0 %}
The following attributes can be important for making sampling decisions
and SHOULD be provided **at span creation time** (if provided at all):

{% for attribute in sampling_attributes | sort(attribute="name") %}* {{ attrs.name_with_link(attribute, attribute_registry_base_url) }}
{% for attribute in sampling_attributes | sort(attribute="name") %}* {{ attrs.name_with_link(attribute, attribute_registry_base_url, lineage_attributes) }}
{% endfor %}{% endif %}{% endmacro %}
2 changes: 1 addition & 1 deletion templates/registry/markdown/snippet.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- markdownlint-capture -->
<!-- markdownlint-disable -->
{% import 'attribute_table.j2' as at %}{% import 'metric_table.j2' as mt %}{% import 'event_macros.j2' as event %}
{% if snippet_type == "metric_table" %}{{ mt.generate(group) }}{% else %}{% if group.type == "event" %}{{ event.header(group) }}{% endif %}{{ at.generate(group.attributes, tag_filter, attribute_registry_base_url) }}{% endif %}
{% if snippet_type == "metric_table" %}{{ mt.generate(group) }}{% else %}{% if group.type == "event" %}{{ event.header(group) }}{% endif %}{{ at.generate(group.attributes, tag_filter, attribute_registry_base_url, group.lineage.attributes) }}{% endif %}
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- END AUTOGENERATED TEXT -->

0 comments on commit ab96615

Please sign in to comment.