Skip to content

[mdatagen] Mdatagen link metrics and attributes from metadata to semconv#14598

Closed
osullivandonal wants to merge 23 commits intoopen-telemetry:mainfrom
osullivandonal:mdatagen-link-metrics-and-attributes-from-metadata-to-semconv
Closed

[mdatagen] Mdatagen link metrics and attributes from metadata to semconv#14598
osullivandonal wants to merge 23 commits intoopen-telemetry:mainfrom
osullivandonal:mdatagen-link-metrics-and-attributes-from-metadata-to-semconv

Conversation

@osullivandonal
Copy link
Copy Markdown
Contributor

@osullivandonal osullivandonal commented Feb 16, 2026

Description

This PR add's support for linking metrics defined in metadata.yaml to their Semantic Conventions definitions. When a metric specifies a semantic_convention.ref URL, the generated code will:

  • Import the appropriate semconv package (e.g., systemconv)
  • Use semconv types for metric Name(), Description(), and Unit() instead of hardcoded strings
  • Auto-infer the semconv package and type from the metric name (e.g., system.cpu.timesystemconv.CPUTime)
    This enables components to leverage stable semantic convention definitions directly, ensuring consistency with the OTel specification.

For example, if we use the semantic_convention.ref url for system.memory.limit:

  system.memory.limit:
    enabled: true
    stability: development
    description: Total bytes of memory available.
    unit: By
    sum:
      value_type: int
      monotonic: false
      aggregation_temporality: cumulative
    # package and type are intentionally omitted to test auto-inference from metric name
    semantic_convention:
      ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemmemorylimit

The generated code from running make gogenerate:

Before this update to mdatagen:

// init fills system.memory.limit metric with initial data.
func (m *metricSystemMemoryLimit) init() {
	m.data.SetName("system.memory.limit")
	m.data.SetDescription("Total bytes of memory available.")
	m.data.SetUnit("By")
	m.data.SetEmptySum()
...
}

After using this PR to generate code

// init fills system.cpu.time metric with initial data.
func (m *metricSystemCPUTime) init() {
	m.data.SetName(metricSemConvSystemCPUTime.Name())
	m.data.SetDescription(metricSemConvSystemCPUTime.Description())
	m.data.SetUnit(metricSemConvSystemCPUTime.Unit())
	m.data.SetEmptySum()
...
}

Link to tracking issue

Fixes #13297

Testing

  • Added unit tests for InferSemConvFromMetricName covering various metric name patterns
  • Added unit tests for inferSemConvTypes to verify auto-population of Package/Type
  • Added loader test for semconv version validation (requires >= 1.32.0)
  • Updated samplereceiver with semconv-linked metrics (system.cpu.time, system.memory.limit) to verify end-to-end code generation

Documentation

  • Updated metadata-schema.yaml with documentation for the semantic_convention field
  • Package and type fields are documented as auto-inferred when only ref is provided

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 92.71523% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.84%. Comparing base (6dd7ac8) to head (1c0aa26).
⚠️ Report is 41 commits behind head on main.

Files with missing lines Patch % Lines
...plereceiver/internal/metadata/generated_metrics.go 87.20% 10 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (92.71%) 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   #14598    +/-   ##
========================================
  Coverage   91.83%   91.84%            
========================================
  Files         679      679            
  Lines       42921    43063   +142     
========================================
+ Hits        39416    39550   +134     
- Misses       2437     2442     +5     
- Partials     1068     1071     +3     

☔ 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 24, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 61 untouched benchmarks
⏩ 20 skipped benchmarks1


Comparing osullivandonal:mdatagen-link-metrics-and-attributes-from-metadata-to-semconv (1c0aa26) with main (1b90e21)

Open in CodSpeed

Footnotes

  1. 20 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

These have been removed as we don't want the consumer to have to
manually specify this, mdatagen can infer thse directly from the
semantic_convention ref url.
@osullivandonal
Copy link
Copy Markdown
Contributor Author

Closing this PR for now as the direction for this work has changed slightly. This PR also found an issue with using the approach of using the semconv go sdk to generate code using semconv go code, semconv version of >= 1.32.0. There is an open PR to update the attributes in the metadata schema with the semantic_convention ref, which this work doesn't tackle. #14646

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mdatagen] Consider linking metrics/attributes from metadata.yaml to SemConv definitions

1 participant