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

Need a new JINJA filter that can take HTML / Markdown - like strings (found in semconv notes) and Javadoc-friendly them. #291

Closed jsuereth closed 1 month ago

jsuereth commented 2 months ago

We need a way to take notes fields and turn it into well-formed javadoc strings. Currently, the Java community is using a render_markdown template that, in my opinion, lacks a good set of docs on what it really does.

See existing template.

Context: migrating java semconv to weaver is failing

lquerel commented 2 months ago

To summarize, here is what I'm proposing to extend the existing filter comment_with_prefix. I'm thinking about adding the following optional parameters:

To simplify things, we could introduce a new section in weaver.yaml which will define the meaning of a new named format.

comment_formats:
  javadoc:
    syntax: html
    inline_code_style: "{@code {{code}}}"
    block_code_style: "{@snippet: {{code}}"

It should also be possible to define the default comment format in weaver.yaml as follow:

default_comment_format: javadoc

With this approach, we could have something as simple as the following in the Jinja template:

{{ brief | comment_with_prefix(prefix="  *") }}

or even simpler if we add the concept of prefix in the config:

{{ brief | comment }}

This will avoid having repetitive parameters throughout the templates for managing comments for a specific programming language.

Note: by default, we could update the default weaver.yaml file embedded in the weaver binary to pre-define the comment configuration for the most common languages.