Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion scripts/semconv/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ git fetch origin "${SPEC_VERSION}" --depth=1
git reset --hard FETCH_HEAD
cd ${SCRIPT_DIR}

# Generate "semantic-conventions/src/stable_*.ts".
docker run --rm --platform linux/amd64 \
-v ${SCRIPT_DIR}/semantic-conventions/model:/source \
-v ${SCRIPT_DIR}/templates:/weaver/templates \
Expand All @@ -35,7 +36,19 @@ docker run --rm --platform linux/amd64 \
registry generate \
--registry=/source \
--templates=/weaver/templates \
stable \
ts-stable \
/output/

# Generate "semantic-conventions/src/experimental_*.ts".
docker run --rm --platform linux/amd64 \
-v ${SCRIPT_DIR}/semantic-conventions/model:/source \
-v ${SCRIPT_DIR}/templates:/weaver/templates \
-v ${ROOT_DIR}/semantic-conventions/src/:/output \
otel/weaver:$GENERATOR_VERSION \
registry generate \
--registry=/source \
--templates=/weaver/templates \
ts-experimental \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: This PR splits the templates for stable and experimental to two separate dirs, so that the logic can differ between them. Comment #5690 (comment) includes a (slightly out of date) diff of the two dirs to show how similar they are.

I tried to share the unchanged files ("metrics.ts.j2", "docstring.ts.j2"), but weaver borks when you try to use files outside of the root dir.

/output/

# Ensure semconv compiles
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{%- import 'docstring.ts.j2' as d %}
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//----------------------------------------------------------------------------------------------------------
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates/registry/stable/attributes.ts.j2
//----------------------------------------------------------------------------------------------------------

{% for attribute in ctx.attributes | attribute_sort %}
{% if attribute.name not in params.excluded_attributes %}
{% if attribute is not stable %}
{{d.docstring(attribute, "attribute")}}
{% if attribute.type is not template_type %}
export const ATTR_{{ attribute.name | screaming_snake_case }} = '{{attribute.name}}' as const;

{% else %}
export const ATTR_{{ attribute.name | screaming_snake_case }} = (key: string) => `{{attribute.name}}.${key}`;

