Skip to content

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

Open
osullivandonal wants to merge 17 commits intoopen-telemetry:mainfrom
osullivandonal:mdatagen-add-attribute-semconv-refs
Open

[mdatagen] Add semconv reference for attributes in metadata schema#14646
osullivandonal wants to merge 17 commits intoopen-telemetry:mainfrom
osullivandonal:mdatagen-add-attribute-semconv-refs

Conversation

@osullivandonal
Copy link
Contributor

@osullivandonal osullivandonal commented Feb 26, 2026

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
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 65.89595% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.35%. Comparing base (fc354be) to head (b7dc46e).

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 check 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.45%   91.35%   -0.11%     
==========================================
  Files         688      688              
  Lines       43824    43992     +168     
==========================================
+ Hits        40081    40187     +106     
- Misses       2631     2688      +57     
- Partials     1112     1117       +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
"go.opentelemetry.io/collector/pdata/pcommon"
)

const semConvURL = "https://github.com/open-telemetry/semantic-conventions/blob"
Copy link
Member

Choose a reason for hiding this comment

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

While I agree that not having to specify a full URL every time, this assumes all semantic conventions are on the semantic-conventions repository, which may be problematic in the future with open-telemetry/opentelemetry-specification#4906

Copy link
Member

Choose a reason for hiding this comment

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

I think we can proceed with this as is now and revisit once things are more clear in general about how we will link/define semconv and registries in Collector components in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me.

Copy link
Member

@ChrsMark ChrsMark left a comment

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

{{- $attribute := . | attributeInfo }}
| {{ $attribute.Name }} | {{ $attribute.Description }} |
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.RequirementLevel }} |
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.RequirementLevel }} |{{ if $attribute.SemanticConvention }} [{{ $attribute.Name }}]({{ $attribute.SemanticConvention.SemanticConventionRef }}) |{{ else }} |{{ end }}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can be more explicit and use a - or something similar to state that there is no semantic convention definition for this. Having this just empty might raise questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this is good to have, rows with an empty semantic_conventions ref now uses "-":

Attributes

Name Description Values Requirement Level Semantic Convention
string_attr Attribute with any string value. Any Str Recommended -
state Integer attribute with overridden name. Any Int Recommended -
enum_attr Attribute with a known set of string values. Str: red, green, blue Recommended -
slice_attr Attribute with a slice value. Any Slice Recommended -
map_attr Attribute with a map value. Any Map Recommended -

if_configured:
# Optional: the reference to a semantic convention
# Relative path to the semantic convention definition (e.g., "system.md#system-memory-state")
# The full URL is constructed using sem_conv_version: {base}/v{version}/docs/registry/attributes/{ref}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup this makes sense, I have updated all references of this to have a full example.

@codspeed-hq

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants