Skip to content

[mdatagen] Add semconv reference for attributes in metadata schema - #14646

Merged
mx-psi merged 24 commits into
open-telemetry:mainfrom
osullivandonal:mdatagen-add-attribute-semconv-refs
Mar 27, 2026
Merged

[mdatagen] Add semconv reference for attributes in metadata schema#14646
mx-psi merged 24 commits into
open-telemetry:mainfrom
osullivandonal:mdatagen-add-attribute-semconv-refs

Conversation

@osullivandonal

@osullivandonal osullivandonal commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds support in mdatagen for defining semantic conventions references for attributes.

Updating your attribute in metadata.yaml:

attributes:
  state:
    description: Breakdown of memory usage by type.
    type: string
    enum: [buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used]
    semantic_convention:
      ref: system.md#system-memory-state

Important

This work also updates the semantic_convention: ref: to use a relative URL, this was done as we want to ensure the same semconv version from the metadata schema is used, otherwise the end user could have a full url in ref with one semconv version and the schema version being a different version. A new method has been introduced in mdatagen that builds the semconv url at runtime.

Creates this table in the generated docs for that component:

Attributes

Name Description Values Requirement Level Semantic Convention
state Breakdown of memory usage by type. Str: buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used Recommended state

Link to tracking issue

This work is linked to #13297 but doesn't close it.

Testing

  • loader_test.go was updated with attributes for cpu and state.
  • Also cmd/mdatagen/internal/samplereciever was updated and generate code created which creates tests.

Documentation

The documentation template has been updated to reference the semconv definition for attributes if provided in the schema.

This update to mdatagen allows attributes and resource attributes to
reference their semantic convention, this is then included in the
generated documentation.
@codecov

codecov Bot commented Feb 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.89595% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.22%. Comparing base (01ca829) to head (0652f5b).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...plereceiver/internal/metadata/generated_metrics.go 69.15% 31 Missing and 2 partials ⚠️
...mplereceiver/internal/metadata/generated_config.go 31.57% 24 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (65.89%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14646      +/-   ##
==========================================
- Coverage   91.32%   91.22%   -0.11%     
==========================================
  Files         697      697              
  Lines       44456    44624     +168     
==========================================
+ Hits        40601    40707     +106     
- Misses       2716     2773      +57     
- Partials     1139     1144       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The metdata schema has been updated to use relative url refs for linking
attributes and metrics to their semantic-conventions. mdatagen now
builds the url using the semantic-conventions version of the schema.
@osullivandonal
osullivandonal marked this pull request as ready for review February 27, 2026 14:51
@osullivandonal
osullivandonal requested review from a team and dmitryax as code owners February 27, 2026 14:51
Comment thread cmd/mdatagen/internal/metadata.go

@ChrsMark ChrsMark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that addition will be helpful at the moment to link existing attributes to defined Semantic Conventions.

I would like to use this already in https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/k8sattributesprocessor/documentation.md as part of open-telemetry/opentelemetry-collector-contrib#44483.

@mx-psi @dmitryax please take a look

Comment thread cmd/mdatagen/internal/templates/documentation.md.tmpl Outdated
Comment thread cmd/mdatagen/metadata-schema.yaml
Comment thread cmd/mdatagen/internal/metadata.go Outdated
@codspeed-hq

This comment was marked as outdated.

@dmathieu dmathieu added the ready-to-merge Code review completed; ready to merge by maintainers label Mar 22, 2026

@mx-psi mx-psi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, ready to merge once the CI is fixed

@mx-psi
mx-psi added this pull request to the merge queue Mar 27, 2026
Merged via the queue into open-telemetry:main with commit 6a56478 Mar 27, 2026
66 of 67 checks passed
blakerouse pushed a commit to blakerouse/opentelemetry-collector that referenced this pull request May 13, 2026
…pen-telemetry#14646)

#### Description

This PR adds support in mdatagen for defining semantic conventions
references for attributes.

Updating your attribute in `metadata.yaml`:

```yaml
attributes:
  state:
    description: Breakdown of memory usage by type.
    type: string
    enum: [buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used]
    semantic_convention:
      ref: system.md#system-memory-state
```

> [!IMPORTANT]
> This work also updates the `semantic_convention: ref:` to use a
relative URL, this was done as we want to ensure the same semconv
version from the metadata schema is used, otherwise the end user could
have a full url in `ref` with one semconv version and the schema version
being a different version. A new method has been introduced in mdatagen
that builds the semconv url at runtime.

Creates this table in the generated docs for that component:

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention
|
| ---- | ----------- | ------ | ----------------- | -------------------
|
| state | Breakdown of memory usage by type. | Str: ``buffered``,
``cached``, ``inactive``, ``free``, ``slab_reclaimable``,
``slab_unreclaimable``, ``used`` | Recommended |
[state](https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state)
|

<!-- Issue number if applicable -->
#### Link to tracking issue
This work is linked to open-telemetry#13297 but doesn't close it.

<!--Describe what testing was performed and which tests were added.-->
#### Testing 

- loader_test.go was updated with attributes for `cpu` and `state`.
- Also `cmd/mdatagen/internal/samplereciever` was updated and generate
code created which creates tests.

<!--Describe the documentation added.-->
#### Documentation

The documentation template has been updated to reference the semconv
definition for attributes if provided in the schema.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd/mdatagen ready-to-merge Code review completed; ready to merge by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants