open-telemetry / weaver

OTel Weaver lets you easily develop, validate, document, and deploy semantic conventions
Apache License 2.0
52 stars 19 forks source link

`comment_with_prefix` should normalize the content #266

Closed lmolkova closed 1 month ago

lmolkova commented 2 months ago

We can do a better job in semantic conventions wrt trailing dots (we don't 😿 ), but build-tools compensated for it by removing trailing dots at the end of the note or brief.

comment_with_prefix could implement this behavior, which is apparently not trivial to do in jinja.

{%- macro remove_trailing_dots(str) -%}
{%- if str[-1:] == '.' -%}{{ remove_trailing_dots(str[:-1]) }}{%- else -%}{{ str }}{%- endif -%}
{%- endmacro -%}

{%- macro to_docstring(str, prefix) -%}
{{remove_trailing_dots(str | trim(' \n')) | comment_with_prefix(prefix)}}
{%- endmacro %}

IT could also be useful to trim any whitespace characters that might or might not be enforced by they yamllint in semantic conventions.

lmolkova commented 2 months ago

Also maybe need to escape \ - need to check if java/c#/any other language needs it, python linters complain about docstring with unescaped \:

image

/home/runner/work/opentelemetry-python/opentelemetry-python/opentelemetry-semantic-conventions/src/opentelemetry/semconv/_incubating/metrics/system_metrics.py:156:9: W605 invalid escape sequence '\%'

lquerel commented 2 months ago

See also #291

jsuereth commented 1 month ago

duplicate of #309

lquerel commented 1 month ago

Implemented in #309