fix(mdatagen): fix generated tests for conditionally_required enum attributes#14594
Open
RoryGlenn wants to merge 1 commit intoopen-telemetry:mainfrom
Open
fix(mdatagen): fix generated tests for conditionally_required enum attributes#14594RoryGlenn wants to merge 1 commit intoopen-telemetry:mainfrom
RoryGlenn wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an attribute is both enum-typed and
conditionally_required, the generatedWith*MetricAttributefunction accepted astringparameter (Type.Primitive) but the generated test code passed the enum constant (e.g.,AttributeEnumAttrRedof typeint), causing a compile error:This fixes the
metrics.go.tmpltemplate 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 inRecord*DataPointmethods.Also updates
sampleconnector/metadata.yamlto setenum_attrasconditionally_required, exercising the fix in generated test code to prevent regression.Link to tracking issue
Fixes #14196
Testing
conditionally_requiredenum attributego test ./...— 14 packages OK)