Skip to content

Commit

Permalink
[mdatagen] Sanitize attributes in metrics builder code generation (#6905
Browse files Browse the repository at this point in the history
)

This change fixes metrics builder code generation for attributes with symbols like dots
  • Loading branch information
dmitryax authored Dec 20, 2021
1 parent f7d4c89 commit 4854bf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (mn attributeName) Render() (string, error) {
return formatIdentifier(string(mn), true)
}

func (mn attributeName) RenderUnexported() (string, error) {
return formatIdentifier(string(mn), false)
}

type metric struct {
// Enabled defines whether the metric is enabled by default.
Enabled bool `yaml:"enabled"`
Expand Down
4 changes: 2 additions & 2 deletions cmd/mdatagen/metrics_v2.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (mb *MetricsBuilder) initMetrics() {
// Any attribute of AttributeValueTypeEmpty type will be skipped.
func (mb *MetricsBuilder) Record{{ $name.Render }}DataPoint(ts pdata.Timestamp
{{- if $metric.Data.HasMetricValueType }}, val {{ $metric.Data.MetricValueType.BasicType }}{{ end }}
{{- range $metric.Attributes -}}, {{ . }}AttributeValue string {{ end }}) {
{{- range $metric.Attributes -}}, {{ .RenderUnexported }}AttributeValue string {{ end }}) {
if !mb.config.{{- $name.Render }}.Enabled {
return
}
Expand All @@ -173,7 +173,7 @@ func (mb *MetricsBuilder) Record{{ $name.Render }}DataPoint(ts pdata.Timestamp
dp.Set{{ $metric.Data.MetricValueType }}Val(val)
{{- end }}
{{ range $metric.Attributes -}}
dp.Attributes().Insert(A.{{ .Render }}, pdata.NewAttributeValueString({{ . }}AttributeValue))
dp.Attributes().Insert(A.{{ .Render }}, pdata.NewAttributeValueString({{ .RenderUnexported }}AttributeValue))
{{ end -}}
}
{{ end }}
Expand Down

0 comments on commit 4854bf4

Please sign in to comment.