Skip to content
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

Add embed concept for attributes reuse (in addition to ref) #240

Open
AlexanderWert opened this issue Nov 24, 2023 · 3 comments
Open

Add embed concept for attributes reuse (in addition to ref) #240

AlexanderWert opened this issue Nov 24, 2023 · 3 comments
Assignees

Comments

@AlexanderWert
Copy link
Member

This issue describes a concrete proposal on how to realise attributes reuse through yaml syntax and tooling.

Related issues / PRs:

Proposal

I'm proposing to introduce a new, additional type of attribute reference called embed (alternatively: nest) in the syntax that would behave similarly to ref property BUT with the following difference: When embed is used the referenced attribute will be nested under the namespace of the attribute group in which the attribute is being referenced.

Example

See the following example that illustrates the idea and the difference to ref:

We would define geo attributes in a geo.yaml file:

groups:
  - id: geo
    prefix: geo
    type: attribute_group
    brief: Describes the geo location
    attributes:
      - id: location.lon
        type: double
        brief: Longitude of the geo location in [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
        examples: [ -73.614830 ]
      - id: location.lat
        type: double
        brief: Latitude of the geo location in [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
        examples: [ 45.505918 ]

In client and server files we would embed the attributes.
! Note: Here I consciously embed the geo.location.lon attribute BUT ref the geo.location.lat attribute to demonstrate the difference:

groups:
  - id: client
    prefix: client
    type: attribute_group
    brief: ...
    attributes:
      - id: address
        ...
      - embed: geo.location.lon            <<-- THAT IS NEW
      - ref: geo.location.lat

When rendering (or code generating) the above it will result in the following attributes:

  • client.geo.location.lon
  • geo.location.lat

Note the difference that geo.location.lon is now nested under the client namespace because it was embedded (embed) while geo.location.lat keeps it's original full name because it was referenced (ref).

Extended proposal

We could even think about an embed_namespaces property on the attribute_group level to simplify embeddings of entire namespaces into other namespace. For example for geo we could do something like the following to embed ALL of the geo.* fields into the client:

groups:
  - id: client
    prefix: client
    type: attribute_group
    brief: ...
    embed_namespaces:
      - id: geo                                        <<-- EMBED the entire geo namespace under client
    attributes:
      - id: address
        ...
@AlexanderWert
Copy link
Member Author

AlexanderWert commented Nov 24, 2023

@open-telemetry/specs-semconv-approvers @open-telemetry/specs-semconv-maintainers would love your thoughts on the above!

@ChrsMark
Copy link
Member

Most probably embed_namespaces is more handy because it would save us time from having to embed all of the attributes one by one. However I would like to have support for both so as to have the flexibility to embed only specific attributes if needed.

I cannot think of any particular pitfall here (maybe others can spot sth) but in general I like this proposal +1.

@trisch-me
Copy link

trisch-me commented Mar 11, 2024

Bumping up this issue and add more information.

I propose to add following keywords:


1. includes

This one will make the whole namespace re-usable and adds it to the current group on the same level - without adding a prefix to the group. It should allow to add multiple namespaces

Example: in the current schema we do have browser.yaml inside models

groups:
  - id: browser
    prefix: browser
    type: resource
    brief: >
        The web browser in which the application represented by the resource is running.
        The `browser.*` attributes MUST be used only for resources that represent applications
        running in a web browser (regardless of whether running on a mobile or desktop device).
    attributes:
      - ref: browser.brands
      - ref: browser.platform
      - ref: browser.mobile
      - ref: browser.language
      - ref: user_agent.original        

using new keyword it will be written as following:

groups:
  - id: browser
    prefix: browser
    type: resource
    includes: [browser] <--- NEW keyword
    brief: >
        The web browser in which the application represented by the resource is running.
        The `browser.*` attributes MUST be used only for resources that represent applications
        running in a web browser (regardless of whether running on a mobile or desktop device).
    attributes:
      - ref: user_agent.original

where in md file we could either unpack namespace into specific fields or just give a link to the registry for the whole namespace:

| [`browser.*`](../attributes-registry/browser.md) | Namespace | Browser namespace | | Opt-In | <---- includes

2. embeds

This one will make the whole namespace re-usable and adds it to the current group UNDER the group using its prefix. It should allow to add multiple namespaces

Example: we would like to add whole geo.* namespace to the client and server to make it possible to attach additional attributes to the both client and server.

groups:
  - id: client
    prefix: client
    type: attribute_group
    brief: >
      These attributes may be used to describe the client in a connection-based network interaction
      .......
    attributes:
      - id: address
        stability: stable
        type: string

using new keyword it will be written as following:

groups:
  - id: client
    prefix: client
    type: attribute_group
    embeds: [geo] <---- **NEW**
    brief: >
      These attributes may be used to describe the client in a connection-based network...
    attributes:
      - id: address
      - .....

which resolves into following construction in the md file:

| [`client.geo.*`](../attributes-registry/geo.md) | Namespace | Geo namespace | | Opt-In | <---- embeds

3. embed

This one will make possible to re-use only specific attributes of the namespace, similar to the ref but with a prefix

Example: we don't want to add the whole namespace to the client but only a few attributes.

groups:
  - id: client
    prefix: client
    type: attribute_group
    brief: >
      These attributes may be used to describe the client in a connection-based network...
    attributes:
      - ref: client.geo.location.lon
      - ...
      - embed: geo.location.lat

which resolves into following construction in the md file:

| [`geo.location.lon`](../attributes-registry/geo.md) | type | Description | | Opt-In | <---- ref
| [`client.geo.location.lat`](../attributes-registry/geo.md) | type | Description | | Opt-In | <---- embed

To summarise we would have following representation of all different types (I have changed real browser example to artificial one for similarity with others):

| [`geo.*`](../attributes-registry/geo.md) | Namespace | Geo namespace | | Opt-In | <---- includes whole namespace
| [`client.geo.*`](../attributes-registry/geo.md) | Namespace | Geo namespace | | Opt-In | <---- embeds whole namespace under client
| [`geo.location.lon`](../attributes-registry/geo.md) | type | Description | | Opt-In | <---- referenced attribute
| [`client.geo.location.lat`](../attributes-registry/geo.md) | type | Description | | Opt-In | <---- embedded attribute under client

Please let me know what do you think about this idea, I would like to start to work on it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Improve YAML Schema
Development

No branches or pull requests

3 participants