-
Notifications
You must be signed in to change notification settings - Fork 55
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
Enable rendering of "template" attributes in table generation #186
Enable rendering of "template" attributes in table generation #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM as a way forward
Nice!! groups:
- id: http.request.headers
type: attribute_group
prefix: http.request.header
brief: 'This group defines dynamic attributes in `http.request.headers` namespace'
attributes:
- id: key
type: string
template: true # or 'dynamic' , etc <<---- THIS IS NEW
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' or even this: groups:
- id: http.request.headers
type: wildcard_attribute_group # or namespace, etc <<---- THIS IS NEW
prefix: http.request.header
brief: 'This group registers a namespace for HTTP request headers'
note: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values. I personally prefer the latter because we don't need to define any attributes (and specify levels, or type which make no sense in this case). |
@lmolkova
So, how about we try to model it as a special kind of attribute (similar to your first proposal)? Regarding the first proposal: So, what do you think about the following counter proposal?: groups:
- id: http.trace.http.common
type: attribute_group
prefix: http
brief: 'This group defines dynamic attributes in `http.request.headers` namespace'
attributes:
- id: request.header
type: string
template_name: key # <<---- THIS IS NEW
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' So, instead of a WDYT? |
I think this YAML-proposal is very good @AlexanderWert. However, I have a different opinion on
I think it is OK to let unadjusted code templates break. The upside is that after adjustment, it should be easier to handle non-template and template attributes in the same loop and also there seems to be no logical reason to render them out-of-order. In the meantime, the breakage when name is We may want to provide a |
Thanks @Oberon00 !
I agree for rendering in the markdown files: they should be treated very similar / same as normal attributes in the markdown files. However, wouldn't we explicitly want to treat them separately for code generation because they will result in completely different constructs? For example in Java, normal attributes result in constants in this file, however, template attributes have a different construct, which is a helper class, like done here manually. Wouldn't that imply that we actually want the code rendering for template attributes to happen out-of-order (or at least from a different set as the normal attributes)? Otherwise, we'd need to explicitly exclude template attributes from places like in this template. Maybe I didn't fully get yet the benefit or cases for:
|
For the case of Java it might indeed be easier, but I think many languages just produce string constants.
No, I think you got it. It's not that big of a benefit (e.g. you can apparently use |
I'm fine with both. The main motivation to keep it separate was to not introduce breaking changes with that. How about inverting your proposal? So, not separating the concepts, but instead of opting-out rather opt-in into rendering template-attributes with something like That would not separate those but also prevent breaking changes (or the need to change invocation parameters to keep the current behavior). |
I was thinking of that as well, but that would make the tool suppress information by default and you have to know about the flag, otherwise everything will silently work but be reduced. I'd prefer the separate lists over that I think, but it's a very fine line at this point |
@lmolkova , @trask Otherwise, I'd adapt this PR according to that proposal, WDYT? |
@AlexanderWert it looks great! One thing I'm slightly concerned about is I wonder if it can match the full attribute name, i.e. groups:
- id: http.trace.http.common
type: attribute_group
prefix: http
brief: 'This group defines dynamic attributes in `http.request.headers` namespace'
attributes:
- id: request.header.*
type: string
template_name: key # <<---- THIS IS NEW
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' otherwise, we're defining a namespace an alternative: groups:
attributes:
- id_template: request.header.{key} // or request.header.[key], etc # <<---- THIS IS NEW
type: string
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' |
Agreed, it seems to be a good idea to mark the How about using groups:
- id: http.trace.http.common
type: attribute_group
prefix: http
brief: 'This group defines dynamic attributes in `http.request.headers` namespace'
attributes:
- namespace: request.header # <--- namespace instead of id, no need to add extra "template_name"
type: string
brief: >
Namespace for HTTP request headers, the id being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' Another idea would be to use |
The problem with omitting the So how about @lmolkova 's second proposal but keeping the groups:
attributes:
- id: request.header.<key> // <<---- SPECIAL FORMAT that allows the tooling to differentiate
type: string
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' |
It would be possible to adapt this so that for referencing (and also unique-ness checks!) it behaves just like "id". Might be too cumbersome / complicate the code too much to be worth it though. |
704ffd7
to
0c6d950
Compare
yeah, I fear it would complicate things a lot. I adapted the PR to implement this approach: groups:
attributes:
- id: request.header.<key> // <<---- SPECIAL FORMAT that allows the tooling to differentiate
type: string
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' I think it's the least invasive still the
Please have another look and if you're fine with that let's get this merged so we can move those parts to YAML as well. Thanks! |
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Show resolved
Hide resolved
@lmolkova Actually, we are not defining a namespace with that, but a |
…ader.<key>` Signed-off-by: Alexander Wert <[email protected]>
0c6d950
to
90e3c3a
Compare
Based on the feedback, the newest update in this PR contains the following variant: groups:
- id: http.trace.http.common
type: attribute_group
prefix: http
brief: 'This group ...'
attributes:
- id: request.header
type: template[string[]] <--- THIS IS NEW
brief: >
HTTP request headers, `<key>` being the normalized HTTP Header name
(lowercase, with - characters replaced by _), the value being the header values.
examples: '`http.request.header.content_type=["application/json"]`' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Could you please also update a few things?
- changelog
- docs: https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/syntax.md#type
- schema definition: https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/semconv.schema.json#L282
I'm also curious how code generation will work on this - I'll try later today and share.
…cs and changelog Signed-off-by: Alexander Wert <[email protected]>
I added the requested changes:
In addition I also added the capability to render code (in a way that it should not affect existing code generation templates). Also added a test for the code generation of template attributes. |
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_attribute.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/model/semantic_convention.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/opentelemetry/semconv/templating/markdown/__init__.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexander Wert <[email protected]>
007d33e
to
d86eea4
Compare
@lmolkova can this be merged? Or anything missing? |
@open-telemetry/specs-semconv-maintainers Can we merge this? |
Problem
In the semantic conventions we have
template
-style attributes in some places.Examples are:
http.request.header.<key>
,http.response.header.<key>
db.elasticsearch.path_parts.<key>
This kind of attributes could not be included in the model
.yml
files yet, and thus could not be included in table generation.Solution
This PR proposes a fix that enables definition of
template
-style attributes in the YAML files and corresponding table generation.How it works
Template-style attributes (i.e. that do not result in a single attribute, but a group of attributes, for example
http.request.header.<key>
) can be defined in a separateattribute-templates
sub-path in an attribute group.Attribute templates extend the normal attributes by adding an additional property
parameter_name
that is the name of the parameter in the angle brackets (e.g.key
in the example above).Here is an example YAML file snippet:
This will result in the following markdown result through table generation:
Defining such attributes templates in a separate path in the yaml (instead of listing them under the normal attributes) has the following advantages:
These attribute templates have slightly different semantic (compared to normal attributes) as they represent a group of attributes (for which the actual name is runtime dynamic / unknown at specification time).
It does not break code generation for attributes, because it's a separate path that is currently just not considered for code generation. Later, we could even build dedicated code generators for template-style attributes for the different languages. That's something that is currently defined 'manually' in all the SDKs.
For markdown table generation, this PR already includes template-style attributes as an additional set of attributes. Hence, template-style attributes can be defined in YAML files and are included in table generation.