Skip to content

Conversation

@Arunodoy18
Copy link

Description:
Fixes #14196
Fixes #14230

Fixes an issue where mdatagen generated invalid Go code for metrics tests when an attribute is of type enum and has requirement_level: conditionally_required.

The generated test code passes a typed Enum constant (e.g., AttributeEnumAttrRed) to the option function, but the generated option function signature incorrectly expected a primitive string, causing compilation errors in tests.

Changes:

  • Modified cmd/mdatagen/internal/templates/metrics.go.tmpl:
    • Updated With<Attr>MetricAttribute to accept the specific Enum type instead of a string.
    • Added internal conversion (.String()) before storing the attribute value.

Testing:

Fixes an issue where mdatagen generated invalid Go code for metrics tests when an attribute is of type enum and has requirement_level: conditionally_required.

The generated test code passes a typed Enum constant (e.g., AttributeEnumAttrRed) to the option function, but the generated option function signature incorrectly expected a primitive string, causing compilation errors in tests.

Changes:

  • Modified cmd/mdatagen/internal/templates/metrics.go.tmpl:
    • Updated With<Attr>MetricAttribute to accept the specific Enum type instead of a string.
    • Added internal conversion (.String()) before storing the attribute value.

Testing:

  • Verified that go generate produces valid code for components with conditional enum attributes.
  • Confirmed tests pass with go test ./... in cmd/mdatagen.

@Arunodoy18 Arunodoy18 requested review from a team, bogdandrutu and dmitryax as code owners January 13, 2026 21:21

if err := proctelemetry.RegisterProcessMetrics(srv.telemetrySettings); err != nil {
return nil, fmt.Errorf("failed to register process metrics: %w", err)
// Only register process metrics if metrics telemetry is enabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as on other PRs, please don't include multiple changes in a single pull request

When service.telemetry.metrics.level is set to 'none', the collector
should skip registering process metrics to avoid errors on platforms
where gopsutil is not supported (such as AIX).

This change conditionally registers process metrics only when the
metrics level is not LevelNone, preventing the 'failed to register
process metrics: not implemented yet' error on unsupported platforms.

Fixes regression introduced in v0.136.0 where the check for metrics
level was removed.
Similar to the resolution for pcommon.Value in previous changes, this update
ensures consistent documentation across all pdata types by clarifying that
calling functions on zero-initialized instances is invalid usage.

Changes:
- Updated template files (one_of_field.go, one_of_message_value.go) to generate
  improved comment wording
- Updated pcommon/value.go comments manually
- Updated all generated pdata files to use consistent wording:
  'is invalid and will cause a panic' instead of 'will cause a panic'

This makes it clearer that using zero-initialized instances is not just
dangerous but explicitly invalid usage, improving API documentation clarity.
Fixes open-telemetry#14326

mdatagen was generating invalid Go code for histogram metrics by using NumberDataPoint API methods (SetDoubleValue, ValueType) on HistogramDataPoint types, causing compilation errors.

Changes: Update metrics.go.tmpl to use HistogramDataPoint API for histogram metrics with dp.SetCount(1) and dp.SetSum(val). Update metrics_test.go.tmpl to assert dp.Count() and dp.Sum() for histograms. Add system.cpu.utilization histogram to samplescraper metadata for validation.
@Arunodoy18 Arunodoy18 force-pushed the fix/mdatagen-enum-conditional-attributes branch from 2964730 to b7200b5 Compare January 26, 2026 11:22
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] Invalid generated tests for conditionally_required enum attribute

2 participants