Skip to content

fix(mdatagen): fix generated tests for conditionally_required enum attributes#14594

Open
RoryGlenn wants to merge 1 commit intoopen-telemetry:mainfrom
RoryGlenn:fix/14196-mdatagen-enum-conditional-required
Open

fix(mdatagen): fix generated tests for conditionally_required enum attributes#14594
RoryGlenn wants to merge 1 commit intoopen-telemetry:mainfrom
RoryGlenn:fix/14196-mdatagen-enum-conditional-required

Conversation

@RoryGlenn
Copy link

Description

When an attribute is both enum-typed and conditionally_required, the generated With*MetricAttribute function accepted a string parameter (Type.Primitive) but the generated test code passed the enum constant (e.g., AttributeEnumAttrRed of type int), causing a compile error:

cannot use AttributeEnumAttrRed (constant 1 of int type AttributeEnumAttr) as string value in argument to WithEnumAttrMetricAttribute

This fixes the metrics.go.tmpl template to use the enum type (Attribute*) as the parameter type and call .String() internally when putting the attribute value, consistent with how non-conditional enum attributes are already handled in Record*DataPoint methods.

Also updates sampleconnector/metadata.yaml to set enum_attr as conditionally_required, exercising the fix in generated test code to prevent regression.

Link to tracking issue

Fixes #14196

Testing

  • Built mdatagen with the template fix
  • Regenerated sampleconnector code with conditionally_required enum attribute
  • All mdatagen tests pass (go test ./... — 14 packages OK)
  • Generated code compiles correctly with proper type matching

…tributes

When an attribute is both enum-typed and conditionally_required, the
generated With*MetricAttribute function accepted a string parameter
(Type.Primitive) but the generated test code passed the enum constant
(e.g., AttributeEnumAttrRed of type int), causing a compile error.

Fix the metrics.go.tmpl template to use the enum type (Attribute*)
as the parameter type and call .String() internally, consistent with
how non-conditional enum attributes are handled in Record*DataPoint.

Update sampleconnector metadata.yaml to set enum_attr as
conditionally_required, exercising the fix in generated test code.

Fixes open-telemetry#14196

Assisted-by: Claude Opus 4.6
@RoryGlenn RoryGlenn requested review from a team and dmitryax as code owners February 15, 2026 23:16
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.

[mdatagen] Invalid generated tests for conditionally_required enum attribute

1 participant