Skip to content

Commit 0170f84

Browse files
committed
[mdatagen] Fix generated tests for conditional enum attributes
1 parent 1fbaab9 commit 0170f84

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
change_type: bug_fix
2+
component: cmd/mdatagen
3+
note: Fix invalid generated tests for conditionally_required enum attributes in metrics.
4+
issues: [14196, 14230]

cmd/mdatagen/internal/templates/metrics.go.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ func (maof metricAttributeOptionFunc) apply(dp pmetric.NumberDataPoint) {
100100
}
101101

102102
{{ range getMetricConditionalAttributes .Attributes }}
103-
func With{{ .Render }}MetricAttribute({{ .RenderUnexported }}AttributeValue {{ (attributeInfo .).Type.Primitive }}) MetricAttributeOption {
103+
func With{{ .Render }}MetricAttribute({{ .RenderUnexported }}AttributeValue {{ if (attributeInfo .).Enum }}Attribute{{ .Render }}{{ else }}{{ (attributeInfo .).Type.Primitive }}{{ end }}) MetricAttributeOption {
104104
return metricAttributeOptionFunc(func(dp pmetric.NumberDataPoint) {
105+
{{- if (attributeInfo .).Enum }}
106+
dp.Attributes().PutStr("{{ (attributeInfo .).Name }}", {{ .RenderUnexported }}AttributeValue.String())
107+
{{- else }}
105108
{{- template "putAttribute" . }}
109+
{{- end }}
106110
})
107111
}
108112
{{ end }}

0 commit comments

Comments
 (0)