{% endif %}
{% endif %}
{% if attribute.type is mapping %}
{% for espec in attribute.type.members | sort(attribute='value') %}
{#- Grandfather NETWORK_TRANSPORT_VALUE_QUIC as stable until v1.34.0 is released. #}
{% if espec is not stable and not (attribute.name == 'network.transport' and espec.value == 'quic') %}
/**
* Enum value {{ espec.value | print_member_value }} for attribute {@link ATTR_{{ attribute.name | screaming_snake_case }}}.
*/
export const {{ attribute.name | screaming_snake_case }}_VALUE_{{ espec.id | screaming_snake_case }} = {{ espec.value | print_member_value }} as const;

{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,53 +1,23 @@

params:
excluded_attributes: ["messaging.client_id"]

# https://github.com/open-telemetry/weaver/blob/main/crates/weaver_forge/README.md#comment-filter
comment_formats:
jsdoc:
format: markdown
header: '/**'
# Note: This results in trailing whitespace on empty lines. IMHO the
# 'comment' filter should handle those.
prefix: ' * '
footer: ' */'
trim: true
indent_first_level_list_items: true
escape_backslashes: true
default_comment_format: jsdoc
# ts-experimental/... generates the "semantic-conventions/src/experimental_*.ts"
# files.

# Notes:
# - Use `""` and `null` with `exclude_stability` to skip attributes/metrics that
# accidentally do not have a stability set
# (e.g. https://github.com/open-telemetry/semantic-conventions/issues/1777).
templates:
- pattern: attributes.ts.j2
file_name: "stable_attributes.ts"
filter: >
semconv_attributes({
"stable_only": true
}) | {
attributes: .
}
application_mode: single
- pattern: attributes.ts.j2
file_name: "experimental_attributes.ts"
# This "exclude_stability" does *not* exclude "stable" because it needs
# to process *stable* enums that might have *unstable* members. (e.g.,
# `db.system.name` is stable, but some of its enum values are not.)
filter: >
semconv_attributes({
"exclude_stability": ["stable", "", null]
"exclude_stability": ["", null]
}) | {
attributes: .
}
application_mode: single
- pattern: metrics.ts.j2
file_name: "stable_metrics.ts"
filter: >
semconv_metrics({
"stable_only": true
}) | {
metrics: .
}
application_mode: single
- pattern: metrics.ts.j2
file_name: "experimental_metrics.ts"
filter: >
Expand All @@ -58,6 +28,27 @@ templates:
}
application_mode: single

params:
excluded_attributes: ["messaging.client_id"]

##
# Everything below here is expected to be the same as in "../ts-*/weaver.yaml".
##

# https://github.com/open-telemetry/weaver/blob/main/crates/weaver_forge/README.md#comment-filter
comment_formats:
jsdoc:
format: markdown
header: '/**'
# Note: This results in trailing whitespace on empty lines. IMHO the
# 'comment' filter should handle those.
prefix: ' * '
footer: ' */'
trim: true
indent_first_level_list_items: true
escape_backslashes: true
default_comment_format: jsdoc

# Whitespace control settings to simplify the definition of templates
whitespace_control:
trim_blocks: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export const ATTR_{{ attribute.name | screaming_snake_case }} = (key: string) =>
{% endif %}
{% if attribute.type is mapping %}
{% for espec in attribute.type.members | sort(attribute='value') %}
{#- Grandfather NETWORK_TRANSPORT_VALUE_QUIC as stable until v1.34.0 is released. #}
{% if espec is stable or (attribute.name == 'network.transport' and espec.value == 'quic') %}
/**
* Enum value {{ espec.value | print_member_value }} for attribute {@link ATTR_{{ attribute.name | screaming_snake_case }}}.
*/
export const {{ attribute.name | screaming_snake_case }}_VALUE_{{ espec.id | screaming_snake_case }} = {{ espec.value | print_member_value }} as const;

{% endif %}
{% endfor %}
{% endif %}
{% endif %}
Expand Down
34 changes: 34 additions & 0 deletions scripts/semconv/templates/registry/ts-stable/docstring.ts.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% macro strong_rfc2119(string) -%}{{ string | regex_replace("\\b(MUST NOT|MUST|REQUIRED|SHALL NOT|SHALL|SHOULD NOT|SHOULD|RECOMMENDED|MAY|OPTIONAL)\\b", "**$1**") }}{% endmacro -%}

{% macro docstring(obj, type="value") -%}
{%- set examples_jsdoc %}
{% if obj.examples is sequence %}
{% for example in obj.examples %}
@example {{ example }}
{% endfor %}
{% elif obj.examples %}
@example {{ obj.examples | print_member_value }}
{% endif %}
{% endset -%}

{%- if obj.note %}
{% set note_jsdoc = "@note " ~ strong_rfc2119(obj.note) %}
{% endif -%}

{%- if obj.stability != "stable" %}
{% set stability_jsdoc = "@experimental This " ~ type ~ " is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`." %}
{% endif -%}

{%- if obj is deprecated %}
{%- set deprecated_jsdoc = "\n@deprecated " ~ strong_rfc2119(obj.deprecated.note) -%}
{%- endif -%}

{{ [
strong_rfc2119(obj.brief) | trim,
"\n",
examples_jsdoc,
note_jsdoc,
stability_jsdoc,
deprecated_jsdoc,
] | comment }}
{%- endmacro -%}
26 changes: 26 additions & 0 deletions scripts/semconv/templates/registry/ts-stable/metrics.ts.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{%- import 'docstring.ts.j2' as d %}
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//----------------------------------------------------------------------------------------------------------
// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates/register/stable/metrics.ts.j2
//----------------------------------------------------------------------------------------------------------

{% for metric in ctx.metrics | sort(attribute="metric_name") %}
{{d.docstring(metric, "metric")}}
export const METRIC_{{ metric.metric_name | screaming_snake_case }} = '{{metric.metric_name}}' as const;

{% endfor %}
55 changes: 55 additions & 0 deletions scripts/semconv/templates/registry/ts-stable/weaver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ts-stable/... generates the "semantic-conventions/src/stable_*.ts" files.

templates:
- pattern: attributes.ts.j2
file_name: "stable_attributes.ts"
filter: >
semconv_attributes({
"stable_only": true
}) | {
attributes: .
}
application_mode: single
- pattern: metrics.ts.j2
file_name: "stable_metrics.ts"
filter: >
semconv_metrics({
"stable_only": true
}) | {
metrics: .
}
application_mode: single

params:
excluded_attributes: ["messaging.client_id"]

##
# Everything below here is expected to be the same as in "../ts-*/weaver.yaml".
##

# https://github.com/open-telemetry/weaver/blob/main/crates/weaver_forge/README.md#comment-filter
comment_formats:
jsdoc:
format: markdown
header: '/**'
# Note: This results in trailing whitespace on empty lines. IMHO the
# 'comment' filter should handle those.
prefix: ' * '
footer: ' */'
trim: true
indent_first_level_list_items: true
escape_backslashes: true
default_comment_format: jsdoc

# Whitespace control settings to simplify the definition of templates
whitespace_control:
trim_blocks: true
lstrip_blocks: true

text_maps:
js_types:
int: number
double: number
boolean: boolean
string: string
string[]: string[]
3 changes: 3 additions & 0 deletions semantic-conventions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ All notable changes to the semantic-conventions package will be documented in th

### :boom: Breaking Changes

* fix: Remove the subset of `DB_SYSTEM_NAME_VALUE_*` exports that are unstable from the `@opentelemetry/semantic-conventions` entry point. [#5690](https://github.com/open-telemetry/opentelemetry-js/pull/5690)
* Version 1.33.0 erroneously included all `DB_SYSTEM_NAME_VALUE_*` constants in the stable entry point. Some of those enum values are not yet stable. They have been moved back to the unstable `@opentelemetry/semantic-conventions/incubating` entry point. See the PR description for a full list.

### :rocket: Features

### :bug: Bug Fixes
Expand Down
Loading